Merge with git://www.denx.de/git/u-boot.git
[platform/kernel/u-boot.git] / board / trab / auto_update.c
index 36fdf18..54d3645 100644 (file)
@@ -34,7 +34,7 @@
 
 #ifdef CONFIG_AUTO_UPDATE
 
-#ifndef CONFIG_USB_OHCI
+#ifndef CONFIG_USB_OHCI_NEW
 #error "must define CONFIG_USB_OHCI"
 #endif
 
@@ -46,8 +46,8 @@
 #error "must define CFG_HUSH_PARSER"
 #endif
 
-#if !(CONFIG_COMMANDS & CFG_CMD_FAT)
-#error "must define CFG_CMD_FAT"
+#if !defined(CONFIG_CMD_FAT)
+#error "must define CONFIG_CMD_FAT"
 #endif
 
 /*
@@ -57,9 +57,9 @@
  *             valid then run it.
  *     2) if preinst.img is found load it into memory. If it is
  *             valid then run it. Update the EEPROM.
- *     3) if firmware.img is found load it into memory. If it is valid,
+ *     3) if firmw_01.img is found load it into memory. If it is valid,
  *             burn it into FLASH and update the EEPROM.
- *     4) if kernel.img is found load it into memory. If it is valid,
+ *     4) if kernl_01.img is found load it into memory. If it is valid,
  *             burn it into FLASH and update the EEPROM.
  *     5) if app.img is found load it into memory. If it is valid,
  *             burn it into FLASH and update the EEPROM.
@@ -81,8 +81,8 @@
 /* possible names of files on the USB stick. */
 #define AU_PREPARE     "prepare.img"
 #define AU_PREINST     "preinst.img"
-#define AU_FIRMWARE    "firmware.img"
-#define AU_KERNEL      "kernel.img"
+#define AU_FIRMWARE    "firmw_01.img"
+#define AU_KERNEL      "kernl_01.img"
 #define AU_APP         "app.img"
 #define AU_DISK                "disk.img"
 #define AU_POSTINST    "postinst.img"
@@ -199,11 +199,10 @@ extern int transfer_pic(unsigned char, unsigned char *, int, int);
 #endif
 extern int flash_sect_erase(ulong, ulong);
 extern int flash_sect_protect (int, ulong, ulong);
-extern int flash_write (uchar *, ulong, ulong);
+extern int flash_write (char *, ulong, ulong);
 /* change char* to void* to shutup the compiler */
 extern int i2c_write_multiple (uchar, uint, int, void *, int);
 extern int i2c_read_multiple (uchar, uint, int, void *, int);
-extern block_dev_desc_t *get_dev (char*, int);
 extern int u_boot_hush_start(void);
 
 int
@@ -222,7 +221,7 @@ au_check_cksum_valid(int idx, long nbytes)
        /* check the data CRC */
        checksum = ntohl(hdr->ih_dcrc);
 
