From: Bjorn Andersson <bjorn.andersson@linaro.org>
To: Bjorn Andersson <bjorn.andersson@linaro.org>,
Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Rob Herring <robh+dt@kernel.org>,
linux-arm-msm@vger.kernel.org, linux-remoteproc@vger.kernel.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 04/13] soc: qcom: mdt_loader: Allow hash to reside in any segment
Date: Thu, 27 Jan 2022 18:55:04 -0800 [thread overview]
Message-ID: <20220128025513.97188-5-bjorn.andersson@linaro.org> (raw)
In-Reply-To: <20220128025513.97188-1-bjorn.andersson@linaro.org>
It's been observed that some firmware found on Qualcomm SM8450 devices
carries the hash segment as the last segment in the ELF. Extend the
support to allow picking the hash from any segment in the MDT/MBN.
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
---
drivers/soc/qcom/mdt_loader.c | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/drivers/soc/qcom/mdt_loader.c b/drivers/soc/qcom/mdt_loader.c
index 4372d8e38b29..c5bd13b05c1a 100644
--- a/drivers/soc/qcom/mdt_loader.c
+++ b/drivers/soc/qcom/mdt_loader.c
@@ -126,9 +126,11 @@ void *qcom_mdt_read_metadata(const struct firmware *fw, size_t *data_len,
{
const struct elf32_phdr *phdrs;
const struct elf32_hdr *ehdr;
+ unsigned int hash_segment = 0;
size_t hash_offset;
size_t hash_size;
size_t ehdr_size;
+ unsigned int i;
ssize_t ret;
void *data;
@@ -141,11 +143,20 @@ void *qcom_mdt_read_metadata(const struct firmware *fw, size_t *data_len,
if (phdrs[0].p_type == PT_LOAD)
return ERR_PTR(-EINVAL);
- if ((phdrs[1].p_flags & QCOM_MDT_TYPE_MASK) != QCOM_MDT_TYPE_HASH)
+ for (i = 1; i < ehdr->e_phnum; i++) {
+ if ((phdrs[i].p_flags & QCOM_MDT_TYPE_MASK) == QCOM_MDT_TYPE_HASH) {
+ hash_segment = i;
+ break;
+ }
+ }
+
+ if (!hash_segment) {
+ dev_err(dev, "no hash segment found in %s\n", fw_name);
return ERR_PTR(-EINVAL);
+ }
ehdr_size = phdrs[0].p_filesz;
- hash_size = phdrs[1].p_filesz;
+ hash_size = phdrs[hash_segment].p_filesz;
data = kmalloc(ehdr_size + hash_size, GFP_KERNEL);
if (!data)
@@ -158,13 +169,13 @@ void *qcom_mdt_read_metadata(const struct firmware *fw, size_t *data_len,
/* Firmware is split and hash is packed following the ELF header */
hash_offset = phdrs[0].p_filesz;
memcpy(data + ehdr_size, fw->data + hash_offset, hash_size);
- } else if (phdrs[1].p_offset + hash_size <= fw->size) {
+ } else if (phdrs[hash_segment].p_offset + hash_size <= fw->size) {
/* Hash is in its own segment, but within the loaded file */
- hash_offset = phdrs[1].p_offset;
+ hash_offset = phdrs[hash_segment].p_offset;
memcpy(data + ehdr_size, fw->data + hash_offset, hash_size);
} else {
/* Hash is in its own segment, beyond the loaded file */
- ret = mdt_load_split_segment(data + ehdr_size, phdrs, 1, fw_name, dev);
+ ret = mdt_load_split_segment(data + ehdr_size, phdrs, hash_segment, fw_name, dev);
if (ret) {
kfree(data);
return ERR_PTR(ret);
--
2.33.1
next prev parent reply other threads:[~2022-01-28 2:55 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-28 2:55 [PATCH 00/13] soc: qcom: mdt_loader: Support Qualcomm SM8450 Bjorn Andersson
2022-01-28 2:55 ` [PATCH 01/13] firmware: qcom: scm: Introduce pas_metadata context Bjorn Andersson
2023-05-24 11:17 ` Robert Marko
2022-01-28 2:55 ` [PATCH 02/13] soc: qcom: mdt_loader: Split out split-file-loader Bjorn Andersson
2022-01-28 2:55 ` [PATCH 03/13] soc: qcom: mdt_loader: Allow hash segment to be split out Bjorn Andersson
2022-01-28 2:55 ` Bjorn Andersson [this message]
2022-01-28 2:55 ` [PATCH 05/13] soc: qcom: mdt_loader: Extend check for split firmware Bjorn Andersson
2022-01-28 2:55 ` [PATCH 06/13] soc: qcom: mdt_loader: Reorder parts of __qcom_mdt_load() Bjorn Andersson
2022-01-28 2:55 ` [PATCH 07/13] soc: qcom: mdt_loader: Always invoke PAS mem_setup Bjorn Andersson
2022-01-28 2:55 ` [PATCH 08/13] soc: qcom: mdt_loader: Extract PAS operations Bjorn Andersson
2022-01-28 2:55 ` [PATCH 09/13] remoteproc: qcom: pas: Carry PAS metadata context Bjorn Andersson
2022-01-28 2:55 ` [PATCH 10/13] dt-bindings: remoteproc: qcom: pas: Add SM8450 PAS compatibles Bjorn Andersson
2022-01-28 2:55 ` [PATCH 11/13] remoteproc: qcom: pas: Add SM8450 remoteproc support Bjorn Andersson
2022-01-28 2:55 ` [PATCH 12/13] arm64: dts: qcom: sm8450: Add remoteproc enablers and instances Bjorn Andersson
2022-02-28 8:13 ` Dmitry Baryshkov
2022-01-28 2:55 ` [PATCH 13/13] arm64: dts: qcom: sm8450-qrd: Enable remoteproc instances Bjorn Andersson
2022-02-03 15:11 ` [PATCH 00/13] soc: qcom: mdt_loader: Support Qualcomm SM8450 Dmitry Baryshkov
2022-02-03 18:20 ` Bjorn Andersson
2022-02-04 18:35 ` (subset) " Bjorn Andersson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220128025513.97188-5-bjorn.andersson@linaro.org \
--to=bjorn.andersson@linaro.org \
--cc=devicetree@vger.kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-remoteproc@vger.kernel.org \
--cc=mathieu.poirier@linaro.org \
--cc=robh+dt@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox