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