blob: 0ba9736b1ab34fe746504893ca47c93c2a0fd8ec [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
17#include <common.h>
18#include <command.h>
Simon Glass6bf6dbe2019-08-01 09:46:49 -060019#include <env.h>
wdenkd0dd1072002-10-20 17:17:16 +000020#include <image.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060021#include <log.h>
wdenkd0dd1072002-10-20 17:17:16 +000022#include <malloc.h>
Joe Hershberger0eb25b62015-03-22 17:08:59 -050023#include <mapmem.h>
wdenkd0dd1072002-10-20 17:17:16 +000024#include <asm/byteorder.h>
Simon Glass4ca30d62013-04-20 08:42:49 +000025#include <asm/io.h>
wdenkd0dd1072002-10-20 17:17:16 +000026
Simon Glass09140112020-05-10 11:40:03 -060027static int do_source(struct cmd_tbl *cmdtp, int flag, int argc,
28 char *const argv[])
wdenkd0dd1072002-10-20 17:17:16 +000029{
30 ulong addr;
31 int rcode;
Sean Andersonbcc85b92022-12-12 14:12:11 -050032 const char *fit_uname = NULL, *confname = NULL;
wdenkd0dd1072002-10-20 17:17:16 +000033
Marian Balakowicz424c4ab2008-03-12 10:33:00 +010034 /* Find script image */
wdenkd0dd1072002-10-20 17:17:16 +000035 if (argc < 2) {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020036 addr = CONFIG_SYS_LOAD_ADDR;
Simon Glass3c7dded2020-05-10 11:40:04 -060037 debug("* source: default load address = 0x%08lx\n", addr);
Marian Balakowicz424c4ab2008-03-12 10:33:00 +010038#if defined(CONFIG_FIT)
Simon Glassbb872dd2019-12-28 10:45:02 -070039 } else if (fit_parse_subimage(argv[1], image_load_addr, &addr,
40 &fit_uname)) {
Simon Glass3c7dded2020-05-10 11:40:04 -060041 debug("* source: subimage '%s' from FIT image at 0x%08lx\n",
42 fit_uname, addr);
Sean Andersonbcc85b92022-12-12 14:12:11 -050043 } else if (fit_parse_conf(argv[1], image_load_addr, &addr, &confname)) {
44 debug("* source: config '%s' from FIT image at 0x%08lx\n",
45 confname, addr);
Marian Balakowicz424c4ab2008-03-12 10:33:00 +010046#endif
wdenkd0dd1072002-10-20 17:17:16 +000047 } else {
Simon Glass7e5f4602021-07-24 09:03:29 -060048 addr = hextoul(argv[1], NULL);
Simon Glass3c7dded2020-05-10 11:40:04 -060049 debug("* source: cmdline image address = 0x%08lx\n", addr);
wdenkd0dd1072002-10-20 17:17:16 +000050 }
51
Marian Balakowicz424c4ab2008-03-12 10:33:00 +010052 printf ("## Executing script at %08lx\n", addr);
Simon Glass30f33332023-01-06 08:52:28 -060053 rcode = cmd_source_script(addr, fit_uname, confname);
wdenkd0dd1072002-10-20 17:17:16 +000054 return rcode;
55}
wdenk8bde7f72003-06-27 21:31:46 +000056
Tom Rini36162182023-10-07 15:13:08 -040057U_BOOT_LONGHELP(source,
Marian Balakowicz424c4ab2008-03-12 10:33:00 +010058#if defined(CONFIG_FIT)
Sean Andersonbcc85b92022-12-12 14:12:11 -050059 "[<addr>][:[<image>]|#[<config>]]\n"
60 "\t- Run script starting at addr\n"
61 "\t- A FIT config name or subimage name may be specified with : or #\n"
62 "\t (like bootm). If the image or config name is omitted, the\n"
Tom Rini36162182023-10-07 15:13:08 -040063 "\t default is used."
Sean Andersonbcc85b92022-12-12 14:12:11 -050064#else
65 "[<addr>]\n"
Tom Rini36162182023-10-07 15:13:08 -040066 "\t- Run script starting at addr"
Jon Loeliger90253172007-07-10 11:02:44 -050067#endif
Tom Rini36162182023-10-07 15:13:08 -040068 );
Kim Phillips088f1b12012-10-29 13:34:31 +000069
70U_BOOT_CMD(
71 source, 2, 0, do_source,
72 "run script from memory", source_help_text
Marian Balakowicz424c4ab2008-03-12 10:33:00 +010073);