From: Simon Schwarz Date: Thu, 11 Aug 2011 16:44:56 +0200 Subject: [U-Boot] [PATCH 7/7] omap-common: fixes BSS overwriting problem In-Reply-To: <1313073896-12952-1-git-send-email-simonschwarzcor@gmail.com> References: <1313073896-12952-1-git-send-email-simonschwarzcor@gmail.com> Message-ID: <1313073896-12952-8-git-send-email-simonschwarzcor@gmail.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de 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 --- arch/arm/cpu/armv7/omap-common/spl_nand.c | 21 ++++++++++++++++++--- 1 files changed, 18 insertions(+), 3 deletions(-) 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 #include #include +#include #include #include #include @@ -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 { -- 1.7.4.1