Move CBFS header to a safer place.
[coreboot.git] / util / cbfstool / cbfstool.h
1 /*
2  * cbfstool
3  *
4  * Copyright (C) 2008 Jordan Crouse <jordan@cosmicpenguin.net>
5  *
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.
9  *
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.
14  *
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
18  */
19
20 #ifndef _ROMTOOL_H_
21 #define _ROMTOOL_H_
22
23 #include <stdio.h>
24 #include <arpa/inet.h>
25 #include "cbfs.h"
26
27 /* Definitions */
28
29 /* Structures */
30
31 struct rom {
32         unsigned char *name;
33         unsigned char *ptr;
34         /* this will *almost* *always* be 0-rom->size, save for some really 
35          * misdesigned systems (which have existed)
36          */
37         unsigned long rombase;
38
39         int fd;
40         int size;
41         int fssize;
42
43         struct cbfs_header *header;
44 };
45
46 /* Macros */
47
48 #define ROM_OFFSET(_r, _c) ((unsigned int) ((unsigned char *) (_c) - (_r)->ptr))
49
50 #define ROM_PTR(_r, _o) ((_r)->ptr + (_o))
51 #define ROM_WRITEL(_r, _o, _v) do { *((unsigned int *) ROM_PTR((_r), (_o))) = (_v); } while(0)
52 #define ROM_READL(_r, _o) *((unsigned int *) (ROM_PTR((_r), (_o))))
53
54 #define ERROR(err, args...) fprintf(stderr, "(cbfstool) E: " err, ##args)
55 #define WARN(err, args...) fprintf(stderr, "(cbfstool) W: " err, ##args)
56 #define VERBOSE(str, args...) printf(str, ##args)
57
58 #define TRUNCATE(_v, _a)  ( (_v) & ~( (_a) - 1 ) )
59 #define ALIGN(_v, _a) ( ( (_v) + ( (_a) - 1 ) ) & ~( (_a) - 1 ) )
60
61 /* Function prototypes */
62
63 /* util.c */
64 void flashinit(void *ptr, size_t len);
65 int open_rom(struct rom *rom, const char *filename);
66 int create_rom(struct rom *rom, const unsigned char *filename, int size,
67                const char *bootblockname, int bootblocksize,
68                int align);
69 int size_and_open(const char *filename, unsigned int *size);
70 int copy_from_fd(int fd, void *ptr, int size);
71 int get_size(const char *size);
72 int add_bootblock(struct rom *rom, const char *filename);
73
74 /* fs.c */
75
76 struct cbfs_file *rom_find(struct rom *rom, int offset);
77 struct cbfs_file *rom_find_first(struct rom *);
78 struct cbfs_file *rom_find_next(struct rom *, struct cbfs_file *);
79 int rom_add(struct rom *rom, const char *name, void *, unsigned long address, int size, int type);
80 int rom_set_header(struct rom *rom, struct cbfs_file *c, 
81         const char*name, int size, int type);
82 int rom_extract(struct rom *rom, const char *name, void **buf, int *size);
83 int rom_remove(struct rom *rom, const char *name);
84 int rom_used_space(struct rom *rom);
85 int rom_exists(struct rom *rom);
86
87 #endif