Correction patch
[oweals/u-boot.git] / board / mcc200 / auto_update.c
index faa01bd308dc5ac00b0ef32b4bfbb7ef66782b2b..28e4c877b538fe0d6dae5746861fa0a9f6823627 100644 (file)
@@ -44,8 +44,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
 
 #undef AU_DEBUG
@@ -162,7 +162,7 @@ int au_check_cksum_valid(int idx, long nbytes)
 int au_check_header_valid(int idx, long nbytes)
 {
        image_header_t *hdr;
-       unsigned long checksum;
+       unsigned long checksum, fsize;
 
        hdr = (image_header_t *)LOAD_ADDR;
        /* check the easy ones first */
@@ -205,7 +205,7 @@ int au_check_header_valid(int idx, long nbytes)
                return -1;
        }
        if ((idx == IDX_ROOTFS) &&
-               ( (hdr->ih_type != IH_TYPE_RAMDISK) || (hdr->ih_type != IH_TYPE_FILESYSTEM) )
+               ( (hdr->ih_type != IH_TYPE_RAMDISK) && (hdr->ih_type != IH_TYPE_FILESYSTEM) )
           ) {
                printf ("Image %s wrong type\n", aufile[idx]);
                ausize[idx] = 0;
@@ -213,8 +213,10 @@ int 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_FIRMWARE)
+
+       fsize = checksum + sizeof(*hdr);
+       /* for kernel and ramdisk the image header must also fit into flash */
+       if (idx == IDX_KERNEL || hdr->ih_type == IH_TYPE_RAMDISK)
                checksum += sizeof(*hdr);
 
        /* check the size does not exceed space in flash. HUSH scripts */
@@ -224,7 +226,7 @@ int au_check_header_valid(int idx, long nbytes)
                return -1;
        }
        /* Update with the real filesize */
-       ausize[idx] = (idx == IDX_FIRMWARE ? checksum + sizeof(*hdr) : checksum);
+       ausize[idx] = fsize;
 
        return checksum; /* return size to be written to flash */
 }
@@ -328,6 +330,8 @@ int do_auto_update(void)
        int i, res = 0, bitmap_first, cnt, old_ctrlc, got_ctrlc;
        char *env;
        long start, end;
+
+#if 0 /* disable key-press detection to speed up boot-up time */
        uchar keypad_status1[2] = {0,0}, keypad_status2[2] = {0,0};
 
        /*
@@ -345,6 +349,7 @@ int do_auto_update(void)
                return 0;
        }
 
+#endif
        au_usb_stor_curr_dev = -1;
        /* start USB */
        if (usb_stop() < 0) {
@@ -362,18 +367,21 @@ int 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");
@@ -502,7 +510,7 @@ int do_auto_update(void)
                } while (res < 0);
 #endif
        }
-       usb_stop();
+
        /* restore the old state */
        disable_ctrlc(old_ctrlc);
 #ifdef CONFIG_PROGRESSBAR
@@ -515,6 +523,8 @@ int do_auto_update(void)
                lcd_enable();
        }
 #endif
-       return 0;
+ xit:
+       usb_stop();
+       return res;
 }
 #endif /* CONFIG_AUTO_UPDATE */