blob: 0ba9736b1ab34fe746504893ca47c93c2a0fd8ec [file] [log] [blame]
Tom Rini10e47792018-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 Denk85c25df2009-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 Glassc301bd82019-08-01 09:46:49 -060019#include <env.h>
wdenkd0dd1072002-10-20 17:17:16 +000020#include <image.h>
Simon Glass0f2af882020-05-10 11:40:05 -060021#include <log.h>
wdenkd0dd1072002-10-20 17:17:16 +000022#include <malloc.h>
Joe Hershberger65b905b2015-03-22 17:08:59 -050023#include <mapmem.h>
wdenkd0dd1072002-10-20 17:17:16 +000024#include <asm/byteorder.h>
Simon Glass7e5581e2013-04-20 08:42:49 +000025#include <asm/io.h>
wdenkd0dd1072002-10-20 17:17:16 +000026
Simon Glassed38aef2020-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 Andersond3e7e202022-12-12 14:12:11 -050032 const char *fit_uname = NULL, *confname = NULL;
wdenkd0dd1072002-10-20 17:17:16 +000033
Marian Balakowicz23b77a22008-03-12 10:33:00 +010034 /* Find script image */
wdenkd0dd1072002-10-20 17:17:16 +000035 if (argc < 2) {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020036 addr = CONFIG_SYS_LOAD_ADDR;
Simon Glass8f055af2020-05-10 11:40:04 -060037 debug("* source: default load address = 0x%08lx\n", addr);
Marian Balakowicz23b77a22008-03-12 10:33:00 +010038#if defined(CONFIG_FIT)
Simon Glass892265d2019-12-28 10:45:02 -070039 } else if (fit_parse_subimage(argv[1], image_load_addr, &addr,
40 &fit_uname)) {
Simon Glass8f055af2020-05-10 11:40:04 -060041 debug("* source: subimage '%s' from FIT image at 0x%08lx\n",
42 fit_uname, addr);
Sean Andersond3e7e202022-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 Balakowicz23b77a22008-03-12 10:33:00 +010046#endif
wdenkd0dd1072002-10-20 17:17:16 +000047 } else {
Simon Glass3ff49ec2021-07-24 09:03:29 -060048 addr = hextoul(argv[1], NULL);
Simon Glass8f055af2020-05-10 11:40:04 -060049 debug("* source: cmdline image address = 0x%08lx\n", addr);
wdenkd0dd1072002-10-20 17:17:16 +000050 }
51
Marian Balakowicz23b77a22008-03-12 10:33:00 +010052 printf ("## Executing script at %08lx\n", addr);
Simon Glassdaee3ba2023-01-06 08:52:28 -060053 rcode = cmd_source_script(addr, fit_uname, confname);
wdenkd0dd1072002-10-20 17:17:16 +000054 return rcode;
55}
wdenk57b2d802003-06-27 21:31:46 +000056
Tom Rini03f146c2023-10-07 15:13:08 -040057U_BOOT_LONGHELP(source,
Marian Balakowicz23b77a22008-03-12 10:33:00 +010058#if defined(CONFIG_FIT)
Sean Andersond3e7e202022-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 Rini03f146c2023-10-07 15:13:08 -040063 "\t default is used."
Sean Andersond3e7e202022-12-12 14:12:11 -050064#else
65 "[<addr>]\n"
Tom Rini03f146c2023-10-07 15:13:08 -040066 "\t- Run script starting at addr"
Kim Phillipsdc00a682012-10-29 13:34:31 +000067#endif
Tom Rini03f146c2023-10-07 15:13:08 -040068 );
Kim Phillipsdc00a682012-10-29 13:34:31 +000069
70U_BOOT_CMD(
71 source, 2, 0, do_source,
72 "run script from memory", source_help_text
Marian Balakowicz23b77a22008-03-12 10:33:00 +010073);