]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - fs/jffs2/jffs2_1pass.c
fix comments with new drivers organization
[karo-tx-uboot.git] / fs / jffs2 / jffs2_1pass.c
index 6658512b20d9a188e9e16bce8dee7dff48cf9779..69f53eabcf0e39d1573009b984523d0c8e961b6b 100644 (file)
 #include <linux/stat.h>
 #include <linux/time.h>
 
-#if (CONFIG_COMMANDS & CFG_CMD_JFFS2)
+#if defined(CONFIG_CMD_JFFS2)
 
 #include <jffs2/jffs2.h>
 #include <jffs2/jffs2_1pass.h>
 /* keeps pointer to currentlu processed partition */
 static struct part_info *current_part;
 
-#if defined(CONFIG_JFFS2_NAND) && (CONFIG_COMMANDS & CFG_CMD_NAND) && !defined(CONFIG_NEW_NAND_CODE)
+#if (defined(CONFIG_JFFS2_NAND) && \
+     defined(CONFIG_CMD_NAND) )
+#if defined(CFG_NAND_LEGACY)
+#include <linux/mtd/nand_legacy.h>
+#else
+#include <nand.h>
+#endif
 /*
  * Support for jffs2 on top of NAND-flash
  *
@@ -154,9 +160,14 @@ static struct part_info *current_part;
  *
  */
 
-/* this one defined in cmd_nand.c */
+#if defined(CFG_NAND_LEGACY)
+/* this one defined in nand_legacy.c */
 int read_jffs2_nand(size_t start, size_t len,
-                   size_t * retlen, u_char * buf, int nanddev);
+               size_t * retlen, u_char * buf, int nanddev);
+#else
+/* info for NAND chips, defined in drivers/mtd/nand/nand.c */
+extern nand_info_t nand_info[];
+#endif
 
 #define NAND_PAGE_SIZE 512
 #define NAND_PAGE_SHIFT 9
@@ -174,7 +185,11 @@ static int read_nand_cached(u32 off, u32 size, u_char *buf)
 {
        struct mtdids *id = current_part->dev->id;
        u32 bytes_read = 0;
+#if defined(CFG_NAND_LEGACY)
        size_t retlen;
+#else
+       ulong retlen;
+#endif
        int cpy_bytes;
 
        while (bytes_read < size) {
@@ -191,6 +206,8 @@ static int read_nand_cached(u32 off, u32 size, u_char *buf)
                                        return -1;
                                }
                        }
+
+#if defined(CFG_NAND_LEGACY)
                        if (read_jffs2_nand(nand_cache_off, NAND_CACHE_SIZE,
                                                &retlen, nand_cache, id->num) < 0 ||
                                        retlen != NAND_CACHE_SIZE) {
@@ -198,6 +215,16 @@ static int read_nand_cached(u32 off, u32 size, u_char *buf)
                                                nand_cache_off, NAND_CACHE_SIZE);
                                return -1;
                        }
+#else
+                       retlen = NAND_CACHE_SIZE;
+                       if (nand_read(&nand_info[id->num], nand_cache_off,
+                                               &retlen, nand_cache) != 0 ||
+                                       retlen != NAND_CACHE_SIZE) {
+                               printf("read_nand_cached: error reading nand off %#x size %d bytes\n",
+                                               nand_cache_off, NAND_CACHE_SIZE);
+                               return -1;
+                       }
+#endif
                }
                cpy_bytes = nand_cache_off + NAND_CACHE_SIZE - (off + bytes_read);
                if (cpy_bytes > size - bytes_read)
@@ -248,10 +275,10 @@ static void put_fl_mem_nand(void *buf)
 {
        free(buf);
 }
-#endif /* #if defined(CONFIG_JFFS2_NAND) && (CONFIG_COMMANDS & CFG_CMD_NAND) */
+#endif
 
 
-#if (CONFIG_COMMANDS & CFG_CMD_FLASH)
+#if defined(CONFIG_CMD_FLASH)
 /*
  * Support for jffs2 on top of NOR-flash
  *
@@ -263,7 +290,7 @@ static inline void *get_fl_mem_nor(u32 off)
        u32 addr = off;
        struct mtdids *id = current_part->dev->id;
 
-       extern flash_info_t flash_info[CFG_MAX_FLASH_BANKS];
+       extern flash_info_t flash_info[];
        flash_info_t *flash = &flash_info[id->num];
 
        addr += flash->start[0];
@@ -274,7 +301,7 @@ static inline void *get_node_mem_nor(u32 off)
 {
        return (void*)get_fl_mem_nor(off);
 }
-#endif /* #if (CONFIG_COMMANDS & CFG_CMD_FLASH) */
+#endif
 
 
 /*
@@ -285,12 +312,12 @@ static inline void *get_fl_mem(u32 off, u32 size, void *ext_buf)
 {
        struct mtdids *id = current_part->dev->id;
 
-#if (CONFIG_COMMANDS & CFG_CMD_FLASH)
+#if defined(CONFIG_CMD_FLASH)
        if (id->type == MTD_DEV_TYPE_NOR)
                return get_fl_mem_nor(off);
 #endif
 
-#if defined(CONFIG_JFFS2_NAND) && (CONFIG_COMMANDS & CFG_CMD_NAND) && !defined(CONFIG_NEW_NAND_CODE)
+#if defined(CONFIG_JFFS2_NAND) && defined(CONFIG_CMD_NAND)
        if (id->type == MTD_DEV_TYPE_NAND)
                return get_fl_mem_nand(off, size, ext_buf);
 #endif
@@ -303,12 +330,13 @@ static inline void *get_node_mem(u32 off)
 {
        struct mtdids *id = current_part->dev->id;
 
-#if (CONFIG_COMMANDS & CFG_CMD_FLASH)
+#if defined(CONFIG_CMD_FLASH)
        if (id->type == MTD_DEV_TYPE_NOR)
                return get_node_mem_nor(off);
 #endif
 
-#if defined(CONFIG_JFFS2_NAND) && (CONFIG_COMMANDS & CFG_CMD_NAND) && !defined(CONFIG_NEW_NAND_CODE)
+#if defined(CONFIG_JFFS2_NAND) && \
+    defined(CONFIG_CMD_NAND)
        if (id->type == MTD_DEV_TYPE_NAND)
                return get_node_mem_nand(off);
 #endif
@@ -319,7 +347,8 @@ static inline void *get_node_mem(u32 off)
 
 static inline void put_fl_mem(void *buf)
 {
-#if defined(CONFIG_JFFS2_NAND) && (CONFIG_COMMANDS & CFG_CMD_NAND) && !defined(CONFIG_NEW_NAND_CODE)
+#if defined(CONFIG_JFFS2_NAND) && \
+    defined(CONFIG_CMD_NAND)
        struct mtdids *id = current_part->dev->id;
 
        if (id->type == MTD_DEV_TYPE_NAND)
@@ -496,7 +525,7 @@ static int compare_dirents(struct b_node *new, struct b_node *old)
 
        /* length is also the same, so use ascending sort by name
         */
