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: 11659775 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 B2B22618 for ; Mon, 13 Jul 2020 13:32:07 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8B1F0206F0 for ; Mon, 13 Jul 2020 13:32:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="V+S0psXY"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=baylibre-com.20150623.gappssmtp.com header.i=@baylibre-com.20150623.gappssmtp.com header.b="j0V0viTo" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8B1F0206F0 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=gKG6KyadT0oXqHuNlReTsMb4J23M0toB86LQe1gy/Bw=; b=V+S0psXYSa9dL6hExrjXHLk/K uL8/+u0WIm6dFRZr4+Z35tYkBA/wlYx3OtVNBheEB5s/oEDPa5tVAqAPdEY78yzXMIxDo+WAVA/nN doz8c7Rq/HeJKDTr0qYjrydCNFV9loLL2eGDoZJh7/KiIYeHr7nlpSjMDyw4yh7ZcFSNcWePQCwzD tZEc3cPt+eMuDe8cAbw7oFzEfkvv8Boqua6JNF5J3xjpANflObLTCh+b7UzngZ6oKIgulZstr2hTK RjRys7UxPHZi6QynsIOwqXTytKFskxCC3xBbgjD6sh1puf2UZxmrHUvNKSBDnJc4bYWj1xSJiMZMp 8qR53IAjw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1juyXW-0000Kw-Ua; Mon, 13 Jul 2020 13:30:38 +0000 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1juyWf-0008Ln-Cc for linux-arm-kernel@lists.infradead.org; Mon, 13 Jul 2020 13:29:51 +0000 Received: by mail-wr1-x443.google.com with SMTP id j4so16547684wrp.10 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=QMtm7zxAi1aNZb0g+EpZyOOv7KBcp7sxDzEjQaZzFJ/YSs6Jc36mi6tiMkooIzBkbK EMe5DBkBXUKN++iUJubH9w5+fTJ16f6VHPdRtEWKZwJt8G5MF6Jf2wat94+uXdIqbd6/ Z/8DSiIG86yn0TvX0AKSnTQcFvutytOV2VPPpMWc6/PX0CiGJaTnrWIJknQNnM8EdTAJ 2L0C5666o8oLHfvYruuOkcObQO3q72L/G0X2p2Fu3aqk4DClL57Xh9pkj5/nREdDgiED 0nxUJl+So+YiWYyn4vqNp4sWXVpab/wzGWheZnbpB9tE2WO0zX2PNkoxtcGExeOGBUsq ylbw== X-Gm-Message-State: AOAM533Q9IgHuk7YM2zmfZ65vdUOdUVUI+shW4zbc0lA1RxJujWXZvlQ xuFacZblYUfRLseflhL/cbNyTg== 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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200713_092945_523043_AE095354 X-CRM114-Status: GOOD ( 14.53 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:443 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Alexandre Bailon , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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)