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