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
Some compilers will complain about use of strlen() within a static array
size declaration. For this type of string, "sizeof() - 1" is equivalent
and prevents the build error.
Error:
io_paral.c:48:13: error: variably modified 'vol_nodes' at file scope
Signed-off-by: Brian Norris <computersforpeace@gmail.com> Acked-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Artem Bityutskiy <dedekind1@gmail.com>
Brian Norris [Mon, 27 Jun 2011 18:27:27 +0000 (11:27 -0700)]
nanddump: remove unused variable
The "bb_default" bool was temporarily being used to straighten out
potential issues with the changing --bb=METHOD options and to warn
users properly. Now, it's unnecessary.
Signed-off-by: Brian Norris <computersforpeace@gmail.com> Acked-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Artem Bityutskiy <dedekind1@gmail.com>
Mike Frysinger [Sat, 25 Jun 2011 17:20:37 +0000 (13:20 -0400)]
rewrite build system to avoid recursion
The ubi-utils/src/ subdir is tossed as it just complicates things for no
real gain. The dictionary.h header is relocated to the ubi-utils/include/
since other headers in there need it.
The top level clean is replaced with a `find -delete` on objects, so it
might prune more than necessary, but many projects now do this sort of
thing and no one complained there.
A "mkdep" helper generates the actual rule, and the variables are used
with "foreach" to expand these automatically.
The tests subdir is updated only to reflect the ubi-utils source move.
Otherwise, it is left untouched as making that non-recursive isn't really
worth the effort.
While we're gutting things, also through in kbuild style output while
building to make things more legible.
Signed-off-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Artem Bityutskiy <dedekind1@gmail.com>
Need to include <linux/fs.h>, at least for my build system. Otherwise,
you can't build the 'tests'.
integck.c: In function ‘parse_mount_options’:
integck.c:2862: error: ‘MS_DIRSYNC’ undeclared (first use in this
function)
integck.c:2862: error: (Each undeclared identifier is reported only once
integck.c:2862: error: for each function it appears in.)
integck.c:2872: error: ‘MS_RELATIME’ undeclared (first use in this
function)
Signed-off-by: Brian Norris <computersforpeace@gmail.com> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Brian Norris [Fri, 24 Jun 2011 18:03:11 +0000 (11:03 -0700)]
nanddump: change -o to mean --oob, not --omitoob
As warned earlier, we are changing the meaning of `nanddump -o' to
mirror the usage in nandwrite, where -o means to include OOB (i.e.,
`nandwrite -o' writes data to both in-band and out-of-band areas, so
`nanddump -o' should dump data from both in-band and out-of-band areas).
Signed-off-by: Brian Norris <computersforpeace@gmail.com> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Brian Norris [Fri, 24 Jun 2011 18:03:10 +0000 (11:03 -0700)]
nanddump: change default to --bb=skipbad
As promised, we change the default bad block handling method to
--bb=skipbad. This works as a better inverse to nandwrite, since
nandwrite skips bad blocks when writing data.
And of course, we remove the warning messages.
Signed-off-by: Brian Norris <computersforpeace@gmail.com> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Brian Norris [Fri, 24 Jun 2011 18:03:09 +0000 (11:03 -0700)]
nanddump: kill --omitbad, --noskipbad
As mentioned previously, we are killing --omitbad in favor of the new
--bb=skipbad option, which functions fairly similarly. Also, --noskipbad
has become --bb=dumpbad, so remove the old `-N' and `--noskipbad' flags.
Signed-off-by: Brian Norris <computersforpeace@gmail.com> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Mike Frysinger [Sat, 25 Jun 2011 04:57:37 +0000 (00:57 -0400)]
punt redundant libcrc32
The libcrc32.a is only used in one place: mkfs.ubifs. But this also
uses libmtd.a, and the only file in libcrc32.a is also in libmtd.a.
So libcrc32.a itself is completely redundant. Punt!
Signed-off-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Brian Norris [Wed, 22 Jun 2011 16:49:23 +0000 (09:49 -0700)]
nanddump: document, warn about future default --omitoob
To work as a proper inverse to nandwrite, nanddump must not dump OOB data by
default. This patch prints a warning regarding the future change. We also
suggest using the new flag, `--oob', for transitioning to the next release
with new default behavior.
Note that we are changing `-o' to mean `--oob' in the next release,
similar to `nandwrite -o'. This is a break from previous behavior.
Signed-off-by: Brian Norris <computersforpeace@gmail.com> Signed-off-by: Artem Bityutskiy <dedekind1@gmail.com>
Brian Norris [Wed, 22 Jun 2011 16:49:22 +0000 (09:49 -0700)]
nanddump: add --oob option
Adds an explicit option for including OOB data in our data dump.
Currently, this is the default behavior, but in the next release, the
default will be to exclude OOB data. This is done to mirror the '-o'
option in nandwrite.
Signed-off-by: Brian Norris <computersforpeace@gmail.com> Signed-off-by: Artem Bityutskiy <dedekind1@gmail.com>
Brian Norris [Wed, 22 Jun 2011 16:49:20 +0000 (09:49 -0700)]
nanddump: warn about new default BB handling
In an upcoming release, we will no longer default to --bb=padbad. Instead,
the default will be --bb=skipbad. This makes nanddump a better inverse
operation to nandwrite.
This patch prints warnings for users so that they get a chance to update
their scripts before the default changes officially.
Signed-off-by: Brian Norris <computersforpeace@gmail.com> Signed-off-by: Artem Bityutskiy <dedekind1@gmail.com>
Brian Norris [Wed, 22 Jun 2011 16:49:18 +0000 (09:49 -0700)]
nanddump: remove --skipbad, leaving --bb=skipbad
We are moving to unify bad block handling methods under the --bb=METHOD
option. Since --skipbad has not been included in a mtd-utils release yet,
we can safely replace it without a deprecation and phase-out period.
Signed-off-by: Brian Norris <computersforpeace@gmail.com> Signed-off-by: Artem Bityutskiy <dedekind1@gmail.com>
Brian Norris [Wed, 22 Jun 2011 16:49:17 +0000 (09:49 -0700)]
nanddump: add --bb=METHOD option
We have too many separate bad block handling methods:
--omitbad
--noskipbad
--skipbad
On top of these, we have the default option: that bad blocks are
replaced with 0xFF.
These options will be unified under --bb=METHOD. The end goal will be
something like:
----------------------------------------------------------------------------------------------
Old option New option Comment
----------------------------------------------------------------------------------------------
<default> --bb=padbad dump flash data, substituting 0xFF for any bad blocks
--noskipbad --bb=dumpbad dump flash data, including any bad blocks
--skipbad --bb=skipbad dump good data, completely skipping any bad blocks (new default)
--omitbad N/A very similar to `skipbad' (DEPRECTATED)
The BB options are all mutually exclusive, so we check that we do not
have more than one BB option explicitly enabled on the command line by
tracking whether or not a BB method has been set by the user.
Signed-off-by: Brian Norris <computersforpeace@gmail.com> Signed-off-by: Artem Bityutskiy <dedekind1@gmail.com>
Mike Frysinger [Wed, 8 Jun 2011 19:11:32 +0000 (15:11 -0400)]
mtdinfo: add regioninfo/eraseblock map display
This brings the mtdinfo utility in line with the functionality
of the flash_info utility. It dumps the erase regioninfo (if
the devices has it) as well as showing a handy eraseblock map
(if the user has requested it). The eraseblock map also shows
which blocks are locked and which ones are bad.
Signed-off-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Artem Bityutskiy [Wed, 8 Jun 2011 12:30:14 +0000 (15:30 +0300)]
libmtd: improve mtd_islocked interface
This patch first of all, re-names 'mtd_islocked()' into 'mtd_is_locked()' since
this seems to be the name Mike wanted, and it looks a bit nicer.
This patch also makes 'mtd_is_locked()' print an error message if it fails. I'm
not sure if it is good idea for a library to do so, but all functions do this,
so it certainly _not_ a good idea to be inconsistent.
However, for the special case, when the the "is locked" ioctl is not supported
or is not valid for this device, we do not print an error message and return
ENOTSUPP error code.
Thus, the user can distinguish between real errors and non-fatal "not
supported" cases.
Mike Frysinger [Tue, 7 Jun 2011 06:19:03 +0000 (02:19 -0400)]
jffs2: make lzo optional at build time
The external lzo dep can be a pain to deal with when cross-compiling,
so make it optional for jffs2. This is useful if people aren't even
using the functionality, or for quicker development.
Signed-off-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Mike Frysinger [Tue, 7 Jun 2011 15:02:02 +0000 (11:02 -0400)]
ubi-utils: send help/version info to stdout
Usage/version information should go to stdout when it is expected behavior
(i.e. the user requested it explicitly). This info should go to stderr
only when the usage info is being shown as a result of incorrect options.
Signed-off-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Mike Frysinger [Mon, 6 Jun 2011 17:15:01 +0000 (13:15 -0400)]
ignore (FLAT) gdb files
Linux FLAT toolchains produce .gdb files alongside the normal program
for debugging purposes (so linking to "foo" will also produce "foo.gdb").
Ignore these too.
Signed-off-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Steven Miao [Mon, 6 Jun 2011 04:09:14 +0000 (00:09 -0400)]
flash_{lock, unlock}: fix off-by-one error for "entire device" length
This basically reverts commit 43feb39f35a9ee0ed3 which changed the full
length calculation to be one less than one sector. I don't understand
the logic in the commit message where it states that the length should
be one sector smaller as this results in misbehavior at runtime.
For example, with a mtd device with total size 0x400000 and erase block
size of 0x20000 (which gives us a total of 32 sectors), this new logic
results in:
mtdLockInfo.start = 0;
mtdLockInfo.length = 0x3e0000; /* (32 - 1) * 0x20000 */
Calling MEMLOCK/MEMUNLOCK on the device with this range leaves the last
sector unchanged which is certainly not what we want. So drop this -1
part of the calculation.
To look at it another way, if we only attempt to lock one sector, this
calculation would end up with the .length set to 0. Calling MEMLOCK
with a length of 0 does not lock the sector as this simple code shows:
int main(int argc, char *argv[]) {
erase_info_t e0 = { 0, 0 }, e1 = { 0, 0x20000 };
int fd = open(argv[1], O_RDONLY);
ioctl(fd, MEMUNLOCK, &e1);
printf("%i\n", ioctl(fd, MEMISLOCKED, &e1));
ioctl(fd, MEMLOCK, &e0);
printf("%i\n", ioctl(fd, MEMISLOCKED, &e1));
}
MEMISLOCKED returns 0 both times. If we change the argument to MEMLOCK
to e1, then MEMISLOCKED returns 1.
Signed-off-by: Steven Miao <realmz6@gmail.com> Signed-off-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Mike Frysinger [Mon, 6 Jun 2011 04:09:11 +0000 (00:09 -0400)]
flash_{lock,unlock}: merge functionality
The flash_lock util has a bit of extra argument checking, and it supports
a magic value of "-1" to mean "all blocks".
The flash_unlock util supports automatic 2nd/3rd arguments to unlock the
whole flash. It also supports multiple bases (not just hex) for selecting
the range of the device to unlock.
So tweak both utilities so that they have equivalent functionality again
by adding the missing features to each.
Signed-off-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Brian Norris [Fri, 3 Jun 2011 18:25:00 +0000 (11:25 -0700)]
nanddump: add --skipbad option for bad blocks
This patch adds a new option "--skipbad" to nanddump. It is subtly
different than "--omitbad". The following description was included in
the help message to attempt to clarify the differences.
Notes on --omitbad and --skipbad:
With either option, we stop dumping data when we encounter a bad block
and resume dumping at the next good block. However, with --omitbad, we
count the bad block as part of the total dump length, whereas with
--skipbad, the bad block is 'skipped,' that is, not counted toward the
total dump length.
Signed-off-by: Brian Norris <computersforpeace@gmail.com> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Ben Gardiner [Wed, 1 Jun 2011 13:49:36 +0000 (09:49 -0400)]
mkfs.ubifs: trivial: 2.6.40 -> 3.0
In commit 04665066ebedb0a31335b525fb5f19df32cb8cfe it was noted that the free
space fixup feature would be available in kernels 2.6.40 or greater. Since
then it has been decided that the release following 2.6.39 will be 3.0.
Replace the instances of 2.6.40 with 3.0.
Signed-off-by: Ben Gardiner <bengardiner@nanometrics.ca> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Commit 924862c864da0b62cf93ba7abf2dc78a7e6ac48f broke ubimkvol parrameters
parsing by initializing the 'error' parameter of 'simple_strtoul()' to 1
instead of 0. This patch fixes the issue.
Artem Bityutskiy [Thu, 26 May 2011 11:58:26 +0000 (14:58 +0300)]
fs-tests: integck: print error message on error
Currently pcv macro print the error message only if we are not doing power cut
testing or if we have -v flag. But if we run without -v and an error happen
and the error code is not EROFS/EIO, pcv() does not print anything. This patch
makes it print the error message in that case as well.
Artem Bityutskiy [Thu, 26 May 2011 10:43:13 +0000 (13:43 +0300)]
fs-tests: integck: close files after creation
The 'file_new()' function should create a file but should not keep it
open. There is a different path to open files and keep them open. This
patch makes 'file_new()' close newly created files.
Artem Bityutskiy [Wed, 25 May 2011 15:22:51 +0000 (18:22 +0300)]
fs-tests: integck: make directory checking work
This patch makes the directory checking in case of power cut emulation
actually work. There were many bugs. Basically, we cannot rely on anything
unless the directory is marked as clean.
Artem Bityutskiy [Tue, 24 May 2011 14:46:11 +0000 (17:46 +0300)]
fs-tests: integck: always check clean data
Check the clean data after every emulated power cut, not only when
'create_test_data()'/'update_test_data()' succeed. This required some minor
re-work.
Artem Bityutskiy [Mon, 23 May 2011 11:30:01 +0000 (14:30 +0300)]
fs-tests: integck: EIO can also be return in power-cut testing
Currently when we are doing UBIFS power cut emulation testing we assume that
EROFS is returned in case of an emulated power cut event. However, this is
not true and sometimes Linux returns EIO to user-space instead. Namely, this
happens when we are waiting for write-back to finish. Here is a call trace
form kernel 2.6.39-rc7:
Artem Bityutskiy [Fri, 20 May 2011 15:27:36 +0000 (18:27 +0300)]
fs-tests: integck: implement MTD reattaching
This patch adds -m <mtdnum> option to integck and teaches integck to re-attach
the MTD device to UBI in case of an emulated power cut event. This is needed
for the new UBI power cut and unstable bits emulation infrastructure: when UBI
emulates a power cut the only way to recover form this is to re-attach the MTD
device.
Matthew L. Creech [Wed, 11 May 2011 21:02:28 +0000 (17:02 -0400)]
mkfs.ubifs: add "-F" option for "free-space fixup"
This adds a superblock flag indicating that "free-space fixup" is needed, and
allows it to be set by the user via the "-F" command-line option. The first
time the filesystem is mounted, this flag will trigger a one-time re-mapping of
all LEBs containing free space. This fixes problems seen on some NAND flashes
when a non-UBIFS-aware flash programmer is used.
Artem: add a bit more help text, tweaked the patch a bit.
Thanks to Ben Gardiner <bengardiner@nanometrics.ca> for help.
Signed-off-by: Matthew L. Creech <mlcreech@gmail.com> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Artem Bityutskiy [Tue, 17 May 2011 07:28:00 +0000 (10:28 +0300)]
fs-tests: integck: read all files in power cut mode
When we are in power cut mode read all files after re-mounting. This will
check that FS recovery worked well and all files are readable after recovery.
Artem Bityutskiy [Mon, 16 May 2011 14:04:49 +0000 (17:04 +0300)]
fs-tests: integck: make -v work -e
Make the verify option -v work with power cut emulation option -e. We can
verify all operations except of writing to the file, because of write-back.
Indeed, even if we write successfully, the pages may still be in the page-cache
and if an emulated power cut happens they will be dropped, and our verification
will fail.
I am not 100% sure it is save to verify non-write operation in other FSes, but
only UBIFS has power cut emulation mode now, so we do not really care about
other FSes at this point.
Artem Bityutskiy [Mon, 16 May 2011 13:57:05 +0000 (16:57 +0300)]
fs-tests: integck: check direntries in power cut mode
Enable directory entry checking in power cut mode. This means that with this
patch integck will check that all directory entries in the file-system were
created by integck.
Artem Bityutskiy [Tue, 3 May 2011 12:02:58 +0000 (15:02 +0300)]
fs-tests: integck: check errno in pvc macro
All errors but write errors have corresponding CHECK(), so if something
gets wrong we fail. But in case of I/O errors we do not fail if an
unexpected error happens, which makes it difficult to trace issues.
Inject the errno checking to the pvc macro to make sure we fail if
errno is not EROFS.
Artem Bityutskiy [Mon, 2 May 2011 15:19:47 +0000 (18:19 +0300)]
fs-tests: integck: fix segfault
Commit 1394a46213e8180e1233ca6d4811e7c77d49b1e0 was a good idea, but it
introduced a segfault - files can be unlinked and 'file->links' is NULL, it is
bad idea to unconditionally dereference it with 'file->links->name'. This patch
introduces a helper function which takes care of the situation with unlinked
files, plus it adds few assertions.
fs-tests: integck: re-structure file_write a little
This is just a preparation - re-structure 'file_write()' to make one "success"
return point - we'll add synchronization stuff there. Also, while on it, make
it delete the file errored in truncation, not only in write. Also, move
the fsync() call to this function because it is common to all write paths.
I observes segfaults in integck test, and unfortunately I do not have the core
file to investigate the problem. But I see one possibility for the test to
segfault - it has unbounded recursion. Limit the maximum recursion depth.
fs-tests: integck: fail loudly on unexpected EROFS
If we are not in power cut testing mode (-p was not used) and we get an
unexpected EROFS, we silently exit. This patch fixes this behavior and make
the test loudly fail instead.
The test sometimes dies due to SIGBUS because a power cut event happens when
we are writing to an mmap()'ed area. SIGBUS is very difficult to ignore, so
fix the issue simply by avoiding doing 'mmap()' operations when in power cut
testing mode.
fs-tests: integck: fix line number in CHECK() output
In 'check_failed()' use the file and line number provided by the CHECK()
macro via the function parameters, rather than using __LINE__ directly.
Otherwise the funtion prints its own line, instead of the line where the
CHECK() failed.
fs-tests: integck: do not run checking when in power cut mode
Do not check the file-system when we are in power cut mode. Currently
we still check the FS if we did not encounter any error, and the test
fails sometimes because meanwhile write-back encounters an error and
drops pages. Disable the checking so far. It should be enabled when
we implement the 'clean' flag for files.
The integck test assumes that if the FS is rootfs then it cannot
re-mount it, otherwise it can. However, this is not true because the
tested FS can be not remountable even if it is not rootfs, e.g., if
'integck' lives on this FS and is executed from it.
This patch improves the integck logic and actually checks wheter it
is possible to re-mount the FS before starting the test.
Also, it makes sure that power cut testing is run only on re-mountable
FS, because we have to be able to clean the "corrupted" state of the
file-system.
-v (verbose) switch is supposed to turn power cut testing error
messages on/off. However, it does not work because the messages
are printed even if -v was not specified. This patch fixes it.
Instead of using rand_r with own seed for operations and rand() with
global state for data it is cleaner to use rand_r with own different
states for these things. This patch eliminates 'srand()' and 'rand()'
usage.
fs-tests: use independent random generators for ops and data
Currently integck uses the same global random generator for everything -
for choosing the operation, generating the data, and for checking. This
makes integck to become stuck sometimes. My guess this is because of
we somehow re-set it back with srand() when checking files.
This patch makes integck use different generators for data and for
choosing operations by using rand_r() with own seed for operations.
I often need to use gdb to debug integck, or sometimes even attach
already running integck. But when it is compiled with optimizations, it
is nearly impossible to use gdb. Introduce 'debug' target to compile
integck without optimizations.
Additionally, to make the stack backtraces work, add a dirty hack to
integck.c to remove all the static keywords - this turns static
functions to non-static and makes them appear in stack backtraces.
fs-tests: integck: add -e option to verify operations
Improve the test and add -e option which forces integck to verify all
operation it performs. This patch does not implement file writes and
holes operations so far - will be done in subsequent patches.
fs-tests: integck: print backtrace in case of failure
This patch teaches the 'CHECK()' macro to print the back-trace in
case of failure which is sometimes very useful for debugging. This
patch also adds a helper function for the 'CHECK()' macro because
otherwise it becomes too large.
Note, since all functions in the test are static, the stack trace
does not really show symbols.