]> www.infradead.org Git - mtd-utils.git/log
mtd-utils.git
10 years agolibmtd: fix comment typo
Baruch Siach [Wed, 29 Apr 2015 08:28:43 +0000 (11:28 +0300)]
libmtd: fix comment typo

Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
10 years agomtd-utils: libfec: use standard C type instead of u_long
Imre Kaloz [Mon, 4 May 2015 13:36:34 +0000 (15:36 +0200)]
mtd-utils: libfec: use standard C type instead of u_long

Fixes compilation on hosts with the musl C library.
Also drops the unused u_short typedef.

Signed-off-by: Imre Kaloz <kaloz@openwrt.org>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
10 years agomkfs.ubifs: Fix build with gcc 5.1
Bernhard Walle [Sat, 2 May 2015 12:38:06 +0000 (14:38 +0200)]
mkfs.ubifs: Fix build with gcc 5.1

In gcc 5.1, the default C standard which is used to compile a C file,
has changed from gnu89 to gnu11. This changed the meaning of 'extern
inline'. See https://gcc.gnu.org/gcc-5/porting_to.html.

In mkfs.ubifs, this leads to multiple definitions of
hashtable_iterator_key and -hashtable_iterator_value. I think the most
pragmatic way to fix the issue is to replace 'extern inline' with
'static inline' here.

Signed-off-by: Bernhard Walle <bernhard@bwalle.de>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
10 years agomtd-utils: jffs2dump: XATTR and XREF support for endianess conversion
Timo Warns [Wed, 15 Oct 2014 19:16:22 +0000 (21:16 +0200)]
mtd-utils: jffs2dump: XATTR and XREF support for endianess conversion

Add support for XATTR and XREF nodes to "convert image endianness" action of
jffs2dump.

Signed-off-by: Timo Warns <timo.warns@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
10 years agomtd-utils: jffs2dump: XATTR and XREF support for content dump
Timo Warns [Wed, 15 Oct 2014 19:12:03 +0000 (21:12 +0200)]
mtd-utils: jffs2dump: XATTR and XREF support for content dump

Add support for XATTR and XREF nodes to "dump image content" action of
jffs2dump.

Signed-off-by: Timo Warns <timo.warns@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
10 years agolibmtd: don't ignore "region index" parameter in mtd_regioninfo()
Brian Norris [Mon, 15 Sep 2014 17:35:00 +0000 (10:35 -0700)]
libmtd: don't ignore "region index" parameter in mtd_regioninfo()

ioctl(MEMGETREGIONINFO) has one input parameter (regionindex) and three
output parameters (info about the erase region). There are two problems
in mtdinfo/libmtd here:

 1. mtdinfo.c doesn't initialize its region_info_user struct, instead
    passing uninitialized data to mtd_regioninfo()

 2. mtd_regioninfo() fails to utilize the 'regidx' parameter to fill out
    the regionindex parameter properly, so the garbage from mtdinfo.c is
    propagated to the ioctl()

This means that mtdinfo will continuously probe the same (possibly
out-of-range) erase region, instead of looping over the valid regions.

Let's fix this in the mtd_regioninfo() helper, and at the same time,
let's zero out the mtdinfo.c buffer, as an additional precaution to keep
from using uninitialized data.

Initial error report from Yang, when running "mtdinfo /dev/mtd0" on a
Cavium 6100 board:

root@CN61XX:~# mtdinfo /dev/mtd0
mtd0
Name:                           phys_mapped_flash
Type:                           nor
Eraseblock size:                65536 bytes, 64.0 KiB
Amount of eraseblocks:          128 (8388608 bytes, 8.0 MiB)
Minimum input/output unit size: 1 byte
Sub-page size:                  1 byte
Additional erase regions:       0
Character device major/minor:   90:0
Bad blocks are allowed:         false
Device is writable:             true
libmtd: error!: MEMGETREGIONINFO ioctl failed for erase region 0
        error 22 (Invalid argument)
Eraseblock region 0:  info is unavailable
libmtd: error!: MEMGETREGIONINFO ioctl failed for erase region 1
        error 22 (Invalid argument)
Eraseblock region 1:  info is unavailable

Reported-by: Yang Wei <Wei.Yang@windriver.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
10 years agoubifs-media.h: include "byteorder.h"
Artem Bityutskiy [Thu, 30 Oct 2014 08:14:20 +0000 (10:14 +0200)]
ubifs-media.h: include "byteorder.h"

... in order to have definitions of things like __le16.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
10 years agoMove mkfs.ubifs/ubifs-media.h to include/mtd
Artem Bityutskiy [Thu, 30 Oct 2014 07:55:51 +0000 (09:55 +0200)]
Move mkfs.ubifs/ubifs-media.h to include/mtd

This file will be shared with the ubidump tool in the future.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
10 years agomkfs.ubifs: start using common code
Artem Bityutskiy [Mon, 20 Oct 2014 10:47:09 +0000 (13:47 +0300)]
mkfs.ubifs: start using common code

Several commonly used macros are now defined in 'common.h', let's start using
them in mkfs.ubifs, instead of duplicating them.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
10 years agomtd-utils: Add macros to include/common.h
hujianyang [Thu, 16 Oct 2014 12:02:09 +0000 (20:02 +0800)]
mtd-utils: Add macros to include/common.h

This patch adds four macros:

    ALIGN, __ALIGN_MASK, min_t and max_t

to include/common.h.

Signed-off-by: hujianyang <hujianyang@huawei.com>
10 years agoubiformat: fix the subpage size hint on the error path
Artem Bityutskiy [Mon, 8 Sep 2014 12:05:54 +0000 (15:05 +0300)]
ubiformat: fix the subpage size hint on the error path

David Binderman <dcb314@hotmail.com> reports that the following piece of looks
wrong:

