summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Georgi <pgeorgi@chromium.org>2015-09-11 18:34:39 +0200
committerPatrick Georgi <pgeorgi@google.com>2015-09-28 10:13:33 +0000
commit2f953d304e02be9a2f4f6fbd86b41dd6c86ec5db (patch)
tree5653a8068aa81a15d5ef3a8b462137526a0d85e4
parent6dd99fcafe83fed2632a90821de6373516c14a0c (diff)
downloadcoreboot-2f953d304e02be9a2f4f6fbd86b41dd6c86ec5db.tar.xz
cbfstool: prefer fmap data over cbfs master header if it exists
Up to now, if both fmap and a master header existed, the master header was used. Now, use the master header only if no fmap is found. Change-Id: Iafbf2c9dc325597e23a9780b495549b5d912e9ad Signed-off-by: Patrick Georgi <pgeorgi@chromium.org> Reviewed-on: http://review.coreboot.org/11629 Tested-by: build bot (Jenkins) Reviewed-by: Aaron Durbin <adurbin@chromium.org>
-rw-r--r--util/cbfstool/cbfs_image.c12
-rw-r--r--util/cbfstool/cbfstool.c9
-rw-r--r--util/cbfstool/partitioned_file.c15
-rw-r--r--util/cbfstool/partitioned_file.h24
4 files changed, 14 insertions, 46 deletions
diff --git a/util/cbfstool/cbfs_image.c b/util/cbfstool/cbfs_image.c
index 55f80844db..24ab0c4977 100644
--- a/util/cbfstool/cbfs_image.c
+++ b/util/cbfstool/cbfs_image.c
@@ -343,20 +343,22 @@ int cbfs_image_from_buffer(struct cbfs_image *out, struct buffer *in,
buffer_clone(&out->buffer, in);
out->has_header = false;
+ if (cbfs_is_valid_cbfs(out)) {
+ return 0;
+ }
+
void *header_loc = cbfs_find_header(in->data, in->size, offset);
if (header_loc) {
cbfs_get_header(&out->header, header_loc);
out->has_header = true;
cbfs_fix_legacy_size(out, header_loc);
+ return 0;
} else if (offset != ~0u) {
ERROR("The -H switch is only valid on legacy images having CBFS master headers.\n");
return 1;
- } else if (!cbfs_is_valid_cbfs(out)) {
- ERROR("Selected image region is not a valid CBFS.\n");
- return 1;
}
-
- return 0;
+ ERROR("Selected image region is not a valid CBFS.\n");
+ return 1;
}
int cbfs_copy_instance(struct cbfs_image *image, size_t copy_offset,
diff --git a/util/cbfstool/cbfstool.c b/util/cbfstool/cbfstool.c
index bf589a5a27..35747d3d68 100644
--- a/util/cbfstool/cbfstool.c
+++ b/util/cbfstool/cbfstool.c
@@ -881,12 +881,6 @@ static int cbfs_copy(void)
return cbfs_copy_instance(&image, param.copyoffset, param.size);
}
-static bool cbfs_is_legacy_format(struct buffer *buffer)
-{
- // Legacy CBFSes are those containing the deprecated CBFS master header.
- return cbfs_find_header(buffer->data, buffer->size, -1);
-}
-
static const struct command commands[] = {
{"add", "H:r:f:n:t:c:b:a:vh?", cbfs_add, true, true},
{"add-flat-binary", "H:r:f:n:l:e:c:b:vh?", cbfs_add_flat_binary, true,
@@ -1250,8 +1244,7 @@ int main(int argc, char **argv)
}
} else {
param.image_file =
- partitioned_file_reopen(image_name,
- cbfs_is_legacy_format);
+ partitioned_file_reopen(image_name);
}
if (!param.image_file)
return 1;
diff --git a/util/cbfstool/partitioned_file.c b/util/cbfstool/partitioned_file.c
index 9d67832a54..041ef1168b 100644
--- a/util/cbfstool/partitioned_file.c
+++ b/util/cbfstool/partitioned_file.c
@@ -165,8 +165,7 @@ partitioned_file_t *partitioned_file_create(const char *filename,
return file;
}
-partitioned_file_t *partitioned_file_reopen(const char *filename,
- partitioned_file_flat_decider_t flat_override)
+partitioned_file_t *partitioned_file_reopen(const char *filename)
{
assert(filename);
@@ -174,11 +173,6 @@ partitioned_file_t *partitioned_file_reopen(const char *filename,
if (!file)
return NULL;
- if (flat_override && flat_override(&file->buffer)) {
- INFO("Opening image as a flat file in response to explicit request\n");
- return file;
- }
-
long fmap_region_offset = fmap_find((const uint8_t *)file->buffer.data,
file->buffer.size);
if (fmap_region_offset < 0) {
@@ -365,10 +359,3 @@ static bool select_parents_of(const struct fmap_area *parent, const void *arg)
}
const partitioned_file_fmap_selector_t partitioned_file_fmap_select_parents_of =
select_parents_of;
-
-static bool open_as_flat(unused struct buffer *buffer)
-{
- return true;
-}
-const partitioned_file_flat_decider_t partitioned_file_open_as_flat =
- open_as_flat;
diff --git a/util/cbfstool/partitioned_file.h b/util/cbfstool/partitioned_file.h
index 45833161e4..3698a19b3a 100644
--- a/util/cbfstool/partitioned_file.h
+++ b/util/cbfstool/partitioned_file.h
@@ -28,15 +28,6 @@
typedef struct partitioned_file partitioned_file_t;
-/** @return Whether the specific existing file should be opened in flat mode. */
-typedef bool (*partitioned_file_flat_decider_t)(struct buffer *buffer);
-
-/** Pass to partitioned_file_reopen() to force opening as a partitioned file. */
-#define partitioned_file_open_as_partitioned NULL
-
-/** Pass to partitioned_file_reopen() to force opening as a flat file. */
-extern const partitioned_file_flat_decider_t partitioned_file_open_as_flat;
-
/**
* Create a new filesystem-backed flat buffer.
* This backwards-compatibility function creates a new in-memory buffer and
@@ -76,22 +67,17 @@ partitioned_file_t *partitioned_file_create(const char *filename,
/**
* Read a file back in from the disk.
- * An in-memory buffer is created and populated with the file's contents. If
- * flat_override is NULL and the image contains an FMAP, it will be opened as a
- * full partitioned file; otherwise, it will be opened as a flat file as if it
- * had been created by partitioned_file_create_flat(). This selection behavior
- * is extensible: if a flat_override function is provided, it is invoked before
- * searching for an FMAP, and has the option of explicitly instructing the
- * module to open the image as a flat file based on its contents.
+ * An in-memory buffer is created and populated with the file's
+ * contents. If the image contains an FMAP, it will be opened as a
+ * full partitioned file; otherwise, it will be opened as a flat file as
+ * if it had been created by partitioned_file_create_flat().
* The partitioned_file_t returned from this function is separately owned by the
* caller, and must later be passed to partitioned_file_close();
*
* @param filename Name of the file to read in
- * @param flat_override Callback that can decide to open it as flat, or NULL
* @return Caller-owned partitioned file, or NULL on error
*/
-partitioned_file_t *partitioned_file_reopen(const char *filename,
- partitioned_file_flat_decider_t flat_override);
+partitioned_file_t *partitioned_file_reopen(const char *filename);
/**
* Write a buffer's contents to its original region within a segmented file.