Skip to content

Commit

Permalink
elf loader: The rproc elf loading problem
Browse files Browse the repository at this point in the history
The elf loader assumes that the last ELF program segment will always
be a LOAD type segment. I deduce this from the fact that the elf_load()
function, when loading the remote ELF sections during the
RPROC_LOADER_READY_TO_LOAD stage, compares the last load segment num
to the total ELF sections to determine if the loading is complete and
it can move to the next stage RPROC_LOADER_POST_DATA_LOAD. If the last
program segment in the ELF is not of type LOAD, the last loaded LOAD
segment never equals total ELF sections. This creates an error
condition and the firmware loading fails. This patch fixes this issue
by comparing the last loaded LOAD segment number with the max LOAD
segment number in the ELF.

Signed-off-by: Umair Khan <umair_khan@mentor.com>
  • Loading branch information
UmairKhanUET committed Feb 20, 2024
1 parent b32187e commit a7e99b2
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions lib/remoteproc/elf_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -571,20 +571,24 @@ int elf_load(struct remoteproc *rproc,
nsegment = *load_state & ELF_NEXT_SEGMENT_MASK;
phdr = elf_next_load_segment(*img_info, &nsegment, da,
noffset, &nsize, &nsegmsize);
if (!phdr) {
metal_log(METAL_LOG_DEBUG, "cannot find more segment\r\n");
*load_state = (*load_state & (~ELF_NEXT_SEGMENT_MASK)) |
(nsegment & ELF_NEXT_SEGMENT_MASK);
return *load_state;
}

phnums = elf_phnum(*img_info);
if (phdr) {

Check warning on line 576 in lib/remoteproc/elf_loader.c

View workflow job for this annotation

GitHub Actions / checkpatch review

SUSPECT_CODE_INDENT

lib/remoteproc/elf_loader.c:576 suspect code indent for conditional statements (16, 16)
*nlen = nsize;
*nmemsize = nsegmsize;
phnums = elf_phnum(*img_info);
metal_log(METAL_LOG_DEBUG, "segment: %d, total segs %d\r\n",
nsegment, phnums);
metal_log(METAL_LOG_DEBUG, "segment: %d, total segs %d\r\n", nsegment, phnums);

Check warning on line 579 in lib/remoteproc/elf_loader.c

View workflow job for this annotation

GitHub Actions / checkpatch review

LONG_LINE

lib/remoteproc/elf_loader.c:579 line over 100 characters
}

if (nsegment == phnums) {
if (phdr) {

Check warning on line 583 in lib/remoteproc/elf_loader.c

View workflow job for this annotation

GitHub Actions / checkpatch review

SUSPECT_CODE_INDENT

lib/remoteproc/elf_loader.c:583 suspect code indent for conditional statements (24, 24)
*load_state = (*load_state & (~RPROC_LOADER_MASK)) |
RPROC_LOADER_POST_DATA_LOAD;
} else {
metal_log(METAL_LOG_DEBUG, "no more segment to load\r\n");

Check failure on line 587 in lib/remoteproc/elf_loader.c

View workflow job for this annotation

GitHub Actions / checkpatch review

CODE_INDENT

lib/remoteproc/elf_loader.c:587 code indent should use tabs where possible

Check warning on line 587 in lib/remoteproc/elf_loader.c

View workflow job for this annotation

GitHub Actions / checkpatch review

SPACE_BEFORE_TAB

lib/remoteproc/elf_loader.c:587 please, no space before tabs

Check warning on line 587 in lib/remoteproc/elf_loader.c

View workflow job for this annotation

GitHub Actions / checkpatch review

LEADING_SPACE

lib/remoteproc/elf_loader.c:587 please, no spaces at the start of a line
*load_state = (*load_state & (~RPROC_LOADER_MASK)) |
RPROC_LOADER_LOAD_COMPLETE;
*da = RPROC_LOAD_ANYADDR;
}
}
*load_state = (*load_state & (~ELF_NEXT_SEGMENT_MASK)) |
(nsegment & ELF_NEXT_SEGMENT_MASK);
Expand Down

0 comments on commit a7e99b2

Please sign in to comment.