X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=src%2Fcoreboot.c;h=e328c15acfb53f9d6cfb6b2b173d61163a89142a;hb=refs%2Fheads%2Fcoreboot;hp=f99146e4aff31b50f58c786577b44e7798dd4b80;hpb=2929c352b73e35a32d90d0fdd7fd723591a408de;p=seabios.git diff --git a/src/coreboot.c b/src/coreboot.c index f99146e..e328c15 100644 --- a/src/coreboot.c +++ b/src/coreboot.c @@ -6,103 +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 "memmap.h" // malloc_fseg - - -/**************************************************************** - * 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 -scan_tables(u32 start, u32 size) -{ - void *p = (void*)ALIGN(start, 16); - void *end = (void*)start + size; - for (; ptype; if (type == CB_MEM_TABLE) { type = E820_RESERVED; - scan_tables(m->start, m->size); } else if (type == E820_ACPI || type == E820_RAM) { u64 end = m->start + m->size; if (end > 0x100000000ull) { @@ -262,17 +167,11 @@ coreboot_fill_map() // confuses grub. So, override it. add_e820(0, 16*1024, E820_RAM); - // XXX - just create dummy smbios table for now - should detect if - // smbios/dmi table is found from coreboot and use that instead. - smbios_init(); - 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; @@ -287,10 +186,53 @@ fail: } +/**************************************************************** + * BIOS table copying + ****************************************************************/ + +// Attempt to find (and relocate) any standard bios tables found in a +// given address range. +static void +scan_tables(u32 start, u32 size) +{ + void *p = (void*)ALIGN(start, 16); + void *end = (void*)start + size; + for (; pmap[i]; + if (m->type == CB_MEM_TABLE) + scan_tables(m->start, m->size); + } + + // XXX - create a dummy smbios table for now. + if (!SMBiosAddr) + smbios_init(); +} + + /**************************************************************** * ulzma ****************************************************************/ +// Uncompress data in flash to an area of memory. static int ulzma(u8 *dst, u32 maxlen, const u8 *src, u32 srclen) { @@ -304,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; @@ -329,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 @@ -351,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; } @@ -378,165 +315,139 @@ struct cbfs_file { char filename[0]; } PACKED; +// Verify a cbfs entry looks valid. static struct cbfs_file * -cbfs_search(struct cbfs_file *file) +cbfs_verify(struct cbfs_file *file) { - for (;;) { - if (file < (struct cbfs_file *)(0xFFFFFFFF - ntohl(CBHDR->romsize))) - return NULL; - u64 magic = file->magic; - if (magic == CBFS_FILE_MAGIC) { - dprintf(5, "Found CBFS file %s\n", file->filename); - return file; - } - if (magic == 0) - return NULL; - file = (void*)file + ntohl(CBHDR->align); + if (file < (struct cbfs_file *)(0xFFFFFFFF - ntohl(CBHDR->romsize))) + return NULL; + u64 magic = file->magic; + if (magic == CBFS_FILE_MAGIC) { + dprintf(5, "Found CBFS file %s\n", file->filename); + return file; } + return NULL; } +// Return the first file in the CBFS archive static struct cbfs_file * -cbfs_getfirst() +cbfs_getfirst(void) { if (! CBHDR) return NULL; - return cbfs_search((void *)(0 - ntohl(CBHDR->romsize) + ntohl(CBHDR->offset))); + return cbfs_verify((void *)(0 - ntohl(CBHDR->romsize) + ntohl(CBHDR->offset))); } +// Return the file after the given file. static struct cbfs_file * cbfs_getnext(struct cbfs_file *file) { file = (void*)file + ALIGN(ntohl(file->len) + ntohl(file->offset), ntohl(CBHDR->align)); - return cbfs_search(file); + return cbfs_verify(file); } -static struct cbfs_file * +// Find the file with the given filename. +struct cbfs_file * cbfs_findfile(const char *fname) { dprintf(3, "Searching CBFS for %s\n", fname); struct cbfs_file *file; - for (file = cbfs_getfirst(); file; file = cbfs_getnext(file)) { + for (file = cbfs_getfirst(); file; file = cbfs_getnext(file)) if (strcmp(fname, file->filename) == 0) return file; - } return NULL; } -static int -data_copy(u8 *dst, u32 maxlen, const u8 *src, u32 srclen) +// Find next file with the given filename prefix. +struct cbfs_file * +cbfs_findprefix(const char *prefix, struct cbfs_file *last) { - dprintf(3, "Copying data %d@%p to %d@%p\n", srclen, src, maxlen, dst); - if (srclen > maxlen) { - dprintf(1, "File too big to copy\n"); - return -1; - } - memcpy(dst, src, srclen); - return srclen; + if (!CONFIG_COREBOOT || !CONFIG_COREBOOT_FLASH) + return NULL; + + dprintf(3, "Searching CBFS for prefix %s\n", prefix); + int len = strlen(prefix); + struct cbfs_file *file; + if (! last) + file = cbfs_getfirst(); + else + file = cbfs_getnext(last); + for (; file; file = cbfs_getnext(file)) + if (memcmp(prefix, file->filename, len) == 0) + return file; + return NULL; } -// Copy a file to memory (uncompressing if necessary) -static int -cbfs_copyfile(void *dst, u32 maxlen, const char *fname) +// Find a file with the given filename (possibly with ".lzma" extension). +struct cbfs_file * +cbfs_finddatafile(const char *fname) { - dprintf(3, "Searching CBFS for data file %s\n", fname); int fnlen = strlen(fname); - struct cbfs_file *file; - for (file = cbfs_getfirst(); file; file = cbfs_getnext(file)) { - if (memcmp(fname, file->filename, fnlen) != 0) - continue; - u32 size = ntohl(file->len); - void *src = (void*)file + ntohl(file->offset); - if (file->filename[fnlen] == '\0') - return data_copy(dst, maxlen, src, size); - if (strcmp(&file->filename[fnlen], ".lzma") == 0) - return ulzma(dst, maxlen, src, size); + struct cbfs_file *file = NULL; + for (;;) { + file = cbfs_findprefix(fname, file); + if (!file) + return NULL; + if (file->filename[fnlen] == '\0' + || strcmp(&file->filename[fnlen], ".lzma") == 0) + return file; } - return -1; } -const char * -cbfs_findNprefix(const char *prefix, int n) +// Determine whether the file has a ".lzma" extension. +static int +cbfs_iscomp(struct cbfs_file *file) { - if (! CONFIG_COREBOOT_FLASH) - return NULL; - - dprintf(3, "Searching CBFS for prefix %s\n", prefix); - int len = strlen(prefix); - struct cbfs_file *file; - for (file = cbfs_getfirst(); file; file = cbfs_getnext(file)) { - if (memcmp(prefix, file->filename, len) == 0) { - if (n <= 0) - return file->filename; - n--; - } - } - return NULL; + int fnamelen = strlen(file->filename); + return fnamelen > 5 && strcmp(&file->filename[fnamelen-5], ".lzma") == 0; } -static char -getHex(u8 x) +// Return the filename of a given file. +const char * +cbfs_filename(struct cbfs_file *file) { - if (x <= 9) - return '0' + x; - return 'a' + x - 10; + return file->filename; } -static u32 -hexify4(u16 x) +// Determine the uncompressed size of a datafile. +u32 +cbfs_datasize(struct cbfs_file *file) { - return ((getHex(x&0xf) << 24) - | (getHex((x>>4)&0xf) << 16) - | (getHex((x>>8)&0xf) << 8) - | (getHex(x>>12))); + void *src = (void*)file + ntohl(file->offset); + if (cbfs_iscomp(file)) + return *(u32*)(src + LZMA_PROPERTIES_SIZE); + return ntohl(file->len); } +// Copy a file to memory (uncompressing if necessary) int -cbfs_copy_optionrom(void *dst, u32 maxlen, u32 vendev) +cbfs_copyfile(struct cbfs_file *file, void *dst, u32 maxlen) { - if (! CONFIG_COREBOOT_FLASH) + if (!CONFIG_COREBOOT || !CONFIG_COREBOOT_FLASH || !file) return -1; - char fname[17]; - // Ughh - poor man's sprintf of "pci%04x,%04x.rom" - *(u32*)fname = 0x20696370; // "pci " - *(u32*)&fname[3] = hexify4(vendev); - fname[7] = ','; - *(u32*)&fname[8] = hexify4(vendev >> 16); - *(u32*)&fname[12] = 0x6d6f722e; // ".rom" - fname[16] = '\0'; - - return cbfs_copyfile(dst, maxlen, fname); -} + u32 size = ntohl(file->len); + void *src = (void*)file + ntohl(file->offset); + if (cbfs_iscomp(file)) { + // Compressed - copy to temp ram and uncompress it. + void *temp = malloc_tmphigh(size); + if (!temp) + return -1; + iomemcpy(temp, src, size); + int ret = ulzma(dst, maxlen, temp, size); + yield(); + free(temp); + return ret; + } -// Copy the next file with the given prefix - starting at pos 'last'. -struct cbfs_file * -cbfs_copyfile_prefix(void *dst, u32 maxlen, const char *prefix - , struct cbfs_file *last) -{ - if (! CONFIG_COREBOOT_FLASH) - return NULL; - dprintf(3, "Searching CBFS for data file prefix %s\n", prefix); - struct cbfs_file *file; - if (! last) - file = cbfs_getfirst(); - else - file = cbfs_getnext(last); - int prefixlen = strlen(prefix); - for (; file; file = cbfs_getnext(file)) { - if (memcmp(prefix, file->filename, prefixlen) != 0) - continue; - u32 size = ntohl(file->len); - void *src = (void*)file + ntohl(file->offset); - int fnamelen = strlen(file->filename); - int rv; - if (fnamelen > 5 && strcmp(&file->filename[fnamelen-5], ".lzma") == 0) - rv = ulzma(dst, maxlen, src, size); - else - rv = data_copy(dst, maxlen, src, size); - if (rv >= 0) - return file; + // Not compressed. + dprintf(3, "Copying data %d@%p to %d@%p\n", size, src, maxlen, dst); + if (size > maxlen) { + warn_noalloc(); + return -1; } - return NULL; + iomemcpy(dst, src, size); + return size; } struct cbfs_payload_segment { @@ -559,14 +470,11 @@ struct cbfs_payload { }; void -cbfs_run_payload(const char *filename) +cbfs_run_payload(struct cbfs_file *file) { - if (! CONFIG_COREBOOT_FLASH) - return; - dprintf(1, "Run %s\n", filename); - struct cbfs_file *file = cbfs_findfile(filename); - if (!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); struct cbfs_payload_segment *seg = pay->segments; for (;;) { @@ -611,6 +519,21 @@ cbfs_run_payload(const char *filename) } } +// 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) {