Skip to content

Commit daba5cc

Browse files
dedekindThomas Gleixner
authored andcommitted
[JFFS2] Fix dataflash support
- assume wbuf may be of size which is not power of 2 - don't make strange assumption about not padding wbuf for DataFlash - use wbuf = DataFlash page and eraseblock >= 8 Dataflash pages From: Peter Menzebach <pm-mtd@mw-itcon.de> Acked-by: Artem B. Bityutskiy <dedekind@infradead.org> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
1 parent 83a3683 commit daba5cc

3 files changed

Lines changed: 40 additions & 22 deletions

File tree

‎fs/jffs2/os-linux.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* For licensing information, see the file 'LICENCE' in this directory.
99
*
10-
* $Id: os-linux.h,v 1.63 2005/09/21 11:55:21 dedekind Exp $
10+
* $Id: os-linux.h,v 1.64 2005/09/30 13:59:13 dedekind Exp $
1111
*
1212
*/
1313

@@ -65,8 +65,9 @@ static inline void jffs2_init_inode_info(struct jffs2_inode_info *f)
6565

6666
#define jffs2_is_readonly(c) (OFNI_BS_2SFFJ(c)->s_flags & MS_RDONLY)
6767

68+
#define SECTOR_ADDR(x) ( (((unsigned long)(x) / c->sector_size) * c->sector_size) )
6869
#ifndef CONFIG_JFFS2_FS_WRITEBUFFER
69-
#define SECTOR_ADDR(x) ( ((unsigned long)(x) & ~(c->sector_size-1)) )
70+
7071

7172
#ifdef CONFIG_JFFS2_SUMMARY
7273
#define jffs2_can_mark_obsolete(c) (0)
@@ -102,7 +103,6 @@ static inline void jffs2_init_inode_info(struct jffs2_inode_info *f)
102103
#else /* NAND and/or ECC'd NOR support present */
103104

104105
#define jffs2_is_writebuffered(c) (c->wbuf != NULL)
105-
#define SECTOR_ADDR(x) ( ((unsigned long)(x) / (unsigned long)(c->sector_size)) * c->sector_size )
106106

107107
#ifdef CONFIG_JFFS2_SUMMARY
108108
#define jffs2_can_mark_obsolete(c) (0)

