2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2002-10-20 17:17:16 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2001
|
|
|
|
* Kyle Harris, kharris@nexus-tech.net
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2009-04-01 21:34:12 +00:00
|
|
|
* The "source" command allows to define "script images", i. e. files
|
|
|
|
* that contain command sequences that can be executed by the command
|
|
|
|
* interpreter. It returns the exit status of the last command
|
|
|
|
* executed from the script. This is very similar to running a shell
|
|
|
|
* script in a UNIX shell, hence the name for the command.
|
2002-10-20 17:17:16 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* #define DEBUG */
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <command.h>
|
2019-08-01 15:46:49 +00:00
|
|
|
#include <env.h>
|
2002-10-20 17:17:16 +00:00
|
|
|
#include <image.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2002-10-20 17:17:16 +00:00
|
|
|
#include <malloc.h>
|
2015-03-22 22:08:59 +00:00
|
|
|
#include <mapmem.h>
|
2002-10-20 17:17:16 +00:00
|
|
|
#include <asm/byteorder.h>
|
2013-04-20 08:42:49 +00:00
|
|
|
#include <asm/io.h>
|
2002-10-20 17:17:16 +00:00
|
|
|
|
2020-05-10 17:40:03 +00:00
|
|
|
static int do_source(struct cmd_tbl *cmdtp, int flag, int argc,
|
|
|
|
char *const argv[])
|
2002-10-20 17:17:16 +00:00
|
|
|
{
|
|
|
|
ulong addr;
|
|
|
|
int rcode;
|
2022-12-12 19:12:11 +00:00
|
|
|
const char *fit_uname = NULL, *confname = NULL;
|
2002-10-20 17:17:16 +00:00
|
|
|
|
2008-03-12 09:33:00 +00:00
|
|
|
/* Find script image */
|
2002-10-20 17:17:16 +00:00
|
|
|
if (argc < 2) {
|
2008-10-16 13:01:15 +00:00
|
|
|
addr = CONFIG_SYS_LOAD_ADDR;
|
2020-05-10 17:40:04 +00:00
|
|
|
debug("* source: default load address = 0x%08lx\n", addr);
|
2008-03-12 09:33:00 +00:00
|
|
|
#if defined(CONFIG_FIT)
|
2019-12-28 17:45:02 +00:00
|
|
|
} else if (fit_parse_subimage(argv[1], image_load_addr, &addr,
|
|
|
|
&fit_uname)) {
|
2020-05-10 17:40:04 +00:00
|
|
|
debug("* source: subimage '%s' from FIT image at 0x%08lx\n",
|
|
|
|
fit_uname, addr);
|
2022-12-12 19:12:11 +00:00
|
|
|
} else if (fit_parse_conf(argv[1], image_load_addr, &addr, &confname)) {
|
|
|
|
debug("* source: config '%s' from FIT image at 0x%08lx\n",
|
|
|
|
confname, addr);
|
2008-03-12 09:33:00 +00:00
|
|
|
#endif
|
2002-10-20 17:17:16 +00:00
|
|
|
} else {
|
2021-07-24 15:03:29 +00:00
|
|
|
addr = hextoul(argv[1], NULL);
|
2020-05-10 17:40:04 +00:00
|
|
|
debug("* source: cmdline image address = 0x%08lx\n", addr);
|
2002-10-20 17:17:16 +00:00
|
|
|
}
|
|
|
|
|
2008-03-12 09:33:00 +00:00
|
|
|
printf ("## Executing script at %08lx\n", addr);
|
2023-01-06 14:52:28 +00:00
|
|
|
rcode = cmd_source_script(addr, fit_uname, confname);
|
2002-10-20 17:17:16 +00:00
|
|
|
return rcode;
|
|
|
|
}
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2012-10-29 13:34:31 +00:00
|
|
|
#ifdef CONFIG_SYS_LONGHELP
|
|
|
|
static char source_help_text[] =
|
2008-03-12 09:33:00 +00:00
|
|
|
#if defined(CONFIG_FIT)
|
2022-12-12 19:12:11 +00:00
|
|
|
"[<addr>][:[<image>]|#[<config>]]\n"
|
|
|
|
"\t- Run script starting at addr\n"
|
|
|
|
"\t- A FIT config name or subimage name may be specified with : or #\n"
|
|
|
|
"\t (like bootm). If the image or config name is omitted, the\n"
|
|
|
|
"\t default is used.";
|
|
|
|
#else
|
|
|
|
"[<addr>]\n"
|
|
|
|
"\t- Run script starting at addr";
|
2007-07-10 16:02:44 +00:00
|
|
|
#endif
|
2012-10-29 13:34:31 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
U_BOOT_CMD(
|
|
|
|
source, 2, 0, do_source,
|
|
|
|
"run script from memory", source_help_text
|
2008-03-12 09:33:00 +00:00
|
|
|
);
|