if (!args.subpage_size != mtd->min_io_size)
    normsg("may be sub-page size is incorrect?");

I totally agree with him and I believe that we actually meant to have no
negation in fron to f 'args.subpage_size', so instead, the code should look
like this:

if (args.subpage_size != mtd->min_io_size)
    normsg("may be sub-page size is incorrect?");

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
10 years agolibmtd: fix mtd_dev_present return value on legacy systems
Guido Martínez [Wed, 10 Sep 2014 14:56:40 +0000 (11:56 -0300)]
libmtd: fix mtd_dev_present return value on legacy systems

On legacy systems, if "/proc/mtd" doesn't exist or gives a read error,
mtd_dev_present returns -1 (since it calls legacy_dev_present), contrary
to what's specified in the header file.

This causes checks like

  if (mtd_dev_present(n)) {
    ...
  }

to give false positives. Fix this by comparing the return value to 1.

Signed-off-by: Guido Martínez <guido@vanguardiasur.com.ar>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
10 years agonandtest: fix --reads argument
Guido Martínez [Thu, 14 Aug 2014 16:29:45 +0000 (13:29 -0300)]
nandtest: fix --reads argument

The --reads option specifies the argument as optional, but doesn't check
for a null optarg, which means that nandtest segfaults when run as
"nandtest --reads".

Fix this by making the argument required, and changing the help text to
not specify it as optional. Argument -r already specifies the argument
as required, so we fix this inconsistency too.

Signed-off-by: Guido Martínez <guido@vanguardiasur.com.ar>
Acked-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
11 years agonandtest: Introduce multiple reads & check iterations
Ezequiel García [Tue, 6 May 2014 15:07:49 +0000 (12:07 -0300)]
nandtest: Introduce multiple reads & check iterations

The current nandtest performs a simple test which consists of:

  1. erase block
  2. write data
  3. read and verify

In order to improve the nandtest strength, this commit adds a new parameter
to increase the number of "read and verify" iterations. In other words,
the test now consists of:

  1. erase block
  2. write data
  3. read and verify (N times)

This seem to apply more pressure on a NAND driver's ECC engine and has been
used to discover stability problems with an old OMAP2.

Signed-off-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
Acked-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
11 years agonandtest: Move the "read and compare" code to a function
Ezequiel Garcia [Mon, 28 Apr 2014 13:14:18 +0000 (10:14 -0300)]
nandtest: Move the "read and compare" code to a function

This commit makes no functionality change, and simply moves the
read and compare code into a separate read_and_compare() function.

Signed-off-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
11 years agonandtest: Remove redundant check
Ezequiel Garcia [Mon, 28 Apr 2014 13:14:17 +0000 (10:14 -0300)]
nandtest: Remove redundant check

This commit removes a redundant 'len' check, which is already performed
just after the pread call.

Signed-off-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
11 years agoinclude/common.h: fix build against recent 0.9.33 uClibc
Baruch Siach [Wed, 16 Apr 2014 04:52:48 +0000 (07:52 +0300)]
include/common.h: fix build against recent 0.9.33 uClibc

An implementation of rpmatch() was backported to the 0.9.33 branch of uClibc.
So the uClibc version check introduced in commit 50c9e11f7e (include/common.h:
fix build against current uClibc) is not enough. Rename the local rpmatch()
implementation to avoid collision.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Acked-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
11 years agomtd-utils: integck: Use $(CC) and $(AR) instead of 'gcc' and 'ar' consistently
Mats Kärrman [Fri, 11 Apr 2014 07:38:21 +0000 (09:38 +0200)]
mtd-utils: integck: Use $(CC) and $(AR) instead of 'gcc' and 'ar' consistently

Not using the macros may be a problem when cross-compiling.

Signed-off-by: Mats Karrman <mats.karrman@tritech.se>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
11 years agoinclude/common.h: fix build against current uClibc
Baruch Siach [Sun, 13 Apr 2014 12:26:46 +0000 (15:26 +0300)]
include/common.h: fix build against current uClibc

Commit dbe0fd17f2 (mtd-utils: new prompt() helper for talking to the user)
introduced a rpmatch() call. However, uClibc versions older than (not yet
released) 0.9.34 don't have rpmatch() implementation. Add one.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>
11 years agomake_a_release.sh: suggest announcement e-mail
Artem Bityutskiy [Mon, 7 May 2012 08:44:38 +0000 (11:44 +0300)]
make_a_release.sh: suggest announcement e-mail

The 'make_a_release.sh' script appears to be extremely useful - I do not
forget things as I used to anymore (amending Makefile, signing, uploading
to the FTP server, etc). It is very useful that it suggest me exact commands
which I may just copy-past to my command line.

This patch improves the script and makes it suggest the e-mail announcement
which I may just copy-paste to my command line and the announcement will
be sent using 'git send-email' command. It will include all the interested
parties in CC.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
11 years agoRelease mtd-utils-1.5.1 v1.5.1
Artem Bityutskiy [Mon, 7 Apr 2014 11:01:36 +0000 (14:01 +0300)]
Release mtd-utils-1.5.1

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
11 years agoubiformat: correct "non-ubifs" warning message
Brian Norris [Mon, 31 Mar 2014 17:03:04 +0000 (10:03 -0700)]
ubiformat: correct "non-ubifs" warning message

UBI's raw flash scan actually scans for UBI data, not UBIFS data (there
*are* UBI users that are not UBIFS!), so correct the warning message.
This also matches the comment in libscan.h.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
11 years agoubi-utils: Fix file descriptor leaks in libubi
Daniel van Gerpen [Sat, 29 Mar 2014 23:52:10 +0000 (00:52 +0100)]
ubi-utils: Fix file descriptor leaks in libubi

Amended by Artem.

