summaryrefslogtreecommitdiffstats
path: root/util/cbfstool/common.h
diff options
context:
space:
mode:
authorSol Boucher <solb@chromium.org>2015-03-25 13:40:08 -0700
committerPatrick Georgi <pgeorgi@google.com>2015-05-08 20:25:20 +0200
commite3260a042f438cedb446c5e7b3dc6f55a3b9aa95 (patch)
tree56149aa77d5dfcb9eb57081e890711a1e3470d40 /util/cbfstool/common.h
parent64c6cd73f3567e893a9cde7d08eb5505c1a19c62 (diff)
downloadcoreboot-e3260a042f438cedb446c5e7b3dc6f55a3b9aa95.tar.gz
coreboot-e3260a042f438cedb446c5e7b3dc6f55a3b9aa95.tar.bz2
coreboot-e3260a042f438cedb446c5e7b3dc6f55a3b9aa95.zip
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 <solb@chromium.org> Original-Commit-Id: 7e1c96a48e7a27fc6b90289d35e6e169d5e7ad20 Original-Change-Id: Ia4a1a4c48df42b9ec2d6b9471b3a10eb7b24bb39 Original-Signed-off-by: Sol Boucher <solb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/265581 Original-Reviewed-by: Aaron Durbin <adurbin@chromium.org> Reviewed-on: http://review.coreboot.org/10134 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
Diffstat (limited to 'util/cbfstool/common.h')
-rw-r--r--util/cbfstool/common.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/util/cbfstool/common.h b/util/cbfstool/common.h
index 0cf6b6e31f87..416d0a44d4be 100644
--- a/util/cbfstool/common.h
+++ b/util/cbfstool/common.h
@@ -20,8 +20,10 @@
#ifndef __CBFSTOOL_COMMON_H
#define __CBFSTOOL_COMMON_H
+#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
+#include <string.h>
#include <assert.h>
/* Endianess */
@@ -121,6 +123,15 @@ static inline void buffer_seek(struct buffer *b, size_t size)
b->data += size;
}
+/* Returns whether the buffer begins with the specified magic bytes. */
+static inline bool buffer_check_magic(const struct buffer *b, const char *magic,
+ size_t magic_len)
+{
+ assert(magic);
+ return b && b->size >= magic_len &&
+ memcmp(b->data, magic, magic_len) == 0;
+}
+
/* Creates an empty memory buffer with given size.
* Returns 0 on success, otherwise non-zero. */
int buffer_create(struct buffer *buffer, size_t size, const char *name);