‎fs/jffs2/scan.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* For licensing information, see the file 'LICENCE' in this directory.
99
*
10-
* $Id: scan.c,v 1.124 2005/09/21 13:05:22 dedekind Exp $
10+
* $Id: scan.c,v 1.125 2005/09/30 13:59:13 dedekind Exp $
1111
*
1212
*/
1313
#include <linux/kernel.h>
@@ -233,12 +233,12 @@ int jffs2_scan_medium(struct jffs2_sb_info *c)
233233
c->nextblock->dirty_size = 0;
234234
}
235235
#ifdef CONFIG_JFFS2_FS_WRITEBUFFER
236-
if (!jffs2_can_mark_obsolete(c) && c->nextblock && (c->nextblock->free_size & (c->wbuf_pagesize-1))) {
236+
if (!jffs2_can_mark_obsolete(c) && c->nextblock && (c->nextblock->free_size % c->wbuf_pagesize)) {
237237
/* If we're going to start writing into a block which already
238238
contains data, and the end of the data isn't page-aligned,
239239
skip a little and align it. */
240240

241-
uint32_t skip = c->nextblock->free_size & (c->wbuf_pagesize-1);
241+
uint32_t skip = c->nextblock->free_size % c->wbuf_pagesize;
242242

243243
D1(printk(KERN_DEBUG "jffs2_scan_medium(): Skipping %d bytes in nextblock to ensure page alignment\n",
244244
skip));

‎fs/jffs2/wbuf.c‎

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
* For licensing information, see the file 'LICENCE' in this directory.
1111
*
12-
* $Id: wbuf.c,v 1.99 2005/09/21 16:11:04 dedekind Exp $
12+
* $Id: wbuf.c,v 1.100 2005/09/30 13:59:13 dedekind Exp $
1313
*
1414
*/
1515

@@ -30,6 +30,9 @@
3030
static unsigned char *brokenbuf;
3131
#endif
3232

33+
#define PAGE_DIV(x) ( ((unsigned long)(x) / (unsigned long)(c->wbuf_pagesize)) * (unsigned long)(c->wbuf_pagesize) )
34+
#define PAGE_MOD(x) ( (unsigned long)(x) % (unsigned long)(c->wbuf_pagesize) )
35+
3336
/* max. erase failures before we mark a block bad */
3437
#define MAX_ERASE_FAILURES 2
3538

@@ -433,7 +436,7 @@ static int __jffs2_flush_wbuf(struct jffs2_sb_info *c, int pad)
433436
if we have a switch to next page, we will not have
434437
enough remaining space for this.
435438
*/
436-
if (pad && !jffs2_dataflash(c)) {
439+
if (pad ) {
437440
c->wbuf_len = PAD(c->wbuf_len);
438441

439442
/* Pad with JFFS2_DIRTY_BITMASK initially. this helps out ECC'd NOR
@@ -482,9 +485,9 @@ static int __jffs2_flush_wbuf(struct jffs2_sb_info *c, int pad)
482485
}
483486

484487
spin_lock(&c->erase_completion_lock);
485-
488+
486489
/* Adjust free size of the block if we padded. */
487-
if (pad && !jffs2_dataflash(c)) {
490+
if (pad) {
488491
struct jffs2_eraseblock *jeb;
489492

490493
jeb = &c->blocks[c->wbuf_ofs / c->sector_size];
@@ -601,15 +604,6 @@ int jffs2_flush_wbuf_pad(struct jffs2_sb_info *c)
601604

602605
return ret;
603606
}
604-
605-
#ifdef CONFIG_JFFS2_FS_WRITEBUFFER
606-
#define PAGE_DIV(x) ( ((unsigned long)(x) / (unsigned long)(c->wbuf_pagesize)) * (unsigned long)(c->wbuf_pagesize) )
607-
#define PAGE_MOD(x) ( (unsigned long)(x) % (unsigned long)(c->wbuf_pagesize) )
608-
#else
609-
#define PAGE_DIV(x) ( (x) & (~(c->wbuf_pagesize - 1)) )
610-
#define PAGE_MOD(x) ( (x) & (c->wbuf_pagesize - 1) )
611-
#endif
612-
613607
int jffs2_flash_writev(struct jffs2_sb_info *c, const struct kvec *invecs, unsigned long count, loff_t to, size_t *retlen, uint32_t ino)
614608
{
615609
struct kvec outvecs[3];
@@ -1203,14 +1197,38 @@ int jffs2_dataflash_setup(struct jffs2_sb_info *c) {
12031197

12041198
/* Initialize write buffer */
12051199
init_rwsem(&c->wbuf_sem);
1206-
c->wbuf_pagesize = c->sector_size;
1207-
c->wbuf_ofs = 0xFFFFFFFF;
1200+
1201+
1202+
c->wbuf_pagesize = c->mtd->erasesize;
1203+
1204+
/* Find a suitable c->sector_size
1205+
* - Not too much sectors
1206+
* - Sectors have to be at least 4 K + some bytes
1207+
* - All known dataflashes have erase sizes of 528 or 1056
1208+
* - we take at least 8 eraseblocks and want to have at least 8K size
1209+
* - The concatenation should be a power of 2
1210+
*/
1211+
1212+
c->sector_size = 8 * c->mtd->erasesize;
1213+
1214+
while (c->sector_size < 8192) {
1215+
c->sector_size *= 2;
1216+
}
1217+
1218+
/* It may be necessary to adjust the flash size */
1219+
c->flash_size = c->mtd->size;
12081220

1221+
if ((c->flash_size % c->sector_size) != 0) {
1222+
c->flash_size = (c->flash_size / c->sector_size) * c->sector_size;
1223+
printk(KERN_WARNING "JFFS2 flash size adjusted to %dKiB\n", c->flash_size);
1224+
};
1225+
1226+
c->wbuf_ofs = 0xFFFFFFFF;
12091227
c->wbuf = kmalloc(c->wbuf_pagesize, GFP_KERNEL);
12101228
if (!c->wbuf)
12111229
return -ENOMEM;
12121230

1213-
printk(KERN_INFO "JFFS2 write-buffering enabled (%i)\n", c->wbuf_pagesize);
1231+
printk(KERN_INFO "JFFS2 write-buffering enabled buffer (%d) erasesize (%d)\n", c->wbuf_pagesize, c->sector_size);
12141232

12151233
return 0;
12161234
}

0 commit comments

Comments
 (0)