From d3da2a207c05e251fe4ea9ee518944a17c127bb0 Mon Sep 17 00:00:00 2001 From: Karthick Jeyaraman Date: Sat, 4 Jul 2020 14:18:19 +0530 Subject: [PATCH] IPQ5018: Redcued U-boot reserved memory to 2MB - u-boot text region + pgtable requires 800KB. Hence adjusted text base address to 0x4A92000, so that the text region + pgtable fits at the last 800KB of 2MB memory space, leaving 200KB above them for other regions - Size of Heap region is reduced to 1MB from 1.5MB - Maple uses gmac controller for Ethernet DMA process, which does not require non-cached memory, hence we can avoid reserving 1MB for noncached memory and the same can used for other components. - Right now, 256KB of memory was used from stack for env reloc/save functionalities which makes the SP extend beyond 2MB. Hence, modified them to allocate memory from Heap. - With this patchset, the u-boot fits into 2MB space and the rest 2MB can be used for other components Change-Id: I962d86d81b1c52cbef575f974924d16ec6e3db89 Signed-off-by: Karthick Jeyaraman --- common/env_fat.c | 11 ++++++++++- common/env_mmc.c | 20 +++++++++++++++++--- common/env_nand.c | 30 ++++++++++++++++++++++++------ common/env_ubi.c | 25 ++++++++++++++++++++++--- include/configs/ipq5018.h | 4 ++-- 5 files changed, 75 insertions(+), 15 deletions(-) diff --git a/common/env_fat.c b/common/env_fat.c index d79d864a0c..32ba497d4f 100644 --- a/common/env_fat.c +++ b/common/env_fat.c @@ -76,12 +76,18 @@ int saveenv(void) void env_relocate_spec(void) { - ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE); + char *buf = NULL; block_dev_desc_t *dev_desc = NULL; disk_partition_t info; int dev, part; int err; + buf = (char *)memalign(ARCH_DMA_MINALIGN, CONFIG_ENV_SIZE); + if (!buf) { + printf("Error: Cannot allocate %d bytes\n", CONFIG_ENV_SIZE); + goto err_env_relocate; + } + part = get_device_and_partition(FAT_ENV_INTERFACE, FAT_ENV_DEVICE_AND_PART, &dev_desc, &info, 1); @@ -103,8 +109,11 @@ void env_relocate_spec(void) } env_import(buf, 1); + free(buf); return; err_env_relocate: set_default_env(NULL); + if (buf) + free(buf); } diff --git a/common/env_mmc.c b/common/env_mmc.c index 12f60ca50c..16aadcb686 100644 --- a/common/env_mmc.c +++ b/common/env_mmc.c @@ -139,15 +139,21 @@ static unsigned char env_flags; int mmc_saveenv(void) { - ALLOC_CACHE_ALIGN_BUFFER(env_t, env_new, 1); struct mmc *mmc = find_mmc_device(CONFIG_SYS_MMC_ENV_DEV); u32 offset; int ret, copy = 0; const char *errmsg; + env_t *env_new = (env_t *)memalign(ARCH_DMA_MINALIGN, CONFIG_ENV_SIZE); + if (!env_new) { + printf("Error: Cannot allocate %d bytes\n", CONFIG_ENV_SIZE); + return 1; + } + errmsg = init_mmc_for_env(mmc); if (errmsg) { printf("%s\n", errmsg); + free(env_new); return 1; } @@ -184,6 +190,7 @@ int mmc_saveenv(void) fini: fini_mmc_for_env(mmc); + free(env_new); return ret; } #endif /* CONFIG_CMD_SAVEENV */ @@ -298,12 +305,17 @@ err: void mmc_env_relocate_spec(void) { #if !defined(ENV_IS_EMBEDDED) - ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE); struct mmc *mmc; u32 offset; int ret; int dev = CONFIG_SYS_MMC_ENV_DEV; - const char *errmsg; + const char *errmsg = NULL; + char *buf = (char *)memalign(ARCH_DMA_MINALIGN, CONFIG_ENV_SIZE); + if (!buf) { + printf("Error: Cannot allocate %d bytes\n", CONFIG_ENV_SIZE); + ret = 1; + goto err; + } #ifdef CONFIG_SPL_BUILD dev = 0; @@ -336,6 +348,8 @@ fini: err: if (ret) set_default_env(errmsg); + if (buf) + free(buf); #endif } #endif /* CONFIG_ENV_OFFSET_REDUND */ diff --git a/common/env_nand.c b/common/env_nand.c index d1f617a088..3481a73479 100644 --- a/common/env_nand.c +++ b/common/env_nand.c @@ -183,7 +183,6 @@ static unsigned char env_flags; int nand_saveenv(void) { int ret = 0; - ALLOC_CACHE_ALIGN_BUFFER(env_t, env_new, 1); int env_idx = 0; struct env_location location[] = { { @@ -204,13 +203,22 @@ int nand_saveenv(void) #endif }; - - if (CONFIG_ENV_RANGE > board_env_size) + env_t *env_new = (env_t *)memalign(ARCH_DMA_MINALIGN, CONFIG_ENV_SIZE); + if (!env_new) { + printf("Error: Cannot allocate %d bytes\n", CONFIG_ENV_SIZE); return 1; + } + + if (CONFIG_ENV_RANGE > board_env_size) { + free(env_new); + return 1; + } ret = env_export(env_new); - if (ret) + if (ret) { + free(env_new); return ret; + } #ifdef CONFIG_ENV_OFFSET_REDUND env_new->flags = ++env_flags; /* increase the serial */ @@ -221,6 +229,7 @@ int nand_saveenv(void) if (!ret) { /* preset other copy for next write */ gd->env_valid = gd->env_valid == 2 ? 1 : 2; + free(env_new); return ret; } @@ -230,7 +239,7 @@ int nand_saveenv(void) printf("Warning: primary env write failed," " redundancy is lost!\n"); #endif - + free(env_new); return ret; } #endif /* CMD_SAVEENV */ @@ -385,7 +394,13 @@ void nand_env_relocate_spec(void) { #if !defined(ENV_IS_EMBEDDED) int ret; - ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE); + char *buf = NULL; + buf = (char *)memalign(ARCH_DMA_MINALIGN, CONFIG_ENV_SIZE); + if (!buf) { + printf("Error: Cannot allocate %d bytes\n", CONFIG_ENV_SIZE); + set_default_env(NULL); + return; + } #if defined(CONFIG_ENV_OFFSET_OOB) ret = get_nand_env_oob(&nand_info[nand_env_device], &nand_env_oob_offset); @@ -397,6 +412,7 @@ void nand_env_relocate_spec(void) printf("Found Environment offset in OOB..\n"); } else { set_default_env("!no env offset in OOB"); + free(buf); return; } #endif @@ -404,10 +420,12 @@ void nand_env_relocate_spec(void) ret = readenv(CONFIG_ENV_OFFSET, (u_char *)buf); if (ret) { set_default_env("!readenv() failed"); + free(buf); return; } env_import(buf, 1); + free(buf); #endif /* ! ENV_IS_EMBEDDED */ } #endif /* CONFIG_ENV_OFFSET_REDUND */ diff --git a/common/env_ubi.c b/common/env_ubi.c index e611199a58..50178a9a2f 100644 --- a/common/env_ubi.c +++ b/common/env_ubi.c @@ -81,14 +81,21 @@ int saveenv(void) #else /* ! CONFIG_SYS_REDUNDAND_ENVIRONMENT */ int saveenv(void) { - ALLOC_CACHE_ALIGN_BUFFER(env_t, env_new, 1); int ret; + env_t *env_new = (env_t *)memalign(ARCH_DMA_MINALIGN, CONFIG_ENV_SIZE) + if (!env_new) { + printf("Error: Cannot allocate %d bytes\n", CONFIG_ENV_SIZE); + return 1; + } ret = env_export(env_new); - if (ret) + if (ret) { + free(env_new); return ret; + } if (ubi_part(CONFIG_ENV_UBI_PART, NULL)) { + free(env_new); printf("\n** Cannot find mtd partition \"%s\"\n", CONFIG_ENV_UBI_PART); return 1; @@ -96,11 +103,13 @@ int saveenv(void) if (ubi_volume_write(CONFIG_ENV_UBI_VOLUME, (void *)env_new, CONFIG_ENV_SIZE)) { + free(env_new); printf("\n** Unable to write env to %s:%s **\n", CONFIG_ENV_UBI_PART, CONFIG_ENV_UBI_VOLUME); return 1; } + free(env_new); puts("done\n"); return 0; } @@ -172,12 +181,20 @@ void env_relocate_spec(void) #else /* ! CONFIG_SYS_REDUNDAND_ENVIRONMENT */ void env_relocate_spec(void) { - ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE); + + char *buf = NULL; + buf = (char *)memalign(ARCH_DMA_MINALIGN, CONFIG_ENV_SIZE); + if (!buf) { + printf("Error: Cannot allocate %d bytes\n"); + set_default_env(NULL); + return; + } if (ubi_part(CONFIG_ENV_UBI_PART, NULL)) { printf("\n** Cannot find mtd partition \"%s\"\n", CONFIG_ENV_UBI_PART); set_default_env(NULL); + free(buf); return; } @@ -185,9 +202,11 @@ void env_relocate_spec(void) printf("\n** Unable to read env from %s:%s **\n", CONFIG_ENV_UBI_PART, CONFIG_ENV_UBI_VOLUME); set_default_env(NULL); + free(buf); return; } env_import(buf, 1); + free(buf); } #endif /* CONFIG_SYS_REDUNDAND_ENVIRONMENT */ diff --git a/include/configs/ipq5018.h b/include/configs/ipq5018.h index 6f3dc90373..a0dcce7f26 100644 --- a/include/configs/ipq5018.h +++ b/include/configs/ipq5018.h @@ -96,7 +96,7 @@ #define GPIO_IN_OUT_ADDR(x) (TLMM_BASE + 0x4 + (x)*0x1000) #define CONFIG_SYS_SDRAM_BASE 0x40000000 -#define CONFIG_SYS_TEXT_BASE 0x4A900000 +#define CONFIG_SYS_TEXT_BASE 0x4A920000 #define CONFIG_SYS_SDRAM_SIZE 0x10000000 #define CONFIG_MAX_RAM_BANK_SIZE CONFIG_SYS_SDRAM_SIZE #define CONFIG_SYS_LOAD_ADDR (CONFIG_SYS_SDRAM_BASE + (64 << 20)) @@ -134,7 +134,7 @@ extern loff_t board_env_size; #define CONFIG_ENV_OFFSET board_env_offset #define CONFIG_ENV_SIZE CONFIG_ENV_SIZE_MAX #define CONFIG_ENV_RANGE board_env_range -#define CONFIG_SYS_MALLOC_LEN (CONFIG_ENV_SIZE_MAX + (1024 << 10)) +#define CONFIG_SYS_MALLOC_LEN (CONFIG_ENV_SIZE_MAX + (500 << 10)) /* * NAND Flash Configs