Author: mcayland Date: Sun Mar 9 21:51:13 2014 New Revision: 1280 URL: http://tracker.coreboot.org/trac/openbios/changeset/1280
Log: bootcode_load.c: use new get-bootcode-info plus minor bootcode fixes
Bring the bootcode loader in line with all of the other existing loaders, making use of our new get-bootcode-info word to pass the parameters instead of creating global variables for them all.
Here we remove all global variables and references to the fixed load address used by the quik bootcode loader as this is handled by get-bootcode-info. This exposes a minor bug where we need to return success as soon as a valid bootcode is detected; otherwise we inadvertently drop into the filesystem detection code which is invalid.
Based upon a patch by Andrei E. Warkentin andrey.warkentin@gmail.com.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk
Modified: trunk/openbios-devel/forth/debugging/client.fs trunk/openbios-devel/libopenbios/bootcode_load.c trunk/openbios-devel/libopenbios/load.c trunk/openbios-devel/packages/mac-parts.c
Modified: trunk/openbios-devel/forth/debugging/client.fs ============================================================================== --- trunk/openbios-devel/forth/debugging/client.fs Sun Mar 9 21:50:51 2014 (r1279) +++ trunk/openbios-devel/forth/debugging/client.fs Sun Mar 9 21:51:13 2014 (r1280) @@ -27,9 +27,6 @@ variable state-valid 0 state-valid !
-variable want-bootcode -0 want-bootcode ! - variable file-size
: !load-size file-size ! ;
Modified: trunk/openbios-devel/libopenbios/bootcode_load.c ============================================================================== --- trunk/openbios-devel/libopenbios/bootcode_load.c Sun Mar 9 21:50:51 2014 (r1279) +++ trunk/openbios-devel/libopenbios/bootcode_load.c Sun Mar 9 21:51:13 2014 (r1280) @@ -12,13 +12,13 @@ #define printf printk #define debug printk
-#define OLDWORLD_BOOTCODE_BASEADDR (0x3f4000)
int bootcode_load(ihandle_t dev) { int retval = -1, count = 0, fd; - unsigned long bootcode, loadbase, offset; + unsigned long bootcode, loadbase, entry, size, offset; + ihandle_t bootcode_info;
/* Mark the saved-program-state as invalid */ feval("0 state-valid !"); @@ -28,18 +28,37 @@ goto out; }
+ /* If we don't have the get-bootcode-info word then we don't support + loading bootcode via %BOOT */ + bootcode_info = find_ih_method("get-bootcode-info", dev); + if (!bootcode_info) { + goto out; + } + /* Default to loading at load-base */ fword("load-base"); loadbase = POP(); + entry = loadbase; + size = 0;
#ifdef CONFIG_PPC - /* ...except that QUIK (the only known user of %BOOT to date) is built - with a hard-coded address of 0x3f4000. Let's just use this for the - moment on both New World and Old World Macs, allowing QUIK to also - work under a New World Mac. If we find another user of %BOOT we can - rethink this later. PReP machines should be left unaffected. */ + /* + * Apple OF does not honor load-base and instead uses pmBootLoad + * value from the boot partition descriptor. + * + * Tested with: + * a debian image with QUIK installed + * a debian image with iQUIK installed (https://github.com/andreiw/quik) + * an IQUIK boot floppy + * a NetBSD boot floppy (boots stage 2) + */ if (is_apple()) { - loadbase = OLDWORLD_BOOTCODE_BASEADDR; + PUSH(bootcode_info); + fword("execute"); + + loadbase = POP(); + entry = POP(); + size = POP(); } #endif
@@ -58,11 +77,16 @@ if (!count) { goto out; } + + /* Use proper file size if we got it from bootcode info */ + if (size == 0) { + size = offset; + }
/* Initialise saved-program-state */ - PUSH(loadbase); + PUSH(entry); feval("saved-program-state >sps.entry !"); - PUSH(offset); + PUSH(size); feval("saved-program-state >sps.file-size !"); feval("bootcode saved-program-state >sps.file-type !");
Modified: trunk/openbios-devel/libopenbios/load.c ============================================================================== --- trunk/openbios-devel/libopenbios/load.c Sun Mar 9 21:50:51 2014 (r1279) +++ trunk/openbios-devel/libopenbios/load.c Sun Mar 9 21:51:13 2014 (r1280) @@ -108,11 +108,13 @@
#ifdef CONFIG_LOADER_BOOTCODE /* Check for a "raw" %BOOT bootcode payload */ - feval("want-bootcode @"); - valid = POP(); - if (valid) { - bootcode_load(dev); - } + bootcode_load(dev); + feval("state-valid @"); + valid = POP(); + if (valid) { + feval("saved-program-state >sps.file-size @"); + return; + } #endif
/* Didn't load anything, so return zero size */
Modified: trunk/openbios-devel/packages/mac-parts.c ============================================================================== --- trunk/openbios-devel/packages/mac-parts.c Sun Mar 9 21:50:51 2014 (r1279) +++ trunk/openbios-devel/packages/mac-parts.c Sun Mar 9 21:51:13 2014 (r1280) @@ -92,9 +92,6 @@ /* Detect if we are looking for the bootcode */ if (strcmp(argstr, "%BOOT") == 0) { want_bootcode = 1; - feval("1 want-bootcode !"); - } else { - feval("0 want-bootcode !"); } }
@@ -261,6 +258,11 @@ di->size_hi = size >> BITS; di->size_lo = size & (ucell) -1;
+ /* If we're trying to execute bootcode then we're all done */ + if (want_bootcode) { + goto out; + } + /* We have a valid partition - so probe for a filesystem at the current offset */ DPRINTF("mac-parts: about to probe for fs\n"); DPUSH( offs ); @@ -289,7 +291,7 @@ /* If we have been asked to open a particular file, interpose the filesystem package with the passed filename as an argument */ - if (!want_bootcode && strlen(argstr)) { + if (strlen(argstr)) { push_str( argstr ); PUSH_ph( ph ); fword("interpose");