comparison loadtools/flmain.c @ 506:0dd2c87c1b63

fc-loadtool flash support overhaul
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 28 May 2019 05:12:47 +0000
parents 545e1718f5fb
children 211be4dc6be2
comparison
equal deleted inserted replaced
505:7bf0d909c87e 506:0dd2c87c1b63
9 #include <string.h> 9 #include <string.h>
10 #include <strings.h> 10 #include <strings.h>
11 #include <stdlib.h> 11 #include <stdlib.h>
12 #include "flash.h" 12 #include "flash.h"
13 13
14 /* K5A32xx device description */ 14 extern int flash_global_config;
15 extern struct flash_bank_info flash_bank_info[2];
15 16
16 static struct flash_geom k5a32xx_topboot_geom = { 17 flashcmd_geom(argc, argv, bank)
17 .total_size = 0x400000,
18 .nregions = 2,
19 .regions = {0x10000, 63, 0x2000, 8},
20 .total_sectors = 71,
21 };
22
23 static struct flash_idcheck k5a32xx_topboot_idcheck[2] = {
24 {0x00, 0x00EC},
25 {0x02, 0x22A0}
26 };
27
28 static struct flash_bank_desc k5a32xx_topboot_bankdesc = {
29 0x400000, &k5a32xx_topboot_geom, k5a32xx_topboot_idcheck, 2
30 };
31
32 /* S{29,71}PL129N device description */
33
34 static struct flash_geom pl129n_ce1_geom = {
35 .total_size = 0x800000,
36 .nregions = 2,
37 .regions = {0x10000, 4, 0x40000, 31},
38 .total_sectors = 35,
39 };
40
41 static struct flash_geom pl129n_ce2_geom = {
42 .total_size = 0x800000,
43 .nregions = 2,
44 .regions = {0x40000, 31, 0x10000, 4},
45 .total_sectors = 35,
46 };
47
48 static struct flash_idcheck pl129n_idcheck[4] = {
49 {0x00, 0x0001},
50 {0x02, 0x227E},
51 {0x1C, 0x2221},
52 {0x1E, 0x2200}
53 };
54
55 static struct flash_bank_desc pl129n_banks[2] = {
56 {0x800000, &pl129n_ce1_geom, pl129n_idcheck, 4},
57 {0x800000, &pl129n_ce2_geom, pl129n_idcheck, 4}
58 };
59
60 /* 28F640W30B device description */
61
62 static struct flash_geom f640w30b_geom = {
63 .total_size = 0x800000,
64 .nregions = 2,
65 .regions = {0x2000, 8, 0x10000, 127},
66 .total_sectors = 135,
67 };
68
69 static struct flash_idcheck f640w30b_idcheck[2] = {
70 {0x00, 0x0089},
71 {0x02, 0x8855}
72 };
73
74 static struct flash_bank_desc f640w30b_bankdesc = {
75 0x800000, &f640w30b_geom, f640w30b_idcheck, 2
76 };
77
78 /* bank configurations for CFI */
79
80 static struct flash_bank_desc cfi_4M_bankdesc = {
81 0x400000, 0, 0, 0
82 };
83
84 static struct flash_bank_desc cfi_8M_bankdesc = {
85 0x800000, 0, 0, 0
86 };
87
88 /* list of supported flash devices */
89
90 extern struct flash_cmdset flash_cmdset_amd;
91 extern struct flash_cmdset flash_cmdset_intel_w30;
92
93 struct flash_device_desc flash_device_list[] = {
94 {"cfi-4M", &cfi_4M_bankdesc, 1, 0},
95 {"cfi-8M", &cfi_8M_bankdesc, 1, 0},
96 {"k5a32xx_t", &k5a32xx_topboot_bankdesc, 1, &flash_cmdset_amd},
97 {"pl129n", pl129n_banks, 2, &flash_cmdset_amd},
98 {"28f640w30b", &f640w30b_bankdesc, 1, &flash_cmdset_intel_w30},
99 {0, 0, 0, 0} /* array terminator */
100 };
101
102 /* the following variables describe our selected flash device */
103
104 struct flash_device_desc *selected_flash_device;
105 struct flash_bank_info flash_bank_info[2];
106
107 /* called from hwparam.c config file parser */
108 void
109 set_flash_device(arg, filename_for_errs, lineno_for_errs)
110 char *arg;
111 char *filename_for_errs;
112 int lineno_for_errs;
113 {
114 char *cp, *np, *ep;
115 struct flash_device_desc *tp;
116 int bank;
117 struct flash_bank_info *bi;
118
119 if (selected_flash_device) {
120 fprintf(stderr, "%s line %d: duplicate flash setting\n",
121 filename_for_errs, lineno_for_errs);
122 exit(1);
123 }
124 for (cp = arg; isspace(*cp); cp++)
125 ;
126 if (!*cp || *cp == '#') {
127 too_few_arg: fprintf(stderr,
128 "%s line %d: flash setting: too few arguments\n",
129 filename_for_errs, lineno_for_errs);
130 exit(1);
131 }
132 for (np = cp; *cp && !isspace(*cp); cp++)
133 ;
134 if (*cp)
135 *cp++ = '\0';
136 for (tp = flash_device_list; tp->name; tp++)
137 if (!strcmp(tp->name, np))
138 break;
139 if (!tp->name) {
140 fprintf(stderr,
141 "%s line %d: unknown flash device \"%s\"\n",
142 filename_for_errs, lineno_for_errs, np);
143 exit(1);
144 }
145 selected_flash_device = tp;
146
147 /* now initialize flash_bank_info */
148 for (bank = 0; bank < selected_flash_device->nbanks; bank++) {
149 while (isspace(*cp))
150 cp++;
151 if (!*cp || *cp == '#')
152 goto too_few_arg;
153 for (np = cp; *cp && !isspace(*cp); cp++)
154 ;
155 if (*cp)
156 *cp++ = '\0';
157 bi = flash_bank_info + bank;
158 bi->base_addr = strtoul(np, &ep, 16);
159 if (*ep) {
160 fprintf(stderr,
161 "%s line %d: syntax error (base addr expected after flash device type)\n",
162 filename_for_errs, lineno_for_errs);
163 exit(1);
164 }
165 /* the rest comes from the flash device type */
166 bi->bank_desc = selected_flash_device->bank_desc + bank;
167 if (bi->base_addr & (bi->bank_desc->align_size - 1)) {
168 fprintf(stderr,
169 "%s line %d: flash bank %d base addr is not aligned to the bank size (0x%lx)\n",
170 filename_for_errs, lineno_for_errs, bank,
171 (u_long) bi->bank_desc->align_size);
172 exit(1);
173 }
174 bi->geom = bi->bank_desc->geom;
175 bi->ops = selected_flash_device->cmdset;
176 }
177 while (isspace(*cp))
178 cp++;
179 if (*cp && *cp != '#') {
180 fprintf(stderr,
181 "%s line %d: flash setting: too many arguments\n",
182 filename_for_errs, lineno_for_errs);
183 exit(1);
184 }
185 }
186
187 flashcmd_help()
188 {
189 return loadtool_help("flash");
190 }
191
192 flashcmd_info(argc, argv, bank)
193 char **argv; 18 char **argv;
194 { 19 {
195 struct flash_bank_info *bi; 20 struct flash_bank_info *bi;
196 21
197 if (argc > 2) { 22 if (argc > 2) {
198 fprintf(stderr, "error: too many arguments\n"); 23 fprintf(stderr, "error: too many arguments\n");
199 return(-1); 24 return(-1);
200 } 25 }
26 if (flash_detect(bank, 0) < 0)
27 return(-1);
201 bi = flash_bank_info + bank; 28 bi = flash_bank_info + bank;
202 printf("Flash device type: %s\n", selected_flash_device->name); 29 if (bi->device->bank_geom[1])
203 printf("Bank %d base address: %08lX\n", bank, (u_long) bi->base_addr); 30 printf("Device has two banks, looking at bank %d\n", bank);
204 if (flash_get_cfi(bank) < 0) 31 else
205 return(-1); 32 printf("Single-bank flash device\n");
206 printf("Bank %d total size: %lx\n", bank, 33 printf("Bank %d total size: %lx\n", bank,
207 (u_long) bi->geom->total_size); 34 (u_long) bi->geom->total_size);
208 printf("Sectors in bank %d: %u (%u regions)\n", bank, 35 printf("Sectors in bank %d: %u (%u regions)\n", bank,
209 bi->geom->total_sectors, bi->geom->nregions); 36 bi->geom->total_sectors, bi->geom->nregions);
210 printf("Command set style: %s\n", bi->ops->cmdset_name); 37 printf("Command set style: %s\n", bi->ops->cmdset_name);
211 flash_id_check(bank, 1); 38 return(0);
212 if (selected_flash_device->nbanks == 2 && !bank) 39 }
213 printf("\nFlash device has 2 banks; flash2 command available\n"); 40
41 flashcmd_help()
42 {
43 return loadtool_help("flash");
44 }
45
46 flashcmd_id(argc, argv, bank)
47 char **argv;
48 {
49 if (argc > 2) {
50 fprintf(stderr, "error: too many arguments\n");
51 return(-1);
52 }
53 return flash_detect(bank, 1);
54 }
55
56 flashcmd_info(argc, argv)
57 char **argv;
58 {
59 int bank, nbanks;
60
61 if (argc > 2) {
62 fprintf(stderr, "error: too many arguments\n");
63 return(-1);
64 }
65 switch (flash_global_config) {
66 case FLASH_GLOBAL_CFG_SINGLE_4M:
67 printf("Configured for a single flash bank of up to 4 MiB\n");
68 nbanks = 1;
69 break;
70 case FLASH_GLOBAL_CFG_SINGLE_8M:
71 printf("Configured for a single flash bank of up to 8 MiB\n");
72 nbanks = 1;
73 break;
74 case FLASH_GLOBAL_CFG_DUAL_8M:
75 printf("Configured for two flash banks of up to 8 MiB each\n");
76 nbanks = 2;
77 break;
78 default:
79 fprintf(stderr, "error: invalid global config\n");
80 return(-1);
81 }
82 for (bank = 0; bank < nbanks; bank++)
83 printf("Bank %d base address: %08lX\n", bank,
84 (u_long) flash_bank_info[bank].base_addr);
214 return(0); 85 return(0);
215 } 86 }
216 87
217 extern int flashcmd_blankchk(); 88 extern int flashcmd_blankchk();
218 extern int flashcmd_dump2file(); 89 extern int flashcmd_dump2file();
234 {"blankchk", flashcmd_blankchk}, 105 {"blankchk", flashcmd_blankchk},
235 {"dump2bin", flashcmd_dump2file}, 106 {"dump2bin", flashcmd_dump2file},
236 {"dump2srec", flashcmd_dump2file}, 107 {"dump2srec", flashcmd_dump2file},
237 {"erase", flashcmd_erase}, 108 {"erase", flashcmd_erase},
238 {"erase-program-boot", flashcmd_erase_program_boot}, 109 {"erase-program-boot", flashcmd_erase_program_boot},
110 {"geom", flashcmd_geom},
239 {"help", flashcmd_help}, 111 {"help", flashcmd_help},
112 {"id", flashcmd_id},
240 {"info", flashcmd_info}, 113 {"info", flashcmd_info},
241 {"program-bin", flashcmd_progbin}, 114 {"program-bin", flashcmd_progbin},
242 {"program-m0", flashcmd_program_m0}, 115 {"program-m0", flashcmd_program_m0},
243 {"program-srec", flashcmd_program_srec}, 116 {"program-srec", flashcmd_program_srec},
244 {"quickprog", flashcmd_quickprog}, 117 {"quickprog", flashcmd_quickprog},
253 char **argv; 126 char **argv;
254 { 127 {
255 int bank; 128 int bank;
256 struct cmdtab *tp; 129 struct cmdtab *tp;
257 130
258 if (!selected_flash_device) { 131 if (!flash_global_config) {
259 fprintf(stderr, "No flash configuration defined\n"); 132 fprintf(stderr, "No flash configuration defined\n");
260 return(-1); 133 return(-1);
261 } 134 }
262 if (argv[0][5] == '2') { 135 if (argv[0][5] == '2') {
263 if (selected_flash_device->nbanks < 2) { 136 if (flash_global_config != FLASH_GLOBAL_CFG_DUAL_8M) {
264 fprintf(stderr, "Flash device %s has only one bank\n", 137 fprintf(stderr, "No second flash bank configured\n");
265 selected_flash_device->name);
266 return(-1); 138 return(-1);
267 } 139 }
268 bank = 1; 140 bank = 1;
269 } else 141 } else
270 bank = 0; 142 bank = 0;