blob: 00e4f3675fe4cac8bf4feebbd8b12025cf606686 [file] [log] [blame]
Peng Fan4de11282022-04-06 14:30:25 +08001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2016 Freescale Semiconductor, Inc.
4 * Copyright 2018-2022 NXP
5 */
6
Peng Fan4de11282022-04-06 14:30:25 +08007#include <command.h>
Tom Rinidec7ea02024-05-20 13:35:03 -06008#include <vsprintf.h>
Peng Fan4de11282022-04-06 14:30:25 +08009#include <asm/arch/sys_proto.h>
10#include <linux/errno.h>
11#include <asm/io.h>
12#include <stdbool.h>
13#include <mmc.h>
14#include <env.h>
15
16static int check_mmc_autodetect(void)
17{
18 char *autodetect_str = env_get("mmcautodetect");
19
20 if (autodetect_str && !strcmp(autodetect_str, "yes"))
21 return 1;
22
23 return 0;
24}
25
26/* This should be defined for each board */
27__weak int mmc_map_to_kernel_blk(int dev_no)
28{
29 return dev_no;
30}
31
32void board_late_mmc_env_init(void)
33{
34 char cmd[32];
35 char mmcblk[32];
36 u32 dev_no = mmc_get_env_dev();
37
38 if (!check_mmc_autodetect())
39 return;
40
41 env_set_ulong("mmcdev", dev_no);
42
43 /* Set mmcblk env */
44 sprintf(mmcblk, "/dev/mmcblk%dp2 rootwait rw", mmc_map_to_kernel_blk(dev_no));
45 env_set("mmcroot", mmcblk);
46
47 sprintf(cmd, "mmc dev %d", dev_no);
48 run_command(cmd, 0);
49}