Oliver Graute | fe133eb | 2021-05-31 15:50:40 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (C) 2016 Freescale Semiconductor, Inc. |
| 4 | * Copyright 2018 NXP |
| 5 | * |
| 6 | */ |
| 7 | #include <common.h> |
| 8 | #include <linux/errno.h> |
| 9 | #include <asm/io.h> |
| 10 | #include <env.h> |
| 11 | #include <command.h> |
| 12 | #include <stdbool.h> |
| 13 | #include <mmc.h> |
| 14 | |
| 15 | static int check_mmc_autodetect(void) |
| 16 | { |
| 17 | char *autodetect_str = env_get("mmcautodetect"); |
| 18 | |
| 19 | if ((autodetect_str) && (strcmp(autodetect_str, "yes") == 0)) |
| 20 | return 1; |
| 21 | |
| 22 | return 0; |
| 23 | } |
| 24 | |
| 25 | /* This should be defined for each board */ |
| 26 | __weak int mmc_map_to_kernel_blk(int dev_no) |
| 27 | { |
| 28 | return dev_no; |
| 29 | } |
| 30 | |
| 31 | void board_late_mmc_env_init(void) |
| 32 | { |
| 33 | char cmd[32]; |
| 34 | char mmcblk[32]; |
| 35 | u32 dev_no = mmc_get_env_dev(); |
| 36 | |
| 37 | if (!check_mmc_autodetect()) |
| 38 | return; |
| 39 | |
| 40 | env_set_ulong("mmcdev", dev_no); |
| 41 | |
| 42 | /* Set mmcblk env */ |
| 43 | sprintf(mmcblk, "/dev/mmcblk%dp2 rootwait rw", |
| 44 | 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 | } |