Signed-off-by: Daniel van Gerpen <daniel@vangerpen.de>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
11 years agomkfs.ubifs: correct and improve LEB size error prints
Brian Norris [Sat, 22 Mar 2014 06:45:44 +0000 (23:45 -0700)]
mkfs.ubifs: correct and improve LEB size error prints

The error message is incorrect for "too small LEB size" -- we were
printing the minimum I/O size instead of the LEB size.

At the same time, let's print the max LEB size along with the message
for "too large LEB size", to be consistent and more helpful.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
11 years agoubi-utils: Add ubiblock tool
Ezequiel Garcia [Fri, 14 Mar 2014 14:25:24 +0000 (11:25 -0300)]
ubi-utils: Add ubiblock tool

With the addition of block device access to UBI volumes, we now
add a simple userspace tool to access the new ioctls.

Usage of this tool is as simple as it gets:

  $ ubiblock --create /dev/ubi0_0

will create a new block device /dev/ubiblock0_0, and

  $ ubiblock --remove /dev/ubi0_0

will remove the device.

Artem: slightly changed the header comment.

Signed-off-by: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
11 years agomtd-utils: Makefile: add LDFLAGS_mkfs.ubifs
Aaron Sierra [Fri, 27 Sep 2013 16:34:04 +0000 (11:34 -0500)]
mtd-utils: Makefile: add LDFLAGS_mkfs.ubifs

The build rule for mkfs.ubifs was missing an LDFLAGS_* variable like
mkfs.jffs2 had. This prevented mkfs.ubifs from being built against
explicit external libraries which is needed when cross-compiling.

This also adds UUIDCPPFLAGS and UUIDLDFLAGS variables to support the
mkfs.ubifs build.

Signed-off-by: Aaron Sierra <asierra@xes-inc.com>
11 years agoflash_erase: check the nand type
Huang Shijie [Thu, 24 Oct 2013 10:59:51 +0000 (18:59 +0800)]
flash_erase: check the nand type

Now, the MTD_NANDFLASH stands for SLC nand, and the MTD_MLCNANDFLASH
stands for the MLC nand.

This patch includes the stdbool.h, and changes the "isNAND" to boolean type,
and checks the right nand type for the MLC and SLC nand.

If the user wants to format a MLC nand for JFFS2, we will print out a message
to warn him, and exit right now.

Signed-off-by: Huang Shijie <b32955@freescale.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
11 years agocheck the MLC nand type
Huang Shijie [Tue, 20 Aug 2013 05:58:37 +0000 (13:58 +0800)]
check the MLC nand type

In the current code, the MTD_NANDFLASH stands for both the SLC and MLC.

In the kernel, the MTD_NANDFLASH only stands for the SLC now,
so in order to keep the logic unchanged, we should also check the MLC
NAND by MTD_MLCNANDFLASH.

Signed-off-by: Huang Shijie <b32955@freescale.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
11 years agoflash_otp_write: use helper to check the nand
Huang Shijie [Tue, 20 Aug 2013 05:58:36 +0000 (13:58 +0800)]
flash_otp_write: use helper to check the nand

Use the mtd_type_is_nand_user() helper to check if it is a NAND
(including SLC/MLC).

Signed-off-by: Huang Shijie <b32955@freescale.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
11 years agomtd: mtd-abi: add a helper to detect the nand type
Huang Shijie [Tue, 20 Aug 2013 05:58:35 +0000 (13:58 +0800)]
mtd: mtd-abi: add a helper to detect the nand type

The helper is for user applications, and it is just a copy of
the kernel helper: mtd_type_is_nand();

Signed-off-by: Huang Shijie <b32955@freescale.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
11 years agoadd the MTD_MLCNANDFLASH case
Huang Shijie [Tue, 20 Aug 2013 05:58:34 +0000 (13:58 +0800)]
add the MTD_MLCNANDFLASH case

The MTD_MLCNANDFLASH case is missed in the current code.
This patch adds it.

Signed-off-by: Huang Shijie <b32955@freescale.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
12 years agoubiupdatevol: add a --skip option
Mike Frysinger [Thu, 9 May 2013 17:59:24 +0000 (13:59 -0400)]
ubiupdatevol: add a --skip option

This already has a --size option for controlling how many bytes to read
from the input.  Add a --skip option to control the offset into the input
too.  This way people don't have to do `dd | ubiupdatevol`.

While we're here, I've fixed the types used with args.size and the read
loop so that they can hold the right sizes (like setting a 32bit+ size).

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agonandwrite: amendment to Mike's --input-* series
Artem Bityutskiy [Mon, 1 Jul 2013 06:12:43 +0000 (09:12 +0300)]
nandwrite: amendment to Mike's --input-* series

This is a delta between v1 and v2 of the patches. I pushed v1 instead of
picking v2, and this is a fixup.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agonandwrite: add --input-{skip,size} options
Mike Frysinger [Thu, 9 May 2013 00:03:14 +0000 (20:03 -0400)]
nandwrite: add --input-{skip,size} options

If you have a file image and want to copy sub-portions out and into
NAND, there's no easy way to do that.  You can use dd to extract it
to a temp file, or pipe it to nandwrite 1 page at a time.  Both suck.

Add two new flags to explicitly set the size and offset of the input
file.  Seeking stdin isn't currently supported as I'm not sure it's
necessary.  It wouldn't be hard to add though...

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agonandwrite: clean up length types
Mike Frysinger [Thu, 9 May 2013 00:03:13 +0000 (20:03 -0400)]
nandwrite: clean up length types

We use 'int' in many places to represent offsets/sizes.  That obviously
does not play well with larger NAND devices on 32bit systems.  Instead,
use the right type as needed:
 - long long to represent the length of the image
 - use fstat() rather than lseek();lseek(); to get the length of the image
 - use size_t/ssize_t when working with read()
 - tweak the printf formats as needed

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agonand{dump, test, write}: clean up --help handling
Mike Frysinger [Wed, 8 May 2013 23:02:03 +0000 (19:02 -0400)]
nand{dump, test, write}: clean up --help handling

