Age | Commit message (Collapse) | Author |
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
|
|
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>
|
|
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>
|
|
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>
|
|
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
|
|
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>
|
|
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
|
|
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>
|
|
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
Signed-off-by: Jehan Bing <jehan@orb.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
Signed-off-by: Jehan Bing <jehan@orb.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|