[ELDK] [PATCH V2 03/10] META-ELDK: u-boot: Fix memory slowness on M53EVK

Marek Vasut marex at denx.de
Tue Apr 1 23:21:14 CEST 2014


Add patches for M53EVK which make the DRAM access in U-Boot much faster.
Please see u-boot/m53evk/0004-arm-mx5-Fix-memory-slowness-on-M53EVK.patch
commit message for complete explanation of the issue and it's resolution.

Signed-off-by: Marek Vasut <marex at denx.de>
Cc: Wolfgang Denk <wd at denx.de>
---
 ...on-Add-get_effective_memsize-to-memsize.c.patch | 230 +++++++++++++++++++++
 ...005-arm-mx5-Fix-memory-slowness-on-M53EVK.patch |  63 ++++++
 ...5-Avoid-hardcoding-memory-sizes-on-M53EVK.patch | 111 ++++++++++
 meta-eldk/recipes-bsp/uboot/u-boot_2014.01.bb      |   3 +
 4 files changed, 407 insertions(+)
 create mode 100644 meta-eldk/recipes-bsp/uboot/u-boot/m53evk/0004-common-Add-get_effective_memsize-to-memsize.c.patch
 create mode 100644 meta-eldk/recipes-bsp/uboot/u-boot/m53evk/0005-arm-mx5-Fix-memory-slowness-on-M53EVK.patch
 create mode 100644 meta-eldk/recipes-bsp/uboot/u-boot/m53evk/0006-arm-mx5-Avoid-hardcoding-memory-sizes-on-M53EVK.patch

V2: Add missing patch, which is backported from mainline U-Boot commit
    e38661634b3d60af80d85ce9eb570a45db4729ca . This is important as without
    this backport, the remaining two patches are useless. Apologies for the
    screwup.

