Blame view
cmd/source.c
4.06 KB
d0dd10777 Initial revision |
1 2 3 4 |
/* * (C) Copyright 2001 * Kyle Harris, kharris@nexus-tech.net * |
1a4596601 Add GPL-2.0+ SPDX... |
5 |
* SPDX-License-Identifier: GPL-2.0+ |
d0dd10777 Initial revision |
6 7 8 |
*/ /* |
74de7aefd Add "source" comm... |
9 10 11 12 13 |
* The "source" command allows to define "script images", i. e. files * that contain command sequences that can be executed by the command * interpreter. It returns the exit status of the last command * executed from the script. This is very similar to running a shell * script in a UNIX shell, hence the name for the command. |
d0dd10777 Initial revision |
14 15 16 17 18 19 20 21 |
*/ /* #define DEBUG */ #include <common.h> #include <command.h> #include <image.h> #include <malloc.h> |
0eb25b619 common: Make sure... |
22 |
#include <mapmem.h> |
d0dd10777 Initial revision |
23 |
#include <asm/byteorder.h> |
4ca30d602 sandbox: Support ... |
24 |
#include <asm/io.h> |
d0dd10777 Initial revision |
25 26 27 |
#if defined(CONFIG_8xx) #include <mpc8xx.h> #endif |
d0dd10777 Initial revision |
28 |
|
d0dd10777 Initial revision |
29 |
int |
74de7aefd Add "source" comm... |
30 |
source (ulong addr, const char *fit_uname) |
d0dd10777 Initial revision |
31 |
{ |
53677ef18 Big white-space c... |
32 |
ulong len; |
21d29f7f9 bootm: make use o... |
33 |
#if defined(CONFIG_IMAGE_FORMAT_LEGACY) |
4ca30d602 sandbox: Support ... |
34 |
const image_header_t *hdr; |
21d29f7f9 bootm: make use o... |
35 |
#endif |
210fbee90 common/cmd_source... |
36 |
u32 *data; |
424c4abdd [new uImage] Add ... |
37 |
int verify; |
4ca30d602 sandbox: Support ... |
38 |
void *buf; |
424c4abdd [new uImage] Add ... |
39 40 41 42 43 44 |
#if defined(CONFIG_FIT) const void* fit_hdr; int noffset; const void *fit_data; size_t fit_len; #endif |
d0dd10777 Initial revision |
45 |
|
edbed247a Memory footprint ... |
46 |
verify = getenv_yesno ("verify"); |
d0dd10777 Initial revision |
47 |
|
4ca30d602 sandbox: Support ... |
48 49 |
buf = map_sysmem(addr, 0); switch (genimg_get_format(buf)) { |
21d29f7f9 bootm: make use o... |
50 |
#if defined(CONFIG_IMAGE_FORMAT_LEGACY) |
d5934ad77 [new uImage] Add ... |
51 |
case IMAGE_FORMAT_LEGACY: |
4ca30d602 sandbox: Support ... |
52 |
hdr = buf; |
d0dd10777 Initial revision |
53 |
|
d5934ad77 [new uImage] Add ... |
54 55 56 57 58 |
if (!image_check_magic (hdr)) { puts ("Bad magic number "); return 1; } |
d0dd10777 Initial revision |
59 |
|
d5934ad77 [new uImage] Add ... |
60 61 62 |
if (!image_check_hcrc (hdr)) { puts ("Bad header crc "); |
d0dd10777 Initial revision |
63 64 |
return 1; } |
d0dd10777 Initial revision |
65 |
|
d5934ad77 [new uImage] Add ... |
66 67 68 69 70 71 72 73 74 75 76 77 78 |
if (verify) { if (!image_check_dcrc (hdr)) { puts ("Bad data crc "); return 1; } } if (!image_check_type (hdr, IH_TYPE_SCRIPT)) { puts ("Bad image type "); return 1; } |
d0dd10777 Initial revision |
79 |
|
d5934ad77 [new uImage] Add ... |
80 |
/* get length of script */ |
210fbee90 common/cmd_source... |
81 |
data = (u32 *)image_get_data (hdr); |
d0dd10777 Initial revision |
82 |
|
9a4daad0a [new uImage] Upda... |
83 |
if ((len = uimage_to_cpu (*data)) == 0) { |
d5934ad77 [new uImage] Add ... |
84 85 86 87 |
puts ("Empty Script "); return 1; } |
36cc8cbb3 [new uImage] Fix ... |
88 89 90 91 92 93 94 |
/* * scripts are just multi-image files with one component, seek * past the zero-terminated sequence of image lengths to get * to the actual image data */ while (*data++); |
d5934ad77 [new uImage] Add ... |
95 |
break; |
21d29f7f9 bootm: make use o... |
96 |
#endif |
d5934ad77 [new uImage] Add ... |
97 98 |
#if defined(CONFIG_FIT) case IMAGE_FORMAT_FIT: |
424c4abdd [new uImage] Add ... |
99 100 101 102 103 |
if (fit_uname == NULL) { puts ("No FIT subimage unit name "); return 1; } |
4ca30d602 sandbox: Support ... |
104 |
fit_hdr = buf; |
424c4abdd [new uImage] Add ... |
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
if (!fit_check_format (fit_hdr)) { puts ("Bad FIT image format "); return 1; } /* get script component image node offset */ noffset = fit_image_get_node (fit_hdr, fit_uname); if (noffset < 0) { printf ("Can't find '%s' FIT subimage ", fit_uname); return 1; } if (!fit_image_check_type (fit_hdr, noffset, IH_TYPE_SCRIPT)) { puts ("Not a image image "); return 1; } /* verify integrity */ if (verify) { |
b8da83665 image: Rename fit... |
127 |
if (!fit_image_verify(fit_hdr, noffset)) { |
424c4abdd [new uImage] Add ... |
128 129 130 131 132 133 134 135 136 137 138 139 |
puts ("Bad Data Hash "); return 1; } } /* get script subimage data address and length */ if (fit_image_get_data (fit_hdr, noffset, &fit_data, &fit_len)) { puts ("Could not find script subimage data "); return 1; } |
210fbee90 common/cmd_source... |
140 |
data = (u32 *)fit_data; |
424c4abdd [new uImage] Add ... |
141 142 |
len = (ulong)fit_len; break; |
d5934ad77 [new uImage] Add ... |
143 144 |
#endif default: |
74de7aefd Add "source" comm... |
145 146 |
puts ("Wrong image format for \"source\" command "); |
d0dd10777 Initial revision |
147 148 |
return 1; } |
699b13a60 * Fix mdelay() on... |
149 150 |
debug ("** Script length: %ld ", len); |
d51004a83 Add run_command_l... |
151 |
return run_command_list((char *)data, len, 0); |
d0dd10777 Initial revision |
152 |
} |
8bde7f776 * Code cleanup: |
153 |
/**************************************************/ |
74de7aefd Add "source" comm... |
154 |
#if defined(CONFIG_CMD_SOURCE) |
0e350f81e common: commands:... |
155 |
static int do_source(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
d0dd10777 Initial revision |
156 157 158 |
{ ulong addr; int rcode; |
424c4abdd [new uImage] Add ... |
159 |
const char *fit_uname = NULL; |
d0dd10777 Initial revision |
160 |
|
424c4abdd [new uImage] Add ... |
161 |
/* Find script image */ |
d0dd10777 Initial revision |
162 |
if (argc < 2) { |
6d0f6bcf3 rename CFG_ macro... |
163 |
addr = CONFIG_SYS_LOAD_ADDR; |
74de7aefd Add "source" comm... |
164 165 |
debug ("* source: default load address = 0x%08lx ", addr); |
424c4abdd [new uImage] Add ... |
166 167 |
#if defined(CONFIG_FIT) } else if (fit_parse_subimage (argv[1], load_addr, &addr, &fit_uname)) { |
74de7aefd Add "source" comm... |
168 169 |
debug ("* source: subimage '%s' from FIT image at 0x%08lx ", |
424c4abdd [new uImage] Add ... |
170 171 |
fit_uname, addr); #endif |
d0dd10777 Initial revision |
172 |
} else { |
424c4abdd [new uImage] Add ... |
173 |
addr = simple_strtoul(argv[1], NULL, 16); |
74de7aefd Add "source" comm... |
174 175 |
debug ("* source: cmdline image address = 0x%08lx ", addr); |
d0dd10777 Initial revision |
176 |
} |
424c4abdd [new uImage] Add ... |
177 178 |
printf ("## Executing script at %08lx ", addr); |
74de7aefd Add "source" comm... |
179 |
rcode = source (addr, fit_uname); |
d0dd10777 Initial revision |
180 181 |
return rcode; } |
8bde7f776 * Code cleanup: |
182 |
|
088f1b199 common/cmd_*.c: s... |
183 184 |
#ifdef CONFIG_SYS_LONGHELP static char source_help_text[] = |
74de7aefd Add "source" comm... |
185 186 187 188 |
"[addr] " "\t- run script starting at addr " |
a89c33db9 General help mess... |
189 |
"\t- A valid image header must be present" |
424c4abdd [new uImage] Add ... |
190 |
#if defined(CONFIG_FIT) |
a89c33db9 General help mess... |
191 192 |
" " |
424c4abdd [new uImage] Add ... |
193 194 |
"For FIT format uImage addr must include subimage " |
a89c33db9 General help mess... |
195 |
"unit name in the form of addr:<subimg_uname>" |
902531788 common/: Remove l... |
196 |
#endif |
088f1b199 common/cmd_*.c: s... |
197 198 199 200 201 202 |
""; #endif U_BOOT_CMD( source, 2, 0, do_source, "run script from memory", source_help_text |
424c4abdd [new uImage] Add ... |
203 |
); |
902531788 common/: Remove l... |
204 |
#endif |