Patrick Georgi (patrick@georgi-clan.de) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/116
-gerrit
commit ad9b1d81d3f46ccab9e7fc5570b0b8d495386547 Author: Patrick Georgi patrick.georgi@secunet.com Date: Fri Jul 22 10:00:38 2011 +0200
Adapt filo to libpayload changes
libpayload comes with CBFS and LZMA support now, and FILO's copy leads to conflicts (which is what the libpayload copy intends to solve)
Change-Id: I1c70eda7b260d7149c7079cb0d681c274f510ed8 Signed-off-by: Patrick Georgi patrick.georgi@secunet.com --- fs/Makefile.inc | 2 - fs/cbfs.c | 236 ------------------------------------------------------- fs/fsys_cbfs.c | 2 +- include/cbfs.h | 173 ---------------------------------------- 4 files changed, 1 insertions(+), 412 deletions(-)
diff --git a/fs/Makefile.inc b/fs/Makefile.inc index 99c0207..4d8650b 100644 --- a/fs/Makefile.inc +++ b/fs/Makefile.inc @@ -31,5 +31,3 @@ TARGETS-$(CONFIG_FSYS_SQUASHFS) += fs/fsys_squashfs.o TARGETS-$(CONFIG_FSYS_SQUASHFS) += fs/squashfs_zlib.o TARGETS-$(CONFIG_ARTEC_BOOT) += fs/fsys_aboot.o TARGETS-$(CONFIG_FSYS_CBFS) += fs/fsys_cbfs.o -TARGETS-$(CONFIG_FSYS_CBFS) += fs/cbfs.o -TARGETS-$(CONFIG_FSYS_CBFS) += fs/lzma.o diff --git a/fs/cbfs.c b/fs/cbfs.c deleted file mode 100644 index 23e0a89..0000000 --- a/fs/cbfs.c +++ /dev/null @@ -1,236 +0,0 @@ -/* - * This file is part of the coreboot project. - * - * Copyright (C) 2008, Jordan Crouse jordan@cosmicpenguin.net - * - * 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; version 2 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA - */ - -#include <arch/types.h> -#include <arch/virtual.h> -#include <cbfs.h> - -#define ALIGN(val,by) ((val+by-1)&~(by-1)) -#define cbfs_printf(...) /* printf(__VA_ARGS__) */ -#define printk_spew cbfs_printf -#define printk_debug cbfs_printf -#define printk_info cbfs_printf -#define printk_err cbfs_printf - -#ifndef CONFIG_BIG_ENDIAN -#define ntohl(x) ( ((x&0xff)<<24) | ((x&0xff00)<<8) | \ - ((x&0xff0000) >> 8) | ((x&0xff000000) >> 24) ) -#else -#define ntohl(x) (x) -#endif - -int cbfs_decompress(int algo, void *src, void *dst, int len) -{ - switch(algo) { - case CBFS_COMPRESS_NONE: - memcpy(dst, src, len); - return 0; - - case CBFS_COMPRESS_LZMA: { - unsigned long ulzma(unsigned char *src, unsigned char *dst); - ulzma(src, dst); - } - return 0; - - default: - printk_info( "CBFS: Unknown compression type %d\n", - algo); - return -1; - } -} - -int cbfs_check_magic(struct cbfs_file *file) -{ - return !strcmp(file->magic, CBFS_FILE_MAGIC) ? 1 : 0; -} - -struct cbfs_header *cbfs_master_header(void) -{ - struct cbfs_header *header; - - void *ptr = phys_to_virt((void *)*((unsigned long *) phys_to_virt(CBFS_HEADPTR_ADDR))); - printk_spew("Check CBFS header at %p\n", ptr); - header = (struct cbfs_header *) ptr; - - printk_spew("magic is %08x\n", ntohl(header->magic)); - if (ntohl(header->magic) != CBFS_HEADER_MAGIC) { - printk_err("ERROR: No valid CBFS header found!\n"); - return NULL; - } - - printk_spew("Found CBFS header at %p\n", ptr); - return header; -} - -struct cbfs_file *cbfs_find(const char *name) -{ - struct cbfs_header *header = cbfs_master_header(); - unsigned long offset; - - if (header == NULL) - return NULL; - offset = (unsigned long) phys_to_virt(0 - ntohl(header->romsize) + ntohl(header->offset)); - - int align= ntohl(header->align); - - while(1) { - struct cbfs_file *file = (struct cbfs_file *) offset; - if (!cbfs_check_magic(file)) return NULL; - printk_debug("Check %s\n", CBFS_NAME(file)); - if (!strcmp(CBFS_NAME(file), name)) - return file; - - int flen = ntohl(file->len); - int foffset = ntohl(file->offset); - printk_spew("CBFS: follow chain: %p + %x + %x + align -> ", (void *)offset, foffset, flen); - - unsigned long oldoffset = offset; - offset = ALIGN(offset + foffset + flen, align); - printk_spew("%p\n", (void *)offset); - if (virt_to_phys(offset) <= virt_to_phys(oldoffset)) return NULL; - - if (offset < (unsigned long)phys_to_virt(0xFFFFFFFF - ntohl(header->romsize))) - return NULL; - } -} - -struct cbfs_stage *cbfs_find_file(const char *name, int type) -{ - struct cbfs_file *file = cbfs_find(name); - - if (file == NULL) { - printk_info( "CBFS: Could not find file %s\n", - name); - return NULL; - } - - if (ntohl(file->type) != type) { - printk_info( "CBFS: File %s is of type %x instead of" - "type %x\n", name, file->type, type); - - return NULL; - } - - return (void *) CBFS_SUBHEADER(file); -} - -void *cbfs_load_optionrom(u16 vendor, u16 device, void * dest) -{ - char name[17]; - struct cbfs_optionrom *orom; - u8 *src; - - sprintf(name,"pci%04x,%04x.rom", vendor, device); - - orom = (struct cbfs_optionrom *) - cbfs_find_file(name, CBFS_TYPE_OPTIONROM); - - if (orom == NULL) - return NULL; - - /* They might have specified a dest address. If so, we can decompress. - * If not, there's not much hope of decompressing or relocating the rom. - * in the common case, the expansion rom is uncompressed, we - * pass 0 in for the dest, and all we have to do is find the rom and - * return a pointer to it. - */ - - /* BUG: the cbfstool is (not yet) including a cbfs_optionrom header */ - src = ((unsigned char *) orom); // + sizeof(struct cbfs_optionrom); - - if (! dest) - return src; - - if (cbfs_decompress(ntohl(orom->compression), - src, - dest, - ntohl(orom->len))) - return NULL; - - return dest; -} - -void * cbfs_load_stage(const char *name) -{ - struct cbfs_stage *stage = (struct cbfs_stage *) - cbfs_find_file(name, CBFS_TYPE_STAGE); - /* this is a mess. There is no ntohll. */ - /* for now, assume compatible byte order until we solve this. */ - u32 entry; - - if (stage == NULL) - return (void *) -1; - - printk_info("Stage: load %s @ %d/%d bytes, enter @ %llx\n", - name, - (u32) stage->load, stage->memlen, - stage->entry); - memset((void *) (u32) stage->load, 0, stage->memlen); - - if (cbfs_decompress(stage->compression, - ((unsigned char *) stage) + - sizeof(struct cbfs_stage), - (void *) (u32) stage->load, - stage->len)) - return (void *) -1; - printk_info("Stage: done loading.\n"); - - entry = stage->entry; -// return (void *) ntohl((u32) stage->entry); - return (void *) entry; -} - -void * cbfs_get_file(const char *name) -{ - return cbfs_find(name); -} - -int cbfs_execute_stage(const char *name) -{ - struct cbfs_stage *stage = (struct cbfs_stage *) - cbfs_find_file(name, CBFS_TYPE_STAGE); - - if (stage == NULL) - return 1; - - if (ntohl(stage->compression) != CBFS_COMPRESS_NONE) { - printk_info( "CBFS: Unable to run %s: Compressed file" - "Not supported for in-place execution\n", name); - return 1; - } - - /* FIXME: This isn't right */ - printk_info( "CBFS: run @ %p\n", (void *) ntohl((u32) stage->entry)); - return run_address((void *) ntohl((u32) stage->entry)); -} - -/** - * run_address is passed the address of a function taking no parameters and - * jumps to it, returning the result. - * @param f the address to call as a function. - * returns value returned by the function. - */ - -int run_address(void *f) -{ - int (*v) (void); - v = f; - return v(); -} - diff --git a/fs/fsys_cbfs.c b/fs/fsys_cbfs.c index 59c6e35..5c389e9 100644 --- a/fs/fsys_cbfs.c +++ b/fs/fsys_cbfs.c @@ -31,7 +31,7 @@ cbfs_mount (void) return 0;
/* CBFS? */ - if (!cbfs_master_header()) + if (get_cbfs_header() == (void*)0xffffffff) return 0;
return 1; diff --git a/include/cbfs.h b/include/cbfs.h deleted file mode 100644 index 9d6832c..0000000 --- a/include/cbfs.h +++ /dev/null @@ -1,173 +0,0 @@ -/* - * This file is part of the coreboot project. - * - * Copyright (C) 2008 Jordan Crouse jordan@cosmicpenguin.net - * - * This file is dual-licensed. You can choose between: - * - The GNU GPL, version 2, as published by the Free Software Foundation - * - The revised BSD license (without advertising clause) - * - * --------------------------------------------------------------------------- - * 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; version 2 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA - * --------------------------------------------------------------------------- - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * --------------------------------------------------------------------------- - */ - -#ifndef _CBFS_H_ -#define _CBFS_H_ - -/** These are standard values for the known compression - alogrithms that coreboot knows about for stages and - payloads. Of course, other LAR users can use whatever - values they want, as long as they understand them. */ - -#define CBFS_COMPRESS_NONE 0 -#define CBFS_COMPRESS_LZMA 1 - -/** These are standard component types for well known - components (i.e - those that coreboot needs to consume. - Users are welcome to use any other value for their - components */ - -#define CBFS_TYPE_STAGE 0x10 -#define CBFS_TYPE_PAYLOAD 0x20 -#define CBFS_TYPE_OPTIONROM 0x30 - -/** this is the master cbfs header - it need to be - located somewhere in the bootblock. Where it - actually lives is up to coreboot. A pointer to - this header will live at 0xFFFFFFFc, so we can - easily find it. */ - -#define CBFS_HEADER_MAGIC 0x4F524243 -#define CBFS_HEADPTR_ADDR 0xFFFFFFFc -#define VERSION1 0x31313131 - -struct cbfs_header { - u32 magic; - u32 version; - u32 romsize; - u32 bootblocksize; - u32 align; - u32 offset; - u32 pad[2]; -} __attribute__((packed)); - -/** This is a component header - every entry in the CBFS - will have this header. - - This is how the component is arranged in the ROM: - - -------------- <- 0 - component header - -------------- <- sizeof(struct component) - component name - -------------- <- offset - data - ... - -------------- <- offset + len -*/ - -#define CBFS_FILE_MAGIC "LARCHIVE" - -struct cbfs_file { - char magic[8]; - u32 len; - u32 type; - u32 checksum; - u32 offset; -} __attribute__((packed)); - -/*** Component sub-headers ***/ - -/* Following are component sub-headers for the "standard" - component types */ - -/** This is the sub-header for stage components. Stages are - loaded by coreboot during the normal boot process */ - -struct cbfs_stage { - u32 compression; /** Compression type */ - u64 entry; /** entry point */ - u64 load; /** Where to load in memory */ - u32 len; /** length of data to load */ - u32 memlen; /** total length of object in memory */ -} __attribute__((packed)); - -/** this is the sub-header for payload components. Payloads - are loaded by coreboot at the end of the boot process */ - -struct cbfs_payload_segment { - u32 type; - u32 compression; - u32 offset; - u64 load_addr; - u32 len; - u32 mem_len; -} __attribute__((packed)); - -struct cbfs_payload { - struct cbfs_payload_segment segments; -}; - -#define PAYLOAD_SEGMENT_CODE 0x45444F43 -#define PAYLOAD_SEGMENT_DATA 0x41544144 -#define PAYLOAD_SEGMENT_BSS 0x20535342 -#define PAYLOAD_SEGMENT_PARAMS 0x41524150 -#define PAYLOAD_SEGMENT_ENTRY 0x52544E45 - -struct cbfs_optionrom { - u32 compression; - u32 len; -} __attribute__((packed)); - -#define CBFS_NAME(_c) (((char *) (_c)) + sizeof(struct cbfs_file)) -#define CBFS_SUBHEADER(_p) ( (void *) ((((u8 *) (_p)) + ntohl((_p)->offset))) ) - -void * cbfs_load_stage(const char *name); -int cbfs_execute_stage(const char *name); -void * cbfs_get_file(const char *name); -void *cbfs_load_optionrom(u16 vendor, u16 device, void * dest); -int run_address(void *f); -int cbfs_decompress(int algo, void *src, void *dst, int len); -struct cbfs_stage *cbfs_find_file(const char *name, int type); -int cbfs_check_magic(struct cbfs_file *file); -struct cbfs_header *cbfs_master_header(void); -struct cbfs_file *cbfs_find(const char *name); -void cbfs_and_run_core(char* filename, unsigned int ebp); - -#endif -