We should send the output to stdout when the user passes -h/--help
and then exit(0), but otherwise the output should go to stderr and
then exit(1).

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agouse xstrdup in a few more places
Mike Frysinger [Wed, 8 May 2013 23:01:55 +0000 (19:01 -0400)]
use xstrdup in a few more places

These call sites either assume there is no failure (they deref the
pointer right away), or the exit themselves.  Use xstrdup() instead.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agomkfs.ubifs: allow reformatting of devices
Mike Frysinger [Wed, 8 May 2013 16:27:26 +0000 (12:27 -0400)]
mkfs.ubifs: allow reformatting of devices

Sometimes I want to re-initialize an existing ubifs, but the tool
currently bails out if the volume is already formatted.  Prompt the
user instead so they can decide.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agomtd-utils: new prompt() helper for talking to the user
Mike Frysinger [Wed, 8 May 2013 16:27:25 +0000 (12:27 -0400)]
mtd-utils: new prompt() helper for talking to the user

We've got a few tools that prompt the user for "yes/no" questions.
Add a common helper to simplify the various implementations.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agomove _GNU_SOURCE to the main makefile
Mike Frysinger [Wed, 8 May 2013 16:27:24 +0000 (12:27 -0400)]
move _GNU_SOURCE to the main makefile

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>
12 years agofix build errors w/newer kernel headers & glibc
Mike Frysinger [Wed, 8 May 2013 16:26:13 +0000 (12:26 -0400)]
fix build errors w/newer kernel headers & glibc

Building with linux-headers-3.9 and glibc-2.17 fails like so:
In file included from summary.h:15:0,
                 from jffs2dump.c:37:
/usr/include/linux/uio.h:16:8: error: redefinition of 'struct iovec'
 struct iovec
        ^
In file included from /usr/include/bits/fcntl-linux.h:38:0,
                 from /usr/include/bits/fcntl.h:61,
                 from /usr/include/fcntl.h:35,
                 from jffs2dump.c:25:
/usr/include/bits/uio.h:43:8: note: originally defined here
 struct iovec
        ^

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
12 years agoftl_check/ftl_format/nftldump: use existing mtd_swab.h header
Mike Frysinger [Wed, 8 May 2013 16:21:23 +0000 (12:21 -0400)]
ftl_check/ftl_format/nftldump: use existing mtd_swab.h header

We already have a helper header for swapping bytes as needed, so cut
the ftl tools over to that rather than re-implement things.

I don't actually have any devices with this kind of flash, so I can't
runtime test it.  But things *look* ok to me :).

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
12 years agoubinize: fix usage text
Mike Frysinger [Mon, 6 May 2013 22:54:07 +0000 (18:54 -0400)]
ubinize: fix usage text

Drop duplicate "and the", and tweak grammar slightly.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agoflash_erase: use pwrite() rather than lseek() && write()
Mike Frysinger [Thu, 2 May 2013 16:33:21 +0000 (12:33 -0400)]
flash_erase: use pwrite() rather than lseek() && write()

Saves a syscall.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agointegck: fix identation a bit
Artem Bityutskiy [Mon, 11 Mar 2013 08:44:29 +0000 (10:44 +0200)]
integck: fix identation a bit

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agoTypo fixes: avaiable -> available and priortiry -> priority
Elie De Brauwer [Fri, 1 Mar 2013 18:37:40 +0000 (19:37 +0100)]
Typo fixes: avaiable -> available and priortiry -> priority

Signed-off-by: Elie De Brauwer <eliedebrauwer@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agointegck.c: Fix buffer overflow in save_file
Elie De Brauwer [Fri, 1 Mar 2013 18:37:39 +0000 (19:37 +0100)]
integck.c: Fix buffer overflow in save_file

In the problem above I've spend several hours waiting for the issue to
appear, only to had the 'luck' that it was found in a file whose name was
256 bytes in length, resulting in the write to fail. Closer examination
showed that the buffer to store the path was 256 bytes in length, but this
buffer also includes /tmp and the read/write suffix and should be able to
contain a filename which is up to 255 bytes (NAME_MAX in linux/limits.h)
in size which is a bad fit. So that array is modified to FILENAME_MAX
(stdio_lim.h) and some checking is added to truncate the filename should
it cause an overflow.

The following log shows the first patch in action (see the correct seed),
and shows why this third patch is needed:
<quote>
integck:     File Data:
integck:         Offset: 0  Size: 1  Seed: 5008310  R.Off: 0
integck:     1 writes
integck:     ============================================
integck:     Write Info:
integck:         Offset: 0  Size: 1  Seed: 5008310  R.Off: 0
integck:         Offset: 0  Size: 1  Seed: 8246352  R.Off: 0
integck:         Offset: 0  Size: 1  Seed: 5078796  R.Off: 0
integck:         Offset: 0  Size: 1  Seed: 2267087  R.Off: 0
integck:         Offset: 0  Size: 1  Seed: 3602680  R.Off: 0
integck:     5 writes or truncations
integck:     ============================================
integck: Saving /tmp/yqcnfygfitaatyeyvffrguegcdttamcnyhowhgieljfuxfipiljsjcbluaeaghwyinkggommsbwnmvekihgnwgiibccpbwfrpxuxwkmnyghnutrudienngxwgorudbskedaaekiuiyqksfazrwzfwbfhzjjqoiulebtlpbfiuffmsnguqkjzqjqizimsmhbqqagaebjdhqwmzdxghiavtcxubegawlgtvstuqurkurpnrckjfkgostdtpg.integ.sav.readn
integck: error!: condition 'w_fd != -1' failed in save_file() at integck.c:1445
integck: error 36 (File name too long)
</quote>

