USB: fix those pesky aliasing warnings issued by gcc-4.2
[oweals/u-boot.git] / common / cmd_doc.c
index 31862cf2444fd261d7f0d513c89e0573f7772871..83aba3744e96dd40be2cf65507bfa25ace03605b 100644 (file)
 #include <command.h>
 #include <malloc.h>
 #include <asm/io.h>
-
-#ifdef CONFIG_SHOW_BOOT_PROGRESS
-# include <status_led.h>
-# define SHOW_BOOT_PROGRESS(arg)       show_boot_progress(arg)
-#else
-# define SHOW_BOOT_PROGRESS(arg)
-#endif
-
-#if (CONFIG_COMMANDS & CFG_CMD_DOC)
-
 #include <linux/mtd/nftl.h>
-#include <linux/mtd/nand.h>
-#include <linux/mtd/nand_ids.h>
 #include <linux/mtd/doc2000.h>
-#include <linux/mtd/nftl.h>
 
 #ifdef CFG_DOC_SUPPORT_2000
 #define DoC_is_2000(doc) (doc->ChipID == DOC_ChipID_Doc2k)
@@ -68,6 +55,32 @@ static struct DiskOnChip doc_dev_desc[CFG_MAX_DOC_DEVICE];
 /* Current DOC Device  */
 static int curr_device = -1;
 
+/* Supported NAND flash devices */
+static struct nand_flash_dev nand_flash_ids[] = {
+       {"Toshiba TC5816BDC",     NAND_MFR_TOSHIBA, 0x64, 21, 1, 2, 0x1000, 0},
+       {"Toshiba TC5832DC",      NAND_MFR_TOSHIBA, 0x6b, 22, 0, 2, 0x2000, 0},
+       {"Toshiba TH58V128DC",    NAND_MFR_TOSHIBA, 0x73, 24, 0, 2, 0x4000, 0},
+       {"Toshiba TC58256FT/DC",  NAND_MFR_TOSHIBA, 0x75, 25, 0, 2, 0x4000, 0},
+       {"Toshiba TH58512FT",     NAND_MFR_TOSHIBA, 0x76, 26, 0, 3, 0x4000, 0},
+       {"Toshiba TC58V32DC",     NAND_MFR_TOSHIBA, 0xe5, 22, 0, 2, 0x2000, 0},
+       {"Toshiba TC58V64AFT/DC", NAND_MFR_TOSHIBA, 0xe6, 23, 0, 2, 0x2000, 0},
+       {"Toshiba TC58V16BDC",    NAND_MFR_TOSHIBA, 0xea, 21, 1, 2, 0x1000, 0},
+       {"Toshiba TH58100FT",     NAND_MFR_TOSHIBA, 0x79, 27, 0, 3, 0x4000, 0},
+       {"Samsung KM29N16000",    NAND_MFR_SAMSUNG, 0x64, 21, 1, 2, 0x1000, 0},
+       {"Samsung unknown 4Mb",   NAND_MFR_SAMSUNG, 0x6b, 22, 0, 2, 0x2000, 0},
+       {"Samsung KM29U128T",     NAND_MFR_SAMSUNG, 0x73, 24, 0, 2, 0x4000, 0},
+       {"Samsung KM29U256T",     NAND_MFR_SAMSUNG, 0x75, 25, 0, 2, 0x4000, 0},
+       {"Samsung unknown 64Mb",  NAND_MFR_SAMSUNG, 0x76, 26, 0, 3, 0x4000, 0},
+       {"Samsung KM29W32000",    NAND_MFR_SAMSUNG, 0xe3, 22, 0, 2, 0x2000, 0},
+       {"Samsung unknown 4Mb",   NAND_MFR_SAMSUNG, 0xe5, 22, 0, 2, 0x2000, 0},
+       {"Samsung KM29U64000",    NAND_MFR_SAMSUNG, 0xe6, 23, 0, 2, 0x2000, 0},
+       {"Samsung KM29W16000",    NAND_MFR_SAMSUNG, 0xea, 21, 1, 2, 0x1000, 0},
+       {"Samsung K9F5616Q0C",    NAND_MFR_SAMSUNG, 0x45, 25, 0, 2, 0x4000, 1},
+       {"Samsung K9K1216Q0C",    NAND_MFR_SAMSUNG, 0x46, 26, 0, 3, 0x4000, 1},
+       {"Samsung K9F1G08U0M",    NAND_MFR_SAMSUNG, 0xf1, 27, 0, 2, 0, 0},
+       {NULL,}
+};
+
 /* ------------------------------------------------------------------------- */
 
 int do_doc (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
@@ -143,7 +156,7 @@ int do_doc (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
                        cmd ? "read" : "write", curr_device, off, size);
 
                ret = doc_rw(doc_dev_desc + curr_device, cmd, off, size,
-                            &total, (u_char*)addr);
+                            (size_t *)&total, (u_char*)addr);
 
                printf ("%d bytes %s: %s\n", total, cmd ? "read" : "write",
                        ret ? "ERROR" : "OK");
