2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2017-02-13 16:24:24 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2016 Socionext Inc.
|
|
|
|
* Author: Masahiro Yamada <yamada.masahiro@socionext.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2020-05-10 17:40:03 +00:00
|
|
|
#include <command.h>
|
2019-08-01 15:46:47 +00:00
|
|
|
#include <env.h>
|
2017-02-13 16:24:24 +00:00
|
|
|
#include <mmc.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
|
2020-02-13 03:27:37 +00:00
|
|
|
static int find_first_mmc_device(bool is_sd)
|
2017-02-13 16:24:24 +00:00
|
|
|
{
|
|
|
|
struct mmc *mmc;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; (mmc = find_mmc_device(i)); i++) {
|
2020-02-13 03:27:37 +00:00
|
|
|
if (!mmc_init(mmc) &&
|
|
|
|
((is_sd && IS_SD(mmc)) || (!is_sd && IS_MMC(mmc))))
|
2017-02-13 16:24:24 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
int mmc_get_env_dev(void)
|
|
|
|
{
|
2020-02-13 03:27:37 +00:00
|
|
|
return find_first_mmc_device(false);
|
2017-02-13 16:24:24 +00:00
|
|
|
}
|
|
|
|
|
2020-05-10 17:40:03 +00:00
|
|
|
static int do_mmcsetn(struct cmd_tbl *cmdtp, int flag, int argc,
|
|
|
|
char *const argv[])
|
2017-02-13 16:24:24 +00:00
|
|
|
{
|
|
|
|
int dev;
|
|
|
|
|
2020-02-13 03:27:37 +00:00
|
|
|
dev = find_first_mmc_device(false);
|
2017-02-13 16:24:24 +00:00
|
|
|
if (dev < 0)
|
|
|
|
return CMD_RET_FAILURE;
|
|
|
|
|
2017-08-03 18:22:10 +00:00
|
|
|
env_set_ulong("mmc_first_dev", dev);
|
2017-02-13 16:24:24 +00:00
|
|
|
return CMD_RET_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_BOOT_CMD(
|
|
|
|
mmcsetn, 1, 1, do_mmcsetn,
|
|
|
|
"Set the first MMC (not SD) dev number to \"mmc_first_dev\" environment",
|
|
|
|
""
|
|
|
|
);
|
2020-02-13 03:27:37 +00:00
|
|
|
|
2020-05-10 17:40:03 +00:00
|
|
|
static int do_sdsetn(struct cmd_tbl *cmdtp, int flag, int argc,
|
|
|
|
char *const argv[])
|
2020-02-13 03:27:37 +00:00
|
|
|
{
|
|
|
|
int dev;
|
|
|
|
|
|
|
|
dev = find_first_mmc_device(true);
|
|
|
|
if (dev < 0)
|
|
|
|
return CMD_RET_FAILURE;
|
|
|
|
|
|
|
|
env_set_ulong("sd_first_dev", dev);
|
|
|
|
return CMD_RET_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_BOOT_CMD(
|
|
|
|
sdsetn, 1, 1, do_sdsetn,
|
|
|
|
"Set the first SD dev number to \"sd_first_dev\" environment",
|
|
|
|
""
|
|
|
|
);
|