summaryrefslogtreecommitdiff
path: root/drivers/mtd/nand/nand_util.c
Commit message (Collapse)AuthorAgeLines
* nand_util.c: Use '%zd' for length in nand_unlock debug printTom Rini2013-12-17-1/+1
| | | | | | | length is size_t so needs to be '%zd' not '%d' to avoid warnings. Cc: Scott Wood <scottwood@freescale.com> Signed-off-by: Tom Rini <trini@ti.com>
* nand_util.c: Correct licensingTom Rini2013-10-31-1/+3
| | | | | | | | | | | Prior to SPDX licensing this file was GPL-2.0 with Freescale granting rights for "or later" for their contributed code. We incorrectly moved this file to GPL-2.0+, so correct it to GPL-2.0. In addition we cannot easily denote in the file where or what code is "or later", so just set that aside for now and the file as a whole is GPL-2.0 regardless. Cc: Scott Wood <scottwood@freescale.com> Signed-off-by: Tom Rini <trini@ti.com>
* Coding Style cleanup: replace leading SPACEs by TABsWolfgang Denk2013-10-14-2/+2
| | | | | | Signed-off-by: Wolfgang Denk <wd@denx.de> [trini: Drop changes for PEP 4 following python tools] Signed-off-by: Tom Rini <trini@ti.com>
* nand_util: delete a useless variableMasahiro Yamada2013-08-22-2/+1
| | | | Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
* Add GPL-2.0+ SPDX-License-Identifier to source filesWolfgang Denk2013-07-24-23/+1
| | | | | | Signed-off-by: Wolfgang Denk <wd@denx.de> [trini: Fixup common/cmd_io.c] Signed-off-by: Tom Rini <trini@ti.com>
* dfu, nand: before write a buffer to nand, erase the nand sectorsHeiko Schocher2013-06-24-0/+4
| | | | | | | | | | | | | | | | | | | | | | before writing the received buffer to nand, erase the nand sectors. If not doing this, nand write fails. See for more info here: http://lists.denx.de/pipermail/u-boot/2013-June/156361.html Using the nand erase option "spread", maybe overwrite blocks on, for example another mtd partition, if the erasing range contains bad blocks. So a limit option is added to nand_erase_opts() Signed-off-by: Heiko Schocher <hs@denx.de> Cc: Scott Wood <scottwood@freescale.com> Cc: Pantelis Antoniou <panto@antoniou-consulting.com> Cc: Lukasz Majewski <l.majewski@samsung.com> Cc: Kyungmin Park <kyungmin.park@samsung.com> Cc: Marek Vasut <marex@denx.de> Cc: Tom Rini <trini@ti.com> Signed-off-by: Scott Wood <scottwood@freescale.com>
* mtd: resync with Linux-3.7.1Sergey Lapin2013-05-31-11/+12
| | | | | | | | | | | | | | | | | | | | | | This patch is essentially an update of u-boot MTD subsystem to the state of Linux-3.7.1 with exclusion of some bits: - the update is concentrated on NAND, no onenand or CFI/NOR/SPI flashes interfaces are updated EXCEPT for API changes. - new large NAND chips support is there, though some updates have got in Linux-3.8.-rc1, (which will follow on top of this patch). To produce this update I used tag v3.7.1 of linux-stable repository. The update was made using application of relevant patches, with changes relevant to U-Boot-only stuff sticked together to keep bisectability. Then all changes were grouped together to this patch. Signed-off-by: Sergey Lapin <slapin@ossfans.org> [scottwood@freescale.com: some eccstrength and build fixes] Signed-off-by: Scott Wood <scottwood@freescale.com>
* mtd: nand: use ssize_t instead of size_t to prevent infinite loophtbegin2013-05-22-1/+2
| | | | | | | | | | | When a all 0xFF buffer is passed to drop_ffs, the no-0xFF check loop will loop forever. After the fix, If ssize_t i = -1 and size_t l = i + 1, the value of l will still be 0 as expected. Signed-off-by: Tao Hou <hotforest@gmail.com> Cc: Ben Gardiner <bengardiner@nanometrics.ca> Cc: Scott Wood <scottwood@freescale.com>
* nand: Extend nand_(read|write)_skip_bad with *actual and limit parametersTom Rini2013-04-10-8/+60
| | | | | | | | | | | | | | | | | We make these two functions take a size_t pointer to how much space was used on NAND to read or write the buffer (when reads/writes happen) so that bad blocks can be accounted for. We also make them take an loff_t limit on how much data can be read or written. This means that we can now catch the case of when writing to a partition would exceed the partition size due to bad blocks. To do this we also need to make check_skip_len count not just complete blocks used but partial ones as well. All callers of nand_(read|write)_skip_bad are adjusted to call these with the most sensible limits available. The changes were started by Pantelis and finished by Tom. Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com> Signed-off-by: Tom Rini <trini@ti.com>
* mtd: nand: Check if NAND is locked tight before lock cmdsJoe Hershberger2013-02-22-1/+18
| | | | | | | | | If the NAND is locked tight, commands such as lock and unlock will not work, but the NAND chip may not report an error. Check the lock tight status before attempting such operations so that an error status can be reported if we know the operation will not succeed. Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
* nand: Add torture featureBenoît Thébaudeau2012-11-26-0/+122
| | | | | | | | | | | | | This patch adds a NAND Flash torture feature, which is useful as a block stress test to determine if a block is still good and reliable (or should be marked as bad), e.g. after a write error. This code is ported from mtd-utils' lib/libmtd.c. Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com> Cc: Scott Wood <scottwood@freescale.com> [scottwood@freescale.com: removed unnec. ifdef and unwrapped error strings] Signed-off-by: Scott Wood <scottwood@freescale.com>
* nand: Fix nand_erase_opts() offset checkBenoît Thébaudeau2012-11-26-2/+2
| | | | | | | NAND Flash is erased by blocks, not by pages. Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com> Cc: Scott Wood <scottwood@freescale.com>
* nand: Clean up nand_utilBenoît Thébaudeau2012-11-26-32/+32
| | | | | | | | | | | This patch cleans up nand_util.c: - Fix tabs. - Fix typos. - Remove space character before opening parenthesis in function calls. - Fix comments. Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com> Cc: Scott Wood <scottwood@freescale.com>
* nand: Make NAND lock status compatible with MicronJoe Hershberger2012-09-17-2/+0
| | | | | | | | | | Micron NAND flash (e.g. MT29F4G08ABADAH4) BLOCK LOCK READ STATUS is not the same as others. Instead of bit 1 being lock, it is #lock_tight. To make the driver support either format, ignore bit 1 and use only bit 0 and bit 2. Signed-off-by: Joe Hershberger <joe.hershberger@ni.com> Signed-off-by: Scott Wood <scottwood@freescale.com>
* nand: consolidate duplicated constantsJoe Hershberger2012-09-17-6/+0
| | | | | | | NAND_CMD_ constants for lock/unlock should be in the header Signed-off-by: Joe Hershberger <joe.hershberger@ni.com> Signed-off-by: Scott Wood <scottwood@freescale.com>
* nand: Change ulong to loff_t and size_tJoe Hershberger2012-09-17-2/+3
| | | | | | | Missed in previous cleanup. Signed-off-by: Joe Hershberger <joe.hershberger@ni.com> Signed-off-by: Scott Wood <scottwood@freescale.com>
* nand: Add support for unlock.invertJoe Hershberger2012-09-17-3/+14
| | | | | | | | | NAND unlock command allows an invert bit to be set to unlock all but the selected page range. Signed-off-by: Joe Hershberger <joe.hershberger@ni.com> [scottwood@freescale.com: updated docs and added comment about invert bit] Signed-off-by: Scott Wood <scottwood@freescale.com>
* nand_util: correct YAFFS image write functionLiu, Wentao2012-05-18-1/+1
| | | | | | | | | | In function nand_write_skip_bad(),for YAFFS filesystem part, write_oob() will return 0 when success, so when rval equals 0, it should continue to write the next page, and no break. Signed-off-by: Wentao, Liu <wentao.liu@intel.com> Acked-by: Lei Wen <leiwen@marvell.com> Signed-off-by: Scott Wood <scott@tyr.buserror.net>
* NAND: Really ignore bad blocks when scrubbingMarek Vasut2011-10-03-21/+8
| | | | | | | | | | Signed-off-by: Marek Vasut <marek.vasut@gmail.com> Cc: Scott Wood <scottwood@freescale.com> Cc: Stefano Babic <sbabic@denx.de> Cc: Wolfgang Denk <wd@denx.de> Cc: Detlev Zundel <dzu@denx.de> [scottwood@freescale.com: use chip instead of redundant priv_nand] Signed-off-by: Scott Wood <scottwood@freescale.com>
* nand_util: drop trailing all-0xff pages if requestedBen Gardiner2011-07-01-3/+37
| | | | | | | | | | | | | | | | | | | | Add a flag to nand_read_skip_bad() such that if true, any trailing pages in an eraseblock whose contents are entirely 0xff will be dropped. The implementation is via a new drop_ffs() function which is based on the function of the same name from the ubiformat utility by Artem Bityutskiy. This is as-per the reccomendations of the UBI FAQ [1] [1] http://www.linux-mtd.infradead.org/doc/ubi.html#L_flasher_algo Signed-off-by: Ben Gardiner <bengardiner@nanometrics.ca> CC: Artem Bityutskiy <dedekind1@gmail.com> Acked-by: Detlev Zundel <dzu@denx.de> CC: Scott Wood <scottwood@freescale.com> Signed-off-by: Scott Wood <scottwood@freescale.com>
* nand_util: treat WITH_YAFFS_OOB as a modeBen Gardiner2011-07-01-0/+3
| | | | | | | | | | | | | When specified in the flags argument of nand_write, WITH_YAFFS_OOB causes an operation which is mutually exclusive with the 'usual' way of writing. Add a check that client code does not specify WITH_YAFFS_OOB along with any other flags and add a comment indicating that the WITH_YAFFS_OOB flag should not be mixed with other flags. Signed-off-by: Ben Gardiner <bengardiner@nanometrics.ca> CC: Scott Wood <scottwood@freescale.com> Signed-off-by: Scott Wood <scottwood@freescale.com>
* nand_util: convert nand_write_skip_bad() to flagsBen Gardiner2011-07-01-4/+4
| | | | | | | | | | | | | | | | | | | | | | In a future commit the behaviour of nand_write_skip_bad() will be further extended. Convert the only flag currently passed to the nand_write_ skip_bad() function to a bitfield of only one allocated member. This should avoid an explosion of int's at the end of the parameter list or the ambiguous calls like nand_write_skip_bad(info, offset, len, buf, 0, 1, 1); nand_write_skip_bad(info, offset, len, buf, 0, 1, 0); Instead there will be: nand_write_skip_bad(info, offset, len, buf, WITH_YAFFS_OOB | WITH_OTHER); Signed-off-by: Ben Gardiner <bengardiner@nanometrics.ca> Acked-by: Detlev Zundel <dzu@denx.de> Signed-off-by: Scott Wood <scottwood@freescale.com>
* NAND: add more watchdog resetsScott Wood2011-04-01-0/+2
| | | | | | | Poke the watchdog in a variety of looping constructs, which could take a long time to complete. Signed-off-by: Scott Wood <scottwood@freescale.com>
* NAND: add the ability to directly write yaffs imageLei Wen2011-01-12-8/+55
| | | | | | | This patch add addition suffix to nand write to give the uboot the power to directly burn the yaffs image to nand. Signed-off-by: Lei Wen <leiwen@marvell.com>
* nand: remove dead code and suspend/resumeScott Wood2010-10-11-35/+0
| | | | | | | | | | | | | | | Get rid of the several "#if 0" sections that were keeping around Linux code that isn't relevant to U-Boot. Besides cluttering the code, these sections make tracking upstream changes harder, rather than easier. It's easy to discard obviously irrelevant diff hunks that patch rejects, but it's not as easy to notice hunks that apply cleanly to the #if 0 section, but *are* relevant to U-Boot and require modification elsewhere. Also remove suspend/resume, as this is not applicable to U-Boot. Removal saves 232 bytes on powerpc. Signed-off-by: Scott Wood <scottwood@freescale.com> Tested-by: Ben Gardiner <bengardiner@nanometrics.ca>
* nand erase: .spread, .part, .chip subcommandsScott Wood2010-10-11-14/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A while back, in http://lists.denx.de/pipermail/u-boot/2009-June/054428.html, Michele De Candia posted a patch to not count bad blocks toward the requested size to be erased. This is desireable when you're passing in something like $filesize, but not when you're trying to erase a partition. Thus, a .spread subcommand (named for consistency with http://lists.denx.de/pipermail/u-boot/2010-August/075163.html) is introduced to make explicit the user's desire to erase for a given amount of data, rather than to erase a specific region of the chip. While passing $filesize to "nand erase" is useful, accidentally passing something like $fliesize currently produces quite unpleasant results, as the variable evaluates to nothing and U-Boot assumes that you want to erase the entire rest of the chip/partition. To improve the safety of the erase command, require the user to make explicit their intentions by using a .part or .chip subcommand. This is an incompatible user interface change, but keeping compatibility would eliminate the safety gain, and IMHO it's worth it. While touching nand_erase_opts(), make it accept 64-bit offsets and sizes, fix the percentage display when erase length is rounded up, eliminate an inconsistent warning about rounding up the erase length which only happened when the length was less than one block (rounding up for $filesize is normal operation), and add a diagnostic if there's an attempt to erase beginning at a non-block boundary. Signed-off-by: Scott Wood <scottwood@freescale.com> Tested-by: Ben Gardiner <bengardiner@nanometrics.ca>
* nand util: read/write: accept unaligned lengthScott Wood2010-10-11-30/+63
| | | | | | | | | | | | | | | | The underlying code in nand_base.c already supports non-page-aligned reads and writes, but the block-skipping wrapper code did not. With block skipping, an unaligned start address is not useful since you really want to be starting at the beginning of a partition -- or at least that's where you want to start checking for blocks to skip, but we don't (yet) support that. So we still require the start address to be aligned. An unaligned length, though, is useful for passing $filesize to the read/write command, and handling it does not complicate block skipping. Signed-off-by: Scott Wood <scottwood@freescale.com> Tested-by: Ben Gardiner <bengardiner@nanometrics.ca>
* Merge branch 'next' of ../nextWolfgang Denk2009-12-15-4/+0
|\
| * common: delete CONFIG_SYS_64BIT_VSPRINTF and CONFIG_SYS_64BIT_STRTOULHeiko Schocher2009-12-08-4/+0
| | | | | | | | | | | | | | | | | | There is more and more usage of printing 64bit values, so enable this feature generally, and delete the CONFIG_SYS_64BIT_VSPRINTF and CONFIG_SYS_64BIT_STRTOUL defines. Signed-off-by: Heiko Schocher <hs@denx.de>
* | nand: Fix access to last block in NAND devicesStefan Roese2009-12-11-2/+2
|/ | | | | | | | | Currently, the last block of NAND devices can't be accessed. This patch fixes this issue by correcting the boundary checking (off-by-one error). Signed-off-by: Stefan Roese <sr@denx.de> Cc: Scott Wood <scottwood@freescale.com> Cc: Wolfgang Denk <wd@denx.de>
* Fix computation in nand_util.c:get_len_incl_badDaniel Hobi2009-12-07-1/+1
| | | | | | | | | | | | | | | Depending on offset, flash size and the number of bad blocks, get_len_incl_bad may return a too small value which may lead to: 1) If there are no bad blocks, nand_{read,write}_skip_bad chooses the bad block aware read/write code. This may hurt performance, but does not have any adverse effects. 2) If there are bad blocks, the nand_{read,write}_skip_bad may choose the bad block unaware read/write code (if len_incl_bad == *length) which leads to corrupted data. Signed-off-by: Daniel Hobi <daniel.hobi@schmid-telecom.ch>
* add WATCHDOG_RESET() on nand write and readGiulio Benetti2009-08-21-0/+4
| | | | | | Signed-off-by: giulio.benetti@micronovasrl.com Acked-by: Wolfgang Denk <wd@denx.de> Signed-off-by: Scott Wood <scottwood@freescale.com>
* nand: fixed failed reads on corrected ECC errors in nand_util.cValeriy Glushkov2009-07-16-5/+5
| | | | | | Signed-off-by: Valeriy Glushkov <gvv@lstec.com> Signed-off-by: Paulraj, Sandeep <s-paulraj@ti.com> Signed-off-by: Scott Wood <scottwood@freescale.com>
* mtd: nand: use loff_t for offsetJean-Christophe PLAGNIOL-VILLARD2009-07-07-10/+10
| | | | | | | | nand_util currently uses size_t which is arch dependent and not always a unsigned long. Now use loff_t, as does the linux mtd layer. Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Signed-off-by: Scott Wood <scottwood@freescale.com>
* mtd: Update MTD infrastructure to support 64bit device sizeStefan Roese2009-06-12-4/+7
| | | | | | | | | | | This patch brings the U-Boot MTD infrastructure in sync with the current Linux MTD version (2.6.30-rc3). Biggest change is the 64bit device size support and a resync of the mtdpart.c file which has seen multiple fixes meanwhile. Signed-off-by: Stefan Roese <sr@denx.de> Cc: Scott Wood <scottwood@freescale.com> Cc: Kyungmin Park <kmpark@infradead.org>
* nand: fixup printf modifiers to match types usedMike Frysinger2009-01-23-6/+6
| | | | | Signed-off-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Scott Wood <scottwood@freescale.com>
* NAND: Enable nand lock, unlock featureNishanth Menon2009-01-23-36/+43
| | | | | | | | | | | | | | | | Enable nand lock, unlock and status of lock feature. Not every device and platform requires this, hence, it is under define for CONFIG_CMD_NAND_LOCK_UNLOCK Nand unlock and status operate on block boundary instead of page boundary. Details in: http://www.micron.com/products/partdetail?part=MT29C2G24MAKLAJG-6%20IT Intial solution provided by Vikram Pandita <vikram.pandita@ti.com> Includes preliminary suggestions from Scott Wood Signed-off-by: Nishanth Menon <nm@ti.com> Signed-off-by: Scott Wood <scottwood@freescale.com>
* NAND: Fix misplaced return statement in nand_{read,write}_skip_bad().Scott Wood2008-11-25-6/+6
| | | | | | | | This caused the operation to be needlessly repeated if there were no bad blocks and no errors. Signed-off-by: Valeriy Glushkov <gvv@lstec.com> Signed-off-by: Scott Wood <scottwood@freescale.com>
* NAND: Properly create JFFS2 cleanmarkers.Scott Wood2008-10-29-19/+11
| | | | | | | | | | | As reported by Ilko Iliev <iliev@ronetix.at>, the "nand erase clean" command is currently broken, and among other things causes all blocks to be marked bad. This implements it properly using MTD_OOB_AUTO, along with some indentation fixes. Signed-off-by: Scott Wood <scottwood@freescale.com>
* Coding Style cleanup, update CHANGELOGWolfgang Denk2008-08-14-6/+6
| | | | Signed-off-by: Wolfgang Denk <wd@denx.de>
* drivers/mtd/nand: Move conditional compilation to MakefileJean-Christophe PLAGNIOL-VILLARD2008-08-13-5/+0
| | | | | | rename CFG_NAND_LEGACY to CONFIG_NAND_LEGACY Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
* NAND read/write fixScott Wood2008-08-12-581/+181
| | | | | | | | Implement block-skipping read/write, based on a patch from Morten Ebbell Hestens <morten.hestnes@tandberg.com>. Signed-off-by: Morten Ebbell Hestnes <morten.hestnes@tandberg.com> Signed-off-by: Scott Wood <scottwood@freescale.com>
* Remove white space at end.William Juul2008-08-12-5/+5
| | | | | Signed-off-by: William Juul <william.juul@tandberg.com> Signed-off-by: Scott Wood <scottwood@freescale.com>
* Update MTD to that of Linux 2.6.22.1William Juul2008-08-12-114/+245
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A lot changed in the Linux MTD code, since it was last ported from Linux to U-Boot. This patch takes U-Boot NAND support to the level of Linux 2.6.22.1 and will enable support for very large NAND devices (4KB pages) and ease the compatibility between U-Boot and Linux filesystems. This patch is tested on two custom boards with PPC and ARM processors running YAFFS in U-Boot and Linux using gcc-4.1.2 cross compilers. MAKEALL ppc/arm has some issues: * DOC/OneNand/nand_spl is not building (I have not tried porting these parts, and since I do not have any HW and I am not familiar with this code/HW I think its best left to someone else.) Except for the issues mentioned above, I have ported all drivers necessary to run MAKEALL ppc/arm without errors and warnings. Many drivers were trivial to port, but some were not so trivial. The following drivers must be examined carefully and maybe rewritten to some degree: cpu/ppc4xx/ndfc.c cpu/arm926ejs/davinci/nand.c board/delta/nand.c board/zylonite/nand.c Signed-off-by: William Juul <william.juul@tandberg.com> Signed-off-by: Stig Olsen <stig.olsen@tandberg.com> Signed-off-by: Scott Wood <scottwood@freescale.com>
* MTD/NAND: Fix printf format warning in nand codeStefan Roese2008-07-10-3/+3
| | | | | | | | | This patch fixes NAND related printf format warning. Those warnings are now visible since patch dc4b0b38d4aadf08826f6c31270f1eecd27964fd [Fix printf errors.] by Andrew Klossner has been applied. Thanks, this is really helpful. Signed-off-by: Stefan Roese <sr@denx.de>
* nand: Correct NAND erase percentage outputDirk Behme2008-05-28-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | For NAND erase sizes smaller than one NAND erase block, erase percentage output becomes grater than 100% e.g. -- cut -- > nand info Device 0: NAND 64MiB 1,8V 8-bit, sector size 16 KiB > nand erase 0x100000 0x2000 NAND erase: device 0 offset 0x100000, size 0x2000 Erasing at 0x100000 -- 200% complete. OK > -- cut -- Correct this and give user a warning that more is erased than specified: -- cut -- > nand erase 0x100000 0x2000 NAND erase: device 0 offset 0x100000, size 0x2000 Warning: Erase size 0x00002000 smaller than one erase block 0x00004000 Erasing 0x00004000 instead Erasing at 0x100000 -- 100% complete. OK > -- cut -- Signed-off-by: Dirk Behme <dirk.behme@gmail.com>
* fix comments with new drivers organizationMarcel Ziswiler2008-01-09-1/+1
| | | | Signed-off-by: Marcel Ziswiler <marcel@ziswiler.com>
* drivers/mtd : move mtd drivers to drivers/mtdJean-Christophe PLAGNIOL-VILLARD2007-11-25-0/+872
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>