From e3260a042f438cedb446c5e7b3dc6f55a3b9aa95 Mon Sep 17 00:00:00 2001 From: Sol Boucher Date: Wed, 25 Mar 2015 13:40:08 -0700 Subject: cbfstool: Restructure around support for reading/writing portions of files The buffer API that cbfstool uses to read and write files only directly supports one-shot operations on whole files. This adds an intermediate partitioned_file module that sits on top of the buffer system and has an awareness of FMAP entries. It provides an easy way to get a buffer for an individual region of a larger image file based on FMAP section name, as well as incrementally write those smaller buffers back to the backing file at the appropriate offset. The module has two distinct modes of operation: - For new images whose layout is described exclusively by an FMAP section, all the aforementioned functionality will be available. - For images in the current format, where the CBFS master header serves as the root of knowledge of the image's size and layout, the module falls back to a legacy operation mode, where it only allows manipulation of the entire image as one unit, but exposes this support through the same interface by mapping the region named SECTION_NAME_PRIMARY_CBFS ("COREBOOT") to the whole file. The tool is presently only ported onto the new module running in legacy mode: higher-level support for true "partitioned" images will be forthcoming. However, as part of this change, the crusty cbfs_image_from_file() and cbfs_image_write_file() abstractions are removed and replaced with a single cbfs_image function, cbfs_image_from_buffer(), as well as centralized image reading/writing directly in cbfstool's main() function. This reduces the boilerplate required to implement each new action, makes the create action much more similar to the others, and will make implementing additional actions and adding in support for the new format much easier. BUG=chromium:470407 TEST=Build panther and nyan_big coreboot.rom images with and without this patch and diff their hexdumps. Ensure that no differences occur at different locations from the diffs between subsequent builds of an identical source tree. Then flash a full new build onto nyan_big and watch it boot normally. BRANCH=None Change-Id: I25578c7b223bc8434c3074cb0dd8894534f8c500 Signed-off-by: Sol Boucher Original-Commit-Id: 7e1c96a48e7a27fc6b90289d35e6e169d5e7ad20 Original-Change-Id: Ia4a1a4c48df42b9ec2d6b9471b3a10eb7b24bb39 Original-Signed-off-by: Sol Boucher Original-Reviewed-on: https://chromium-review.googlesource.com/265581 Original-Reviewed-by: Aaron Durbin Reviewed-on: http://review.coreboot.org/10134 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi --- util/cbfstool/cbfs_image.h | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'util/cbfstool/cbfs_image.h') diff --git a/util/cbfstool/cbfs_image.h b/util/cbfstool/cbfs_image.h index 51d06dca23..ddee3a7efc 100644 --- a/util/cbfstool/cbfs_image.h +++ b/util/cbfstool/cbfs_image.h @@ -38,30 +38,29 @@ void cbfs_put_header(void *dest, const struct cbfs_header *header); void cbfs_get_header(struct cbfs_header *header, void *src); /* Creates an empty CBFS image by given size, and description to its content - * (bootblock, align, header location, starting offset of CBFS entries. + * (bootblock, align, header location, starting offset of CBFS entries). * The output image will contain a valid cbfs_header, with one cbfs_file * entry with type CBFS_COMPONENT_NULL, with max available size. * Returns 0 on success, otherwise none-zero. */ int cbfs_image_create(struct cbfs_image *image, uint32_t arch, - size_t size, uint32_t align, struct buffer *bootblock, uint32_t bootblock_offset, uint32_t header_offset, uint32_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, uint32_t offset); +/* Constructs a cbfs_image from a buffer. The resulting image contains a shallow + * copy of the buffer; releasing either one is the legal way to clean up after + * both of them at once. Always produces a cbfs_image, but... + * Returns 0 if it contains a valid CBFS, non-zero if it's unrecognized data. */ +int cbfs_image_from_buffer(struct cbfs_image *out, struct buffer *in, + uint32_t offset); /* Create a duplicate CBFS image. Returns 0 on success, otherwise non-zero. */ int cbfs_copy_instance(struct cbfs_image *image, size_t copy_offset, size_t copy_size); -/* 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); - /* Releases the CBFS image. Returns 0 on success, otherwise non-zero. */ int cbfs_image_delete(struct cbfs_image *image); -- cgit v1.2.3