Author: mcayland Date: Sat Mar 27 13:09:16 2010 New Revision: 714 URL: http://tracker.coreboot.org/trac/openbios/changeset/714
Log: Move the Fcode loader from arch/*/fcodeload.c to libopenbios/fcode_load.c.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@siriusit.co.uk
Added: trunk/openbios-devel/include/libopenbios/fcode_load.h trunk/openbios-devel/libopenbios/fcode_load.c Deleted: trunk/openbios-devel/arch/sparc64/fcodeload.c Modified: trunk/openbios-devel/arch/sparc64/boot.c trunk/openbios-devel/arch/sparc64/boot.h trunk/openbios-devel/arch/sparc64/build.xml trunk/openbios-devel/libopenbios/build.xml
Modified: trunk/openbios-devel/arch/sparc64/boot.c ============================================================================== --- trunk/openbios-devel/arch/sparc64/boot.c Sat Mar 27 12:59:43 2010 (r713) +++ trunk/openbios-devel/arch/sparc64/boot.c Sat Mar 27 13:09:16 2010 (r714) @@ -10,6 +10,7 @@ #include "libopenbios/sys_info.h" #include "libopenbios/elf_load.h" #include "libopenbios/aout_load.h" +#include "libopenbios/fcode_load.h" #include "boot.h"
struct sys_info sys_info;
Modified: trunk/openbios-devel/arch/sparc64/boot.h ============================================================================== --- trunk/openbios-devel/arch/sparc64/boot.h Sat Mar 27 12:59:43 2010 (r713) +++ trunk/openbios-devel/arch/sparc64/boot.h Sat Mar 27 13:09:16 2010 (r714) @@ -9,9 +9,6 @@ // linux_load.c int linux_load(struct sys_info *info, const char *file, const char *cmdline);
-// fcodeload.c -int fcode_load(const char *filename); - // context.c extern struct context * volatile __context; uint64_t start_elf(uint64_t entry_point, uint64_t param);
Modified: trunk/openbios-devel/arch/sparc64/build.xml ============================================================================== --- trunk/openbios-devel/arch/sparc64/build.xml Sat Mar 27 12:59:43 2010 (r713) +++ trunk/openbios-devel/arch/sparc64/build.xml Sat Mar 27 13:09:16 2010 (r714) @@ -14,7 +14,6 @@ <object source="switch.S"/> <object source="linux_load.c"/> <object source="sys_info.c"/> - <object source="fcodeload.c"/> <object source="ofmem_sparc64.c"/> <object source="entry.S"/> <object source="vectors.S"/>
Added: trunk/openbios-devel/include/libopenbios/fcode_load.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/openbios-devel/include/libopenbios/fcode_load.h Sat Mar 27 13:09:16 2010 (r714) @@ -0,0 +1,22 @@ +/* + * Creation Date: <2010/03/22 18:00:00 mcayland> + * Time-stamp: <2010/03/22 18:00:00 mcayland> + * + * <fcode_load.h> + * + * Fcode loader + * + * Copyright (C) 2010 Mark Cave-Ayland (mark.cave-ayland@siriusit.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_FCODELOAD +#define _H_FCODELOAD + +extern int fcode_load(const char *filename); + +#endif /* _H_FCODELOAD */ \ No newline at end of file
Modified: trunk/openbios-devel/libopenbios/build.xml ============================================================================== --- trunk/openbios-devel/libopenbios/build.xml Sat Mar 27 12:59:43 2010 (r713) +++ trunk/openbios-devel/libopenbios/build.xml Sat Mar 27 13:09:16 2010 (r714) @@ -17,6 +17,7 @@ <object source="elf_load.c" condition="AMD64"/> <object source="font_8x8.c" condition="FONT_8X8"/> <object source="font_8x16.c" condition="FONT_8X16"/> + <object source="fcode_load.c" condition="SPARC64"/> <object source="forth_load.c" condition="X86"/> <object source="ipchecksum.c"/> <object source="linuxbios_info.c" condition="LINUXBIOS"/>
Added: trunk/openbios-devel/libopenbios/fcode_load.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/openbios-devel/libopenbios/fcode_load.c Sat Mar 27 13:09:16 2010 (r714) @@ -0,0 +1,82 @@ +/* + * FCode boot loader + */ + +#include "config.h" +#include "kernel/kernel.h" +#include "libopenbios/bindings.h" +#include "libopenbios/fcode_load.h" +#include "libopenbios/sys_info.h" +#include "libc/diskio.h" +#define printf printk +#define debug printk + +static int fd; + +int fcode_load(const char *filename) +{ + int retval = -1; + uint8_t fcode_header[8]; + unsigned long start, size; + unsigned int offset; + + /* Mark the saved-program-state as invalid */ + feval("0 state-valid !"); + + fd = open_io(filename); + if (!fd) + goto out; + + for (offset = 0; offset < 16 * 512; offset += 512) { + seek_io(fd, offset); + if (read_io(fd, &fcode_header, sizeof(fcode_header)) + != sizeof(fcode_header)) { + debug("Can't read FCode header from file %s\n", filename); + retval = LOADER_NOT_SUPPORT; + goto out; + } + switch (fcode_header[0]) { + case 0xf0: // start0 + case 0xf1: // start1 + case 0xf2: // start2 + case 0xf3: // start4 + case 0xfd: // version1 + goto found; + } + } + + debug("Not a bootable FCode image\n"); + retval = LOADER_NOT_SUPPORT; + goto out; + + found: + size = (fcode_header[4] << 24) | (fcode_header[5] << 16) | + (fcode_header[6] << 8) | fcode_header[7]; + + start = 0x4000; + + printf("Loading FCode image...\n"); + + seek_io(fd, offset + sizeof(fcode_header)); + + if ((size_t)read_io(fd, (void *)start, size) != size) { + printf("Can't read file (size 0x%lx)\n", size); + goto out; + } + + debug("Loaded %lu bytes\n", size); + debug("entry point is %#lx\n", start); + + // Initialise saved-program-state + PUSH(start); + feval("saved-program-state >sps.entry !"); + PUSH(size); + feval("saved-program-state >sps.file-size !"); + feval("fcode saved-program-state >sps.file-type !"); + + feval("-1 state-valid !"); + +out: + close_io(fd); + return retval; +}