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 */ | |
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 fmap_offset = fmap_find(image, size); | |
Louis
2010/12/30 02:57:08
hm... shall we check the return value for fmap_fin
dhendrix
2010/12/31 00:47:02
Yes, definitely! I had only tested using BIOSes wi
| |
198 fmap = (struct fmap *)(image + fmap_offset);; | |
199 | |
200 for (i = 0; i < fmap->nareas; i++) { | |
201 rom_entries[romimages].start = fmap->areas[i].offset; | |
202 rom_entries[romimages].end = fmap->areas[i].offset + | |
203 fmap->areas[i].size; | |
Louis
2010/12/30 02:57:08
should be .offset + .size "- 1" since .end is the
dhendrix
2010/12/31 00:47:02
yes
| |
204 if (fmap->areas[i].flags & FMAP_AREA_RO) | |
Louis
2010/12/30 02:57:08
hm... does this imply we CANNOT update the whole i
dhendrix
2010/12/31 00:47:02
Correct. Using this approach, the way to override
Louis
2010/12/31 09:13:30
This changes the behavior too much and becomes mor
dhendrix
2011/03/04 00:06:17
Agreed.
| |
205 rom_entries[romimages].included = 0; | |
206 else | |
207 rom_entries[romimages].included = 1; | |
208 romimages++; | |
Louis
2010/12/30 02:57:08
Shall we check the romimages if bigger than size o
dhendrix
2010/12/31 00:47:02
Yes. I added a check near the top of this loop.
b
| |
209 } | |
210 | |
211 return fmap->nareas; | |
212 } | |
213 | |
214 | |
188 int find_romentry(char *name) | 215 int find_romentry(char *name) |
189 { | 216 { |
190 int i; | 217 int i; |
191 | 218 |
192 if (!romimages) | 219 if (!romimages) |
193 return -1; | 220 return -1; |
194 | 221 |
195 msg_gdbg("Looking for \"%s\"... ", name); | 222 msg_gdbg("Looking for \"%s\"... ", name); |
196 | 223 |
197 for (i = 0; i < romimages; i++) { | 224 for (i = 0; i < romimages; i++) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
230 } | 257 } |
231 return best_entry; | 258 return best_entry; |
232 } | 259 } |
233 | 260 |
234 int handle_romentries(struct flashchip *flash, uint8_t *oldcontents, uint8_t *ne wcontents) | 261 int handle_romentries(struct flashchip *flash, uint8_t *oldcontents, uint8_t *ne wcontents) |
235 { | 262 { |
236 unsigned int start = 0; | 263 unsigned int start = 0; |
237 int entry; | 264 int entry; |
238 unsigned int size = flash->total_size * 1024; | 265 unsigned int size = flash->total_size * 1024; |
239 | 266 |
267 /* add entries for non-readonly regions specified in flashmap */ | |
268 add_fmap_entries(oldcontents, size); | |
269 | |
240 /* If no layout file was specified or the layout file was empty, assume | 270 /* If no layout file was specified or the layout file was empty, assume |
241 * that the user wants to flash the complete new image. | 271 * that the user wants to flash the complete new image. |
242 */ | 272 */ |
243 if (!romimages) | 273 if (!romimages) |
244 return 0; | 274 return 0; |
245 /* Non-included romentries are ignored. | 275 /* Non-included romentries are ignored. |
246 * The union of all included romentries is used from the new image. | 276 * The union of all included romentries is used from the new image. |
247 */ | 277 */ |
248 while (start < size) { | 278 while (start < size) { |
249 entry = find_next_included_romentry(start); | 279 entry = find_next_included_romentry(start); |
250 /* No more romentries for remaining region? */ | 280 /* No more romentries for remaining region? */ |
251 if (entry < 0) { | 281 if (entry < 0) { |
252 memcpy(newcontents + start, oldcontents + start, | 282 memcpy(newcontents + start, oldcontents + start, |
253 size - start); | 283 size - start); |
254 break; | 284 break; |
255 } | 285 } |
256 if (rom_entries[entry].start > start) | 286 if (rom_entries[entry].start > start) |
257 memcpy(newcontents + start, oldcontents + start, | 287 memcpy(newcontents + start, oldcontents + start, |
258 rom_entries[entry].start - start); | 288 rom_entries[entry].start - start); |
259 /* Skip to location after current romentry. */ | 289 /* Skip to location after current romentry. */ |
260 start = rom_entries[entry].end + 1; | 290 start = rom_entries[entry].end + 1; |
261 /* Catch overflow. */ | 291 /* Catch overflow. */ |
262 if (!start) | 292 if (!start) |
263 break; | 293 break; |
264 } | 294 } |
265 | 295 |
266 return 0; | 296 return 0; |
267 } | 297 } |
OLD | NEW |