[commit] r1105 - in trunk/openbios-devel: config/examples forth/debugging include/libopenbios libopenbios packages

Author: mcayland Date: Fri Apr 5 11:35:08 2013 New Revision: 1105 URL: http://tracker.coreboot.org/trac/openbios/changeset/1105 Log: loader: implement new loader type for CHRP/Apple partition bootcode (%BOOT) One of the primary reasons that issues with the quik bootloader were not detected earlier was because arch/ppc/qemu/main.c has a separate code path for forcing an old-world boot when -boot c is passed to QEMU. This commit implements the bootcode loader as a core OpenBIOS loader which enables old-world payloads such as quik to be executed using: load hd:,%BOOT go Note that we also fix a bug in mac-parts.c to ensure that we don't try and interpose a filesystem package when %BOOT is passed as a filename. Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> CC: Alexander Graf <agraf@suse.de> CC: Andreas Färber <afaerber@suse.de> Added: trunk/openbios-devel/include/libopenbios/bootcode_load.h trunk/openbios-devel/libopenbios/bootcode_load.c Modified: trunk/openbios-devel/config/examples/ppc_config.xml trunk/openbios-devel/forth/debugging/client.fs trunk/openbios-devel/libopenbios/build.xml trunk/openbios-devel/libopenbios/load.c trunk/openbios-devel/packages/mac-parts.c Modified: trunk/openbios-devel/config/examples/ppc_config.xml ============================================================================== --- trunk/openbios-devel/config/examples/ppc_config.xml Thu Apr 4 13:26:41 2013 (r1104) +++ trunk/openbios-devel/config/examples/ppc_config.xml Fri Apr 5 11:35:08 2013 (r1105) @@ -26,6 +26,7 @@ <option name="CONFIG_VGA_DEPTH" type="integer" value="8"/> <option name="CONFIG_LOADER_AOUT" type="boolean" value="false"/> <option name="CONFIG_LOADER_BOOTINFO" type="boolean" value="true"/> + <option name="CONFIG_LOADER_BOOTCODE" type="boolean" value="true"/> <option name="CONFIG_LOADER_ELF" type="boolean" value="true"/> <option name="CONFIG_LOADER_FCODE" type="boolean" value="false"/> <option name="CONFIG_LOADER_FORTH" type="boolean" value="false"/> Modified: trunk/openbios-devel/forth/debugging/client.fs ============================================================================== --- trunk/openbios-devel/forth/debugging/client.fs Thu Apr 4 13:26:41 2013 (r1104) +++ trunk/openbios-devel/forth/debugging/client.fs Fri Apr 5 11:35:08 2013 (r1105) @@ -27,6 +27,9 @@ variable state-valid 0 state-valid ! +variable want-bootcode +0 want-bootcode ! + variable file-size : !load-size file-size ! ; @@ -44,6 +47,7 @@ 5 constant aout 10 constant fcode 11 constant forth +12 constant bootcode : init-program ( -- ) Added: trunk/openbios-devel/include/libopenbios/bootcode_load.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/openbios-devel/include/libopenbios/bootcode_load.h Fri Apr 5 11:35:08 2013 (r1105) @@ -0,0 +1,22 @@ +/* + * Creation Date: <2010/03/22 18:00:00 mcayland> + * Time-stamp: <2010/03/22 18:00:00 mcayland> + * + * <bootcode_load.h> + * + * Raw bootcode (%BOOT) loader + * + * Copyright (C) 2013 Mark Cave-Ayland (mark.cave-ayland@ilande.co.uk) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation + * + */ + +#ifndef _H_BOOTCODELOAD +#define _H_BOOTCODELOAD + +extern int bootcode_load(ihandle_t dev); + +#endif /* _H__H_BOOTCODELOAD */ Added: trunk/openbios-devel/libopenbios/bootcode_load.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/openbios-devel/libopenbios/bootcode_load.c Fri Apr 5 11:35:08 2013 (r1105) @@ -0,0 +1,71 @@ +/* + * Raw bootcode loader (CHRP/Apple %BOOT) + * Written by Mark Cave-Ayland 2013 + */ + +#include "config.h" +#include "kernel/kernel.h" +#include "libopenbios/bindings.h" +#include "libopenbios/bootcode_load.h" +#include "libc/diskio.h" +#include "drivers/drivers.h" +#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; + + /* Mark the saved-program-state as invalid */ + feval("0 state-valid !"); + + fd = open_ih(dev); + if (fd == -1) { + goto out; + } + + /* Default to loading at load-base */ + fword("load-base"); + loadbase = POP(); + +#ifdef CONFIG_PPC + /* However Old World Macs need to load to a different address */ + if (is_oldworld()) { + loadbase = OLDWORLD_BOOTCODE_BASEADDR; + } +#endif + + bootcode = loadbase; + offset = 0; + + while(1) { + if (seek_io(fd, offset) == -1) + break; + count = read_io(fd, (void *)bootcode, 512); + offset += count; + bootcode += count; + } + + /* If we didn't read anything then exit */ + if (!count) { + goto out; + } + + /* Initialise saved-program-state */ + PUSH(loadbase); + feval("saved-program-state >sps.entry !"); + PUSH(offset); + feval("saved-program-state >sps.file-size !"); + feval("bootcode saved-program-state >sps.file-type !"); + + feval("-1 state-valid !"); + +out: + close_io(fd); + return retval; +} + Modified: trunk/openbios-devel/libopenbios/build.xml ============================================================================== --- trunk/openbios-devel/libopenbios/build.xml Thu Apr 4 13:26:41 2013 (r1104) +++ trunk/openbios-devel/libopenbios/build.xml Fri Apr 5 11:35:08 2013 (r1105) @@ -3,6 +3,7 @@ <library name="openbios" type="static" target="target"> <object source="aout_load.c" condition="LOADER_AOUT"/> <object source="bindings.c"/> + <object source="bootcode_load.c" condition="LOADER_BOOTCODE"/> <object source="bootinfo_load.c" condition="LOADER_BOOTINFO"/> <object source="client.c"/> <object source="console_common.c"/> Modified: trunk/openbios-devel/libopenbios/load.c ============================================================================== --- trunk/openbios-devel/libopenbios/load.c Thu Apr 4 13:26:41 2013 (r1104) +++ trunk/openbios-devel/libopenbios/load.c Fri Apr 5 11:35:08 2013 (r1105) @@ -36,6 +36,10 @@ #include "libopenbios/forth_load.h" #endif +#ifdef CONFIG_LOADER_BOOTCODE +#include "libopenbios/bootcode_load.h" +#endif + struct sys_info sys_info; void *elf_boot_notes = NULL; @@ -92,4 +96,13 @@ } #endif +#ifdef CONFIG_LOADER_BOOTCODE + /* Check for a "raw" %BOOT bootcode payload */ + feval("want-bootcode @"); + valid = POP(); + if (valid) { + bootcode_load(dev); + } +#endif + } Modified: trunk/openbios-devel/packages/mac-parts.c ============================================================================== --- trunk/openbios-devel/packages/mac-parts.c Thu Apr 4 13:26:41 2013 (r1104) +++ trunk/openbios-devel/packages/mac-parts.c Fri Apr 5 11:35:08 2013 (r1105) @@ -89,8 +89,12 @@ parnum = atol(parstr); /* Detect if we are looking for the bootcode */ - if (strcmp(argstr, "%BOOT") == 0) + if (strcmp(argstr, "%BOOT") == 0) { want_bootcode = 1; + feval("1 want-bootcode !"); + } else { + feval("0 want-bootcode !"); + } } DPRINTF("parstr: %s argstr: %s parnum: %d\n", parstr, argstr, parnum); @@ -285,16 +289,10 @@ set_property(chosen_ph, "bootpath", bootpath, strlen(bootpath) + 1); } - - /* If the filename was %BOOT then it's not a real filename, so clear argstr before - attempting interpose */ - if (want_bootcode) { - argstr = strdup(""); - } - + /* If we have been asked to open a particular file, interpose the filesystem package with the passed filename as an argument */ - if (strlen(argstr)) { + if (!want_bootcode && strlen(argstr)) { push_str( argstr ); PUSH_ph( ph ); fword("interpose");
participants (1)
-
repository service