1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * (C) Copyright 2001
4 * Kyle Harris, kharris@nexus-tech.net
5 */
6
7 /*
8 * 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.
13 */
14
15 /* #define DEBUG */
16
17 #include <common.h>
18 #include <command.h>
19 #include <env.h>
20 #include <image.h>
21 #include <log.h>
22 #include <malloc.h>
23 #include <mapmem.h>
24 #include <asm/byteorder.h>
25 #include <asm/io.h>
26
do_source(struct cmd_tbl * cmdtp,int flag,int argc,char * const argv[])27 static int do_source(struct cmd_tbl *cmdtp, int flag, int argc,
28 char *const argv[])
29 {
30 ulong addr;
31 int rcode;
32 const char *fit_uname = NULL, *confname = NULL;
33
34 /* Find script image */
35 if (argc < 2) {
36 addr = CONFIG_SYS_LOAD_ADDR;
37 debug("* source: default load address = 0x%08lx\n", addr);
38 #if defined(CONFIG_FIT)
39 } else if (fit_parse_subimage(argv[1], image_load_addr, &addr,
40 &fit_uname)) {
41 debug("* source: subimage '%s' from FIT image at 0x%08lx\n",
42 fit_uname, addr);
43 } 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);
46 #endif
47 } else {
48 addr = hextoul(argv[1], NULL);
49 debug("* source: cmdline image address = 0x%08lx\n", addr);
50 }
51
52 printf ("## Executing script at %08lx\n", addr);
53 rcode = cmd_source_script(addr, fit_uname, confname);
54 return rcode;
55 }
56
57 #ifdef CONFIG_SYS_LONGHELP
58 static char source_help_text[] =
59 #if defined(CONFIG_FIT)
60 "[<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";
68 #endif
69 #endif
70
71 U_BOOT_CMD(
72 source, 2, 0, do_source,
73 "run script from memory", source_help_text
74 );
75