FreeCalypso > hg > fc-am-toolkit
view 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 |
line wrap: on
line source
/* * This C module is the main for c155-analyze-boot utility. */ #include <sys/types.h> #include <sys/file.h> #include <sys/stat.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <strings.h> #include <unistd.h> #include "../bootmatch/bootmatch.h" extern struct bootmatch bootmatch_c155[]; #define LENGTH_OF_INTEREST 0x2000 static u_char image[LENGTH_OF_INTEREST]; static void read_bin_file(filename) char *filename; { int fd; struct stat st; fd = open(filename, O_RDONLY); if (fd < 0) { perror(filename); exit(1); } fstat(fd, &st); if (!S_ISREG(st.st_mode)) { fprintf(stderr, "error: %s is not a regular file\n", filename); exit(1); } if (st.st_size < LENGTH_OF_INTEREST) { fprintf(stderr, "error: %s is too short\n", filename); exit(1); } read(fd, image, LENGTH_OF_INTEREST); close(fd); } main(argc, argv) char **argv; { if (argc != 2) { fprintf(stderr, "usage: %s flashdump.bin\n", argv[0]); exit(1); } read_bin_file(argv[1]); if (check_for_match(image, bootmatch_c155)) puts("ok"); else puts("unknown"); exit(0); }