blob: c9b5f8e400a615c055979270774cd9bde3183a79 [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
wdenkd0dd1072002-10-20 17:17:16 +000017#include <command.h>
Simon Glassc301bd82019-08-01 09:46:49 -060018#include <env.h>
wdenkd0dd1072002-10-20 17:17:16 +000019#include <image.h>
Simon Glass0f2af882020-05-10 11:40:05 -060020#include <log.h>
wdenkd0dd1072002-10-20 17:17:16 +000021#include <malloc.h>
Joe Hershberger65b905b2015-03-22 17:08:59 -050022#include <mapmem.h>
wdenkd0dd1072002-10-20 17:17:16 +000023#include <asm/byteorder.h>
Simon Glass7e5581e2013-04-20 08:42:49 +000024#include <asm/io.h>
wdenkd0dd1072002-10-20 17:17:16 +000025
Simon Glassed38aef2020-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 Andersond3e7e202022-12-12 14:12:11 -050031 const char *fit_uname = NULL, *confname = NULL;
wdenkd0dd1072002-10-20 17:17:16 +000032
Marian Balakowicz23b77a22008-03-12 10:33:00 +010033 /* Find script image */
wdenkd0dd1072002-10-20 17:17:16 +000034 if (argc < 2) {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020035 addr = CONFIG_SYS_LOAD_ADDR;
Simon Glass8f055af2020-05-10 11:40:04 -060036 debug("* source: default load address = 0x%08lx\n", addr);
Marian Balakowicz23b77a22008-03-12 10:33:00 +010037#if defined(CONFIG_FIT)
Simon Glass892265d2019-12-28 10:45:02 -070038 } else if (fit_parse_subimage(argv[1], image_load_addr, &addr,
39 &fit_uname)) {
Simon Glass8f055af2020-05-10 11:40:04 -060040 debug("* source: subimage '%s' from FIT image at 0x%08lx\n",
41 fit_uname, addr);
Sean Andersond3e7e202022-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 Balakowicz23b77a22008-03-12 10:33:00 +010045#endif
wdenkd0dd1072002-10-20 17:17:16 +000046 } else {
Simon Glass3ff49ec2021-07-24 09:03:29 -060047 addr = hextoul(argv[1], NULL);
Simon Glass8f055af2020-05-10 11:40:04 -060048 debug("* source: cmdline image address = 0x%08lx\n", addr);
wdenkd0dd1072002-10-20 17:17:16 +000049 }
50
Marian Balakowicz23b77a22008-03-12 10:33:00 +010051 printf ("## Executing script at %08lx\n", addr);
Simon Glassdaee3ba2023-01-06 08:52:28 -060052 rcode = cmd_source_script(addr, fit_uname, confname);
wdenkd0dd1072002-10-20 17:17:16 +000053 return rcode;
54}
wdenk57b2d802003-06-27 21:31:46 +000055
Tom Rini03f146c2023-10-07 15:13:08 -040056U_BOOT_LONGHELP(source,
Marian Balakowicz23b77a22008-03-12 10:33:00 +010057#if defined(CONFIG_FIT)
Sean Andersond3e7e202022-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 Rini03f146c2023-10-07 15:13:08 -040062 "\t default is used."
Sean Andersond3e7e202022-12-12 14:12:11 -050063#else
64 "[<addr>]\n"
Tom Rini03f146c2023-10-07 15:13:08 -040065 "\t- Run script starting at addr"
Kim Phillipsdc00a682012-10-29 13:34:31 +000066#endif
Tom Rini03f146c2023-10-07 15:13:08 -040067 );
Kim Phillipsdc00a682012-10-29 13:34:31 +000068
69U_BOOT_CMD(
70 source, 2, 0, do_source,
71 "run script from memory", source_help_text
Marian Balakowicz23b77a22008-03-12 10:33:00 +010072);