Signed-off-by: Elie De Brauwer <eliedebrauwer@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agointegck.c: rework file_check_data to immediately dump the buffer containing the errors
Elie De Brauwer [Fri, 1 Mar 2013 18:37:38 +0000 (19:37 +0100)]
integck.c: rework file_check_data to immediately dump the buffer containing the errors

See my problem description int the previous commit, the point is that integck
in file_check_data reads a buffer, and then checks if the data is correct,  it
will do a seek(0), and reread from the same fd. The point is that in the
scenario I observed integck failed (due to a buffer mismatch) but the it saved
(and what was in flash) was actually correct. So I modified this function to
dump the buffers to stderr at the moment an error is found.

Signed-off-by: Elie De Brauwer <eliedebrauwer@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agointegck.c: Only verify the operation after all datastructures have been updated
Elie De Brauwer [Fri, 1 Mar 2013 18:37:37 +0000 (19:37 +0100)]
integck.c: Only verify the operation after all datastructures have been updated

<quote>
integck:     File Data:
integck:         Offset: 0  Size: 196  Seed: 5999877  R.Off: 0
integck:         Offset: 196  Size: 33  Seed: 4160795  R.Off: 0
integck:         Offset: 229  Size: 1252  Seed: 8070052  R.Off: 0
integck:         Offset: 1481  Size: 612  Seed: 4160795  R.Off: 1285
integck:         Offset: 2093  Size: 6  Seed: 6946586  R.Off: 0
integck:         Offset: 2099  Size: 536  Seed: 4160795  R.Off: 1903
integck:         Offset: 2635  Size: 1562  Seed: 9845455  R.Off: 0
integck:         Offset: 4197  Size: 80  Seed: 702818  R.Off: 0
integck:         Offset: 4277  Size: 115  Seed: 9845455  R.Off: 1642
integck:     9 writes
integck:     ============================================
integck:     Write Info:
integck:         Offset: 826  Size: 357  Seed: 5908448  R.Off: 0
integck:         Offset: 4197  Size: 80  Seed: 702818  R.Off: 0
...
</quote>
And I would expect the file data listing to include at offset 826 something
with a size of 357 and a seed of 5908448. Clearly it is not there (which
is already extremely confusing). The point is that file_write_info first
updates the raw_write, then verifies the data (passing the new write)
and only after that updates the write structure. But in file_check_data
only the newly written data is verified (passed as an argument) whilst
the save_file() function to dump the file uses the raw_writes to recreate
the written data (while raw_writes is only updated after after this check
would have succeeded). Several lines to say that in this patch the verify
only gets called _after_ the datastructures are updated.

Signed-off-by: Elie De Brauwer <eliedebrauwer@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agoflash_otp_write: fix a buffer overflow on NAND with write size > 2048
Uwe Kleine-König [Thu, 28 Feb 2013 09:42:26 +0000 (10:42 +0100)]
flash_otp_write: fix a buffer overflow on NAND with write size > 2048

I'm not aware of any chip having a write size bigger than 2048 today.
Still checking for that instead of a sleeping problem to bite us maybe
in a few years is easy.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agoflash_otp_write: fix writing to NAND in presence of partial reads
Uwe Kleine-König [Thu, 28 Feb 2013 09:42:09 +0000 (10:42 +0100)]
flash_otp_write: fix writing to NAND in presence of partial reads

When doing something like:

{ printf "\xff"; printf "\xfe"; } | flash_otp_write -u /dev/mtd0 0

flash_otp_write might see only a single byte when reading from stdin for
the first tim. In this case (and without this patch) it pads to
$writesize with '\xff's and writes that out. In the next iteration it
reads the 2nd byte, pads and writes again. So the 2nd byte is written to
offset $writesize instead of 1.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agoMakefile: also build and install flash_otp_lock and flash_otp_write
Uwe Kleine-König [Wed, 20 Feb 2013 16:41:31 +0000 (17:41 +0100)]
Makefile: also build and install flash_otp_lock and flash_otp_write

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agoubiformat: fix error path
Wolfram Sang [Thu, 13 Dec 2012 16:41:14 +0000 (17:41 +0100)]
ubiformat: fix error path

A few error paths were closing the device, although it was not opened
yet.

Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agoubiformat: clean up synopsis of command-line parameters
Wolfram Sang [Thu, 13 Dec 2012 16:35:58 +0000 (17:35 +0100)]
ubiformat: clean up synopsis of command-line parameters

Add -Q and --image-seq, remove double -v

Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agoubi-tests: fix pthreads linking
Brian Norris [Sun, 25 Nov 2012 07:26:09 +0000 (23:26 -0800)]
ubi-tests: fix pthreads linking

Technically, '-l' linker options should be included only after the
objects which must link to the library. So when we include '-lpthread'
in the LDFLAGS variable, it gets placed too early (i.e., before the
io_paral.o object), and so the pthread linkage never occurs. The
following error probably only shows up with linkers that don't link
pthreads by default.

$ make tests V=1
...
gcc -I../../ubi-utils//include -I ../../include -lpthread -Wall -Wextra -Wwrite-strings -Wno-sign-compare -ffunction-sections -fdata-sections -Wl,--gc-sections   -g -o /home/norris/git/mtd-utils/tests/ubi-tests/io_paral /home/norris/git/mtd-utils/tests/ubi-tests/io_paral.o /home/norris/git/mtd-utils/tests/ubi-tests/helpers.o libubi.a
/home/norris/git/mtd-utils/tests/ubi-tests/io_paral.o: In function `main':
/home/norris/git/mtd-utils/tests/ubi-tests/io_paral.c:287: undefined reference to `pthread_create'
/home/norris/git/mtd-utils/tests/ubi-tests/io_paral.c:295: undefined reference to `pthread_create'
/home/norris/git/mtd-utils/tests/ubi-tests/io_paral.c:303: undefined reference to `pthread_join'
collect2: ld returned 1 exit status
make[2]: *** [/home/norris/git/mtd-utils/tests/ubi-tests/io_paral] Error 1
...

