Add -Werror to help us keep the code clean.
[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
35         int fd;
36         int size;
37         int fssize;
38
39         struct cbfs_header *header;
40 };
41
42 /* Macros */
43
44 #define ROM_OFFSET(_r, _c) ((unsigned int) ((unsigned char *) (_c) - (_r)->ptr))
45
46 #define ROM_PTR(_r, _o) ((_r)->ptr + (_o))
47 #define ROM_WRITEL(_r, _o, _v) do { *((unsigned int *) ROM_PTR((_r), (_o))) = (_v); } while(0)
48 #define ROM_READL(_r, _o) *((unsigned int *) (ROM_PTR((_r), (_o))))
49
50 #define ERROR(err, args...) fprintf(stderr, "(cbfstool) E: " err, ##args)
51 #define WARN(err, args...) fprintf(stderr, "(cbfstool) W: " err, ##args)
52 #define VERBOSE(str, args...) printf(str, ##args)
53
54 #define ALIGN(_v, _a) ( ( (_v) + ( (_a) - 1 ) ) & ~( (_a) - 1 ) )
55
56 /* Function prototypes */
57
58 /* util.c */
59 int open_rom(struct rom *rom, const char *filename);
60 int create_rom(struct rom *rom, const unsigned char *filename, int size,
61                const char *bootblockname, int bootblocksize,
62                int align);
63 int size_and_open(const char *filename, unsigned int *size);
64 int copy_from_fd(int fd, void *ptr, int size);
65 int get_size(const char *size);
66 int add_bootblock(struct rom *rom, const char *filename);
67
68 /* fs.c */
69
70 struct cbfs_file *rom_find(struct rom *rom, int offset);
71 struct cbfs_file *rom_find_first(struct rom *);
72 struct cbfs_file *rom_find_next(struct rom *, struct cbfs_file *);
73 int rom_add(struct rom *rom, const char *name, void *, int size, int type);
74 int rom_set_header(struct rom *rom, struct cbfs_file *c, 
75         const char*name, int size, int type);
76 int rom_extract(struct rom *rom, const char *name, void **buf, int *size);
77 int rom_remove(struct rom *rom, const char *name);
78 int rom_used_space(struct rom *rom);
79 int rom_exists(struct rom *rom);
80
81 #endif