From mboxrd@z Thu Jan 1 00:00:00 1970 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=-10.1 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 F0EDBC433E4 for ; Tue, 21 Jul 2020 20:21:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D0D4120729 for ; Tue, 21 Jul 2020 20:21:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="tCHfjNfY" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730304AbgGUUVb (ORCPT ); Tue, 21 Jul 2020 16:21:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730089AbgGUUVa (ORCPT ); Tue, 21 Jul 2020 16:21:30 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 707A0C0619DB for ; Tue, 21 Jul 2020 13:21:30 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id gc15so1853222pjb.0 for ; Tue, 21 Jul 2020 13:21:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=yz8Pn1+0L8o3BW9wpfpvX9tjdPGaAfKllQBX5CrlbQA=; b=tCHfjNfYorbKQEm370wu+jdtqr5TvIQgpuBB45Meg4+6fvhDoSy7tjjQ60WD2XSNa3 VAGHh2UdTa2UOJPsZ69yp3xCXwzso7pk7mtlf6iVxZwd0UkCe8sc1QItaFmzwclayQy4 /OP3wFrzmne7MneChKgBMj45sambaMnWKho/Tx3GUMzt2xp9UDVwYZIMR0bTlqDB/BhQ 4htZmZDIpFHd9nayV/wqx0K84Mm+EHMrjWGnwrMmW3Kl5KnSagx7zOeNzuG96jpcKRRg gRcgYXztpjnImvOH+bttP99fbubzOEUGNg3OKwCh5wVDVwAE1TZyN3/TuzHsST3VtgdS 3nbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=yz8Pn1+0L8o3BW9wpfpvX9tjdPGaAfKllQBX5CrlbQA=; b=UxuJzFv3uCXaLeIGC9sTlTskOD6/SzA6hyAkPUYhTW9gwv6t9azcrxZz0roXffY2xa YVFYg+fv/rWLjD4R6KeGfGIVdihlIclUncT/yMz4cp5WozJK88YCDO3I/QOxXXJepCKj SDdWVcIeSyynd8oluOR0t7TwXwISP/GtxvWrQIjEm9ZWF5kXTdi3tzFgeNvrrHk/Kkfd yi/4/9CUwjdwYbclV9TKGwTVfEtXkdyjzYLBG979wVKcXWo7DFLG2WW8+gTYG475Y/C3 c+NzRR0Qxdl7asZd9rpB8s8k6NY4sdykLUKPBqkQQR+ae3HNIEpNQsDYoOWMh1ni7LEI Y+gA== X-Gm-Message-State: AOAM531Mjjq1bLQU7TZ86bu5pUIBmeshDaGRFJNqlfFigzG+m6t+bizu zF0EB+tC8DurSGARAex9D0rAsg== X-Google-Smtp-Source: ABdhPJytqLVViBfMVx0NR9p31f2ZvvL3YV4+D+msQxUeUSoE+b4kNfAIQ8/jDFn0Tw3ueffWJro/wA== X-Received: by 2002:a17:90a:290e:: with SMTP id g14mr6723735pjd.85.1595362889850; Tue, 21 Jul 2020 13:21:29 -0700 (PDT) Received: from xps15 (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id t1sm19324221pgq.66.2020.07.21.13.21.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jul 2020 13:21:29 -0700 (PDT) Date: Tue, 21 Jul 2020 14:21:27 -0600 From: Mathieu Poirier To: Alexandre Bailon Cc: ohad@wizery.com, bjorn.andersson@linaro.org, robh+dt@kernel.org, matthias.bgg@gmail.com, 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 Subject: Re: [PATCH 4/6] remoteproc: mtk_vpu_rproc: Don't try to load empty PT_LOAD segment Message-ID: <20200721202127.GB1227776@xps15> References: <20200713132927.24925-1-abailon@baylibre.com> <20200713132927.24925-5-abailon@baylibre.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200713132927.24925-5-abailon@baylibre.com> Sender: linux-remoteproc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org On Mon, Jul 13, 2020 at 03:29:25PM +0200, Alexandre Bailon wrote: > 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. This patch doesn't address the real problem, which are empty load segments. In my opinion that should be dealt with rather than having to patch things up. On the flip side I suspect that you don't control all the process and that systems are out there with faulty fw images. As such: Reviewed-by: Mathieu Poirier > > 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 >