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>
This commit is contained in:
parent
4acd8ea778
commit
ca63027ef7
|
@ -50,6 +50,23 @@ void xdr_segs(struct buffer *output,
|
||||||
xdr_be.put32(&outheader, segs[i].mem_len);
|
xdr_be.put32(&outheader, segs[i].mem_len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void xdr_get_seg(struct cbfs_payload_segment *out,
|
||||||
|
struct cbfs_payload_segment *in)
|
||||||
|
{
|
||||||
|
struct buffer inheader;
|
||||||
|
|
||||||
|
inheader.data = (void *)in;
|
||||||
|
inheader.size = sizeof(*in);
|
||||||
|
|
||||||
|
out->type = xdr_be.get32(&inheader);
|
||||||
|
out->compression = xdr_be.get32(&inheader);
|
||||||
|
out->offset = xdr_be.get32(&inheader);
|
||||||
|
out->load_addr = xdr_be.get64(&inheader);
|
||||||
|
out->len = xdr_be.get32(&inheader);
|
||||||
|
out->mem_len = xdr_be.get32(&inheader);
|
||||||
|
}
|
||||||
|
|
||||||
int parse_elf_to_payload(const struct buffer *input,
|
int parse_elf_to_payload(const struct buffer *input,
|
||||||
struct buffer *output, uint32_t arch, comp_algo algo)
|
struct buffer *output, uint32_t arch, comp_algo algo)
|
||||||
{
|
{
|
||||||
|
|
|
@ -131,5 +131,7 @@ void cbfs_file_get_header(struct buffer *buf, struct cbfs_file *file);
|
||||||
/* cbfs-mkpayload.c */
|
/* cbfs-mkpayload.c */
|
||||||
void xdr_segs(struct buffer *output,
|
void xdr_segs(struct buffer *output,
|
||||||
struct cbfs_payload_segment *segs, int nseg);
|
struct cbfs_payload_segment *segs, int nseg);
|
||||||
|
void xdr_get_seg(struct cbfs_payload_segment *out,
|
||||||
|
struct cbfs_payload_segment *in);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -595,34 +595,40 @@ static int cbfs_print_stage_info(struct cbfs_stage *stage, FILE* fp)
|
||||||
return 0;
|
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)
|
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_CODE:
|
||||||
case PAYLOAD_SEGMENT_DATA:
|
case PAYLOAD_SEGMENT_DATA:
|
||||||
fprintf(fp, " %s (%s compression, offset: 0x%x, "
|
fprintf(fp, " %s (%s compression, offset: 0x%x, "
|
||||||
"load: 0x%" PRIx64 ", length: %d/%d)\n",
|
"load: 0x%" PRIx64 ", length: %d/%d)\n",
|
||||||
(payload->type == PAYLOAD_SEGMENT_CODE ?
|
(payload.type == PAYLOAD_SEGMENT_CODE ?
|
||||||
"code " : "data"),
|
"code " : "data"),
|
||||||
lookup_name_by_type(types_cbfs_compression,
|
lookup_name_by_type(types_cbfs_compression,
|
||||||
ntohl(payload->compression),
|
payload.compression,
|
||||||
"(unknown)"),
|
"(unknown)"),
|
||||||
ntohl(payload->offset),
|
payload.offset,
|
||||||
ntohll(payload->load_addr),
|
payload.load_addr,
|
||||||
ntohl(payload->len), ntohl(payload->mem_len));
|
payload.len, payload.mem_len);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PAYLOAD_SEGMENT_ENTRY:
|
case PAYLOAD_SEGMENT_ENTRY:
|
||||||
fprintf(fp, " entry (0x%" PRIx64 ")\n",
|
fprintf(fp, " entry (0x%" PRIx64 ")\n",
|
||||||
ntohll(payload->load_addr));
|
payload.load_addr);
|
||||||
|
return 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PAYLOAD_SEGMENT_BSS:
|
case PAYLOAD_SEGMENT_BSS:
|
||||||
fprintf(fp, " BSS (address 0x%016" PRIx64 ", "
|
fprintf(fp, " BSS (address 0x%016" PRIx64 ", "
|
||||||
"length 0x%x)\n",
|
"length 0x%x)\n",
|
||||||
ntohll(payload->load_addr),
|
payload.load_addr,
|
||||||
ntohl(payload->len));
|
payload.len);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PAYLOAD_SEGMENT_PARAMS:
|
case PAYLOAD_SEGMENT_PARAMS:
|
||||||
|
@ -632,14 +638,14 @@ static int cbfs_print_payload_segment_info(struct cbfs_payload_segment *payload,
|
||||||
default:
|
default:
|
||||||
fprintf(fp, " 0x%x (%s compression, offset: 0x%x, "
|
fprintf(fp, " 0x%x (%s compression, offset: 0x%x, "
|
||||||
"load: 0x%" PRIx64 ", length: %d/%d\n",
|
"load: 0x%" PRIx64 ", length: %d/%d\n",
|
||||||
payload->type,
|
payload.type,
|
||||||
lookup_name_by_type(types_cbfs_compression,
|
lookup_name_by_type(types_cbfs_compression,
|
||||||
payload->compression,
|
payload.compression,
|
||||||
"(unknown)"),
|
"(unknown)"),
|
||||||
ntohl(payload->offset),
|
payload.offset,
|
||||||
ntohll(payload->load_addr),
|
payload.load_addr,
|
||||||
ntohl(payload->len),
|
payload.len,
|
||||||
ntohl(payload->mem_len));
|
payload.mem_len);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -685,11 +691,11 @@ int cbfs_print_entry_info(struct cbfs_image *image, struct cbfs_file *entry,
|
||||||
payload = (struct cbfs_payload_segment *)
|
payload = (struct cbfs_payload_segment *)
|
||||||
CBFS_SUBHEADER(entry);
|
CBFS_SUBHEADER(entry);
|
||||||
while (payload) {
|
while (payload) {
|
||||||
cbfs_print_payload_segment_info(payload, fp);
|
/* Stop when PAYLOAD_SEGMENT_ENTRY seen. */
|
||||||
if (payload->type == PAYLOAD_SEGMENT_ENTRY)
|
if (cbfs_print_payload_segment_info(payload,
|
||||||
|
fp))
|
||||||
break;
|
break;
|
||||||
else
|
payload ++;
|
||||||
payload ++;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in New Issue