Artem Bityutskiy [Fri, 3 Aug 2012 07:01:18 +0000 (10:01 +0300)]
load_nandsim.sh: remove useless function
We do not really need a separate complex function to check if nandsim
is already loaded or not. Besides, it is safer to check /proc/mtd
in case nandsim is compiled-in.
Tomer Barletz [Tue, 26 Jun 2012 21:46:41 +0000 (14:46 -0700)]
mtd-utils: Check mtdoffset is not larger than mtd.size in case of a bad block.
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.
Brian Norris [Wed, 28 Mar 2012 23:59:06 +0000 (16:59 -0700)]
Makefile: fixup previous 'make clean' fix
Apparently, Makefile comments need to be made without indentation. Otherwise,
they are printed out as shell commands. This fix prevents seeing this in your
shell during 'make clean':
$ make clean
...
# findutils v4.1.x (RHEL 4) do not have '+' syntax
...
Signed-off-by: Brian Norris <computersforpeace@gmail.com> Acked-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Brian Norris [Fri, 9 Mar 2012 17:49:09 +0000 (09:49 -0800)]
Makefile: fix "make clean" for old GNU find
findutils v4.1.x does not have the `-exec CMD {} +' syntax. We can just as
easily use the `-exec CMD {} \;' syntax. However, it will launch a lot more
`rm' processes, so we only use it if the first form fails with an error.
This isn't a perfect solution (`find -exec +' can fail for other reasons)
but it works well enough.
This problem manifests itself in RHEL 4, findutils 4.1.20:
$ make clean
rm -f /XXX/mtd-utils/*.o /XXX/mtd-utils/ftl_format ...
find: missing argument to `-exec'
make: *** [clean] Error 1
Signed-off-by: Brian Norris <computersforpeace@gmail.com> Acked-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Artem Bityutskiy [Wed, 7 Mar 2012 14:08:30 +0000 (16:08 +0200)]
mkfs.ubifs: do not ignore --max-leb-cnt when formatting an UBI volume
When the output file is an UBI volume - mkfs.ubifs just sets --max-leb-cnt
to the volume size and ignores the user-supplied --max-leb-cnt value, which
is wrong. Let's set it to the volume size only if the user did not supply
--max-leb-cnt.
Brian Norris [Wed, 8 Feb 2012 21:26:20 +0000 (13:26 -0800)]
libmtd: perform device checking first
If we don't check for the MTD before calling `legacy_get_dev_info1', we may
get errors like:
libmtd: MTD subsystem is old and does not support sysfs, so MTD character device nodes have to exist
libmtd: error!: "/dev/mtd2" is not a character device
mtdinfo: error!: libmtd failed get MTD device 2 information
error 22 (Invalid argument)
So reverse the order of these two checks.
Signed-off-by: Brian Norris <computersforpeace@gmail.com> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Brian Norris [Sat, 11 Feb 2012 04:35:05 +0000 (20:35 -0800)]
libmtd: fix mtd_write() issues for large data-only writes
ioctl(MEMWRITE) is implemented with memdup_user(), and so it allocates
kernel memory in contiguous regions. This limits its usefulness for large
amounts of data, since contiguous kernel memory can become scarce. I have
experienced "out of memory" problems with ubiformat, for instance, which
writes in eraseblock-sized regions:
This error can be mitigated for now by only using ioctl(MEMWRITE) when we
need to write OOB data, since we can only do this in small transactions
anyway. Then, data-only transactions (like those originating from
ubiformat) can be carried out with write() calls.
This issue can also be solved within the kernel ioctl(), but either way,
this patch is still useful, since write() is more straightforward (and
efficient?) than ioctl() for data-only writes.
Signed-off-by: Brian Norris <computersforpeace@gmail.com> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Brian Norris [Thu, 9 Feb 2012 18:13:30 +0000 (10:13 -0800)]
libmtd: fix segmentation fault on lib->mtd
Legacy systems do not initialize lib->mtd, so we shouldn't perform
strlen(lib->mtd); this produces a segmentation fault. As this code isn't
used in the legacy codepath, we can just move it down to an 'else' branch.
Signed-off-by: Brian Norris <computersforpeace@gmail.com> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Artem Bityutskiy [Thu, 9 Feb 2012 18:13:29 +0000 (10:13 -0800)]
limbtd: implement mtd_dev_present for old kernels
Implement the 'legacy_dev_present()' function which will check whether an MTD
device is present by scanning the /proc/mtd file when the MTD subsystem does
not support sysfs (the case for pre-2.6.30 kernels).
This patch also moves the 'mtd_dev_present()' function to a slightly more
logical position.
Brian Norris [Fri, 27 Jan 2012 18:30:46 +0000 (10:30 -0800)]
mtdinfo: fix `--all' for non-consecutive device numbers
When we have assigned non-consecutive device numbers to our MTD devices,
then we run `mtdinfo --all', we get errors once mtdinfo tries to process
the devices in the "hole". For instance, suppose that at boot time, we have
one MTD (/dev/mtd0) then perform a sequence like the following:
Brian Norris [Thu, 26 Jan 2012 07:31:50 +0000 (23:31 -0800)]
ubinfo: fix `--all' for non-consecutive device numbers
When we have assigned non-consecutive device numbers to our UBI devices,
then we run `ubinfo --all', we get errors once ubinfo tries to process the
devices in the "hole". For instance, suppose there are two UBI devices,
/dev/ubi0 and /dev/ubi10; then, ubinfo will fail trying to open /dev/ubi1
with:
ubinfo: error!: cannot get information about UBI device 1
error 2 (No such file or directory)
This patch adds a check to first see if device is present, then continue
to the next ID if it doesn't exist.
Reported-by: Brian Foster <brian.foster@maxim-ic.com> Signed-off-by: Brian Norris <computersforpeace@gmail.com> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Thomas Cannon [Mon, 9 Jan 2012 16:20:53 +0000 (16:20 +0000)]
libmtd: Variable name same as function name causing compile to fail (Android)
When compiling mtd-utils against Android's bionic libc using the
supplied cross compiler environment it errors:
lib/libmtd.c: In function 'dev_node2num':
lib/libmtd.c:444: error: called object 'major' is not a function
lib/libmtd.c:445: error: called object 'minor' is not a function
lib/libmtd.c: In function 'mtd_probe_node':
lib/libmtd.c:1384: error: called object 'major' is not a function
lib/libmtd.c:1385: error: called object 'minor' is not a function
This patch updates the variable names for "major" and "minor" in two
places. It then compiles cleanly.
Artem: pick different names, also rename major1/minor1 variables for
consistency.
Signed-off-by: Thomas Cannon <mail at thomascannon.net> Cc: linux-mtd at lists.infradead.org
Brian Norris [Fri, 9 Dec 2011 19:45:14 +0000 (11:45 -0800)]
libmtd: allow write operations when MEMWRITE is not supported
MEMWRITE is a recently introduced write interface for MTD; however, it
is only supported on NAND flash. mtd-utils should fall back to
old write methods when either ENOTTY or EOPNOTSUPP are returned.
This is a showstopper when, for instance, using ubiformat on NOR, which
don't have a mtd->write_oob interface (and thus don't support MEMWRITE):
Brian Norris [Fri, 2 Dec 2011 17:46:12 +0000 (09:46 -0800)]
nandtest: seed random generator with time
If a seed is not provided via --seed, we use the default rand() values,
which produces the same sequence of values every run. Since this is
undesirable, we should choose a random seed via the current time().
Note that this patch moves the srand() until after all the initial
options processing.
Signed-off-by: Brian Norris <computersforpeace@gmail.com> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@intel.com>
Mike Frysinger [Sat, 19 Nov 2011 21:02:03 +0000 (16:02 -0500)]
Makefile: separate man page install and compression steps
If the system doesn't have gzip installed, we should still be able
to install the man pages. So install the file in one step, and then
compress it in another (and ignore failures from that).
Signed-off-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@intel.com>
Artem Bityutskiy [Sat, 19 Nov 2011 20:38:50 +0000 (22:38 +0200)]
1.4.8 release
Unfortunately I forgot to update the version in Makefile and tagged v1.4.7.
To fix this, I could not invent anything better than cut a new release 1.4.8.
Brian Norris [Wed, 16 Nov 2011 20:03:57 +0000 (12:03 -0800)]
mtdinfo: provide info when used without arguments
If the user specifies neither a MTD argument nor the `-a' flag, we print
a cryptic message; i.e.,
# mtdinfo
libmtd: error!: cannot get information about "(null)"
error 14 (Bad address)
mtdinfo: error!: cannot get information about MTD device "(null)"
error 14 (Bad address)
This is a regression; previously, mtdinfo would give some short info
about number of devices, etc. when used without arguments. To fix this,
we revert commit d53c03b0989f8354a7e4dbb947a150fc7fe3f6d1 and call
print_general_info() when no device is specified.
Signed-off-by: Brian Norris <computersforpeace@gmail.com> Acked-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@intel.com>
This issue was reported and analyzed by
Anton Olofsson <anol.martinsson@gmail.com>:
when ubiformat encounters a write error while flashing the UBI image (which may
come from a file of from stdout), it correctly marks the faulty eraseblock as
bad and skips it. However, it also incorrectly drops the data buffer which was
supposed to be written, and reads next block of data.
This patch fixes this issue - in case of a write error, we preserve the current
data and write it to the next eraseblock, instead of dropping it.
Brian Norris [Wed, 31 Aug 2011 20:00:38 +0000 (13:00 -0700)]
nandwrite: re-implement `--autoplace' option
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>
Brian Norris [Wed, 31 Aug 2011 20:00:37 +0000 (13:00 -0700)]
nandwrite: kill `--raw' option
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>
Brian Norris [Wed, 31 Aug 2011 20:00:36 +0000 (13:00 -0700)]
mtdutils: move OOB auto-layout into libmtd's mtd_write
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>
Brian Norris [Wed, 31 Aug 2011 20:00:34 +0000 (13:00 -0700)]
libmtd: support MEMWRITE ioctl
`mtd_write()' now will first attempt to use MEMWRITE. Then, if that
doesn't exist, it will attempt to fall back to old methods for writing
OOB and/or page data.
Signed-off-by: Brian Norris <computersforpeace@gmail.com> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
Brian Norris [Wed, 31 Aug 2011 20:00:33 +0000 (13:00 -0700)]
libmtd: modify `mtd_write' to cover OOB writes
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>
Brian Norris [Wed, 31 Aug 2011 20:00:32 +0000 (13:00 -0700)]
nandwrite: consolidate buffer usage
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>
Ben Gardiner [Tue, 9 Aug 2011 20:57:28 +0000 (16:57 -0400)]
nandtest: print number of bits corrected during test
The nandtest program monitors the corrected ecc stat to determine if an
ECC correction has taken place during the last write-read. If so, it
prints "ECC corrected".
The mtd subsytem will store the number of bits corrected in the corrected
ecc stat so update the nandtest output to print also the number of bits
corrected when performing the test.
Signed-off-by: Ben Gardiner <bengardiner@nanometrics.ca> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
Brian Norris [Fri, 19 Aug 2011 17:07:54 +0000 (10:07 -0700)]
nandwrite: cleanup "oobinfochanged" leftovers
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>
Brian Norris [Fri, 19 Aug 2011 17:07:53 +0000 (10:07 -0700)]
nandwrite: kill -j, -y, and -f options
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>
Brian Norris [Fri, 19 Aug 2011 17:07:51 +0000 (10:07 -0700)]
nandwrite: remove `autoplace' features
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>
Brian Norris [Fri, 19 Aug 2011 17:07:47 +0000 (10:07 -0700)]
mtd_debug: fixup style
Remove extraneous spaces.
Put braces on same line as "if", "for", "switch", etc. statements.
No parentheses around return values.
Use "errmsg_die" from common.h.
Replace "exit (1)" with "exit(EXIT_FAILURE)".
Signed-off-by: Brian Norris <computersforpeace@gmail.com> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
Fryar, Jeff [Thu, 11 Aug 2011 15:30:33 +0000 (16:30 +0100)]
nandwrite: invalid erase after page write failure
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>
Brian Norris [Mon, 15 Aug 2011 20:17:05 +0000 (13:17 -0700)]
mtdinfo: consolidate help as display_help()
The help message for mtdinfo is unnecessarily disjointed. It is split
into three strings which reuse the PROGRAM_NAME string inefficiently and
don't have a consistent style.
This fixup should provide a cleaner look with aligned columns and
easier-to-read source code.
Signed-off-by: Brian Norris <computersforpeace@gmail.com> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
Brian Norris [Tue, 9 Aug 2011 21:36:44 +0000 (14:36 -0700)]
mtdinfo: restructure help message
We weren't very consistent in how we listed our options in the mtdinfo
help string (listing short options, long options, or both). Plus, not all
options are inter-operable, so we should distinguish this somewhat.
Signed-off-by: Brian Norris <computersforpeace@gmail.com> Acked-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
On certain flash (NOR flash that have eraseblock region info),
`mtdinfo -a' tries to open the MTD node file, for use with the ioctl
MEMGETREGIONINFO; however, we didn't supply a device node path to
`mtdinfo -a', so it's using NULL, resulting in errors like:
For now, we can just skip dumping region_info with the `-a' flag. If we
find a better way to do this (e.g., export via sysfs, find device nodes
via automatic routines, etc.), then we can kill the workaround and this
FIXME should be removed.
The result of recent changes is that we cannot get region_info for devices
via the `--all' option. We add a note in the help message warning that
mtdinfo may find more info when given a device patch, e.g., /dev/mtdX.
Reported-by: Brian Foster <brian.foster@maxim-ic.com> Acked-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Brian Norris <computersforpeace@gmail.com> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
Brian Norris [Thu, 7 Jul 2011 22:16:17 +0000 (15:16 -0700)]
Makefile: fix "version.h" build for cross-compiling
When using "make CROSS=mipsel-linux-", I get the following errors:
/bin/sh: /home/norris/git/mtd-utils/mipsel-linux/include/version.h.tmp: No such file or directory
make: *** [/home/norris/git/mtd-utils/mipsel-linux/include/version.h.tmp] Error 1
Fix (suggested by Mike Frysinger): create the directory if it doesn't
exist. Also, $(CC) needs to be able to find the generated header in
$(BUILDDIR)/include.
Signed-off-by: Brian Norris <computersforpeace@gmail.com> Acked-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
mkfs.ubifs/mkfs.ubifs.c: In function ‘main’:
mkfs.ubifs/ubifs.h:420:2: warning: ‘child_cnt’ may be used uninitialized in this function [-Wuninitialized]
mkfs.ubifs/mkfs.ubifs.c:1735:6: note: ‘child_cnt’ was declared here