From 9341acda13aa2e8d8df4f04f80c14ace52f9aa27 Mon Sep 17 00:00:00 2001 From: Patrick Georgi Date: Wed, 23 Dec 2009 12:52:56 +0000 Subject: Tiny Bootblock, step 1/n. Introduce the tiny bootblock infrastructure and use it on QEmu. Signed-off-by: Patrick Georgi Acked-by: Myles Watson Acked-by: Ronald G. Minnich git-svn-id: svn://svn.coreboot.org/coreboot/trunk@4989 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1 --- util/cbfstool/cbfs-mkstage.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'util') diff --git a/util/cbfstool/cbfs-mkstage.c b/util/cbfstool/cbfs-mkstage.c index 693d7cc099..6e8daef508 100644 --- a/util/cbfstool/cbfs-mkstage.c +++ b/util/cbfstool/cbfs-mkstage.c @@ -122,6 +122,10 @@ int parse_elf_to_stage(unsigned char *input, unsigned char **output, mem_end = mend; } + if (data_start < *location) { + data_start = *location; + } + /* allocate an intermediate buffer for the data */ buffer = calloc(data_end - data_start, 1); @@ -133,6 +137,7 @@ int parse_elf_to_stage(unsigned char *input, unsigned char **output, /* Copy the file data into the buffer */ for (i = 0; i < headers; i++) { + unsigned int l_start, l_offset = 0; if (elf32_to_native(phdr[i].p_type) != PT_LOAD) continue; @@ -140,9 +145,15 @@ int parse_elf_to_stage(unsigned char *input, unsigned char **output, if (elf32_to_native(phdr[i].p_memsz) == 0) continue; - memcpy(buffer + (elf32_to_native(phdr[i].p_paddr) - data_start), - &header[elf32_to_native(phdr[i].p_offset)], - elf32_to_native(phdr[i].p_filesz)); + l_start = elf32_to_native(phdr[i].p_paddr); + if (l_start < *location) { + l_offset = *location - l_start; + l_start = *location; + } + + memcpy(buffer + (l_start - data_start), + &header[elf32_to_native(phdr[i].p_offset)+l_offset], + elf32_to_native(phdr[i].p_filesz)-l_offset); } /* Now make the output buffer */ -- cgit v1.2.3