diff options
author | Aaron Durbin <adurbin@chromium.org> | 2014-08-05 10:48:20 -0500 |
---|---|---|
committer | Aaron Durbin <adurbin@google.com> | 2014-08-07 19:05:43 +0200 |
commit | ca63027ef7627ba60f6776f2c9bd373cdb2afbb0 (patch) | |
tree | 19234899f0ad46d2b29f43d8ba87ecc3efdf6d5e /util/cbfstool/cbfs_image.c | |
parent | 4acd8ea778388392475ee14cb5efe5f453da3159 (diff) | |
download | coreboot-ca63027ef7627ba60f6776f2c9bd373cdb2afbb0.tar.xz |
cbfstool: process cbfs_payload_segment(s) in host byte order
The printing routines of the cbfs_payload_segment assumed the type
could be accessed in host order. Each of the fields need to be
converted to the host order before inspecting the fields. In addition,
this removes all the ntoh*() calls while processing the
cbfs_payload_segment structures.
cbfstool would crash adding entries or just printing entries
containing a payload when -v was passed on the command line.
Change-Id: Iff41c64a99001b9e3920e2e26828c5fd6e671239
Signed-off-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-on: http://review.coreboot.org/6498
Tested-by: build bot (Jenkins)
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
Reviewed-by: Martin Roth <gaumless@gmail.com>
Diffstat (limited to 'util/cbfstool/cbfs_image.c')
-rw-r--r-- | util/cbfstool/cbfs_image.c | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/util/cbfstool/cbfs_image.c b/util/cbfstool/cbfs_image.c index 12bc2fe74e..afe1298130 100644 --- a/util/cbfstool/cbfs_image.c +++ b/util/cbfstool/cbfs_image.c @@ -595,34 +595,40 @@ static int cbfs_print_stage_info(struct cbfs_stage *stage, FILE* fp) return 0; } -static int cbfs_print_payload_segment_info(struct cbfs_payload_segment *payload, +/* 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) { - switch(payload->type) { + struct cbfs_payload_segment payload; + + xdr_get_seg(&payload, seg_be); + + switch(payload.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 ? + (payload.type == PAYLOAD_SEGMENT_CODE ? "code " : "data"), lookup_name_by_type(types_cbfs_compression, - ntohl(payload->compression), + payload.compression, "(unknown)"), - ntohl(payload->offset), - ntohll(payload->load_addr), - ntohl(payload->len), ntohl(payload->mem_len)); + payload.offset, + payload.load_addr, + payload.len, payload.mem_len); break; case PAYLOAD_SEGMENT_ENTRY: fprintf(fp, " entry (0x%" PRIx64 ")\n", - ntohll(payload->load_addr)); + payload.load_addr); + return 1; break; case PAYLOAD_SEGMENT_BSS: fprintf(fp, " BSS (address 0x%016" PRIx64 ", " "length 0x%x)\n", - ntohll(payload->load_addr), - ntohl(payload->len)); + payload.load_addr, + payload.len); break; case PAYLOAD_SEGMENT_PARAMS: @@ -632,14 +638,14 @@ static int cbfs_print_payload_segment_info(struct cbfs_payload_segment *payload, default: fprintf(fp, " 0x%x (%s compression, offset: 0x%x, " "load: 0x%" PRIx64 ", length: %d/%d\n", - payload->type, + payload.type, lookup_name_by_type(types_cbfs_compression, - payload->compression, + payload.compression, "(unknown)"), - ntohl(payload->offset), - ntohll(payload->load_addr), - ntohl(payload->len), - ntohl(payload->mem_len)); + payload.offset, + payload.load_addr, + payload.len, + payload.mem_len); break; } return 0; @@ -685,11 +691,11 @@ int cbfs_print_entry_info(struct cbfs_image *image, struct cbfs_file *entry, payload = (struct cbfs_payload_segment *) CBFS_SUBHEADER(entry); while (payload) { - cbfs_print_payload_segment_info(payload, fp); - if (payload->type == PAYLOAD_SEGMENT_ENTRY) + /* Stop when PAYLOAD_SEGMENT_ENTRY seen. */ + if (cbfs_print_payload_segment_info(payload, + fp)) break; - else - payload ++; + payload ++; } break; default: |