]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - common/cmd_jffs2.c
rename CFG_ macros to CONFIG_SYS
[karo-tx-uboot.git] / common / cmd_jffs2.c
index 1b67e73f1119d03864b23afeaa197ed2533546f2..791a572cc51a60986cdc21681dea5924b3fb0e3b 100644 (file)
@@ -51,7 +51,7 @@
  * mtdids=<idmap>[,<idmap>,...]
  *
  * <idmap>    := <dev-id>=<mtd-id>
- * <dev-id>   := 'nand'|'nor'<dev-num>
+ * <dev-id>   := 'nand'|'nor'|'onenand'<dev-num>
  * <dev-num>  := mtd device number, 0...
  * <mtd-id>   := unique device tag used by linux kernel to find mtd device (mtd->name)
  *
 #include <cramfs/cramfs_fs.h>
 
 #if defined(CONFIG_CMD_NAND)
-#ifdef CFG_NAND_LEGACY
+#ifdef CONFIG_NAND_LEGACY
 #include <linux/mtd/nand_legacy.h>
-#else /* !CFG_NAND_LEGACY */
+#else /* !CONFIG_NAND_LEGACY */
 #include <linux/mtd/nand.h>
 #include <nand.h>
-#endif /* !CFG_NAND_LEGACY */
+#endif /* !CONFIG_NAND_LEGACY */
 #endif
+
+#if defined(CONFIG_CMD_ONENAND)
+#include <linux/mtd/mtd.h>
+#include <linux/mtd/onenand.h>
+#include <onenand_uboot.h>
+#endif
+
 /* enable/disable debugging messages */
 #define        DEBUG_JFFS
 #undef DEBUG_JFFS
@@ -241,13 +248,13 @@ static void memsize_format(char *buf, u32 size)
 #define SIZE_KB ((u32)1024)
 
        if ((size % SIZE_GB) == 0)
-               sprintf(buf, "%lug", size/SIZE_GB);
+               sprintf(buf, "%ug", size/SIZE_GB);
        else if ((size % SIZE_MB) == 0)
-               sprintf(buf, "%lum", size/SIZE_MB);
+               sprintf(buf, "%um", size/SIZE_MB);
        else if (size % SIZE_KB == 0)
-               sprintf(buf, "%luk", size/SIZE_KB);
+               sprintf(buf, "%uk", size/SIZE_KB);
        else
