Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Side by Side Diff: layout.c

Issue 6025013: Add flashmap (fmap) support to Flashrom (Closed) Base URL: svn://coreboot.org/flashrom/trunk
Patch Set: %lx -> 0x%lx Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« fmap.c ('K') | « fmap.c ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 rom_entries[i].start, 188 rom_entries[i].start,
187 rom_entries[i].end, rom_entries[i].name); 189 rom_entries[i].end, rom_entries[i].name);
188 } 190 }
189 191
190 fclose(romlayout); 192 fclose(romlayout);
191 193
192 return 0; 194 return 0;
193 } 195 }
194 #endif 196 #endif
195 197
198 /* returns the number of entries added, or <0 to indicate error */
199 static int add_fmap_entries(uint8_t *image, int size)
200 {
201 int i;
202 struct fmap *fmap;
203 long int fmap_offset;
204
205 if ((fmap_offset = fmap_find(image, size)) < 0)
206 return 0;
207 fmap = (struct fmap *)(image + fmap_offset);;
208
209 for (i = 0; i < fmap->nareas; i++) {
210 if (romimages >= MAX_ROMLAYOUT) {
211 msg_gerr("ROM image contains too many regions\n");
212 return -1;
213 }
214 rom_entries[romimages].start = fmap->areas[i].offset;
215 rom_entries[romimages].end = fmap->areas[i].offset +
216 fmap->areas[i].size - 1;
217 memset(rom_entries[romimages].name, 0,
218 sizeof(rom_entries[romimages].name));
219 memcpy(rom_entries[romimages].name, fmap->areas[i].name,
220 min(sizeof(rom_entries[romimages].name),
221 sizeof(fmap->areas[i].name)));
222
223 rom_entries[romimages].included = 0;
224
225 msg_gdbg("%s(): added region \"%s\" as %sincluded, offset: 0x%08 x, size: 0x%08x\n",
Louis 2011/03/04 00:40:59 nit: exceeds 80 columns.
dhendrix 2011/03/04 08:04:46 good catch -- fixed.
226 __func__,
227 rom_entries[romimages].name,
228 rom_entries[romimages].included ? "" : "not ",
229 rom_entries[romimages].start,
230 rom_entries[romimages].end);
231 romimages++;
232 }
233
234 return fmap->nareas;
235 }
236
237
196 int find_romentry(char *name) 238 int find_romentry(char *name)
197 { 239 {
198 int i; 240 int i;
199 241
200 if (!romimages) 242 if (!romimages)
201 return -1; 243 return -1;
202 244
203 msg_gdbg("Looking for \"%s\"... ", name); 245 msg_gdbg("Looking for \"%s\"... ", name);
204 246
205 for (i = 0; i < romimages; i++) { 247 for (i = 0; i < romimages; i++) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 } 280 }
239 return best_entry; 281 return best_entry;
240 } 282 }
241 283
242 int handle_romentries(struct flashchip *flash, uint8_t *oldcontents, uint8_t *ne wcontents) 284 int handle_romentries(struct flashchip *flash, uint8_t *oldcontents, uint8_t *ne wcontents)
243 { 285 {
244 unsigned int start = 0; 286 unsigned int start = 0;
245 int entry; 287 int entry;
246 unsigned int size = flash->total_size * 1024; 288 unsigned int size = flash->total_size * 1024;
247 289
290 /* add entries for non-readonly regions specified in flashmap */
291 add_fmap_entries(oldcontents, size);
Louis 2011/03/04 00:40:59 I thought add_fmap_entries() should be called arou
dhendrix 2011/03/04 08:04:46 When responding to this comment, I realized that w
292
248 /* If no layout file was specified or the layout file was empty, assume 293 /* If no layout file was specified or the layout file was empty, assume
249 * that the user wants to flash the complete new image. 294 * that the user wants to flash the complete new image.
250 */ 295 */
251 if (!romimages) 296 if (!romimages)
252 return 0; 297 return 0;
253 /* Non-included romentries are ignored. 298 /* Non-included romentries are ignored.
254 * The union of all included romentries is used from the new image. 299 * The union of all included romentries is used from the new image.
255 */ 300 */
256 while (start < size) { 301 while (start < size) {
257 entry = find_next_included_romentry(start); 302 entry = find_next_included_romentry(start);
258 /* No more romentries for remaining region? */ 303 /* No more romentries for remaining region? */
259 if (entry < 0) { 304 if (entry < 0) {
260 memcpy(newcontents + start, oldcontents + start, 305 memcpy(newcontents + start, oldcontents + start,
261 size - start); 306 size - start);
262 break; 307 break;
263 } 308 }
264 if (rom_entries[entry].start > start) 309 if (rom_entries[entry].start > start)
265 memcpy(newcontents + start, oldcontents + start, 310 memcpy(newcontents + start, oldcontents + start,
266 rom_entries[entry].start - start); 311 rom_entries[entry].start - start);
267 /* Skip to location after current romentry. */ 312 /* Skip to location after current romentry. */
268 start = rom_entries[entry].end + 1; 313 start = rom_entries[entry].end + 1;
269 /* Catch overflow. */ 314 /* Catch overflow. */
270 if (!start) 315 if (!start)
271 break; 316 break;
272 } 317 }
273 318
274 return 0; 319 return 0;
275 } 320 }
OLDNEW
« fmap.c ('K') | « fmap.c ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698