summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorJulius Werner <jwerner@chromium.org>2021-01-12 15:21:03 -0800
committerJulius Werner <jwerner@chromium.org>2021-02-18 02:32:28 +0000
commitff61a39e90e0f8cb94a3dd015a2ebd6cae728cc6 (patch)
treea61e4d212aa5ac7522a337151bbea807403c7fbf /util
parent84446e6e54fa9df42fcbb8450c9a071feaf1f8d0 (diff)
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 Reviewed-on: https://review.coreboot.org/c/coreboot/+/49369 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Angel Pons <th3fanbus@gmail.com> Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Diffstat (limited to 'util')
-rw-r--r--util/cbfstool/cbfs-mkstage.c27
-rw-r--r--util/cbfstool/cbfstool.c5
-rw-r--r--util/cbfstool/common.h3
3 files changed, 9 insertions, 26 deletions
diff --git a/util/cbfstool/cbfs-mkstage.c b/util/cbfstool/cbfs-mkstage.c
index bfe7bf8c33..bd1cf54b6b 100644
--- a/util/cbfstool/cbfs-mkstage.c
+++ b/util/cbfstool/cbfs-mkstage.c
@@ -93,8 +93,7 @@ static void fill_cbfs_stage(struct buffer *outheader, enum cbfs_compression algo
* 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 @@ int parse_elf_to_stage(const struct buffer *input, struct buffer *output,
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 @@ int parse_elf_to_stage(const struct buffer *input, struct buffer *output,
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 @@ int parse_elf_to_stage(const struct buffer *input, struct buffer *output,
/* 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 @@ int parse_elf_to_stage(const struct buffer *input, struct buffer *output,
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 @@ int parse_elf_to_stage(const struct buffer *input, struct buffer *output,
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 2f920e0988..c7330a493e 100644
--- a/util/cbfstool/cbfstool.c
+++ b/util/cbfstool/cbfstool.c
@@ -926,9 +926,10 @@ static int cbfstool_convert_mkstage(struct buffer *buffer, uint32_t *offset,
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 1c83045eee..db9c7e7297 100644
--- a/util/cbfstool/common.h
+++ b/util/cbfstool/common.h
@@ -174,8 +174,7 @@ int parse_flat_binary_to_payload(const struct buffer *input,
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);