Marty E. Plummer has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/36346 )
Change subject: cbfs: store header offset as absolute value BE from fmap_top
......................................................................
cbfs: store header offset as absolute value BE from fmap_top
Change-Id: Idc99b0c133faa2aa15d06f998e7371d332ffa490
Signed-off-by: Marty E. Plummer <hanetzer(a)startmail.com>
---
M src/lib/cbfs.c
M util/cbfstool/cbfstool.c
2 files changed, 9 insertions(+), 5 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/46/36346/1
diff --git a/src/lib/cbfs.c b/src/lib/cbfs.c
index 91368fb..8fb747f 100644
--- a/src/lib/cbfs.c
+++ b/src/lib/cbfs.c
@@ -296,13 +296,14 @@
size_t fmap_top = ___FMAP__COREBOOT_BASE + ___FMAP__COREBOOT_SIZE;
- /* Find location of header using signed 32-bit offset from
+ /* Find location of header using unsigned 32-bit offset from
* end of CBFS region. */
offset = fmap_top - sizeof(int32_t);
if (rdev_readat(bdev, &rel_offset, offset, sizeof(int32_t)) < 0)
return -1;
- offset = fmap_top + rel_offset;
+ /* Subtract after converting to the native byte ordering */
+ offset = fmap_top - ntohl(rel_offset);
if (rdev_readat(bdev, &header, offset, sizeof(header)) < 0)
return -1;
diff --git a/util/cbfstool/cbfstool.c b/util/cbfstool/cbfstool.c
index 65c5e08..c829005 100644
--- a/util/cbfstool/cbfstool.c
+++ b/util/cbfstool/cbfstool.c
@@ -285,8 +285,8 @@
static void fill_header_offset(void *location, uint32_t offset)
{
- // TODO: When we have a BE target, we'll need to store this as BE
- write_le32(location, offset);
+ // Store as BE as all other cbfs data structures are
+ write_be32(location, offset);
}
static int update_master_header_loc_topswap(struct cbfs_image *image,
@@ -380,7 +380,10 @@
uint32_t header_offset = CBFS_SUBHEADER(entry) -
buffer_get(&image.buffer);
- header_offset = -(buffer_size(&image.buffer) - header_offset);
+ /* Store as absolute value (positive) and subtract
+ * it in src/lib/cbfs.c:cbfs_master_header_props
+ */
+ header_offset = buffer_size(&image.buffer) - header_offset;
h_loc = (void *)(buffer_get(&image.buffer) +
buffer_size(&image.buffer) - 4);
--
To view, visit https://review.coreboot.org/c/coreboot/+/36346
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Change-Id: Idc99b0c133faa2aa15d06f998e7371d332ffa490
Gerrit-Change-Number: 36346
Gerrit-PatchSet: 1
Gerrit-Owner: Marty E. Plummer <hanetzer(a)startmail.com>
Gerrit-MessageType: newchange