soc: qcom: mdt_loader: Fix split image detection

Message ID 20230612215804.1883458-1-quic_bjorande@quicinc.com
State New
Headers
Series soc: qcom: mdt_loader: Fix split image detection |

Commit Message

Bjorn Andersson June 12, 2023, 9:58 p.m. UTC
  The enhanced detection introduced in commit '210d12c8197a ("soc: qcom:
mdt_loader: Enhance split binary detection")' requires that all segments
lies within the file on disk.

But the Qualcomm firmware files consistently has a BSS-like segment at
the end, with a p_offset aligned to the next 4k boundary. As the p_size
is 0 and there's nothing to load, the image is not padded to cover this
(empty) segment.

Ignore zero-sized segments when determining if the image is split, to
avoid this problem.

Fixes: 210d12c8197a ("soc: qcom: mdt_loader: Enhance split binary detection")
Signed-off-by: Bjorn Andersson <quic_bjorande@quicinc.com>
---
 drivers/soc/qcom/mdt_loader.c | 8 ++++++++
 1 file changed, 8 insertions(+)
  

Comments

Dmitry Baryshkov June 13, 2023, 12:57 p.m. UTC | #1
On 13/06/2023 00:58, Bjorn Andersson wrote:
> The enhanced detection introduced in commit '210d12c8197a ("soc: qcom:
> mdt_loader: Enhance split binary detection")' requires that all segments
> lies within the file on disk.
> 
> But the Qualcomm firmware files consistently has a BSS-like segment at
> the end, with a p_offset aligned to the next 4k boundary. As the p_size
> is 0 and there's nothing to load, the image is not padded to cover this
> (empty) segment.
> 
> Ignore zero-sized segments when determining if the image is split, to
> avoid this problem.
> 
> Fixes: 210d12c8197a ("soc: qcom: mdt_loader: Enhance split binary detection")
> Signed-off-by: Bjorn Andersson <quic_bjorande@quicinc.com>

Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Tested-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org> # qrb5165-rb5

W/o this patch loading mbn files is broken.

> ---
>   drivers/soc/qcom/mdt_loader.c | 8 ++++++++
>   1 file changed, 8 insertions(+)
> 
> diff --git a/drivers/soc/qcom/mdt_loader.c b/drivers/soc/qcom/mdt_loader.c
> index 9418993a3a92..6f177e46fa0f 100644
> --- a/drivers/soc/qcom/mdt_loader.c
> +++ b/drivers/soc/qcom/mdt_loader.c
> @@ -275,6 +275,14 @@ static bool qcom_mdt_bins_are_split(const struct firmware *fw, const char *fw_na
>   	phdrs = (struct elf32_phdr *)(ehdr + 1);
>   
>   	for (i = 0; i < ehdr->e_phnum; i++) {
> +		/*
> +		 * The size of the MDT file is not padded to include any
> +		 * zero-sized segments at the end. Ignore these, as they should
> +		 * not affect the decision about image being split or not.
> +		 */
> +		if (!phdrs[i].p_filesz)
> +			continue;
> +
>   		seg_start = phdrs[i].p_offset;
>   		seg_end = phdrs[i].p_offset + phdrs[i].p_filesz;
>   		if (seg_start > fw->size || seg_end > fw->size)
  
Bjorn Andersson June 13, 2023, 10:30 p.m. UTC | #2
On Mon, 12 Jun 2023 14:58:04 -0700, Bjorn Andersson wrote:
> The enhanced detection introduced in commit '210d12c8197a ("soc: qcom:
> mdt_loader: Enhance split binary detection")' requires that all segments
> lies within the file on disk.
> 
> But the Qualcomm firmware files consistently has a BSS-like segment at
> the end, with a p_offset aligned to the next 4k boundary. As the p_size
> is 0 and there's nothing to load, the image is not padded to cover this
> (empty) segment.
> 
> [...]

Applied, thanks!

[1/1] soc: qcom: mdt_loader: Fix split image detection
      commit: 0d25da8e7e1e35bdbb521d586be1954bdedd1cca

Best regards,
  

Patch

diff --git a/drivers/soc/qcom/mdt_loader.c b/drivers/soc/qcom/mdt_loader.c
index 9418993a3a92..6f177e46fa0f 100644
--- a/drivers/soc/qcom/mdt_loader.c
+++ b/drivers/soc/qcom/mdt_loader.c
@@ -275,6 +275,14 @@  static bool qcom_mdt_bins_are_split(const struct firmware *fw, const char *fw_na
 	phdrs = (struct elf32_phdr *)(ehdr + 1);
 
 	for (i = 0; i < ehdr->e_phnum; i++) {
+		/*
+		 * The size of the MDT file is not padded to include any
+		 * zero-sized segments at the end. Ignore these, as they should
+		 * not affect the decision about image being split or not.
+		 */
+		if (!phdrs[i].p_filesz)
+			continue;
+
 		seg_start = phdrs[i].p_offset;
 		seg_end = phdrs[i].p_offset + phdrs[i].p_filesz;
 		if (seg_start > fw->size || seg_end > fw->size)