diff options
author | Hung-Te Lin <hungte@chromium.org> | 2013-01-29 02:29:49 +0800 |
---|---|---|
committer | Stefan Reinauer <stefan.reinauer@coreboot.org> | 2013-02-05 22:25:20 +0100 |
commit | 0f8af71f1a40e8ae960ba616cb9a5bf14f10fb13 (patch) | |
tree | 307b6c6ed395745f8769563bb3a32afe0922966a /util/cbfstool/cbfs_image.c | |
parent | 3bb035b095a0e4144adfa55fa45b2332e3a6c7d5 (diff) | |
download | coreboot-0f8af71f1a40e8ae960ba616cb9a5bf14f10fb13.tar.xz |
cbfstool: Use cbfs_image API for "extract" command.
Change the "extract" command to use cbfs_export_entry API. Nothing changed in
its usage.
To verify, run "cbfstool coreboot.rom extract -f blah -n blah" and check if the
raw type file is correctly extracted.
Change-Id: I1ed280d47a2224a9d1213709f6b459b403ce5055
Signed-off-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-on: http://review.coreboot.org/2207
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
Diffstat (limited to 'util/cbfstool/cbfs_image.c')
-rw-r--r-- | util/cbfstool/cbfs_image.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/util/cbfstool/cbfs_image.c b/util/cbfstool/cbfs_image.c index 9fed49424a..7d08b43c79 100644 --- a/util/cbfstool/cbfs_image.c +++ b/util/cbfstool/cbfs_image.c @@ -125,6 +125,47 @@ int cbfs_image_delete(struct cbfs_image *image) { return 0; } +struct cbfs_file *cbfs_get_entry(struct cbfs_image *image, const char *name) { + struct cbfs_file *entry; + for (entry = cbfs_find_first_entry(image); + entry && cbfs_is_valid_entry(entry); + entry = cbfs_find_next_entry(image, entry)) { + if (strcasecmp(CBFS_NAME(entry), name) == 0) { + DEBUG("cbfs_get_entry: found %s\n", name); + return entry; + } + } + return NULL; +} + +int cbfs_export_entry(struct cbfs_image *image, const char *entry_name, + const char *filename) { + struct cbfs_file *entry = cbfs_get_entry(image, entry_name); + struct buffer buffer; + if (!entry) { + ERROR("File not found: %s\n", entry_name); + return -1; + } + LOG("Found file %.30s at 0x%x, type %.12s, size %d\n", + entry_name, cbfs_get_entry_addr(image, entry), + get_cbfs_entry_type_name(ntohl(entry->type)), ntohl(entry->len)); + + if (ntohl(entry->type) != CBFS_COMPONENT_RAW) { + WARN("Only 'raw' files are safe to extract.\n"); + } + + buffer.data = CBFS_SUBHEADER(entry); + buffer.size = ntohl(entry->len); + buffer.name = "(cbfs_export_entry)"; + if (buffer_write_file(&buffer, filename) != 0) { + ERROR("Failed to write %s into %s.\n", + entry_name, filename); + return -1; + } + INFO("Successfully dumped the file to: %s\n", filename); + return 0; +} + int cbfs_print_header_info(struct cbfs_image *image) { char *name = strdup(image->buffer.name); assert(image && image->header); |