2 * Copyright 2011 Freescale Semiconductor, Inc.
4 * SPDX-License-Identifier: GPL-2.0+
12 * The environment variables are written to just after the u-boot image
13 * on SDCard, so we must read the MBR to get the start address and code
14 * length of the u-boot image, then calculate the address of the env.
16 #define ESDHC_BOOT_IMAGE_SIZE 0x48
17 #define ESDHC_BOOT_IMAGE_ADDR 0x50
19 #define ESDHC_DEFAULT_ENVADDR 0x400
21 int mmc_get_env_addr(struct mmc *mmc, int copy, u32 *env_addr)
24 u32 blklen, code_offset, code_len, n;
26 blklen = mmc->read_bl_len;
27 tmp_buf = malloc(blklen);
31 /* read out the first block, get the config data information */
32 n = mmc->block_dev.block_read(mmc->block_dev.dev, 0, 1, tmp_buf);
38 /* Get the Source Address, from offset 0x50 */
39 code_offset = *(u32 *)(tmp_buf + ESDHC_BOOT_IMAGE_ADDR);
41 /* Get the code size from offset 0x48 */
42 code_len = *(u32 *)(tmp_buf + ESDHC_BOOT_IMAGE_SIZE);
44 #ifdef CONFIG_ESDHC_HC_BLK_ADDR
46 * On soc BSC9131, BSC9132:
47 * In High Capacity SD Cards (> 2 GBytes), the 32-bit source address and
48 * code length of these soc specify the memory address in block address
49 * format. Block length is fixed to 512 bytes as per the SD High
50 * Capacity specification.
54 if (mmc->high_capacity) {
55 tmp = (u64)code_offset * blklen;
56 tmp += code_len * blklen;
58 tmp = code_offset + code_len;
60 if ((tmp + CONFIG_ENV_SIZE > mmc->capacity) ||
62 *env_addr = ESDHC_DEFAULT_ENVADDR;
71 *env_addr = code_offset + code_len;