Chromium Code Reviews| 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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 188 rom_entries[i].start, | 190 rom_entries[i].start, |
| 189 rom_entries[i].end, rom_entries[i].name); | 191 rom_entries[i].end, rom_entries[i].name); |
| 190 } | 192 } |
| 191 | 193 |
| 192 fclose(romlayout); | 194 fclose(romlayout); |
| 193 | 195 |
| 194 return 0; | 196 return 0; |
| 195 } | 197 } |
| 196 #endif | 198 #endif |
| 197 | 199 |
| 200 /* returns the number of entries added, or <0 to indicate error */ | |
| 201 static int add_fmap_entries(uint8_t *image, int size) | |
| 202 { | |
| 203 int i; | |
| 204 struct fmap *fmap; | |
| 205 long int fmap_offset; | |
| 206 | |
| 207 if ((fmap_offset = fmap_find(image, size)) < 0) | |
| 208 return 0; | |
| 209 fmap = (struct fmap *)(image + fmap_offset);; | |
| 210 | |
| 211 for (i = 0; i < fmap->nareas; i++) { | |
| 212 if (romimages >= MAX_ROMLAYOUT) { | |
| 213 msg_gerr("ROM image contains too many regions\n"); | |
| 214 return -1; | |
| 215 } | |
| 216 rom_entries[romimages].start = fmap->areas[i].offset; | |
| 217 | |
| 218 /* | |
| 219 * Flashrom rom entries use absolute addresses. So for non-zero | |
| 220 * length entries, we need to subtract 1 from offset + size to | |
| 221 * determine the end address. | |
| 222 */ | |
| 223 rom_entries[romimages].end = fmap->areas[i].offset + | |
| 224 fmap->areas[i].size; | |
| 225 if (fmap->areas[i].size) | |
| 226 rom_entries[romimages].end--; | |
| 227 | |
| 228 memset(rom_entries[romimages].name, 0, | |
| 229 sizeof(rom_entries[romimages].name)); | |
| 230 memcpy(rom_entries[romimages].name, fmap->areas[i].name, | |
| 231 min(sizeof(rom_entries[romimages].name), | |
| 232 sizeof(fmap->areas[i].name))); | |
| 233 | |
| 234 rom_entries[romimages].included = 0; | |
| 235 | |
|
Louis
2011/03/04 11:01:13
strcpy(rom_entries[romimages].file, "");
dhendrix
2011/03/04 21:46:33
Done.
| |
| 236 msg_gdbg("%s(): added region \"%s\" as %sincluded, offset: 0x%08 x, " | |
|
Louis
2011/03/04 11:01:13
nit:
exceed 80 columns.
dhendrix
2011/03/04 21:46:33
fixed. thanks for catching that.
| |
| 237 "size: 0x%08x\n", __func__, | |
| 238 rom_entries[romimages].name, | |
|
Louis
2011/03/04 11:01:13
add [].file?
dhendrix
2011/03/04 21:46:33
Done.
I also updated this debug string to omit th
| |
| 239 rom_entries[romimages].included ? "" : "not ", | |
| 240 rom_entries[romimages].start, | |
| 241 rom_entries[romimages].end); | |
| 242 romimages++; | |
| 243 } | |
| 244 | |
| 245 return fmap->nareas; | |
| 246 } | |
| 247 | |
| 248 | |
| 198 int find_romentry(char *name) | 249 int find_romentry(char *name) |
| 199 { | 250 { |
| 200 int i; | 251 int i; |
| 201 char *file = NULL; | 252 char *file = NULL; |
| 202 | 253 |
| 203 if (!romimages) | 254 if (!romimages) |
| 204 return -1; | 255 return -1; |
| 205 | 256 |
| 206 /* -i <image>[:<file>] */ | 257 /* -i <image>[:<file>] */ |
| 207 if (strtok(name, ":")) { | 258 if (strtok(name, ":")) { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 275 } | 326 } |
| 276 return 0; | 327 return 0; |
| 277 } | 328 } |
| 278 | 329 |
| 279 int handle_romentries(struct flashchip *flash, uint8_t *oldcontents, uint8_t *ne wcontents) | 330 int handle_romentries(struct flashchip *flash, uint8_t *oldcontents, uint8_t *ne wcontents) |
| 280 { | 331 { |
| 281 unsigned int start = 0; | 332 unsigned int start = 0; |
| 282 int entry; | 333 int entry; |
| 283 unsigned int size = flash->total_size * 1024; | 334 unsigned int size = flash->total_size * 1024; |
| 284 | 335 |
| 336 /* add entries for non-readonly regions specified in flashmap */ | |
|
Louis
2011/03/04 11:01:13
Why do we limit to "non-readonly" regions?
dhendrix
2011/03/04 21:46:33
I believe that is an obsolete comment, so I have r
| |
| 337 add_fmap_entries(oldcontents, size); | |
| 338 | |
| 285 /* If no layout file was specified or the layout file was empty, assume | 339 /* If no layout file was specified or the layout file was empty, assume |
| 286 * that the user wants to flash the complete new image. | 340 * that the user wants to flash the complete new image. |
| 287 */ | 341 */ |
| 288 if (!romimages) | 342 if (!romimages) |
| 289 return 0; | 343 return 0; |
| 290 /* Non-included romentries are ignored. | 344 /* Non-included romentries are ignored. |
| 291 * The union of all included romentries is used from the new image. | 345 * The union of all included romentries is used from the new image. |
| 292 */ | 346 */ |
| 293 while (start < size) { | 347 while (start < size) { |
| 294 | 348 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 343 struct flashchip *flash, | 397 struct flashchip *flash, |
| 344 uint8_t *buf, | 398 uint8_t *buf, |
| 345 int (*read) (struct flashchip *flash, uint8_t *buf, int start, int len)) { | 399 int (*read) (struct flashchip *flash, uint8_t *buf, int start, int len)) { |
| 346 | 400 |
| 347 unsigned int start = 0; | 401 unsigned int start = 0; |
| 348 int entry; | 402 int entry; |
| 349 unsigned int size = flash->total_size * 1024; | 403 unsigned int size = flash->total_size * 1024; |
| 350 int count = 0; | 404 int count = 0; |
| 351 | 405 |
| 352 /* If no layout file was specified or the layout file was empty, assume | 406 /* If no layout file was specified or the layout file was empty, assume |
| 353 * that the user wants to flash the complete new image. | 407 * that the user wants to flash the complete new image. |
|
Louis
2011/03/04 11:01:13
This is my bad. I forgot to refine this comment. C
dhendrix
2011/03/04 21:46:33
Heh, I also noticed that this comment needs to be
| |
| 354 */ | 408 */ |
| 355 if (!romimages) | 409 if (!romimages) |
| 356 return 0; | 410 return 0; |
| 357 /* Walk through the table and write content to file for those included | 411 /* Walk through the table and write content to file for those included |
| 358 * partition. */ | 412 * partition. */ |
| 359 while (start < size) { | 413 while (start < size) { |
| 360 int len; | 414 int len; |
| 361 | 415 |
| 362 entry = find_next_included_romentry(start); | 416 entry = find_next_included_romentry(start); |
| 363 /* No more romentries for remaining region? */ | 417 /* No more romentries for remaining region? */ |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 378 | 432 |
| 379 /* Skip to location after current romentry. */ | 433 /* Skip to location after current romentry. */ |
| 380 start = rom_entries[entry].end + 1; | 434 start = rom_entries[entry].end + 1; |
| 381 /* Catch overflow. */ | 435 /* Catch overflow. */ |
| 382 if (!start) | 436 if (!start) |
| 383 break; | 437 break; |
| 384 } | 438 } |
| 385 | 439 |
| 386 return count; | 440 return count; |
| 387 } | 441 } |
| OLD | NEW |