X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=src%2Fcoreboot.c;h=e328c15acfb53f9d6cfb6b2b173d61163a89142a;hb=refs%2Fheads%2Fcoreboot;hp=7fa18e4da0698b6806a11997e970de5efc50522e;hpb=340369654992d86c8d3ce7d93963736e6d9a8750;p=seabios.git diff --git a/src/coreboot.c b/src/coreboot.c index 7fa18e4..e328c15 100644 --- a/src/coreboot.c +++ b/src/coreboot.c @@ -6,12 +6,10 @@ #include "memmap.h" // add_e820 #include "util.h" // dprintf -#include "pci.h" // struct pir_header -#include "acpi.h" // struct rsdp_descriptor -#include "mptable.h" // MPTABLE_SIGNATURE #include "biosvar.h" // GET_EBDA #include "lzmadecode.h" // LzmaDecode #include "smbios.h" // smbios_init +#include "boot.h" // boot_add_cbfs /**************************************************************** @@ -119,15 +117,14 @@ find_cb_subtable(struct cb_header *cbh, u32 tag) } static struct cb_memory *CBMemTable; +const char *CBvendor = "", *CBpart = ""; // Populate max ram and e820 map info by scanning for a coreboot table. static void -coreboot_fill_map() +coreboot_fill_map(void) { dprintf(3, "Attempting to find coreboot table\n"); - CBMemTable = NULL; - // Find coreboot table. struct cb_header *cbh = find_cb_header(0, 0x1000); if (!cbh) @@ -172,11 +169,9 @@ coreboot_fill_map() struct cb_mainboard *cbmb = find_cb_subtable(cbh, CB_TAG_MAINBOARD); if (cbmb) { - const char *vendor = &cbmb->strings[cbmb->vendor_idx]; - const char *part = &cbmb->strings[cbmb->part_idx]; - dprintf(1, "Found mainboard %s %s\n", vendor, part); - - vgahook_setup(vendor, part); + CBvendor = &cbmb->strings[cbmb->vendor_idx]; + CBpart = &cbmb->strings[cbmb->part_idx]; + dprintf(1, "Found mainboard %s %s\n", CBvendor, CBpart); } return; @@ -195,78 +190,6 @@ fail: * BIOS table copying ****************************************************************/ -static void -copy_pir(void *pos) -{ - struct pir_header *p = pos; - if (p->signature != PIR_SIGNATURE) - return; - if (PirOffset) - return; - if (p->size < sizeof(*p)) - return; - if (checksum(pos, p->size) != 0) - return; - void *newpos = malloc_fseg(p->size); - if (!newpos) { - dprintf(1, "No room to copy PIR table!\n"); - return; - } - dprintf(1, "Copying PIR from %p to %p\n", pos, newpos); - memcpy(newpos, pos, p->size); - PirOffset = (u32)newpos - BUILD_BIOS_ADDR; -} - -static void -copy_mptable(void *pos) -{ - struct mptable_floating_s *p = pos; - if (p->signature != MPTABLE_SIGNATURE) - return; - if (!p->physaddr) - return; - if (checksum(pos, sizeof(*p)) != 0) - return; - u32 length = p->length * 16; - u16 mpclength = ((struct mptable_config_s *)p->physaddr)->length; - struct mptable_floating_s *newpos = malloc_fseg(length + mpclength); - if (!newpos) { - dprintf(1, "No room to copy MPTABLE!\n"); - return; - } - dprintf(1, "Copying MPTABLE from %p/%x to %p\n", pos, p->physaddr, newpos); - memcpy(newpos, pos, length); - newpos->physaddr = (u32)newpos + length; - newpos->checksum -= checksum(newpos, sizeof(*newpos)); - memcpy((void*)newpos + length, (void*)p->physaddr, mpclength); -} - -static void -copy_acpi_rsdp(void *pos) -{ - if (RsdpAddr) - return; - struct rsdp_descriptor *p = pos; - if (p->signature != RSDP_SIGNATURE) - return; - u32 length = 20; - if (checksum(pos, length) != 0) - return; - if (p->revision > 1) { - length = p->length; - if (checksum(pos, length) != 0) - return; - } - void *newpos = malloc_fseg(length); - if (!newpos) { - dprintf(1, "No room to copy ACPI RSDP table!\n"); - return; - } - dprintf(1, "Copying ACPI RSDP from %p to %p\n", pos, newpos); - memcpy(newpos, pos, length); - RsdpAddr = newpos; -} - // Attempt to find (and relocate) any standard bios tables found in a // given address range. static void @@ -278,11 +201,12 @@ scan_tables(u32 start, u32 size) copy_pir(p); copy_mptable(p); copy_acpi_rsdp(p); + copy_smbios(p); } } void -coreboot_copy_biostable() +coreboot_copy_biostable(void) { struct cb_memory *cbm = CBMemTable; if (! CONFIG_COREBOOT || !cbm) @@ -290,10 +214,6 @@ coreboot_copy_biostable() dprintf(3, "Relocating coreboot bios tables\n"); - // Init variables set in coreboot table memory scan. - PirOffset = 0; - RsdpAddr = 0; - // Scan CB_MEM_TABLE areas for bios tables. int i, count = MEM_RANGE_COUNT(cbm); for (i=0; istart, m->size); } - // XXX - just create dummy smbios table for now - should detect if - // smbios/dmi table is found from coreboot and use that instead. - smbios_init(); + // XXX - create a dummy smbios table for now. + if (!SMBiosAddr) + smbios_init(); } @@ -326,7 +246,7 @@ ulzma(u8 *dst, u32 maxlen, const u8 *src, u32 srclen) u8 scratch[15980]; int need = (LzmaGetNumProbs(&state.Properties) * sizeof(CProb)); if (need > sizeof(scratch)) { - dprintf(1, "LzmaDecode need %d have %d\n", need, sizeof(scratch)); + dprintf(1, "LzmaDecode need %d have %d\n", need, (unsigned int)sizeof(scratch)); return -1; } state.Probs = (CProb *)scratch; @@ -351,11 +271,6 @@ ulzma(u8 *dst, u32 maxlen, const u8 *src, u32 srclen) * Coreboot flash format ****************************************************************/ -// XXX - optimize -#define ntohl(x) ((((x)&0xff)<<24) | (((x)&0xff00)<<8) | \ - (((x)&0xff0000) >> 8) | (((x)&0xff000000) >> 24)) -#define htonl(x) ntohl(x) - #define CBFS_HEADER_MAGIC 0x4F524243 #define CBFS_HEADPTR_ADDR 0xFFFFFFFc #define CBFS_VERSION1 0x31313131 @@ -373,15 +288,15 @@ struct cbfs_header { static struct cbfs_header *CBHDR; static void -cbfs_setup() +cbfs_setup(void) { - if (! CONFIG_COREBOOT_FLASH) + if (!CONFIG_COREBOOT || !CONFIG_COREBOOT_FLASH) return; CBHDR = *(void **)CBFS_HEADPTR_ADDR; if (CBHDR->magic != htonl(CBFS_HEADER_MAGIC)) { - dprintf(1, "Unable to find CBFS (got %x not %x)\n" - , CBHDR->magic, htonl(CBFS_HEADER_MAGIC)); + dprintf(1, "Unable to find CBFS (ptr=%p; got %x not %x)\n" + , CBHDR, CBHDR->magic, htonl(CBFS_HEADER_MAGIC)); CBHDR = NULL; return; } @@ -416,7 +331,7 @@ cbfs_verify(struct cbfs_file *file) // Return the first file in the CBFS archive static struct cbfs_file * -cbfs_getfirst() +cbfs_getfirst(void) { if (! CBHDR) return NULL; @@ -447,7 +362,7 @@ cbfs_findfile(const char *fname) struct cbfs_file * cbfs_findprefix(const char *prefix, struct cbfs_file *last) { - if (! CONFIG_COREBOOT_FLASH) + if (!CONFIG_COREBOOT || !CONFIG_COREBOOT_FLASH) return NULL; dprintf(3, "Searching CBFS for prefix %s\n", prefix); @@ -464,7 +379,7 @@ cbfs_findprefix(const char *prefix, struct cbfs_file *last) } // Find a file with the given filename (possibly with ".lzma" extension). -static struct cbfs_file * +struct cbfs_file * cbfs_finddatafile(const char *fname) { int fnlen = strlen(fname); @@ -508,18 +423,17 @@ cbfs_datasize(struct cbfs_file *file) int cbfs_copyfile(struct cbfs_file *file, void *dst, u32 maxlen) { - if (! CONFIG_COREBOOT_FLASH || !file) + if (!CONFIG_COREBOOT || !CONFIG_COREBOOT_FLASH || !file) return -1; u32 size = ntohl(file->len); void *src = (void*)file + ntohl(file->offset); if (cbfs_iscomp(file)) { // Compressed - copy to temp ram and uncompress it. - u32 asize = ALIGN(size, 4); - void *temp = malloc_tmphigh(asize); + void *temp = malloc_tmphigh(size); if (!temp) return -1; - iomemcpy(temp, src, asize); + iomemcpy(temp, src, size); int ret = ulzma(dst, maxlen, temp, size); yield(); free(temp); @@ -529,26 +443,13 @@ cbfs_copyfile(struct cbfs_file *file, void *dst, u32 maxlen) // Not compressed. dprintf(3, "Copying data %d@%p to %d@%p\n", size, src, maxlen, dst); if (size > maxlen) { - dprintf(1, "File too big to copy\n"); + warn_noalloc(); return -1; } iomemcpy(dst, src, size); return size; } -// Find and copy the optionrom for the given vendor/device id. -int -cbfs_copy_optionrom(void *dst, u32 maxlen, u32 vendev) -{ - if (! CONFIG_COREBOOT_FLASH) - return -1; - - char fname[17]; - snprintf(fname, sizeof(fname), "pci%04x,%04x.rom" - , (u16)vendev, vendev >> 16); - return cbfs_copyfile(cbfs_finddatafile(fname), dst, maxlen); -} - struct cbfs_payload_segment { u32 type; u32 compression; @@ -571,7 +472,7 @@ struct cbfs_payload { void cbfs_run_payload(struct cbfs_file *file) { - if (!CONFIG_COREBOOT_FLASH || !file) + if (!CONFIG_COREBOOT || !CONFIG_COREBOOT_FLASH || !file) return; dprintf(1, "Run %s\n", file->filename); struct cbfs_payload *pay = (void*)file + ntohl(file->offset); @@ -618,6 +519,21 @@ cbfs_run_payload(struct cbfs_file *file) } } +// Register payloads in "img/" directory with boot system. +void +cbfs_payload_setup(void) +{ + struct cbfs_file *file = NULL; + for (;;) { + file = cbfs_findprefix("img/", file); + if (!file) + break; + const char *filename = cbfs_filename(file); + char *desc = znprintf(MAXDESCSIZE, "Payload [%s]", &filename[4]); + boot_add_cbfs(file, desc, bootprio_find_named_rom(filename, 0)); + } +} + void coreboot_setup(void) {