Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1E5FAC74A5B for ; Thu, 30 Mar 2023 05:23:23 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2B01C85D63; Thu, 30 Mar 2023 07:23:21 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1680153801; bh=8g24h2pnugc6FWhEGOfdSVhA3Qnk7mBCLbvWohtnZSE=; h=Date:Subject:To:References:From:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=JBPsgNSK7jS3ehIiQSVFarVzsnQf4bl7X4IRjDDef9RqCh01Q0dVZATK2Knqe8iGl 5/rRc15O7LW7AlNGiY0pkuIACwS2fw6bE+I5ozvr7LrDtK+sL64S0UWvs2yOuou25Q p8Il0CP+L0fMloaYJHJ1P2HiFln2tjxhzKNYBAK06d0br5mOWxn5O7TPE5r+ZBqesX QKDzH1ukGaT50Hnd8Vw45xlJtUHbiHSkpgFBrzowAKyc4xxLqC0cGuW3qw7FIczjIU nlBFQYWGcB/aCOgm8+JuCm9X1vcEXzyCh/nc7no30hVCn2RZIxL0d+B/Zn6NIi7NOq k/kyeTrQcENiQ== Received: by phobos.denx.de (Postfix, from userid 109) id 36F0A85D9B; Thu, 30 Mar 2023 07:23:19 +0200 (CEST) Received: from mout-u-107.mailbox.org (mout-u-107.mailbox.org [IPv6:2001:67c:2050:101:465::107]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 5003E85D63 for ; Thu, 30 Mar 2023 07:23:16 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sr@denx.de Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-u-107.mailbox.org (Postfix) with ESMTPS id 4PnBdt032yz9sSL; Thu, 30 Mar 2023 07:23:14 +0200 (CEST) Message-ID: <24094346-ea79-80ec-5a45-9c7efceb543d@denx.de> Date: Thu, 30 Mar 2023 07:23:13 +0200 MIME-Version: 1.0 Subject: Re: [PATCH] mtd: cfi: respect reg address length Content-Language: en-US To: =?UTF-8?Q?Nuno_S=c3=a1?= , u-boot@lists.denx.de References: <20230327132229.1061821-1-nuno.sa@analog.com> From: Stefan Roese In-Reply-To: <20230327132229.1061821-1-nuno.sa@analog.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 4PnBdt032yz9sSL X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean On 3/27/23 15:22, Nuno Sá wrote: > flash_get_size() will get the flash size from the device itself and go > through all erase regions to read protection status. However, the device > mappable region (eg: devicetree reg property) might be lower than the > device full size which means that the above cycle will result in a data > bus exception. This change fixes it by reading the 'addr_size' during > probe() and also use that as one possible upper limit. > > Signed-off-by: Nuno Sá > --- > > To give a bit more of background for this patch, I caught this issue > when running u-boot on microblaze which uses xilinx axi_linear_flash IP. > On ADI designs using that IP, the flash size was set to 32MiB resulting > in the mentioned data bus exception as we obviously access past the > IP size. > > That said, there was not real reason for the flash truncation so we'll > be fixing our designs so the IP will contemplate the complete flash > size. > > For the above reason, I was not really sure to mark the patch as RFC or > not... Anyways, it still feels like a valid "protection" to have rather > then just aborting (even if it does not really make sense to ever > truncate the flash in devicetree). > > drivers/mtd/cfi_flash.c | 10 ++++++++-- > include/flash.h | 1 + > 2 files changed, 9 insertions(+), 2 deletions(-) Reviewed-by: Stefan Roese Thanks, Stefan > diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c > index f378f6fb6139..432d0d5c9ecb 100644 > --- a/drivers/mtd/cfi_flash.c > +++ b/drivers/mtd/cfi_flash.c > @@ -2196,7 +2196,11 @@ ulong flash_get_size(phys_addr_t base, int banknum) > /* multiply the size by the number of chips */ > info->size *= size_ratio; > max_size = cfi_flash_bank_size(banknum); > - if (max_size && info->size > max_size) { > + if (max_size) > + max_size = min(info->addr_size, max_size); > + else > + max_size = info->addr_size; > + if (info->size > max_size) { > debug("[truncated from %ldMiB]", info->size >> 20); > info->size = max_size; > } > @@ -2492,15 +2496,17 @@ unsigned long flash_init(void) > static int cfi_flash_probe(struct udevice *dev) > { > fdt_addr_t addr; > + fdt_size_t size; > int idx; > > for (idx = 0; idx < CFI_MAX_FLASH_BANKS; idx++) { > - addr = dev_read_addr_index(dev, idx); > + addr = dev_read_addr_size_index(dev, idx, &size); > if (addr == FDT_ADDR_T_NONE) > break; > > flash_info[cfi_flash_num_flash_banks].dev = dev; > flash_info[cfi_flash_num_flash_banks].base = addr; > + flash_info[cfi_flash_num_flash_banks].addr_size = size; > cfi_flash_num_flash_banks++; > } > gd->bd->bi_flashstart = flash_info[0].base; > diff --git a/include/flash.h b/include/flash.h > index 95992fa689bb..3710a2731b76 100644 > --- a/include/flash.h > +++ b/include/flash.h > @@ -46,6 +46,7 @@ typedef struct { > #ifdef CONFIG_CFI_FLASH /* DM-specific parts */ > struct udevice *dev; > phys_addr_t base; > + phys_size_t addr_size; > #endif > } flash_info_t; > Viele Grüße, Stefan Roese -- DENX Software Engineering GmbH, Managing Director: Erika Unter HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr@denx.de