summaryrefslogtreecommitdiff
path: root/nandwrite.c
AgeCommit message (Collapse)Author
2011-09-11nandwrite: trivial variable moveBrian Norris
Signed-off-by: Brian Norris <computersforpeace@gmail.com> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
2011-08-23nandwrite: refactor "old_oobinfo" codeBrian Norris
Move variable within conditional and remove duplicated code. Signed-off-by: Brian Norris <computersforpeace@gmail.com> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
2011-08-23nandwrite: cleanup "oobinfochanged" leftoversBrian Norris
We don't really use oobinfochanged anymore, since all the calls to the MEMSETOOBSEL ioctls are gone. The remaining usage of it is superfluous now, as the only case where it is changed is under the "noecc" condition and the only case where it is tested is under the "!noecc" condition. We also no longer need the "restoreoob" label and can instead simply close everything done with the single remaining label, "closeall". Note that `close(-1)' is legal, although useless. Finally, we move `old_oobinfo' into the only block of code in which it's used now. Signed-off-by: Brian Norris <computersforpeace@gmail.com> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
2011-08-23nandwrite: kill -j, -y, and -f optionsBrian Norris
The legacy -j (--jffs2) and -y (--yaffs) options haven't been operational for a long time, since MEMSETOOBSEL was killed. I don't think anybody will miss these options (correct me if I'm wrong). They can be replaced by proper usage of MTD_OOB_AUTO modes. The -f (--forcelegacy) option went hand in hand with -j and -y. Now that -j and -y are gone, there's no use for -f. Kill it. Signed-off-by: Brian Norris <computersforpeace@gmail.com> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
2011-08-23nandwrite: kill more MEMSETOOBSELBrian Norris
Signed-off-by: Brian Norris <computersforpeace@gmail.com> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
2011-08-23nandwrite: remove `autoplace' featuresBrian Norris
The `autoplace' option was meant to force an MTD_OOB_AUTO layout while writing to flash. This option has not been properly supported for a very long time, as the necessary ioctl, MEMSETOOBSEL, has been removed. Apparently nobody uses this option. Kill it. Other code depends on the availability of the `old_oobinfo' data, so we move some code within a block that handles autoplacement if it's *already* enabled. This, however, is inconsistent and should be cleaned up shortly. Note: this option may be re-implemented in the near future with the addition of a new ioctl that allows on-the-fly chaning of MTD OOB modes. Signed-off-by: Brian Norris <computersforpeace@gmail.com> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
2011-08-23nandwrite: remove C99 comment styleBrian Norris
Signed-off-by: Brian Norris <computersforpeace@gmail.com> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
2011-08-19 nandwrite: invalid erase after page write failureFryar, Jeff
mtd-utils nandwrite.c: After a page write failure, the calculation of the block number to erase is incorrect. The erase block size is being passed as the erase block number in the call to mtd_erase(). Signed-off-by: Jeff Fryar <jeff.fryar@hp.com> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
2011-06-27autogenerate version.h from build systemMike Frysinger
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2011-03-08nandwrite: add only write oob optionLei Wen
Write only oob part goes different path in nand_base.c, it is better to have userland program so that we could easy debug this path when the write only oob fail like the mtd_oobtest in mtd_test suit. Signed-off-by: Lei Wen <leiwen@marvell.com> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2010-12-02nandwrite: use common.h "errmsg_die"Brian Norris
errmsg_die() should be nearly the equivalent of the error message used here. This saves a few lines. Also edited the error message to include the offending option and got rid of the quotes. Signed-off-by: Brian Norris <computersforpeace@gmail.com> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2010-12-02nandwrite: add check for negative blockalignBrian Norris
Includes error messages for negative blockalign, telling the user what the offending option and value were. Signed-off-by: Brian Norris <computersforpeace@gmail.com> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2010-12-02nanddump/nandwrite: use "simple_" str functionsBrian Norris
Per Mike Frysinger's suggestion, we check for strtoll() and strtoull() errors by using the "common.h" helper functions simple_strtoll() and simple_strtoull(). Signed-off-by: Brian Norris <computersforpeace@gmail.com> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2010-11-13mtd-utils: nandwrite: type consistencyBrian Norris
Change type off "offs" for type consistency of 64-bit data types. The "loff_t" type is no longer needed for the MEMGETBADBLOCK ioctl since it isn't called dirently anymore - this is handled by mtd_is_bad(). Also change an accompanying printf(). Signed-off-by: Brian Norris <computersforpeace@gmail.com> Acked-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2010-11-13mtd-utils: nandwrite: full 64-bit support w/ libmtdBrian Norris
Several ioctls are replaced with libmtd calls which should give us 64-bit support for large devices. libmtd mostly provides drop-in replacements for the functionality we need. However, when we require erasure of a badly-written block, mtd_erase() only erases a single block, whereas MEMERASE could erase a larger region. In nandwrite, we may have a "virtual blocksize" of more than one (when blockalign > 1). Thus, I added a loop for this case. The mtd_oob_buf struct is no longer needed, nor is "erase_info_t". Error messages for the new libmtd calls reflect the style found in flash_erase. Tested with nandsim and with NAND chips up to 4GB in size (I don't have a device that truly requires 64-bit addressing yet). Signed-off-by: Brian Norris <computersforpeace@gmail.com> Acked-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2010-11-13mtd-utils: nandwrite: prevent 32-bit overflowBrian Norris
For large block- and page-sizes, the multiplication of ebsize_aligned and pagelen can overflow a 32-bit integer. This overflow can be prevented by a simple change in order of operations (i.e., do division first). Since ebsize_aligned is always a multiple of mtd.min_io_size, this produces no change in results. Signed-off-by: Brian Norris <computersforpeace@gmail.com> Acked-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2010-11-13mtd-utils: nandwrite: avoid NULL buffer pointersBrian Norris
Commit 07005d915d6a79dbdee14b0c4360df5058c3a98b made changes to the buffer allocation in nandwrite and did not handle all affected code areas properly. In particular, we were assigning: oob.ptr = noecc ? oobreadbuf : oobbuf; However, since oobreadbuf and oobbuf are declared dynamically, they are NULL at this point. If they aren't properly assigned later, we unwittingly are passing a NULL pointer as oob buffer. This assignment line is best moved after the buffer allocations and pointer assignment. Effects of this problem can be seen when writing oob data with the "-o" flag and without the "-n" flag: $ ./nandwrite -o /dev/mtd0 img.bin Writing data to block 0 at offset 0x0 ioctl(MEMWRITEOOB): Bad address Data was only partially written due to error : Bad address Signed-off-by: Brian Norris <computersforpeace@gmail.com> Acked-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2010-11-13mtd-utils: nandwrite: Use 64-bit offsetBrian Norris
To support large NAND devices, we need 64-bit data types for write offsets. This patch makes data type changes along with their corresponding printf() formats and the input conversion (i.e., use "strtoll()" instead of "strol()"). Signed-off-by: Brian Norris <computersforpeace@gmail.com> Acked-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2010-11-13mtd-utils: nandwrite: Use libmtd to get correct mtd parametersBrian Norris
Begin utilizing libmtd for MTD operations: use mtd_get_dev_info() to return a more detailed set of information about our MTD. Most importantly, libmtd will yield a 64-bit "size" parameter. This is necessary to properly detect devices larer than 4GB. printf() arguments needed reformatted for the new mtd_dev_info data types. In addition, the printf() was restructured to keep lines shorter. Signed-off-by: Brian Norris <computersforpeace@gmail.com> Acked-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2010-11-13mtd-utils: nandwrite: switch "oobsize" for "writesize"Brian Norris
The text of a printf() states that we're printing OOB area, but the corresponding argument passes writesize. That probably wasn't the intent. Signed-off-by: Brian Norris <computersforpeace@gmail.com> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2010-11-13mtd-utils: nandwrite: Clarify usage of aligned "erasesize"Brian Norris
Due to the presence of the "--block-align" flag, nandwrite uses a blocksize throughout that, depeding on the execution parameters, may not be the actual erasesize of the NAND flash. In order to clarify this situation for the untrained viewer of nandwrite's code, we should not change the value of "meminfo.erasesize" itself; rather, we can utilize a separate, calculated "ebsize_aligned". Then, when a user actually wants to refer to the physical erasesize, it's straightforward. Signed-off-by: Brian Norris <computersforpeace@gmail.com> Acked-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2010-11-13mtd-utils: nandwrite: Comment, style fixupsBrian Norris
Comment on "blockalign" default value is incorrect; it only defaults to a 1x multiplier of the actual block size. Perhaps this is a relic of early NAND where all block sizes were 16KB? Reformatted a multi-line comment. Changed separete "if" statements to a combined "if-else-if" since they were logically combinable. Should have no effect on results with minor effect on efficiency. Signed-off-by: Brian Norris <computersforpeace@gmail.com> Acked-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2010-10-25mtd-utils: nanddump/nandwrite: style, signed-ness, printing fixupsBrian Norris
There were some signed/unsigned integer comparisons. Their types were changed for safety. Also, "strtol" was improperly used for unsigned data types. Nanddump's pretty print options needed a slight reformat to prepare for printing offsets that are more than 32 bits (8 hex characters) wide. This prevents overlap of output and ensures that at least one space is printed between hex and ascii printouts. Perhaps this could use some better alignment in the future. Other fixes: * Corrected several simple spacing issues * Changed indentation of some global variable declarations in order to prepare for the next patch, which makes those declarations longer * Used macro for PRETTY_ROW_SIZE instead of constant 16 * Reformatted, edited a multi-line comment * Removed some unnecessary casts Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2010-10-17mtd-utils: nanddump/nandwrite: Style fixupsBrian Norris
Signed-off-by: Brian Norris <computersforpeace@gmail.com> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2010-10-17mtd-utils: nandwrite: Large page+oob supportBrian Norris
Dynamic allocation of the oob buffer provides the necessary support for removing the oob size check. Now, new unknown OOB sizes can be handled correctly (for example, 8KB page + 448B OOB). Included common.h for the use of xmalloc. Memory freeing should occur on "restoreoob" as well as on "closeall." [Conflicts resolved by Artem] Signed-off-by: Brian Norris <computersforpeace@gmail.com> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2010-09-27mtd-utils: standardize PROGRAM_NAMEMike Frysinger
Make sure all the utils define PROGRAM_NAME and do so at the start of the file so that sub-headers may assume it exists. Signed-off-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2010-09-25nandwrite: Remove redundant 'autoplace' checkShinya Kuribayashi
We're already in 'if (autoplace) { }' block at ths moment. Signed-off-by: Shinya Kuribayashi <shinya.kuribayashi.px@renesas.com> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2010-09-24nandwrite: add --skipbad to write bad blocksMike Frysinger
Sometimes dumping bad blocks is useful, like when the block isn't actually bad but the OOB layout isn't what the kernel is expecting or is otherwise screwed up. The --skipbad option allows just that. Signed-off-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2010-06-12mtd-utils: support 4096+64 page sizesEnric Balletbo i Serra
Add support for oobsize 64 and writesize 4096 in nanddump & nandwrite. Artem: some more info from further e-mail exchange: > Are there flashes with the 4096 page / 64 spare combination? Could you > refer to one? May be any URL? I thought 4096 comes with 128. Much to my regret I can't provide a URL because is not public. IGEP v2 board has a Onenand with two dice of 2048/64 spare combination but mtd views 4096/64. The minimal write page is 4K (2K from first dice and 2K from second dice). Signed-off-by: Enric Balletbo i Serra <eballetbo@iseebcn.com> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2010-05-22nandwrite: check if the start address is page-alignedStanley.Miao
Only page-aligned address is permitted in NAND subsystem. Signed-off-by: Stanley.Miao <stanley.miao@windriver.com> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2010-05-22nandwrite: fix the bug of writing a yaffs2 image to NANDStanley.Miao
The tool mkyaffs2image doesn't know the oob layout of a NAND flash, so it puts the yaffs2 tags at the offset 0 of oob area, as a result, the image generated by mkyaffs2image is different with the image dumped by nanddump. Now adding a parameter "-r" for nandwrite to differentiate these images. Write a image generated by mkyaffs2image: $> nandwrite -a -o /dev/mtd3 yaffs2.bin Write a image dumped by nanddump: $> nandwrite -a -r /dev/mtd3 image.bin Signed-off-by: Stanley.Miao <stanley.miao@windriver.com> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2009-08-12nandwrite: allow writing the OOB when using the standard inputJehan Bing
Signed-off-by: Jehan Bing <jehan@orb.com> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2009-08-11nandwrite: fix incorrect use of errno.Jehan Bing
Signed-off-by: Jehan Bing <jehan@orb.com> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2009-08-11nandwrite: unified reading from standard input and from file - part 3Jehan Bing
Nandwrite tries to use lseek() when failing to write on a page. lseek() will fail when used on the standard input so nandwrite fails. This code replaces lseek with a buffer. When the data is read, it is put in a buffer (filebuf). This buffer is reset at each block boundary. So a "seek" just means reading from the beginning of the buffer. writebuf and oobreadbuf are now just pointers to locations in filebuf. Signed-off-by: Jehan Bing <jehan@orb.com> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2009-08-11nandwrite: unified reading from standard input and from file - part2Jehan Bing
Use the same code structure when reading the OOB than when reading the regular data. Signed-off-by: Jehan Bing <jehan@orb.com> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2009-08-11nandwrite: unified reading from standard input and from file - part 1Jehan Bing
Use same code path for reading data (not the OOB) from either the standard input or a regular file. Signed-off-by: Jehan Bing <jehan@orb.com> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2009-06-09nandwrite: fix error handlingJehan Bing
Artem Bityutskiy wrote: > Yes, write and erase failure mean that the erasblock is bad. But I think > marking a block as bad straight away is just dangerous. Who knows may be > this is a small glitch in a bus, or a software bug, or some-one > corrupted driver's memory, or whatever. This is why UBI is doing > eraseblock torturing before marking it as bad. And it is very careful > about error codes - only EIO code is considered as a reason to mark an > eraseblock as bad. Fixed broken behavior in case of write failure. More specifically: - Only try to mark a block bad if the errors are EIO. Other errors will abort the tool. - Also abort the tool if the marking fails instead of ignoring it. Signed-off-by: Jehan Bing <jehan@orb.com> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2009-06-09nandwrite: return error if failure when reading from standard inputJehan Bing
Fix nandwrite to return EXIT_FAILURE in case of error when using the standard input instead of a file for input. Signed-off-by: Jehan Bing <jehan@orb.com> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2009-06-08nandwrite: amend loop conditionJehan Bing
If the file contains only a few bytes in the last page and the --oob option is selected, the loop may exit early (readlen < meminfo.oobsize). Most of the time it will still work though because the code tries to read the whole OOB in one chunk. Signed-off-by: Jehan Bing <jehan@orb.com> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2008-12-26nandwrite: correct data readingArtem Bityutskiy
The "read" syscall does not necessarily return all the requested data, in which case the caller has to try again and read more. Take this into account when reading input data. This patch is an improved vestion of the original patch sent by Hai Zaar. Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com> Tested-by: Hai Zaar <haizaar@codefidence.com>
2008-09-08nandwrite: Add Support for Reading from Standard InputGrant Erickson
Added suppport for reading in band data from standard input based on a patch originally generated by Richard Titmuss <titmuss@slimdevices.com> at <http://lists.slimdevices.com/pipermail/jive-checkins/2008-May/001918.html>. Signed-off-by: Grant Erickson <gerickson@nuovations.com> Acked-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com> Signed-off-by: Josh Boyer <jwboyer@gmail.com>
2008-09-08nandwrite: Clean-up Usage OutputGrant Erickson
Realign help usage output to make it more explict when a description needs to be wrapped. Use sentence case for the help usage output option short descriptions. Signed-off-by: Grant Erickson <gerickson@nuovations.com> Acked-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com> Signed-off-by: Josh Boyer <jwboyer@gmail.com>
2008-09-08nandwrite: Use Boolean Mnemonics from stdbool.hGrant Erickson
Added include directive for stdbool.h and leveraged where appropriate to improve code readability by making variable intent and usage more explicit. Signed-off-by: Grant Erickson <gerickson@nuovations.com> Acked-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com> Signed-off-by: Josh Boyer <jwboyer@gmail.com>
2008-09-08nandwrite: Pass Real Names as Arguments to perrorGrant Erickson
Pass the MTD device node and input file name as arguments to perror rather than more ambigous, static messages on open failures. Signed-off-by: Grant Erickson <gerickson@nuovations.com> Acked-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com> Signed-off-by: Josh Boyer <jwboyer@gmail.com>
2008-09-08nandwrite: Utilize Standard Exit MnemonicsGrant Erickson
Replace main exit and return status codes with equivalent mnemonics. Signed-off-by: Grant Erickson <gerickson@nuovations.com> Acked-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com> Signed-off-by: Josh Boyer <jwboyer@gmail.com>
2008-09-08nandwrite: Qualifier Clean-upGrant Erickson
Static-qualified all globals except 'main' because they have no use beyond file scope. Constant-qualified MTD device and input positional parameter globals. Constant-qualified argv array. Signed-off-by: Grant Erickson <gerickson@nuovations.com> Acked-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com> Signed-off-by: Josh Boyer <jwboyer@gmail.com>
2008-08-21mtd-utils: add support for 4k pages.Thomas Gleixner
Add support for 4K pages in nanddump & nandwrite. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Sebastian Siewior <bigeasy@linutronix.de> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2007-08-06Copy with write errors in nandwrite, add 'markbad' option too.David Woodhouse
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
2007-08-03Remove $Id:$ tagsJosh Boyer
The $Id:$ tags are left over from the old CVS repository. Several files have since been changed, and they generally have little value in a git repo so they should be removed. Signed-off-by: Josh Boyer <jwboyer@gmail.com>
2007-03-15MTD-Utils: fix handling of ioctl return value in nand-utilsFrank Haverkamp
Older kernel do not implement the MTDFILEMODE ioctl. In this case nandwrite and nanddump should have used MEMGETOOBSEL in combination with MEMSETOOBSEL. Unfortunately the return value of the unsucessfull ioctl is not -ENOTTY, but -1 and errno contains ENOTTY. This change fixes this issue. I have not tested all cornercases. Would be good if someone could do more careful testing than I did, or maybe reviewing is sufficient in this case. Signed-off-by: Frank Haverkamp <haver@vnet.ibm.com> Signed-off-by: Josh Boyer <jwboyer@gmail.com>