From 128de2915b99addc681396989b95c7333ff8dc25 Mon Sep 17 00:00:00 2001 From: hanzongcheng Date: Fri, 15 Mar 2024 19:53:01 +0800 Subject: [PATCH] openamp: backport patch to fix elf loader bug * Add 0001-remoteproc-Fix-management-of-non-loadable-program-se.patch to fix elf loader bug Signed-off-by: hanzongcheng --- ...anagement-of-non-loadable-program-se.patch | 63 +++++++++++++++++++ openamp.spec | 6 +- 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 0001-remoteproc-Fix-management-of-non-loadable-program-se.patch diff --git a/0001-remoteproc-Fix-management-of-non-loadable-program-se.patch b/0001-remoteproc-Fix-management-of-non-loadable-program-se.patch new file mode 100644 index 0000000..1cd4be8 --- /dev/null +++ b/0001-remoteproc-Fix-management-of-non-loadable-program-se.patch @@ -0,0 +1,63 @@ +From 79b795e954e15d0d7c37d49fd32ac9cc0315bc3c Mon Sep 17 00:00:00 2001 +From: Umair Khan +Date: Wed, 7 Feb 2024 19:43:04 +0500 +Subject: [PATCH] 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 + +diff --git a/lib/remoteproc/elf_loader.c b/lib/remoteproc/elf_loader.c +index 4d50183..c0eb116 100644 +--- a/lib/remoteproc/elf_loader.c ++++ b/lib/remoteproc/elf_loader.c +@@ -571,20 +571,25 @@ 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; +- } +- *nlen = nsize; +- *nmemsize = nsegmsize; ++ + phnums = elf_phnum(*img_info); +- metal_log(METAL_LOG_DEBUG, "segment: %d, total segs %d\r\n", +- nsegment, phnums); ++ if (phdr) { ++ *nlen = nsize; ++ *nmemsize = nsegmsize; ++ metal_log(METAL_LOG_DEBUG, "segment: %d, total segs %d\r\n", ++ nsegment, phnums); ++ } ++ + if (nsegment == phnums) { +- *load_state = (*load_state & (~RPROC_LOADER_MASK)) | ++ if (phdr) { ++ *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"); ++ *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); +-- +2.34.1 + diff --git a/openamp.spec b/openamp.spec index e0f3e3c..a855492 100644 --- a/openamp.spec +++ b/openamp.spec @@ -1,6 +1,6 @@ Name: openamp Version: 2022.10.1 -Release: 5 +Release: 6 Summary: Open asymmetric multiprocessing framework License: BSD-3-Clause @@ -9,6 +9,7 @@ Source0: https://github.com/OpenAMP/open-amp/archive/refs/tags/v%{version}/%{nam Patch0001:0001-apps-Fix-atomic_flag-error-for-clang-compilation.patch Patch0002:0002-lib-Fix-atomic_flag-error-for-clang-compilation.patch +Patch0003:0001-remoteproc-Fix-management-of-non-loadable-program-se.patch BuildRequires: cmake BuildRequires: gcc @@ -70,6 +71,9 @@ cd build %{_bindir}/*-shared %changelog +* Sat Mar 16 2024 hanzongcheng - 2022.10.1-6 +- Add patch to fix elf loader bug + * Mon Jun 05 2023 hanzongcheng - 2022.10.1-5 - Keep changlog and release consistent -- Gitee