3 * Kyle Harris, kharris@nexus-tech.net
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 * autoscript allows a remote host to download a command file and,
26 * optionally, binary data for automatically updating the target. For
27 * example, you create a new kernel image and want the user to be
28 * able to simply download the image and the machine does the rest.
29 * The kernel image is postprocessed with mkimage, which creates an
30 * image with a script file prepended. If enabled, autoscript will
31 * verify the script and contents of the download and execute the
32 * script portion. This would be responsible for erasing flash,
33 * copying the new image, and rebooting the machine.
42 #include <asm/byteorder.h>
43 #if defined(CONFIG_8xx)
46 #ifdef CFG_HUSH_PARSER
50 #if defined(CONFIG_AUTOSCRIPT) || \
51 (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT )
53 extern image_header_t header
; /* from cmd_bootm.c */
55 autoscript (ulong addr
)
58 image_header_t
*hdr
= &header
;
64 cmd
= getenv ("verify");
65 verify
= (cmd
&& (*cmd
== 'n')) ? 0 : 1;
68 memmove (hdr
, (char *)addr
, sizeof(image_header_t
));
70 if (ntohl(hdr
->ih_magic
) != IH_MAGIC
) {
71 puts ("Bad magic number\n");
75 crc
= ntohl(hdr
->ih_hcrc
);
77 len
= sizeof (image_header_t
);
79 if (crc32(0, (uchar
*)data
, len
) != crc
) {
80 puts ("Bad header crc\n");
84 data
= addr
+ sizeof(image_header_t
);
85 len
= ntohl(hdr
->ih_size
);
88 if (crc32(0, (uchar
*)data
, len
) != ntohl(hdr
->ih_dcrc
)) {
89 puts ("Bad data crc\n");
94 if (hdr
->ih_type
!= IH_TYPE_SCRIPT
) {
95 puts ("Bad image type\n");
99 /* get length of script */
100 len_ptr
= (ulong
*)data
;
102 if ((len
= ntohl(*len_ptr
)) == 0) {
103 puts ("Empty Script\n");
107 debug ("** Script length: %ld\n", len
);
109 if ((cmd
= malloc (len
+ 1)) == NULL
) {
115 /* make sure cmd is null terminated */
116 memmove (cmd
, (char *)len_ptr
, len
);
119 #ifdef CFG_HUSH_PARSER /*?? */
120 rcode
= parse_string_outer (cmd
, FLAG_PARSE_SEMICOLON
);
127 * break into individual lines,
128 * and execute each line;
129 * terminate on error.
134 /* run only non-empty commands */
135 if ((next
- line
) > 1) {
136 debug ("** exec: \"%s\"\n",
138 if (run_command (line
, 0) < 0) {
153 #endif /* CONFIG_AUTOSCRIPT || CFG_CMD_AUTOSCRIPT */
154 /**************************************************/
155 #if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
157 do_autoscript (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
163 addr
= CFG_LOAD_ADDR
;
165 addr
= simple_strtoul (argv
[1],0,16);
168 printf ("## Executing script at %08lx\n",addr
);
169 rcode
= autoscript (addr
);
173 #if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
175 autoscr
, 2, 0, do_autoscript
,
176 "autoscr - run script from memory\n",
177 "[addr] - run script starting at addr"
178 " - A valid autoscr header must be present\n"
180 #endif /* CFG_CMD_AUTOSCRIPT */
182 #endif /* CONFIG_AUTOSCRIPT || CFG_CMD_AUTOSCRIPT */