On Armada 38x platforms the ROM code loads SPL from offset 0 of eMMC hardware boot partitions. When there are no boot partitions (i.e. SD card) the ROM skips the first sector that usually contains the (logical) partition table. Since the generated .kwb image contains the main U-Boot image in a fixed location (0x140 sectors by default), we end up with the main U-Boot image in offset of 1 sector. The current workaround is to manually set CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR to 0x141 to compensate for that.
This patch uses the run-time detected boot partition to determine the right offset of the main U-Boot partition. The generated .kwb image is now compatible with both eMMC boot partition, and SD card main data partition. Signed-off-by: Baruch Siach <bar...@tkos.co.il> --- common/spl/Kconfig | 12 ++++++++++++ common/spl/spl_mmc.c | 28 +++++++++++++++++++++------- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/common/spl/Kconfig b/common/spl/Kconfig index 9fe99681305c..47ee59118d27 100644 --- a/common/spl/Kconfig +++ b/common/spl/Kconfig @@ -280,6 +280,18 @@ config SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR Address on the MMC to load U-Boot from, when the MMC is being used in raw mode. Units: MMC sectors (1 sector = 512 bytes). +config SYS_MMCSD_RAW_MODE_U_BOOT_DATA_PART_OFFSET + hex "U-Boot main hardware partition image offset" + depends on SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR + default 0x0 + help + On some platforms SPL location depends on hardware partition. The ROM + code skips the MBR sector when loading SPL from main hardware data + partition. This adds offset to the main U-Boot image. Set this symbol + to the number of skipped sectors. + + If unsure, leave the default. + config SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION bool "MMC Raw mode: by partition" help diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c index 324d91c88404..7c7d9ccae4cf 100644 --- a/common/spl/spl_mmc.c +++ b/common/spl/spl_mmc.c @@ -49,6 +49,20 @@ static ulong h_spl_load_read(struct spl_load_info *load, ulong sector, return blk_dread(mmc_get_blk_desc(mmc), sector, count, buf); } +#if IS_ENABLED(CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR) +static unsigned long spl_mmc_raw_uboot_sector(int part) +{ + unsigned long raw_sector = CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR; + + if (part == 0) + raw_sector += CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_DATA_PART_OFFSET; + + return raw_sector; +} +#else +static unsigned long spl_mmc_raw_uboot_sector(int part) { return 0; } +#endif + static __maybe_unused int mmc_load_image_raw_sector(struct spl_image_info *spl_image, struct mmc *mmc, unsigned long sector) @@ -307,7 +321,7 @@ int spl_mmc_load_image(struct spl_image_info *spl_image, struct mmc *mmc = NULL; u32 boot_mode; int err = 0; - __maybe_unused int part; + __maybe_unused int part = 0; err = spl_mmc_find_device(&mmc, bootdev->boot_device); if (err) @@ -364,12 +378,12 @@ int spl_mmc_load_image(struct spl_image_info *spl_image, if (!err) return err; #endif -#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR - err = mmc_load_image_raw_sector(spl_image, mmc, - CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR); - if (!err) - return err; -#endif + if (IS_ENABLED(CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR)) { + err = mmc_load_image_raw_sector(spl_image, mmc, + spl_mmc_raw_uboot_sector(part)); + if (!err) + return err; + } /* If RAW mode fails, try FS mode. */ case MMCSD_MODE_FS: debug("spl: mmc boot mode: fs\n"); -- 2.20.1 _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot