Skip to contentSkip to conversation

rockchip: Reconfigure the malloc based to point to system memory

PATCH Superseded Sjoerd Simons 3 participants 3 messages Oct 1, 2015 – Oct 2, 2015

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 rockchip: Reconfigure the malloc based to point to system memory

When malloc_base initially gets setup in the SPL it is based on the current (early) stack pointer, which for rockchip is pointing into SRAM. This means simple memory allocations happen in SRAM space, which is somewhat unfortunate. Specifically a bounce buffer for the mmc allocated in SRAM space seems to cause the mmc engine to stall/fail causing timeouts and a failure to load the main u-boot image.

To resolve this, reconfigure the malloc_base to start at the relocated stack pointer after DRAM has been setup.

For reference, things did work fine on rockchip before 596380db was merged to fix memalign_simple due to a combination of rockchip SDRAM starting at address 0 and the dw_mmc driver not checking errors from bounce_buffer_start. As a result, when a bounce buffer needed to be allocated mem_align simple would fail and return NULL. The mmc driver ignored the error and happily continued with the bounce buffer address being set to 0, which just happened to work fine..

---
A potentially better fix for this issue would be to reconfigure the malloc_base in spl_relocate_stack_gd following the same steps as is done for the initial setup. However at this point in the release cycle i preferred to do a minimal rockchip only fix (so those boards become bootable again) for this issue to minimize the potential impact on other boards.

Changes in v2:
- Also gd->malloc_ptr to 0 to not waste any potential space

 arch/arm/mach-rockchip/board-spl.c | 5 +++++
 1 file changed, 5 insertions(+)
arch/arm/mach-rockchip/board-spl.c +5 -0
index a241d96..982a1d9 100644
@@ -217,6 +217,11 @@ void board_init_f(ulong dummy)
 		debug("DRAM init failed: %d\n", ret);
 		return;
 	}
+
+	/* Now that DRAM is initialized setup base pointer for simple malloc
+	 * into RAM */
+	gd->malloc_base = CONFIG_SPL_STACK_R_ADDR;
+	gd->malloc_ptr = 0;
 }
 
 static int setup_led(void)
Signature · 1 line
2.5.3
#1 lore raw

PATCH v2 1/1 rockchip: Reconfigure the malloc based to point to system memory

Hi,

Quoted 18 lines · Sjoerd Simons

When malloc_base initially gets setup in the SPL it is based on the current (early) stack pointer, which for rockchip is pointing into SRAM. This means simple memory allocations happen in SRAM space, which is somewhat unfortunate. Specifically a bounce buffer for the mmc allocated in SRAM space seems to cause the mmc engine to stall/fail causing timeouts and a failure to load the main u-boot image.

To resolve this, reconfigure the malloc_base to start at the relocated stack pointer after DRAM has been setup.

For reference, things did work fine on rockchip before 596380db was merged to fix memalign_simple due to a combination of rockchip SDRAM starting at address 0 and the dw_mmc driver not checking errors from bounce_buffer_start. As a result, when a bounce buffer needed to be allocated mem_align simple would fail and return NULL. The mmc driver ignored the error and happily continued with the bounce buffer address being set to 0, which just happened to work fine..

Quoted 1 line

Looks good to me, with the caveat that we really should do something better (and revert this one) for v2016.01:

Regards,

Hans

Quoted 32 lines

---
A potentially better fix for this issue would be to reconfigure the malloc_base in spl_relocate_stack_gd following the same steps as is done for the initial setup. However at this point in the release cycle i preferred to do a minimal rockchip only fix (so those boards become bootable again) for this issue to minimize the potential impact on other boards.

Changes in v2:
- Also gd->malloc_ptr to 0 to not waste any potential space

  arch/arm/mach-rockchip/board-spl.c | 5 +++++
  1 file changed, 5 insertions(+)
arch/arm/mach-rockchip/board-spl.c +5 -0
index a241d96..982a1d9 100644
@@ -217,6 +217,11 @@ void board_init_f(ulong dummy)
  		debug("DRAM init failed: %d\n", ret);
  		return;
  	}
+
+	/* Now that DRAM is initialized setup base pointer for simple malloc
+	 * into RAM */
+	gd->malloc_base = CONFIG_SPL_STACK_R_ADDR;
+	gd->malloc_ptr = 0;
  }
 
  static int setup_led(void)
#2 lore raw

PATCH v2 1/1 rockchip: Reconfigure the malloc based to point to system memory

In reply to Sjoerd Simons

Hi,

Quoted 28 lines · Sjoerd Simons

When malloc_base initially gets setup in the SPL it is based on the current (early) stack pointer, which for rockchip is pointing into SRAM. This means simple memory allocations happen in SRAM space, which is somewhat unfortunate. Specifically a bounce buffer for the mmc allocated in SRAM space seems to cause the mmc engine to stall/fail causing timeouts and a failure to load the main u-boot image.

To resolve this, reconfigure the malloc_base to start at the relocated stack pointer after DRAM has been setup.

For reference, things did work fine on rockchip before 596380db was merged to fix memalign_simple due to a combination of rockchip SDRAM starting at address 0 and the dw_mmc driver not checking errors from bounce_buffer_start. As a result, when a bounce buffer needed to be allocated mem_align simple would fail and return NULL. The mmc driver ignored the error and happily continued with the bounce buffer address being set to 0, which just happened to work fine..

---
A potentially better fix for this issue would be to reconfigure the malloc_base in spl_relocate_stack_gd following the same steps as is done for the initial setup. However at this point in the release cycle i preferred to do a minimal rockchip only fix (so those boards become bootable again) for this issue to minimize the potential impact on other boards.

Quoted 5 lines

Changes in v2:
- Also gd->malloc_ptr to 0 to not waste any potential space

 arch/arm/mach-rockchip/board-spl.c | 5 +++++
 1 file changed, 5 insertions(+)

arch/arm/mach-rockchip/board-spl.c void board_init_f(ulong dummy) · line 222

Quoted 12 lines
arch/arm/mach-rockchip/board-spl.c +3 -0
index a241d96..982a1d9 100644
@@ -217,6 +217,11 @@ void board_init_f(ulong dummy)
                debug("DRAM init failed: %d\n", ret);
                return;
        }
+
+       /* Now that DRAM is initialized setup base pointer for simple malloc
+        * into RAM */

Little nit - can you fix the comment style? Or I can do that when applying if you prefer.

Quoted 8 lines
arch/arm/mach-rockchip/board-spl.c +2 -1
+       gd->malloc_base = CONFIG_SPL_STACK_R_ADDR;
+       gd->malloc_ptr = 0;
 }
 
 static int setup_led(void)
--

2.5.3

Regards,
Simon