$ ld --version
GNU ld (GNU Binutils for Ubuntu) 2.22
...
$ gcc --version
gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
...

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agoubi-tests: switch to using common.h from the top level
Artem Bityutskiy [Fri, 16 Nov 2012 07:56:52 +0000 (09:56 +0200)]
ubi-tests: switch to using common.h from the top level

Sorry, the commit is huge, I just did not have time to split it.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agoubi-tests: rename common.[ch] to helpers.[ch]
Artem Bityutskiy [Fri, 16 Nov 2012 07:52:21 +0000 (09:52 +0200)]
ubi-tests: rename common.[ch] to helpers.[ch]

... to avoid confusion when the local common.h shadows the top-level common.h.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agoubi-tests: ubi_leb_change_start() no longer uses 'dtype'.
Bill Pringlemeir [Mon, 5 Nov 2012 17:38:36 +0000 (12:38 -0500)]
ubi-tests: ubi_leb_change_start() no longer uses 'dtype'.

This will not compile for me (due to bit rot?).  Maybe the program is
never used?

Signed-off-by: Bill Pringlemeir <bpringlemeir@nbsps.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agoubiformat: really skip some messages when quiet
Wolfram Sang [Sat, 20 Oct 2012 15:12:56 +0000 (17:12 +0200)]
ubiformat: really skip some messages when quiet

Both logic (only print when not quiet) and the indentation suggest that
the braces around the block have been forgotten.

Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agomkfs.ubifs: Improve error handling of is_contained()
Marcus Prebble [Tue, 16 Oct 2012 11:51:01 +0000 (13:51 +0200)]
mkfs.ubifs: Improve error handling of is_contained()

The is_contained() function returns -1 if an error occurs when
canonicalizing the output file path/root directory. This resulted in the
confusing error message 'Error: The output file cannot be in the UBIFS
root' when specifying a non-existent directory for the output.
This patch changes the error handling to display a different error
message for the case when is_contained() returns -1.
Additionally it frees all memory allocated by is_contained().

Signed-off-by: Marcus Prebble <marcus.prebble@axis.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agomkfs.ubifs: rewrite path checking
Artem Bityutskiy [Wed, 10 Oct 2012 11:23:18 +0000 (14:23 +0300)]
mkfs.ubifs: rewrite path checking

We use the 'in_path()' function to check whether the output image is
withing the mkfs.ubifs root directory or not. However, this function
is not correct and it fails for the following situation, as
Marcus Prebble <marcus.prebble@axis.com> reports:

1. We have our root file-system mounted at / and want to build an image
   out of it.
2. We have tmpfs mounted at /tmp
3. We mount the root file-system under /tmp/newroot
4. We run mkfs.ubifs with -r /tmp/newroot -o /tmp/image

And this fails. It fails because 'in_path()' misses this use-case.

This patch re-implements the check completely. Now we use 'realpath()'
to find canonical paths and just check that the output file is not
under the root mkfs.ubifs directory.

Reported-by: Marcus Prebble <marcus.prebble@axis.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Tested-by: Marcus Prebble <marcus.prebble@axis.com>
12 years agomkfs.jffs2: correct some warnings using PRIdoff_t
Richard Genoud [Wed, 12 Sep 2012 14:38:35 +0000 (16:38 +0200)]
mkfs.jffs2: correct some warnings using PRIdoff_t

When compiled with WITHOUT_LARGEFILE, there was warnings like that:
warning: format '%9llu' expects type 'long long unsigned int',
but argument 3 has type '__off_t'

Using PRIdoff_t corrects that.

Signed-off-by: Richard Genoud <richard.genoud@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agoconsistency between u_int32_t / off_t / off64_t
Richard Genoud [Wed, 12 Sep 2012 14:38:34 +0000 (16:38 +0200)]
consistency between u_int32_t / off_t / off64_t

We should use the off_t type instead of off64_t or u_int32_t as its
length is controlled by the WITHOUT_LARGEFILE flag.

Signed-off-by: Richard Genoud <richard.genoud@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agointroduce PRIxoff_t and PRIdoff_t printf helpers
Richard Genoud [Wed, 12 Sep 2012 14:38:33 +0000 (16:38 +0200)]
introduce PRIxoff_t and PRIdoff_t printf helpers

They will be usefull when printing offsets.

Signed-off-by: Richard Genoud <richard.genoud@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agotests: io_update correct lseek parameters order
Richard Genoud [Wed, 12 Sep 2012 14:37:54 +0000 (16:37 +0200)]
tests: io_update correct lseek parameters order

There's a typo in lseek parameters order.

But, due to the value of SEEK_SET, this commit doesn't introduce a
change.

Signed-off-by: Richard Genoud <richard.genoud@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agoubiformat: fix failure on big partitions (>4Gio)
Richard Genoud [Wed, 12 Sep 2012 14:37:19 +0000 (16:37 +0200)]
ubiformat: fix failure on big partitions (>4Gio)

The offset (which is 64bits when mtd-utils are not compile with
WITHOUT_LARGEFILE) is calculated like that:
offset = nb * size;
But nb and size are int, so on 32bits platforms, there's a possible
overflow.

So, it should be replace with:
offset = (off_t)nb * size;
If WITHOUT_LARGEFILE is defined, there still be an overflow, but it's
what we want, right ?

Cheney Chen tested an ubiformat on a NAND (5.9 GiB mtd part).

