This patch adds Jordan's romtool support for v2.
[coreboot.git] / util / romtool / romtool.h
1 /*
2  * romtool
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 "romfs.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 romfs_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, "(romtool) E: " err, ##args)
51 #define WARN(err, args...) fprintf(stderr, "(romtool) 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         int bootblocksize,  int align);
62 int size_and_open(const char *filename, unsigned int *size);
63 int copy_from_fd(int fd, void *ptr, int size);
64 int get_size(const char *size);
65 int add_bootblock(struct rom *rom, const char *filename);
66
67 /* fs.c */
68
69 struct romfs_file *rom_find(struct rom *rom, unsigned int offset);
70 struct romfs_file *rom_find_first(struct rom *);
71 struct romfs_file *rom_find_next(struct rom *, struct romfs_file *);
72 int rom_add(struct rom *rom, const char *name, void *, int size, int type);
73 int rom_remove(struct rom *rom, const char *name);
74 unsigned int rom_used_space(struct rom *rom);
75 int rom_exists(struct rom *rom);
76
77 #endif