Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1007468ybh; Tue, 21 Jul 2020 13:22:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyY4OAnf41jAr2J7J8Z14fEbbzOMsqIOUPr9SYyc0eXFuLnaeobP5j1zea/RMS2Pg9Axg3a X-Received: by 2002:aa7:dad6:: with SMTP id x22mr26932705eds.310.1595362952869; Tue, 21 Jul 2020 13:22:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595362952; cv=none; d=google.com; s=arc-20160816; b=MFTwI2lZ3lCj6Jtt2FtYsyERMMqvZnL1aOix0tWo+vwnbNXMqQV/iOChl31ivXhtMa uhm1L2DLkoZmuNsmdBwGsXTPqltQunSj38CV0XG0SZ3e7rQF9RxaOATvRShYf3H1Y3Q6 wCX0Lezeh4OajW0RwEQ8CErwsv1VMiBY40DwGX5rqyTckQaQcA7OLefl0JbIkXlMnQSz KIVD9/9fQflPi5wkpKe4Ii+yaT+fC9k/Ex9DVe7uGbE6BfHsLom7+t8DWDRzmtOBY+fG YzbZpMwc39wV9mdirOKue5BHzmR9i1UvIrMVRjZlCOVjLH+957oVUGMU2uwUwuIbkP7O aceA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=yz8Pn1+0L8o3BW9wpfpvX9tjdPGaAfKllQBX5CrlbQA=; b=OZVfSNH0joPxmWxRvBTnebE6fN1zBmfZDCFQKYzOjaylP3rbgxRNnq1oz3huzhZ8vP DDuy3vYxGgtcaXIzmk8JpwzhEA/EbJiiIuKuVK0b4LqDEgpIwtRAB50sxM5+hi8xz8Zk nQo3Mi0moy8QlMLU6T4Kees+LHvKUA+KK5xy/W5rvskiLP2SG1MVJswlFrtJAZrjmhhY +Xh2XBtL5xk4kAvJDaMXV+1poiBKk2Z+AyT1sxRU9fwskdmh7KpuWE15V+9uRqDr15+U QFzIZMOIW8m9rNKvQvm8CJsmBtDNfThkpQYGElHjed255/Yfl1ZCic8gjorVIYbee+dy lv2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tCHfjNfY; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j18si13770818eja.217.2020.07.21.13.22.09; Tue, 21 Jul 2020 13:22:32 -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=@linaro.org header.s=google header.b=tCHfjNfY; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730312AbgGUUVb (ORCPT + 99 others); Tue, 21 Jul 2020 16:21:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729928AbgGUUVa (ORCPT ); Tue, 21 Jul 2020 16:21:30 -0400 Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 816C2C0619DC for ; Tue, 21 Jul 2020 13:21:30 -0700 (PDT) Received: by mail-pl1-x643.google.com with SMTP id p1so10751199pls.4 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=B2YDlMYTZujfFetYdWNotAw73Rlw0/myL6A3aPQA2yxaumjorCzvmRM2WkEhbqbQAM uNyvIO7H66MAmW45GsRB/bdoXcwzGhQSVjlsXiNChlwMXU3dwJbO9apTtItLiB6YtY9n OikgVxCdDQkvbQq2BRhkD6J4rRX4OcSGdXsm4c/9VZA3QWrBZK/CBdxd5FpGSESKfPPw 9TmgtmXmXDEbsMKREFkBOuKpnnFxVdI9x82Xf5lkKgUfjZbi6oIAeXWIs53ByaCW8LIv y//XQ+IQoauEvBuwB3mFB0OZjrWWOvYB+eLkTa02OxT9i4GOmbZBiUwkn9zuXnJkiLSw M9Jg== X-Gm-Message-State: AOAM533scfDl+BLKGpntiy0NboekuajfPsWs3X7LViN581fr0VJrnVwW mQ5xA4j0iUQemAJjqilr/9WLFA== 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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 >