comparison helpers/mk-flash-script.c @ 257:d4d07c751e56

helpers: mk-flash-script helper program written
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 04 Aug 2017 06:54:12 +0000
parents
children
comparison
equal deleted inserted replaced
256:ba63f14d1e84 257:d4d07c751e56
1 /*
2 * This helper program generates the fc-loadtool command script
3 * for flashing the just-built firmware image.
4 */
5
6 #include <sys/types.h>
7 #include <sys/stat.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <unistd.h>
11
12 main(argc, argv)
13 char **argv;
14 {
15 struct stat st;
16 u_long image_size, sector_size;
17
18 if (argc != 4) {
19 fprintf(stderr,
20 "usage: %s fwimage.bin flash-base flash-sector-size\n",
21 argv[0]);
22 exit(1);
23 }
24 if (stat(argv[1], &st) < 0) {
25 perror(argv[1]);
26 exit(1);
27 }
28 if (!S_ISREG(st.st_mode)) {
29 fprintf(stderr, "error: %s is not a regular file\n", argv[1]);
30 exit(1);
31 }
32 image_size = st.st_size;
33 sector_size = strtoul(argv[3], 0, 16);
34 image_size += sector_size - 1;
35 image_size &= ~(sector_size - 1);
36 printf("flash erase %s 0x%lx\n", argv[2], image_size);
37 printf("flash program-bin %s %s\n", argv[2], argv[1]);
38 exit(0);
39 }