From patchwork Wed Jan 6 21:23:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddharth Gupta X-Patchwork-Id: 12002299 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ADF23C433DB for ; Wed, 6 Jan 2021 21:24:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7BB9D2333C for ; Wed, 6 Jan 2021 21:24:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726663AbhAFVYi (ORCPT ); Wed, 6 Jan 2021 16:24:38 -0500 Received: from so254-31.mailgun.net ([198.61.254.31]:51112 "EHLO so254-31.mailgun.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726499AbhAFVYi (ORCPT ); Wed, 6 Jan 2021 16:24:38 -0500 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1609968255; h=References: In-Reply-To: Message-Id: Date: Subject: Cc: To: From: Sender; bh=jqzm0CxwVjPPoXHkI362trmov4+GkgN4j5eOnnkRcHM=; b=T2meY386Hd1t8XrHK77+/dVkgM0z+snFFXIuFTZxAqRZr+Tke/DQE58nYj0B5flOKtMZyvVo +vdHC09ZlxfhZxZrnDeA+6VrcSzEe5bQMrn9Ke5yatU/ag05+Xe+blGeUGIf1lAxz+1CnvaN s5zCiJ3f6tHvPcSiJKcBA+rOdzw= X-Mailgun-Sending-Ip: 198.61.254.31 X-Mailgun-Sid: WyI1MzIzYiIsICJsaW51eC1hcm0tbXNtQHZnZXIua2VybmVsLm9yZyIsICJiZTllNGEiXQ== Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n09.prod.us-east-1.postgun.com with SMTP id 5ff62a62a1d2634b3fc08d33 (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Wed, 06 Jan 2021 21:23:46 GMT Sender: sidgup=codeaurora.org@mg.codeaurora.org Received: by smtp.codeaurora.org (Postfix, from userid 1001) id BD33EC43466; Wed, 6 Jan 2021 21:23:45 +0000 (UTC) Received: from sidgup-linux.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: sidgup) by smtp.codeaurora.org (Postfix) with ESMTPSA id C8E3EC43461; Wed, 6 Jan 2021 21:23:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org C8E3EC43461 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=fail smtp.mailfrom=sidgup@codeaurora.org From: Siddharth Gupta 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 , 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 Message-Id: <1609968211-7579-2-git-send-email-sidgup@codeaurora.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1609968211-7579-1-git-send-email-sidgup@codeaurora.org> References: <1609968211-7579-1-git-send-email-sidgup@codeaurora.org> Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.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 Reviewed-by: Bjorn Andersson --- 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 @@ -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); From patchwork Wed Jan 6 21:23:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddharth Gupta X-Patchwork-Id: 12002303 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1F0FEC4332D for ; Wed, 6 Jan 2021 21:24:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EC4312336F for ; Wed, 6 Jan 2021 21:24:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726688AbhAFVYn (ORCPT ); Wed, 6 Jan 2021 16:24:43 -0500 Received: from m43-15.mailgun.net ([69.72.43.15]:61815 "EHLO m43-15.mailgun.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725815AbhAFVYn (ORCPT ); Wed, 6 Jan 2021 16:24:43 -0500 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1609968260; h=References: In-Reply-To: Message-Id: Date: Subject: Cc: To: From: Sender; bh=4TYWfsSk+aG1z3XPwo/hidVUb383BnbZ9LPVZgIeQqE=; b=YAgCVT5c5jINWZjr8OryZPCkP6sK+AHuHuQvUHlYeN94+284jPeALtasDPAXxjzXGW63oTvI CQs53Tm+Ppb3XOzcvNPjcMBIVC6g84JDeH3zkIOBc2BlOtEXbv8DnYF1pEDmtg/b+sjVbYf8 zljdspHvuPjwOEBG7dSJlIJ6xBE= X-Mailgun-Sending-Ip: 69.72.43.15 X-Mailgun-Sid: WyI1MzIzYiIsICJsaW51eC1hcm0tbXNtQHZnZXIua2VybmVsLm9yZyIsICJiZTllNGEiXQ== Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n01.prod.us-west-2.postgun.com with SMTP id 5ff62a62b95fc5932662053d (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Wed, 06 Jan 2021 21:23:46 GMT Sender: sidgup=codeaurora.org@mg.codeaurora.org Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 877EDC43463; Wed, 6 Jan 2021 21:23:46 +0000 (UTC) Received: from sidgup-linux.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: sidgup) by smtp.codeaurora.org (Postfix) with ESMTPSA id 7AFF9C43464; Wed, 6 Jan 2021 21:23:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 7AFF9C43464 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=fail smtp.mailfrom=sidgup@codeaurora.org From: Siddharth Gupta 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 , psodagud@codeaurora.org, rishabhb@codeaurora.org Subject: [PATCH 2/3] soc: qcom: mdt_loader: Handle split bins correctly Date: Wed, 6 Jan 2021 13:23:30 -0800 Message-Id: <1609968211-7579-3-git-send-email-sidgup@codeaurora.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1609968211-7579-1-git-send-email-sidgup@codeaurora.org> References: <1609968211-7579-1-git-send-email-sidgup@codeaurora.org> Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org It may be that the offset of the first program header lies inside the mdt's filesize, in this case the loader would incorrectly assume that the bins were not split. The loading would then continue on to fail for split bins. This change updates the logic used by the mdt loader to understand whether the firmware images are split or not. It figures this out by checking if each program header's segment lies within the file or not. Signed-off-by: Siddharth Gupta --- drivers/soc/qcom/mdt_loader.c | 60 +++++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 22 deletions(-) diff --git a/drivers/soc/qcom/mdt_loader.c b/drivers/soc/qcom/mdt_loader.c index 813216d..c9bbd8c 100644 --- a/drivers/soc/qcom/mdt_loader.c +++ b/drivers/soc/qcom/mdt_loader.c @@ -31,6 +31,26 @@ static bool mdt_phdr_valid(const struct elf32_phdr *phdr) return true; } +static bool qcom_mdt_bins_are_split(const struct firmware *fw) +{ + const struct elf32_phdr *phdrs; + const struct elf32_hdr *ehdr; + uint64_t seg_start, seg_end; + int i; + + ehdr = (struct elf32_hdr *)fw->data; + phdrs = (struct elf32_phdr *)(ehdr + 1); + + for (i = 0; i < ehdr->e_phnum; i++) { + 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) + return true; + } + + return false; +} + /** * qcom_mdt_get_size() - acquire size of the memory region needed to load mdt * @fw: firmware object for the mdt file @@ -118,7 +138,7 @@ void *qcom_mdt_read_metadata(const struct firmware *fw, size_t *data_len) return ERR_PTR(-ENOMEM); /* Is the header and hash already packed */ - if (ehdr_size + hash_size == fw->size) + if (qcom_mdt_bins_are_split(fw)) hash_offset = phdrs[0].p_filesz; else hash_offset = phdrs[hash_index].p_offset; @@ -150,6 +170,7 @@ static int __qcom_mdt_load(struct device *dev, const struct firmware *fw, void *metadata; char *fw_name; bool relocate = false; + bool is_split; void *ptr; int ret = 0; int i; @@ -157,6 +178,7 @@ static int __qcom_mdt_load(struct device *dev, const struct firmware *fw, if (!fw || !mem_region || !mem_phys || !mem_size) return -EINVAL; + is_split = qcom_mdt_bins_are_split(fw); ehdr = (struct elf32_hdr *)fw->data; phdrs = (struct elf32_phdr *)(ehdr + 1); @@ -238,28 +260,22 @@ static int __qcom_mdt_load(struct device *dev, const struct firmware *fw, ptr = mem_region + offset; - if (phdr->p_filesz && phdr->p_offset < fw->size) { - /* Firmware is large enough to be non-split */ - if (phdr->p_offset + phdr->p_filesz > fw->size) { - dev_err(dev, - "failed to load segment %d from truncated file %s\n", - i, firmware); - ret = -EINVAL; - break; + if (phdr->p_filesz) { + if (!is_split) { + /* Firmware is large enough to be non-split */ + memcpy(ptr, fw->data + phdr->p_offset, phdr->p_filesz); + } else { + /* Firmware not large enough, load split-out segments */ + snprintf(fw_name + fw_name_len - 3, 4, "b%02d", i); + ret = request_firmware_into_buf(&seg_fw, fw_name, dev, + ptr, phdr->p_filesz); + if (ret) { + dev_err(dev, "failed to load %s\n", fw_name); + break; + } + + release_firmware(seg_fw); } - - memcpy(ptr, fw->data + phdr->p_offset, phdr->p_filesz); - } else if (phdr->p_filesz) { - /* Firmware not large enough, load split-out segments */ - sprintf(fw_name + fw_name_len - 3, "b%02d", i); - ret = request_firmware_into_buf(&seg_fw, fw_name, dev, - ptr, phdr->p_filesz); - if (ret) { - dev_err(dev, "failed to load %s\n", fw_name); - break; - } - - release_firmware(seg_fw); } if (phdr->p_memsz > phdr->p_filesz) From patchwork Wed Jan 6 21:23:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddharth Gupta X-Patchwork-Id: 12002305 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78E1EC43333 for ; Wed, 6 Jan 2021 21:24:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 649722313C for ; Wed, 6 Jan 2021 21:24:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725788AbhAFVYt (ORCPT ); Wed, 6 Jan 2021 16:24:49 -0500 Received: from so254-31.mailgun.net ([198.61.254.31]:31727 "EHLO so254-31.mailgun.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726499AbhAFVYk (ORCPT ); Wed, 6 Jan 2021 16:24:40 -0500 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1609968254; h=References: In-Reply-To: Message-Id: Date: Subject: Cc: To: From: Sender; bh=MYazQZSddXgcH9RSsDLWhr+gbu/RoBdunijn/+4XvK0=; b=sB6k/WsdZXlySuo46TARvNijM3avRsQ7Bwe6nzpyl03Nvw9LxN+872kJgBUTGfCGcLYjxXXK rtTtpMcNg81gOwpa7JrVajAlwDeGJ9nKUZhi6HJ+YgL0LRit9N7G1c7r/349qVnPn8ZwOWpZ 8ymrpkPl+7ksgoRaFGeR6UqnCQo= X-Mailgun-Sending-Ip: 198.61.254.31 X-Mailgun-Sid: WyI1MzIzYiIsICJsaW51eC1hcm0tbXNtQHZnZXIua2VybmVsLm9yZyIsICJiZTllNGEiXQ== Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n06.prod.us-west-2.postgun.com with SMTP id 5ff62a63661021aa280f66e6 (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Wed, 06 Jan 2021 21:23:47 GMT Sender: sidgup=codeaurora.org@mg.codeaurora.org Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 3D129C43462; Wed, 6 Jan 2021 21:23:47 +0000 (UTC) Received: from sidgup-linux.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: sidgup) by smtp.codeaurora.org (Postfix) with ESMTPSA id 29629C433CA; Wed, 6 Jan 2021 21:23:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 29629C433CA Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=fail smtp.mailfrom=sidgup@codeaurora.org From: Siddharth Gupta 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 , psodagud@codeaurora.org, rishabhb@codeaurora.org Subject: [PATCH 3/3] soc: qcom: mdt_loader: Read hash from firmware blob Date: Wed, 6 Jan 2021 13:23:31 -0800 Message-Id: <1609968211-7579-4-git-send-email-sidgup@codeaurora.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1609968211-7579-1-git-send-email-sidgup@codeaurora.org> References: <1609968211-7579-1-git-send-email-sidgup@codeaurora.org> Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Since the split elf blobs will always contain the hash segment, we rely on the blob file to get the hash rather than assume that it will be present in the mdt file. This change uses the hash index to read the appropriate elf blob to get the hash segment. Signed-off-by: Siddharth Gupta --- drivers/remoteproc/qcom_q6v5_mss.c | 4 ++-- drivers/soc/qcom/mdt_loader.c | 38 +++++++++++++++++++++++++++---------- include/linux/soc/qcom/mdt_loader.h | 3 ++- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/drivers/remoteproc/qcom_q6v5_mss.c b/drivers/remoteproc/qcom_q6v5_mss.c index 66106ba..74c0229 100644 --- a/drivers/remoteproc/qcom_q6v5_mss.c +++ b/drivers/remoteproc/qcom_q6v5_mss.c @@ -4,7 +4,7 @@ * * Copyright (C) 2016 Linaro Ltd. * Copyright (C) 2014 Sony Mobile Communications AB - * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. + * Copyright (c) 2012-2013, 2020 The Linux Foundation. All rights reserved. */ #include @@ -828,7 +828,7 @@ static int q6v5_mpss_init_image(struct q6v5 *qproc, const struct firmware *fw) void *ptr; int ret; - metadata = qcom_mdt_read_metadata(fw, &size); + metadata = qcom_mdt_read_metadata(qproc->dev, fw, qproc->hexagon_mdt_image, &size); if (IS_ERR(metadata)) return PTR_ERR(metadata); diff --git a/drivers/soc/qcom/mdt_loader.c b/drivers/soc/qcom/mdt_loader.c index c9bbd8c..6876c0b 100644 --- a/drivers/soc/qcom/mdt_loader.c +++ b/drivers/soc/qcom/mdt_loader.c @@ -103,15 +103,18 @@ EXPORT_SYMBOL_GPL(qcom_mdt_get_size); * * Return: pointer to data, or ERR_PTR() */ -void *qcom_mdt_read_metadata(const struct firmware *fw, size_t *data_len) +void *qcom_mdt_read_metadata(struct device *dev, const struct firmware *fw, const char *firmware, + size_t *data_len) { const struct elf32_phdr *phdrs; const struct elf32_hdr *ehdr; - size_t hash_offset; + const struct firmware *seg_fw; size_t hash_index; size_t hash_size; size_t ehdr_size; + char *fw_name; void *data; + int ret; ehdr = (struct elf32_hdr *)fw->data; phdrs = (struct elf32_phdr *)(ehdr + 1); @@ -137,14 +140,29 @@ void *qcom_mdt_read_metadata(const struct firmware *fw, size_t *data_len) if (!data) return ERR_PTR(-ENOMEM); - /* Is the header and hash already packed */ - if (qcom_mdt_bins_are_split(fw)) - hash_offset = phdrs[0].p_filesz; - else - hash_offset = phdrs[hash_index].p_offset; - + /* copy elf header */ memcpy(data, fw->data, ehdr_size); - memcpy(data + ehdr_size, fw->data + hash_offset, hash_size); + + if (qcom_mdt_bins_are_split(fw)) { + fw_name = kstrdup(firmware, GFP_KERNEL); + if (!fw_name) { + kfree(data); + return ERR_PTR(-ENOMEM); + } + snprintf(fw_name + strlen(fw_name) - 3, 4, "b%02d", hash_index); + + ret = request_firmware_into_buf(&seg_fw, fw_name, dev, data + ehdr_size, hash_size); + kfree(fw_name); + + if (ret) { + kfree(data); + return ERR_PTR(ret); + } + + release_firmware(seg_fw); + } else { + memcpy(data + ehdr_size, fw->data + phdrs[hash_index].p_offset, hash_size); + } *data_len = ehdr_size + hash_size; @@ -191,7 +209,7 @@ static int __qcom_mdt_load(struct device *dev, const struct firmware *fw, return -ENOMEM; if (pas_init) { - metadata = qcom_mdt_read_metadata(fw, &metadata_len); + metadata = qcom_mdt_read_metadata(dev, fw, firmware, &metadata_len); if (IS_ERR(metadata)) { ret = PTR_ERR(metadata); goto out; diff --git a/include/linux/soc/qcom/mdt_loader.h b/include/linux/soc/qcom/mdt_loader.h index e600bae..04ba5e8 100644 --- a/include/linux/soc/qcom/mdt_loader.h +++ b/include/linux/soc/qcom/mdt_loader.h @@ -21,6 +21,7 @@ int qcom_mdt_load_no_init(struct device *dev, const struct firmware *fw, const char *fw_name, int pas_id, void *mem_region, phys_addr_t mem_phys, size_t mem_size, phys_addr_t *reloc_base); -void *qcom_mdt_read_metadata(const struct firmware *fw, size_t *data_len); +void *qcom_mdt_read_metadata(struct device *dev, const struct firmware *fw, const char *firmware, + size_t *data_len); #endif