1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2013 Freescale Semiconductor, Inc.
13 * The environment variables are written to just after the u-boot image
14 * on SDCard, so we must read the MBR to get the start address and code
15 * length of the u-boot image, then calculate the address of the env.
17 #define ESDHC_BOOT_SIGNATURE_OFF 0x40
18 #define ESDHC_BOOT_SIGNATURE 0x424f4f54
19 #define ESDHC_BOOT_IMAGE_SIZE 0x48
20 #define ESDHC_BOOT_IMAGE_ADDR 0x50
21 #define MBRDBR_BOOT_SIG_55 0x1fe
22 #define MBRDBR_BOOT_SIG_AA 0x1ff
23 #define CONFIG_CFG_DATA_SECTOR 0
26 void mmc_spl_load_image(uint32_t offs, unsigned int size, void *vdst)
28 uint blk_start, blk_cnt, err;
30 struct mmc *mmc = find_mmc_device(0);
32 puts("spl: mmc device not found!!\n");
37 puts("MMC init failed\n");
41 blk_start = ALIGN(offs, mmc->read_bl_len) / mmc->read_bl_len;
42 blk_cnt = ALIGN(size, mmc->read_bl_len) / mmc->read_bl_len;
44 err = mmc->block_dev.block_read(&mmc->block_dev, blk_start, blk_cnt,
47 puts("spl: mmc read failed!!\n");
53 * The main entry for mmc booting. It's necessary that SDRAM is already
54 * configured and available since this code loads the main U-Boot image
55 * from mmc into SDRAM and starts it from there.
58 void __noreturn mmc_boot(void)
60 __attribute__((noreturn)) void (*uboot)(void);
61 uint blk_start, blk_cnt, err;
62 #ifndef CONFIG_FSL_CORENET
66 #ifndef CONFIG_SPL_FSL_PBL
74 mmc = find_mmc_device(0);
76 puts("spl: mmc device not found!!\n");
80 #ifdef CONFIG_FSL_CORENET
81 offset = CONFIG_SYS_MMC_U_BOOT_OFFS;
82 code_len = CONFIG_SYS_MMC_U_BOOT_SIZE;
84 blklen = mmc->read_bl_len;
85 tmp_buf = malloc(blklen);
87 puts("spl: malloc memory failed!!\n");
90 memset(tmp_buf, 0, blklen);
93 * Read source addr from sd card
95 err = mmc->block_dev.block_read(&mmc->block_dev,
96 CONFIG_CFG_DATA_SECTOR, 1, tmp_buf);
98 puts("spl: mmc read failed!!\n");
102 #ifdef CONFIG_SPL_FSL_PBL
103 val = *(tmp_buf + MBRDBR_BOOT_SIG_55);
105 puts("spl: mmc MBR/DBR signature is not valid!!\n");
108 val = *(tmp_buf + MBRDBR_BOOT_SIG_AA);
110 puts("spl: mmc MBR/DBR signature is not valid!!\n");
115 * Booting from On-Chip ROM (eSDHC or eSPI), Document Number: AN3659, Rev. 2, 06/2012.
116 * Pre-PBL BootROMs (MPC8536E, MPC8569E, P2020, P1011, P1012, P1013, P1020, P1021, P1022)
117 * require custom BOOT signature on sector 0 and MBR/DBR signature is not required at all.
121 for (i = 0; i < byte_num; i++) {
122 val = *(tmp_buf + ESDHC_BOOT_SIGNATURE_OFF + i);
123 val32 = (val32 << 8) + val;
125 if (val32 != ESDHC_BOOT_SIGNATURE) {
126 puts("spl: mmc BOOT signature is not valid!!\n");
133 for (i = 0; i < byte_num; i++) {
134 val = *(tmp_buf + ESDHC_BOOT_IMAGE_ADDR + i);
135 offset = (offset << 8) + val;
137 offset += CONFIG_SYS_MMC_U_BOOT_OFFS;
138 /* Get the code size from offset 0x48 */
141 for (i = 0; i < byte_num; i++) {
142 val = *(tmp_buf + ESDHC_BOOT_IMAGE_SIZE + i);
143 code_len = (code_len << 8) + val;
145 code_len -= CONFIG_SYS_MMC_U_BOOT_OFFS;
147 * Load U-Boot image from mmc into RAM
150 blk_start = ALIGN(offset, mmc->read_bl_len) / mmc->read_bl_len;
151 blk_cnt = ALIGN(code_len, mmc->read_bl_len) / mmc->read_bl_len;
152 err = mmc->block_dev.block_read(&mmc->block_dev, blk_start, blk_cnt,
153 (uchar *)CONFIG_SYS_MMC_U_BOOT_DST);
154 if (err != blk_cnt) {
155 puts("spl: mmc read failed!!\n");
156 #ifndef CONFIG_FSL_CORENET
163 * Clean d-cache and invalidate i-cache, to
164 * make sure that no stale data is executed.
166 flush_cache(CONFIG_SYS_MMC_U_BOOT_DST, CONFIG_SYS_MMC_U_BOOT_SIZE);
169 * Jump to U-Boot image
171 uboot = (void *)CONFIG_SYS_MMC_U_BOOT_START;