All of lore.kernel.org
 help / color / mirror / Atom feed
From: Siddharth Gupta <sidgup@codeaurora.org>
To: bjorn.andersson@linaro.org, agross@kernel.org, ohad@wizery.com,
	linux-arm-msm@vger.kernel.org, linux-remoteproc@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: Siddharth Gupta <sidgup@codeaurora.org>,
	psodagud@codeaurora.org, rishabhb@codeaurora.org
Subject: [PATCH 1/3] soc: qcom: mdt_loader: Allow hash at any phdr
Date: Wed,  6 Jan 2021 13:23:29 -0800	[thread overview]
Message-ID: <1609968211-7579-2-git-send-email-sidgup@codeaurora.org> (raw)
In-Reply-To: <1609968211-7579-1-git-send-email-sidgup@codeaurora.org>

The assumption that the elf program header will always have the hash
segment program header at index 1 may not hold true in all cases. This
change updates the read metadata function to find the hash program header
dynamically.

Signed-off-by: Siddharth Gupta <sidgup@codeaurora.org>
---
 drivers/soc/qcom/mdt_loader.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/drivers/soc/qcom/mdt_loader.c b/drivers/soc/qcom/mdt_loader.c
index 24cd193..813216d 100644
--- a/drivers/soc/qcom/mdt_loader.c
+++ b/drivers/soc/qcom/mdt_loader.c
@@ -4,7 +4,7 @@
  *
  * Copyright (C) 2016 Linaro Ltd
  * Copyright (C) 2015 Sony Mobile Communications Inc
- * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2012-2013, 2020 The Linux Foundation. All rights reserved.
  */
 
 #include <linux/device.h>
@@ -88,6 +88,7 @@ void *qcom_mdt_read_metadata(const struct firmware *fw, size_t *data_len)
 	const struct elf32_phdr *phdrs;
 	const struct elf32_hdr *ehdr;
 	size_t hash_offset;
+	size_t hash_index;
 	size_t hash_size;
 	size_t ehdr_size;
 	void *data;
@@ -98,14 +99,19 @@ void *qcom_mdt_read_metadata(const struct firmware *fw, size_t *data_len)
 	if (ehdr->e_phnum < 2)
 		return ERR_PTR(-EINVAL);
 
-	if (phdrs[0].p_type == PT_LOAD || phdrs[1].p_type == PT_LOAD)
+	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 (hash_index = 1; hash_index < ehdr->e_phnum; hash_index++) {
+		if (phdrs[hash_index].p_type != PT_LOAD &&
+		   (phdrs[hash_index].p_flags & QCOM_MDT_TYPE_MASK) == QCOM_MDT_TYPE_HASH)
+			break;
+	}
+	if (hash_index >= ehdr->e_phnum)
 		return ERR_PTR(-EINVAL);
 
 	ehdr_size = phdrs[0].p_filesz;
-	hash_size = phdrs[1].p_filesz;
+	hash_size = phdrs[hash_index].p_filesz;
 
 	data = kmalloc(ehdr_size + hash_size, GFP_KERNEL);
 	if (!data)
@@ -115,7 +121,7 @@ void *qcom_mdt_read_metadata(const struct firmware *fw, size_t *data_len)
 	if (ehdr_size + hash_size == fw->size)
 		hash_offset = phdrs[0].p_filesz;
 	else
-		hash_offset = phdrs[1].p_offset;
+		hash_offset = phdrs[hash_index].p_offset;
 
 	memcpy(data, fw->data, ehdr_size);
 	memcpy(data + ehdr_size, fw->data + hash_offset, hash_size);
-- 
Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


  reply	other threads:[~2021-01-06 21:24 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-06 21:23 [PATCH 0/3] soc: qcom: mdt_loader: General improvements Siddharth Gupta
2021-01-06 21:23 ` Siddharth Gupta [this message]
2021-01-08  0:03   ` [PATCH 1/3] soc: qcom: mdt_loader: Allow hash at any phdr Bjorn Andersson
2021-01-06 21:23 ` [PATCH 2/3] soc: qcom: mdt_loader: Handle split bins correctly Siddharth Gupta
2021-01-08  0:07   ` Bjorn Andersson
2021-01-06 21:23 ` [PATCH 3/3] soc: qcom: mdt_loader: Read hash from firmware blob Siddharth Gupta
2021-01-06 23:41   ` kernel test robot
2021-01-06 23:41     ` kernel test robot
2021-01-08  0:21   ` Bjorn Andersson
2021-01-13 23:01     ` Siddharth Gupta
2021-01-14 17:46       ` Bjorn Andersson
2021-01-17 23:03         ` Siddharth Gupta

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=1609968211-7579-2-git-send-email-sidgup@codeaurora.org \
    --to=sidgup@codeaurora.org \
    --cc=agross@kernel.org \
    --cc=bjorn.andersson@linaro.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-remoteproc@vger.kernel.org \
    --cc=ohad@wizery.com \
    --cc=psodagud@codeaurora.org \
    --cc=rishabhb@codeaurora.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.