From 747d931340b0965c02fca91cee0b49b4ab4411af Mon Sep 17 00:00:00 2001 From: Kathiravan T Date: Thu, 21 Dec 2017 10:24:05 +0530 Subject: [PATCH] ipq806x: use proper partition for env varibales in eMMC In eMMC flash, whenever we save the env variables, it is updated in the wrong offset instead of using the APPSBLENV partition, which leads to the system hang in the next reboot. This patch addresses the same. Also, moved the function board_mmc_env_init to common/env.c, since the same functionality is used across ipq806x/ipq40xx/ipq807x. Change-Id: I4c446dad583089fb2515e13267aa7b4724c16fba Signed-off-by: Kathiravan T --- board/qca/arm/common/env.c | 41 +++++++++++++++++++++++++++++++++ board/qca/arm/ipq40xx/ipq40xx.c | 32 +------------------------ board/qca/arm/ipq806x/ipq806x.c | 4 ++++ board/qca/arm/ipq807x/ipq807x.c | 33 +------------------------- 4 files changed, 47 insertions(+), 63 deletions(-) diff --git a/board/qca/arm/common/env.c b/board/qca/arm/common/env.c index f35122d33f..3050b82f57 100644 --- a/board/qca/arm/common/env.c +++ b/board/qca/arm/common/env.c @@ -15,6 +15,10 @@ #include #include +#ifdef CONFIG_SDHCI_SUPPORT +#include +#endif + extern void nand_env_relocate_spec(void); extern int nand_env_init(void); @@ -26,6 +30,7 @@ extern int sf_env_init(void); #ifdef CONFIG_QCA_MMC extern int mmc_env_init(void); extern void mmc_env_relocate_spec(void); +extern int mmc_init(struct mmc *mmc); #endif /* @@ -84,3 +89,39 @@ void env_relocate_spec(void) } }; + +#ifdef CONFIG_QCA_MMC +#ifdef CONFIG_SDHCI_SUPPORT +int board_mmc_env_init(struct sdhci_host mmc_host) +#else +int board_mmc_env_init(qca_mmc mmc_host) +#endif +{ + block_dev_desc_t *blk_dev; + disk_partition_t disk_info; + int ret; + + if (mmc_init(mmc_host.mmc)) { + /* The HS mode command(cmd6) is getting timed out. So mmc card is + * not getting initialized properly. Since the env partition is not + * visible, the env default values are writing into the default + * partition (start of the mmc device). So do a reset again. + */ + if (mmc_init(mmc_host.mmc)) { + printf("MMC init failed \n"); + return -1; + } + } + blk_dev = mmc_get_dev(mmc_host.dev_num); + ret = get_partition_info_efi_by_name(blk_dev, + "0:APPSBLENV", &disk_info); + + if (ret == 0) { + board_env_offset = disk_info.start * disk_info.blksz; + board_env_size = disk_info.size * disk_info.blksz; + board_env_range = board_env_size; + BUG_ON(board_env_size > CONFIG_ENV_SIZE_MAX); + } + return ret; +} +#endif diff --git a/board/qca/arm/ipq40xx/ipq40xx.c b/board/qca/arm/ipq40xx/ipq40xx.c index 061c4308fd..ac89aa0c9e 100644 --- a/board/qca/arm/ipq40xx/ipq40xx.c +++ b/board/qca/arm/ipq40xx/ipq40xx.c @@ -227,36 +227,6 @@ int board_eth_init(bd_t *bis) } #ifdef CONFIG_QCA_MMC -int board_mmc_env_init(void) -{ - block_dev_desc_t *blk_dev; - disk_partition_t disk_info; - int ret; - - if (mmc_init(mmc_host.mmc)) { - /* The HS mode command(cmd6) is getting timed out. So mmc card is - * not getting initialized properly. Since the env partition is not - * visible, the env default values are writing into the default - * partition (start of the mmc device). So do a reset again. - */ - if (mmc_init(mmc_host.mmc)) { - printf("MMC init failed \n"); - return -1; - } - } - blk_dev = mmc_get_dev(mmc_host.dev_num); - ret = get_partition_info_efi_by_name(blk_dev, - "0:APPSBLENV", &disk_info); - - if (ret == 0) { - board_env_offset = disk_info.start * disk_info.blksz; - board_env_size = disk_info.size * disk_info.blksz; - board_env_range = board_env_size; - BUG_ON(board_env_size > CONFIG_ENV_SIZE_MAX); - } - return ret; -} - int board_mmc_init(bd_t *bis) { int ret; @@ -286,7 +256,7 @@ int board_mmc_init(bd_t *bis) ret = qca_mmc_init(bis, &mmc_host); if (!ret && sfi->flash_type == SMEM_BOOT_MMC_FLASH) { - ret = board_mmc_env_init(); + ret = board_mmc_env_init(mmc_host); } return ret; diff --git a/board/qca/arm/ipq806x/ipq806x.c b/board/qca/arm/ipq806x/ipq806x.c index 3218ac6277..d07d30dc18 100644 --- a/board/qca/arm/ipq806x/ipq806x.c +++ b/board/qca/arm/ipq806x/ipq806x.c @@ -185,6 +185,7 @@ int board_mmc_init(bd_t *bis) int ret = -ENODEV; u32 *emmc_base; int len; + qca_smem_flash_info_t *sfi = &qca_smem_flash_info; node = fdt_path_offset(gd->fdt_blob, "sdcc"); @@ -210,6 +211,9 @@ int board_mmc_init(bd_t *bis) ret = qca_mmc_init(bis, &mmc_host); } + if (!ret && sfi->flash_type == SMEM_BOOT_MMC_FLASH) { + ret = board_mmc_env_init(mmc_host); + } out: return ret; } diff --git a/board/qca/arm/ipq807x/ipq807x.c b/board/qca/arm/ipq807x/ipq807x.c index 6262103615..894becb78e 100644 --- a/board/qca/arm/ipq807x/ipq807x.c +++ b/board/qca/arm/ipq807x/ipq807x.c @@ -413,37 +413,6 @@ int board_eth_init(bd_t *bis) return ret; } -int board_mmc_env_init(void) -{ - block_dev_desc_t *blk_dev; - disk_partition_t disk_info; - int ret; - - if (mmc_init(mmc_host.mmc)) { - /* The HS mode command(cmd6) is getting timed out. So mmc card - * is not getting initialized properly. Since the env partition - * is not visible, the env default values are writing into the - * default partition (start of the mmc device). - * So do a reset again. - */ - if (mmc_init(mmc_host.mmc)) { - printf("MMC init failed \n"); - return -1; - } - } - blk_dev = mmc_get_dev(mmc_host.dev_num); - ret = get_partition_info_efi_by_name(blk_dev, - "0:APPSBLENV", &disk_info); - - if (ret == 0) { - board_env_offset = disk_info.start * disk_info.blksz; - board_env_size = disk_info.size * disk_info.blksz; - board_env_range = board_env_size; - BUG_ON(board_env_size > CONFIG_ENV_SIZE_MAX); - } - return ret; -} - int board_mmc_init(bd_t *bis) { int ret; @@ -475,7 +444,7 @@ int board_mmc_init(bd_t *bis) #endif if (!ret && sfi->flash_type == SMEM_BOOT_MMC_FLASH) { - ret = board_mmc_env_init(); + ret = board_mmc_env_init(mmc_host); } return ret;