2002-10-20 17:17:16 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2001
|
|
|
|
* Kyle Harris, kharris@nexus-tech.net
|
|
|
|
*
|
|
|
|
* See file CREDITS for list of people who contributed to this
|
|
|
|
* project.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* autoscript allows a remote host to download a command file and,
|
|
|
|
* optionally, binary data for automatically updating the target. For
|
|
|
|
* example, you create a new kernel image and want the user to be
|
|
|
|
* able to simply download the image and the machine does the rest.
|
|
|
|
* The kernel image is postprocessed with mkimage, which creates an
|
|
|
|
* image with a script file prepended. If enabled, autoscript will
|
|
|
|
* verify the script and contents of the download and execute the
|
|
|
|
* script portion. This would be responsible for erasing flash,
|
|
|
|
* copying the new image, and rebooting the machine.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* #define DEBUG */
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <command.h>
|
|
|
|
#include <image.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
#include <asm/byteorder.h>
|
|
|
|
#if defined(CONFIG_8xx)
|
|
|
|
#include <mpc8xx.h>
|
|
|
|
#endif
|
|
|
|
#ifdef CFG_HUSH_PARSER
|
|
|
|
#include <hush.h>
|
|
|
|
#endif
|
|
|
|
|
2007-07-08 22:51:39 +00:00
|
|
|
#if defined(CONFIG_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)
|
2002-10-20 17:17:16 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
autoscript (ulong addr)
|
|
|
|
{
|
2008-01-08 17:14:09 +00:00
|
|
|
ulong len;
|
|
|
|
image_header_t *hdr = (image_header_t *)addr;
|
2008-01-08 17:12:17 +00:00
|
|
|
ulong *data;
|
2002-10-20 17:17:16 +00:00
|
|
|
char *cmd;
|
|
|
|
int rcode = 0;
|
|
|
|
int verify;
|
|
|
|
|
2008-01-08 17:14:09 +00:00
|
|
|
verify = getenv_verify ();
|
2002-10-20 17:17:16 +00:00
|
|
|
|
2008-01-08 17:14:09 +00:00
|
|
|
if (!image_check_magic (hdr)) {
|
2004-03-23 22:14:11 +00:00
|
|
|
puts ("Bad magic number\n");
|
2002-10-20 17:17:16 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-01-08 17:14:09 +00:00
|
|
|
if (!image_check_hcrc (hdr)) {
|
2004-03-23 22:14:11 +00:00
|
|
|
puts ("Bad header crc\n");
|
2002-10-20 17:17:16 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (verify) {
|
2008-01-08 17:14:09 +00:00
|
|
|
if (!image_check_dcrc (hdr)) {
|
2004-03-23 22:14:11 +00:00
|
|
|
puts ("Bad data crc\n");
|
2002-10-20 17:17:16 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-08 17:14:09 +00:00
|
|
|
if (!image_check_type (hdr, IH_TYPE_SCRIPT)) {
|
2004-03-23 22:14:11 +00:00
|
|
|
puts ("Bad image type\n");
|
2002-10-20 17:17:16 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get length of script */
|
2008-01-08 17:12:17 +00:00
|
|
|
data = (ulong *)image_get_data (hdr);
|
2002-10-20 17:17:16 +00:00
|
|
|
|
2008-01-08 17:12:17 +00:00
|
|
|
if ((len = image_to_cpu (*data)) == 0) {
|
2004-03-23 22:14:11 +00:00
|
|
|
puts ("Empty Script\n");
|
2002-10-20 17:17:16 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-11-03 18:03:52 +00:00
|
|
|
debug ("** Script length: %ld\n", len);
|
2002-10-20 17:17:16 +00:00
|
|
|
|
|
|
|
if ((cmd = malloc (len + 1)) == NULL) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-01-08 17:12:17 +00:00
|
|
|
while (*data++);
|
2002-10-20 17:17:16 +00:00
|
|
|
|
|
|
|
/* make sure cmd is null terminated */
|
2008-01-08 17:12:17 +00:00
|
|
|
memmove (cmd, (char *)data, len);
|
2002-10-20 17:17:16 +00:00
|
|
|
*(cmd + len) = 0;
|
|
|
|
|
2003-06-27 21:31:46 +00:00
|
|
|
#ifdef CFG_HUSH_PARSER /*?? */
|
2002-10-20 17:17:16 +00:00
|
|
|
rcode = parse_string_outer (cmd, FLAG_PARSE_SEMICOLON);
|
|
|
|
#else
|
|
|
|
{
|
|
|
|
char *line = cmd;
|
|
|
|
char *next = cmd;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* break into individual lines,
|
|
|
|
* and execute each line;
|
|
|
|
* terminate on error.
|
|
|
|
*/
|
|
|
|
while (*next) {
|
|
|
|
if (*next == '\n') {
|
|
|
|
*next = '\0';
|
|
|
|
/* run only non-empty commands */
|
|
|
|
if ((next - line) > 1) {
|
|
|
|
debug ("** exec: \"%s\"\n",
|
|
|
|
line);
|
|
|
|
if (run_command (line, 0) < 0) {
|
|
|
|
rcode = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
line = next + 1;
|
|
|
|
}
|
|
|
|
++next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
free (cmd);
|
|
|
|
return rcode;
|
|
|
|
}
|
|
|
|
|
2007-07-10 16:02:44 +00:00
|
|
|
#endif
|
|
|
|
|
2003-06-27 21:31:46 +00:00
|
|
|
/**************************************************/
|
2007-07-08 22:51:39 +00:00
|
|
|
#if defined(CONFIG_CMD_AUTOSCRIPT)
|
2002-10-20 17:17:16 +00:00
|
|
|
int
|
|
|
|
do_autoscript (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
|
|
|
|
{
|
|
|
|
ulong addr;
|
|
|
|
int rcode;
|
|
|
|
|
|
|
|
if (argc < 2) {
|
|
|
|
addr = CFG_LOAD_ADDR;
|
|
|
|
} else {
|
|
|
|
addr = simple_strtoul (argv[1],0,16);
|
|
|
|
}
|
|
|
|
|
|
|
|
printf ("## Executing script at %08lx\n",addr);
|
|
|
|
rcode = autoscript (addr);
|
|
|
|
return rcode;
|
|
|
|
}
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2007-07-08 22:51:39 +00:00
|
|
|
#if defined(CONFIG_CMD_AUTOSCRIPT)
|
2003-07-01 21:06:45 +00:00
|
|
|
U_BOOT_CMD(
|
|
|
|
autoscr, 2, 0, do_autoscript,
|
2003-06-27 21:31:46 +00:00
|
|
|
"autoscr - run script from memory\n",
|
|
|
|
"[addr] - run script starting at addr"
|
|
|
|
" - A valid autoscr header must be present\n"
|
|
|
|
);
|
2007-07-10 16:02:44 +00:00
|
|
|
#endif
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2007-07-10 16:02:44 +00:00
|
|
|
#endif
|