summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorHung-Te Lin <hungte@chromium.org>2014-05-16 10:14:05 +0800
committerMarc Jones <marc.jones@se-eng.com>2015-01-03 17:33:13 +0100
commit0780d67ffe8ef754ace0912114e2b1e772554990 (patch)
treedd2b1adf8828b1d1855c8d7cff12be2b34a00d1a /util
parent3ae558f5a1f00aba39621c5d0f042436c5f71789 (diff)
util/cbfstool: Fix byte-ordering for payload type field.
In https://chromium-review.googlesource.com/181272 the payload->type has been changed to big-endian (network ordering) but the cbfs_image is still parsing type as host ordering, which caused printing cbfs image verbosely (cbfstool imge print -v) to fail to find entry field and print numerous garbage output. Payload fields should be always parsed in big-endian (network ordering). BUG=none TEST=make; cbfstool image.bin print -v -v -v # see payloads correctly Original-Change-Id: If1ac355b8847fb54988069f694bd2f317ce49a1a Original-Signed-off-by: Hung-Te Lin <hungte@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/200158 Original-Reviewed-by: Ronald Minnich <rminnich@chromium.org> (cherry picked from commit 423f7dd28f8b071692d57401e144232d5ee2e479) Signed-off-by: Marc Jones <marc.jones@se-eng.com> Change-Id: I5a4694e887c7ff48d8d0713bb5808c29256141a9 Reviewed-on: http://review.coreboot.org/8005 Reviewed-by: Ronald G. Minnich <rminnich@gmail.com> Tested-by: build bot (Jenkins)
Diffstat (limited to 'util')
-rw-r--r--util/cbfstool/cbfs_image.c64
1 files changed, 38 insertions, 26 deletions
diff --git a/util/cbfstool/cbfs_image.c b/util/cbfstool/cbfs_image.c
index 1a522bd655..6775b069dd 100644
--- a/util/cbfstool/cbfs_image.c
+++ b/util/cbfstool/cbfs_image.c
@@ -153,6 +153,22 @@ void cbfs_put_header(void *dest, const struct cbfs_header *header)
xdr_be.put32(&outheader, header->architecture);
}
+static void cbfs_decode_payload_segment(struct cbfs_payload_segment *output,
+ struct cbfs_payload_segment *input)
+{
+ struct buffer seg = {
+ .data = (void *)input,
+ .size = sizeof(*input),
+ };
+ output->type = xdr_be.get32(&seg);
+ output->compression = xdr_be.get32(&seg);
+ output->offset = xdr_be.get32(&seg);
+ output->load_addr = xdr_be.get64(&seg);
+ output->len = xdr_be.get32(&seg);
+ output->mem_len = xdr_be.get32(&seg);
+ assert(seg.size == 0);
+}
+
void cbfs_get_header(struct cbfs_header *header, const void *src)
{
struct buffer outheader;
@@ -596,40 +612,35 @@ static int cbfs_print_stage_info(struct cbfs_stage *stage, FILE* fp)
return 0;
}
-/* Return 1 when segment is of type PAYLOAD_SEGMENT_ENTRY. */
-static int cbfs_print_payload_segment_info(struct cbfs_payload_segment *seg_be,
- FILE *fp)
+static int cbfs_print_decoded_payload_segment_info(
+ struct cbfs_payload_segment *seg, FILE *fp)
{
- struct cbfs_payload_segment payload;
-
- xdr_get_seg(&payload, seg_be);
-
- switch(payload.type) {
+ /* The input (seg) must be already decoded by
+ * cbfs_decode_payload_segment.
+ */
+ switch (seg->type) {
case PAYLOAD_SEGMENT_CODE:
case PAYLOAD_SEGMENT_DATA:
fprintf(fp, " %s (%s compression, offset: 0x%x, "
"load: 0x%" PRIx64 ", length: %d/%d)\n",
- (payload.type == PAYLOAD_SEGMENT_CODE ?
+ (seg->type == PAYLOAD_SEGMENT_CODE ?
"code " : "data"),
lookup_name_by_type(types_cbfs_compression,
- payload.compression,
+ seg->compression,
"(unknown)"),
- payload.offset,
- payload.load_addr,
- payload.len, payload.mem_len);
+ seg->offset, seg->load_addr, seg->len,
+ seg->mem_len);
break;
case PAYLOAD_SEGMENT_ENTRY:
fprintf(fp, " entry (0x%" PRIx64 ")\n",
- payload.load_addr);
- return 1;
+ seg->load_addr);
break;
case PAYLOAD_SEGMENT_BSS:
fprintf(fp, " BSS (address 0x%016" PRIx64 ", "
"length 0x%x)\n",
- payload.load_addr,
- payload.len);
+ seg->load_addr, seg->len);
break;
case PAYLOAD_SEGMENT_PARAMS:
@@ -639,14 +650,12 @@ static int cbfs_print_payload_segment_info(struct cbfs_payload_segment *seg_be,
default:
fprintf(fp, " 0x%x (%s compression, offset: 0x%x, "
"load: 0x%" PRIx64 ", length: %d/%d\n",
- payload.type,
+ seg->type,
lookup_name_by_type(types_cbfs_compression,
- payload.compression,
+ seg->compression,
"(unknown)"),
- payload.offset,
- payload.load_addr,
- payload.len,
- payload.mem_len);
+ seg->offset, seg->load_addr, seg->len,
+ seg->mem_len);
break;
}
return 0;
@@ -692,10 +701,13 @@ int cbfs_print_entry_info(struct cbfs_image *image, struct cbfs_file *entry,
payload = (struct cbfs_payload_segment *)
CBFS_SUBHEADER(entry);
while (payload) {
- /* Stop when PAYLOAD_SEGMENT_ENTRY seen. */
- if (cbfs_print_payload_segment_info(payload,
- fp))
+ struct cbfs_payload_segment seg;
+ cbfs_decode_payload_segment(&seg, payload);
+ cbfs_print_decoded_payload_segment_info(
+ &seg, fp);
+ if (seg.type == PAYLOAD_SEGMENT_ENTRY)
break;
+ else
payload ++;
}
break;