-       if (crc32 (0, (char *)(LOAD_ADDR + sizeof(*hdr)), ntohl(hdr->ih_size))
+       if (crc32 (0, (uchar *)(LOAD_ADDR + sizeof(*hdr)), ntohl(hdr->ih_size))
                != checksum)
        {
                printf ("Image %s bad data checksum\n", aufile[idx]);
@@ -261,7 +260,7 @@ au_check_header_valid(int idx, long nbytes)
        checksum = ntohl(hdr->ih_hcrc);
        hdr->ih_hcrc = 0;
 
-       if (crc32 (0, (char *)hdr, sizeof(*hdr)) != checksum) {
+       if (crc32 (0, (uchar *)hdr, sizeof(*hdr)) != checksum) {
                printf ("Image %s bad header checksum\n", aufile[idx]);
                return -1;
        }
@@ -279,8 +278,8 @@ au_check_header_valid(int idx, long nbytes)
                printf ("Image %s wrong type\n", aufile[idx]);
                return -1;
        }
-       if ((idx == IDX_APP) && (hdr->ih_type != IH_TYPE_RAMDISK) 
-            && (hdr->ih_type != IH_TYPE_FILESYSTEM)) {
+       if ((idx == IDX_APP) && (hdr->ih_type != IH_TYPE_RAMDISK)
+           && (hdr->ih_type != IH_TYPE_FILESYSTEM)) {
                printf ("Image %s wrong type\n", aufile[idx]);
                return -1;
        }
@@ -296,7 +295,7 @@ au_check_header_valid(int idx, long nbytes)
        /* recycle checksum */
        checksum = ntohl(hdr->ih_size);
        /* for kernel and app the image header must also fit into flash */
-       if (idx != IDX_DISK)
+       if ((idx != IDX_DISK) && (idx != IDX_FIRMWARE))
                checksum += sizeof(*hdr);
        /* check the size does not exceed space in flash. HUSH scripts */
        /* all have ausize[] set to 0 */
@@ -397,7 +396,7 @@ au_do_update(int idx, long sz)
        }
 
        /* check the dcrc of the copy */
-       if (crc32 (0, (char *)(start + off), ntohl(hdr->ih_size)) != ntohl(hdr->ih_dcrc)) {
+       if (crc32 (0, (uchar *)(start + off), ntohl(hdr->ih_size)) != ntohl(hdr->ih_dcrc)) {
                printf ("Image %s Bad Data Checksum After COPY\n", aufile[idx]);
                return -1;
        }
@@ -416,6 +415,13 @@ au_update_eeprom(int idx)
        int off;
        uint32_t val;
 
+       /* special case for prepare.img */
+       if (idx == IDX_PREPARE) {
+               /* enable the power switch */
+               *CPLD_VFD_BK &= ~POWER_OFF;
+               return 0;
+       }
+
        hdr = (image_header_t *)LOAD_ADDR;
        /* write the time field into EEPROM */
        off = auee_off[idx].time;
@@ -444,7 +450,7 @@ do_auto_update(void)
 {
        block_dev_desc_t *stor_dev;
        long sz;
-       int i, res, bitmap_first, cnt, old_ctrlc, got_ctrlc;
+       int i, res = 0, bitmap_first, cnt, old_ctrlc, got_ctrlc;
        char *env;
        long start, end;
 
@@ -471,18 +477,21 @@ do_auto_update(void)
        au_usb_stor_curr_dev = usb_stor_scan(0);
        if (au_usb_stor_curr_dev == -1) {
                debug ("No device found. Not initialized?\n");
-               return -1;
+               res = -1;
+               goto xit;
        }
        /* check whether it has a partition table */
        stor_dev = get_dev("usb", 0);
        if (stor_dev == NULL) {
                debug ("uknown device type\n");
-               return -1;
+               res = -1;
+               goto xit;
        }
        if (fat_register_device(stor_dev, 1) != 0) {
                debug ("Unable to use USB %d:%d for fatls\n",
                        au_usb_stor_curr_dev, 1);
-               return -1;
+               res = -1;
+               goto xit;
        }
        if (file_fat_detectfs() != 0) {
                debug ("file_fat_detectfs failed\n");
@@ -606,7 +615,8 @@ do_auto_update(void)
 #define VFD_LOGO_WIDTH 112
 #define VFD_LOGO_HEIGHT 72
                                /* must call transfer_pic directly */
-                               transfer_pic(3, env, VFD_LOGO_HEIGHT, VFD_LOGO_WIDTH);
+                               transfer_pic(3, (unsigned char *)env,
+                                            VFD_LOGO_HEIGHT, VFD_LOGO_WIDTH);
                        }
                        bitmap_first = 1;
                }
@@ -641,9 +651,10 @@ do_auto_update(void)
                        /* enable the power switch */
                        *CPLD_VFD_BK &= ~POWER_OFF;
        }
-       usb_stop();
        /* restore the old state */
        disable_ctrlc(old_ctrlc);
-       return 0;
+xit:
+       usb_stop();
+       return res;
 }
 #endif /* CONFIG_AUTO_UPDATE */