blob: acc859a6c3f917ce7abaaafaac13208e644ebfca [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
Simon Glass4d949a22017-08-03 12:22:10 -060038 env_set_ulong("mmc_first_dev", dev);
Masahiro Yamadab692c3f2017-02-14 01:24:24 +090039 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);