Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | d0dd107 | 2002-10-20 17:17:16 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2001 |
| 4 | * Kyle Harris, kharris@nexus-tech.net |
wdenk | d0dd107 | 2002-10-20 17:17:16 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | /* |
Wolfgang Denk | 74de7ae | 2009-04-01 23:34:12 +0200 | [diff] [blame] | 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. |
wdenk | d0dd107 | 2002-10-20 17:17:16 +0000 | [diff] [blame] | 13 | */ |
| 14 | |
| 15 | /* #define DEBUG */ |
| 16 | |
wdenk | d0dd107 | 2002-10-20 17:17:16 +0000 | [diff] [blame] | 17 | #include <command.h> |
Simon Glass | 6bf6dbe | 2019-08-01 09:46:49 -0600 | [diff] [blame] | 18 | #include <env.h> |
wdenk | d0dd107 | 2002-10-20 17:17:16 +0000 | [diff] [blame] | 19 | #include <image.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 20 | #include <log.h> |
wdenk | d0dd107 | 2002-10-20 17:17:16 +0000 | [diff] [blame] | 21 | #include <malloc.h> |
Joe Hershberger | 0eb25b6 | 2015-03-22 17:08:59 -0500 | [diff] [blame] | 22 | #include <mapmem.h> |
wdenk | d0dd107 | 2002-10-20 17:17:16 +0000 | [diff] [blame] | 23 | #include <asm/byteorder.h> |
Simon Glass | 4ca30d6 | 2013-04-20 08:42:49 +0000 | [diff] [blame] | 24 | #include <asm/io.h> |
wdenk | d0dd107 | 2002-10-20 17:17:16 +0000 | [diff] [blame] | 25 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 26 | static int do_source(struct cmd_tbl *cmdtp, int flag, int argc, |
| 27 | char *const argv[]) |
wdenk | d0dd107 | 2002-10-20 17:17:16 +0000 | [diff] [blame] | 28 | { |
| 29 | ulong addr; |
| 30 | int rcode; |
Sean Anderson | bcc85b9 | 2022-12-12 14:12:11 -0500 | [diff] [blame] | 31 | const char *fit_uname = NULL, *confname = NULL; |
wdenk | d0dd107 | 2002-10-20 17:17:16 +0000 | [diff] [blame] | 32 | |
Marian Balakowicz | 424c4ab | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 33 | /* Find script image */ |
wdenk | d0dd107 | 2002-10-20 17:17:16 +0000 | [diff] [blame] | 34 | if (argc < 2) { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 35 | addr = CONFIG_SYS_LOAD_ADDR; |
Simon Glass | 3c7dded | 2020-05-10 11:40:04 -0600 | [diff] [blame] | 36 | debug("* source: default load address = 0x%08lx\n", addr); |
Marian Balakowicz | 424c4ab | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 37 | #if defined(CONFIG_FIT) |
Simon Glass | bb872dd | 2019-12-28 10:45:02 -0700 | [diff] [blame] | 38 | } else if (fit_parse_subimage(argv[1], image_load_addr, &addr, |
| 39 | &fit_uname)) { |
Simon Glass | 3c7dded | 2020-05-10 11:40:04 -0600 | [diff] [blame] | 40 | debug("* source: subimage '%s' from FIT image at 0x%08lx\n", |
| 41 | fit_uname, addr); |
Sean Anderson | bcc85b9 | 2022-12-12 14:12:11 -0500 | [diff] [blame] | 42 | } 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 Balakowicz | 424c4ab | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 45 | #endif |
wdenk | d0dd107 | 2002-10-20 17:17:16 +0000 | [diff] [blame] | 46 | } else { |
Simon Glass | 7e5f460 | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 47 | addr = hextoul(argv[1], NULL); |
Simon Glass | 3c7dded | 2020-05-10 11:40:04 -0600 | [diff] [blame] | 48 | debug("* source: cmdline image address = 0x%08lx\n", addr); |
wdenk | d0dd107 | 2002-10-20 17:17:16 +0000 | [diff] [blame] | 49 | } |
| 50 | |
Marian Balakowicz | 424c4ab | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 51 | printf ("## Executing script at %08lx\n", addr); |
Simon Glass | 30f3333 | 2023-01-06 08:52:28 -0600 | [diff] [blame] | 52 | rcode = cmd_source_script(addr, fit_uname, confname); |
wdenk | d0dd107 | 2002-10-20 17:17:16 +0000 | [diff] [blame] | 53 | return rcode; |
| 54 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 55 | |
Tom Rini | 3616218 | 2023-10-07 15:13:08 -0400 | [diff] [blame] | 56 | U_BOOT_LONGHELP(source, |
Marian Balakowicz | 424c4ab | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 57 | #if defined(CONFIG_FIT) |
Sean Anderson | bcc85b9 | 2022-12-12 14:12:11 -0500 | [diff] [blame] | 58 | "[<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 Rini | 3616218 | 2023-10-07 15:13:08 -0400 | [diff] [blame] | 62 | "\t default is used." |
Sean Anderson | bcc85b9 | 2022-12-12 14:12:11 -0500 | [diff] [blame] | 63 | #else |
| 64 | "[<addr>]\n" |
Tom Rini | 3616218 | 2023-10-07 15:13:08 -0400 | [diff] [blame] | 65 | "\t- Run script starting at addr" |
Jon Loeliger | 9025317 | 2007-07-10 11:02:44 -0500 | [diff] [blame] | 66 | #endif |
Tom Rini | 3616218 | 2023-10-07 15:13:08 -0400 | [diff] [blame] | 67 | ); |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 68 | |
| 69 | U_BOOT_CMD( |
| 70 | source, 2, 0, do_source, |
| 71 | "run script from memory", source_help_text |
Marian Balakowicz | 424c4ab | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 72 | ); |