Patchwork [U-Boot,V3,7/8] omap-common: fixes BSS overwriting problem

login
register
mail settings
Submitter Simon Schwarz
Date Aug. 25, 2011, 8:33 a.m.
Message ID <1314261196-23197-8-git-send-email-simonschwarzcor@gmail.com>
Download mbox | patch
Permalink /patch/111518/
State Superseded
Headers show

Comments

Simon Schwarz - Aug. 25, 2011, 8:33 a.m.
spl_nand overwrote BSS section because it reads a whole block everytime. Now
loads the block to spare area and just copy the needed junk to destination.
Whole block read is necessary for ecc check!

Signed-off-by: Simon Schwarz <simonschwarzcor@gmail.com>
---

V2 changes:
nothing

V3 changes:
nothing
---
 arch/arm/cpu/armv7/omap-common/spl_nand.c |   21 ++++++++++++++++++---
 1 files changed, 18 insertions(+), 3 deletions(-)

Patch

diff --git a/arch/arm/cpu/armv7/omap-common/spl_nand.c b/arch/arm/cpu/armv7/omap-common/spl_nand.c
index 06254b2..408892f 100644
--- a/arch/arm/cpu/armv7/omap-common/spl_nand.c
+++ b/arch/arm/cpu/armv7/omap-common/spl_nand.c
@@ -24,6 +24,7 @@ 
 #include <asm/u-boot.h>
 #include <asm/utils.h>
 #include <asm/arch/sys_proto.h>
+#include <asm/io.h>
 #include <nand.h>
 #include <timestamp_autogenerated.h>
 #include <version_autogenerated.h>
@@ -33,6 +34,7 @@ 
 void spl_nand_load_image(void)
 {
 	struct image_header *header;
+	int *src, *dst;
 	switch (omap_boot_mode()) {
 	case NAND_MODE_HW_ECC:
 		debug("spl: nand - using hw ecc\n");
@@ -49,16 +51,29 @@  void spl_nand_load_image(void)
 #ifdef CONFIG_SPL_OS_BOOT
 	if (!spl_uboot_key()) {
 		/* load parameter image */
-		nand_spl_load_image(CONFIG_CMD_SAVEBP_NAND_OFS ,
+		/* load to temp position since nand_spl_load_image reads
+		 * a whole block which is typically larger than
+		 * CONFIG_CMD_SAVEBP_WRITE_SIZE therefore may overwrite
+		 * following sections like BSS */
+		nand_spl_load_image(CONFIG_CMD_SAVEBP_NAND_OFS,
 			CONFIG_CMD_SAVEBP_WRITE_SIZE,
-			(void *)CONFIG_SYS_SPL_ARGS_ADDR);
+			(void *)CONFIG_SYS_TEXT_BASE);
+		/* copy to destintion */
+		for (dst = (int *)CONFIG_SYS_SPL_ARGS_ADDR,
+				src = (int *)CONFIG_SYS_TEXT_BASE;
+				src < (int *)(CONFIG_SYS_TEXT_BASE +
+				CONFIG_CMD_SAVEBP_WRITE_SIZE);
+				src++, dst++) {
+			writel(readl(src), dst);
+		}
 
 		/* load linux */
 		nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS,
 			CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
 		spl_parse_image_header(header);
 		nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS,
-			spl_image.size, (void *)spl_image.load_addr);
+			spl_image.size,
+			(void *)spl_image.load_addr - sizeof(header));
 	} else
 #endif
 	{