Skip to content

Commit

Permalink
Add an xdr function for the cbfs_file header
Browse files Browse the repository at this point in the history
And use it in fit.c and remove one more use of htonl.

Change-Id: Ibf18dcc0a7f08d75c2374115de0db7a4bf64ec1e
Signed-off-by: Ronald G. Minnich <[email protected]>
Reviewed-on: http://review.coreboot.org/5120
Tested-by: build bot (Jenkins)
Reviewed-by: Ronald G. Minnich <[email protected]>
  • Loading branch information
rminnichcodeu authored and rminnich committed Feb 5, 2014
1 parent c625d09 commit 3fcde22
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
3 changes: 3 additions & 0 deletions util/cbfstool/cbfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ uint32_t get_cbfs_entry_type(const char *name, uint32_t default_value);
const char *get_cbfs_entry_type_name(uint32_t type);
uint32_t get_cbfs_compression(const char *name, uint32_t unknown);

/* common.c */
void cbfs_file_get_header(struct buffer *buf, struct cbfs_file *file);

/* elfheaders.c */
int
elf_headers(const struct buffer *pinput,
Expand Down
9 changes: 9 additions & 0 deletions util/cbfstool/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ void buffer_delete(struct buffer *buffer) {
buffer->size = 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);
}

static struct {
uint32_t arch;
const char *name;
Expand Down
1 change: 1 addition & 0 deletions util/cbfstool/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,6 @@ struct xdr {

/* xdr.c */
extern struct xdr xdr_le, xdr_be;
int bgets(struct buffer *input, void *output, size_t len);

#endif
19 changes: 15 additions & 4 deletions util/cbfstool/fit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, &current_offset, &file_length);

num_mcus = 0;
while (file_length > sizeof(struct microcode_header))
Expand Down
9 changes: 9 additions & 0 deletions util/cbfstool/xdr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down

0 comments on commit 3fcde22

Please sign in to comment.