]> git.sur5r.net Git - u-boot/blobdiff - board/mpl/common/common_util.c
Merge branch 'new-image' of git://www.denx.de/git/u-boot-testing
[u-boot] / board / mpl / common / common_util.c
index 8d4cbe852e95e526f8051099e57290c3fce3692a..785d20469640b7b1b6552c67345a62397e951725 100644 (file)
@@ -57,9 +57,6 @@ extern int mem_test(ulong start, ulong ramsize, int quiet);
 
 extern flash_info_t flash_info[];      /* info for FLASH chips */
 
-static image_header_t header;
-
-
 static int
 mpl_prg(uchar *src, ulong size)
 {
@@ -77,7 +74,7 @@ mpl_prg(uchar *src, ulong size)
        info = &flash_info[0];
 
 #if defined(CONFIG_PIP405) || defined(CONFIG_MIP405) || defined(CONFIG_PATI)
-       if (ntohl(magic[0]) != IH_MAGIC) {
+       if (uimage_to_cpu (magic[0]) != IH_MAGIC) {
                puts("Bad Magic number\n");
                return -1;
        }
@@ -179,44 +176,46 @@ mpl_prg(uchar *src, ulong size)
 static int
 mpl_prg_image(uchar *ld_addr)
 {
-       unsigned long len, checksum;
+       unsigned long len;
        uchar *data;
-       image_header_t *hdr = &header;
+       image_header_t *hdr = (image_header_t *)ld_addr;
        int rc;
 
-       /* Copy header so we can blank CRC field for re-calculation */
-       memcpy (&header, (char *)ld_addr, sizeof(image_header_t));
-       if (ntohl(hdr->ih_magic)  != IH_MAGIC) {
+#if defined(CONFIG_FIT)
+       if (genimg_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) {
+               puts ("Non legacy image format not supported\n");
+               return -1;
+       }
+#endif
+
+       if (!image_check_magic (hdr)) {
                puts("Bad Magic Number\n");
                return 1;
        }
-       print_image_hdr(hdr);
-       if (hdr->ih_os  != IH_OS_U_BOOT) {
+       image_print_contents (hdr);
+       if (!image_check_os (hdr, IH_OS_U_BOOT)) {
                puts("No U-Boot Image\n");
                return 1;
        }
-       if (hdr->ih_type  != IH_TYPE_FIRMWARE) {
+       if (!image_check_type (hdr, IH_TYPE_FIRMWARE)) {
                puts("No Firmware Image\n");
                return 1;
        }
-       data = (uchar *)&header;
-       len  = sizeof(image_header_t);
-       checksum = ntohl(hdr->ih_hcrc);
-       hdr->ih_hcrc = 0;
-       if (crc32 (0, (uchar *)data, len) != checksum) {
+       if (!image_check_hcrc (hdr)) {
                puts("Bad Header Checksum\n");
                return 1;
        }
-       data = ld_addr + sizeof(image_header_t);
-       len  = ntohl(hdr->ih_size);
        puts("Verifying Checksum ... ");
-       if (crc32 (0, (uchar *)data, len) != ntohl(hdr->ih_dcrc)) {
+       if (!image_check_dcrc (hdr)) {
                puts("Bad Data CRC\n");
                return 1;
        }
        puts("OK\n");
 
-       if (hdr->ih_comp != IH_COMP_NONE) {
+       data = (uchar *)image_get_data (hdr);
+       len = image_get_data_size (hdr);
+
+       if (image_get_comp (hdr) != IH_COMP_NONE) {
                uchar *buf;
                /* reserve space for uncompressed image */
                if ((buf = malloc(IMAGE_SIZE)) == NULL) {
@@ -224,7 +223,7 @@ mpl_prg_image(uchar *ld_addr)
                        return 1;
                }
 
-               switch (hdr->ih_comp) {
+               switch (image_get_comp (hdr)) {
                case IH_COMP_GZIP:
                        puts("Uncompressing (GZIP) ... ");
                        rc = gunzip ((void *)(buf), IMAGE_SIZE, data, &len);
@@ -253,7 +252,8 @@ mpl_prg_image(uchar *ld_addr)
                        break;
 #endif
                default:
-                       printf ("Unimplemented compression type %d\n", hdr->ih_comp);
+                       printf ("Unimplemented compression type %d\n",
+                               image_get_comp (hdr));
                        free(buf);
                        return 1;
                }