]>
git.ipfire.org Git - thirdparty/u-boot.git/blob - drivers/mmc/fsl_esdhc_spl.c
1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2013 Freescale Semiconductor, Inc.
12 #ifndef CFG_SYS_MMC_U_BOOT_OFFS
13 extern uchar mmc_u_boot_offs
[];
17 * The environment variables are written to just after the u-boot image
18 * on SDCard, so we must read the MBR to get the start address and code
19 * length of the u-boot image, then calculate the address of the env.
21 #define ESDHC_BOOT_SIGNATURE_OFF 0x40
22 #define ESDHC_BOOT_SIGNATURE 0x424f4f54
23 #define ESDHC_BOOT_IMAGE_SIZE 0x48
24 #define ESDHC_BOOT_IMAGE_ADDR 0x50
25 #define MBRDBR_BOOT_SIG_55 0x1fe
26 #define MBRDBR_BOOT_SIG_AA 0x1ff
29 void mmc_spl_load_image(uint32_t offs
, unsigned int size
, void *vdst
)
31 uint blk_start
, blk_cnt
, err
;
33 struct mmc
*mmc
= find_mmc_device(0);
35 puts("spl: mmc device not found!!\n");
40 puts("MMC init failed\n");
44 blk_start
= ALIGN(offs
, mmc
->read_bl_len
) / mmc
->read_bl_len
;
45 blk_cnt
= ALIGN(size
, mmc
->read_bl_len
) / mmc
->read_bl_len
;
47 err
= mmc
->block_dev
.block_read(&mmc
->block_dev
, blk_start
, blk_cnt
,
50 puts("spl: mmc read failed!!\n");
56 * The main entry for mmc booting. It's necessary that SDRAM is already
57 * configured and available since this code loads the main U-Boot image
58 * from mmc into SDRAM and starts it from there.
61 void __noreturn
mmc_boot(void)
63 __attribute__((noreturn
)) void (*uboot
)(void);
64 uint blk_start
, blk_cnt
, err
;
68 #ifndef CONFIG_FSL_CORENET
70 #ifndef CONFIG_SPL_FSL_PBL
79 mmc
= find_mmc_device(0);
81 puts("spl: mmc device not found!!\n");
86 puts("spl: mmc device init failed!\n");
90 blklen
= mmc
->read_bl_len
;
93 tmp_buf
= malloc(blklen
);
95 puts("spl: malloc memory failed!!\n");
99 #ifdef CONFIG_FSL_CORENET
100 offset
= CFG_SYS_MMC_U_BOOT_OFFS
;
104 memset(tmp_buf
, 0, blklen
);
107 * Read source addr from sd card
109 blk_start
= (sector
* 512) / mmc
->read_bl_len
;
110 blk_off
= (sector
* 512) % mmc
->read_bl_len
;
111 blk_cnt
= DIV_ROUND_UP(512, mmc
->read_bl_len
);
112 err
= mmc
->block_dev
.block_read(&mmc
->block_dev
, blk_start
, blk_cnt
, tmp_buf
);
113 if (err
!= blk_cnt
) {
114 puts("spl: mmc read failed!!\n");
118 #ifdef CONFIG_SPL_FSL_PBL
119 val
= *(tmp_buf
+ blk_off
+ MBRDBR_BOOT_SIG_55
);
121 puts("spl: mmc MBR/DBR signature is not valid!!\n");
124 val
= *(tmp_buf
+ blk_off
+ MBRDBR_BOOT_SIG_AA
);
126 puts("spl: mmc MBR/DBR signature is not valid!!\n");
131 * Booting from On-Chip ROM (eSDHC or eSPI), Document Number: AN3659, Rev. 2, 06/2012.
132 * Pre-PBL BootROMs (MPC8536E, MPC8569E, P2020, P1011, P1012, P1013, P1020, P1021, P1022)
133 * require custom BOOT signature on sector 0 and MBR/DBR signature is not required at all.
137 for (i
= 0; i
< byte_num
; i
++) {
138 val
= *(tmp_buf
+ blk_off
+ ESDHC_BOOT_SIGNATURE_OFF
+ i
);
139 val32
= (val32
<< 8) + val
;
141 if (val32
!= ESDHC_BOOT_SIGNATURE
) {
142 /* BOOT signature may be on the first 24 sectors (each being 512 bytes) */
145 puts("spl: mmc BOOT signature is not valid!!\n");
152 for (i
= 0; i
< byte_num
; i
++) {
153 val
= *(tmp_buf
+ blk_off
+ ESDHC_BOOT_IMAGE_ADDR
+ i
);
154 offset
= (offset
<< 8) + val
;
156 #ifndef CFG_SYS_MMC_U_BOOT_OFFS
157 offset
+= (ulong
)&mmc_u_boot_offs
- CONFIG_SPL_TEXT_BASE
;
159 offset
+= CFG_SYS_MMC_U_BOOT_OFFS
;
163 * Load U-Boot image from mmc into RAM
165 code_len
= CFG_SYS_MMC_U_BOOT_SIZE
;
166 blk_start
= offset
/ mmc
->read_bl_len
;
167 blk_off
= offset
% mmc
->read_bl_len
;
168 blk_cnt
= ALIGN(code_len
, mmc
->read_bl_len
) / mmc
->read_bl_len
+ 1;
170 err
= mmc
->block_dev
.block_read(&mmc
->block_dev
,
171 blk_start
, 1, tmp_buf
);
173 puts("spl: mmc read failed!!\n");
178 err
= mmc
->block_dev
.block_read(&mmc
->block_dev
, blk_start
, blk_cnt
,
179 (uchar
*)CFG_SYS_MMC_U_BOOT_DST
+
180 (blk_off
? (mmc
->read_bl_len
- blk_off
) : 0));
181 if (err
!= blk_cnt
) {
182 puts("spl: mmc read failed!!\n");
187 * SDHC DMA may erase bytes at dst + bl_len - blk_off - 8
188 * due to unaligned access. So copy leading bytes from tmp_buf
189 * after SDHC DMA transfer.
192 memcpy((uchar
*)CFG_SYS_MMC_U_BOOT_DST
,
193 tmp_buf
+ blk_off
, mmc
->read_bl_len
- blk_off
);
196 * Clean d-cache and invalidate i-cache, to
197 * make sure that no stale data is executed.
199 flush_cache(CFG_SYS_MMC_U_BOOT_DST
, CFG_SYS_MMC_U_BOOT_SIZE
);
202 * Jump to U-Boot image
204 uboot
= (void *)CFG_SYS_MMC_U_BOOT_START
;