Reported-by: Cheney Chen <cheneychencl2012@gmail.com>
Tested-by: Cheney Chen <cheneychencl2012@gmail.com>
Signed-off-by: Richard Genoud <richard.genoud@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agoubirmvol: correct missing space on usage
Richard Genoud [Fri, 31 Aug 2012 14:50:05 +0000 (16:50 +0200)]
ubirmvol: correct missing space on usage

Signed-off-by: Richard Genoud <richard.genoud@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agoubiattach: fail if kernel ignores max_beb_per1024
Richard Genoud [Wed, 22 Aug 2012 16:04:37 +0000 (18:04 +0200)]
ubiattach: fail if kernel ignores max_beb_per1024

If the kernel doesn't know the max_beb_per1024 parameter in the attach
ioctl, but the call still succeeded ubi_attach and ubi_attach_mtd will
return 1 instead of 0.

In this case, the ubiattach command will detach the device and fail with
an error message.

Signed-off-by: Richard Genoud <richard.genoud@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agoubiattach: introduce max_beb_per1024 in UBI_IOCATT
Richard Genoud [Wed, 22 Aug 2012 16:04:36 +0000 (18:04 +0200)]
ubiattach: introduce max_beb_per1024 in UBI_IOCATT

The ioctl UBI_IOCATT has been extended with max_beb_per1024 parameter.

This parameter is used for adjusting the "maximum expected number of
bad blocks per 1024 blocks" for each mtd device.
The number of physical erase blocks (PEB) that UBI will reserve for bad
block handling is now:
whole_flash_chipset__PEB_number * max_beb_per1024 / 1024

This means that for a 4096 PEB NAND device with 3 MTD partitions:
mtd0: 512 PEB
mtd1: 1536 PEB
mtd2: 2048 PEB

the commands:
ubiattach -m 0 -d 0 -b 20 /dev/ubi_ctrl
ubiattach -m 1 -d 1 -b 20 /dev/ubi_ctrl
ubiattach -m 2 -d 2 -b 20 /dev/ubi_ctrl
will attach mtdx to UBIx and reserve:
80 PEB for bad block handling on UBI0
80 PEB for bad block handling on UBI1
80 PEB for bad block handling on UBI2

=> for the whole device, 240 PEB will be reserved for bad block
handling.

This may seems a waste of space, but as far as the bad blocks can appear
every where on a flash device, in the worst case scenario they can
all appear in one MTD partition.
So the maximum number of expected erase blocks given by the NAND
manufacturer should be reserve on each MTD partition.

Signed-off-by: Richard Genoud <richard.genoud@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agolibubi: kill ubi_attach_mtd
Artem Bityutskiy [Thu, 23 Aug 2012 08:37:05 +0000 (11:37 +0300)]
libubi: kill ubi_attach_mtd

The 'ubi_attach_mtd()' is not used and it is redundant now. 'ubi_attach()'
function may be used instead.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agolibubi: factorize ubi_attach and ubi_attach_mtd code
Richard Genoud [Wed, 22 Aug 2012 16:04:34 +0000 (18:04 +0200)]
libubi: factorize ubi_attach and ubi_attach_mtd code

The req->mtd_num value is now updated with the MTD device number found
by mtd_node_to_num.

Signed-off-by: Richard Genoud <richard.genoud@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agoubi-user.h: add max_beb_per1024 parameter
Richard Genoud [Wed, 22 Aug 2012 09:27:59 +0000 (11:27 +0200)]
ubi-user.h: add max_beb_per1024 parameter

Signed-off-by: Richard Genoud <richard.genoud@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agoUBI: sync ubi-user.h with kernel v3.6-rc1
Richard Genoud [Wed, 22 Aug 2012 09:27:56 +0000 (11:27 +0200)]
UBI: sync ubi-user.h with kernel v3.6-rc1

Also remove the eraseblock type support, because kernel commit
a65a0eb6d198e058687a9214683bd1c418f20d39 set the dtype
parameter as obsolete.

Also adjust to some renames:
* 'UBI_PROP_DIRECT_WRITE' -> 'UBI_VOL_PROP_DIRECT_WRITE'
* 'struct ubi_set_prop_req' -> 'struct ubi_set_vol_prop_req'.
* 'UBI_IOCSETPROP' -> 'UBI_IOCSETVOLPROP'

Signed-off-by: Richard Genoud <richard.genoud@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agostress-test.sh: remove a warning
Artem Bityutskiy [Fri, 3 Aug 2012 14:25:40 +0000 (17:25 +0300)]
stress-test.sh: remove a warning

If /proc/mtd does not exist, we have this warning:
grep: /proc/mtd: No such file or directory

Get rid of this.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agostress-test.sh: add mtdram tests
Artem Bityutskiy [Fri, 3 Aug 2012 13:38:16 +0000 (16:38 +0300)]
stress-test.sh: add mtdram tests

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agostress-test.sh: support testing without sub-pages
Artem Bityutskiy [Fri, 3 Aug 2012 12:36:04 +0000 (15:36 +0300)]
stress-test.sh: support testing without sub-pages

Run the tests with VID header at the second page as well for better coverage.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agostress-test.sh: develop the test further
Artem Bityutskiy [Fri, 3 Aug 2012 08:33:07 +0000 (11:33 +0300)]
stress-test.sh: develop the test further

Add a lot of test passes on nandsim with different geometry.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agoruntests.sh: print more consistent messages
Artem Bityutskiy [Fri, 3 Aug 2012 08:32:18 +0000 (11:32 +0300)]
runtests.sh: print more consistent messages

On success we print "SUCCESS", lets print "FAILURE" on failure.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agoload_nandsim: switch to sh
Artem Bityutskiy [Fri, 3 Aug 2012 07:35:36 +0000 (10:35 +0300)]
load_nandsim: switch to sh

