blob: 8c45229a8953f77459cba4cf58111b135eba3365 [file] [log] [blame]
Masahiro Yamadab692c3f2017-02-14 01:24:24 +09001/*
2 * Copyright (C) 2016 Socionext Inc.
3 * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8#include <common.h>
9#include <mmc.h>
10#include <linux/errno.h>
11
12static int find_first_mmc_device(void)
13{
14 struct mmc *mmc;
15 int i;
16
17 for (i = 0; (mmc = find_mmc_device(i)); i++) {
18 if (!mmc_init(mmc) && IS_MMC(mmc))
19 return i;
20 }
21
22 return -ENODEV;
23}
24
25int mmc_get_env_dev(void)
26{
27 return find_first_mmc_device();
28}
29
30static int do_mmcsetn(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
31{
32 int dev;
33
34 dev = find_first_mmc_device();
35 if (dev < 0)
36 return CMD_RET_FAILURE;
37
38 setenv_ulong("mmc_first_dev", dev);
39 return CMD_RET_SUCCESS;
40}
41
42U_BOOT_CMD(
43 mmcsetn, 1, 1, do_mmcsetn,
44 "Set the first MMC (not SD) dev number to \"mmc_first_dev\" environment",
45 ""
46);