All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
To: Andy Gross <agross@kernel.org>,
	Bjorn Andersson <andersson@kernel.org>,
	Konrad Dybcio <konrad.dybcio@linaro.org>,
	Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: linux-arm-msm@vger.kernel.org, linux-remoteproc@vger.kernel.org
Subject: [PATCH v2] remoteproc: qcom_q6v5_mss: support loading MBN file on msm8974
Date: Mon,  8 May 2023 18:35:24 +0300	[thread overview]
Message-ID: <20230508153524.2371795-1-dmitry.baryshkov@linaro.org> (raw)

On MSM8974 and APQ8074 the MSS requires loading raw MBA image instead of
the ELF file. Skip the ELF headers if mba.mbn was specified as the
firmware image.

Fixes: 051fb70fd4ea ("remoteproc: qcom: Driver for the self-authenticating Hexagon v5")
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
---

Changes since v1:
- Replace fixed offset 0x1000 with the value obtained from ELF headers
- Implement ELF validity checks

---
 drivers/remoteproc/qcom_q6v5_mss.c | 47 +++++++++++++++++++++++++++++-
 1 file changed, 46 insertions(+), 1 deletion(-)

diff --git a/drivers/remoteproc/qcom_q6v5_mss.c b/drivers/remoteproc/qcom_q6v5_mss.c
index ab053084f7a2..b4ff900f0304 100644
--- a/drivers/remoteproc/qcom_q6v5_mss.c
+++ b/drivers/remoteproc/qcom_q6v5_mss.c
@@ -11,6 +11,7 @@
 #include <linux/delay.h>
 #include <linux/devcoredump.h>
 #include <linux/dma-mapping.h>
+#include <linux/firmware.h>
 #include <linux/interrupt.h>
 #include <linux/kernel.h>
 #include <linux/mfd/syscon.h>
@@ -29,6 +30,7 @@
 #include <linux/iopoll.h>
 #include <linux/slab.h>
 
+#include "remoteproc_elf_helpers.h"
 #include "remoteproc_internal.h"
 #include "qcom_common.h"
 #include "qcom_pil_info.h"
@@ -459,6 +461,35 @@ static void q6v5_debug_policy_load(struct q6v5 *qproc, void *mba_region)
 	release_firmware(dp_fw);
 }
 
+/* Get the offset of the segment 0 for mba.mbn */
+static int q6v5_mba_get_offset(struct rproc *rproc, const struct firmware *fw)
+{
+	const struct elf32_hdr *ehdr;
+	const void *phdr;
+	char class;
+	u64 phoffset, poffset;
+	u16 phentsize;
+	int ret;
+
+	ret = rproc_elf_sanity_check(rproc, fw);
+	if (ret < 0)
+		return ret;
+
+	ehdr = (const struct elf32_hdr *)fw->data;
+	class = ehdr->e_ident[EI_CLASS];
+	phoffset = elf_hdr_get_e_phoff(class, ehdr);
+	phentsize = elf_hdr_get_e_phentsize(class, ehdr);
+	if (phoffset + phentsize > fw->size)
+		return -EINVAL;
+
+	phdr = fw->data + elf_hdr_get_e_phoff(class, ehdr);
+	poffset = elf_phdr_get_p_offset(class, phdr);
+	if (poffset > fw->size)
+		return -EINVAL;
+
+	return poffset;
+}
+
 static int q6v5_load(struct rproc *rproc, const struct firmware *fw)
 {
 	struct q6v5 *qproc = rproc->priv;
@@ -477,7 +508,21 @@ static int q6v5_load(struct rproc *rproc, const struct firmware *fw)
 		return -EBUSY;
 	}
 
-	memcpy(mba_region, fw->data, fw->size);
+	if (qproc->version == MSS_MSM8974 &&
+	    !memcmp(fw->data, ELFMAG, SELFMAG)) {
+		int poffset;
+
+		poffset = q6v5_mba_get_offset(rproc, fw);
+		if (poffset < 0) {
+			memunmap(mba_region);
+			return poffset;
+		}
+
+		memcpy(mba_region, fw->data + poffset, fw->size - poffset);
+	} else {
+		memcpy(mba_region, fw->data, fw->size);
+	}
+
 	q6v5_debug_policy_load(qproc, mba_region);
 	memunmap(mba_region);
 
-- 
2.39.2


             reply	other threads:[~2023-05-08 15:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-08 15:35 Dmitry Baryshkov [this message]
2023-07-15 20:39 ` [PATCH v2] remoteproc: qcom_q6v5_mss: support loading MBN file on msm8974 Bjorn Andersson
2023-08-29 20:53   ` Dmitry Baryshkov

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=20230508153524.2371795-1-dmitry.baryshkov@linaro.org \
    --to=dmitry.baryshkov@linaro.org \
    --cc=agross@kernel.org \
    --cc=andersson@kernel.org \
    --cc=konrad.dybcio@linaro.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-remoteproc@vger.kernel.org \
    --cc=mathieu.poirier@linaro.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.