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)
49 walk = (unsigned int *)(bios + size - 0x10);
52 if ((*walk) == 0 || ((*walk) & 0x3ff) != 0) {
53 /* We might have an NVIDIA chipset BIOS which stores the ID
54 * information at a different location.
56 walk = (unsigned int *)(bios + size - 0x80);
61 * Check if coreboot last image size is 0 or not a multiple of 1k or
62 * bigger than the chip or if the pointers to vendor ID or mainboard ID
63 * are outside the image of if the start of ID strings are nonsensical
64 * (nonprintable and not \0).
66 if ((*walk) == 0 || ((*walk) & 0x3ff) != 0 || *walk > size ||
67 *(walk - 1) > size || *(walk - 2) > size ||
68 (!isprint((const char *)(bios + size - *(walk - 1))) &&
69 ((const char *)(bios + size - *(walk - 1)))) ||
70 (!isprint((const char *)(bios + size - *(walk - 2))) &&
71 ((const char *)(bios + size - *(walk - 2))))) {
72 printf("Flash image seems to be a legacy BIOS. Disabling checks.\n");
73 mainboard_vendor = def_name;
74 mainboard_part = def_name;
78 printf_debug("coreboot last image size "
79 "(not ROM size) is %d bytes.\n", *walk);
82 mainboard_part = strdup((const char *)(bios + size - *walk));
84 mainboard_vendor = strdup((const char *)(bios + size - *walk));
85 printf_debug("Manufacturer: %s\n", mainboard_vendor);
86 printf_debug("Mainboard ID: %s\n", mainboard_part);
89 * If lb_vendor is not set, the coreboot table was
90 * not found. Nor was -m VENDOR:PART specified.
92 if (!lb_vendor || !lb_part) {
93 printf("Note: If the following flash access fails, "
94 "try -m <vendor>:<mainboard>.\n");
98 /* These comparisons are case insensitive to make things
99 * a little less user^Werror prone.
101 if (!strcasecmp(mainboard_vendor, lb_vendor) &&
102 !strcasecmp(mainboard_part, lb_part)) {
103 printf_debug("This firmware image matches "
104 "this motherboard.\n");
107 printf("WARNING: This firmware image does not "
108 "seem to fit to this machine - forcing it.\n");
110 printf("ERROR: Your firmware image (%s:%s) does not "
111 "appear to\n be correct for the detected "
112 "mainboard (%s:%s)\n\nOverride with --force if you "
113 "are absolutely sure that you\nare using a correct "
114 "image for this mainboard or override\nthe detected "
115 "values with --mainboard <vendor>:<mainboard>.\n\n",
116 mainboard_vendor, mainboard_part, lb_vendor,
125 int read_romlayout(char *name)
131 romlayout = fopen(name, "r");
134 fprintf(stderr, "ERROR: Could not open ROM layout (%s).\n",
139 while (!feof(romlayout)) {
141 fscanf(romlayout, "%s %s\n", tempstr,
142 rom_entries[romimages].name);
144 // fscanf does not like arbitrary comments like that :( later
145 if (tempstr[0] == '#') {
149 tstr1 = strtok(tempstr, ":");
150 tstr2 = strtok(NULL, ":");
151 rom_entries[romimages].start = strtol(tstr1, (char **)NULL, 16);
152 rom_entries[romimages].end = strtol(tstr2, (char **)NULL, 16);
153 rom_entries[romimages].included = 0;
157 for (i = 0; i < romimages; i++) {
158 printf_debug("romlayout %08x - %08x named %s\n",
159 rom_entries[i].start,
160 rom_entries[i].end, rom_entries[i].name);
168 int find_romentry(char *name)
175 printf("Looking for \"%s\"... ", name);
177 for (i = 0; i < romimages; i++) {
178 if (!strcmp(rom_entries[i].name, name)) {
179 rom_entries[i].included = 1;
184 printf("not found.\n"); // Not found. Error.
189 int handle_romentries(uint8_t *buffer, uint8_t *content)
193 // This function does not safe flash write cycles.
195 // Also it does not cope with overlapping rom layout
198 // 00000000:00008fff gfxrom
199 // 00009000:0003ffff normal
200 // 00040000:0007ffff fallback
201 // 00000000:0007ffff all
203 // If you'd specify -i all the included flag of all other
204 // sections is still 0, so no changes will be made to the
205 // flash. Same thing if you specify -i normal -i all only
206 // normal will be updated and the rest will be kept.
208 for (i = 0; i < romimages; i++) {
210 if (rom_entries[i].included)
213 memcpy(buffer + rom_entries[i].start,
214 content + rom_entries[i].start,
215 rom_entries[i].end - rom_entries[i].start);