mmc: fsl_esdhc_spl: Add support for loading proper U-Boot from unaligned location
Subsystems (2)
PATCH 1/3 mmc: fsl_esdhc_spl: Add support for loading proper U-Boot from unaligned location
This allows to concatenate SPL and proper U-Boot without extra alignment.
--- drivers/mmc/fsl_esdhc_spl.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-)
drivers/mmc/fsl_esdhc_spl.c +22 -3
@@ -155,10 +155,21 @@ again:* Load U-Boot image from mmc into RAM */ code_len =CONFIG_SYS_MMC_U_BOOT_SIZE ; - blk_start =ALIGN (offset, mmc->read_bl_len) / mmc->read_bl_len; - blk_cnt =ALIGN (code_len, mmc->read_bl_len) / mmc->read_bl_len; + blk_start = offset / mmc->read_bl_len; + blk_off = offset % mmc->read_bl_len; + blk_cnt =ALIGN (code_len, mmc->read_bl_len) / mmc->read_bl_len +1 ; +if (blk_off) { + err = mmc->block_dev.block_read (&mmc->block_dev, + blk_start,1 , tmp_buf); +if (err !=1 ) { +puts ("spl: mmc read failed!!\n" ); +hang (); + } + blk_start++; + } err = mmc->block_dev.block_read (&mmc->block_dev, blk_start, blk_cnt, - (uchar *)CONFIG_SYS_MMC_U_BOOT_DST ); + (uchar *)CONFIG_SYS_MMC_U_BOOT_DST + + (blk_off ? (mmc->read_bl_len - blk_off) :0 ));if (err != blk_cnt) {puts ("spl: mmc read failed!!\n" );#ifndef CONFIG_FSL_CORENET
@@ -166,6 +177,14 @@ again:#endif hang (); } +/* +* SDHC DMA may erase bytes at dst + bl_len - blk_off - 8 +* due to unaligned access. So copy leading bytes from tmp_buf +* after SDHC DMA transfer. +*/ +if (blk_off) +memcpy ((uchar *)CONFIG_SYS_MMC_U_BOOT_DST , + tmp_buf + blk_off, mmc->read_bl_len - blk_off);/* * Clean d-cache and invalidate i-cache, to
Signature · 1 line
2.20.1
PATCH 2/3 mmc: fsl_esdhc_spl: Add support for builds without CONFIG_SYS_MMC_U_BOOT_OFFS
When fixed offset via CONFIG_SYS_MMC_U_BOOT_OFFS is not specified then expects that U-Boot proper is placed immediately after SPL without any additional padding.
This allows to generate smaller SPL+U-Boot final binary as it is not required to specify fixed offset to U-Boot proper at SPL compile time.
In this case offset to U-Boot proper is calculated at SPL compile time in linker script.
--- arch/powerpc/cpu/mpc85xx/u-boot-spl.lds | 10 ++++++++++ drivers/mmc/fsl_esdhc_spl.c | 8 ++++++++ 2 files changed, 18 insertions(+)
arch/powerpc/cpu/mpc85xx/u-boot-spl.lds +10 -0
@@ -59,6 +59,13 @@ SECTIONS __init_begin = .; __init_end = .; _end = .; + +#ifdef CONFIG_SYS_MPC85XX_NO_RESETVEC +#if defined(CONFIG_SDCARD) && !defined(CONFIG_SYS_MMC_U_BOOT_OFFS) + mmc_u_boot_offs = .; +#endif +#endif + #ifdef CONFIG_SPL_SKIP_RELOCATE . = ALIGN(4); __bss_start = .;
@@ -91,6 +98,9 @@ SECTIONS .resetvec IMAGE_TEXT_BASE + RESET_VECTOR_OFFSET : { KEEP(*(.resetvec)) } = 0xffff +#if defined(CONFIG_SDCARD) && !defined(CONFIG_SYS_MMC_U_BOOT_OFFS) + mmc_u_boot_offs = .; +#endif #endif #ifndef CONFIG_SPL_SKIP_RELOCATE
drivers/mmc/fsl_esdhc_spl.c +8 -0
@@ -9,6 +9,10 @@#include <mmc.h> #include <malloc.h> +#ifndef CONFIG_SYS_MMC_U_BOOT_OFFS +extern uchar mmc_u_boot_offs[]; +#endif +/* * The environment variables are written to just after the u-boot image * on SDCard, so we must read the MBR to get the start address and code
@@ -149,7 +153,11 @@ again: val = *(tmp_buf + blk_off +ESDHC_BOOT_IMAGE_ADDR + i); offset = (offset << 8) + val; } +#ifndef CONFIG_SYS_MMC_U_BOOT_OFFS + offset += (ulong )&mmc_u_boot_offs -CONFIG_SPL_TEXT_BASE ; +#else offset +=CONFIG_SYS_MMC_U_BOOT_OFFS ; +#endif #endif /* * Load U-Boot image from mmc into RAM
Signature · 1 line
2.20.1
PATCH 3/3 powerpc: mpc85xx: Fix loading U-Boot proper from SD card in SPL
In reply to Pali RohárChange 8-byte alignment of SPL binary to just 4-byte alignment as objcopy trims trailing zero bytes when converting ELF file to RAW binary.
This is same fix for SPL linker script as was done fix for U-Boot linker script in commit e8c0e0064c8a ("powerpc: mpc85xx: Fix CONFIG_OF_SEPARATE support").
It is required for the patch "mmc: fsl_esdhc_spl: Add support for builds without CONFIG_SYS_MMC_U_BOOT_OFFS" which triggered this issue in SPL.
--- arch/powerpc/cpu/mpc85xx/u-boot-spl.lds | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/cpu/mpc85xx/u-boot-spl.lds +1 -1
@@ -55,7 +55,7 @@ SECTIONS __ex_table : { *(__ex_table) } __stop___ex_table = .; - . = ALIGN(8); + . = ALIGN(4); __init_begin = .; __init_end = .; _end = .;
Signature · 1 line
2.20.1
Quoted 12 lines · Pali Rohár
This allows to concatenate SPL and proper U-Boot without extra alignment.
Signed-off-by Pali Rohár <[email protected]>--- drivers/mmc/fsl_esdhc_spl.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-)drivers/mmc/fsl_esdhc_spl.c +0
-0
drivers/mmc/fsl_esdhc_spl.c again: · line 159
Quoted 7 lines
drivers/mmc/fsl_esdhc_spl.c +2
-2@@ -155,10 +155,21 @@ again:* Load U-Boot image from mmc into RAM */ code_len =CONFIG_SYS_MMC_U_BOOT_SIZE ; - blk_start =ALIGN (offset, mmc->read_bl_len) / mmc->read_bl_len; - blk_cnt =ALIGN (code_len, mmc->read_bl_len) / mmc->read_bl_len; + blk_start = offset / mmc->read_bl_len; + blk_off = offset % mmc->read_bl_len;
Build fail because of blk_off not defined.
Regards,
Peng.
Quoted 32 lines
drivers/mmc/fsl_esdhc_spl.c +20
-1+ blk_cnt =ALIGN (code_len, mmc->read_bl_len) / mmc->read_bl_len +1 ; +if (blk_off) { + err = mmc->block_dev.block_read (&mmc->block_dev, + blk_start,1 , tmp_buf); +if (err !=1 ) { +puts ("spl: mmc read failed!!\n" ); +hang (); + } + blk_start++; + } err = mmc->block_dev.block_read (&mmc->block_dev, blk_start, blk_cnt, - (uchar *)CONFIG_SYS_MMC_U_BOOT_DST ); + (uchar *)CONFIG_SYS_MMC_U_BOOT_DST + + (blk_off ? (mmc->read_bl_len - blk_off) :0 ));if (err != blk_cnt) {puts ("spl: mmc read failed!!\n" );#ifndef CONFIG_FSL_CORENET @@ -166,6 +177,14 @@ again:#endif hang (); } +/* +* SDHC DMA may erase bytes at dst + bl_len - blk_off - 8 +* due to unaligned access. So copy leading bytes from tmp_buf +* after SDHC DMA transfer. +*/ +if (blk_off) +memcpy ((uchar *)CONFIG_SYS_MMC_U_BOOT_DST , + tmp_buf + blk_off, mmc->read_bl_len - blk_off);/* * Clean d-cache and invalidate i-cache, to
PATCH v2 1/1 mmc: fsl_esdhc_spl: Add support for loading proper U-Boot from unaligned location
This allows to concatenate SPL and proper U-Boot without extra alignment.
---
Changes in v2:
* Rebased on top of the U-Boot next branch, commit 98c4828740f4944462b7d9608b95d5b73850c7b0
--- drivers/mmc/fsl_esdhc_spl.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-)
drivers/mmc/fsl_esdhc_spl.c +23 -4
@@ -58,10 +58,10 @@ void __noreturn mmc_boot(void) { __attribute__((noreturn))void (*uboot)(void );uint blk_start, blk_cnt, err; +u32 blk_off;#ifndef CONFIG_FSL_CORENET uchar *tmp_buf;u32 blklen; -u32 blk_off;uchar val;#ifndef CONFIG_SPL_FSL_PBL u32 val32;
@@ -155,10 +155,21 @@ again:* Load U-Boot image from mmc into RAM */ code_len =CONFIG_SYS_MMC_U_BOOT_SIZE ; - blk_start =ALIGN (offset, mmc->read_bl_len) / mmc->read_bl_len; - blk_cnt =ALIGN (code_len, mmc->read_bl_len) / mmc->read_bl_len; + blk_start = offset / mmc->read_bl_len; + blk_off = offset % mmc->read_bl_len; + blk_cnt =ALIGN (code_len, mmc->read_bl_len) / mmc->read_bl_len +1 ; +if (blk_off) { + err = mmc->block_dev.block_read (&mmc->block_dev, + blk_start,1 , tmp_buf); +if (err !=1 ) { +puts ("spl: mmc read failed!!\n" ); +hang (); + } + blk_start++; + } err = mmc->block_dev.block_read (&mmc->block_dev, blk_start, blk_cnt, - (uchar *)CONFIG_SYS_MMC_U_BOOT_DST ); + (uchar *)CONFIG_SYS_MMC_U_BOOT_DST + + (blk_off ? (mmc->read_bl_len - blk_off) :0 ));if (err != blk_cnt) {puts ("spl: mmc read failed!!\n" );#ifndef CONFIG_FSL_CORENET
@@ -166,6 +177,14 @@ again:#endif hang (); } +/* +* SDHC DMA may erase bytes at dst + bl_len - blk_off - 8 +* due to unaligned access. So copy leading bytes from tmp_buf +* after SDHC DMA transfer. +*/ +if (blk_off) +memcpy ((uchar *)CONFIG_SYS_MMC_U_BOOT_DST , + tmp_buf + blk_off, mmc->read_bl_len - blk_off);/* * Clean d-cache and invalidate i-cache, to
Signature · 1 line
2.20.1
Quoted 6 lines · On Monday 20 June 2022 12:54:26 Pali Rohár wrote:
This allows to concatenate SPL and proper U-Boot without extra alignment.
Signed-off-by Pali Rohár <[email protected]>---
Changes in v2:
* Rebased on top of the U-Boot next branch, commit98c4828740f4944462b7d9608b95d5b73850c7b0
PING?
Quoted 63 lines
--- drivers/mmc/fsl_esdhc_spl.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-)drivers/mmc/fsl_esdhc_spl.c +23
-4@@ -58,10 +58,10 @@ void __noreturn mmc_boot(void) { __attribute__((noreturn))void (*uboot)(void );uint blk_start, blk_cnt, err; +u32 blk_off;#ifndef CONFIG_FSL_CORENET uchar *tmp_buf;u32 blklen; -u32 blk_off;uchar val;#ifndef CONFIG_SPL_FSL_PBL u32 val32;@@ -155,10 +155,21 @@ again:* Load U-Boot image from mmc into RAM */ code_len =CONFIG_SYS_MMC_U_BOOT_SIZE ; - blk_start =ALIGN (offset, mmc->read_bl_len) / mmc->read_bl_len; - blk_cnt =ALIGN (code_len, mmc->read_bl_len) / mmc->read_bl_len; + blk_start = offset / mmc->read_bl_len; + blk_off = offset % mmc->read_bl_len; + blk_cnt =ALIGN (code_len, mmc->read_bl_len) / mmc->read_bl_len +1 ; +if (blk_off) { + err = mmc->block_dev.block_read (&mmc->block_dev, + blk_start,1 , tmp_buf); +if (err !=1 ) { +puts ("spl: mmc read failed!!\n" ); +hang (); + } + blk_start++; + } err = mmc->block_dev.block_read (&mmc->block_dev, blk_start, blk_cnt, - (uchar *)CONFIG_SYS_MMC_U_BOOT_DST ); + (uchar *)CONFIG_SYS_MMC_U_BOOT_DST + + (blk_off ? (mmc->read_bl_len - blk_off) :0 ));if (err != blk_cnt) {puts ("spl: mmc read failed!!\n" );#ifndef CONFIG_FSL_CORENET @@ -166,6 +177,14 @@ again:#endif hang (); } +/* +* SDHC DMA may erase bytes at dst + bl_len - blk_off - 8 +* due to unaligned access. So copy leading bytes from tmp_buf +* after SDHC DMA transfer. +*/ +if (blk_off) +memcpy ((uchar *)CONFIG_SYS_MMC_U_BOOT_DST , + tmp_buf + blk_off, mmc->read_bl_len - blk_off);/* * Clean d-cache and invalidate i-cache, to Signature · 1 line
2.20.1
Quoted 9 lines · On Thursday 23 June 2022 15:31:14 Pali Rohár wrote:
Quoted 6 lines · On Monday 20 June 2022 12:54:26 Pali Rohár wrote:
This allows to concatenate SPL and proper U-Boot without extra alignment.
Signed-off-by Pali Rohár <[email protected]>---
Changes in v2:
* Rebased on top of the U-Boot next branch, commit98c4828740f4944462b7d9608b95d5b73850c7b0PING?
PING?
Quoted 63 lines
Quoted 63 lines
--- drivers/mmc/fsl_esdhc_spl.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-)drivers/mmc/fsl_esdhc_spl.c +23
-4@@ -58,10 +58,10 @@ void __noreturn mmc_boot(void) { __attribute__((noreturn))void (*uboot)(void );uint blk_start, blk_cnt, err; +u32 blk_off;#ifndef CONFIG_FSL_CORENET uchar *tmp_buf;u32 blklen; -u32 blk_off;uchar val;#ifndef CONFIG_SPL_FSL_PBL u32 val32;@@ -155,10 +155,21 @@ again:* Load U-Boot image from mmc into RAM */ code_len =CONFIG_SYS_MMC_U_BOOT_SIZE ; - blk_start =ALIGN (offset, mmc->read_bl_len) / mmc->read_bl_len; - blk_cnt =ALIGN (code_len, mmc->read_bl_len) / mmc->read_bl_len; + blk_start = offset / mmc->read_bl_len; + blk_off = offset % mmc->read_bl_len; + blk_cnt =ALIGN (code_len, mmc->read_bl_len) / mmc->read_bl_len +1 ; +if (blk_off) { + err = mmc->block_dev.block_read (&mmc->block_dev, + blk_start,1 , tmp_buf); +if (err !=1 ) { +puts ("spl: mmc read failed!!\n" ); +hang (); + } + blk_start++; + } err = mmc->block_dev.block_read (&mmc->block_dev, blk_start, blk_cnt, - (uchar *)CONFIG_SYS_MMC_U_BOOT_DST ); + (uchar *)CONFIG_SYS_MMC_U_BOOT_DST + + (blk_off ? (mmc->read_bl_len - blk_off) :0 ));if (err != blk_cnt) {puts ("spl: mmc read failed!!\n" );#ifndef CONFIG_FSL_CORENET @@ -166,6 +177,14 @@ again:#endif hang (); } +/* +* SDHC DMA may erase bytes at dst + bl_len - blk_off - 8 +* due to unaligned access. So copy leading bytes from tmp_buf +* after SDHC DMA transfer. +*/ +if (blk_off) +memcpy ((uchar *)CONFIG_SYS_MMC_U_BOOT_DST , + tmp_buf + blk_off, mmc->read_bl_len - blk_off);/* * Clean d-cache and invalidate i-cache, to Signature · 1 line
2.20.1
Quoted 4 lines · On Tuesday 28 June 2022 20:14:36 Pali Rohár wrote:
Quoted 3 lines · On Thursday 23 June 2022 15:31:14 Pali Rohár wrote:
Quoted 2 lines · On Monday 20 June 2022 12:54:26 Pali Rohár wrote:
This allows to concatenate SPL and proper U-Boot without extra alignment.
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Signed-off-by Pali Rohár <[email protected]>---
Changes in v2:
* Rebased on top of the U-Boot next branch, commit98c4828740f4944462b7d9608b95d5b73850c7b0PING?
PING?
PING?
Quoted 63 lines
Quoted 63 lines
Quoted 63 lines
--- drivers/mmc/fsl_esdhc_spl.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-)drivers/mmc/fsl_esdhc_spl.c +23
-4@@ -58,10 +58,10 @@ void __noreturn mmc_boot(void) { __attribute__((noreturn))void (*uboot)(void );uint blk_start, blk_cnt, err; +u32 blk_off;#ifndef CONFIG_FSL_CORENET uchar *tmp_buf;u32 blklen; -u32 blk_off;uchar val;#ifndef CONFIG_SPL_FSL_PBL u32 val32;@@ -155,10 +155,21 @@ again:* Load U-Boot image from mmc into RAM */ code_len =CONFIG_SYS_MMC_U_BOOT_SIZE ; - blk_start =ALIGN (offset, mmc->read_bl_len) / mmc->read_bl_len; - blk_cnt =ALIGN (code_len, mmc->read_bl_len) / mmc->read_bl_len; + blk_start = offset / mmc->read_bl_len; + blk_off = offset % mmc->read_bl_len; + blk_cnt =ALIGN (code_len, mmc->read_bl_len) / mmc->read_bl_len +1 ; +if (blk_off) { + err = mmc->block_dev.block_read (&mmc->block_dev, + blk_start,1 , tmp_buf); +if (err !=1 ) { +puts ("spl: mmc read failed!!\n" ); +hang (); + } + blk_start++; + } err = mmc->block_dev.block_read (&mmc->block_dev, blk_start, blk_cnt, - (uchar *)CONFIG_SYS_MMC_U_BOOT_DST ); + (uchar *)CONFIG_SYS_MMC_U_BOOT_DST + + (blk_off ? (mmc->read_bl_len - blk_off) :0 ));if (err != blk_cnt) {puts ("spl: mmc read failed!!\n" );#ifndef CONFIG_FSL_CORENET @@ -166,6 +177,14 @@ again:#endif hang (); } +/* +* SDHC DMA may erase bytes at dst + bl_len - blk_off - 8 +* due to unaligned access. So copy leading bytes from tmp_buf +* after SDHC DMA transfer. +*/ +if (blk_off) +memcpy ((uchar *)CONFIG_SYS_MMC_U_BOOT_DST , + tmp_buf + blk_off, mmc->read_bl_len - blk_off);/* * Clean d-cache and invalidate i-cache, to Signature · 1 line
2.20.1
Quoted 10 lines · On Thursday 14 July 2022 01:50:44 Pali Rohár wrote:
Quoted 9 lines · On Tuesday 28 June 2022 20:14:36 Pali Rohár wrote:
Quoted 8 lines · On Thursday 23 June 2022 15:31:14 Pali Rohár wrote:
Quoted 6 lines · On Monday 20 June 2022 12:54:26 Pali Rohár wrote:
This allows to concatenate SPL and proper U-Boot without extra alignment.
Signed-off-by Pali Rohár <[email protected]>---
Changes in v2:
* Rebased on top of the U-Boot next branch, commit98c4828740f4944462b7d9608b95d5b73850c7b0
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
PING?
PING?
PING?
PING? What is happening here? I have not received any reply for this patch for more than month. You asked me for rebasing more patches, I did it in one day since request and get no reply.
Quoted 63 lines
Quoted 63 lines
Quoted 63 lines
Quoted 63 lines
--- drivers/mmc/fsl_esdhc_spl.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-)drivers/mmc/fsl_esdhc_spl.c +23
-4@@ -58,10 +58,10 @@ void __noreturn mmc_boot(void) { __attribute__((noreturn))void (*uboot)(void );uint blk_start, blk_cnt, err; +u32 blk_off;#ifndef CONFIG_FSL_CORENET uchar *tmp_buf;u32 blklen; -u32 blk_off;uchar val;#ifndef CONFIG_SPL_FSL_PBL u32 val32;@@ -155,10 +155,21 @@ again:* Load U-Boot image from mmc into RAM */ code_len =CONFIG_SYS_MMC_U_BOOT_SIZE ; - blk_start =ALIGN (offset, mmc->read_bl_len) / mmc->read_bl_len; - blk_cnt =ALIGN (code_len, mmc->read_bl_len) / mmc->read_bl_len; + blk_start = offset / mmc->read_bl_len; + blk_off = offset % mmc->read_bl_len; + blk_cnt =ALIGN (code_len, mmc->read_bl_len) / mmc->read_bl_len +1 ; +if (blk_off) { + err = mmc->block_dev.block_read (&mmc->block_dev, + blk_start,1 , tmp_buf); +if (err !=1 ) { +puts ("spl: mmc read failed!!\n" ); +hang (); + } + blk_start++; + } err = mmc->block_dev.block_read (&mmc->block_dev, blk_start, blk_cnt, - (uchar *)CONFIG_SYS_MMC_U_BOOT_DST ); + (uchar *)CONFIG_SYS_MMC_U_BOOT_DST + + (blk_off ? (mmc->read_bl_len - blk_off) :0 ));if (err != blk_cnt) {puts ("spl: mmc read failed!!\n" );#ifndef CONFIG_FSL_CORENET @@ -166,6 +177,14 @@ again:#endif hang (); } +/* +* SDHC DMA may erase bytes at dst + bl_len - blk_off - 8 +* due to unaligned access. So copy leading bytes from tmp_buf +* after SDHC DMA transfer. +*/ +if (blk_off) +memcpy ((uchar *)CONFIG_SYS_MMC_U_BOOT_DST , + tmp_buf + blk_off, mmc->read_bl_len - blk_off);/* * Clean d-cache and invalidate i-cache, to Signature · 1 line
2.20.1
Quoted 3 lines · Pali Rohár
This allows to concatenate SPL and proper U-Boot without extra alignment.
Signed-off-by Pali Rohár <[email protected]>
Best Regards,
Jaehoon Chung
Quoted 63 lines
---
Changes in v2:
* Rebased on top of the U-Boot next branch, commit98c4828740f4944462b7d9608b95d5b73850c7b0--- drivers/mmc/fsl_esdhc_spl.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-)drivers/mmc/fsl_esdhc_spl.c +23
-4@@ -58,10 +58,10 @@ void __noreturn mmc_boot(void) { __attribute__((noreturn))void (*uboot)(void );uint blk_start, blk_cnt, err; +u32 blk_off;#ifndef CONFIG_FSL_CORENET uchar *tmp_buf;u32 blklen; -u32 blk_off;uchar val;#ifndef CONFIG_SPL_FSL_PBL u32 val32;@@ -155,10 +155,21 @@ again:* Load U-Boot image from mmc into RAM */ code_len =CONFIG_SYS_MMC_U_BOOT_SIZE ; - blk_start =ALIGN (offset, mmc->read_bl_len) / mmc->read_bl_len; - blk_cnt =ALIGN (code_len, mmc->read_bl_len) / mmc->read_bl_len; + blk_start = offset / mmc->read_bl_len; + blk_off = offset % mmc->read_bl_len; + blk_cnt =ALIGN (code_len, mmc->read_bl_len) / mmc->read_bl_len +1 ; +if (blk_off) { + err = mmc->block_dev.block_read (&mmc->block_dev, + blk_start,1 , tmp_buf); +if (err !=1 ) { +puts ("spl: mmc read failed!!\n" ); +hang (); + } + blk_start++; + } err = mmc->block_dev.block_read (&mmc->block_dev, blk_start, blk_cnt, - (uchar *)CONFIG_SYS_MMC_U_BOOT_DST ); + (uchar *)CONFIG_SYS_MMC_U_BOOT_DST + + (blk_off ? (mmc->read_bl_len - blk_off) :0 ));if (err != blk_cnt) {puts ("spl: mmc read failed!!\n" );#ifndef CONFIG_FSL_CORENET @@ -166,6 +177,14 @@ again:#endif hang (); } +/* +* SDHC DMA may erase bytes at dst + bl_len - blk_off - 8 +* due to unaligned access. So copy leading bytes from tmp_buf +* after SDHC DMA transfer. +*/ +if (blk_off) +memcpy ((uchar *)CONFIG_SYS_MMC_U_BOOT_DST , + tmp_buf + blk_off, mmc->read_bl_len - blk_off);/* * Clean d-cache and invalidate i-cache, to
PATCH v3 1/3 mmc: fsl_esdhc_spl: Add support for loading proper U-Boot from unaligned location
In reply to Pali RohárThis allows to concatenate SPL and proper U-Boot without extra alignment.
---
Changes in v3:
* Fix compilation with CONFIG_FSL_CORENET
Changes in v2:
* Rebased on top of the U-Boot next branch, commit 98c4828740f4944462b7d9608b95d5b73850c7b0
--- drivers/mmc/fsl_esdhc_spl.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-)
drivers/mmc/fsl_esdhc_spl.c +26 -9
@@ -58,10 +58,10 @@ void __noreturn mmc_boot(void) { __attribute__((noreturn))void (*uboot)(void );uint blk_start, blk_cnt, err; -#ifndef CONFIG_FSL_CORENET uchar *tmp_buf;u32 blklen;u32 blk_off; +#ifndef CONFIG_FSL_CORENET uchar val;#ifndef CONFIG_SPL_FSL_PBL u32 val32;
@@ -83,9 +83,6 @@ void __noreturn mmc_boot(void)hang (); } -#ifdef CONFIG_FSL_CORENET - offset =CONFIG_SYS_MMC_U_BOOT_OFFS ; -#else blklen = mmc->read_bl_len;if (blklen <512 ) blklen =512 ;
@@ -95,6 +92,9 @@ void __noreturn mmc_boot(void)hang (); } +#ifdef CONFIG_FSL_CORENET + offset =CONFIG_SYS_MMC_U_BOOT_OFFS ; +#else sector =0 ; again:memset (tmp_buf,0 , blklen);
@@ -155,17 +155,34 @@ again:* Load U-Boot image from mmc into RAM */ code_len =CONFIG_SYS_MMC_U_BOOT_SIZE ; - blk_start =ALIGN (offset, mmc->read_bl_len) / mmc->read_bl_len; - blk_cnt =ALIGN (code_len, mmc->read_bl_len) / mmc->read_bl_len; + blk_start = offset / mmc->read_bl_len; + blk_off = offset % mmc->read_bl_len; + blk_cnt =ALIGN (code_len, mmc->read_bl_len) / mmc->read_bl_len +1 ; +if (blk_off) { + err = mmc->block_dev.block_read (&mmc->block_dev, + blk_start,1 , tmp_buf); +if (err !=1 ) { +puts ("spl: mmc read failed!!\n" ); +hang (); + } + blk_start++; + } err = mmc->block_dev.block_read (&mmc->block_dev, blk_start, blk_cnt, - (uchar *)CONFIG_SYS_MMC_U_BOOT_DST ); + (uchar *)CONFIG_SYS_MMC_U_BOOT_DST + + (blk_off ? (mmc->read_bl_len - blk_off) :0 ));if (err != blk_cnt) {puts ("spl: mmc read failed!!\n" ); -#ifndef CONFIG_FSL_CORENET free (tmp_buf); -#endif hang (); } +/* +* SDHC DMA may erase bytes at dst + bl_len - blk_off - 8 +* due to unaligned access. So copy leading bytes from tmp_buf +* after SDHC DMA transfer. +*/ +if (blk_off) +memcpy ((uchar *)CONFIG_SYS_MMC_U_BOOT_DST , + tmp_buf + blk_off, mmc->read_bl_len - blk_off);/* * Clean d-cache and invalidate i-cache, to
Signature · 1 line
2.20.1
PATCH v3 2/3 powerpc: mpc85xx: Fix loading U-Boot proper from SD card in SPL
Change 8-byte alignment of SPL binary to just 4-byte alignment as objcopy trims trailing zero bytes when converting ELF file to RAW binary.
This is same fix for SPL linker script as was done fix for U-Boot linker script in commit e8c0e0064c8a ("powerpc: mpc85xx: Fix CONFIG_OF_SEPARATE support").
It is required for the patch "mmc: fsl_esdhc_spl: Add support for builds without CONFIG_SYS_MMC_U_BOOT_OFFS" which triggered this issue in SPL.
--- arch/powerpc/cpu/mpc85xx/u-boot-spl.lds | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/cpu/mpc85xx/u-boot-spl.lds +1 -1
@@ -58,7 +58,7 @@ SECTIONS __ex_table : { *(__ex_table) } __stop___ex_table = .; - . = ALIGN(8); + . = ALIGN(4); __init_begin = .; __init_end = .; _end = .;
Signature · 1 line
2.20.1
PATCH v3 3/3 mmc: fsl_esdhc_spl: Add support for builds without CONFIG_SYS_MMC_U_BOOT_OFFS
In reply to Pali RohárWhen fixed offset via CONFIG_SYS_MMC_U_BOOT_OFFS is not specified then expects that U-Boot proper is placed immediately after SPL without any additional padding.
This allows to generate smaller SPL+U-Boot final binary as it is not required to specify fixed offset to U-Boot proper at SPL compile time.
In this case offset to U-Boot proper is calculated at SPL compile time in linker script.
--- arch/powerpc/cpu/mpc85xx/u-boot-spl.lds | 10 ++++++++++ drivers/mmc/fsl_esdhc_spl.c | 8 ++++++++ 2 files changed, 18 insertions(+)
arch/powerpc/cpu/mpc85xx/u-boot-spl.lds +10 -0
@@ -62,6 +62,13 @@ SECTIONS __init_begin = .; __init_end = .; _end = .; + +#ifdef CONFIG_SYS_MPC85XX_NO_RESETVEC +#if defined(CONFIG_SDCARD) && !defined(CONFIG_SYS_MMC_U_BOOT_OFFS) + mmc_u_boot_offs = .; +#endif +#endif + #ifdef CONFIG_SPL_SKIP_RELOCATE . = ALIGN(4); __bss_start = .;
@@ -94,6 +101,9 @@ SECTIONS .resetvec IMAGE_TEXT_BASE + RESET_VECTOR_OFFSET : { KEEP(*(.resetvec)) } = 0xffff +#if defined(CONFIG_SDCARD) && !defined(CONFIG_SYS_MMC_U_BOOT_OFFS) + mmc_u_boot_offs = .; +#endif #endif #ifndef CONFIG_SPL_SKIP_RELOCATE
drivers/mmc/fsl_esdhc_spl.c +8 -0
@@ -9,6 +9,10 @@#include <mmc.h> #include <malloc.h> +#ifndef CONFIG_SYS_MMC_U_BOOT_OFFS +extern uchar mmc_u_boot_offs[]; +#endif +/* * The environment variables are written to just after the u-boot image * on SDCard, so we must read the MBR to get the start address and code
@@ -149,7 +153,11 @@ again: val = *(tmp_buf + blk_off +ESDHC_BOOT_IMAGE_ADDR + i); offset = (offset << 8) + val; } +#ifndef CONFIG_SYS_MMC_U_BOOT_OFFS + offset += (ulong )&mmc_u_boot_offs -CONFIG_SPL_TEXT_BASE ; +#else offset +=CONFIG_SYS_MMC_U_BOOT_OFFS ; +#endif #endif /* * Load U-Boot image from mmc into RAM
Signature · 1 line
2.20.1
RE: [PATCH v3 3/3] mmc: fsl_esdhc_spl: Add support for builds without CONFIG_SYS_MMC_U_BOOT_OFFS
Hi,
Quoted 12 lines
-----Original Message-----
From: Pali Rohar [mailto:[email protected]]
Sent: Saturday, August 6, 2022 5:10 AM
To: Jaehoon Chung; Peng Fan; Marek Behun
Cc: Sinan Akman; [email protected]
Subject: [PATCH v3 3/3] mmc:fsl_esdhc_spl: Add support for builds withoutCONFIG_SYS_MMC_U_BOOT_OFFSWhen fixed offset via
CONFIG_SYS_MMC_U_BOOT_OFFSis not specified then expects that U-Boot proper is placed immediately after SPL without any additional padding.
Quoted 7 lines
This allows to generate smaller SPL+U-Boot final binary as it is not required to specify fixed offset to U-Boot proper at SPL compile time.
In this case offset to U-Boot proper is calculated at SPL compile time in linker script.
Signed-off-by Pali Rohar <[email protected]>
Best Regards,
Jaehoon Chung
Quoted 62 lines
--- arch/powerpc/cpu/mpc85xx/u-boot-spl.lds | 10 ++++++++++ drivers/mmc/fsl_esdhc_spl.c | 8 ++++++++ 2 files changed, 18 insertions(+)arch/powerpc/cpu/mpc85xx/u-boot-spl.lds +10
-0@@ -62,6 +62,13 @@ SECTIONS __init_begin = .; __init_end = .; _end = .; + +#ifdef CONFIG_SYS_MPC85XX_NO_RESETVEC +#if defined(CONFIG_SDCARD) && !defined(CONFIG_SYS_MMC_U_BOOT_OFFS) + mmc_u_boot_offs = .; +#endif +#endif + #ifdef CONFIG_SPL_SKIP_RELOCATE . = ALIGN(4); __bss_start = .;@@ -94,6 +101,9 @@ SECTIONS .resetvec IMAGE_TEXT_BASE + RESET_VECTOR_OFFSET : { KEEP(*(.resetvec)) } = 0xffff +#if defined(CONFIG_SDCARD) && !defined(CONFIG_SYS_MMC_U_BOOT_OFFS) + mmc_u_boot_offs = .; +#endif #endif #ifndef CONFIG_SPL_SKIP_RELOCATEdrivers/mmc/fsl_esdhc_spl.c +8
-1@@ -9,6 +9,10 @@#include <mmc.h> #include <malloc.h> +#ifndef CONFIG_SYS_MMC_U_BOOT_OFFS +extern uchar mmc_u_boot_offs[]; +#endif +/* * The environment variables are written to just after the u-boot image * on SDCard, so we must read the MBR to get the start address and code @@ -149,7 +153,11 @@ again: val = *(tmp_buf + blk_off +ESDHC_BOOT_IMAGE_ADDR + i); offset = (offset << 8) + val; } +#ifndef CONFIG_SYS_MMC_U_BOOT_OFFS + offset += (ulong )&mmc_u_boot_offs -CONFIG_SPL_TEXT_BASE ; +#else offset +=CONFIG_SYS_MMC_U_BOOT_OFFS ; +#endif #endif /* * Load U-Boot image from mmc into RAM -- 2.20.1