-               sprintf(buf, "%lu", size);
+               sprintf(buf, "%u", size);
 }
 
 /**
@@ -400,6 +407,43 @@ static int part_validate_nand(struct mtdids *id, struct part_info *part)
 #endif
 }
 
+/**
+ * Performs sanity check for supplied OneNAND flash partition.
+ * Table of existing OneNAND flash devices is searched and partition device
+ * is located. Alignment with the granularity of nand erasesize is verified.
+ *
+ * @param id of the parent device
+ * @param part partition to validate
+ * @return 0 if partition is valid, 1 otherwise
+ */
+static int part_validate_onenand(struct mtdids *id, struct part_info *part)
+{
+#if defined(CONFIG_CMD_ONENAND)
+       /* info for OneNAND chips */
+       struct mtd_info *mtd;
+
+       mtd = &onenand_mtd;
+
+       if ((unsigned long)(part->offset) % mtd->erasesize) {
+               printf("%s%d: partition (%s) start offset"
+                       "alignment incorrect\n",
+                               MTD_DEV_TYPE(id->type), id->num, part->name);
+               return 1;
+       }
+
+       if (part->size % mtd->erasesize) {
+               printf("%s%d: partition (%s) size alignment incorrect\n",
+                               MTD_DEV_TYPE(id->type), id->num, part->name);
+               return 1;
+       }
+
+       return 0;
+#else
+       return 1;
+#endif
+}
+
+
 /**
  * Performs sanity check for supplied partition. Offset and size are verified
  * to be within valid range. Partition type is checked and either
@@ -416,7 +460,7 @@ static int part_validate(struct mtdids *id, struct part_info *part)
                part->size = id->size - part->offset;
 
        if (part->offset > id->size) {
-               printf("%s: offset %08lx beyond flash size %08lx\n",
+               printf("%s: offset %08x beyond flash size %08x\n",
                                id->mtd_id, part->offset, id->size);
                return 1;
        }
@@ -436,6 +480,8 @@ static int part_validate(struct mtdids *id, struct part_info *part)
                return part_validate_nand(id, part);
        else if (id->type == MTD_DEV_TYPE_NOR)
                return part_validate_nor(id, part);
+       else if (id->type == MTD_DEV_TYPE_ONENAND)
+               return part_validate_onenand(id, part);
        else
                DEBUGF("part_validate: invalid dev type\n");
 
@@ -476,7 +522,7 @@ static int part_del(struct mtd_device *dev, struct part_info *part)
                }
        }
 
-#ifdef CFG_NAND_LEGACY
+#ifdef CONFIG_NAND_LEGACY
        jffs2_free_cache(part);
 #endif
        list_del(&part->link);
@@ -505,7 +551,7 @@ static void part_delall(struct list_head *head)
        list_for_each_safe(entry, n, head) {
                part_tmp = list_entry(entry, struct part_info, link);
 
-#ifdef CFG_NAND_LEGACY
+#ifdef CONFIG_NAND_LEGACY
                jffs2_free_cache(part_tmp);
 #endif
                list_del(entry);
@@ -726,7 +772,7 @@ static int device_validate(u8 type, u8 num, u32 *size)
 {
        if (type == MTD_DEV_TYPE_NOR) {
 #if defined(CONFIG_CMD_FLASH)
-               if (num < CFG_MAX_FLASH_BANKS) {
+               if (num < CONFIG_SYS_MAX_FLASH_BANKS) {
                        extern flash_info_t flash_info[];
                        *size = flash_info[num].size;
 
@@ -734,28 +780,36 @@ static int device_validate(u8 type, u8 num, u32 *size)
                }
 
                printf("no such FLASH device: %s%d (valid range 0 ... %d\n",
-                               MTD_DEV_TYPE(type), num, CFG_MAX_FLASH_BANKS - 1);
+                               MTD_DEV_TYPE(type), num, CONFIG_SYS_MAX_FLASH_BANKS - 1);
 #else
                printf("support for FLASH devices not present\n");
 #endif
        } else if (type == MTD_DEV_TYPE_NAND) {
 #if defined(CONFIG_JFFS2_NAND) && defined(CONFIG_CMD_NAND)
-               if (num < CFG_MAX_NAND_DEVICE) {
-#ifndef CFG_NAND_LEGACY
+               if (num < CONFIG_SYS_MAX_NAND_DEVICE) {
+#ifndef CONFIG_NAND_LEGACY
                        *size = nand_info[num].size;
 #else
-                       extern struct nand_chip nand_dev_desc[CFG_MAX_NAND_DEVICE];
+                       extern struct nand_chip nand_dev_desc[CONFIG_SYS_MAX_NAND_DEVICE];
                        *size = nand_dev_desc[num].totlen;
 #endif
                        return 0;
                }
 
                printf("no such NAND device: %s%d (valid range 0 ... %d)\n",
-                               MTD_DEV_TYPE(type), num, CFG_MAX_NAND_DEVICE - 1);
+                               MTD_DEV_TYPE(type), num, CONFIG_SYS_MAX_NAND_DEVICE - 1);
 #else
                printf("support for NAND devices not present\n");
 #endif
-       }
+       } else if (type == MTD_DEV_TYPE_ONENAND) {
+#if defined(CONFIG_CMD_ONENAND)
+               *size = onenand_mtd.size;
+               return 0;
+#else
+               printf("support for OneNAND devices not present\n");
+#endif
+       } else
+               printf("Unknown defice type %d\n", type);
 
        return 1;
 }
@@ -1065,8 +1119,8 @@ static struct mtdids* id_find_by_mtd_id(const char *mtd_id, unsigned int mtd_id_
 #endif /* #ifdef CONFIG_JFFS2_CMDLINE */
 
 /**
- * Parse device id string <dev-id> := 'nand'|'nor'<dev-num>, return device
- * type and number.
+ * Parse device id string <dev-id> := 'nand'|'nor'|'onenand'<dev-num>,
+ * return device type and number.
  *
  * @param id string describing device id
  * @param ret_id output pointer to next char after parse completes (output)
@@ -1085,6 +1139,9 @@ int id_parse(const char *id, const char **ret_id, u8 *dev_type, u8 *dev_num)
        } else if (strncmp(p, "nor", 3) == 0) {
                *dev_type = MTD_DEV_TYPE_NOR;
                p += 3;
+       } else if (strncmp(p, "onenand", 7) == 0) {
+               *dev_type = MTD_DEV_TYPE_ONENAND;
+               p += 7;
        } else {
                printf("incorrect device type in %s\n", id);
                return 1;
@@ -1288,7 +1345,7 @@ static void list_partitions(void)
        if (current_dev) {
                part = jffs2_part_info(current_dev, current_partnum);
                if (part) {
-                       printf("\nactive partition: %s%d,%d - (%s) 0x%08lx @ 0x%08lx\n",
+                       printf("\nactive partition: %s%d,%d - (%s) 0x%08x @ 0x%08x\n",
                                        MTD_DEV_TYPE(current_dev->id->type),
                                        current_dev->id->num, current_partnum,
                                        part->name, part->size, part->offset);
@@ -1489,7 +1546,7 @@ static int parse_mtdids(const char *const ids)
        while(p && (*p != '\0')) {
 
                ret = 1;
-               /* parse 'nor'|'nand'<dev-num> */
+               /* parse 'nor'|'nand'|'onenand'<dev-num> */
                if (id_parse(p, &p, &type, &num) != 0)
                        break;
 
@@ -2181,7 +2238,7 @@ U_BOOT_CMD(
        "'mtdids' - linux kernel mtd device id <-> u-boot device id mapping\n\n"
        "mtdids=<idmap>[,<idmap>,...]\n\n"
        "<idmap>    := <dev-id>=<mtd-id>\n"
-       "<dev-id>   := 'nand'|'nor'<dev-num>\n"
+       "<dev-id>   := 'nand'|'nor'|'onenand'<dev-num>\n"
        "<dev-num>  := mtd device number, 0...\n"
        "<mtd-id>   := unique device tag used by linux kernel to find mtd device (mtd->name)\n\n"
        "'mtdparts' - partition list\n\n"