coreboot-kgpe-d16/util/cbfstool/cbfstool.h
Ronald G. Minnich 6ce41c06cc This is transition code for cbfs to implement
cbfs files at fixed addresses.

I call this transitional as the approach I am taking is to add
capability to cbfstool but not change code in a way that will break
existing usages. Later, once we're sure nothing has broken, we can start to 
smooth the edges. 

Right now, fixed address file are only supported via the add command. 

There is one additional command syntax, so, example:
cbfstool add rom romstrap optionrom 0xffffd000

Will add the file to that fix location for a romstrap.

The assumption is that the ROM is based at the end of a 32-bit address
space. As you can see from the code, that assumption can easily be
over-ridden, if we ever need to, with a command option.

Here is one example output result.

rminnich@xcpu2:~/src/bios/coreboot-v2/util/cbfstool$ ./cbfstool x.cbf print
x.cbf: 1024 kB, bootblocksize 32768, romsize 1048576, offset 0x0
Alignment: 16 bytes

Name                           Offset     Type         Size
h                              0x0        optionrom   251
                             0x130      free         917120
h3                             0xdffe0    optionrom    251
                             0xe0110    free         97960

The way this is implemented is pretty simple. I introduce a new
operator, split, that splits an unallocated area into two unallocated
areas. Then, allocation merely becomes a matter of 0, 1, or 2 splits:
0 split -- the free area is the exact fit
1 splits -- need to split some off the front or back
2 splits -- need to split off BOTH the front and back

I think you'll be able to see what I've done. I call this transitional
because, in the end state, we only need one allocate function; for now
I've left two in, to make sure I don't break compatibilty.

Why I like this better than ldscript approach: I like having the
ROMSTRAP located by cbfs, not linker scripts. For one thing, it makes
romstrap visible as a first class object. I think I would have latched
onto a problem I was having much more quickly had I remembered the
ROMSTRAP. It gets lost in the linker scripts.

At this point, we should be able to start removing special ROMSTRAP location 
code from linker scripts. 

Signed-off-by: Ronald G. Minnich <rminnich@gmail.com>
Acked-by: Patrick Georgi <patrick.georgi@coresystems.de>


git-svn-id: svn://svn.coreboot.org/coreboot/trunk@4351 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
2009-06-08 03:33:57 +00:00

87 lines
2.8 KiB
C

/*
* cbfstool
*
* 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
*/
#ifndef _ROMTOOL_H_
#define _ROMTOOL_H_
#include <stdio.h>
#include <arpa/inet.h>
#include "cbfs.h"
/* Definitions */
/* Structures */
struct rom {
unsigned char *name;
unsigned char *ptr;
/* this will *almost* *always* be 0-rom->size, save for some really
* misdesigned systems (which have existed)
*/
unsigned long rombase;
int fd;
int size;
int fssize;
struct cbfs_header *header;
};
/* Macros */
#define ROM_OFFSET(_r, _c) ((unsigned int) ((unsigned char *) (_c) - (_r)->ptr))
#define ROM_PTR(_r, _o) ((_r)->ptr + (_o))
#define ROM_WRITEL(_r, _o, _v) do { *((unsigned int *) ROM_PTR((_r), (_o))) = (_v); } while(0)
#define ROM_READL(_r, _o) *((unsigned int *) (ROM_PTR((_r), (_o))))
#define ERROR(err, args...) fprintf(stderr, "(cbfstool) E: " err, ##args)
#define WARN(err, args...) fprintf(stderr, "(cbfstool) W: " err, ##args)
#define VERBOSE(str, args...) printf(str, ##args)
#define TRUNCATE(_v, _a) ( (_v) & ~( (_a) - 1 ) )
#define ALIGN(_v, _a) ( ( (_v) + ( (_a) - 1 ) ) & ~( (_a) - 1 ) )
/* Function prototypes */
/* util.c */
void flashinit(void *ptr, size_t len);
int open_rom(struct rom *rom, const char *filename);
int create_rom(struct rom *rom, const unsigned char *filename, int size,
const char *bootblockname, int bootblocksize,
int align);
int size_and_open(const char *filename, unsigned int *size);
int copy_from_fd(int fd, void *ptr, int size);
int get_size(const char *size);
int add_bootblock(struct rom *rom, const char *filename);
/* fs.c */
struct cbfs_file *rom_find(struct rom *rom, int offset);
struct cbfs_file *rom_find_first(struct rom *);
struct cbfs_file *rom_find_next(struct rom *, struct cbfs_file *);
int rom_add(struct rom *rom, const char *name, void *, unsigned long address, int size, int type);
int rom_set_header(struct rom *rom, struct cbfs_file *c,
const char*name, int size, int type);
int rom_extract(struct rom *rom, const char *name, void **buf, int *size);
int rom_remove(struct rom *rom, const char *name);
int rom_used_space(struct rom *rom);
int rom_exists(struct rom *rom);
#endif