@@ -192,7 +205,11 @@ int do_docboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
        ulong offset = 0;
        image_header_t *hdr;
        int rcode = 0;
+#if defined(CONFIG_FIT)
+       const void *fit_hdr;
+#endif
 
+       show_boot_progress (34);
        switch (argc) {
        case 1:
                addr = CFG_LOAD_ADDR;
@@ -213,24 +230,27 @@ int do_docboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
                break;
        default:
                printf ("Usage:\n%s\n", cmdtp->usage);
-               SHOW_BOOT_PROGRESS (-1);
+               show_boot_progress (-35);
                return 1;
        }
 
+       show_boot_progress (35);
        if (!boot_device) {
                puts ("\n** No boot device **\n");
-               SHOW_BOOT_PROGRESS (-1);
+               show_boot_progress (-36);
                return 1;
        }
+       show_boot_progress (36);
 
        dev = simple_strtoul(boot_device, &ep, 16);
 
        if ((dev >= CFG_MAX_DOC_DEVICE) ||
            (doc_dev_desc[dev].ChipID == DOC_ChipID_UNKNOWN)) {
                printf ("\n** Device %d not available\n", dev);
-               SHOW_BOOT_PROGRESS (-1);
+               show_boot_progress (-37);
                return 1;
        }
+       show_boot_progress (37);
 
        printf ("\nLoading from device %d: %s at 0x%lX (offset 0x%lX)\n",
                dev, doc_dev_desc[dev].name, doc_dev_desc[dev].physadr,
@@ -239,30 +259,54 @@ int do_docboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
        if (doc_rw (doc_dev_desc + dev, 1, offset,
                    SECTORSIZE, NULL, (u_char *)addr)) {
                printf ("** Read error on %d\n", dev);
-               SHOW_BOOT_PROGRESS (-1);
+               show_boot_progress (-38);
                return 1;
        }
+       show_boot_progress (38);
 
-       hdr = (image_header_t *)addr;
+       switch (genimg_get_format ((void *)addr)) {
+       case IMAGE_FORMAT_LEGACY:
+               hdr = (image_header_t *)addr;
 
-       if (hdr->ih_magic == IH_MAGIC) {
+               image_print_contents (hdr);
 
-               print_image_hdr (hdr);
+               cnt = image_get_image_size (hdr);
+               break;
+#if defined(CONFIG_FIT)
+       case IMAGE_FORMAT_FIT:
+               fit_hdr = (const void *)addr;
+               if (!fit_check_format (fit_hdr)) {
+                       show_boot_progress (-130);
+                       puts ("** Bad FIT image format\n");
+                       return 1;
+               }
+               show_boot_progress (131);
+               puts ("Fit image detected...\n");
 
-               cnt = (hdr->ih_size + sizeof(image_header_t));
-               cnt -= SECTORSIZE;
-       } else {
-               puts ("\n** Bad Magic Number **\n");
-               SHOW_BOOT_PROGRESS (-1);
+               cnt = fit_get_size (fit_hdr);
+               break;
+#endif
+       default:
+               show_boot_progress (-39);
+               puts ("** Unknown image type\n");
                return 1;
        }
+       show_boot_progress (39);
 
+       cnt -= SECTORSIZE;
        if (doc_rw (doc_dev_desc + dev, 1, offset + SECTORSIZE, cnt,
                    NULL, (u_char *)(addr+SECTORSIZE))) {
                printf ("** Read error on %d\n", dev);
-               SHOW_BOOT_PROGRESS (-1);
+               show_boot_progress (-40);
                return 1;
        }
+       show_boot_progress (40);
+
+#if defined(CONFIG_FIT)
+       /* This cannot be done earlier, we need complete FIT image in RAM first */
+       if (genimg_get_format ((void *)addr) == IMAGE_FORMAT_FIT)
+               fit_print_contents ((const void *)addr);
+#endif
 
        /* Loading ok, update default load address */
 
@@ -304,12 +348,12 @@ int doc_rw (struct DiskOnChip* this, int cmd,
 
                if (cmd)
                        ret = doc_read_ecc(this, from, len,
-                                          &n, (u_char*)buf,
-                                          noecc ? NULL : eccbuf);
+                                          (size_t *)&n, (u_char*)buf,
+                                          noecc ? (uchar *)NULL : (uchar *)eccbuf);
                else
                        ret = doc_write_ecc(this, from, len,
-                                           &n, (u_char*)buf,
-                                           noecc ? NULL : eccbuf);
+                                           (size_t *)&n, (u_char*)buf,
+                                           noecc ? (uchar *)NULL : (uchar *)eccbuf);
 
                if (ret)
                        break;
@@ -804,7 +848,7 @@ static int find_boot_record(struct NFTLrecord *nftl)
                /* Check for ANAND header first. Then can whinge if it's found but later
                   checks fail */
                if ((ret = doc_read_ecc(nftl->mtd, block * nftl->EraseSize, SECTORSIZE,
-                                       &retlen, buf, NULL))) {
+                                       (size_t *)&retlen, buf, NULL))) {
                        static int warncount = 5;
 
                        if (warncount) {
@@ -829,7 +873,7 @@ static int find_boot_record(struct NFTLrecord *nftl)
 
                /* To be safer with BIOS, also use erase mark as discriminant */
                if ((ret = doc_read_oob(nftl->mtd, block * nftl->EraseSize + SECTORSIZE + 8,
-                               8, &retlen, (char *)&h1) < 0)) {
+                               8, (size_t *)&retlen, (uchar *)&h1) < 0)) {
 #ifdef NFTL_DEBUG
                        printf("ANAND header found at 0x%x, but OOB data read failed\n",
                               block * nftl->EraseSize);
@@ -861,8 +905,13 @@ static int find_boot_record(struct NFTLrecord *nftl)
                memcpy(mh, buf, sizeof(struct NFTLMediaHeader));
 
                /* Do some sanity checks on it */
-               if (mh->UnitSizeFactor != 0xff) {
-                       puts ("Sorry, we don't support UnitSizeFactor "
+               if (mh->UnitSizeFactor == 0) {
+#ifdef NFTL_DEBUG
+                       puts ("UnitSizeFactor 0x00 detected.\n"
+                             "This violates the spec but we think we know what it means...\n");
+#endif
+               } else if (mh->UnitSizeFactor != 0xff) {
+                       printf ("Sorry, we don't support UnitSizeFactor "
                              "of != 1 yet.\n");
                        return -1;
                }
@@ -897,7 +946,7 @@ static int find_boot_record(struct NFTLrecord *nftl)
                                /* read one sector for every SECTORSIZE of blocks */
                                if ((ret = doc_read_ecc(nftl->mtd, block * nftl->EraseSize +
                                                       i + SECTORSIZE, SECTORSIZE,
-                                                      &retlen, buf, (char *)&oob)) < 0) {
+                                                      (size_t *)&retlen, buf, (uchar *)&oob)) < 0) {
                                        puts ("Read of bad sector table failed\n");
                                        return -1;
                                }
@@ -950,6 +999,8 @@ static void DoC2k_init(struct DiskOnChip* this)
 
        /* Ident all the chips present. */
        DoC_ScanChips(this);
+       if ((!this->numchips) || (!this->chips))
+               return;
 
        nftl = &this->nftl;
 
@@ -1577,5 +1628,3 @@ void doc_probe(unsigned long physadr)
                puts ("No DiskOnChip found\n");
        }
 }
-
-#endif /* (CONFIG_COMMANDS & CFG_CMD_DOC) */