comparison 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
comparison
equal deleted inserted replaced
413:1ed2d78f150c 414:a2df77833c21
2 * This module contains the implementation of the flash erase-program-boot 2 * This module contains the implementation of the flash erase-program-boot
3 * hack for brickable Compal phones. 3 * hack for brickable Compal phones.
4 */ 4 */
5 5
6 #include <sys/types.h> 6 #include <sys/types.h>
7 #include <sys/stat.h>
7 #include <ctype.h> 8 #include <ctype.h>
8 #include <stdio.h> 9 #include <stdio.h>
9 #include <stdint.h> 10 #include <stdint.h>
10 #include <string.h> 11 #include <string.h>
11 #include <strings.h> 12 #include <strings.h>
12 #include <stdlib.h> 13 #include <stdlib.h>
13 #include "flash.h" 14 #include "flash.h"
15
16 extern struct flash_bank_info flash_bank_info[2];
17 extern struct flash_cmdset flash_cmdset_intel;
14 18
15 static int hack_enabled; 19 static int hack_enabled;
16 static uint32_t boot_sector_size; 20 static uint32_t boot_sector_size;
17 static uint32_t ram_buffer_addr; 21 static uint32_t ram_buffer_addr;
18 22
70 filename_for_errs, lineno_for_errs); 74 filename_for_errs, lineno_for_errs);
71 exit(1); 75 exit(1);
72 } 76 }
73 hack_enabled = 1; 77 hack_enabled = 1;
74 } 78 }
79
80 flashcmd_erase_program_boot(argc, argv)
81 char **argv;
82 {
83 FILE *binf;
84 struct stat filestat;
85 size_t len;
86 char *strtoul_endp;
87
88 if (!hack_enabled) {
89 fprintf(stderr,
90 "Operation not applicable to this target device\n");
91 return(-1);
92 }
93 if (argc < 3 || argc > 4) {
94 inv: fprintf(stderr, "usage: %s %s binfile [length]\n",
95 argv[0], argv[1]);
96 return(-1);
97 }
98 if (flash_get_cfi(0) < 0)
99 return(-1);
100 if (flash_bank_info[0].geom->regions[0].sector_size
101 != boot_sector_size) {
102 fprintf(stderr,
103 "error: detected flash boot sector size differs from config\n");
104 return(-1);
105 }
106 if (flash_bank_info[0].ops != &flash_cmdset_intel) {
107 fprintf(stderr,
108 "error: operation implemented for Intel flash only\n");
109 return(-1);
110 }
111
112 binf = fopen(argv[2], "r");
113 if (!binf) {
114 perror(argv[2]);
115 return(-1);
116 }
117 fstat(fileno(binf), &filestat);
118 if (!S_ISREG(filestat.st_mode)) {
119 fprintf(stderr, "%s is not a regular file\n", argv[2]);
120 fclose(binf);
121 return(-1);
122 }
123 if (argc > 3) {
124 len = strtoul(argv[3], &strtoul_endp, 16);
125 if (*strtoul_endp) {
126 fclose(binf);
127 goto inv;
128 }
129 if (len > filestat.st_size) {
130 fprintf(stderr,
131 "error: specified length exceeds file length\n");
132 fclose(binf);
133 return(-1);
134 }
135 } else
136 len = filestat.st_size;
137 if (len > boot_sector_size) {
138 fprintf(stderr, "error: length exceeds boot sector size\n");
139 fclose(binf);
140 return(-1);
141 }
142
143
144 }