OLD | NEW |
---|---|
1 /* | 1 /* |
2 * This file is part of the flashrom project. | 2 * This file is part of the flashrom project. |
3 * | 3 * |
4 * Copyright (C) 2005-2008 coresystems GmbH | 4 * Copyright (C) 2005-2008 coresystems GmbH |
5 * (Written by Stefan Reinauer <stepan@coresystems.de> for coresystems GmbH) | 5 * (Written by Stefan Reinauer <stepan@coresystems.de> for coresystems GmbH) |
6 * Portions (C) 2010 Google Inc. | |
6 * | 7 * |
7 * This program is free software; you can redistribute it and/or modify | 8 * This program is free software; you can redistribute it and/or modify |
8 * it under the terms of the GNU General Public License as published by | 9 * it under the terms of the GNU General Public License as published by |
9 * the Free Software Foundation; version 2 of the License. | 10 * the Free Software Foundation; version 2 of the License. |
10 * | 11 * |
11 * This program is distributed in the hope that it will be useful, | 12 * This program is distributed in the hope that it will be useful, |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 * GNU General Public License for more details. | 15 * GNU General Public License for more details. |
15 * | 16 * |
16 * You should have received a copy of the GNU General Public License | 17 * You should have received a copy of the GNU General Public License |
17 * along with this program; if not, write to the Free Software | 18 * along with this program; if not, write to the Free Software |
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | 19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
19 */ | 20 */ |
20 | 21 |
21 #include <stdio.h> | 22 #include <stdio.h> |
22 #include <stdlib.h> | 23 #include <stdlib.h> |
23 #include <string.h> | 24 #include <string.h> |
24 #include <ctype.h> | 25 #include <ctype.h> |
25 #include <limits.h> | 26 #include <limits.h> |
26 #include "flash.h" | 27 #include "flash.h" |
28 #include "fmap.h" | |
27 #include "programmer.h" | 29 #include "programmer.h" |
28 | 30 |
29 #if CONFIG_INTERNAL == 1 | 31 #if CONFIG_INTERNAL == 1 |
30 char *mainboard_vendor = NULL; | 32 char *mainboard_vendor = NULL; |
31 char *mainboard_part = NULL; | 33 char *mainboard_part = NULL; |
32 #endif | 34 #endif |
33 static int romimages = 0; | 35 static int romimages = 0; |
34 | 36 |
35 #define MAX_ROMLAYOUT 64 | 37 #define MAX_ROMLAYOUT 64 |
36 | 38 |
37 typedef struct { | 39 typedef struct { |
38 unsigned int start; | 40 unsigned int start; |
39 unsigned int end; | 41 unsigned int end; |
40 unsigned int included; | 42 unsigned int included; |
41 char name[256]; | 43 char name[256]; |
42 char file[256]; /* file[0]=='\0' means not specified. */ | 44 char file[256]; /* file[0]=='\0' means not specified. */ |
43 } romlayout_t; | 45 } romlayout_t; |
44 | 46 |
45 /* | 47 /* |
46 * include_args lists arguments specified at the command line with -i. They | 48 * include_args lists arguments specified at the command line with -i. They |
47 * must be processed at some point so that desired regions are marked as | 49 * must be processed at some point so that desired regions are marked as |
48 * "included" in the master rom_entries list. | 50 * "included" in the master rom_entries list. |
49 */ | 51 */ |
50 static char *include_args[MAX_ROMLAYOUT]; | 52 static char *include_args[MAX_ROMLAYOUT]; |
Louis
2011/03/04 23:33:16
Did you accidentally include code from CL 6625011?
dhendrix
2011/03/05 00:25:30
I think that is due to git... I have this patch se
| |
51 static romlayout_t rom_entries[MAX_ROMLAYOUT]; | 53 static romlayout_t rom_entries[MAX_ROMLAYOUT]; |
52 | 54 |
53 #if CONFIG_INTERNAL == 1 /* FIXME: Move the whole block to cbtable.c? */ | 55 #if CONFIG_INTERNAL == 1 /* FIXME: Move the whole block to cbtable.c? */ |
54 static char *def_name = "DEFAULT"; | 56 static char *def_name = "DEFAULT"; |
55 | 57 |
56 int show_id(uint8_t *bios, int size, int force) | 58 int show_id(uint8_t *bios, int size, int force) |
57 { | 59 { |
58 unsigned int *walk; | 60 unsigned int *walk; |
59 unsigned int mb_part_offset, mb_vendor_offset; | 61 unsigned int mb_part_offset, mb_vendor_offset; |
60 char *mb_part, *mb_vendor; | 62 char *mb_part, *mb_vendor; |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
194 rom_entries[i].start, | 196 rom_entries[i].start, |
195 rom_entries[i].end, rom_entries[i].name); | 197 rom_entries[i].end, rom_entries[i].name); |
196 } | 198 } |
197 | 199 |
198 fclose(romlayout); | 200 fclose(romlayout); |
199 | 201 |
200 return 0; | 202 return 0; |
201 } | 203 } |
202 #endif | 204 #endif |
203 | 205 |
206 /* returns the number of entries added, or <0 to indicate error */ | |
207 static int add_fmap_entries(uint8_t *image, int size) | |
208 { | |
209 int i; | |
210 struct fmap *fmap; | |
211 long int fmap_offset; | |
212 | |
213 if ((fmap_offset = fmap_find(image, size)) < 0) | |
214 return 0; | |
215 fmap = (struct fmap *)(image + fmap_offset);; | |
216 | |
217 for (i = 0; i < fmap->nareas; i++) { | |
218 if (romimages >= MAX_ROMLAYOUT) { | |
219 msg_gerr("ROM image contains too many regions\n"); | |
220 return -1; | |
221 } | |
222 rom_entries[romimages].start = fmap->areas[i].offset; | |
223 | |
224 /* | |
225 * Flashrom rom entries use absolute addresses. So for non-zero | |
226 * length entries, we need to subtract 1 from offset + size to | |
227 * determine the end address. | |
228 */ | |
229 rom_entries[romimages].end = fmap->areas[i].offset + | |
230 fmap->areas[i].size; | |
231 if (fmap->areas[i].size) | |
232 rom_entries[romimages].end--; | |
233 | |
234 memset(rom_entries[romimages].name, 0, | |
235 sizeof(rom_entries[romimages].name)); | |
236 memcpy(rom_entries[romimages].name, fmap->areas[i].name, | |
237 min(sizeof(rom_entries[romimages].name), | |
238 sizeof(fmap->areas[i].name))); | |
239 | |
240 rom_entries[romimages].included = 0; | |
241 strcpy(rom_entries[romimages].file, ""); | |
242 | |
243 msg_gdbg("added fmap region \"%s\" (file=\"%s\") as %sincluded," | |
244 " offset: 0x%08x, size: 0x%08x\n", | |
245 rom_entries[romimages].name, | |
246 rom_entries[romimages].file, | |
247 rom_entries[romimages].included ? "" : "not ", | |
248 rom_entries[romimages].start, | |
249 rom_entries[romimages].end); | |
250 romimages++; | |
251 } | |
252 | |
253 return fmap->nareas; | |
254 } | |
255 | |
204 /* register an include argument (-i) for later processing */ | 256 /* register an include argument (-i) for later processing */ |
205 int register_include_arg(char *name) | 257 int register_include_arg(char *name) |
206 { | 258 { |
207 static int i = 0; | 259 static int i = 0; |
208 | 260 |
209 if (i >= MAX_ROMLAYOUT) { | 261 if (i >= MAX_ROMLAYOUT) { |
210 msg_gerr("too many regions included\n"); | 262 msg_gerr("too many regions included\n"); |
211 return -1; | 263 return -1; |
212 } | 264 } |
213 | 265 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
322 } | 374 } |
323 return 0; | 375 return 0; |
324 } | 376 } |
325 | 377 |
326 int handle_romentries(struct flashchip *flash, uint8_t *oldcontents, uint8_t *ne wcontents) | 378 int handle_romentries(struct flashchip *flash, uint8_t *oldcontents, uint8_t *ne wcontents) |
327 { | 379 { |
328 unsigned int start = 0; | 380 unsigned int start = 0; |
329 int entry; | 381 int entry; |
330 unsigned int size = flash->total_size * 1024; | 382 unsigned int size = flash->total_size * 1024; |
331 | 383 |
384 /* add entries for non-readonly regions specified in flashmap */ | |
Louis
2011/03/04 23:33:16
Oooops. I guess you forgot to remove this comment.
dhendrix
2011/03/05 00:25:30
Fixed (note: this call and the updated comment are
| |
385 add_fmap_entries(oldcontents, size); | |
386 | |
332 /* If no layout file was specified or the layout file was empty, assume | 387 /* If no layout file was specified or the layout file was empty, assume |
333 * that the user wants to flash the complete new image. | 388 * that the user wants to flash the complete new image. |
334 */ | 389 */ |
335 if (!romimages) | 390 if (!romimages) |
336 return 0; | 391 return 0; |
337 | 392 |
338 /* Non-included romentries are ignored. | 393 /* Non-included romentries are ignored. |
339 * The union of all included romentries is used from the new image. | 394 * The union of all included romentries is used from the new image. |
340 */ | 395 */ |
341 while (start < size) { | 396 while (start < size) { |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
427 | 482 |
428 /* Skip to location after current romentry. */ | 483 /* Skip to location after current romentry. */ |
429 start = rom_entries[entry].end + 1; | 484 start = rom_entries[entry].end + 1; |
430 /* Catch overflow. */ | 485 /* Catch overflow. */ |
431 if (!start) | 486 if (!start) |
432 break; | 487 break; |
433 } | 488 } |
434 | 489 |
435 return count; | 490 return count; |
436 } | 491 } |
OLD | NEW |