]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
mtd: cfi: respect reg address length
authorNuno Sá <nuno.sa@analog.com>
Thu, 11 May 2023 11:19:50 +0000 (13:19 +0200)
committerStefan Roese <sr@denx.de>
Mon, 15 May 2023 08:00:30 +0000 (10:00 +0200)
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á <nuno.sa@analog.com>
drivers/mtd/cfi_flash.c
include/flash.h

index f378f6fb6139b58c85b7a4fd6ee789a21d5764ac..8ade7949a68e0010b37af641c20d85c4f95b7b38 100644 (file)
@@ -2196,6 +2196,12 @@ 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);
+#ifdef CONFIG_CFI_FLASH
+               if (max_size)
+                       max_size = min((unsigned long)info->addr_size, max_size);
+               else
+                       max_size = info->addr_size;
+#endif
                if (max_size && info->size > max_size) {
                        debug("[truncated from %ldMiB]", info->size >> 20);
                        info->size = max_size;
@@ -2492,15 +2498,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;
index 95992fa689bbc7c8cbb2fbe34e7cbdac958a77f4..3710a2731b760b2500eba76b4b69ef271b451825 100644 (file)
@@ -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;