2 * This file is part of the coreboot project.
4 * Copyright (C) 2008, Jordan Crouse <jordan@cosmicpenguin.net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
22 #include <console/console.h>
25 #include <arch/byteorder.h>
29 #define CBFS_CORE_WITH_LZMA
31 #define phys_to_virt(x) (void*)(x)
32 #define virt_to_phys(x) (uint32_t)(x)
33 #define ERROR(x...) printk(BIOS_ERR, x)
34 #define LOG(x...) printk(BIOS_INFO, x)
35 // FIXME: romstart/romend are fine on x86, but not on ARM
36 #define romstart() 0xffffffff
39 #include "cbfs_core.c"
42 static inline int tohex4(unsigned int c)
44 return (c<=9)?(c+'0'):(c-10+'a');
47 static void tohex16(unsigned int val, char* dest)
49 dest[0]=tohex4(val>>12);
50 dest[1]=tohex4((val>>8) & 0xf);
51 dest[2]=tohex4((val>>4) & 0xf);
52 dest[3]=tohex4(val & 0xf);
55 void *cbfs_load_optionrom(u16 vendor, u16 device, void * dest)
57 char name[17]="pciXXXX,XXXX.rom";
58 struct cbfs_optionrom *orom;
61 tohex16(vendor, name+3);
62 tohex16(device, name+8);
64 orom = (struct cbfs_optionrom *)
65 cbfs_find_file(name, CBFS_TYPE_OPTIONROM);
70 /* They might have specified a dest address. If so, we can decompress.
71 * If not, there's not much hope of decompressing or relocating the rom.
72 * in the common case, the expansion rom is uncompressed, we
73 * pass 0 in for the dest, and all we have to do is find the rom and
74 * return a pointer to it.
77 /* BUG: the cbfstool is (not yet) including a cbfs_optionrom header */
78 src = ((unsigned char *) orom); // + sizeof(struct cbfs_optionrom);
83 if (cbfs_decompress(ntohl(orom->compression),
92 void * cbfs_load_stage(const char *name)
94 struct cbfs_stage *stage = (struct cbfs_stage *)
95 cbfs_find_file(name, CBFS_TYPE_STAGE);
96 /* this is a mess. There is no ntohll. */
97 /* for now, assume compatible byte order until we solve this. */
103 printk(BIOS_INFO, "Stage: loading %s @ 0x%x (%d bytes), entry @ 0x%llx\n",
105 (u32) stage->load, stage->memlen,
107 memset((void *) (u32) stage->load, 0, stage->memlen);
109 if (cbfs_decompress(stage->compression,
110 ((unsigned char *) stage) +
111 sizeof(struct cbfs_stage),
112 (void *) (u32) stage->load,
116 printk(BIOS_DEBUG, "Stage: done loading.\n");
118 entry = stage->entry;
119 // entry = ntohl((u32) stage->entry);
121 return (void *) entry;
124 int cbfs_execute_stage(const char *name)
126 struct cbfs_stage *stage = (struct cbfs_stage *)
127 cbfs_find_file(name, CBFS_TYPE_STAGE);
132 if (ntohl(stage->compression) != CBFS_COMPRESS_NONE) {
133 printk(BIOS_INFO, "CBFS: Unable to run %s: Compressed file"
134 "Not supported for in-place execution\n", name);
138 /* FIXME: This isn't right */
139 printk(BIOS_INFO, "CBFS: run @ %p\n", (void *) ntohl((u32) stage->entry));
140 return run_address((void *) ntohl((u32) stage->entry));
144 * run_address is passed the address of a function taking no parameters and
145 * jumps to it, returning the result.
146 * @param f the address to call as a function.
147 * @return value returned by the function.
150 int run_address(void *f)