blob: c9b5f8e400a615c055979270774cd9bde3183a79 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
wdenkd0dd1072002-10-20 17:17:16 +00002/*
3 * (C) Copyright 2001
4 * Kyle Harris, kharris@nexus-tech.net
wdenkd0dd1072002-10-20 17:17:16 +00005 */
6
7/*
Wolfgang Denk74de7ae2009-04-01 23:34:12 +02008 * The "source" command allows to define "script images", i. e. files
9 * that contain command sequences that can be executed by the command
10 * interpreter. It returns the exit status of the last command
11 * executed from the script. This is very similar to running a shell
12 * script in a UNIX shell, hence the name for the command.
wdenkd0dd1072002-10-20 17:17:16 +000013 */
14
15/* #define DEBUG */
16
wdenkd0dd1072002-10-20 17:17:16 +000017#include <command.h>
Simon Glass6bf6dbe2019-08-01 09:46:49 -060018#include <env.h>
wdenkd0dd1072002-10-20 17:17:16 +000019#include <image.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060020#include <log.h>
wdenkd0dd1072002-10-20 17:17:16 +000021#include <malloc.h>
Joe Hershberger0eb25b62015-03-22 17:08:59 -050022#include <mapmem.h>
wdenkd0dd1072002-10-20 17:17:16 +000023#include <asm/byteorder.h>
Simon Glass4ca30d62013-04-20 08:42:49 +000024#include <asm/io.h>
wdenkd0dd1072002-10-20 17:17:16 +000025
Simon Glass09140112020-05-10 11:40:03 -060026static int do_source(struct cmd_tbl *cmdtp, int flag, int argc,
27 char *const argv[])
wdenkd0dd1072002-10-20 17:17:16 +000028{
29 ulong addr;
30 int rcode;
Sean Andersonbcc85b92022-12-12 14:12:11 -050031 const char *fit_uname = NULL, *confname = NULL;
wdenkd0dd1072002-10-20 17:17:16 +000032
Marian Balakowicz424c4ab2008-03-12 10:33:00 +010033 /* Find script image */
wdenkd0dd1072002-10-20 17:17:16 +000034 if (argc < 2) {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020035 addr = CONFIG_SYS_LOAD_ADDR;
Simon Glass3c7dded2020-05-10 11:40:04 -060036 debug("* source: default load address = 0x%08lx\n", addr);
Marian Balakowicz424c4ab2008-03-12 10:33:00 +010037#if defined(CONFIG_FIT)
Simon Glassbb872dd2019-12-28 10:45:02 -070038 } else if (fit_parse_subimage(argv[1], image_load_addr, &addr,
39 &fit_uname)) {
Simon Glass3c7dded2020-05-10 11:40:04 -060040 debug("* source: subimage '%s' from FIT image at 0x%08lx\n",
41 fit_uname, addr);
Sean Andersonbcc85b92022-12-12 14:12:11 -050042 } else if (fit_parse_conf(argv[1], image_load_addr, &addr, &confname)) {
43 debug("* source: config '%s' from FIT image at 0x%08lx\n",
44 confname, addr);
Marian Balakowicz424c4ab2008-03-12 10:33:00 +010045#endif
wdenkd0dd1072002-10-20 17:17:16 +000046 } else {
Simon Glass7e5f4602021-07-24 09:03:29 -060047 addr = hextoul(argv[1], NULL);
Simon Glass3c7dded2020-05-10 11:40:04 -060048 debug("* source: cmdline image address = 0x%08lx\n", addr);
wdenkd0dd1072002-10-20 17:17:16 +000049 }
50
Marian Balakowicz424c4ab2008-03-12 10:33:00 +010051 printf ("## Executing script at %08lx\n", addr);
Simon Glass30f33332023-01-06 08:52:28 -060052 rcode = cmd_source_script(addr, fit_uname, confname);
wdenkd0dd1072002-10-20 17:17:16 +000053 return rcode;
54}
wdenk8bde7f72003-06-27 21:31:46 +000055
Tom Rini36162182023-10-07 15:13:08 -040056U_BOOT_LONGHELP(source,
Marian Balakowicz424c4ab2008-03-12 10:33:00 +010057#if defined(CONFIG_FIT)
Sean Andersonbcc85b92022-12-12 14:12:11 -050058 "[<addr>][:[<image>]|#[<config>]]\n"
59 "\t- Run script starting at addr\n"
60 "\t- A FIT config name or subimage name may be specified with : or #\n"
61 "\t (like bootm). If the image or config name is omitted, the\n"
Tom Rini36162182023-10-07 15:13:08 -040062 "\t default is used."
Sean Andersonbcc85b92022-12-12 14:12:11 -050063#else
64 "[<addr>]\n"
Tom Rini36162182023-10-07 15:13:08 -040065 "\t- Run script starting at addr"
Jon Loeliger90253172007-07-10 11:02:44 -050066#endif
Tom Rini36162182023-10-07 15:13:08 -040067 );
Kim Phillips088f1b12012-10-29 13:34:31 +000068
69U_BOOT_CMD(
70 source, 2, 0, do_source,
71 "run script from memory", source_help_text
Marian Balakowicz424c4ab2008-03-12 10:33:00 +010072);