summaryrefslogtreecommitdiff
path: root/common/cmd_autoscript.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/cmd_autoscript.c')
-rw-r--r--common/cmd_autoscript.c76
1 files changed, 39 insertions, 37 deletions
diff --git a/common/cmd_autoscript.c b/common/cmd_autoscript.c
index a6038a6..f9ab1d9 100644
--- a/common/cmd_autoscript.c
+++ b/common/cmd_autoscript.c
@@ -49,57 +49,59 @@
#if defined(CONFIG_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)
-extern image_header_t header; /* from cmd_bootm.c */
int
autoscript (ulong addr)
{
- ulong crc, data, len;
- image_header_t *hdr = &header;
- ulong *len_ptr;
+ ulong len;
+ image_header_t *hdr;
+ ulong *data;
char *cmd;
int rcode = 0;
int verify;
- cmd = getenv ("verify");
- verify = (cmd && (*cmd == 'n')) ? 0 : 1;
+ verify = getenv_verify ();
+ switch (gen_image_get_format ((void *)addr)) {
+ case IMAGE_FORMAT_LEGACY:
+ hdr = (image_header_t *)addr;
- memmove (hdr, (char *)addr, sizeof(image_header_t));
-
- if (ntohl(hdr->ih_magic) != IH_MAGIC) {
- puts ("Bad magic number\n");
- return 1;
- }
+ if (!image_check_magic (hdr)) {
+ puts ("Bad magic number\n");
+ return 1;
+ }
- crc = ntohl(hdr->ih_hcrc);
- hdr->ih_hcrc = 0;
- len = sizeof (image_header_t);
- data = (ulong)hdr;
- if (crc32(0, (uchar *)data, len) != crc) {
- puts ("Bad header crc\n");
- return 1;
- }
+ if (!image_check_hcrc (hdr)) {
+ puts ("Bad header crc\n");
+ return 1;
+ }
- data = addr + sizeof(image_header_t);
- len = ntohl(hdr->ih_size);
+ if (verify) {
+ if (!image_check_dcrc (hdr)) {
+ puts ("Bad data crc\n");
+ return 1;
+ }
+ }
- if (verify) {
- if (crc32(0, (uchar *)data, len) != ntohl(hdr->ih_dcrc)) {
- puts ("Bad data crc\n");
+ if (!image_check_type (hdr, IH_TYPE_SCRIPT)) {
+ puts ("Bad image type\n");
return 1;
}
- }
-
- if (hdr->ih_type != IH_TYPE_SCRIPT) {
- puts ("Bad image type\n");
- return 1;
- }
- /* get length of script */
- len_ptr = (ulong *)data;
+ /* get length of script */
+ data = (ulong *)image_get_data (hdr);
- if ((len = ntohl(*len_ptr)) == 0) {
- puts ("Empty Script\n");
+ if ((len = image_to_cpu (*data)) == 0) {
+ puts ("Empty Script\n");
+ return 1;
+ }
+ break;
+#if defined(CONFIG_FIT)
+ case IMAGE_FORMAT_FIT:
+ fit_unsupported ("autoscript");
+ return 1;
+#endif
+ default:
+ puts ("Wrong image format for autoscript\n");
return 1;
}
@@ -109,10 +111,10 @@ autoscript (ulong addr)
return 1;
}
- while (*len_ptr++);
+ while (*data++);
/* make sure cmd is null terminated */
- memmove (cmd, (char *)len_ptr, len);
+ memmove (cmd, (char *)data, len);
*(cmd + len) = 0;
#ifdef CFG_HUSH_PARSER /*?? */