diff --git a/meta-eldk/recipes-bsp/uboot/u-boot/m53evk/0004-common-Add-get_effective_memsize-to-memsize.c.patch b/meta-eldk/recipes-bsp/uboot/u-boot/m53evk/0004-common-Add-get_effective_memsize-to-memsize.c.patch
new file mode 100644
index 0000000..26b6510
--- /dev/null
+++ b/meta-eldk/recipes-bsp/uboot/u-boot/m53evk/0004-common-Add-get_effective_memsize-to-memsize.c.patch
@@ -0,0 +1,230 @@
+From 21733a06721c1a3c858108cda4096656a39331df Mon Sep 17 00:00:00 2001
+From: York Sun <yorksun at freescale.com>
+Date: Tue, 11 Feb 2014 11:57:26 -0800
+Subject: [PATCH 1/3] common: Add get_effective_memsize() to memsize.c
+
+This function has been around for powerpc. It is used for systems with
+memory more than CONFIG_MAX_MEM_MAPPED. In case of non-contiguous memory,
+this feature can limit U-boot to one block without going over the limit.
+
+Signed-off-by: York Sun <yorksun at freescale.com>
+Acked-by: Albert ARIBAUD <albert.u.boot at aribaud.net>
+---
+ arch/arm/lib/board.c               |  2 +-
+ arch/powerpc/cpu/mpc512x/traps.c   |  1 -
+ arch/powerpc/cpu/mpc85xx/traps.c   |  1 -
+ arch/powerpc/cpu/mpc86xx/traps.c   |  1 -
+ arch/powerpc/lib/board.c           | 18 ------------------
+ arch/powerpc/lib/bootm.c           |  1 -
+ board/freescale/p1022ds/spl.c      |  2 +-
+ board/freescale/p1_p2_rdb_pc/spl.c |  2 +-
+ common/board_f.c                   | 11 -----------
+ common/cmd_log.c                   |  2 +-
+ common/memsize.c                   | 16 +++++++++++++++-
+ include/common.h                   |  1 +
+ 12 files changed, 20 insertions(+), 38 deletions(-)
+
+diff --git a/arch/arm/lib/board.c b/arch/arm/lib/board.c
+index b770e25..5fbb3a9 100644
+--- a/arch/arm/lib/board.c
++++ b/arch/arm/lib/board.c
+@@ -322,7 +322,7 @@ void board_init_f(ulong bootflag)
+ 	gd->ram_size -= CONFIG_SYS_MEM_TOP_HIDE;
+ #endif
+ 
+-	addr = CONFIG_SYS_SDRAM_BASE + gd->ram_size;
++	addr = CONFIG_SYS_SDRAM_BASE + get_effective_memsize();
+ 
+ #ifdef CONFIG_LOGBUFFER
+ #ifndef CONFIG_ALT_LB_ADDR
+diff --git a/arch/powerpc/cpu/mpc512x/traps.c b/arch/powerpc/cpu/mpc512x/traps.c
+index 1016991..9f5bcd7 100644
+--- a/arch/powerpc/cpu/mpc512x/traps.c
++++ b/arch/powerpc/cpu/mpc512x/traps.c
+@@ -27,7 +27,6 @@ extern unsigned long search_exception_table(unsigned long);
+  * amount of memory on the system if we're unable to keep all
+  * the memory mapped in.
+  */
+-extern ulong get_effective_memsize(void);
+ #define END_OF_MEM (gd->bd->bi_memstart + get_effective_memsize())
+ 
+ /*
+diff --git a/arch/powerpc/cpu/mpc85xx/traps.c b/arch/powerpc/cpu/mpc85xx/traps.c
+index 3ef6e4a..24adbc3 100644
+--- a/arch/powerpc/cpu/mpc85xx/traps.c
++++ b/arch/powerpc/cpu/mpc85xx/traps.c
+@@ -35,7 +35,6 @@ extern unsigned long search_exception_table(unsigned long);
+  * amount of memory on the system if we're unable to keep all
+  * the memory mapped in.
+  */
+-extern ulong get_effective_memsize(void);
+ #define END_OF_MEM (gd->bd->bi_memstart + get_effective_memsize())
+ 
+ static __inline__ void set_tsr(unsigned long val)
+diff --git a/arch/powerpc/cpu/mpc86xx/traps.c b/arch/powerpc/cpu/mpc86xx/traps.c
+index 0b7ea3b..92fb537 100644
+--- a/arch/powerpc/cpu/mpc86xx/traps.c
++++ b/arch/powerpc/cpu/mpc86xx/traps.c
+@@ -29,7 +29,6 @@ extern unsigned long search_exception_table(unsigned long);
+  * amount of memory on the system if we're unable to keep all
+  * the memory mapped in.
+  */
+-extern ulong get_effective_memsize(void);
+ #define END_OF_MEM (gd->bd->bi_memstart + get_effective_memsize())
+ 
+ /*
+diff --git a/arch/powerpc/lib/board.c b/arch/powerpc/lib/board.c
+index 34bbfca..13d761c 100644
+--- a/arch/powerpc/lib/board.c
++++ b/arch/powerpc/lib/board.c
+@@ -312,17 +312,6 @@ static init_fnc_t *init_sequence[] = {
+ 	NULL,	/* Terminate this list */
+ };
+ 
+-ulong get_effective_memsize(void)
+-{
+-#ifndef	CONFIG_VERY_BIG_RAM
+-	return gd->ram_size;
+-#else
+-	/* limit stack to what we can reasonable map */
+-	return ((gd->ram_size > CONFIG_MAX_MEM_MAPPED) ?
+-		CONFIG_MAX_MEM_MAPPED : gd->ram_size);
+-#endif
+-}
+-
+ static int __fixup_cpu(void)
+ {
+ 	return 0;
+@@ -343,13 +332,6 @@ int fixup_cpu(void) __attribute__((weak, alias("__fixup_cpu")));
+  * initialized, and stack space is limited to a few kB.
+  */
+ 
+-#ifdef CONFIG_LOGBUFFER
+-unsigned long logbuffer_base(void)
+-{
+-	return CONFIG_SYS_SDRAM_BASE + get_effective_memsize() - LOGBUFF_LEN;
+-}
+-#endif
+-
+ void board_init_f(ulong bootflag)
+ {
+ 	bd_t *bd;
+diff --git a/arch/powerpc/lib/bootm.c b/arch/powerpc/lib/bootm.c
+index 41fc8f7..c08b62c 100644
+--- a/arch/powerpc/lib/bootm.c
++++ b/arch/powerpc/lib/bootm.c
+@@ -30,7 +30,6 @@
+ 
+ DECLARE_GLOBAL_DATA_PTR;
+ 
+-extern ulong get_effective_memsize(void);
+ static ulong get_sp (void);
+ extern void ft_fixup_num_cores(void *blob);
+ static void set_clocks_in_mhz (bd_t *kbd);
+diff --git a/board/freescale/p1022ds/spl.c b/board/freescale/p1022ds/spl.c
+index 7f151e3..7bd9d29 100644
+--- a/board/freescale/p1022ds/spl.c
++++ b/board/freescale/p1022ds/spl.c
+@@ -21,7 +21,7 @@ static const u32 sysclk_tbl[] = {
+ 	99999000, 11111000, 12499800, 13333200
+ };
+ 
+-ulong get_effective_memsize(void)
++phys_size_t get_effective_memsize(void)
+ {
+ 	return CONFIG_SYS_L2_SIZE;
+ }
+diff --git a/board/freescale/p1_p2_rdb_pc/spl.c b/board/freescale/p1_p2_rdb_pc/spl.c
+index 9bb0716..8d0d850 100644
+--- a/board/freescale/p1_p2_rdb_pc/spl.c
++++ b/board/freescale/p1_p2_rdb_pc/spl.c
+@@ -20,7 +20,7 @@ static const u32 sysclk_tbl[] = {
+ 	99999000, 11111000, 12499800, 13333200
+ };
+ 
+-ulong get_effective_memsize(void)
++phys_size_t get_effective_memsize(void)
+ {
+ 	return CONFIG_SYS_L2_SIZE;
+ }
+diff --git a/common/board_f.c b/common/board_f.c
+index aa70c3e..5c7a17f 100644
+--- a/common/board_f.c
++++ b/common/board_f.c
+@@ -223,17 +223,6 @@ static int show_dram_config(void)
+ 	return 0;
+ }
+ 
+-ulong get_effective_memsize(void)
+-{
+-#ifndef	CONFIG_VERY_BIG_RAM
+-	return gd->ram_size;
+-#else
+-	/* limit stack to what we can reasonable map */
+-	return ((gd->ram_size > CONFIG_MAX_MEM_MAPPED) ?
+-		CONFIG_MAX_MEM_MAPPED : gd->ram_size);
+-#endif
+-}
+-
+ void __dram_init_banksize(void)
+ {
+ #if defined(CONFIG_NR_DRAM_BANKS) && defined(CONFIG_SYS_SDRAM_BASE)
+diff --git a/common/cmd_log.c b/common/cmd_log.c
+index 8164bdf..38d0f5e 100644
+--- a/common/cmd_log.c
++++ b/common/cmd_log.c
+@@ -52,7 +52,7 @@ static char *lbuf;
+ 
+ unsigned long __logbuffer_base(void)
+ {
+-	return CONFIG_SYS_SDRAM_BASE + gd->ram_size - LOGBUFF_LEN;
++	return CONFIG_SYS_SDRAM_BASE + get_effective_memsize() - LOGBUFF_LEN;
+ }
+ unsigned long logbuffer_base(void)
+ __attribute__((weak, alias("__logbuffer_base")));
+diff --git a/common/memsize.c b/common/memsize.c
+index 73b92c8..589400d 100644
+--- a/common/memsize.c
++++ b/common/memsize.c
+@@ -5,7 +5,10 @@
+  * SPDX-License-Identifier:	GPL-2.0+
+  */
+ 
+-#include <config.h>
++#include <common.h>
++
++DECLARE_GLOBAL_DATA_PTR;
++
+ #ifdef __PPC__
+ /*
+  * At least on G2 PowerPC cores, sequential accesses to non-existent
+@@ -76,3 +79,14 @@ long get_ram_size(long *base, long maxsize)
+ 
+ 	return (maxsize);
+ }
++
++phys_size_t __weak get_effective_memsize(void)
++{
++#ifndef CONFIG_VERY_BIG_RAM
++	return gd->ram_size;
++#else
++	/* limit stack to what we can reasonable map */
++	return ((gd->ram_size > CONFIG_MAX_MEM_MAPPED) ?
++		CONFIG_MAX_MEM_MAPPED : gd->ram_size);
++#endif
++}
+diff --git a/include/common.h b/include/common.h
+index d49c514..ff109e7 100644
+--- a/include/common.h
++++ b/include/common.h
+@@ -454,6 +454,7 @@ void	api_init (void);
+ 
+ /* common/memsize.c */
+ long	get_ram_size  (long *, long);
++phys_size_t get_effective_memsize(void);
+ 
+ /* $(BOARD)/$(BOARD).c */
+ void	reset_phy     (void);
+-- 
+1.9.0
+
diff --git a/meta-eldk/recipes-bsp/uboot/u-boot/m53evk/0005-arm-mx5-Fix-memory-slowness-on-M53EVK.patch b/meta-eldk/recipes-bsp/uboot/u-boot/m53evk/0005-arm-mx5-Fix-memory-slowness-on-M53EVK.patch
new file mode 100644
index 0000000..94e9cfe
--- /dev/null
+++ b/meta-eldk/recipes-bsp/uboot/u-boot/m53evk/0005-arm-mx5-Fix-memory-slowness-on-M53EVK.patch
@@ -0,0 +1,63 @@
+From 07469fd3ae3c64dbc9d014c92a3ca74cd97aa297 Mon Sep 17 00:00:00 2001
+From: Marek Vasut <marex at denx.de>
+Date: Fri, 28 Mar 2014 04:45:16 +0100
+Subject: [PATCH 1/2] arm: mx5: Fix memory slowness on M53EVK
+
+Fix memory access slowness on i.MX53 M53EVK board. Let us inspect the
+issue: First of all, the i.MX53 CPU has two memory banks mapped at
+0x7000_0000 and 0xb000_0000 and each of those can hold up to 1GiB of
+DRAM memory. Notice that the memory area is not continuous. On M53EVK,
+each of the banks contain 512MiB of DRAM, which makes a total of 1GiB
+of memory available to the system.
+
+The problem is how the relocation of U-Boot is treated on i.MX53 . The
+U-Boot is placed at the ((start of first DRAM partition) + (gd->ram_size)) .
+This in turn poses a problem, since in our case, the gd->ram_size is 1GiB,
+the first DRAM bank starts at 0x7000_0000 and contains 512MiB of memory.
+Thus, with this algorithm, U-Boot is placed at offset:
+
+    0x7000_0000 + 1GiB - sizeof(u-boot and some small margin)
+
+This is past the DRAM available in the first bank on M53EVK, but is still
+within the address range of the first DRAM bank. Because of the memory
+wrap-around, the data can still be read and written to this area, but the
+access is much slower.
+
+There were two ideas how to solve this problem, first was to map both of
+the available DRAM chunks next to one another by using MMU, second was to
+define CONFIG_VERY_BIG_RAM and CONFIG_MAX_MEM_MAPPED to size of the memory
+in the first DRAM bank. We choose the later because it turns out the former
+is not applicable afterall. The former cannot be used in case Linux kernel
+was loaded into the second DRAM bank area, which would be remapped and one
+would try booting the kernel, since at some point before the kernel is started,
+the MMU would be turned off, which would destroy the mapping and hang the
+system.
+
+Signed-off-by: Marek Vasut <marex at denx.de>
+Cc: Fabio Estevam <fabio.estevam at freescale.com>
+Cc: Stefano Babic <sbabic at denx.de>
+Cc: Wolfgang Denk <wd at denx.de>
+
+V2: Reword the commit message
+---
+ include/configs/m53evk.h | 4 +++-
+ 1 file changed, 3 insertions(+), 1 deletion(-)
+
+diff --git a/include/configs/m53evk.h b/include/configs/m53evk.h
+index 9d41e75..d592318 100644
+--- a/include/configs/m53evk.h
++++ b/include/configs/m53evk.h
+@@ -62,7 +62,9 @@
+ #define PHYS_SDRAM_SIZE			(PHYS_SDRAM_1_SIZE + PHYS_SDRAM_2_SIZE)
+ #define CONFIG_SYS_MALLOC_LEN		(10 * 1024 * 1024)
+ #define CONFIG_SYS_MEMTEST_START	0x70000000
+-#define CONFIG_SYS_MEMTEST_END		0xaff00000
++#define CONFIG_SYS_MEMTEST_END		0x8ff00000
++#define CONFIG_VERY_BIG_RAM
++#define CONFIG_MAX_MEM_MAPPED		PHYS_SDRAM_1_SIZE
+ 
+ #define CONFIG_SYS_SDRAM_BASE		(PHYS_SDRAM_1)
+ #define CONFIG_SYS_INIT_RAM_ADDR	(IRAM_BASE_ADDR)
+-- 
+1.9.0
+
diff --git a/meta-eldk/recipes-bsp/uboot/u-boot/m53evk/0006-arm-mx5-Avoid-hardcoding-memory-sizes-on-M53EVK.patch b/meta-eldk/recipes-bsp/uboot/u-boot/m53evk/0006-arm-mx5-Avoid-hardcoding-memory-sizes-on-M53EVK.patch
new file mode 100644
index 0000000..c6a7806
--- /dev/null
+++ b/meta-eldk/recipes-bsp/uboot/u-boot/m53evk/0006-arm-mx5-Avoid-hardcoding-memory-sizes-on-M53EVK.patch
@@ -0,0 +1,111 @@
+From 62bb0c9ef2772474d741f88c85f29e666f955e63 Mon Sep 17 00:00:00 2001
+From: Marek Vasut <marex at denx.de>
+Date: Fri, 28 Mar 2014 05:09:23 +0100
+Subject: [PATCH 2/2] arm: mx5: Avoid hardcoding memory sizes on M53EVK
+
+The DRAM size can be easily detected at runtime on i.MX53. Implement
+such detection on M53EVK and adjust the rest of the macros accordingly
+to use the detected values.
+
+An important thing to note here is that we had to override the function
+for trimming the effective DRAM address, get_effective_memsize(). That
+is because the function uses CONFIG_MAX_MEM_MAPPED as the upper bound of
+the available DRAM and we don't have gd->bd->bi_dram[0].size set up at
+the time the function is called, thus we cannot put this into the macro
+CONFIG_MAX_MEM_MAPPED . Instead, we use custom override where we use the
+size of the first DRAM block which we just detected.
+
+Signed-off-by: Marek Vasut <marex at denx.de>
+Cc: Fabio Estevam <fabio.estevam at freescale.com>
+Cc: Stefano Babic <sbabic at denx.de>
+Cc: Wolfgang Denk <wd at denx.de>
+
+V2: Use linux/sizes.h instead of asm/sizes.h
+V3: - Drop use of sizes.h completely
+    - Add beefy comment as to why we override get_effective_memsize()
+    - Drop CONFIG_VERY_BIG_RAM and CONFIG_MAX_MEM_MAPPED as we no longer
+      need it if we override get_effective_memsize()
+---
+ board/denx/m53evk/m53evk.c | 31 ++++++++++++++++++++++++-------
+ include/configs/m53evk.h   |  8 +++-----
+ 2 files changed, 27 insertions(+), 12 deletions(-)
+
+diff --git a/board/denx/m53evk/m53evk.c b/board/denx/m53evk/m53evk.c
+index 0f71a16..74f9501 100644
+--- a/board/denx/m53evk/m53evk.c
++++ b/board/denx/m53evk/m53evk.c
+@@ -31,24 +31,41 @@
+ 
+ DECLARE_GLOBAL_DATA_PTR;
+ 
+-int dram_init(void)
++static uint32_t mx53_dram_size[2];
++
++phys_size_t get_effective_memsize(void)
+ {
+-	u32 size1, size2;
++	/*
++	 * WARNING: We must override get_effective_memsize() function here
++	 * to report only the size of the first DRAM bank. This is to make
++	 * U-Boot relocator place U-Boot into valid memory, that is, at the
++	 * end of the first DRAM bank. If we did not override this function
++	 * like so, U-Boot would be placed at the address of the first DRAM
++	 * bank + total DRAM size - sizeof(uboot), which in the setup where
++	 * each DRAM bank contains 512MiB of DRAM would result in placing
++	 * U-Boot into invalid memory area close to the end of the first
++	 * DRAM bank.
++	 */
++	return mx53_dram_size[0];
++}
+ 
+-	size1 = get_ram_size((void *)PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE);
+-	size2 = get_ram_size((void *)PHYS_SDRAM_2, PHYS_SDRAM_2_SIZE);
++int dram_init(void)
++{
++	mx53_dram_size[0] = get_ram_size((void *)PHYS_SDRAM_1, 1 << 30);
++	mx53_dram_size[1] = get_ram_size((void *)PHYS_SDRAM_2, 1 << 30);
+ 
+-	gd->ram_size = size1 + size2;
++	gd->ram_size = mx53_dram_size[0] + mx53_dram_size[1];
+ 
+ 	return 0;
+ }
++
+ void dram_init_banksize(void)
+ {
+ 	gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
+-	gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
++	gd->bd->bi_dram[0].size = mx53_dram_size[0];
+ 
+ 	gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
+-	gd->bd->bi_dram[1].size = PHYS_SDRAM_2_SIZE;
++	gd->bd->bi_dram[1].size = mx53_dram_size[1];
+ }
+ 
+ static void setup_iomux_uart(void)
+diff --git a/include/configs/m53evk.h b/include/configs/m53evk.h
+index d592318..1324877 100644
+--- a/include/configs/m53evk.h
++++ b/include/configs/m53evk.h
+@@ -56,15 +56,13 @@
+  */
+ #define CONFIG_NR_DRAM_BANKS		2
+ #define PHYS_SDRAM_1			CSD0_BASE_ADDR
+-#define PHYS_SDRAM_1_SIZE		(512 * 1024 * 1024)
++#define PHYS_SDRAM_1_SIZE		(gd->bd->bi_dram[0].size)
+ #define PHYS_SDRAM_2			CSD1_BASE_ADDR
+-#define PHYS_SDRAM_2_SIZE		(512 * 1024 * 1024)
+-#define PHYS_SDRAM_SIZE			(PHYS_SDRAM_1_SIZE + PHYS_SDRAM_2_SIZE)
++#define PHYS_SDRAM_2_SIZE		(gd->bd->bi_dram[1].size)
++#define PHYS_SDRAM_SIZE			(gd->ram_size)
+ #define CONFIG_SYS_MALLOC_LEN		(10 * 1024 * 1024)
+ #define CONFIG_SYS_MEMTEST_START	0x70000000
+ #define CONFIG_SYS_MEMTEST_END		0x8ff00000
+-#define CONFIG_VERY_BIG_RAM
+-#define CONFIG_MAX_MEM_MAPPED		PHYS_SDRAM_1_SIZE
+ 
+ #define CONFIG_SYS_SDRAM_BASE		(PHYS_SDRAM_1)
+ #define CONFIG_SYS_INIT_RAM_ADDR	(IRAM_BASE_ADDR)
+-- 
+1.9.0
+
diff --git a/meta-eldk/recipes-bsp/uboot/u-boot_2014.01.bb b/meta-eldk/recipes-bsp/uboot/u-boot_2014.01.bb
index 7010cd3..4ae5956 100644
--- a/meta-eldk/recipes-bsp/uboot/u-boot_2014.01.bb
+++ b/meta-eldk/recipes-bsp/uboot/u-boot_2014.01.bb
@@ -26,6 +26,9 @@ SRC_URI_append_m53evk = " \
 			file://0001-ARM-m53evk-add-needed-commands-and-options.patch \
 			file://0002-ARM-m53evk-Adjust-mtdparts-settings.patch \
 			file://0003-ARM-m53evk-Update-default-environment.patch \
+			file://0004-common-Add-get_effective_memsize-to-memsize.c.patch \
+			file://0005-arm-mx5-Fix-memory-slowness-on-M53EVK.patch \
+			file://0006-arm-mx5-Avoid-hardcoding-memory-sizes-on-M53EVK.patch \
 			"
 
 # Build u-boot-with-nand-spl.imx for the M53EVK so we can place it in the image
-- 
1.9.0



More information about the eldk mailing list