Merge git://git.infradead.org/mtd-2.6

* git://git.infradead.org/mtd-2.6:
[JFFS2] print a message when marking bad block
[JFFS2] Check for all-zero node headers
[MTD] [OneNAND] Classify the page data and oob buffer
[MTD] [OneNAND] Exit the loop when transferring/filling of the oob is finished
[MTD] [OneNAND] add Nokia Copyright and a credit
[MTD] [OneNAND] Fix typo & wrong comments
[MTD] [OneNAND] Use oob buffer instead of main one in oob functions
[MTD] Correct partition failed erase address
[JFFS2] Use yield() between GC passes in background thread.
[MTD] [NAND] Correct misspelled preprocessor variable.
[MTD] [MAPS] dilnetpc: Fix printk warning
[MTD] [NOR] Fix oops in cfi_amdstd_sync
[MTD] ESB2 check for closed ROM window
[JFFS2] Fix writebuffer recovery in the first page of a block
[MTD] [NAND] make oobavail public

+115 -38
+2
drivers/mtd/chips/cfi_cmdset_0002.c
··· 359 359 cfi->chips[i].word_write_time = 1<<cfi->cfiq->WordWriteTimeoutTyp; 360 360 cfi->chips[i].buffer_write_time = 1<<cfi->cfiq->BufWriteTimeoutTyp; 361 361 cfi->chips[i].erase_time = 1<<cfi->cfiq->BlockEraseTimeoutTyp; 362 + cfi->chips[i].ref_point_counter = 0; 363 + init_waitqueue_head(&(cfi->chips[i].wq)); 362 364 } 363 365 364 366 map->fldrv = &cfi_amdstd_chipdrv;
+2
drivers/mtd/chips/cfi_cmdset_0020.c
··· 158 158 cfi->chips[i].word_write_time = 128; 159 159 cfi->chips[i].buffer_write_time = 128; 160 160 cfi->chips[i].erase_time = 1024; 161 + cfi->chips[i].ref_point_counter = 0; 162 + init_waitqueue_head(&(cfi->chips[i].wq)); 161 163 } 162 164 163 165 return cfi_staa_setup(map);
+2 -2
drivers/mtd/maps/dilnetpc.c
··· 402 402 ++higlvl_partition_info[i].name; 403 403 } 404 404 405 - printk(KERN_NOTICE "DIL/Net %s flash: 0x%lx at 0x%lx\n", 406 - is_dnp ? "DNPC" : "ADNP", dnpc_map.size, dnpc_map.phys); 405 + printk(KERN_NOTICE "DIL/Net %s flash: 0x%lx at 0x%llx\n", 406 + is_dnp ? "DNPC" : "ADNP", dnpc_map.size, (unsigned long long)dnpc_map.phys); 407 407 408 408 dnpc_map.virt = ioremap_nocache(dnpc_map.phys, dnpc_map.size); 409 409
+8 -3
drivers/mtd/maps/esb2rom.c
··· 30 30 31 31 #define ROM_PROBE_STEP_SIZE (64*1024) /* 64KiB */ 32 32 33 - #define BIOS_CNTL 0xDC 33 + #define BIOS_CNTL 0xDC 34 34 #define BIOS_LOCK_ENABLE 0x02 35 35 #define BIOS_WRITE_ENABLE 0x01 36 36 ··· 145 145 } 146 146 147 147 static int __devinit esb2rom_init_one(struct pci_dev *pdev, 148 - const struct pci_device_id *ent) 148 + const struct pci_device_id *ent) 149 149 { 150 150 static char *rom_probe_types[] = { "cfi_probe", "jedec_probe", NULL }; 151 151 struct esb2rom_window *window = &esb2rom_window; ··· 185 185 /* Find a region continuous to the end of the ROM window */ 186 186 window->phys = 0; 187 187 pci_read_config_word(pdev, FWH_DEC_EN1, &word); 188 - printk(KERN_DEBUG "pci_read_config_byte : %x\n", word); 188 + printk(KERN_DEBUG "pci_read_config_word : %x\n", word); 189 189 190 190 if ((word & FWH_8MiB) == FWH_8MiB) 191 191 window->phys = 0xff400000; ··· 211 211 window->phys = 0xfff00000; 212 212 else if ((word & FWH_0_5MiB) == FWH_0_5MiB) 213 213 window->phys = 0xfff80000; 214 + 215 + if (window->phys == 0) { 216 + printk(KERN_ERR MOD_NAME ": Rom window is closed\n"); 217 + goto out; 218 + } 214 219 215 220 /* reserved 0x0020 and 0x0010 */ 216 221 window->phys -= 0x400000UL;
+1
drivers/mtd/mtdconcat.c
··· 727 727 concat->mtd.erasesize = subdev[0]->erasesize; 728 728 concat->mtd.writesize = subdev[0]->writesize; 729 729 concat->mtd.oobsize = subdev[0]->oobsize; 730 + concat->mtd.oobavail = subdev[0]->oobavail; 730 731 if (subdev[0]->writev) 731 732 concat->mtd.writev = concat_writev; 732 733 if (subdev[0]->read_oob)
+6 -1
drivers/mtd/mtdpart.c
··· 200 200 return -EINVAL; 201 201 instr->addr += part->offset; 202 202 ret = part->master->erase(part->master, instr); 203 + if (ret) { 204 + if (instr->fail_addr != 0xffffffff) 205 + instr->fail_addr -= part->offset; 206 + instr->addr -= part->offset; 207 + } 203 208 return ret; 204 209 } 205 210 ··· 343 338 slave->mtd.size = parts[i].size; 344 339 slave->mtd.writesize = master->writesize; 345 340 slave->mtd.oobsize = master->oobsize; 341 + slave->mtd.oobavail = master->oobavail; 346 342 slave->mtd.subpage_sft = master->subpage_sft; 347 343 348 344 slave->mtd.name = parts[i].name; ··· 565 559 MODULE_LICENSE("GPL"); 566 560 MODULE_AUTHOR("Nicolas Pitre <nico@cam.org>"); 567 561 MODULE_DESCRIPTION("Generic support for partitioning of MTD devices"); 568 -
+1 -1
drivers/mtd/nand/diskonchip.c
··· 114 114 static int show_firmware_partition = 0; 115 115 module_param(show_firmware_partition, int, 0); 116 116 117 - #ifdef MTD_NAND_DISKONCHIP_BBTWRITE 117 + #ifdef CONFIG_MTD_NAND_DISKONCHIP_BBTWRITE 118 118 static int inftl_bbt_write = 1; 119 119 #else 120 120 static int inftl_bbt_write = 0;
+1
drivers/mtd/nand/nand_base.c
··· 2524 2524 for (i = 0; chip->ecc.layout->oobfree[i].length; i++) 2525 2525 chip->ecc.layout->oobavail += 2526 2526 chip->ecc.layout->oobfree[i].length; 2527 + mtd->oobavail = chip->ecc.layout->oobavail; 2527 2528 2528 2529 /* 2529 2530 * Set the number of read / write steps for one page depending on ECC
+51 -26
drivers/mtd/onenand/onenand_base.c
··· 4 4 * Copyright (C) 2005-2007 Samsung Electronics 5 5 * Kyungmin Park <kyungmin.park@samsung.com> 6 6 * 7 + * Credits: 8 + * Adrian Hunter <ext-adrian.hunter@nokia.com>: 9 + * auto-placement support, read-while load support, various fixes 10 + * Copyright (C) Nokia Corporation, 2007 11 + * 7 12 * This program is free software; you can redistribute it and/or modify 8 13 * it under the terms of the GNU General Public License version 2 as 9 14 * published by the Free Software Foundation. ··· 836 831 int readcol = column; 837 832 int readend = column + thislen; 838 833 int lastgap = 0; 839 - uint8_t *oob_buf = this->page_buf + mtd->writesize; 834 + uint8_t *oob_buf = this->oob_buf; 840 835 841 836 for (free = this->ecclayout->oobfree; free->length; ++free) { 842 837 if (readcol >= lastgap) ··· 854 849 int n = ed - st; 855 850 memcpy(buf, oob_buf + st, n); 856 851 buf += n; 857 - } 852 + } else 853 + break; 858 854 } 859 855 return 0; 860 856 } ··· 953 947 954 948 /** 955 949 * onenand_read_oob - [MTD Interface] NAND write data and/or out-of-band 956 - * @mtd: MTD device structure 957 - * @from: offset to read from 958 - * @ops: oob operation description structure 950 + * @param mtd: MTD device structure 951 + * @param from: offset to read from 952 + * @param ops: oob operation description structure 959 953 */ 960 954 static int onenand_read_oob(struct mtd_info *mtd, loff_t from, 961 955 struct mtd_oob_ops *ops) ··· 1023 1017 * onenand_bbt_read_oob - [MTD Interface] OneNAND read out-of-band for bbt scan 1024 1018 * @param mtd MTD device structure 1025 1019 * @param from offset to read from 1026 - * @param @ops oob operation description structure 1020 + * @param ops oob operation description structure 1027 1021 * 1028 1022 * OneNAND read out-of-band data from the spare area for bbt scan 1029 1023 */ ··· 1099 1093 static int onenand_verify_oob(struct mtd_info *mtd, const u_char *buf, loff_t to) 1100 1094 { 1101 1095 struct onenand_chip *this = mtd->priv; 1102 - char *readp = this->page_buf + mtd->writesize; 1096 + char oobbuf[64]; 1103 1097 int status, i; 1104 1098 1105 1099 this->command(mtd, ONENAND_CMD_READOOB, to, mtd->oobsize); ··· 1108 1102 if (status) 1109 1103 return status; 1110 1104 1111 - this->read_bufferram(mtd, ONENAND_SPARERAM, readp, 0, mtd->oobsize); 1112 - for(i = 0; i < mtd->oobsize; i++) 1113 - if (buf[i] != 0xFF && buf[i] != readp[i]) 1105 + this->read_bufferram(mtd, ONENAND_SPARERAM, oobbuf, 0, mtd->oobsize); 1106 + for (i = 0; i < mtd->oobsize; i++) 1107 + if (buf[i] != 0xFF && buf[i] != oobbuf[i]) 1114 1108 return -EBADMSG; 1115 1109 1116 1110 return 0; ··· 1296 1290 int n = ed - st; 1297 1291 memcpy(oob_buf + st, buf, n); 1298 1292 buf += n; 1299 - } 1293 + } else 1294 + break; 1300 1295 } 1301 1296 return 0; 1302 1297 } ··· 1319 1312 struct onenand_chip *this = mtd->priv; 1320 1313 int column, ret = 0, oobsize; 1321 1314 int written = 0; 1315 + u_char *oobbuf; 1322 1316 1323 1317 DEBUG(MTD_DEBUG_LEVEL3, "onenand_write_oob: to = 0x%08x, len = %i\n", (unsigned int) to, (int) len); 1324 1318 ··· 1339 1331 } 1340 1332 1341 1333 /* For compatibility with NAND: Do not allow write past end of page */ 1342 - if (column + len > oobsize) { 1334 + if (unlikely(column + len > oobsize)) { 1343 1335 printk(KERN_ERR "onenand_write_oob: " 1344 1336 "Attempt to write past end of page\n"); 1345 1337 return -EINVAL; ··· 1356 1348 /* Grab the lock and see if the device is available */ 1357 1349 onenand_get_device(mtd, FL_WRITING); 1358 1350 1351 + oobbuf = this->oob_buf; 1352 + 1359 1353 /* Loop until all data write */ 1360 1354 while (written < len) { 1361 1355 int thislen = min_t(int, oobsize, len - written); ··· 1368 1358 1369 1359 /* We send data to spare ram with oobsize 1370 1360 * to prevent byte access */ 1371 - memset(this->page_buf, 0xff, mtd->oobsize); 1361 + memset(oobbuf, 0xff, mtd->oobsize); 1372 1362 if (mode == MTD_OOB_AUTO) 1373 - onenand_fill_auto_oob(mtd, this->page_buf, buf, column, thislen); 1363 + onenand_fill_auto_oob(mtd, oobbuf, buf, column, thislen); 1374 1364 else 1375 - memcpy(this->page_buf + column, buf, thislen); 1376 - this->write_bufferram(mtd, ONENAND_SPARERAM, this->page_buf, 0, mtd->oobsize); 1365 + memcpy(oobbuf + column, buf, thislen); 1366 + this->write_bufferram(mtd, ONENAND_SPARERAM, oobbuf, 0, mtd->oobsize); 1377 1367 1378 1368 this->command(mtd, ONENAND_CMD_PROGOOB, to, mtd->oobsize); 1379 1369 ··· 1385 1375 break; 1386 1376 } 1387 1377 1388 - ret = onenand_verify_oob(mtd, this->page_buf, to); 1378 + ret = onenand_verify_oob(mtd, oobbuf, to); 1389 1379 if (ret) { 1390 1380 printk(KERN_ERR "onenand_write_oob: verify failed %d\n", ret); 1391 1381 break; ··· 1410 1400 1411 1401 /** 1412 1402 * onenand_write_oob - [MTD Interface] NAND write data and/or out-of-band 1413 - * @mtd: MTD device structure 1414 - * @from: offset to read from 1415 - * @ops: oob operation description structure 1403 + * @param mtd: MTD device structure 1404 + * @param to: offset to write 1405 + * @param ops: oob operation description structure 1416 1406 */ 1417 1407 static int onenand_write_oob(struct mtd_info *mtd, loff_t to, 1418 1408 struct mtd_oob_ops *ops) ··· 1626 1616 * @param mtd MTD device structure 1627 1617 * @param ofs offset relative to mtd start 1628 1618 * @param len number of bytes to lock or unlock 1619 + * @param cmd lock or unlock command 1629 1620 * 1630 1621 * Lock or unlock one or more blocks 1631 1622 */ ··· 2128 2117 } 2129 2118 2130 2119 /** 2131 - * onenand_print_device_info - Print device ID 2120 + * onenand_print_device_info - Print device & version ID 2132 2121 * @param device device ID 2122 + * @param version version ID 2133 2123 * 2134 - * Print device ID 2124 + * Print device & version ID 2135 2125 */ 2136 2126 static void onenand_print_device_info(int device, int version) 2137 2127 { ··· 2332 2320 2333 2321 /* Allocate buffers, if necessary */ 2334 2322 if (!this->page_buf) { 2335 - size_t len; 2336 - len = mtd->writesize + mtd->oobsize; 2337 - this->page_buf = kmalloc(len, GFP_KERNEL); 2323 + this->page_buf = kzalloc(mtd->writesize, GFP_KERNEL); 2338 2324 if (!this->page_buf) { 2339 2325 printk(KERN_ERR "onenand_scan(): Can't allocate page_buf\n"); 2340 2326 return -ENOMEM; 2341 2327 } 2342 2328 this->options |= ONENAND_PAGEBUF_ALLOC; 2329 + } 2330 + if (!this->oob_buf) { 2331 + this->oob_buf = kzalloc(mtd->oobsize, GFP_KERNEL); 2332 + if (!this->oob_buf) { 2333 + printk(KERN_ERR "onenand_scan(): Can't allocate oob_buf\n"); 2334 + if (this->options & ONENAND_PAGEBUF_ALLOC) { 2335 + this->options &= ~ONENAND_PAGEBUF_ALLOC; 2336 + kfree(this->page_buf); 2337 + } 2338 + return -ENOMEM; 2339 + } 2340 + this->options |= ONENAND_OOBBUF_ALLOC; 2343 2341 } 2344 2342 2345 2343 this->state = FL_READY; ··· 2389 2367 for (i = 0; this->ecclayout->oobfree[i].length; i++) 2390 2368 this->ecclayout->oobavail += 2391 2369 this->ecclayout->oobfree[i].length; 2370 + mtd->oobavail = this->ecclayout->oobavail; 2392 2371 2393 2372 mtd->ecclayout = this->ecclayout; 2394 2373 ··· 2447 2424 kfree(bbm->bbt); 2448 2425 kfree(this->bbm); 2449 2426 } 2450 - /* Buffer allocated by onenand_scan */ 2427 + /* Buffers allocated by onenand_scan */ 2451 2428 if (this->options & ONENAND_PAGEBUF_ALLOC) 2452 2429 kfree(this->page_buf); 2430 + if (this->options & ONENAND_OOBBUF_ALLOC) 2431 + kfree(this->oob_buf); 2453 2432 } 2454 2433 2455 2434 EXPORT_SYMBOL_GPL(onenand_scan);
+7 -1
fs/jffs2/background.c
··· 99 99 if (try_to_freeze()) 100 100 continue; 101 101 102 - cond_resched(); 102 + /* This thread is purely an optimisation. But if it runs when 103 + other things could be running, it actually makes things a 104 + lot worse. Use yield() and put it at the back of the runqueue 105 + every time. Especially during boot, pulling an inode in 106 + with read_inode() is much preferable to having the GC thread 107 + get there first. */ 108 + yield(); 103 109 104 110 /* Put_super will send a SIGKILL and then wait on the sem. 105 111 */
+15 -1
fs/jffs2/readinode.c
··· 373 373 static inline int read_unknown(struct jffs2_sb_info *c, struct jffs2_raw_node_ref *ref, struct jffs2_unknown_node *un) 374 374 { 375 375 /* We don't mark unknown nodes as REF_UNCHECKED */ 376 - BUG_ON(ref_flags(ref) == REF_UNCHECKED); 376 + if (ref_flags(ref) == REF_UNCHECKED) { 377 + JFFS2_ERROR("REF_UNCHECKED but unknown node at %#08x\n", 378 + ref_offset(ref)); 379 + JFFS2_ERROR("Node is {%04x,%04x,%08x,%08x}. Please report this error.\n", 380 + je16_to_cpu(un->magic), je16_to_cpu(un->nodetype), 381 + je32_to_cpu(un->totlen), je32_to_cpu(un->hdr_crc)); 382 + return 1; 383 + } 377 384 378 385 un->nodetype = cpu_to_je16(JFFS2_NODE_ACCURATE | je16_to_cpu(un->nodetype)); 379 386 ··· 580 573 je32_to_cpu(node->u.totlen), 581 574 je32_to_cpu(node->u.hdr_crc)); 582 575 jffs2_dbg_dump_node(c, ref_offset(ref)); 576 + jffs2_mark_node_obsolete(c, ref); 577 + goto cont; 578 + } 579 + /* Due to poor choice of crc32 seed, an all-zero node will have a correct CRC */ 580 + if (!je32_to_cpu(node->u.hdr_crc) && !je16_to_cpu(node->u.nodetype) && 581 + !je16_to_cpu(node->u.magic) && !je32_to_cpu(node->u.totlen)) { 582 + JFFS2_NOTICE("All zero node header at %#08x.\n", ref_offset(ref)); 583 583 jffs2_mark_node_obsolete(c, ref); 584 584 goto cont; 585 585 }
+9
fs/jffs2/scan.c
··· 734 734 ofs += 4; 735 735 continue; 736 736 } 737 + /* Due to poor choice of crc32 seed, an all-zero node will have a correct CRC */ 738 + if (!je32_to_cpu(node->hdr_crc) && !je16_to_cpu(node->nodetype) && 739 + !je16_to_cpu(node->magic) && !je32_to_cpu(node->totlen)) { 740 + noisy_printk(&noise, "jffs2_scan_eraseblock(): All zero node header at 0x%08x.\n", ofs); 741 + if ((err = jffs2_scan_dirty_space(c, jeb, 4))) 742 + return err; 743 + ofs += 4; 744 + continue; 745 + } 737 746 738 747 if (ofs + je32_to_cpu(node->totlen) > 739 748 jeb->offset + c->sector_size) {
+5 -2
fs/jffs2/wbuf.c
··· 238 238 jeb = &c->blocks[c->wbuf_ofs / c->sector_size]; 239 239 240 240 spin_lock(&c->erase_completion_lock); 241 - jffs2_block_refile(c, jeb, REFILE_NOTEMPTY); 241 + if (c->wbuf_ofs % c->mtd->erasesize) 242 + jffs2_block_refile(c, jeb, REFILE_NOTEMPTY); 243 + else 244 + jffs2_block_refile(c, jeb, REFILE_ANYWAY); 242 245 spin_unlock(&c->erase_completion_lock); 243 246 244 247 BUG_ON(!ref_obsolete(jeb->last_node)); ··· 1090 1087 if (!c->mtd->block_markbad) 1091 1088 return 1; // What else can we do? 1092 1089 1093 - D1(printk(KERN_WARNING "jffs2_write_nand_badblock(): Marking bad block at %08x\n", bad_offset)); 1090 + printk(KERN_WARNING "JFFS2: marking eraseblock at %08x\n as bad", bad_offset); 1094 1091 ret = c->mtd->block_markbad(c->mtd, bad_offset); 1095 1092 1096 1093 if (ret) {
+1
include/linux/mtd/mtd.h
··· 121 121 u_int32_t writesize; 122 122 123 123 u_int32_t oobsize; // Amount of OOB data per block (e.g. 16) 124 + u_int32_t oobavail; // Available OOB bytes per block 124 125 125 126 // Kernel-only stuff starts here. 126 127 char *name;
+4 -1
include/linux/mtd/onenand.h
··· 82 82 * @wq: [INTERN] wait queue to sleep on if a OneNAND 83 83 * operation is in progress 84 84 * @state: [INTERN] the current state of the OneNAND device 85 - * @page_buf: data buffer 85 + * @page_buf: [INTERN] page main data buffer 86 + * @oob_buf: [INTERN] page oob data buffer 86 87 * @subpagesize: [INTERN] holds the subpagesize 87 88 * @ecclayout: [REPLACEABLE] the default ecc placement scheme 88 89 * @bbm: [REPLACEABLE] pointer to Bad Block Management ··· 123 122 wait_queue_head_t wq; 124 123 onenand_state_t state; 125 124 unsigned char *page_buf; 125 + unsigned char *oob_buf; 126 126 127 127 int subpagesize; 128 128 struct nand_ecclayout *ecclayout; ··· 158 156 #define ONENAND_HAS_CONT_LOCK (0x0001) 159 157 #define ONENAND_HAS_UNLOCK_ALL (0x0002) 160 158 #define ONENAND_PAGEBUF_ALLOC (0x1000) 159 + #define ONENAND_OOBBUF_ALLOC (0x2000) 161 160 162 161 /* 163 162 * OneNAND Flash Manufacturer ID Codes