2009-04-14 09:40:01 +02:00
|
|
|
/*
|
|
|
|
* 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 <types.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <console/console.h>
|
|
|
|
#include <cbfs.h>
|
2009-10-28 17:13:28 +01:00
|
|
|
#include <lib.h>
|
2010-02-22 05:33:13 +01:00
|
|
|
#include <arch/byteorder.h>
|
2009-04-14 09:40:01 +02:00
|
|
|
|
2011-07-21 15:11:40 +02:00
|
|
|
// use CBFS core
|
|
|
|
#ifndef __SMM__
|
|
|
|
#define CBFS_CORE_WITH_LZMA
|
|
|
|
#endif
|
|
|
|
#define phys_to_virt(x) (void*)(x)
|
|
|
|
#define virt_to_phys(x) (uint32_t)(x)
|
2012-05-03 01:33:18 +02:00
|
|
|
#define ERROR(x...) printk(BIOS_ERR, "CBFS: " x)
|
|
|
|
#define LOG(x...) printk(BIOS_INFO, "CBFS: " x)
|
|
|
|
#if CONFIG_DEBUG_CBFS
|
|
|
|
#define DEBUG(x...) printk(BIOS_SPEW, "CBFS: " x)
|
|
|
|
#else
|
|
|
|
#define DEBUG(x...)
|
|
|
|
#endif
|
2011-07-21 15:11:40 +02:00
|
|
|
// FIXME: romstart/romend are fine on x86, but not on ARM
|
|
|
|
#define romstart() 0xffffffff
|
|
|
|
#define romend() 0
|
|
|
|
|
|
|
|
#include "cbfs_core.c"
|
2009-04-14 09:40:01 +02:00
|
|
|
|
2011-06-12 14:35:11 +02:00
|
|
|
#ifndef __SMM__
|
2010-03-01 09:34:19 +01:00
|
|
|
static inline int tohex4(unsigned int c)
|
2009-08-20 16:48:03 +02:00
|
|
|
{
|
|
|
|
return (c<=9)?(c+'0'):(c-10+'a');
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tohex16(unsigned int val, char* dest)
|
|
|
|
{
|
|
|
|
dest[0]=tohex4(val>>12);
|
|
|
|
dest[1]=tohex4((val>>8) & 0xf);
|
|
|
|
dest[2]=tohex4((val>>4) & 0xf);
|
|
|
|
dest[3]=tohex4(val & 0xf);
|
|
|
|
}
|
|
|
|
|
2009-04-14 09:40:01 +02:00
|
|
|
void *cbfs_load_optionrom(u16 vendor, u16 device, void * dest)
|
|
|
|
{
|
2009-08-20 16:48:03 +02:00
|
|
|
char name[17]="pciXXXX,XXXX.rom";
|
2009-04-14 09:40:01 +02:00
|
|
|
struct cbfs_optionrom *orom;
|
|
|
|
u8 *src;
|
|
|
|
|
2009-08-20 16:48:03 +02:00
|
|
|
tohex16(vendor, name+3);
|
|
|
|
tohex16(device, name+8);
|
2009-04-14 09:40:01 +02:00
|
|
|
|
|
|
|
orom = (struct cbfs_optionrom *)
|
|
|
|
cbfs_find_file(name, CBFS_TYPE_OPTIONROM);
|
|
|
|
|
|
|
|
if (orom == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2010-04-27 08:56:47 +02:00
|
|
|
/* They might have specified a dest address. If so, we can decompress.
|
2009-04-14 09:40:01 +02:00
|
|
|
* If not, there's not much hope of decompressing or relocating the rom.
|
|
|
|
* in the common case, the expansion rom is uncompressed, we
|
2010-04-27 08:56:47 +02:00
|
|
|
* pass 0 in for the dest, and all we have to do is find the rom and
|
|
|
|
* return a pointer to it.
|
2009-04-14 09:40:01 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
2012-05-03 01:33:18 +02:00
|
|
|
LOG("loading stage %s @ 0x%x (%d bytes), entry @ 0x%llx\n",
|
2009-07-18 16:20:39 +02:00
|
|
|
name,
|
2010-04-27 08:56:47 +02:00
|
|
|
(u32) stage->load, stage->memlen,
|
2009-04-14 09:40:01 +02:00
|
|
|
stage->entry);
|
2009-05-27 16:19:31 +02:00
|
|
|
memset((void *) (u32) stage->load, 0, stage->memlen);
|
2009-04-14 09:40:01 +02:00
|
|
|
|
2009-05-27 16:19:31 +02:00
|
|
|
if (cbfs_decompress(stage->compression,
|
2009-04-14 09:40:01 +02:00
|
|
|
((unsigned char *) stage) +
|
|
|
|
sizeof(struct cbfs_stage),
|
2009-05-27 16:19:31 +02:00
|
|
|
(void *) (u32) stage->load,
|
|
|
|
stage->len))
|
2009-04-14 09:40:01 +02:00
|
|
|
return (void *) -1;
|
2009-10-26 18:15:53 +01:00
|
|
|
|
2012-05-03 01:33:18 +02:00
|
|
|
DEBUG("stage loaded.\n");
|
2009-04-14 09:40:01 +02:00
|
|
|
|
|
|
|
entry = stage->entry;
|
2011-10-17 18:51:15 +02:00
|
|
|
// entry = ntohll(stage->entry);
|
2009-10-26 18:15:53 +01:00
|
|
|
|
2009-04-14 09:40:01 +02:00
|
|
|
return (void *) entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2012-05-03 01:33:18 +02:00
|
|
|
LOG("Unable to run %s: Compressed file"
|
2009-04-14 09:40:01 +02:00
|
|
|
"Not supported for in-place execution\n", name);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: This isn't right */
|
2012-05-03 01:33:18 +02:00
|
|
|
LOG("run @ %p\n", (void *) ntohl((u32) stage->entry));
|
2011-10-17 18:51:15 +02:00
|
|
|
return run_address((void *) (intptr_t)ntohll(stage->entry));
|
2009-04-14 09:40:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* run_address is passed the address of a function taking no parameters and
|
2010-04-27 08:56:47 +02:00
|
|
|
* jumps to it, returning the result.
|
|
|
|
* @param f the address to call as a function.
|
|
|
|
* @return value returned by the function.
|
2009-04-14 09:40:01 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
int run_address(void *f)
|
|
|
|
{
|
|
|
|
int (*v) (void);
|
|
|
|
v = f;
|
|
|
|
return v();
|
|
|
|
}
|
2011-06-12 14:35:11 +02:00
|
|
|
#endif
|