Re: [PATCH 1/3] mmc: fsl_esdhc_spl: Add support for loading proper U-Boot from unaligned location

Peng Fan (OSS)
2022-06-20T06:00:51Z

在 2022/5/12 2:33, Pali Rohár 写道:
> This allows to concatenate SPL and proper U-Boot without extra alignment.
>
> Signed-off-by: Pali Rohár <pali@kernel.org>
> ---
> drivers/mmc/fsl_esdhc_spl.c | 25 ++++++++++++++++++++++---
> 1 file changed, 22 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/mmc/fsl_esdhc_spl.c b/drivers/mmc/fsl_esdhc_spl.c
> index 760f13d24018..e3175de16bab 100644
> --- a/drivers/mmc/fsl_esdhc_spl.c
> +++ b/drivers/mmc/fsl_esdhc_spl.c
> @@ -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.
> + 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