Skip to content

Commit 79b795e

Browse files
Umair Khanarnopo
authored andcommitted
remoteproc: Fix management of non loadable program segments
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>
1 parent 0c7e420 commit 79b795e

1 file changed

Lines changed: 16 additions & 11 deletions

File tree

lib/remoteproc/elf_loader.c

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -571,20 +571,25 @@ int elf_load(struct remoteproc *rproc,
571571
nsegment = *load_state & ELF_NEXT_SEGMENT_MASK;
572572
phdr = elf_next_load_segment(*img_info, &nsegment, da,
573573
noffset, &nsize, &nsegmsize);
574-
if (!phdr) {
575-
metal_log(METAL_LOG_DEBUG, "cannot find more segment\r\n");
576-
*load_state = (*load_state & (~ELF_NEXT_SEGMENT_MASK)) |
577-
(nsegment & ELF_NEXT_SEGMENT_MASK);
578-
return *load_state;
579-
}
580-
*nlen = nsize;
581-
*nmemsize = nsegmsize;
574+
582575
phnums = elf_phnum(*img_info);
583-
metal_log(METAL_LOG_DEBUG, "segment: %d, total segs %d\r\n",
584-
nsegment, phnums);
576+
if (phdr) {
577+
*nlen = nsize;
578+
*nmemsize = nsegmsize;
579+
metal_log(METAL_LOG_DEBUG, "segment: %d, total segs %d\r\n",
580+
nsegment, phnums);
581+
}
582+
585583
if (nsegment == phnums) {
586-
*load_state = (*load_state & (~RPROC_LOADER_MASK)) |
584+
if (phdr) {
585+
*load_state = (*load_state & (~RPROC_LOADER_MASK)) |
587586
RPROC_LOADER_POST_DATA_LOAD;
587+
} else {
588+
metal_log(METAL_LOG_DEBUG, "no more segment to load\r\n");
589+
*load_state = (*load_state & (~RPROC_LOADER_MASK)) |
590+
RPROC_LOADER_LOAD_COMPLETE;
591+
*da = RPROC_LOAD_ANYADDR;
592+
}
588593
}
589594
*load_state = (*load_state & (~ELF_NEXT_SEGMENT_MASK)) |
590595
(nsegment & ELF_NEXT_SEGMENT_MASK);

0 commit comments

Comments
 (0)