-       cmp = strncmp(jNew->name, jOld->name, jNew->nsize);
+       cmp = strncmp((char *)jNew->name, (char *)jOld->name, jNew->nsize);
        if (cmp != 0)
                return cmp > 0;
 
@@ -572,8 +601,8 @@ jffs2_1pass_read_inode(struct b_lists *pL, u32 inode, char *dest)
        struct jffs2_raw_inode *jNode;
        u32 totalSize = 0;
        u32 latestVersion = 0;
-       char *lDest;
-       char *src;
+       uchar *lDest;
+       uchar *src;
        long ret;
        int i;
        u32 counter = 0;
@@ -624,14 +653,14 @@ jffs2_1pass_read_inode(struct b_lists *pL, u32 inode, char *dest)
 #endif
 
                        if(dest) {
-                               src = ((char *) jNode) + sizeof(struct jffs2_raw_inode);
+                               src = ((uchar *) jNode) + sizeof(struct jffs2_raw_inode);
                                /* ignore data behind latest known EOF */
                                if (jNode->offset > totalSize) {
                                        put_fl_mem(jNode);
                                        continue;
                                }
 
-                               lDest = (char *) (dest + jNode->offset);
+                               lDest = (uchar *) (dest + jNode->offset);
 #if 0
                                putLabeledWord("read_inode: src = ", src);
                                putLabeledWord("read_inode: dest = ", lDest);
@@ -709,7 +738,7 @@ jffs2_1pass_find_inode(struct b_lists * pL, const char *name, u32 pino)
                jDir = (struct jffs2_raw_dirent *) get_node_mem(b->offset);
                if ((pino == jDir->pino) && (len == jDir->nsize) &&
                    (jDir->ino) &&      /* 0 for unlink */
-                   (!strncmp(jDir->name, name, len))) {        /* a match */
+                   (!strncmp((char *)jDir->name, name, len))) {        /* a match */
                        if (jDir->version < version) {
                                put_fl_mem(jDir);
                                continue;
@@ -776,7 +805,7 @@ static inline void dump_stat(struct stat *st, const char *name)
        if (st->st_mtime == (time_t)(-1)) /* some ctimes really hate -1 */
                st->st_mtime = 1;
 
-       ctime_r(&st->st_mtime, s/*,64*/); /* newlib ctime doesn't have buflen */
+       ctime_r((time_t *)&st->st_mtime, s/*,64*/); /* newlib ctime doesn't have buflen */
 
        if ((p = strchr(s,'\n')) != NULL) *p = '\0';
        if ((p = strchr(s,'\r')) != NULL) *p = '\0';
@@ -796,7 +825,7 @@ static inline u32 dump_inode(struct b_lists * pL, struct jffs2_raw_dirent *d, st
 
        if(!d || !i) return -1;
 
-       strncpy(fname, d->name, d->nsize);
+       strncpy(fname, (char *)d->name, d->nsize);
        fname[d->nsize] = '\0';
 
        memset(&st,0,sizeof(st));
@@ -971,7 +1000,7 @@ jffs2_1pass_resolve_inode(struct b_lists * pL, u32 ino)
                        putnstr(src, jNode->dsize);
                        putstr("\r\n");
 #endif
-                       strncpy(tmp, src, jNode->dsize);
+                       strncpy(tmp, (char *)src, jNode->dsize);
                        tmp[jNode->dsize] = '\0';
                        put_fl_mem(jNode);
                        break;
@@ -1167,7 +1196,8 @@ jffs2_1pass_build_lists(struct part_info * part)
                if (node->magic == JFFS2_MAGIC_BITMASK && hdr_crc(node)) {
                        /* if its a fragment add it */
                        if (node->nodetype == JFFS2_NODETYPE_INODE &&
-                                   inode_crc((struct jffs2_raw_inode *) node)) {
+                                   inode_crc((struct jffs2_raw_inode *) node) &&
+                                   data_crc((struct jffs2_raw_inode *) node)) {
                                if (insert_node(&pL->frag, (u32) part->offset +
                                                offset) == NULL) {
                                        put_fl_mem(node);
@@ -1367,4 +1397,4 @@ jffs2_1pass_info(struct part_info * part)
        return 1;
 }
 
-#endif /* CFG_CMD_JFFS2 */
+#endif