Tom Rini | 10e4779 | 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 | 85c25df | 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 | |
| 17 | #include <common.h> |
| 18 | #include <command.h> |
Simon Glass | c301bd8 | 2019-08-01 09:46:49 -0600 | [diff] [blame] | 19 | #include <env.h> |
wdenk | d0dd107 | 2002-10-20 17:17:16 +0000 | [diff] [blame] | 20 | #include <image.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 21 | #include <log.h> |
wdenk | d0dd107 | 2002-10-20 17:17:16 +0000 | [diff] [blame] | 22 | #include <malloc.h> |
Joe Hershberger | 65b905b | 2015-03-22 17:08:59 -0500 | [diff] [blame] | 23 | #include <mapmem.h> |
wdenk | d0dd107 | 2002-10-20 17:17:16 +0000 | [diff] [blame] | 24 | #include <asm/byteorder.h> |
Simon Glass | 7e5581e | 2013-04-20 08:42:49 +0000 | [diff] [blame] | 25 | #include <asm/io.h> |
wdenk | d0dd107 | 2002-10-20 17:17:16 +0000 | [diff] [blame] | 26 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 27 | static int do_source(struct cmd_tbl *cmdtp, int flag, int argc, |
| 28 | char *const argv[]) |
wdenk | d0dd107 | 2002-10-20 17:17:16 +0000 | [diff] [blame] | 29 | { |
| 30 | ulong addr; |
| 31 | int rcode; |
Sean Anderson | d3e7e20 | 2022-12-12 14:12:11 -0500 | [diff] [blame] | 32 | const char *fit_uname = NULL, *confname = NULL; |
wdenk | d0dd107 | 2002-10-20 17:17:16 +0000 | [diff] [blame] | 33 | |
Marian Balakowicz | 23b77a2 | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 34 | /* Find script image */ |
wdenk | d0dd107 | 2002-10-20 17:17:16 +0000 | [diff] [blame] | 35 | if (argc < 2) { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 36 | addr = CONFIG_SYS_LOAD_ADDR; |
Simon Glass | 8f055af | 2020-05-10 11:40:04 -0600 | [diff] [blame] | 37 | debug("* source: default load address = 0x%08lx\n", addr); |
Marian Balakowicz | 23b77a2 | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 38 | #if defined(CONFIG_FIT) |
Simon Glass | 892265d | 2019-12-28 10:45:02 -0700 | [diff] [blame] | 39 | } else if (fit_parse_subimage(argv[1], image_load_addr, &addr, |
| 40 | &fit_uname)) { |
Simon Glass | 8f055af | 2020-05-10 11:40:04 -0600 | [diff] [blame] | 41 | debug("* source: subimage '%s' from FIT image at 0x%08lx\n", |
| 42 | fit_uname, addr); |
Sean Anderson | d3e7e20 | 2022-12-12 14:12:11 -0500 | [diff] [blame] | 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); |
Marian Balakowicz | 23b77a2 | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 46 | #endif |
wdenk | d0dd107 | 2002-10-20 17:17:16 +0000 | [diff] [blame] | 47 | } else { |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 48 | addr = hextoul(argv[1], NULL); |
Simon Glass | 8f055af | 2020-05-10 11:40:04 -0600 | [diff] [blame] | 49 | debug("* source: cmdline image address = 0x%08lx\n", addr); |
wdenk | d0dd107 | 2002-10-20 17:17:16 +0000 | [diff] [blame] | 50 | } |
| 51 | |
Marian Balakowicz | 23b77a2 | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 52 | printf ("## Executing script at %08lx\n", addr); |
Simon Glass | daee3ba | 2023-01-06 08:52:28 -0600 | [diff] [blame] | 53 | rcode = cmd_source_script(addr, fit_uname, confname); |
wdenk | d0dd107 | 2002-10-20 17:17:16 +0000 | [diff] [blame] | 54 | return rcode; |
| 55 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 56 | |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 57 | #ifdef CONFIG_SYS_LONGHELP |
| 58 | static char source_help_text[] = |
Marian Balakowicz | 23b77a2 | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 59 | #if defined(CONFIG_FIT) |
Sean Anderson | d3e7e20 | 2022-12-12 14:12:11 -0500 | [diff] [blame] | 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"; |
Jon Loeliger | d704d91 | 2007-07-10 11:02:44 -0500 | [diff] [blame] | 68 | #endif |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 69 | #endif |
| 70 | |
| 71 | U_BOOT_CMD( |
| 72 | source, 2, 0, do_source, |
| 73 | "run script from memory", source_help_text |
Marian Balakowicz | 23b77a2 | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 74 | ); |