aboutsummaryrefslogtreecommitdiff
path: root/util/cbfstool/cbfstool.c
diff options
context:
space:
mode:
authorHung-Te Lin <hungte@chromium.org>2013-01-29 10:24:00 +0800
committerStefan Reinauer <stefan.reinauer@coreboot.org>2013-02-05 22:27:13 +0100
commit5f3eb26d857628615e6c92180a2dc2213011dd09 (patch)
tree67ed2f539784df57bf77c70c517f18a02dc0ffae /util/cbfstool/cbfstool.c
parentf56c73f1e1c2b13c7b2b989fc44358138394cc68 (diff)
cbfstool: Use cbfs_image api for "add" command.
The "add" command is compatible with all legacy usage. Also, to support platforms without top-aligned address, all address-type params (-b, -H, -l) can now be ROM offset (address < 0x8000000) or x86 top-aligned address (address > 0x80000000). Example: cbfstool coreboot.rom add -f config -n config -t raw -b 0x2000 cbfstool coreboot.rom add -f stage -n newstage -b 0xffffd1c0 Verified boot-able on both ARM(snow) and x86(QEMU) system. Change-Id: I485e4e88b5e269494a4b138e0a83f793ffc5a084 Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: http://review.coreboot.org/2216 Tested-by: build bot (Jenkins) Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
Diffstat (limited to 'util/cbfstool/cbfstool.c')
-rw-r--r--util/cbfstool/cbfstool.c78
1 files changed, 50 insertions, 28 deletions
diff --git a/util/cbfstool/cbfstool.c b/util/cbfstool/cbfstool.c
index 2aa1df01eb..28ca15fe05 100644
--- a/util/cbfstool/cbfstool.c
+++ b/util/cbfstool/cbfstool.c
@@ -58,62 +58,84 @@ static struct param {
.algo = CBFS_COMPRESS_NONE,
};
-static int cbfs_add(void)
-{
- uint32_t filesize = 0;
- void *rom, *filedata, *cbfsfile;
+typedef int (*convert_buffer_t)(struct buffer *buffer);
+
+static int cbfs_add_component(const char *cbfs_name,
+ const char *filename,
+ const char *name,
+ uint32_t type,
+ uint32_t offset,
+ convert_buffer_t convert) {
+ struct cbfs_image image;
+ struct buffer buffer;
- if (!param.filename) {
+ if (!filename) {
ERROR("You need to specify -f/--filename.\n");
return 1;
}
- if (!param.name) {
+ if (!name) {
ERROR("You need to specify -n/--name.\n");
return 1;
}
- if (param.type == 0) {
+ if (type == 0) {
ERROR("You need to specify a valid -t/--type.\n");
return 1;
}
- rom = loadrom(param.cbfs_name);
- if (rom == NULL) {
- ERROR("Could not load ROM image '%s'.\n",
- param.cbfs_name);
+ if (buffer_from_file(&buffer, filename) != 0) {
+ ERROR("Could not load file '%s'.\n", filename);
return 1;
}
- filedata = loadfile(param.filename, &filesize, 0, SEEK_SET);
- if (filedata == NULL) {
- ERROR("Could not load file '%s'.\n",
- param.filename);
- free(rom);
+ if (convert && convert(&buffer) != 0) {
+ ERROR("Failed to parse file '%s'.\n", filename);
+ buffer_delete(&buffer);
return 1;
}
- cbfsfile = create_cbfs_file(param.name, filedata, &filesize,
- param.type, &param.baseaddress);
- free(filedata);
+ if (cbfs_image_from_file(&image, cbfs_name) != 0) {
+ ERROR("Could not load ROM image '%s'.\n", cbfs_name);
+ buffer_delete(&buffer);
+ return 1;
+ }
- if (add_file_to_cbfs(cbfsfile, filesize, param.baseaddress)) {
- ERROR("Adding file '%s' failed.\n", param.filename);
- free(cbfsfile);
- free(rom);
+ if (cbfs_get_entry(&image, name)) {
+ ERROR("'%s' already in ROM image.\n", name);
+ buffer_delete(&buffer);
+ cbfs_image_delete(&image);
return 1;
}
- if (writerom(param.cbfs_name, rom, romsize)) {
- free(cbfsfile);
- free(rom);
+
+ if (cbfs_add_entry(&image, &buffer, name, type, offset) != 0) {
+ ERROR("Failed to add '%s' into ROM image.\n", filename);
+ buffer_delete(&buffer);
+ cbfs_image_delete(&image);
return 1;
}
- free(cbfsfile);
- free(rom);
+ if (cbfs_image_write_file(&image, cbfs_name) != 0) {
+ buffer_delete(&buffer);
+ cbfs_image_delete(&image);
+ return 1;
+ }
+
+ buffer_delete(&buffer);
+ cbfs_image_delete(&image);
return 0;
}
+static int cbfs_add(void)
+{
+ return cbfs_add_component(param.cbfs_name,
+ param.filename,
+ param.name,
+ param.type,
+ param.baseaddress,
+ NULL);
+}
+
static int cbfs_add_payload(void)
{
uint32_t filesize = 0;