From 1c6eb591e977ee3b3a3646cace6ccfb5bd3b187b Mon Sep 17 00:00:00 2001 From: ollie Date: Sat, 26 Nov 2005 21:55:36 +0000 Subject: Original v2 revision: 2111 flasrom update from Stefan, resovle issue 21 git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@34 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1 --- layout.c | 170 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 170 insertions(+) create mode 100644 layout.c (limited to 'layout.c') diff --git a/layout.c b/layout.c new file mode 100644 index 0000000..2219096 --- /dev/null +++ b/layout.c @@ -0,0 +1,170 @@ +#include +#include +#include +#include +#include "layout.h" +#include "lbtable.h" +#include "debug.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("LinuxBIOS image size=%d\n", *walk); + + walk--; mainboard_part=strdup((const char *)(bios+size-*walk)); + walk--; mainboard_vendor=strdup((const char *)(bios+size-*walk)); + printf("MANUFACTURER: %s\n", mainboard_vendor); + printf("MAINBOARD ID: %s\n", mainboard_part); + if(lb_vendor && !strcmp(mainboard_vendor, lb_vendor) && + lb_part && !strcmp(mainboard_part, lb_part)) { + printf ("This firmware image matches " + "this motherboard.\n"); + } else { + if(force) { + printf("WARNING: This firmware image does not " + "fit to this machine - forcing it.\n"); + } else { + printf("ERROR: This firmware image does not " + "fit to this machine\nOverride with -m if" + "you know exactly what you are doing.\n"); + exit(1); + } + } + + return 0; +} + +int read_romlayout(char *name) +{ + FILE *romlayout; + char tempstr[256]; + int i; + + romlayout=fopen (name, "r"); + + if(!romlayout) { + printf("Error while opening rom layout.\n"); + 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