2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2012-08-15 10:31:20 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 Boundary Devices Inc.
|
|
|
|
*/
|
|
|
|
#include <common.h>
|
2016-09-21 02:28:55 +00:00
|
|
|
#include <linux/errno.h>
|
2012-08-15 10:31:20 +00:00
|
|
|
#include <asm/io.h>
|
2017-06-29 08:16:06 +00:00
|
|
|
#include <asm/mach-imx/boot_mode.h>
|
2012-08-15 10:31:20 +00:00
|
|
|
#include <malloc.h>
|
2012-10-12 10:27:04 +00:00
|
|
|
#include <command.h>
|
2012-08-15 10:31:20 +00:00
|
|
|
|
|
|
|
static const struct boot_mode *modes[2];
|
|
|
|
|
|
|
|
static const struct boot_mode *search_modes(char *arg)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(modes); i++) {
|
|
|
|
const struct boot_mode *p = modes[i];
|
|
|
|
if (p) {
|
|
|
|
while (p->name) {
|
|
|
|
if (!strcmp(p->name, arg))
|
|
|
|
return p;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int create_usage(char *dest)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int size = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(modes); i++) {
|
|
|
|
const struct boot_mode *p = modes[i];
|
|
|
|
if (p) {
|
|
|
|
while (p->name) {
|
|
|
|
int len = strlen(p->name);
|
|
|
|
if (dest) {
|
|
|
|
memcpy(dest, p->name, len);
|
|
|
|
dest += len;
|
|
|
|
*dest++ = '|';
|
|
|
|
}
|
|
|
|
size += len + 1;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (dest)
|
|
|
|
memcpy(dest - 1, " [noreset]", 11); /* include trailing 0 */
|
|
|
|
size += 10;
|
2020-08-05 13:34:06 +00:00
|
|
|
|
|
|
|
if (dest)
|
|
|
|
memcpy(dest - 1, "\nbmode - getprisec", 19);
|
|
|
|
size += 18;
|
|
|
|
|
2012-08-15 10:31:20 +00:00
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2020-08-05 13:34:06 +00:00
|
|
|
__weak int boot_mode_getprisec(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-10 17:40:03 +00:00
|
|
|
static int do_boot_mode(struct cmd_tbl *cmdtp, int flag, int argc,
|
|
|
|
char *const argv[])
|
2012-08-15 10:31:20 +00:00
|
|
|
{
|
|
|
|
const struct boot_mode *p;
|
|
|
|
int reset_requested = 1;
|
|
|
|
|
|
|
|
if (argc < 2)
|
|
|
|
return CMD_RET_USAGE;
|
2020-08-05 13:34:06 +00:00
|
|
|
if (!strcmp(argv[1], "getprisec"))
|
|
|
|
return boot_mode_getprisec();
|
2012-08-15 10:31:20 +00:00
|
|
|
p = search_modes(argv[1]);
|
|
|
|
if (!p)
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
if (argc == 3) {
|
|
|
|
if (strcmp(argv[2], "noreset"))
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
reset_requested = 0;
|
|
|
|
}
|
|
|
|
|
2023-10-16 16:16:15 +00:00
|
|
|
/* No longer applicable to i.MX8M */
|
|
|
|
#if IS_ENABLED(CONFIG_MX53) || IS_ENABLED(CONFIG_MX6) || IS_ENABLED(CONFIG_MX7)
|
2012-08-15 10:31:20 +00:00
|
|
|
boot_mode_apply(p->cfg_val);
|
2023-10-16 16:16:15 +00:00
|
|
|
#endif
|
|
|
|
|
2012-08-15 10:31:20 +00:00
|
|
|
if (reset_requested && p->cfg_val)
|
|
|
|
do_reset(NULL, 0, 0, NULL);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_BOOT_CMD(
|
|
|
|
bmode, 3, 0, do_boot_mode,
|
|
|
|
NULL,
|
|
|
|
"");
|
|
|
|
|
|
|
|
void add_board_boot_modes(const struct boot_mode *p)
|
|
|
|
{
|
|
|
|
int size;
|
|
|
|
char *dest;
|
|
|
|
|
2020-05-10 17:40:03 +00:00
|
|
|
struct cmd_tbl *entry = ll_entry_get(struct cmd_tbl, bmode, cmd);
|
2012-10-12 10:27:04 +00:00
|
|
|
|
|
|
|
if (entry->usage) {
|
|
|
|
free(entry->usage);
|
|
|
|
entry->usage = NULL;
|
2012-08-15 10:31:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
modes[0] = p;
|
|
|
|
modes[1] = soc_boot_modes;
|
|
|
|
size = create_usage(NULL);
|
|
|
|
dest = malloc(size);
|
|
|
|
if (dest) {
|
|
|
|
create_usage(dest);
|
2012-10-12 10:27:04 +00:00
|
|
|
entry->usage = dest;
|
2012-08-15 10:31:20 +00:00
|
|
|
}
|
|
|
|
}
|