We do not use bashizms any longer, so we can switch to 'sh'. Also, use
strict sh options.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agoload_nandsim.sh: simplify the code
Artem Bityutskiy [Fri, 3 Aug 2012 07:33:35 +0000 (10:33 +0300)]
load_nandsim.sh: simplify the code

First find out what the kernel module parameters should be, then load it
once, instead of doing it in each 'case' section.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agoload_nandsim.sh: rename variable
Artem Bityutskiy [Fri, 3 Aug 2012 07:22:40 +0000 (10:22 +0300)]
load_nandsim.sh: rename variable

Rename local variables - make them more descriptive and stop using capital
letters.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agoload_nandsim.sh: introduce a separate usage function
Artem Bityutskiy [Fri, 3 Aug 2012 07:19:07 +0000 (10:19 +0300)]
load_nandsim.sh: introduce a separate usage function

Just because this is more readable.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agoload_nandsim.sh: intruduce fatal function
Artem Bityutskiy [Fri, 3 Aug 2012 07:18:04 +0000 (10:18 +0300)]
load_nandsim.sh: intruduce fatal function

And used it, which simplifies the code.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agoload_nandsim.sh: use dochere for help output
Artem Bityutskiy [Fri, 3 Aug 2012 07:14:33 +0000 (10:14 +0300)]
load_nandsim.sh: use dochere for help output

Because it is cleaner.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agostress-test.sh: do not use pipe unnecessarily
Artem Bityutskiy [Fri, 3 Aug 2012 07:11:02 +0000 (10:11 +0300)]
stress-test.sh: do not use pipe unnecessarily

Use 'grep patt file' instead of cat file | grep patt.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agoload_nandsim.sh: use less bashisms + cleanups
Artem Bityutskiy [Fri, 3 Aug 2012 07:09:17 +0000 (10:09 +0300)]
load_nandsim.sh: use less bashisms + cleanups

Use posix shell constructs in the "if" statements.
Additionally, use quotes everywhere for variables.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agoload_nandsim.sh: remove useless function
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.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agotests: ubi: add stress-test.sh
Artem Bityutskiy [Thu, 2 Aug 2012 18:51:43 +0000 (21:51 +0300)]
tests: ubi: add stress-test.sh

It is not finished yet, but it will run all tests on nandsim and mtdram
of different geometry.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agotests: ubi: clean-up runtests.sh some more
Artem Bityutskiy [Thu, 2 Aug 2012 14:51:39 +0000 (17:51 +0300)]
tests: ubi: clean-up runtests.sh some more

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 years agotests: ubi: clean-up the runtests.sh script
Artem Bityutskiy [Thu, 2 Aug 2012 14:38:05 +0000 (17:38 +0300)]
tests: ubi: clean-up the runtests.sh script

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
13 years agomtd-utils: Check mtdoffset is not larger than mtd.size in case of a bad block.
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.

Signed-off-by: Tomer Barletz <barletz@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
13 years agonandwrite: minor cleanups
Artem Bityutskiy [Fri, 29 Jun 2012 07:18:57 +0000 (10:18 +0300)]
nandwrite: minor cleanups

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>
13 years agoRelease mtd-utils-1.5.0 v1.5.0
Artem Bityutskiy [Mon, 7 May 2012 07:19:39 +0000 (10:19 +0300)]
Release mtd-utils-1.5.0

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
13 years agomtd-utils: better document --pagesize of mkfs.jffs2
Shmulik Ladkani [Thu, 3 May 2012 18:59:59 +0000 (21:59 +0300)]
mtd-utils: better document --pagesize of mkfs.jffs2

Add a strict explanation '--pagesize' refers to target system's mm page
size.

Signed-off-by: Shmulik Ladkani <shmulik.ladkani@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
13 years agoMakefile: fixup previous 'make clean' fix
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>
13 years agoMakefile: fix "make clean" for old GNU find
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>
13 years agomkfs.ubifs: do not ignore --max-leb-cnt when formatting an UBI volume
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.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
13 years agolibmtd_legacy: don't open device in R/W
Brian Norris [Wed, 8 Feb 2012 21:26:21 +0000 (13:26 -0800)]
libmtd_legacy: don't open device in R/W

On legacy kernels with ROM devices, we can get mtdinfo errors like:

libmtd: error!: cannot open "/dev/mtd4"
        error 13 (Permission denied)
mtdinfo: error!: libmtd failed get MTD device 4 information
         error 13 (Permission denied)

We don't need O_RDRW access for informational ioctls(), so make this
O_RDONLY.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
13 years agolibmtd: perform device checking first
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>
13 years agolibmtd: fix mtd_write() issues for large data-only writes
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:

  ...
  ubiformat: flashing eraseblock 12 -- 72 % complete
  ubiformat: page allocation failure.
  order:8, mode:0xd0
  Call Trace:
  [<8043fa7c>] dump_stack+0x8/0x34
  [<8008c940>] __alloc_pages_nodemask+0x408/0x618
  [<800bd748>] cache_alloc_refill+0x400/0x730
  [<800bdbbc>] __kmalloc+0x144/0x154
  [<8009cae4>] memdup_user+0x24/0x94
  [<802d04e4>] mtd_ioctl+0xba8/0xbd0
  [<802d0544>] mtd_unlocked_ioctl+0x38/0x5c
  [<800d43c0>] do_vfs_ioctl+0xa4/0x6e4
  [<800d4a44>] sys_ioctl+0x44/0xa0
  [<8000f95c>] stack_done+0x20/0x40
  ...
  libmtd: error!: MEMWRITE ioctl failed for eraseblock 12 (mtd0)
          error 12 (Cannot allocate memory)
  ubiformat: error!: cannot write eraseblock 12
             error 12 (Cannot allocate memory)

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>