aboutsummaryrefslogtreecommitdiffstats
path: root/layout.c
blob: 46fcc431c0df570e193a3d7d007878befcde420f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
pre { line-height: 125%; margin: 0; }
td.linenos pre { color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px; }
span.linenos { color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px; }
td.linenos pre.special { color: #000000; background-color: #ffffc0; padding: 0 5px 0 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding: 0 5px 0 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight { background: #ffffff; }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color:
/*
 * This file is part of the flashrom project.
 *
 * Copyright (C) 2005-2008 coresyst
terms of the GNU General Public License as published by * the Free Software Foundation; version 2 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdint.h> #include "flash.h" char *mainboard_vendor = NULL; char *mainboard_part = NULL; int romimages = 0; extern int force; #define MAX_ROMLAYOUT 16 typedef struct { unsigned int start; unsigned int end; unsigned int included; char name[256]; } romlayout_t; romlayout_t rom_entries[MAX_ROMLAYOUT]; static char *def_name = "DEFAULT"; int show_id(uint8_t *bios, int size) { unsigned int *walk; walk = (unsigned int *)(bios + size - 0x10); walk--; if ((*walk) == 0 || ((*walk) & 0x3ff) != 0) { /* We might have an Nvidia chipset bios * which stores the id information at a * different location. */ walk = (unsigned int *)(bios + size - 0x80); walk--; } if ((*walk) == 0 || ((*walk) & 0x3ff) != 0) { printf("Flash image seems to be a legacy BIOS. Disabling checks.\n"); mainboard_vendor = def_name; mainboard_part = def_name; return 0; } printf_debug("coreboot last image size " "(not ROM size) is %d bytes.\n", *walk); walk--; mainboard_part = strdup((const char *)(bios + size - *walk)); walk--; mainboard_vendor = strdup((const char *)(bios + size - *walk)); printf_debug("Manufacturer: %s\n", mainboard_vendor); printf_debug("Mainboard ID: %s\n", mainboard_part); /* * If lb_vendor is not set, the coreboot table was * not found. Nor was -mVENDOR:PART specified */ if (!lb_vendor || !lb_part) { printf("Note: If the following flash access fails, " "you might need to specify -m <vendor>:<mainboard>.\n"); return 0; } /* These comparisons are case insensitive to make things * a little less user^Werror prone. */ if (!strcasecmp(mainboard_vendor, lb_vendor) && !strcasecmp(mainboard_part, lb_part)) { printf_debug("This firmware image matches " "this motherboard.\n"); } else { if (force) { printf("WARNING: This firmware image does not " "seem to fit to this machine - forcing it.\n"); } else { printf("ERROR: Your firmware image (%s:%s) does not " "appear to\n be correct for the detected " "mainboard (%s:%s)\n\nOverride with --force if you " "are absolutely sure that you\nare using a correct " "image for this mainboard or override\nthe detected " "values with --mainboard <vendor>:<mainboard>.\n\n", mainboard_vendor, mainboard_part, lb_vendor, lb_part); exit(1); } } return 0; } int read_romlayout(char *name) { FILE *romlayout; char tempstr[256]; int i; romlayout = fopen(name, "r"); if (!romlayout) { fprintf(stderr, "ERROR: Could not open ROM layout (%s).\n", name); return -1; } while (!feof(romlayout)) { char *tstr1, *tstr2; fscanf(romlayout, "%s %s\n", tempstr, rom_entries[romimages].name); #if 0 // fscanf does not like arbitrary comments like that :( later if (tempstr[0] == '#') { continue; } #endif tstr1 = strtok(tempstr, ":"); tstr2 = strtok(NULL, ":"); rom_entries[romimages].start = strtol(tstr1, (char **)NULL, 16); rom_entries[romimages].end = strtol(tstr2, (char **)NULL, 16); rom_entries[romimages].included = 0; romimages++; } for (i = 0; i < romimages; i++) { printf_debug("romlayout %08x - %08x named %s\n", rom_entries[i].start, rom_entries[i].end, rom_entries[i].name); } fclose(romlayout); return 0; } int find_romentry(char *name) { int i; if (!romimages) return -1; printf("Looking for \"%s\"... ", name); for (i = 0; i < romimages; i++) { if (!strcmp(rom_entries[i].name, name)) { rom_entries[i].included = 1; printf("found.\n"); return i; } } printf("not found.\n"); // Not found. Error. return -1; } int handle_romentries(uint8_t *buffer, uint8_t *content) { int i; // This function does not safe flash write cycles. // // Also it does not cope with overlapping rom layout // sections. // example: // 00000000:00008fff gfxrom // 00009000:0003ffff normal // 00040000:0007ffff fallback // 00000000:0007ffff all // // If you'd specify -i all the included flag of all other // sections is still 0, so no changes will be made to the // flash. Same thing if you specify -i normal -i all only // normal will be updated and the rest will be kept. for (i = 0; i < romimages; i++) { if (rom_entries[i].included) continue; memcpy(buffer + rom_entries[i].start, content + rom_entries[i].start, rom_entries[i].end - rom_entries[i].start); } return 0; }