FreeCalypso > hg > fc-am-toolkit
annotate bootutil/c155_main.c @ 22:873d5f33e8f3
doc: beginning with FC-aftermarket-intro
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 11 Jun 2023 06:18:53 +0000 |
parents | 36e65605d16a |
children |
rev | line source |
---|---|
12
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
15
36e65605d16a
bootutil: add c155-analyze-boot
Mychaela Falconia <falcon@freecalypso.org>
parents:
12
diff
changeset
|
2 * This C module is the main for c155-analyze-boot utility. |
12
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <sys/types.h> |
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/file.h> |
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <sys/stat.h> |
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdio.h> |
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdlib.h> |
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <string.h> |
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <strings.h> |
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <unistd.h> |
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include "../bootmatch/bootmatch.h" |
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 |
15
36e65605d16a
bootutil: add c155-analyze-boot
Mychaela Falconia <falcon@freecalypso.org>
parents:
12
diff
changeset
|
15 extern struct bootmatch bootmatch_c155[]; |
12
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
15
36e65605d16a
bootutil: add c155-analyze-boot
Mychaela Falconia <falcon@freecalypso.org>
parents:
12
diff
changeset
|
17 #define LENGTH_OF_INTEREST 0x2000 |
12
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 static u_char image[LENGTH_OF_INTEREST]; |
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 |
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 static void |
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 read_bin_file(filename) |
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 char *filename; |
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 { |
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 int fd; |
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 struct stat st; |
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 |
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 fd = open(filename, O_RDONLY); |
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 if (fd < 0) { |
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 perror(filename); |
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 exit(1); |
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 } |
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 fstat(fd, &st); |
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 if (!S_ISREG(st.st_mode)) { |
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 fprintf(stderr, "error: %s is not a regular file\n", filename); |
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 exit(1); |
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 } |
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 if (st.st_size < LENGTH_OF_INTEREST) { |
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 fprintf(stderr, "error: %s is too short\n", filename); |
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 exit(1); |
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 } |
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 read(fd, image, LENGTH_OF_INTEREST); |
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 close(fd); |
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 } |
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 |
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 main(argc, argv) |
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 char **argv; |
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 { |
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 if (argc != 2) { |
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 fprintf(stderr, "usage: %s flashdump.bin\n", argv[0]); |
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 exit(1); |
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 } |
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 read_bin_file(argv[1]); |
15
36e65605d16a
bootutil: add c155-analyze-boot
Mychaela Falconia <falcon@freecalypso.org>
parents:
12
diff
changeset
|
54 if (check_for_match(image, bootmatch_c155)) |
36e65605d16a
bootutil: add c155-analyze-boot
Mychaela Falconia <falcon@freecalypso.org>
parents:
12
diff
changeset
|
55 puts("ok"); |
36e65605d16a
bootutil: add c155-analyze-boot
Mychaela Falconia <falcon@freecalypso.org>
parents:
12
diff
changeset
|
56 else |
36e65605d16a
bootutil: add c155-analyze-boot
Mychaela Falconia <falcon@freecalypso.org>
parents:
12
diff
changeset
|
57 puts("unknown"); |
12
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 exit(0); |
fe5f7ba7f154
c139-analyze-boot utility put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 } |