JFFS2: use MTD_OOB_AUTO
RFC PATCH 1/1 JFFS2: use MTD_OOB_AUTO
Here is a patch which teaches JFFS2 to use MTD_OOB_AUTO option which makes much more sense then using MTD_OOB_PLACE. The original motivation was that JFFS2 does not work on OneNAND which has tricky location of free bytes at OOB.
The patch was not well tested yet, just a brief test with nandsim. So it is just an RFC now.
Signature · 2 lines
Best regards, Artem Bityutskiy (Битюцкий Артём)
Nowadays MTD supports an MTD_OOB_AUTO option which allows users to access free bytes in NAND's OOB as a contiguous buffer, although it may be highly discontinuous.
This patch teaches JFFS2 to use this nice feature instead of the old MTD_OOB_PLACE option. This for example caused problems with OneNAND. Now JFFS2 does not care how are the free bytes situated.
This may change position of the clean marker on some flashes, but this is not a problem. JFFS2 will just re-erase the empty eraseblocks and write the new (correct) clean marker.
--- fs/jffs2/jffs2_fs_sb.h | 12 +-- fs/jffs2/scan.c | 10 ++- fs/jffs2/wbuf.c | 206 +++++++++++++++++------------------------------- 3 files changed, 84 insertions(+), 144 deletions(-)
fs/jffs2/jffs2_fs_sb.h +3 -9
@@ -98,20 +98,14 @@ struct jffs2_sb_info {uint32_t wbuf_pagesize;/* 0 for NOR and other flashes with no wbuf */ #ifdef CONFIG_JFFS2_FS_WRITEBUFFER -/* Write-behind buffer for NAND flash */ -unsigned char *wbuf; -unsigned char *oobbuf; +unsigned char *wbuf;/* Write-behind buffer for NAND flash */ uint32_t wbuf_ofs;uint32_t wbuf_len;struct jffs2_inodirty *wbuf_inodes; -struct rw_semaphore wbuf_sem;/* Protects the write buffer */ -/* Information about out-of-band area usage... */ -struct nand_ecclayout *ecclayout; -uint32_t badblock_pos; -uint32_t fsdata_pos; -uint32_t fsdata_len; +unsigned char *oobbuf; +int oobavail;/* How many bytes are available for JFFS2 in OOB */ #endif struct jffs2_summary *summary;/* Summary information */
fs/jffs2/scan.c +7 -3
@@ -450,16 +450,20 @@ static int jffs2_scan_eraseblock (struct#ifdef CONFIG_JFFS2_FS_WRITEBUFFER if (jffs2_cleanmarker_oob (c)) { -int ret =jffs2_check_nand_cleanmarker (c, jeb); +int ret; + +if (c->mtd->block_isbad (c->mtd, jeb->offset)) +return BLK_STATE_BADBLOCK ; + + ret =jffs2_check_nand_cleanmarker (c, jeb);D2 (printk (KERN_NOTICE "jffs_check_nand_cleanmarker returned %d\n" ,ret)); +/* Even if it's not found, we still scan to see if the block is empty. We use this information to decide whether to erase it or not. */ switch (ret) {case 0 : cleanmarkerfound =1 ;break ;case 1 :break ; -case 2 :return BLK_STATE_BADBLOCK ; -case 3 :return BLK_STATE_ALLDIRTY ;/* Block has failed to erase min. once */ default :return ret; } }
fs/jffs2/wbuf.c +74 -132
291 lines not on this page · raw message
Hi Artem,
Quoted 8 lines
Here is a patch which teaches JFFS2 to use
MTD_OOB_AUTOoption which makes much more sense then usingMTD_OOB_PLACE. The original motivation was that JFFS2 does not work on OneNAND which has tricky location of free bytes at OOB.The patch was not well tested yet, just a brief test with nandsim. So it is just an RFC now.
After a minor MTD_OOB_AUTO in OneNAND, it's running.
I'll check and test it more.
I think that it changes the previous jffs2 format. it means it brakes the jffs2 backward compatibility.
So how about adding new configuration e.g., CONFIG_JFFS2_AUTOOOB or another approache
then user choose the oob policy (OOB_PLACE or OOB_AUTO) or runtime dectection???
I'm not sure what is the best one
And one more.
Please re-place the 'oob_cleanmarker' initialization like this. It's almost constant variable.
We don't need to re-init at every jffs2 mount time.
% in fs/jffs2/wbuf.c
+
+static int __init jffs2_writebuffer_init(void)
+{
+ uint32_t crc;
+
+ /* Initialize the OOB cleanmarker pattern */ + oob_cleanmarker.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK); + oob_cleanmarker.nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER); + oob_cleanmarker.totlen = cpu_to_je32(8); + crc = crc32(0, &oob_cleanmarker, sizeof(struct jffs2_unknown_node)-
4);
+ oob_cleanmarker.hdr_crc = cpu_to_je32(crc);
+
+ return 0;
+}
+
+module_init(jffs2_writebuffer_init);
Thank you,
Kyungmin Park
Hi Kyungmin,
Quoted 2 lines · Kyungmin Park
After a minor
MTD_OOB_AUTOin OneNAND, it's running. I'll check and test it more.
Thank you.
Quoted 2 lines
I think that it changes the previous jffs2 format. it means it brakes the jffs2 backward compatibility.
Yes, but I suspect this should not be a problem. The worst thing that should happen is that JFFS2 will just re-erase empty eraseblocks once. We will test this.
Quoted 4 lines
And one more.
Please re-place the 'oob_cleanmarker' initialization like this. It's almost constant variable.
We don't need to re-init at every jffs2 mount time.
Good point, thanks. I'll re-send the patch.
Signature · 2 lines
Best regards, Artem Bityutskiy (Битюцкий Артём)