From 458a12e52beb9dfcb1884dfad6effa8b3d98e8a4 Mon Sep 17 00:00:00 2001 From: Vadim Bendebury Date: Tue, 23 Dec 2014 15:10:12 -0800 Subject: cbfstool: allow user to explicitly specify header location There potentially could be multiple CBFS instances present in the firmware image. cbfstool should be able to operate on any of them, not just the first one present. To accomplish that, allow all CBFS commands to accept the -H parameter (which specifies the exact CBFS header location in the image). If this parameter is specified, the image is not searched for the CBFS header, only the specified location is checked for validity, If the location is valid, it is considered to be the CBFS header, if not - the tool exits with an error status. Note, that default behavior of the tool does not change. BRANCH=storm BUG=chrome-os-partner:34161, chromium:445938 TEST=run the following experiments: - examined an image with three CBFS instances, was able to print all of them. - built a rambi coreboot image and tried the following (cbfstool output abbreviated): $ ./util/cbfstool/cbfstool /build/rambi/firmware/coreboot.rom print coreboot.rom: 8192 kB, bootblocksize 2448, romsize 8388608, offset 0x700000 alignment: 64 bytes, architecture: x86 Name Offset Type Size cmos_layout.bin 0x700000 cmos_layout 1164 ... (empty) 0x7ec600 null 77848 $ \od -tx4 -Ax /build/rambi/firmware/coreboot.rom | tail -2 7ffff0 fff67de9 000000ff fff6dfe9 fffff650 800000 $ ./util/cbfstool/cbfstool /build/rambi/firmware/coreboot.rom print -H 0x7ff650 coreboot.rom: 8192 kB, bootblocksize 2448, romsize 8388608, offset 0x700000 alignment: 64 bytes, architecture: x86 Name Offset Type Size cmos_layout.bin 0x700000 cmos_layout 1164 ... (empty) 0x7ec600 null 77848 $ ./util/cbfstool/cbfstool /build/rambi/firmware/coreboot.rom print -H 0x7ff654 E: /build/rambi/firmware/coreboot.rom does not have CBFS master header. E: Could not load ROM image '/build/rambi/firmware/coreboot.rom'. $ Change-Id: I64cbdc79096f3c7a113762b641305542af7bbd60 Signed-off-by: Patrick Georgi Original-Commit-Id: 86b88222df6eed25bb176d653305e2e57e18b73a Original-Change-Id: I486092e222c96c65868ae7d41a9e8976ffcc93c4 Original-Signed-off-by: Vadim Bendebury Original-Reviewed-on: https://chromium-review.googlesource.com/237485 Original-Reviewed-by: David Hendricks Original-Reviewed-by: Patrick Georgi Original-Reviewed-by: Stefan Reinauer Reviewed-on: http://review.coreboot.org/9741 Tested-by: build bot (Jenkins) Reviewed-by: Stefan Reinauer --- util/cbfstool/cbfs_image.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'util/cbfstool/cbfs_image.h') diff --git a/util/cbfstool/cbfs_image.h b/util/cbfstool/cbfs_image.h index 0a05eb2841..2c1be3da1c 100644 --- a/util/cbfstool/cbfs_image.h +++ b/util/cbfstool/cbfs_image.h @@ -52,7 +52,8 @@ int cbfs_image_create(struct cbfs_image *image, int32_t entries_offset); /* Loads a CBFS image from file. Returns 0 on success, otherwise non-zero. */ -int cbfs_image_from_file(struct cbfs_image *image, const char *filename); +int cbfs_image_from_file(struct cbfs_image *image, + const char *filename, uint32_t offset); /* Writes a CBFS image into file. Returns 0 on success, otherwise non-zero. */ int cbfs_image_write_file(struct cbfs_image *image, const char *filename); @@ -106,7 +107,8 @@ int cbfs_walk(struct cbfs_image *image, cbfs_entry_callback callback, void *arg) * NULL (including when multiple headers were found). If there is a X86 ROM * style signature (pointer at 0xfffffffc) found in ROM, it will be selected as * the only header.*/ -struct cbfs_header *cbfs_find_header(char *data, size_t size); +struct cbfs_header *cbfs_find_header(char *data, size_t size, + uint32_t forced_offset); /* Returns the first cbfs_file entry in CBFS image by CBFS header (no matter if * the entry has valid content or not), otherwise NULL. */ -- cgit v1.2.3