MLK-12434-1: imx: dynamic setting mmcdev and mmcroot
authorPeng Fan <peng.fan@nxp.com>
Tue, 23 Feb 2016 04:43:10 +0000 (12:43 +0800)
committerYe Li <ye.li@nxp.com>
Thu, 29 Apr 2021 05:03:36 +0000 (22:03 -0700)
Align to imx_v2015.04, dynamic setting mmcdev and mmcroot.
Then when boot linux, we can have correct "root=/dev/mmcblk[x]p2"

Signed-off-by: Peng Fan <peng.fan@nxp.com>
(cherry picked from commit b46b99a901eb194e81fc4836ee2259ad8857f4d3)
(cherry picked from commit 6f6a828fbe7478efd5932c302e6368877107bbca)
(cherry picked from commit bb628be4e993e98fb2fe8fc6af7b16e706d0f32d)
(cherry picked from commit 8e56914b4f536094bdf2301e347be02e0ccfee42)
(cherry picked from commit 3352f12289b3979a329486620711ecc2c2fb9fbd)

arch/arm/include/asm/mach-imx/sys_proto.h
board/freescale/common/Makefile
board/freescale/common/mmc.c [new file with mode: 0644]

index b9f42c1..927dfc2 100644 (file)
@@ -209,6 +209,8 @@ int mxs_reset_block(struct mxs_register_32 *reg);
 int mxs_wait_mask_set(struct mxs_register_32 *reg, u32 mask, u32 timeout);
 int mxs_wait_mask_clr(struct mxs_register_32 *reg, u32 mask, u32 timeout);
 
+void board_late_mmc_env_init(void);
+
 void vadc_power_up(void);
 void vadc_power_down(void);
 
index 572a89c..26085e5 100644 (file)
@@ -60,6 +60,9 @@ obj-$(CONFIG_POWER_PFUZE100)  += pfuze.o
 obj-$(CONFIG_DM_PMIC_PFUZE100) += pfuze.o
 obj-$(CONFIG_POWER_MC34VR500)  += mc34vr500.o
 obj-$(CONFIG_MXC_EPDC)         += epdc_setup.o
+ifneq (,$(filter $(SOC), mx25 mx31 mx35 mx5 mx6 mx7 mx7ulp imx8 imx8m vf610))
+obj-y                          += mmc.o
+endif
 
 obj-$(CONFIG_LS102XA_STREAM_ID)        += ls102xa_stream_id.o
 
diff --git a/board/freescale/common/mmc.c b/board/freescale/common/mmc.c
new file mode 100644 (file)
index 0000000..ab1652d
--- /dev/null
@@ -0,0 +1,51 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (C) 2016 Freescale Semiconductor, Inc.
+ * Copyright 2018 NXP
+ */
+#include <common.h>
+#include <command.h>
+#include <asm/arch/sys_proto.h>
+#include <linux/errno.h>
+#include <asm/io.h>
+#include <stdbool.h>
+#include <mmc.h>
+#include <env.h>
+
+static int check_mmc_autodetect(void)
+{
+       char *autodetect_str = env_get("mmcautodetect");
+
+       if ((autodetect_str != NULL) &&
+               (strcmp(autodetect_str, "yes") == 0)) {
+               return 1;
+       }
+
+       return 0;
+}
+
+/* This should be defined for each board */
+__weak int mmc_map_to_kernel_blk(int dev_no)
+{
+       return dev_no;
+}
+
+void board_late_mmc_env_init(void)
+{
+       char cmd[32];
+       char mmcblk[32];
+       u32 dev_no = mmc_get_env_dev();
+
+       if (!check_mmc_autodetect())
+               return;
+
+       env_set_ulong("mmcdev", dev_no);
+
+       /* Set mmcblk env */
+       sprintf(mmcblk, "/dev/mmcblk%dp2 rootwait rw",
+               mmc_map_to_kernel_blk(dev_no));
+       env_set("mmcroot", mmcblk);
+
+       sprintf(cmd, "mmc dev %d", dev_no);
+       run_command(cmd, 0);
+}