2
0
Эх сурвалжийг харах

JFFS2: Suport norflash by mtd apis

Change-Id: Ief32e11b64c2fd97b3fad88b962964099964fabb
Signed-off-by: Jon Lin <jon.lin@rock-chips.com>
Jon Lin 1 жил өмнө
parent
commit
70e7835f80
2 өөрчлөгдсөн 54 нэмэгдсэн , 6 устгасан
  1. 5 6
      cmd/jffs2.c
  2. 49 0
      fs/jffs2/jffs2_1pass.c

+ 5 - 6
cmd/jffs2.c

@@ -162,14 +162,13 @@ static int mtd_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, CONFIG_SYS_MAX_FLASH_BANKS - 1);
 #else
-		struct mtd_info *mtd = get_nand_dev_by_index(num);
+		struct mtd_info *mtd = get_mtd_device_nm(CONFIG_JFFS2_DEV);
 		if (mtd) {
 			*size = mtd->size;
 			return 0;
 		}
 
-		printf("no such Nor device: %s%d (valid range 0 ... %d)\n",
-				MTD_DEV_TYPE(type), num, CONFIG_SYS_MAX_FLASH_BANKS - 1);
+		printf("no such Nor device: %s\n", CONFIG_JFFS2_DEV);
 #endif
 	} else if (type == MTD_DEV_TYPE_NAND) {
 #if defined(CONFIG_JFFS2_NAND) && defined(CONFIG_CMD_NAND)
@@ -295,7 +294,7 @@ static inline u32 get_part_sector_size_nor(struct mtdids *id, struct part_info *
 #else
 	struct mtd_info *mtd;
 
-	mtd = get_nand_dev_by_index(id->num);
+	mtd = get_mtd_device_nm(CONFIG_JFFS2_DEV);
 
 	return mtd->erasesize;
 #endif
@@ -382,7 +381,7 @@ int mtdparts_init(void)
 		id->size = size;
 		INIT_LIST_HEAD(&id->link);
 
-		DEBUGF("dev id: type = %d, num = %d, size = 0x%08lx, mtd_id = %s\n",
+		DEBUGF("dev id: type = %d, num = %d, size = 0x%08llx, mtd_id = %s\n",
 				id->type, id->num, id->size, id->mtd_id);
 
 		/* partition */
@@ -410,7 +409,7 @@ int mtdparts_init(void)
 
 		part->sector_size = get_part_sector_size(id, part);
 
-		DEBUGF("part  : name = %s, size = 0x%08lx, offset = 0x%08lx\n",
+		DEBUGF("part  : name = %s, size = 0x%08llx, offset = 0x%08llx\n",
 				part->name, part->size, part->offset);
 
 		/* device */

+ 49 - 0
fs/jffs2/jffs2_1pass.c

@@ -123,6 +123,7 @@
 #include <jffs2/jffs2_1pass.h>
 #include <linux/compat.h>
 #include <linux/errno.h>
+#include <linux/mtd/mtd.h>
 
 #include "jffs2_private.h"
 
@@ -394,6 +395,46 @@ static inline void *get_node_mem_nor(u32 off, void *ext_buf)
 	return (void *)get_fl_mem_nor(off, pNode->magic == JFFS2_MAGIC_BITMASK ?
 			pNode->totlen : sizeof(*pNode), ext_buf);
 }
+#else
+static void *get_fl_mem_norflash(u32 off, u32 size, void *ext_buf)
+{
+	u_char *buf = ext_buf ? (u_char*)ext_buf : (u_char*)malloc(size);
+	struct mtd_info *mtd;
+	size_t retlen;
+
+	mtd = get_mtd_device_nm(CONFIG_JFFS2_DEV);
+	if (!mtd)
+		return (void *)-1;
+
+	if (NULL == buf) {
+		printf("get_fl_mem_norflash: can't alloc %d bytes\n", size);
+		return NULL;
+	}
+	if (mtd_read(mtd, off, size, &retlen, buf) < 0) {
+		if (!ext_buf)
+			free(buf);
+		return NULL;
+	}
+
+	return buf;
+}
+
+static void *get_node_mem_norflash(u32 off, void *ext_buf)
+{
+	struct jffs2_unknown_node node;
+	void *ret = NULL;
+
+	if (NULL == get_fl_mem_norflash(off, sizeof(node), &node))
+		return NULL;
+
+	if (!(ret = get_fl_mem_norflash(off, node.magic ==
+			       JFFS2_MAGIC_BITMASK ? node.totlen : sizeof(node),
+			       ext_buf))) {
+		printf("off = %#x magic %#x type %#x node.totlen = %d\n",
+		       off, node.magic, node.nodetype, node.totlen);
+	}
+	return ret;
+}
 #endif
 
 
@@ -410,6 +451,10 @@ static inline void *get_fl_mem(u32 off, u32 size, void *ext_buf)
 	case MTD_DEV_TYPE_NOR:
 		return get_fl_mem_nor(off, size, ext_buf);
 		break;
+#else
+	case MTD_DEV_TYPE_NOR:
+		return get_fl_mem_norflash(off, size, ext_buf);
+		break;
 #endif
 #if defined(CONFIG_JFFS2_NAND) && defined(CONFIG_CMD_NAND)
 	case MTD_DEV_TYPE_NAND:
@@ -437,6 +482,10 @@ static inline void *get_node_mem(u32 off, void *ext_buf)
 	case MTD_DEV_TYPE_NOR:
 		return get_node_mem_nor(off, ext_buf);
 		break;
+#else
+	case MTD_DEV_TYPE_NOR:
+		return get_node_mem_norflash(off, ext_buf);
+		break;
 #endif
 #if defined(CONFIG_JFFS2_NAND) && \
     defined(CONFIG_CMD_NAND)