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 |
(...skipping 157 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 int add_fmap_entries(struct flashchip *flash) |
| 208 { |
| 209 int i, fmap_size; |
| 210 uint8_t *buf = NULL; |
| 211 struct fmap *fmap; |
| 212 |
| 213 fmap_size = fmap_find(flash, &buf); |
| 214 if (fmap_size == 0) { |
| 215 msg_gdbg("%s: no fmap present\n", __func__); |
| 216 return 0; |
| 217 } else if (fmap_size < 0) { |
| 218 msg_gdbg("%s: error reading fmap\n", __func__); |
| 219 return -1; |
| 220 } else { |
| 221 fmap = (struct fmap *)(buf); |
| 222 } |
| 223 |
| 224 for (i = 0; i < fmap->nareas; i++) { |
| 225 if (romimages >= MAX_ROMLAYOUT) { |
| 226 msg_gerr("ROM image contains too many regions\n"); |
| 227 free(buf); |
| 228 return -1; |
| 229 } |
| 230 rom_entries[romimages].start = fmap->areas[i].offset; |
| 231 |
| 232 /* |
| 233 * Flashrom rom entries use absolute addresses. So for non-zero |
| 234 * length entries, we need to subtract 1 from offset + size to |
| 235 * determine the end address. |
| 236 */ |
| 237 rom_entries[romimages].end = fmap->areas[i].offset + |
| 238 fmap->areas[i].size; |
| 239 if (fmap->areas[i].size) |
| 240 rom_entries[romimages].end--; |
| 241 |
| 242 memset(rom_entries[romimages].name, 0, |
| 243 sizeof(rom_entries[romimages].name)); |
| 244 memcpy(rom_entries[romimages].name, fmap->areas[i].name, |
| 245 min(sizeof(rom_entries[romimages].name), |
| 246 sizeof(fmap->areas[i].name))); |
| 247 |
| 248 rom_entries[romimages].included = 0; |
| 249 strcpy(rom_entries[romimages].file, ""); |
| 250 |
| 251 msg_gdbg("added fmap region \"%s\" (file=\"%s\") as %sincluded," |
| 252 " offset: 0x%08x, size: 0x%08x\n", |
| 253 rom_entries[romimages].name, |
| 254 rom_entries[romimages].file, |
| 255 rom_entries[romimages].included ? "" : "not ", |
| 256 rom_entries[romimages].start, |
| 257 rom_entries[romimages].end); |
| 258 romimages++; |
| 259 } |
| 260 |
| 261 free(buf); |
| 262 return fmap->nareas; |
| 263 } |
| 264 |
204 /* register an include argument (-i) for later processing */ | 265 /* register an include argument (-i) for later processing */ |
205 int register_include_arg(char *name) | 266 int register_include_arg(char *name) |
206 { | 267 { |
207 static int i = 0; | 268 static int i = 0; |
208 | 269 |
209 if (i >= MAX_ROMLAYOUT) { | 270 if (i >= MAX_ROMLAYOUT) { |
210 msg_gerr("too many regions included\n"); | 271 msg_gerr("too many regions included\n"); |
211 return -1; | 272 return -1; |
212 } | 273 } |
213 | 274 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 } | 383 } |
323 return 0; | 384 return 0; |
324 } | 385 } |
325 | 386 |
326 int handle_romentries(struct flashchip *flash, uint8_t *oldcontents, uint8_t *ne
wcontents) | 387 int handle_romentries(struct flashchip *flash, uint8_t *oldcontents, uint8_t *ne
wcontents) |
327 { | 388 { |
328 unsigned int start = 0; | 389 unsigned int start = 0; |
329 int entry; | 390 int entry; |
330 unsigned int size = flash->total_size * 1024; | 391 unsigned int size = flash->total_size * 1024; |
331 | 392 |
332 » /* If no layout file was specified or the layout file was empty, assume | 393 » /* If no regions were specified for inclusion, assume |
333 » * that the user wants to flash the complete new image. | 394 » * that the user wants to write the complete new image. |
334 */ | 395 */ |
335 » if (!romimages) | 396 » if (!include_args[0]) |
336 return 0; | 397 return 0; |
337 | 398 |
338 /* Non-included romentries are ignored. | 399 /* Non-included romentries are ignored. |
339 * The union of all included romentries is used from the new image. | 400 * The union of all included romentries is used from the new image. |
340 */ | 401 */ |
341 while (start < size) { | 402 while (start < size) { |
342 | 403 |
343 entry = find_next_included_romentry(start); | 404 entry = find_next_included_romentry(start); |
344 /* No more romentries for remaining region? */ | 405 /* No more romentries for remaining region? */ |
345 if (entry < 0) { | 406 if (entry < 0) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 int handle_partial_read( | 451 int handle_partial_read( |
391 struct flashchip *flash, | 452 struct flashchip *flash, |
392 uint8_t *buf, | 453 uint8_t *buf, |
393 int (*read) (struct flashchip *flash, uint8_t *buf, int start, int len)) { | 454 int (*read) (struct flashchip *flash, uint8_t *buf, int start, int len)) { |
394 | 455 |
395 unsigned int start = 0; | 456 unsigned int start = 0; |
396 int entry; | 457 int entry; |
397 unsigned int size = flash->total_size * 1024; | 458 unsigned int size = flash->total_size * 1024; |
398 int count = 0; | 459 int count = 0; |
399 | 460 |
400 » /* If no layout file was specified or the layout file was empty, assume | 461 » /* If no regions were specified for inclusion, assume |
401 » * that the user wants to flash the complete new image. | 462 » * that the user wants to read the complete image. |
402 */ | 463 */ |
403 » if (!romimages) | 464 » if (!include_args[0]) |
404 return 0; | 465 return 0; |
405 | 466 |
406 /* Walk through the table and write content to file for those included | 467 /* Walk through the table and write content to file for those included |
407 * partition. */ | 468 * partition. */ |
408 while (start < size) { | 469 while (start < size) { |
409 int len; | 470 int len; |
410 | 471 |
411 entry = find_next_included_romentry(start); | 472 entry = find_next_included_romentry(start); |
412 /* No more romentries for remaining region? */ | 473 /* No more romentries for remaining region? */ |
413 if (entry < 0) { | 474 if (entry < 0) { |
(...skipping 13 matching lines...) Expand all Loading... |
427 | 488 |
428 /* Skip to location after current romentry. */ | 489 /* Skip to location after current romentry. */ |
429 start = rom_entries[entry].end + 1; | 490 start = rom_entries[entry].end + 1; |
430 /* Catch overflow. */ | 491 /* Catch overflow. */ |
431 if (!start) | 492 if (!start) |
432 break; | 493 break; |
433 } | 494 } |
434 | 495 |
435 return count; | 496 return count; |
436 } | 497 } |
OLD | NEW |