coreboot-kgpe-d16/util/cbfstool/common.h
Patrick Georgi 0da38dde4b Add a "locate" function cbfstool, which helps you find
out a suitable address to put a XIP stage to.

Specifically, you pass it the file (to get its filesize), its filename
(as the header has a variable length that depends on it), and the
granularity requirement it has to fit in (for XIP).
The granularity is MTRR-style: when you request 0x10000, cbfstool looks
for a suitable place in a 64kb-aligned 64kb block.

cbfstool simply prints out a hex value which is the start address of a
suitably located free memory block. That value can then be used with
cbfs add-stage to store the file in the ROM image.

It's a two-step operation (instead of being merged into cbfs add-stage)
because the image must be linked twice: First, with some bogus, but safe
base address (eg. 0) to figure out the target address (based on file
size). Then a second time at the target address.

The work flow is:
 - link file
 - cbfstool locate
 - link file again
 - cbfstool add-stage.

Signed-off-by: Patrick Georgi <patrick.georgi@coresystems.de>
Acked-by: Stefan Reinauer <stepan@coresystems.de>


git-svn-id: svn://svn.coreboot.org/coreboot/trunk@4929 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
2009-11-09 17:18:02 +00:00

69 lines
2.3 KiB
C

/*
* Copyright (C) 2009 coresystems GmbH
* written by Patrick Georgi <patrick.georgi@coresystems.de>
*
* 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 <stdint.h>
extern void *offset;
extern struct cbfs_header *master_header;
extern uint32_t phys_start, phys_end, align, romsize;
static void *phys_to_virt(uint32_t addr)
{
return offset + addr;
}
static uint32_t virt_to_phys(void *addr)
{
return (unsigned long)(addr - offset) & 0xffffffff;
}
#define ALIGN(val, by) (((val) + (by)-1)&~((by)-1))
uint32_t getfilesize(const char *filename);
void *loadfile(const char *filename, uint32_t * romsize_p, void *content,
int place);
void *loadrom(const char *filename);
void writerom(const char *filename, void *start, uint32_t size);
int iself(unsigned char *input);
typedef void (*comp_func_ptr) (char *, int, char *, int *);
typedef enum { CBFS_COMPRESS_NONE = 0, CBFS_COMPRESS_LZMA = 1 } comp_algo;
comp_func_ptr compression_function(comp_algo algo);
uint64_t intfiletype(const char *name);
int parse_elf_to_payload(unsigned char *input, unsigned char **output,
comp_algo algo);
int parse_elf_to_stage(unsigned char *input, unsigned char **output,
comp_algo algo, uint32_t * location);
void *create_cbfs_file(const char *filename, void *data, uint32_t * datasize,
uint32_t type, uint32_t * location);
int create_cbfs_image(const char *romfile, uint32_t romsize,
const char *bootblock, uint32_t align);
int add_file_to_cbfs(void *content, uint32_t contentsize, uint32_t location);
void print_cbfs_directory(const char *filename);
uint32_t cbfs_find_location(const char *romfile, uint32_t filesize,
const char *filename, uint32_t align);
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))