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 32 | 37 #define MAX_ROMLAYOUT 32 |
36 | 38 |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
178 rom_entries[i].start, | 180 rom_entries[i].start, |
179 rom_entries[i].end, rom_entries[i].name); | 181 rom_entries[i].end, rom_entries[i].name); |
180 } | 182 } |
181 | 183 |
182 fclose(romlayout); | 184 fclose(romlayout); |
183 | 185 |
184 return 0; | 186 return 0; |
185 } | 187 } |
186 #endif | 188 #endif |
187 | 189 |
190 /* returns the number of entries added, or <0 to indicate error */ | |
191 static int add_fmap_entries(uint8_t *image, int size) | |
192 { | |
193 int i; | |
194 struct fmap *fmap; | |
195 long int fmap_offset; | |
196 | |
197 if ((fmap_offset = fmap_find(image, size)) < 0) | |
198 return 0; | |
199 fmap = (struct fmap *)(image + fmap_offset);; | |
200 | |
201 for (i = 0; i < fmap->nareas; i++) { | |
202 if (romimages >= MAX_ROMLAYOUT) { | |
203 msg_gerr("ROM image contains too many regions\n"); | |
204 return -1; | |
205 } | |
206 rom_entries[romimages].start = fmap->areas[i].offset; | |
207 rom_entries[romimages].end = fmap->areas[i].offset + | |
208 fmap->areas[i].size - 1; | |
209 memcpy(rom_entries[romimages].name, fmap->areas[i].name, | |
Louis
2010/12/31 09:13:30
remember do this before copy:
memset(rom_entries[r
dhendrix
2011/03/04 00:06:17
Done.
| |
210 min(sizeof(rom_entries[romimages].name), | |
211 sizeof(fmap->areas[i].name))); | |
212 | |
213 if (fmap->areas[i].flags & FMAP_AREA_RO) | |
214 rom_entries[romimages].included = 0; | |
215 else | |
216 rom_entries[romimages].included = 1; | |
217 #if 0 | |
218 rom_entries[romimages].included = 0; | |
219 #endif | |
220 | |
221 msg_gdbg("%s(): added region \"%s\" as %sincluded, offset: 0x%08 x, size: 0x%08x\n", | |
222 __func__, | |
223 rom_entries[romimages].name, | |
224 rom_entries[romimages].included ? "" : "not ", | |
225 rom_entries[romimages].start, | |
226 rom_entries[romimages].end); | |
227 romimages++; | |
228 } | |
229 | |
230 return fmap->nareas; | |
231 } | |
232 | |
233 | |
188 int find_romentry(char *name) | 234 int find_romentry(char *name) |
189 { | 235 { |
190 int i; | 236 int i; |
191 | 237 |
192 if (!romimages) | 238 if (!romimages) |
193 return -1; | 239 return -1; |
194 | 240 |
195 msg_gdbg("Looking for \"%s\"... ", name); | 241 msg_gdbg("Looking for \"%s\"... ", name); |
196 | 242 |
197 for (i = 0; i < romimages; i++) { | 243 for (i = 0; i < romimages; i++) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
230 } | 276 } |
231 return best_entry; | 277 return best_entry; |
232 } | 278 } |
233 | 279 |
234 int handle_romentries(struct flashchip *flash, uint8_t *oldcontents, uint8_t *ne wcontents) | 280 int handle_romentries(struct flashchip *flash, uint8_t *oldcontents, uint8_t *ne wcontents) |
235 { | 281 { |
236 unsigned int start = 0; | 282 unsigned int start = 0; |
237 int entry; | 283 int entry; |
238 unsigned int size = flash->total_size * 1024; | 284 unsigned int size = flash->total_size * 1024; |
239 | 285 |
286 /* add entries for non-readonly regions specified in flashmap */ | |
287 add_fmap_entries(oldcontents, size); | |
288 | |
240 /* If no layout file was specified or the layout file was empty, assume | 289 /* If no layout file was specified or the layout file was empty, assume |
241 * that the user wants to flash the complete new image. | 290 * that the user wants to flash the complete new image. |
242 */ | 291 */ |
243 if (!romimages) | 292 if (!romimages) |
244 return 0; | 293 return 0; |
245 /* Non-included romentries are ignored. | 294 /* Non-included romentries are ignored. |
246 * The union of all included romentries is used from the new image. | 295 * The union of all included romentries is used from the new image. |
247 */ | 296 */ |
248 while (start < size) { | 297 while (start < size) { |
249 entry = find_next_included_romentry(start); | 298 entry = find_next_included_romentry(start); |
250 /* No more romentries for remaining region? */ | 299 /* No more romentries for remaining region? */ |
251 if (entry < 0) { | 300 if (entry < 0) { |
252 memcpy(newcontents + start, oldcontents + start, | 301 memcpy(newcontents + start, oldcontents + start, |
253 size - start); | 302 size - start); |
254 break; | 303 break; |
255 } | 304 } |
256 if (rom_entries[entry].start > start) | 305 if (rom_entries[entry].start > start) |
257 memcpy(newcontents + start, oldcontents + start, | 306 memcpy(newcontents + start, oldcontents + start, |
258 rom_entries[entry].start - start); | 307 rom_entries[entry].start - start); |
259 /* Skip to location after current romentry. */ | 308 /* Skip to location after current romentry. */ |
260 start = rom_entries[entry].end + 1; | 309 start = rom_entries[entry].end + 1; |
261 /* Catch overflow. */ | 310 /* Catch overflow. */ |
262 if (!start) | 311 if (!start) |
263 break; | 312 break; |
264 } | 313 } |
265 | 314 |
266 return 0; | 315 return 0; |
267 } | 316 } |
OLD | NEW |