blob: 92c7835bf50e25826610d49e6f02fc648c39084b [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
Kim Phillipsdc00a682012-10-29 13:34:31 +000057#ifdef CONFIG_SYS_LONGHELP
58static char source_help_text[] =
Marian Balakowicz23b77a22008-03-12 10:33:00 +010059#if defined(CONFIG_FIT)
Sean Andersond3e7e202022-12-12 14:12:11 -050060 "[<addr>][:[<image>]|#[<config>]]\n"
61 "\t- Run script starting at addr\n"
62 "\t- A FIT config name or subimage name may be specified with : or #\n"
63 "\t (like bootm). If the image or config name is omitted, the\n"
64 "\t default is used.";
65#else
66 "[<addr>]\n"
67 "\t- Run script starting at addr";
Jon Loeligerd704d912007-07-10 11:02:44 -050068#endif
Kim Phillipsdc00a682012-10-29 13:34:31 +000069#endif
70
71U_BOOT_CMD(
72 source, 2, 0, do_source,
73 "run script from memory", source_help_text
Marian Balakowicz23b77a22008-03-12 10:33:00 +010074);