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 int mmc_get_env_addr(struct mmc *mmc, int copy, u32 *env_addr)
22 u32 blklen, code_offset, code_len, n;
24 blklen = mmc->read_bl_len;
25 tmp_buf = malloc(blklen);
29 /* read out the first block, get the config data information */
30 n = mmc->block_dev.block_read(mmc->block_dev.dev, 0, 1, tmp_buf);
36 /* Get the Source Address, from offset 0x50 */
37 code_offset = *(u32 *)(tmp_buf + ESDHC_BOOT_IMAGE_ADDR);
39 /* Get the code size from offset 0x48 */
40 code_len = *(u32 *)(tmp_buf + ESDHC_BOOT_IMAGE_SIZE);
42 *env_addr = code_offset + code_len;