2 * This file is part of the flashrom project.
4 * Copyright (C) 2005-2008 coresystems GmbH
5 * (Written by Stefan Reinauer <stepan@coresystems.de> for coresystems GmbH)
7 * 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 * the Free Software Foundation; version 2 of the License.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * 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 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 char *mainboard_vendor = NULL;
29 char *mainboard_part = NULL;
32 #define MAX_ROMLAYOUT 16
37 unsigned int included;
41 romlayout_t rom_entries[MAX_ROMLAYOUT];
43 static char *def_name = "DEFAULT";
45 int show_id(uint8_t *bios, int size, int force)
48 unsigned int mb_part_offset, mb_vendor_offset;
49 char *mb_part, *mb_vendor;
51 mainboard_vendor = def_name;
52 mainboard_part = def_name;
54 walk = (unsigned int *)(bios + size - 0x10);
57 if ((*walk) == 0 || ((*walk) & 0x3ff) != 0) {
58 /* We might have an NVIDIA chipset BIOS which stores the ID
59 * information at a different location.
61 walk = (unsigned int *)(bios + size - 0x80);
66 * Check if coreboot last image size is 0 or not a multiple of 1k or
67 * bigger than the chip or if the pointers to vendor ID or mainboard ID
68 * are outside the image of if the start of ID strings are nonsensical
69 * (nonprintable and not \0).
71 mb_part_offset = *(walk - 1);
72 mb_vendor_offset = *(walk - 2);
73 if ((*walk) == 0 || ((*walk) & 0x3ff) != 0 || (*walk) > size ||
74 mb_part_offset > size || mb_vendor_offset > size) {
75 printf("Flash image seems to be a legacy BIOS. Disabling checks.\n");
79 mb_part = (char *)(bios + size - mb_part_offset);
80 mb_vendor = (char *)(bios + size - mb_vendor_offset);
81 if (!isprint((unsigned char)*mb_part) ||
82 !isprint((unsigned char)*mb_vendor)) {
83 printf("Flash image seems to have garbage in the ID location."
84 " Disabling checks.\n");
88 printf_debug("coreboot last image size "
89 "(not ROM size) is %d bytes.\n", *walk);
91 mainboard_part = strdup(mb_part);
92 mainboard_vendor = strdup(mb_vendor);
93 printf_debug("Manufacturer: %s\n", mainboard_vendor);
94 printf_debug("Mainboard ID: %s\n", mainboard_part);
97 * If lb_vendor is not set, the coreboot table was
98 * not found. Nor was -m VENDOR:PART specified.
100 if (!lb_vendor || !lb_part) {
101 printf("Note: If the following flash access fails, "
102 "try -m <vendor>:<mainboard>.\n");
106 /* These comparisons are case insensitive to make things
107 * a little less user^Werror prone.
109 if (!strcasecmp(mainboard_vendor, lb_vendor) &&
110 !strcasecmp(mainboard_part, lb_part)) {
111 printf_debug("This firmware image matches "
112 "this motherboard.\n");
115 printf("WARNING: This firmware image does not "
116 "seem to fit to this machine - forcing it.\n");
118 printf("ERROR: Your firmware image (%s:%s) does not "
119 "appear to\n be correct for the detected "
120 "mainboard (%s:%s)\n\nOverride with --force if you "
121 "are absolutely sure that you\nare using a correct "
122 "image for this mainboard or override\nthe detected "
123 "values with --mainboard <vendor>:<mainboard>.\n\n",
124 mainboard_vendor, mainboard_part, lb_vendor,
133 int read_romlayout(char *name)
139 romlayout = fopen(name, "r");
142 fprintf(stderr, "ERROR: Could not open ROM layout (%s).\n",
147 while (!feof(romlayout)) {
149 fscanf(romlayout, "%s %s\n", tempstr,
150 rom_entries[romimages].name);
152 // fscanf does not like arbitrary comments like that :( later
153 if (tempstr[0] == '#') {
157 tstr1 = strtok(tempstr, ":");
158 tstr2 = strtok(NULL, ":");
159 rom_entries[romimages].start = strtol(tstr1, (char **)NULL, 16);
160 rom_entries[romimages].end = strtol(tstr2, (char **)NULL, 16);
161 rom_entries[romimages].included = 0;
165 for (i = 0; i < romimages; i++) {
166 printf_debug("romlayout %08x - %08x named %s\n",
167 rom_entries[i].start,
168 rom_entries[i].end, rom_entries[i].name);
176 int find_romentry(char *name)
183 printf("Looking for \"%s\"... ", name);
185 for (i = 0; i < romimages; i++) {
186 if (!strcmp(rom_entries[i].name, name)) {
187 rom_entries[i].included = 1;
192 printf("not found.\n"); // Not found. Error.
197 int handle_romentries(uint8_t *buffer, uint8_t *content)
201 // This function does not safe flash write cycles.
203 // Also it does not cope with overlapping rom layout
206 // 00000000:00008fff gfxrom
207 // 00009000:0003ffff normal
208 // 00040000:0007ffff fallback
209 // 00000000:0007ffff all
211 // If you'd specify -i all the included flag of all other
212 // sections is still 0, so no changes will be made to the
213 // flash. Same thing if you specify -i normal -i all only
214 // normal will be updated and the rest will be kept.
216 for (i = 0; i < romimages; i++) {
218 if (rom_entries[i].included)
221 memcpy(buffer + rom_entries[i].start,
222 content + rom_entries[i].start,
223 rom_entries[i].end - rom_entries[i].start);