From 1faa3fe00b48c638b04ed7bd59fc007e1cf20975 Mon Sep 17 00:00:00 2001 From: Sridharan S N Date: Fri, 15 Sep 2023 15:06:27 +0530 Subject: [PATCH] armv7: qca: common: smem: skip printing the partition info if it exceeds flash size skip printing the partition info in smem if it exceeds flash size for both nand and nor cases. Change-Id: I446a3300865fbf543b6e585f918f747a1b75a15c Signed-off-by: Sridharan S N --- arch/arm/cpu/armv7/qca/common/smem.c | 39 +++++++++++++++++++++++++++- drivers/mtd/spi/spi_flash.c | 8 +++++- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/arch/arm/cpu/armv7/qca/common/smem.c b/arch/arm/cpu/armv7/qca/common/smem.c index 468d1197c5..c2c3f47669 100644 --- a/arch/arm/cpu/armv7/qca/common/smem.c +++ b/arch/arm/cpu/armv7/qca/common/smem.c @@ -42,6 +42,9 @@ #ifdef IPQ_UBI_VOL_WRITE_SUPPORT static struct ubi_device *ubi; #endif + +extern unsigned int get_spi_flash_size(void); + typedef struct smem_pmic_type { unsigned pmic_model; @@ -1162,10 +1165,39 @@ static void print_ubi_vol_info(void) } #endif +int check_flash_exceed(struct smem_ptn *p, uint32_t offset, uint32_t psize) { + + uint32_t fsize = 0; + qca_smem_flash_info_t *sfi = &qca_smem_flash_info; + uint32_t flash_type = sfi->flash_type; + + if(flash_type == SMEM_BOOT_SPI_FLASH) + flash_type = part_which_flash(p) ? SMEM_BOOT_QSPI_NAND_FLASH : + SMEM_BOOT_SPI_FLASH; + + switch (flash_type) { + case SMEM_BOOT_SPI_FLASH: + fsize = get_spi_flash_size(); + break; +#ifdef CONFIG_CMD_NAND + case SMEM_BOOT_QSPI_NAND_FLASH: + fsize = nand_info[CONFIG_QPIC_NAND_NAND_INFO_IDX].size; + break; +#endif + default: + return -1; + } + + if (offset + psize > fsize) + return -1; + + return 0; +} + int do_smeminfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { qca_smem_flash_info_t *sfi = &qca_smem_flash_info; - int i; + int i,ret; uint32_t bsize; #ifdef IPQ_UBI_VOL_WRITE_SUPPORT ubi_set_rootfs_part(); @@ -1218,6 +1250,11 @@ int do_smeminfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) psize = ((loff_t)p->size) * bsize; } + /* skip printing the partition that exceeds flash size */ + ret = check_flash_exceed(p, ((loff_t)p->start) * bsize, psize); + if (ret) + continue; + printf("%3d: " smem_ptn_name_fmt " 0x%08x %#16llx %#16llx\n", i, p->name, p->attr, ((loff_t)p->start) * bsize, psize); #ifdef IPQ_UBI_VOL_WRITE_SUPPORT diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c index 815dec34f8..ad8b24dac0 100644 --- a/drivers/mtd/spi/spi_flash.c +++ b/drivers/mtd/spi/spi_flash.c @@ -31,6 +31,12 @@ DECLARE_GLOBAL_DATA_PTR; +static u32 spi_fsize; + +u32 get_spi_flash_size(void) { + return spi_fsize; +} + static void spi_flash_addr(struct spi_flash *flash, u32 addr, u8 *cmd) { /* cmd[0] is actual command */ @@ -1324,7 +1330,7 @@ do_generic_probe: return -EINVAL; } #endif - + spi_fsize = flash->size; #ifdef CONFIG_SPI_NAND print_sf_info: #endif