aboutsummaryrefslogtreecommitdiff
path: root/util/cbfstool/cbfs-mkstage.c
diff options
context:
space:
mode:
authorHung-Te Lin <hungte@chromium.org>2013-01-29 15:22:11 +0800
committerStefan Reinauer <stefan.reinauer@coreboot.org>2013-02-05 22:27:20 +0100
commitc13e4bf3e16080993fb42399327501201c4f9f13 (patch)
tree40eaf22d9c69ea3409bfb812e9aff61a5f3e4902 /util/cbfstool/cbfs-mkstage.c
parent5f3eb26d857628615e6c92180a2dc2213011dd09 (diff)
cbfstool: Use cbfs_image API for "add-*" (add-payload, add-stage, ...) commands.
add-payload, add-stage, and add-flat-binary are now all using cbfs_image API. To test: cbfstool coreboot.rom add-stage -f FILE -n fallback/romstage -b 0xXXXX cbfstool coreboot.rom add-payload -f FILE -n fallback/pyload And compare with old cbfstool. Verified to boot on ARM(snow) and X86(qemu-i386). Change-Id: If65cb495c476ef6f9d90c778531f0c3caf178281 Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: http://review.coreboot.org/2220 Tested-by: build bot (Jenkins) Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
Diffstat (limited to 'util/cbfstool/cbfs-mkstage.c')
-rw-r--r--util/cbfstool/cbfs-mkstage.c32
1 files changed, 16 insertions, 16 deletions
diff --git a/util/cbfstool/cbfs-mkstage.c b/util/cbfstool/cbfs-mkstage.c
index 4374bdadf5..4008367d9d 100644
--- a/util/cbfstool/cbfs-mkstage.c
+++ b/util/cbfstool/cbfs-mkstage.c
@@ -44,13 +44,12 @@ static unsigned int swap32(unsigned int x)
unsigned int (*elf32_to_native) (unsigned int) = idemp;
/* returns size of result, or -1 if error */
-int parse_elf_to_stage(unsigned char *input, unsigned char **output,
- comp_algo algo, uint32_t * location)
+int parse_elf_to_stage(const struct buffer *input, struct buffer *output,
+ comp_algo algo, uint32_t *location)
{
Elf32_Phdr *phdr;
- Elf32_Ehdr *ehdr = (Elf32_Ehdr *) input;
+ Elf32_Ehdr *ehdr = (Elf32_Ehdr *)input->data;
char *header, *buffer;
- unsigned char *out;
int headers;
int i;
@@ -63,12 +62,15 @@ int parse_elf_to_stage(unsigned char *input, unsigned char **output,
if (!compress)
return -1;
- if (!iself(input)) {
+ DEBUG("start: parse_elf_to_stage(location=0x%x)\n", *location);
+ if (!iself((unsigned char *)input->data)) {
ERROR("The stage file is not in ELF format!\n");
return -1;
}
- if (!((ehdr->e_machine == EM_ARM) && (arch == CBFS_ARCHITECTURE_ARMV7)) &&
+ // The tool may work in architecture-independent way.
+ if (arch != CBFS_ARCHITECTURE_UNKNOWN &&
+ !((ehdr->e_machine == EM_ARM) && (arch == CBFS_ARCHITECTURE_ARMV7)) &&
!((ehdr->e_machine == EM_386) && (arch == CBFS_ARCHITECTURE_X86))) {
ERROR("The stage file has the wrong architecture\n");
return -1;
@@ -162,28 +164,26 @@ int parse_elf_to_stage(unsigned char *input, unsigned char **output,
}
/* Now make the output buffer */
- out = calloc(sizeof(struct cbfs_stage) + data_end - data_start, 1);
-
- if (out == NULL) {
+ if (buffer_create(output, sizeof(*stage) + data_end - data_start,
+ input->name) != 0) {
ERROR("Unable to allocate memory: %m\n");
return -1;
}
+ memset(output->data, 0, output->size);
- stage = (struct cbfs_stage *)out;
+ stage = (struct cbfs_stage *)output->data;
stage->load = data_start; /* FIXME: htonll */
stage->memlen = mem_end - data_start;
stage->compression = algo;
stage->entry = ehdr->e_entry; /* FIXME: htonll */
- compress(buffer, data_end - data_start,
- (char *)(out + sizeof(struct cbfs_stage)), (int *)&stage->len);
-
+ compress(buffer, data_end - data_start, (output->data + sizeof(*stage)),
+ (int *)&stage->len);
free(buffer);
- *output = out;
-
if (*location)
*location -= sizeof(struct cbfs_stage);
- return sizeof(struct cbfs_stage) + stage->len;
+ output->size = sizeof(*stage) + stage->len;
+ return 0;
}