FreeCalypso > hg > fc-selenite
comparison helpers/mk-flash-script.c @ 11:b493d3857f4e
helpers: initial import from Magnetite (pruned)
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 15 Jul 2018 21:24:44 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
10:a8f9cc376e98 | 11:b493d3857f4e |
---|---|
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 } |