annotate loadtools/flcmplboot.c @ 414:a2df77833c21

fc-loadtool: started implementing flash erase-program-boot command
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Tue, 17 Jun 2014 05:46:21 +0000
parents bf49e348576b
children b2487cfd68fd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
412
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * This module contains the implementation of the flash erase-program-boot
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 * hack for brickable Compal phones.
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4 */
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <sys/types.h>
414
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
7 #include <sys/stat.h>
412
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <ctype.h>
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <stdio.h>
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 #include <stdint.h>
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 #include <string.h>
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12 #include <strings.h>
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 #include <stdlib.h>
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14 #include "flash.h"
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15
414
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
16 extern struct flash_bank_info flash_bank_info[2];
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
17 extern struct flash_cmdset flash_cmdset_intel;
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
18
412
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19 static int hack_enabled;
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20 static uint32_t boot_sector_size;
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21 static uint32_t ram_buffer_addr;
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 /* called from hwparam.c config file parser */
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 void
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 set_boot_reflash_hack(arg, filename_for_errs, lineno_for_errs)
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 char *arg;
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 char *filename_for_errs;
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28 int lineno_for_errs;
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 {
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 char *cp, *np, *ep;
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 if (hack_enabled) {
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 fprintf(stderr,
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 "%s line %d: duplicate boot-reflash-hack setting\n",
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 filename_for_errs, lineno_for_errs);
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 exit(1);
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 }
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 for (cp = arg; isspace(*cp); cp++)
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 ;
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 if (!*cp || *cp == '#') {
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 too_few_arg: fprintf(stderr,
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 "%s line %d: boot-reflash-hack setting: too few arguments\n",
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43 filename_for_errs, lineno_for_errs);
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44 exit(1);
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45 }
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 for (np = cp; *cp && !isspace(*cp); cp++)
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 ;
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48 if (!*cp)
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49 goto too_few_arg;
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50 *cp++ = '\0';
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51 ram_buffer_addr = strtoul(np, &ep, 16);
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 if (*ep) {
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53 invhex: fprintf(stderr,
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 "%s line %d: syntax error (hex arguments expected)\n",
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55 filename_for_errs, lineno_for_errs);
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56 exit(1);
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57 }
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58 while (isspace(*cp))
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59 cp++;
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60 if (!*cp || *cp == '#')
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 goto too_few_arg;
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62 for (np = cp; *cp && !isspace(*cp); cp++)
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 ;
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64 if (*cp)
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65 *cp++ = '\0';
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66 boot_sector_size = strtoul(np, &ep, 16);
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
67 if (*ep)
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
68 goto invhex;
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
69 while (isspace(*cp))
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
70 cp++;
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
71 if (*cp && *cp != '#') {
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
72 fprintf(stderr,
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
73 "%s line %d: boot-reflash-hack setting: too many arguments\n",
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
74 filename_for_errs, lineno_for_errs);
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
75 exit(1);
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
76 }
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
77 hack_enabled = 1;
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
78 }
414
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
79
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
80 flashcmd_erase_program_boot(argc, argv)
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
81 char **argv;
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
82 {
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
83 FILE *binf;
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
84 struct stat filestat;
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
85 size_t len;
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
86 char *strtoul_endp;
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
87
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
88 if (!hack_enabled) {
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
89 fprintf(stderr,
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
90 "Operation not applicable to this target device\n");
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
91 return(-1);
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
92 }
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
93 if (argc < 3 || argc > 4) {
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
94 inv: fprintf(stderr, "usage: %s %s binfile [length]\n",
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
95 argv[0], argv[1]);
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
96 return(-1);
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
97 }
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
98 if (flash_get_cfi(0) < 0)
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
99 return(-1);
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
100 if (flash_bank_info[0].geom->regions[0].sector_size
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
101 != boot_sector_size) {
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
102 fprintf(stderr,
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
103 "error: detected flash boot sector size differs from config\n");
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
104 return(-1);
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
105 }
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
106 if (flash_bank_info[0].ops != &flash_cmdset_intel) {
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
107 fprintf(stderr,
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
108 "error: operation implemented for Intel flash only\n");
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
109 return(-1);
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
110 }
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
111
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
112 binf = fopen(argv[2], "r");
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
113 if (!binf) {
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
114 perror(argv[2]);
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
115 return(-1);
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
116 }
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
117 fstat(fileno(binf), &filestat);
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
118 if (!S_ISREG(filestat.st_mode)) {
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
119 fprintf(stderr, "%s is not a regular file\n", argv[2]);
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
120 fclose(binf);
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
121 return(-1);
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
122 }
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
123 if (argc > 3) {
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
124 len = strtoul(argv[3], &strtoul_endp, 16);
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
125 if (*strtoul_endp) {
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
126 fclose(binf);
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
127 goto inv;
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
128 }
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
129 if (len > filestat.st_size) {
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
130 fprintf(stderr,
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
131 "error: specified length exceeds file length\n");
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
132 fclose(binf);
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
133 return(-1);
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
134 }
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
135 } else
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
136 len = filestat.st_size;
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
137 if (len > boot_sector_size) {
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
138 fprintf(stderr, "error: length exceeds boot sector size\n");
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
139 fclose(binf);
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
140 return(-1);
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
141 }
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
142
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
143
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
144 }