Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp984599ybh; Mon, 13 Jul 2020 06:32:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxyZoq2MUR6/fyuf2Y0Va7uesmbfTaF29alPj3sdh8lKJPn2VYVuk5qFQlUlOOKpVSS+c6U X-Received: by 2002:a17:907:2163:: with SMTP id rl3mr71261046ejb.409.1594647146076; Mon, 13 Jul 2020 06:32:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594647146; cv=none; d=google.com; s=arc-20160816; b=OVN3CX9MVz9kXrYZ3fMfw7IpEs/8pgvoTYddar+6D8WnGbZwRZle0t1eXruuDb2Avc Mkf4e5wJecznJCe1v4s2qnL+Fi3PulmhEBuPBz92C6gVApWsQRWExN+1mSPJzrHgn+6I 58bJ1jhV3nlkuKeUTnOii6QftPzGnpnHzxm+8B4ov0K35KpboylKC8eQozav0Zug0eag XibMZy96rb1IW3UwaBDBz+7F5C9K6g7sa1z48VXcBftQ6+vvYoaP/Kka2XKXI20KqLtS TUFSHHPEKlDGLH08DgEEO/XvlP56e+yqYZVPPoaYU1io0nZP1UFYiSpSxld/ew+YYmGt zmlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Pl8osqFHzEcsdNW9tfkecnvuu2M/qEbw8a1f1sca/Bk=; b=tYb5Vu6M6HVMeXBID0kzT/wovkHlACOeha6WMA+QdupVkizidAMvPprQu8Y3o6iVUY 0bqd5HeU7vB6G/qsGYnndLHR2KGWBHEl99r9au9lI/ErgYBfb6S4belC87MGZl7czXun ZRiCJRpTgMWHYsEuwmVG8xaGHqlf6DMt/InjHwkj3UfcwG/5Q4iMcdNf7KubRQodqpM+ 8FTf32K8FcgzXnBpYS5kLu1d6xca4s12gab2DGsVxERJRA5BUa0V/tcfwCA0Yw5RLC+C Ec9C5Hock2o2JNAo6YMrtt6JVvTETpr+vwJLpemHtDPdbIs1MqcVbTv4R0U/Kre9zfsR dT7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=j0V0viTo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v6si9963590edy.149.2020.07.13.06.32.03; Mon, 13 Jul 2020 06:32:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=j0V0viTo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729924AbgGMN3t (ORCPT + 99 others); Mon, 13 Jul 2020 09:29:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729896AbgGMN3s (ORCPT ); Mon, 13 Jul 2020 09:29:48 -0400 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB5B5C08C5E0 for ; Mon, 13 Jul 2020 06:29:45 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id a6so16550454wrm.4 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=ocX4invmAxg0cLwHV4/ma6CR6GwjRaRi5TFQvNpG7TzLoMNImqKsE0+3dL4R4kYnU7 E5IZf59a23Z1dehbeUjPAfWm4oW+u7kaO8JoKxvBRfLcZ6371ynVEUYVzOML42v3mIXm Ed5WpQQVmvtspaBqla2ki1amrUiA7HITj3g1AIZKYYBBQ0p3TafYKDZugexATMRIa/ak x/LwtBG8iRBmHUE04TeBhUtaYJQeSeU2JON213R4dctHta5EN6TTVESdkWsca80vFJ/p QV/K6D6N6xcvnRmMhlTdAAHw23j0AjCZ5hBilAUK66KItPK1BFJZAvfSJnOLlhHrBxnE Iqrw== X-Gm-Message-State: AOAM533qdzZTvkMvb6jQbSfV2zI4sLklGicZLWsDhuRADt+jFZ5ntH69 CvJabsh5733sDRY7ocPZfQ8Aaw== 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 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 --- 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) -- 2.26.2