Attention is currently required from: Furquan Shaikh, Aaron Durbin.

Julius Werner would like Furquan Shaikh and Aaron Durbin to review this change.

View Change

cbfstool: Remove location pointer from parse_elf_to_stage()

The *location argument to parse_elf_to_stage() is a relic from code all
the way back to 2009 where this function was still used to parse XIP
stages. Nowadays we have a separate parse_elf_to_xip_stage() for that,
so there is no need to heed XIP concerns here. Having a pointer to
represent the location in flash is absolutely irrelevant to a non-XIP
stage, and it is used incorrectly -- we just get lucky that no code path
in cbfstool can currently lead to that value being anything other than
0, otherwise the adjustment of data_start to be no lower than *location
could easily screw things up. This patch removes it.

Signed-off-by: Julius Werner <jwerner@chromium.org>
Change-Id: Ia7f850c0edd7536ed3bef643efaae7271599313d
---
M util/cbfstool/cbfs-mkstage.c
M util/cbfstool/cbfstool.c
M util/cbfstool/common.h
3 files changed, 9 insertions(+), 26 deletions(-)

git pull ssh://review.coreboot.org:29418/coreboot refs/changes/69/49369/1
diff --git a/util/cbfstool/cbfs-mkstage.c b/util/cbfstool/cbfs-mkstage.c
index bfe7bf8..bd1cf54 100644
--- a/util/cbfstool/cbfs-mkstage.c
+++ b/util/cbfstool/cbfs-mkstage.c
@@ -93,8 +93,7 @@
* works for all elf files, not just the restricted set.
*/
int parse_elf_to_stage(const struct buffer *input, struct buffer *output,
- enum cbfs_compression algo, uint32_t *location,
- const char *ignore_section)
+ enum cbfs_compression algo, const char *ignore_section)
{
struct parsed_elf pelf;
Elf64_Phdr *phdr;
@@ -113,8 +112,6 @@
if (!compress)
return -1;

- DEBUG("start: parse_elf_to_stage(location=0x%x)\n", *location);
-
int flags = ELF_PARSE_PHDR | ELF_PARSE_SHDR | ELF_PARSE_STRTAB;

if (parse_elf(input, &pelf, flags)) {
@@ -174,10 +171,6 @@
virt_to_phys = phdr[i].p_paddr - phdr[i].p_vaddr;
}

- if (data_start < *location) {
- data_start = *location;
- }
-
if (data_end <= data_start) {
ERROR("data ends (%08lx) before it starts (%08lx). Make sure "
"the ELF file is correct and resides in ROM space.\n",
@@ -196,27 +189,19 @@
/* Copy the file data into the buffer */

for (i = 0; i < headers; i++) {
- uint64_t l_start, l_offset = 0;
-
if (phdr[i].p_type != PT_LOAD)
continue;

if (phdr[i].p_memsz == 0)
continue;

- l_start = phdr[i].p_paddr;
- if (l_start < *location) {
- l_offset = *location - l_start;
- l_start = *location;
- }
-
/* A legal ELF file can have a program header with
* non-zero length but zero-length file size and a
* non-zero offset which, added together, are > than
* input->size (i.e. the total file size). So we need
* to not even test in the case that p_filesz is zero.
*/
- if (! phdr[i].p_filesz)
+ if (!phdr[i].p_filesz)
continue;
if (input->size < (phdr[i].p_offset + phdr[i].p_filesz)){
ERROR("Underflow copying out the segment."
@@ -225,9 +210,9 @@
free(buffer);
goto err;
}
- memcpy(buffer + (l_start - data_start),
- &input->data[phdr[i].p_offset + l_offset],
- phdr[i].p_filesz - l_offset);
+ memcpy(buffer + (phdr[i].p_paddr - data_start),
+ &input->data[phdr[i].p_offset],
+ phdr[i].p_filesz);
}

/* Now make the output buffer */
@@ -303,8 +288,6 @@
fill_cbfs_stage(&outheader, algo, ehdr->e_entry + virt_to_phys,
data_start, outlen, mem_end - data_start);

- if (*location)
- *location -= sizeof(struct cbfs_stage);
output->size = sizeof(struct cbfs_stage) + outlen;
ret = 0;

diff --git a/util/cbfstool/cbfstool.c b/util/cbfstool/cbfstool.c
index bda1c2f..e1eccc5 100644
--- a/util/cbfstool/cbfstool.c
+++ b/util/cbfstool/cbfstool.c
@@ -1113,9 +1113,10 @@

ret = parse_elf_to_xip_stage(buffer, &output, offset,
param.ignore_section);
- } else
+ } else {
ret = parse_elf_to_stage(buffer, &output, param.compression,
- offset, param.ignore_section);
+ param.ignore_section);
+ }

if (ret != 0)
return -1;
diff --git a/util/cbfstool/common.h b/util/cbfstool/common.h
index 1c83045..db9c7e7 100644
--- a/util/cbfstool/common.h
+++ b/util/cbfstool/common.h
@@ -174,8 +174,7 @@
enum cbfs_compression algo);
/* cbfs-mkstage.c */
int parse_elf_to_stage(const struct buffer *input, struct buffer *output,
- enum cbfs_compression algo, uint32_t *location,
- const char *ignore_section);
+ enum cbfs_compression algo, const char *ignore_section);
/* location is TOP aligned. */
int parse_elf_to_xip_stage(const struct buffer *input, struct buffer *output,
uint32_t *location, const char *ignore_section);

To view, visit change 49369. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Change-Id: Ia7f850c0edd7536ed3bef643efaae7271599313d
Gerrit-Change-Number: 49369
Gerrit-PatchSet: 1
Gerrit-Owner: Julius Werner <jwerner@chromium.org>
Gerrit-Reviewer: Aaron Durbin <adurbin@chromium.org>
Gerrit-Reviewer: Furquan Shaikh <furquan@google.com>
Gerrit-Attention: Furquan Shaikh <furquan@google.com>
Gerrit-Attention: Aaron Durbin <adurbin@chromium.org>
Gerrit-MessageType: newchange