aboutsummaryrefslogtreecommitdiff
path: root/nandwrite.c
AgeCommit message (Collapse)Author
2013-07-01move _GNU_SOURCE to the main makefileMike Frysinger
A bunch of utils are relying on _GNU_SOURCE already. The new prompt code uses getline() which is now part of POSIX, but in older versions of glibc, it was behind _GNU_SOURCE as it was a GNU extension. This change doesn't actually tie us to glibc. Only code that uses GNU extensions does that. It just kills warning when using older versions of glibc. Signed-off-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2012-06-29mtd-utils: Check mtdoffset is not larger than mtd.size in case of a bad block.Tomer Barletz
mtdoffset is being tested against mtd.size in the outer two loops, but the third nested one does not test against it. In case of a bad block we'll try to access an out of bounds offset in the next MEMGETBADBLOCK ioctl, which will fail with EINVAL. In case mtdoffset is indeed larger than the partition size, we need to bail, since there are not enough "good" blocks to complete the write. Signed-off-by: Tomer Barletz <barletz@gmail.com> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2012-06-29nandwrite: minor cleanupsArtem Bityutskiy
Remove extra brackets and some style changes to make it more readable for a person who deals mostly with the kernel code. Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2011-09-11nandwrite: use common.h "errmsg" functionsBrian Norris
Convert several forms of exit(), perror(), etc. to use common.h helper functions. Also, move one of our parameter checks inside the process_options() function for consistency. Signed-off-by: Brian Norris <computersforpeace@gmail.com> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
2011-09-11nandwrite: re-implement `--autoplace' optionBrian Norris
The restructuring of mtd_write() has allowed us to use `--autoplace' somewhat successfully; it is supported by the new ioctl(MEMWRITE) as well as some legacy code utilizing the deprecated ioctl(MEMGETOOBSEL). Signed-off-by: Brian Norris <computersforpeace@gmail.com> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
2011-09-11nandwrite: kill `--raw' optionBrian Norris
The `--raw' option has lost all usefulness as it overlapped with several other OOB modes. I cannot even figure out what it was actually intended to do, but I'm sure its functionality fits somewhere in the MTD_OPS_{AUTO_OOB,PLACE_OOB,RAW} options, which are mostly implemented in libmtd's mtd_write(). I don't think users need a warning for this one, unless someone can tell me what it actually was supposed to have done in the first place. Signed-off-by: Brian Norris <computersforpeace@gmail.com> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
2011-09-11mtdutils: move OOB auto-layout into libmtd's mtd_writeBrian Norris
With the addition of the the new ioctl(MEMWRITE), we can use the kernel's internal OOB autoplacement option. It's a cleaner interface and avoids too much duplication of coding effort. This patch moves any legacy code (using MEMGETOOBSEL) into a legacy function in libmtd.c. It's not exactly a "pre-2.6.30" feature, so I'm not moving it to libmtd_legacy.c. Now, autoplacement features are only activated if we call mtd_write with mode == MTD_OPS_AUTO_OOB. This should fix some discrepancies for nandwrite, where we weren't handling OOB consistently (i.e., we had different functionality when the kernel did/didn't support MEMWRITE). But that also means that we now default to using MTD_OPS_PLACE_OOB instead of AUTO layout. To re-enable autoplacement, we can re-implement the `--autoplace' option that had previously rotted. This patch also cleans up a need for an extra OOB buffer in nandwrite. This has been tested a little in nandsim as well as on SLC NAND flash. Signed-off-by: Brian Norris <computersforpeace@gmail.com> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
2011-09-11nandwrite: merge `mtd_write_oob' and `mtd_write' callsBrian Norris
Now that `mtd_write' can write to both OOB and data regions, we need to perform our `mtd_write' call only once. Signed-off-by: Brian Norris <computersforpeace@gmail.com> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
2011-09-11libmtd: modify `mtd_write' to cover OOB writesBrian Norris
To support the MEMWRITE ioctl, we will need a different sort of libmtd interface for writing to flash. We will expand mtd_write to include more functionality; for now, we just change the function definition and description as we begin to add the actual functionality. Signed-off-by: Brian Norris <computersforpeace@gmail.com> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
2011-09-11mtd-utils: update mtd-abi.hBrian Norris
Kernel ABI header added a new ioctl, killed an old one, and exposed OOB modes to user-space. Plus, it added a lot of documentation. We have some trivial name changes for some MTD mode constants as well. Signed-off-by: Brian Norris <computersforpeace@gmail.com> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
2011-09-11nandwrite: consolidate buffer usageBrian Norris
Instead of using two different output buffers for OOB data, let's just use the same one for all output. This adds an extra memcpy, but it simplifies some future work, so it's worth it. Signed-off-by: Brian Norris <computersforpeace@gmail.com> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
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>