This patch series enables SeaBIOS to pull common config settings from CBFS (on coreboot) or fw_cfg (on QEmu). The series also converts several compile-time settings to this new dynamic system.
I choose to place the file names in the "etc/" directory so that it is clear they are configuration settings.
On coreboot, a user would do the following to enable a setting:
/path/to/seabios/tools/encodeint.py boot-menu-wait 5500 ./build/cbfstool coreboot.rom add boot-menu-wait etc/boot-menu-wait raw ./build/cbfstool coreboot.rom print
See the patch descriptions below for the six compile-time settings that are converted.
-Kevin
Kevin O'Connor (8): Add "romfile" code to assist with extract integer config settings. Replace CONFIG_BOOTMENU_WAIT with dynamic "etc/boot-menu-wait" file. Replace CONFIG_EXTRA_PCI_ROOTS with dynamic "etc/extra-pci-roots" file. Replace CONFIG_PS2_KEYBOARD_SPINUP with "etc/ps2-keyboard-spinup" file. Replace "CONFIG_OPTIONROMS_CHECKSUM" with "etc/optionroms-checksum" file. Replace CONFIG_S3_RESUME_VGA_INIT with "etc/s3-resume-vga-init" file. Replace CONFIG_SCREEN_AND_DEBUG with "etc/screen-and-debug" file. Add utility "tools/encodeint.py" for CBFS config file creation.
src/Kconfig | 50 -------------------------------------------------- src/boot.c | 5 ++++- src/optionroms.c | 14 ++++++++++++-- src/output.c | 4 ++-- src/paravirt.c | 19 +++++++++++++++++++ src/paravirt.h | 2 ++ src/pci.c | 8 ++++---- src/ps2port.c | 6 ++++-- src/util.h | 1 + tools/encodeint.py | 21 +++++++++++++++++++++ 10 files changed, 69 insertions(+), 61 deletions(-) create mode 100755 tools/encodeint.py
Add romfile_loadint() function which can be used to extract a little-endian binary encoded integer from rom. --- src/paravirt.c | 19 +++++++++++++++++++ src/paravirt.h | 1 + 2 files changed, 20 insertions(+), 0 deletions(-)
diff --git a/src/paravirt.c b/src/paravirt.c index 09e3d23..9cf77de 100644 --- a/src/paravirt.c +++ b/src/paravirt.c @@ -409,3 +409,22 @@ romfile_loadfile(const char *name, int *psize) data[filesize] = '\0'; return data; } + +// Attempt to load an integer from the given file - return 'defval' +// if unsuccesful. +u64 +romfile_loadint(const char *name, u64 defval) +{ + u32 file = romfile_find(name); + if (!file) + return defval; + + int filesize = romfile_size(file); + if (!filesize || filesize > sizeof(u64) || (filesize & (filesize-1))) + // Doesn't look like a valid integer. + return defval; + + u64 val = 0; + romfile_copy(file, &val, sizeof(val)); + return val; +} diff --git a/src/paravirt.h b/src/paravirt.h index 7bf34b1..83166f4 100644 --- a/src/paravirt.h +++ b/src/paravirt.h @@ -101,6 +101,7 @@ static inline const char* romfile_name(u32 fileid) { return qemu_cfg_name_file(fileid); } void *romfile_loadfile(const char *name, int *psize); +u64 romfile_loadint(const char *name, u64 defval);
u32 qemu_cfg_e820_entries(void); void* qemu_cfg_e820_load_next(void *addr);
--- src/Kconfig | 6 ------ src/boot.c | 5 ++++- 2 files changed, 4 insertions(+), 7 deletions(-)
diff --git a/src/Kconfig b/src/Kconfig index 70e3509..0ffc49e 100644 --- a/src/Kconfig +++ b/src/Kconfig @@ -46,12 +46,6 @@ menu "General Features" default y help Support an interactive boot menu at end of post. - config BOOTMENU_WAIT - depends on BOOTMENU - int "Bootmenu delay" - default 2500 - help - Amount of time (in ms) to wait at menu before selecting normal boot. config BOOTSPLASH depends on BOOTMENU bool "Graphical boot splash screen" diff --git a/src/boot.c b/src/boot.c index f3c165c..fcc95ab 100644 --- a/src/boot.c +++ b/src/boot.c @@ -377,6 +377,8 @@ boot_add_cbfs(void *data, const char *desc, int prio) * Boot menu and BCV execution ****************************************************************/
+#define DEFAULT_BOOTMENU_WAIT 2500 + // Show IPL option menu. static void interactive_bootmenu(void) @@ -389,8 +391,9 @@ interactive_bootmenu(void)
printf("Press F12 for boot menu.\n\n");
+ u32 menutime = romfile_loadint("etc/boot-menu-wait", DEFAULT_BOOTMENU_WAIT); enable_bootsplash(); - int scan_code = get_keystroke(CONFIG_BOOTMENU_WAIT); + int scan_code = get_keystroke(menutime); disable_bootsplash(); if (scan_code != 0x86) /* not F12 */
--- src/Kconfig | 11 ----------- src/paravirt.h | 1 + src/pci.c | 8 ++++---- 3 files changed, 5 insertions(+), 15 deletions(-)
diff --git a/src/Kconfig b/src/Kconfig index 0ffc49e..e732528 100644 --- a/src/Kconfig +++ b/src/Kconfig @@ -194,17 +194,6 @@ menu "Hardware support" help Support parallel ports. This also enables int 17 parallel port calls.
- config EXTRA_PCI_ROOTS - int "Number of extra root buses" - default 0 - help - If the target machine has multiple independent root buses - set this to a positive value. The SeaBIOS PCI probe will - then search for the given number of extra root buses. - - Most machines do not have multiple root buses and this - setting should be zero. - config USE_SMM depends on !COREBOOT bool "System Management Mode (SMM)" diff --git a/src/paravirt.h b/src/paravirt.h index 83166f4..4a370a0 100644 --- a/src/paravirt.h +++ b/src/paravirt.h @@ -1,6 +1,7 @@ #ifndef __PV_H #define __PV_H
+#include "config.h" // CONFIG_COREBOOT #include "util.h"
/* This CPUID returns the signature 'KVMKVMKVM' in ebx, ecx, and edx. It diff --git a/src/pci.c b/src/pci.c index 23a6878..49698ac 100644 --- a/src/pci.c +++ b/src/pci.c @@ -8,8 +8,8 @@ #include "pci.h" // pci_config_writel #include "ioport.h" // outl #include "util.h" // dprintf -#include "config.h" // CONFIG_* -#include "farptr.h" // CONFIG_* +#include "paravirt.h" // romfile_loadint +#include "farptr.h" // MAKE_FLATPTR #include "pci_regs.h" // PCI_VENDOR_ID #include "pci_ids.h" // PCI_CLASS_DISPLAY_VGA
@@ -96,9 +96,9 @@ pci_probe(void) struct pci_device *busdevs[256]; memset(busdevs, 0, sizeof(busdevs)); struct pci_device **pprev = &PCIDevices; + int extraroots = romfile_loadint("etc/extra-pci-roots", 0); int bus = -1, lastbus = 0, rootbuses = 0, count=0; - while (bus < 0xff && (bus < MaxPCIBus - || rootbuses < CONFIG_EXTRA_PCI_ROOTS)) { + while (bus < 0xff && (bus < MaxPCIBus || rootbuses < extraroots)) { bus++; int bdf; foreachbdf(bdf, bus) {
--- src/Kconfig | 8 -------- src/ps2port.c | 6 ++++-- 2 files changed, 4 insertions(+), 10 deletions(-)
diff --git a/src/Kconfig b/src/Kconfig index e732528..7a4d50a 100644 --- a/src/Kconfig +++ b/src/Kconfig @@ -126,14 +126,6 @@ menu "Hardware support" default y help Support PS2 ports (keyboard and mouse). - config PS2_KEYBOARD_SPINUP - depends on PS2PORT && COREBOOT - int "Extra time (in ms) to allow a keyboard to initialize" - default 0 - help - Some PS2 keyboards don't respond to commands immediately - after powering on. Specify a positive value here to allow - additional time for the keyboard to become responsive.
config USB bool "USB" diff --git a/src/ps2port.c b/src/ps2port.c index 8259f65..58335af 100644 --- a/src/ps2port.c +++ b/src/ps2port.c @@ -7,6 +7,7 @@
#include "ioport.h" // inb #include "util.h" // dprintf +#include "paravirt.h" // romfile_loadint #include "biosvar.h" // GET_EBDA #include "ps2port.h" // ps2_kbd_command #include "pic.h" // eoi_pic1 @@ -438,13 +439,14 @@ keyboard_init(void *data)
/* ------------------- keyboard side ------------------------*/ /* reset keyboard and self test (keyboard side) */ - u64 end = calc_future_tsc(CONFIG_PS2_KEYBOARD_SPINUP); + int spinupdelay = romfile_loadint("etc/ps2-keyboard-spinup", 0); + u64 end = calc_future_tsc(spinupdelay); for (;;) { ret = ps2_kbd_command(ATKBD_CMD_RESET_BAT, param); if (!ret) break; if (check_tsc(end)) { - if (CONFIG_PS2_KEYBOARD_SPINUP) + if (spinupdelay) warn_timeout(); return; }
--- src/Kconfig | 11 ----------- src/optionroms.c | 6 +++++- 2 files changed, 5 insertions(+), 12 deletions(-)
diff --git a/src/Kconfig b/src/Kconfig index 7a4d50a..3f63374 100644 --- a/src/Kconfig +++ b/src/Kconfig @@ -248,17 +248,6 @@ menu "BIOS interfaces" Select this if option ROMs are already copied to 0xc0000-0xf0000. This must only be selected when using Bochs or QEMU versions older than 0.12. - config OPTIONROMS_CHECKSUM - depends on OPTIONROMS - bool "Require correct checksum on option ROMs" - default y - help - Option ROMs are required to have correct checksums. - However, some option ROMs in the wild don't correctly - follow the specifications and have bad checksums. - Say N here to allow SeaBIOS to execute them anyways. - - If unsure, say Y. config PMM depends on OPTIONROMS bool "PMM interface" diff --git a/src/optionroms.c b/src/optionroms.c index b5a4297..3839497 100644 --- a/src/optionroms.c +++ b/src/optionroms.c @@ -116,6 +116,8 @@ call_bcv(u16 seg, u16 ip) __callrom(MAKE_FLATPTR(seg, 0), ip, 0); }
+static int EnforceChecksum; + // Verify that an option rom looks valid static int is_valid_rom(struct rom_header *rom) @@ -131,7 +133,7 @@ is_valid_rom(struct rom_header *rom) if (sum != 0) { dprintf(1, "Found option rom with bad checksum: loc=%p len=%d sum=%x\n" , rom, len, sum); - if (CONFIG_OPTIONROMS_CHECKSUM) + if (EnforceChecksum) return 0; } return 1; @@ -468,6 +470,8 @@ vga_setup(void)
dprintf(1, "Scan for VGA option rom\n");
+ EnforceChecksum = romfile_loadint("etc/optionroms-checksum", 1); + if (CONFIG_OPTIONROMS_DEPLOYED) { // Option roms are already deployed on the system. init_optionrom((void*)BUILD_ROM_START, 0, 1);
--- src/Kconfig | 6 ------ src/optionroms.c | 5 ++++- 2 files changed, 4 insertions(+), 7 deletions(-)
diff --git a/src/Kconfig b/src/Kconfig index 3f63374..06ab8c1 100644 --- a/src/Kconfig +++ b/src/Kconfig @@ -281,12 +281,6 @@ menu "BIOS interfaces" default y help Support S3 resume handler. - config S3_RESUME_VGA_INIT - depends on S3_RESUME - bool "Run VGA rom on S3 resume" - default n - help - Run the vga rom during S3 resume.
config VGAHOOKS depends on COREBOOT diff --git a/src/optionroms.c b/src/optionroms.c index 3839497..6c4c9ff 100644 --- a/src/optionroms.c +++ b/src/optionroms.c @@ -461,6 +461,8 @@ optionrom_setup(void) * VGA init ****************************************************************/
+static int S3ResumeVgaInit; + // Call into vga code to turn on console. void vga_setup(void) @@ -471,6 +473,7 @@ vga_setup(void) dprintf(1, "Scan for VGA option rom\n");
EnforceChecksum = romfile_loadint("etc/optionroms-checksum", 1); + S3ResumeVgaInit = romfile_loadint("etc/s3-resume-vga-init", 0);
if (CONFIG_OPTIONROMS_DEPLOYED) { // Option roms are already deployed on the system. @@ -505,7 +508,7 @@ vga_setup(void) void s3_resume_vga_init(void) { - if (!CONFIG_S3_RESUME_VGA_INIT) + if (!S3ResumeVgaInit) return; struct rom_header *rom = (void*)BUILD_ROM_START; if (! is_valid_rom(rom))
--- src/Kconfig | 8 -------- src/optionroms.c | 3 +++ src/output.c | 4 ++-- src/util.h | 1 + 4 files changed, 6 insertions(+), 10 deletions(-)
diff --git a/src/Kconfig b/src/Kconfig index 06ab8c1..81acc1c 100644 --- a/src/Kconfig +++ b/src/Kconfig @@ -346,12 +346,4 @@ menu "Debugging" default 0x3f8 help Base port for serial - generally 0x3f8, 0x2f8, 0x3e8, or 0x2e8. - - config SCREEN_AND_DEBUG - depends on DEBUG_LEVEL != 0 - bool "Show screen writes on debug ports" - default y - help - Send characters that SeaBIOS writes to the screen to the - debug ports. endmenu diff --git a/src/optionroms.c b/src/optionroms.c index 6c4c9ff..3d1a1e4 100644 --- a/src/optionroms.c +++ b/src/optionroms.c @@ -462,6 +462,7 @@ optionrom_setup(void) ****************************************************************/
static int S3ResumeVgaInit; +int ScreenAndDebug;
// Call into vga code to turn on console. void @@ -472,8 +473,10 @@ vga_setup(void)
dprintf(1, "Scan for VGA option rom\n");
+ // Load some config settings that impact VGA. EnforceChecksum = romfile_loadint("etc/optionroms-checksum", 1); S3ResumeVgaInit = romfile_loadint("etc/s3-resume-vga-init", 0); + ScreenAndDebug = romfile_loadint("etc/screen-and-debug", 1);
if (CONFIG_OPTIONROMS_DEPLOYED) { // Option roms are already deployed on the system. diff --git a/src/output.c b/src/output.c index 7c10d33..5c91ae5 100644 --- a/src/output.c +++ b/src/output.c @@ -115,7 +115,7 @@ screenc(char c) static void putc_screen(struct putcinfo *action, char c) { - if (CONFIG_SCREEN_AND_DEBUG) + if (ScreenAndDebug) putc_debug(&debuginfo, c); if (c == '\n') screenc('\r'); @@ -363,7 +363,7 @@ printf(const char *fmt, ...) va_start(args, fmt); bvprintf(&screeninfo, fmt, args); va_end(args); - if (CONFIG_SCREEN_AND_DEBUG) + if (ScreenAndDebug) debug_serial_flush(); }
diff --git a/src/util.h b/src/util.h index eecedac..303c524 100644 --- a/src/util.h +++ b/src/util.h @@ -416,6 +416,7 @@ void optionrom_setup(void); void vga_setup(void); void s3_resume_vga_init(void); extern u32 RomEnd; +extern int ScreenAndDebug;
// bootsplash.c void enable_vga_console(void);
--- tools/encodeint.py | 21 +++++++++++++++++++++ 1 files changed, 21 insertions(+), 0 deletions(-) create mode 100755 tools/encodeint.py
diff --git a/tools/encodeint.py b/tools/encodeint.py new file mode 100755 index 0000000..12be5fe --- /dev/null +++ b/tools/encodeint.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python +# Encode an integer in little endian format in a file. +# +# Copyright (C) 2011 Kevin O'Connor kevin@koconnor.net +# +# This file may be distributed under the terms of the GNU GPLv3 license. + +import sys +import struct + +def main(): + filename = sys.argv[1] + value = int(sys.argv[2]) + + outval = struct.pack('<Q', value) + f = open(filename, 'wb') + f.write(outval) + f.close() + +if __name__ == '__main__': + main()