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; | |
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 msg_gdbg("%s: fmap_size: %d\n", __func__, fmap_size); | |
222 fmap = (struct fmap *)(buf); | |
223 } | |
224 | |
225 for (i = 0; i < fmap->nareas; i++) { | |
226 if (romimages >= MAX_ROMLAYOUT) { | |
227 msg_gerr("ROM image contains too many regions\n"); | |
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 | |
Louis
2011/03/05 01:05:01
buf must be freed.
dhendrix
2011/03/05 02:34:14
d'oh! good catch. I also added free(buf) before li
| |
261 return fmap->nareas; | |
262 } | |
263 | |
204 /* register an include argument (-i) for later processing */ | 264 /* register an include argument (-i) for later processing */ |
205 int register_include_arg(char *name) | 265 int register_include_arg(char *name) |
206 { | 266 { |
207 static int i = 0; | 267 static int i = 0; |
208 | 268 |
209 if (i >= MAX_ROMLAYOUT) { | 269 if (i >= MAX_ROMLAYOUT) { |
210 msg_gerr("too many regions included\n"); | 270 msg_gerr("too many regions included\n"); |
211 return -1; | 271 return -1; |
212 } | 272 } |
213 | 273 |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
427 | 487 |
428 /* Skip to location after current romentry. */ | 488 /* Skip to location after current romentry. */ |
429 start = rom_entries[entry].end + 1; | 489 start = rom_entries[entry].end + 1; |
430 /* Catch overflow. */ | 490 /* Catch overflow. */ |
431 if (!start) | 491 if (!start) |
432 break; | 492 break; |
433 } | 493 } |
434 | 494 |
435 return count; | 495 return count; |
436 } | 496 } |
OLD | NEW |