From patchwork Mon Jul 13 13:29:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Bailon X-Patchwork-Id: 11659745 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 63F54138C for ; Mon, 13 Jul 2020 13:30:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 46410206F0 for ; Mon, 13 Jul 2020 13:30:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20150623.gappssmtp.com header.i=@baylibre-com.20150623.gappssmtp.com header.b="j0V0viTo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729946AbgGMN36 (ORCPT ); Mon, 13 Jul 2020 09:29:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729894AbgGMN3s (ORCPT ); Mon, 13 Jul 2020 09:29:48 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD68CC08C5E2 for ; Mon, 13 Jul 2020 06:29:45 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id f7so16572510wrw.1 for ; Mon, 13 Jul 2020 06:29:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Pl8osqFHzEcsdNW9tfkecnvuu2M/qEbw8a1f1sca/Bk=; b=j0V0viTo0JLbXENBdA8u1+UQl/wK7PVzGbNY3YKPkjM6a93X59GWthJFO0yR9ONhfF +drSmRuFiaHGhkaieOUng8wozlwVYqlzoqVh+ijxMllnXMQqWtoZduqq8nLLZSsheBZR FMrf020wFUq6/ZR6gYCTH1BnUE8yN7ePXjQUyHqBTGkctxxLUcCMfkmkcR8zA9iagnh7 DgCE83w6nFrC2jtNTQfu/xA+iR91Xeg4jNGr6fGMBeEKGSL7aZD6iy4iy9yHxxSPk94H G6m+Am15ak2b7/KYTmu4i9QtIkTJzEBZ9HKtZmSVXS33an9eGFMuG1ZKEEYU7w2IKWs8 6pqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Pl8osqFHzEcsdNW9tfkecnvuu2M/qEbw8a1f1sca/Bk=; b=nQwJd5oRgjtXZV7of0LnN/YPQT4KvRaw6UVLIMzPfBCnwLiadj+yT8zW9PfgUPNNkp GmeycUYZCDYKg+D06iJuTBk7k1afc5qBsTkEcgTdWH2zy9Tb6bWeAx9LnZuz3begJikG MdscAGFmP9h3U6/jfGj0/rPB+gOV4K2KnVT5O0fQVAJEJWI2eYwMUAxFF7Fw5oIQaZIt jumVEewiP/P9pYNkbaH+rgSXDBDPAq9skCq9wJyehWdnUIA1uOs/XAxAINxgI3rLEMz/ FFl1h5E1qkSVpAWlSa/2DZ5yylcfwCNCK6MtZ8TvMbz5JTSG60Pz4/qnDVfCehWQ8faJ aMfw== X-Gm-Message-State: AOAM531dJWzlfM04o9UfCVt/Bv2kPex3h0UNRs7pTUpGT4M36YU4U9/b R4jVDpBTuRU3+EbQ6RSS+kpD8g== X-Google-Smtp-Source: ABdhPJwykKAe+1hKtLIks/qZbsmfhZ3wQYs7n9CAFTDWM+nYh/VUMUiFm2oxGk4afCL5P/rY946YCQ== X-Received: by 2002:adf:f0ce:: with SMTP id x14mr76501632wro.137.1594646984561; Mon, 13 Jul 2020 06:29:44 -0700 (PDT) Received: from linux.local (laubervilliers-658-1-213-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.gmail.com with ESMTPSA id j14sm23896642wrs.75.2020.07.13.06.29.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jul 2020 06:29:43 -0700 (PDT) From: Alexandre Bailon To: ohad@wizery.com, bjorn.andersson@linaro.org, robh+dt@kernel.org, matthias.bgg@gmail.com Cc: linux-remoteproc@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Alexandre Bailon Subject: [PATCH 4/6] remoteproc: mtk_vpu_rproc: Don't try to load empty PT_LOAD segment Date: Mon, 13 Jul 2020 15:29:25 +0200 Message-Id: <20200713132927.24925-5-abailon@baylibre.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200713132927.24925-1-abailon@baylibre.com> References: <20200713132927.24925-1-abailon@baylibre.com> MIME-Version: 1.0 Sender: linux-remoteproc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org The firmware generated by our toolchain contains many empty PT_LOAD segments. The elf loader don't manage it and will raise an error: "bad phdr da 0x0 mem 0x0". To workaround it, implement the sanity_check callback to detect the empty PT_LOAD segment and change it to PT_NULL. In that way, the elf load won't try to load the segment. Signed-off-by: Alexandre Bailon Reviewed-by: Mathieu Poirier --- drivers/remoteproc/mtk_apu_rproc.c | 35 +++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/drivers/remoteproc/mtk_apu_rproc.c b/drivers/remoteproc/mtk_apu_rproc.c index f2342b747a35..565b3adca5de 100644 --- a/drivers/remoteproc/mtk_apu_rproc.c +++ b/drivers/remoteproc/mtk_apu_rproc.c @@ -137,10 +137,39 @@ static void mtk_vpu_rproc_kick(struct rproc *rproc, int vqid) vpu_write32(vpu_rproc, CORE_CTL_XTENSA_INT, 1 << vqid); } +int mtk_vpu_elf_sanity_check(struct rproc *rproc, const struct firmware *fw) +{ + const u8 *elf_data = fw->data; + struct elf32_hdr *ehdr; + struct elf32_phdr *phdr; + int ret; + int i; + + ret = rproc_elf_sanity_check(rproc, fw); + if (ret) + return ret; + + ehdr = (struct elf32_hdr *)elf_data; + phdr = (struct elf32_phdr *)(elf_data + ehdr->e_phoff); + + for (i = 0; i < ehdr->e_phnum; i++, phdr++) { + /* Remove empty PT_LOAD section */ + if (phdr->p_type == PT_LOAD && !phdr->p_paddr) + phdr->p_type = PT_NULL; + } + + return 0; +} + static const struct rproc_ops mtk_vpu_rproc_ops = { - .start = mtk_vpu_rproc_start, - .stop = mtk_vpu_rproc_stop, - .kick = mtk_vpu_rproc_kick, + .start = mtk_vpu_rproc_start, + .stop = mtk_vpu_rproc_stop, + .kick = mtk_vpu_rproc_kick, + .load = rproc_elf_load_segments, + .parse_fw = rproc_elf_load_rsc_table, + .find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table, + .sanity_check = mtk_vpu_elf_sanity_check, + .get_boot_addr = rproc_elf_get_boot_addr, }; static irqreturn_t mtk_vpu_rproc_callback(int irq, void *data)