Ronald G. Minnich (rminnich@gmail.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/5120
-gerrit
commit 34c1680c228cb16aba015d424d3c32c20cf0f89e Author: Ronald G. Minnich rminnich@google.com Date: Tue Feb 4 17:35:44 2014 -0800
Add an xdr function for the cbfs_file header
And use it in fit.c and remove one more use of htonl.
Change-Id: Ibf18dcc0a7f08d75c2374115de0db7a4bf64ec1e Signed-off-by: Ronald G. Minnich rminnich@google.com --- util/cbfstool/cbfs.h | 2 +- util/cbfstool/common.c | 9 +++++++++ util/cbfstool/common.h | 1 + util/cbfstool/fit.c | 19 +++++++++++++++---- util/cbfstool/xdr.c | 9 +++++++++ 5 files changed, 35 insertions(+), 5 deletions(-)
diff --git a/util/cbfstool/cbfs.h b/util/cbfstool/cbfs.h index c0de313..2fb0ff2 100644 --- a/util/cbfstool/cbfs.h +++ b/util/cbfstool/cbfs.h @@ -132,7 +132,7 @@ int find_master_header(void *romarea, size_t size); void recalculate_rom_geometry(void *romarea); struct cbfs_file *cbfs_create_empty_file(uint32_t physaddr, uint32_t size); const char *strfiletype(uint32_t number); - +void cbfs_file_get_header(struct buffer *buf, struct cbfs_file *file); /* elfheaders.c */ int elf_headers(const struct buffer *pinput, diff --git a/util/cbfstool/common.c b/util/cbfstool/common.c index e10d9fb..111c9c0 100644 --- a/util/cbfstool/common.c +++ b/util/cbfstool/common.c @@ -283,6 +283,15 @@ int cbfs_file_header(unsigned long physaddr) return (strncmp(phys_to_virt(physaddr), "LARCHIVE", 8) == 0); }
+void cbfs_file_get_header(struct buffer *buf, struct cbfs_file *file) +{ + bgets(buf, &file->magic, sizeof(file->magic)); + file->len = xdr_be.get32(buf); + file->type = xdr_be.get32(buf); + file->checksum = xdr_be.get32(buf); + file->offset = xdr_be.get32(buf); +} + struct cbfs_file *cbfs_create_empty_file(uint32_t physaddr, uint32_t size) { struct cbfs_file *nextfile = (struct cbfs_file *)phys_to_virt(physaddr); diff --git a/util/cbfstool/common.h b/util/cbfstool/common.h index e41618f..46d0bf9 100644 --- a/util/cbfstool/common.h +++ b/util/cbfstool/common.h @@ -143,5 +143,6 @@ struct xdr {
/* xdr.c */ extern struct xdr xdr_le, xdr_be; +int bgets(struct buffer *input, void *output, size_t len);
#endif diff --git a/util/cbfstool/fit.c b/util/cbfstool/fit.c index a368dad..84f0bff 100644 --- a/util/cbfstool/fit.c +++ b/util/cbfstool/fit.c @@ -188,17 +188,28 @@ static void add_microcodde_entries(struct cbfs_image *image, } }
+static int fit_header(void *ptr, uint32_t *current_offset, uint32_t *file_length) +{ + struct buffer buf; + struct cbfs_file header; + buf.data = ptr; + buf.size = sizeof(header); + cbfs_file_get_header(&buf, &header); + *current_offset = header.offset; + *file_length = header.len; + return 0; +} + static int parse_microcode_blob(struct cbfs_image *image, struct cbfs_file *mcode_file, struct microcode_entry *mcus, int *total_mcus) { int num_mcus; - int current_offset; - int file_length; + uint32_t current_offset; + uint32_t file_length;
current_offset = (int)((char *)mcode_file - image->buffer.data); - current_offset += ntohl(mcode_file->offset); - file_length = ntohl(mcode_file->len); + fit_header(mcode_file, ¤t_offset, &file_length);
num_mcus = 0; while (file_length > sizeof(struct microcode_header)) diff --git a/util/cbfstool/xdr.c b/util/cbfstool/xdr.c index d779675..ddc282e 100644 --- a/util/cbfstool/xdr.c +++ b/util/cbfstool/xdr.c @@ -25,6 +25,15 @@ #include <stdint.h> #include "common.h"
+int bgets(struct buffer *input, void *output, size_t len) +{ + len = input->size < len ? input->size : len; + memmove(output, input->data, len); + input->data += len; + input->size -= len; + return len; +} + /* The assumption in all this code is that we're given a pointer to enough data. * Hence, we do not check for underflow. */