]> www.infradead.org Git - mtd-utils.git/log
mtd-utils.git
2 years agonandflipbits: fix corrupted oob
Christophe Kerello [Thu, 16 Jun 2022 07:39:43 +0000 (09:39 +0200)]
nandflipbits: fix corrupted oob

If a bit is flipped in block 1 or higher, the OOB is corrupted with the
OOB of block 0. Mtd_read_oob API has to take into account the block number
to be able to calculate the right offset.

Fixes: 9fc8db29cf62 ("mtd-utils: Add nandflipbits tool")
Signed-off-by: Christophe Kerello <christophe.kerello@foss.st.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
2 years agoubinfo: Fix --vol_id return code for absent volume id
Andrew Mellor [Mon, 6 Jun 2022 06:38:46 +0000 (16:38 +1000)]
ubinfo: Fix --vol_id return code for absent volume id

When using --vol_id and that volume is missing, it should return
non-zero like the --name option does.

Signed-off-by: Andrew Mellor <andrew.mellor@casa-systems.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
2 years agomtd-utils: nanddump: fix writing big images on 32bit machines
Sascha Hauer [Wed, 8 Jun 2022 07:51:14 +0000 (09:51 +0200)]
mtd-utils: nanddump: fix writing big images on 32bit machines

When writing a full 4GiB NAND to a file end_addr becomes 0x100000000.
With that writing out the first page to the file doesn't happen
because size_left is calculated to 0x100000000 - 0 = 0x100000000
which is then truncated to 32bit and becomes zero. Fix this by
using an appropriate 64bit type for size_left.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
3 years agonandwrite: warn about writing 0xff blocks
Rafał Miłecki [Fri, 25 Mar 2022 12:00:25 +0000 (13:00 +0100)]
nandwrite: warn about writing 0xff blocks

Such blocks may be incorrectly treated as empty (even though they may
have non-erase OOB). Warn about it so people may start useing
--skip-all-ffs .

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
3 years agofix test bashism
Mike Frysinger [Wed, 12 Jan 2022 18:22:34 +0000 (13:22 -0500)]
fix test bashism

Using == with `test` is a bashism.  POSIX shell only supports =.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
3 years agoRelease mtd-utils-2.1.4 v2.1.4
David Oberhollenzer [Thu, 6 Jan 2022 01:50:11 +0000 (02:50 +0100)]
Release mtd-utils-2.1.4

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
3 years agoFix: add missing new-line-escape in jffsX-utils Makemodule.am
David Oberhollenzer [Wed, 5 Jan 2022 09:32:14 +0000 (10:32 +0100)]
Fix: add missing new-line-escape in jffsX-utils Makemodule.am

In commit a888044525, various header files that were added to the
distribution tarball via EXTRA_DIST were instead added to the source
lists of their respective programs instead.

In the case of jffsX-utils, a missing escape for a new-line in the
source list caused the include/linux/jffs2.h header to not be packged
in the release tarball. This went undiscovered, as the system on which
the release tarball was built, had the same header installed installed
in the system include directory, so a `make distcheck` succeeded.

Fixes: a888044525
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
3 years agofectest.c: fix buffer overrun
Ralph Siemsen [Thu, 2 Dec 2021 14:45:18 +0000 (09:45 -0500)]
fectest.c: fix buffer overrun

misc-utils/fectest.c:37:11: warning: iteration 47 invokes undefined behavior [-Waggressive-loop-optimizations]
   37 |   srcs[i] = buf + (i * PKT_SIZE);
      |   ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Ralph Siemsen <ralph.siemsen@linaro.org>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
3 years agomtd-tests: use pages during readtest and stress
Ralph Siemsen [Thu, 2 Dec 2021 14:38:52 +0000 (09:38 -0500)]
mtd-tests: use pages during readtest and stress

Same fix as a2c6bbc ("mtd-tests: Read and write pages during speed
tests") but applied to flash_readtest and flash_stress.

Resolves failure of flash_readtest when subpages are present. The test
reads a (sub)page followed by the entire OOB. Upon reaching the 2nd
subpage, the OOB read fails because it is beyond the end of OOB.

Signed-off-by: Ralph Siemsen <ralph.siemsen@linaro.org>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
3 years agomtd-tests: Read and write pages during speed tests
Miquel Raynal [Wed, 13 Oct 2021 10:08:07 +0000 (12:08 +0200)]
mtd-tests: Read and write pages during speed tests

The speed test does reads and writes of different sizes:
- eraseblock
- page
- two pages

At least this is the theory because, as opposed to the legacy kernel
module doing the same measurement, the userspace tool uses the subpage
size (hence accessing the same page 4, 8 or 16 times depending on the
subpage setting). Of course if the controller does not support subpages,
this issue is not visible.

Use mtd.min_io_size instead for non-NOR devices in order to get the
right bandwidth (at least one that fits the logs).

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
3 years agoAdd ubiscan utility
Diego Ismirlian [Tue, 17 Aug 2021 00:38:02 +0000 (21:38 -0300)]
Add ubiscan utility

ubiscan will scan the PEBs in a specific MTD device and print a summary of
the PEB erase counters and (optionally) details about each PEB's status.

Example output:

# ./ubiscan /dev/mtd6
Summary
=========================================================
mtd    : 6
type   : nand
size   : 110362624 bytes (105.2 MiB)
PEBs   : 842
min I/O: 2048 bytes

PEB erase counters
=========================================================
valid    : 834
empty    : 0
corrupted: 0
alien    : 0
bad      : 8

Histogram
=========================================================
from              to     count      min      avg      max
---------------------------------------------------------
0        ..        9:       55        1        4        9
10       ..       99:      174       10       48       99
100      ..      999:      514      103      287      987
1000     ..     9999:       91     1004     1880     2251
10000    ..    99999:        0        0        0        0
100000   ..      inf:        0        0        0        0
---------------------------------------------------------
Total               :      834        1      392     2251

If the --verbose switch is given, ubiscan will print PEB details:

# ./ubiscan --verbose /dev/mtd6

[... same output as before ...]

Details
=========================================================
PEB        0: 253
PEB        1: 1489
PEB        2: 1
PEB        3: 1
PEB        4: 1
PEB        5: 1
PEB        6: 1
PEB        7: 1
PEB        8: 1
PEB        9: 1
PEB       10: 1
...
PEB      832: 1225
PEB      833: 252
PEB      834: 111
PEB      835: 298
PEB      836: 1264
PEB      837: 11
PEB      838: EB_BAD
PEB      839: EB_BAD
PEB      840: EB_BAD
PEB      841: EB_BAD

Signed-off-by: Diego Ismirlian <dismirlian@gmail.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
3 years agoRelease mtd-utils-2.1.3 v2.1.3
David Oberhollenzer [Sun, 25 Jul 2021 18:49:01 +0000 (20:49 +0200)]
Release mtd-utils-2.1.3

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
3 years agoAdd missing filljffs2.sh to EXTRA_DIST
David Oberhollenzer [Sun, 25 Jul 2021 18:48:20 +0000 (20:48 +0200)]
Add missing filljffs2.sh to EXTRA_DIST

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
3 years agomisc-utils: flashcp: Add new function that copy only different blocks
Harvey Wu [Tue, 1 Jun 2021 07:34:53 +0000 (15:34 +0800)]
misc-utils: flashcp: Add new function that copy only different blocks

- The original flashcp process is erase, write and verify all blocks
  in one time from file to device.
  This patch will add a function that only copy different block data
  from file to device. The function will compare blocks by block
  between file and device, then erase and write block data from file
  to device if found different block.

Signed-off-by: Harvey Wu <harveywu95@gmail.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
3 years agomtd-utils: Add flash_otp_erase
Michael Walle [Tue, 16 Mar 2021 10:40:15 +0000 (11:40 +0100)]
mtd-utils: Add flash_otp_erase

On some SPI NOR flashes you can actually erase the OTP region until its
fully locked. Add a small utility for that.

Signed-off-by: Michael Walle <michael@walle.cc>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
3 years agomtd-utils: flash_erase: Add flash erase chip
Larisa Ileana Grigore [Fri, 23 Apr 2021 15:07:04 +0000 (18:07 +0300)]
mtd-utils: flash_erase: Add flash erase chip

Some flash types support full erase chip command which can reduce the
flash erase time. Try first to erase the entire flash and fall back
to the old method if the operation fails.

Signed-off-by: Larisa Ileana Grigore <larisa.grigore@nxp.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
4 years agomkfs.ubifs: Fix runtime assertions when running without crypto
Henri Roosen [Mon, 8 Mar 2021 14:57:10 +0000 (15:57 +0100)]
mkfs.ubifs: Fix runtime assertions when running without crypto

Running mkfs.ubifs which was build without crypto triggered the
following assertion:

mkfs.ubifs: ubifs-utils/mkfs.ubifs/fscrypt.h:166:
inherit_fscrypt_context: Assertion `0' failed.

A previous commit-cc4c5e295f54 ("mkfs.ubifs: Enable support for building
without crypto") added a check for an existing fscrypt context before calling
functions inherit_fscrypt_context() and free_fscrypt_context(),
however did not properly do this for each call to these functions.

Fixes: cc4c5e295f54 ("mkfs.ubifs: Enable support for building without crypto")
Signed-off-by: Henri Roosen <henri.roosen@ginzinger.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
4 years agomtd-utils: Use AC_SYS_LARGEFILE
Sascha Hauer [Fri, 26 Feb 2021 10:24:21 +0000 (11:24 +0100)]
mtd-utils: Use AC_SYS_LARGEFILE

Currently mtd-utils on 32bit systems fail on devices >2GiB due to off_t being
a signed 32bit type. Add AC_SYS_LARGEFILE to make off_t a 64bit type.
Adding AC_SYS_LARGEFILE results in _FILE_OFFSET_BITS being defined to 64
in include/config.h. To let this have an effect we must make sure that
include/config.h is included before all other includes which is
archieved by adding its inclusion to CPPFLAGS.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
4 years agoFix test binary installation
David Oberhollenzer [Mon, 19 Oct 2020 10:14:25 +0000 (12:14 +0200)]
Fix test binary installation

 - Remove "install tests" configure option, we already have an option
   whether to build tests or not. Don't try to work around autotools
   semantics that people building the package expect.
 - Fix the installation path by propperly defining it and using the
   correct name for the libexec path.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
4 years agoCleanup: Automake: remove single use variables
David Oberhollenzer [Mon, 19 Oct 2020 09:40:56 +0000 (11:40 +0200)]
Cleanup: Automake: remove single use variables

Throughout the Automake files, there is a consistent pattern somewhat
like this:

    FOO_BINS = ....

    sbin_PROGRAMS += $(FOO_BINS)

This commit all such patterns whenever the variable is not used anywhere
else and appends to the target directly.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
4 years agoRemove headers from EXTRA_DIST
David Oberhollenzer [Mon, 19 Oct 2020 09:12:56 +0000 (11:12 +0200)]
Remove headers from EXTRA_DIST

This commit removes the C header files from the EXTRA_DIST variables
and instead assigns them to the SOURCE variable of the respective
components they belong to.

This takes care of having them distributed in the release tar ball and
helps with dependency tracking a little.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
4 years agolibmtd: avoid divide by zero
Chris Packham [Fri, 27 Nov 2020 00:07:08 +0000 (13:07 +1300)]
libmtd: avoid divide by zero

The concept of erase blocks doesn't apply to mtd-ram devices. Such
devices set MTD_NO_ERASE to indicate this and some report 0 for the
erase block size. Avoid a divide by zero when calculating the erase
block count for such devices.

Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
Acked-by: Richard Weinberger <richard@nod.at>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
4 years agomtd-utils: ubihealthd: this tool does not depend on UBIFS
Juergen Borleis [Wed, 25 Nov 2020 10:25:47 +0000 (11:25 +0100)]
mtd-utils: ubihealthd: this tool does not depend on UBIFS

The "need_getrandom" check and result is used only for the "ubihealthd".
This tool is very important to have it around at run-time, while the
corresponding "mkfs.ubifs" tool is still optional (think about offline
generated ubifs images).
Since compiling "mkfs.ubifs" adds more dependencies (various shared
libraries), buildsystems for embedded devices will add these shared
libraries to the root filesystem even if "mkfs.ubifs" isn't used or
installed.

Thus, handling both tools independently makes sense. The previous behavior
is kept, e.g. if UBIFS support is enabled, it enables "ubihealthd" as well.

Signed-off-by: Juergen Borleis <jbe@pengutronix.de>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
4 years agoAdd an ubifs mount helper
Uwe Kleine-König [Tue, 6 Oct 2020 09:19:13 +0000 (11:19 +0200)]
Add an ubifs mount helper

This abstracts away attaching of the right ubi and then selecting the right
ubi device and volume to mount.

As described in the comment at the top this allows to mount ubifs volumes
directly from /etc/fstab without having to use hardcoded numbers (which
depend on mount order and so are unreliable) and extra magic to care for
attaching.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
4 years agomkfs.ubifs: remove OPENSSL_no_config()
Torben Hohn [Fri, 24 Jul 2020 07:47:05 +0000 (09:47 +0200)]
mkfs.ubifs: remove OPENSSL_no_config()

Especially for the pkcs11 engine, a configuration is required
because the provider has to be configured.

Its not clear why OPENSSL_no_config() is called.

Remove OPENSSL_no_config() and call OPENSSL_config(NULL)
instead.

Signed-off-by: Torben Hohn <torben.hohn@linutronix.de>
Signed-off-by: Bastian Germann <bage@linutronix.de>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
4 years agomtd-utils: Add nandflipbits tool
Boris Brezillon [Fri, 24 Apr 2020 16:32:09 +0000 (18:32 +0200)]
mtd-utils: Add nandflipbits tool

The nandflipbits tool is intended to be used when one need to flip one or
several specific bits on a NAND media.
It can be useful to manually recover from an unexpected bit flip on a flash
device, though the main purpose of this tool is to provide a way to test
ECC algorithms robustness.

One typical example I used this tool for is testing HW ECC engines behavior
when bitflips occur in an erased page: most HW engines do not correctly
handle this case, because, most of the time, ECC bits generated for an
empty page are not all 1s, and, empty page detection embedded in such
engines is only validating that all bits are set to 1s (which is not true
when a bit-flip has occurred).

Another use of this tool is replacing nandbiterrs test which
absolutely do not work with MLC-like chips because of the rewriting of
the pages in raw mode to toggle ones into zeroes.

Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
[miquel: Took Boris' work from 2014, addressed comments from Brian made
         in 2015, updated it, tested more extensively and fixed issues]
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
4 years agomisc-utils: Add fectest to build system
Bastian Germann [Sat, 26 Sep 2020 21:18:54 +0000 (23:18 +0200)]
misc-utils: Add fectest to build system

8f627247f6("mtd-utils: move libmtd source files to lib/ subdirectory")
removed fectest.c from the build system 10 years ago.  Add it again.

Signed-off-by: Bastian Germann <bastiangermann@fishpost.de>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
4 years agomkfs.ubifs: Fix build with SELinux
Bastian Germann [Tue, 22 Sep 2020 21:14:37 +0000 (23:14 +0200)]
mkfs.ubifs: Fix build with SELinux

In v2.1.0, SELinux support was introduced. It never compiled with ubifs
because it uses the old add_xattr signature that also changed in v2.1.0
with a1bd316e23("mkfs.ubifs: Implement fscrypto context store as xattr").

Add the ubifs_ino_node and name to the call and remove the nm that is
contructed in the new function version.

Signed-off-by: Bastian Germann <bastiangermann@fishpost.de>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
4 years agoFix typos found by Debian's lintian tool
Bastian Germann [Tue, 8 Sep 2020 20:07:11 +0000 (22:07 +0200)]
Fix typos found by Debian's lintian tool

Signed-off-by: Bastian Germann <bastiangermann@fishpost.de>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
4 years agofix build of jffs2reader and jffs2dump if zlib or lzo headers are not in default...
Rolf Eike Beer [Fri, 15 May 2020 12:56:48 +0000 (14:56 +0200)]
fix build of jffs2reader and jffs2dump if zlib or lzo headers are not in default paths

Signed-off-by: Rolf Eike Beer <eb@emlix.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
4 years agoRelease mtd-utils-2.1.2 v2.1.2
David Oberhollenzer [Mon, 13 Jul 2020 08:06:37 +0000 (10:06 +0200)]
Release mtd-utils-2.1.2

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
4 years agoAdd the mkfs.ubifs sign.h header to the list of sources
David Oberhollenzer [Mon, 13 Jul 2020 08:03:42 +0000 (10:03 +0200)]
Add the mkfs.ubifs sign.h header to the list of sources

The sign.h header added by the authentication patch set was omitted
from the automake file and thus not added to the distribution tarball.

The resulting tarballs were unable to be compiled.

Fixes: a739b59 ("mkfs.ubifs: Add authentication support")
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agomkfs.ubifs: fix broken build if fscrtyp is disabled
David Oberhollenzer [Sun, 9 Feb 2020 21:46:28 +0000 (22:46 +0100)]
mkfs.ubifs: fix broken build if fscrtyp is disabled

First, there is no option named of X509_OPTION. It was presumably
changed during development to AUTH_CERT_OPTION. This commit fixes
the name in the !WITH_CRYPTO branch.

Similarly, '}' got moved into the WITH_CRYPTO branch, but not into
else branch, resulting in tons of errors if fscrypt is disabled.
This commit pulls it back out of both branches.

Fixes: a739b59e ("mkfs.ubifs: Add authentication support")
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agomtd-utils: Add checks to code that copies strings into fixed sized buffers
David Oberhollenzer [Sat, 25 Jan 2020 13:46:31 +0000 (14:46 +0100)]
mtd-utils: Add checks to code that copies strings into fixed sized buffers

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agomtd-utils: Fix potentially unterminated strings
David Oberhollenzer [Sat, 25 Jan 2020 13:39:08 +0000 (14:39 +0100)]
mtd-utils: Fix potentially unterminated strings

This commit fixes some uses of strncpy that could leave the destination
buffer unterminated.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agomtd-utils: Fix "are we really at EOF" test logic in libubi read_data
David Oberhollenzer [Fri, 24 Jan 2020 22:59:47 +0000 (23:59 +0100)]
mtd-utils: Fix "are we really at EOF" test logic in libubi read_data

The function reads file data into a buffer and then checks if we
actually are at the end-of-file by trying to read one more byte.
For whatever reason, the code uses an int instead of a char. It's
not pretty but works. But again, this is something that every
static analysis tool barks at.

Further more, the error messages are inverted. "We aren't at EOF yet"
is printed on failure and something like "read error %m" is printed
on success.

This patch fixes all of the above.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agomtd-utils: Fix wrong argument to sizeof in nanddump
David Oberhollenzer [Fri, 24 Jan 2020 22:57:40 +0000 (23:57 +0100)]
mtd-utils: Fix wrong argument to sizeof in nanddump

Some temporary buffers are allocated with "sizeof(pointer) * count" as
size argument, which cannot possibly be correct.

Assuming what was meant was "sizeof(pointer[0]) * count" makes sense
in the context of how the buffers are used, but is actually pretty
pointless, since the buffers are unsigend char.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agomtd-utils: Fix some simple cases of uninitialized value reads
David Oberhollenzer [Fri, 24 Jan 2020 22:40:45 +0000 (23:40 +0100)]
mtd-utils: Fix some simple cases of uninitialized value reads

This patch modifies the internal helpers to read and parse integers
from sysfs files by initializing them first and removes turns an
obscure "a = open(...) if (a >= 0) {...} if (a == -1) {...}" inside
recv_image into a more straight forward if/else branch.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agomtd-utils: Fix various TOCTOU issues
David Oberhollenzer [Fri, 24 Jan 2020 22:18:18 +0000 (23:18 +0100)]
mtd-utils: Fix various TOCTOU issues

This patch restructures various code parts that follow the pattern
of "stat(x, &sb) ... makes_sense(&sb) ... open(x)".

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agomtd-utils: Fix potential negative arguments passed to close(2)
David Oberhollenzer [Fri, 24 Jan 2020 22:01:57 +0000 (23:01 +0100)]
mtd-utils: Fix potential negative arguments passed to close(2)

Many tools open a file descriptor, close it a the end and have some
form of error path in between that jumps to the end.

In some cases, if opening the file fails the error path is taken and
the utility ends up closing one or more invalid file descriptors. It's
technically not a real issue but something that pretty much any static
analysis tool barks at.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agomtd-utils: Fix printf format specifiers with the wrong type
David Oberhollenzer [Fri, 24 Jan 2020 21:44:01 +0000 (22:44 +0100)]
mtd-utils: Fix printf format specifiers with the wrong type

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agolibubi: remove private kernel header from includes
Bastian Germann [Wed, 29 Jan 2020 18:50:13 +0000 (19:50 +0100)]
libubi: remove private kernel header from includes

libubi.h includes ubi-media.h which was made private in the kernel a
long time ago. There are users of libubi.h, e.g. swupdate, which have to
have ubi-media.h available at build time with this inclusion.

However, libubi.h uses only one symbol from ubi-media.h. Define that symbol
in the header to enable using libubi.h without installing ubi-media.h.

Make up for the transitive symbol use in ubiformat.c by including ubi-media.h.

Signed-off-by: Bastian Germann <bastiangermann@fishpost.de>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agolibubigen: remove unnecessary include
Bastian Germann [Wed, 29 Jan 2020 18:50:12 +0000 (19:50 +0100)]
libubigen: remove unnecessary include

libubigen.h does not use any symbol from mtd/ubi-media.h,
so remove it from includes.

Signed-off-by: Bastian Germann <bastiangermann@fishpost.de>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agomtd-utils: Fix return value of ubiformat
Barry Grussling [Sun, 12 Jan 2020 20:33:32 +0000 (12:33 -0800)]
mtd-utils: Fix return value of ubiformat

This changeset fixes a feature regression in ubiformat.  Older versions of
ubiformat, when invoked with a flash-image, would return 0 in the case no error
was encountered.  Upon upgrading to latest, it was discovered that ubiformat
returned 255 even without encountering an error condition.

This changeset corrects the above issue and causes ubiformat, when given an
image file, to return 0 when no errors are detected.

Tested by running through my loading scripts and verifying ubiformat returned
0.

Signed-off-by: Barry Grussling <barry@grussling.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agomtd-utils: add optional offset parameter to flash_otp_dump
Michael Walle [Wed, 8 Jan 2020 23:23:59 +0000 (00:23 +0100)]
mtd-utils: add optional offset parameter to flash_otp_dump

There are flashes which have gaps between OTP regions and flashes where
the regions don't start at 0 (for example the Winbond 25Q series, which
has three 256 bytes OTP regions starting at 0x1000, 0x2000 and 0x3000).
At the moment it is impossible to dump the OTP memory. Fix it by passing
an optional offset parameter.

Signed-off-by: Michael Walle <michael@walle.cc>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agoubihealthd: Build only if sys/random.h is present
Marek Vasut [Wed, 4 Dec 2019 17:11:47 +0000 (18:11 +0100)]
ubihealthd: Build only if sys/random.h is present

The ubihealthd depends on sys/random.h , which is not present on some
older systems. Build ubihealthd only if sys/random.h is present.

Signed-off-by: Marek Vasut <marex@denx.de>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agofs-tests: don't leak temporary buffers
David Oberhollenzer [Sun, 10 Nov 2019 14:16:53 +0000 (15:16 +0100)]
fs-tests: don't leak temporary buffers

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agojittertest: fix error check for open system call
David Oberhollenzer [Sun, 10 Nov 2019 14:12:58 +0000 (15:12 +0100)]
jittertest: fix error check for open system call

The value 0 is a valid file descriptor. The existing error handling
would not only treat that as an error, but subsequently leak the
file descriptor in the error handling path.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agomtd_debug: cleanup error handling in flash_to_file
David Oberhollenzer [Sun, 10 Nov 2019 14:01:32 +0000 (15:01 +0100)]
mtd_debug: cleanup error handling in flash_to_file

The existing code had multiple error handling labels and did things
like checking if a buffer is not NULL before freeing it.

This patch collapses all of this into a single label. We can do this,
because the standard guarantees us that it is safe to call free() with
a NULL pointer.

This also has the side effect of removing the possibility of using the
wrong error label and accidentally leaking something.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agonanddump: don't leak copied command line arguments
David Oberhollenzer [Sun, 10 Nov 2019 13:56:51 +0000 (14:56 +0100)]
nanddump: don't leak copied command line arguments

For some command line flags, the argument string is copied. Simply
writing over the buffer leads to a resource leak if the same flag
is specified on the command line more than once.

This patch adds a free() call to the old buffer before overwriting
it with the new copy.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agoubiformat: don't leak file descriptors
David Oberhollenzer [Sun, 10 Nov 2019 13:52:05 +0000 (14:52 +0100)]
ubiformat: don't leak file descriptors

The original code had a 'goto out_close' directly after a return error
code, which is obviously not what was intended.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agoftl_format: don't leak temporary buffers
David Oberhollenzer [Sun, 10 Nov 2019 13:55:14 +0000 (14:55 +0100)]
ftl_format: don't leak temporary buffers

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agoftl_check: don't leak temporary buffers
David Oberhollenzer [Sun, 10 Nov 2019 13:51:52 +0000 (14:51 +0100)]
ftl_check: don't leak temporary buffers

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agolibmtd: don't leak temporary buffers
David Oberhollenzer [Sun, 10 Nov 2019 13:48:53 +0000 (14:48 +0100)]
libmtd: don't leak temporary buffers

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agomkfs.jffs2: don't leak temporary buffer if readlink fails
David Oberhollenzer [Sun, 10 Nov 2019 13:43:26 +0000 (14:43 +0100)]
mkfs.jffs2: don't leak temporary buffer if readlink fails

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agomkfs.ubifs: propperly cleanup in ALL interpret_table_entry error paths
David Oberhollenzer [Sun, 10 Nov 2019 13:12:06 +0000 (14:12 +0100)]
mkfs.ubifs: propperly cleanup in ALL interpret_table_entry error paths

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agomkfs.ubifs: don't leak temporary buffers
David Oberhollenzer [Sun, 10 Nov 2019 12:37:20 +0000 (13:37 +0100)]
mkfs.ubifs: don't leak temporary buffers

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agomkfs.ubifs: don't leak hastable iterators
David Oberhollenzer [Sun, 10 Nov 2019 13:02:12 +0000 (14:02 +0100)]
mkfs.ubifs: don't leak hastable iterators

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agomkfs.ubifs: free derived fscrypt context in add_directory error paths
David Oberhollenzer [Sun, 10 Nov 2019 12:46:21 +0000 (13:46 +0100)]
mkfs.ubifs: free derived fscrypt context in add_directory error paths

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agomkfs.ubifs: don't leak copied command line arguments
David Oberhollenzer [Sun, 10 Nov 2019 12:41:41 +0000 (13:41 +0100)]
mkfs.ubifs: don't leak copied command line arguments

For some command line flags, the argument string is copied. Simply
writing over the buffer leads to a resource leak if the same flag
is specified on the command line more than once.

This patch adds a free() call to the old buffer before overwriting
it with the new copy.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agomkfs.ubifs: close file descriptor in add_file error path
David Oberhollenzer [Sun, 10 Nov 2019 12:38:46 +0000 (13:38 +0100)]
mkfs.ubifs: close file descriptor in add_file error path

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agomkfs.ubifs: abort add_directory if readdir fails
David Oberhollenzer [Sun, 10 Nov 2019 13:40:05 +0000 (14:40 +0100)]
mkfs.ubifs: abort add_directory if readdir fails

The existing code sets 'err' to -1 and breaks the readdir loop, but
the error state is never read. This patch modifies the readdir loop
to actualy jump to the error handling branch if readdir fails.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agomkfs.ubifs: fscrypt: bail from encrypt_block if gen_essiv_salt fails
David Oberhollenzer [Sun, 10 Nov 2019 13:17:33 +0000 (14:17 +0100)]
mkfs.ubifs: fscrypt: bail from encrypt_block if gen_essiv_salt fails

What originally cought my attention was that gen_essiv_salt has a
size_t return type and error paths that return -1 on failure.
Further investigation revealed that the error value is never checked
for. The encrypt_block function doesn't use the return value in any
way and simply continues onward.

Furthermore, the gen_essiv_salt function has an error case that emits
an error message but returns success state.

This patch modifes gen_essiv_salt to return an error status in all
error branches, changes the return type to ssize_t and adds a check
to encrypt_block if gen_essiv_salt fails.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agoflashcp: Add option -A/--erase-all
Andrij Abyzov [Mon, 21 Oct 2019 10:10:37 +0000 (12:10 +0200)]
flashcp: Add option -A/--erase-all

Sometimes there's a need to erase the whole device when
programming an image, and not just the area under the
image itself.

Therefore, option -A/--erase-all has been added which
erases the whole device before writing the image.

Signed-off-by: Andrij Abyzov <drolevar@gmail.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agoubihealthd: Add option -h/--help
Alexander Dahl [Thu, 3 Oct 2019 06:35:01 +0000 (08:35 +0200)]
ubihealthd: Add option -h/--help

Using '?' as option did not work, and would be strange to pass anyway,
because it's a glob char for the shell and you would have to escape it
like ./ubihealthd -\? … use the more common -h/--help instead.

Note: this does not touch the output, just changes the options itself.

Signed-off-by: Alexander Dahl <post@lespocky.de>
Acked-by: Richard Weinberger <richard@nod.at>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agoubihealthd: Add missing sentinel in options array
Alexander Dahl [Thu, 3 Oct 2019 06:35:00 +0000 (08:35 +0200)]
ubihealthd: Add missing sentinel in options array

`getopt_long()` requires a null terminated array, otherwise we get
segfaults when passing invalid options.

Fixes: 7f0e2dc21fb2 ("ubi-utils: Implement a ubihealthd")
Signed-off-by: Alexander Dahl <post@lespocky.de>
Acked-by: Richard Weinberger <richard@nod.at>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agoubiupdatevol: Prevent null pointer dereference
Bastian Germann [Sun, 8 Sep 2019 19:59:22 +0000 (21:59 +0200)]
ubiupdatevol: Prevent null pointer dereference

libubi_close(libubi) is called in the error handler if libubi is null.
Prevent that by handling the error case similar to the other ubi
executables.

Signed-off-by: Bastian Germann <bastiangermann@fishpost.de>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agoAdd ubihealthd to gitignore file
David Oberhollenzer [Sun, 25 Aug 2019 11:51:21 +0000 (13:51 +0200)]
Add ubihealthd to gitignore file

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agoubi-utils: Implement a ubihealthd
Richard Weinberger [Thu, 25 Jul 2019 20:34:42 +0000 (22:34 +0200)]
ubi-utils: Implement a ubihealthd

ubihealthd is a simple daemon which scans every PEB
of an UBI device in random order.
It helps to deal with read disturb on systems which either
reboot seldom, use fastmap or read few data.

To use this daemon you need Linux >= v5.1.

Signed-off-by: Richard Weinberger <richard@nod.at>
5 years agomkfs.ubifs: Add authentication support
Sascha Hauer [Tue, 6 Aug 2019 10:49:28 +0000 (12:49 +0200)]
mkfs.ubifs: Add authentication support

This adds support for authenticated UBIFS images. In authenticated
images all UBIFS nodes are hashed as described in the UBIFS
authentication whitepaper. Additionally the superblock node contains a
hash of the master node and itself is cryptographically signed in a node
following the superblock node. The signature is in PKCS #7 CMS format.

To generate an authenticated image these options are necessary:

--hash-algo=NAME     hash algorithm to use for signed images
                     (Valid options include sha1, sha256, sha512)
--auth-key=FILE      filename or PKCS #11 uri containing the authentication key
                     for signing
--auth-cert=FILE     Authentication certificate filename for signing. Unused
                     when certificate is provided via PKCS #11

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agoubifs-media: Update to Linux-5.3-rc3
Sascha Hauer [Tue, 6 Aug 2019 10:49:27 +0000 (12:49 +0200)]
ubifs-media: Update to Linux-5.3-rc3

This updates ubifs-media.h to Linux-5.3-rc3 which brings us the bits
and pieces necessary for UBIFS authentication and offline signing.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agoRelease mtd-utils-2.1.1 v2.1.1
David Oberhollenzer [Sun, 21 Jul 2019 20:40:28 +0000 (22:40 +0200)]
Release mtd-utils-2.1.1

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agomkfs.ubifs: fix description of favor_lzo
Uwe Kleine-König [Thu, 18 Jul 2019 09:42:58 +0000 (11:42 +0200)]
mkfs.ubifs: fix description of favor_lzo

"favor_lzo" uses "lzo" unless the space savings when using "zlib" are
big. The current wording got this wrong.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agomkfs.ubifs: fix compilation without ZSTD
Martin Kaiser [Mon, 15 Jul 2019 13:38:58 +0000 (15:38 +0200)]
mkfs.ubifs: fix compilation without ZSTD

Fix a trivial typo to make sure that zstd.h is included only if
zstd is not disabled.

Signed-off-by: Martin Kaiser <martin@kaiser.cx>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agomkfs.ubifs: remove ZSTD_CLEVEL_DEFAULT for backwards compatibillity
David Oberhollenzer [Tue, 9 Jul 2019 10:22:30 +0000 (12:22 +0200)]
mkfs.ubifs: remove ZSTD_CLEVEL_DEFAULT for backwards compatibillity

Support for ZSTD compression has been added recently through the ZSTD
library, which is famously known for its incredibly well designed and
stable API.

This patch removes usage of ZSTD_CLEVEL_DEFAULT, which isn't exposed
in older versions of the ZSTD library, and replaces it with with the
constant parameter 0. According to the documentation this should then
use a reasonable default (which is defined internally).

Other possible approachs include defining ZSTD_CLEVEL_DEFAULT to 3
(the value it _currently_ has) if it isn't defined. This patch chooses
the approach of passing 0 since this seems to be encouraged by the
existing documentation.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agoubinize: Exit with non-zero exit code on error.
Patrick Doyle [Mon, 1 Jul 2019 18:25:28 +0000 (14:25 -0400)]
ubinize: Exit with non-zero exit code on error.

...specifically -1 in all of the new cases.

Signed-off-by: Patrick Doyle <pdoyle@irobot.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agoubi-tests: fm_param: Replace 'fm_auto' with 'fm_autoconvert'
Zhihao Cheng [Fri, 14 Jun 2019 12:19:50 +0000 (20:19 +0800)]
ubi-tests: fm_param: Replace 'fm_auto' with 'fm_autoconvert'

The value of fm_param should be 'fm_autoconvert' rather than 'fm_auto' when
fastmap is supported by kernel. Currently, following verbose will appear in
dmesg when fm_param is set to 'fm_auto':

  ubi: unknown parameter 'fm_auto' ignored

This patch replace 'fm_auto' with 'fm_autoconvert' for fm_param, so ubi
kernel module can receive correct parameters.

----------------------------------------

Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agoubi-tests: mkvol test: Checks return value 'ENOSPC' for 'ubi_mkvol'
Zhihao Cheng [Fri, 14 Jun 2019 12:18:48 +0000 (20:18 +0800)]
ubi-tests: mkvol test: Checks return value 'ENOSPC' for 'ubi_mkvol'

UBI tests try to create too many volumes in mkvol_bad and mkvol_basic.
Currently mtd-utils allows return value 'ENFILE' from 'ubi_mkvol', that
works fine in most situations. But what if the number of PEBs equals to
the maximum count of volumes? For example, mkvol_basic test will fail in
a 64MiB flash with 512KiB PEB size.
Following is the output of mkvol_basic test:

  ======================================================================
  ======================================================================
  ======================================================================
  Test on mtdram, fastmap enabled, VID header offset factor 1
  ======================================================================
  ======================================================================
  ======================================================================
  mtdram: 64MiB, PEB size 512KiB, fastmap enabled
  Running mkvol_basic /dev/ubi0
  [mkvol_basic] mkvol_multiple():182: function ubi_mkvol() failed with
  error 28 (No space left on device)
  [mkvol_basic] mkvol_multiple():183: vol_id 122
  Error: mkvol_basic failed
  FAILURE

The reason is that there is no available PEB to support a new volume. We
can see following verbose in dmesg:

  ubi0: attached mtd0 (name "mtdram test device", size 64 MiB)
  ubi0: user volume: 0, internal volumes: 1, max. volumes count: 128
  ubi0: available PEBs: 122, total reserved PEBs: 6, PEBs reserved for
  bad PEB handling: 0

The maximum count of volumes is 128, so we can create 128 volumes
theoretically. But there are 122 available PEBs becauese of existence of
reserved PEBs. In addition, a volume occupies at least one PEB. Actually,
we can only create 122 volumes, Therefore, 'ubi_mkvol' returns 'ENOSPC'
when mkvol_basic tries to create 123rd volume. And we can see
corresponding error message in dmesg:

  ubi0 error: ubi_create_volume [ubi]: not enough PEBs, only 0 available
  ubi0 error: ubi_create_volume [ubi]: cannot create volume 122, error -28

So, 'ENOSPC' can happen before 'ENFILE' in flash with a small amount of
PEBs. This patch checks return value 'ENOSPC' for 'ubi_mkvol' when mkvol
test is trying to create too many volumes.

----------------------------------------

Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agoubi-tests: io_read: Filter invalid offset value before 'lseek' in io_read test
Zhihao Cheng [Fri, 14 Jun 2019 12:18:16 +0000 (20:18 +0800)]
ubi-tests: io_read: Filter invalid offset value before 'lseek' in io_read test

There are many different offset values passed in 'lseek' during io_read
testing of ubi test. The offset value maybe a negative number or a big
number that exceeds the volume data size, which can lead to ubi tests
failure by passing invalid offset value to 'lseek'. For example:

Example 1: The data size of volume is 39525 bytes, offset = (sz) -
MAX_NAND_PAGE_SIZE - 1, where MAX_NAND_PAGE_SIZE is 65536. Here, offset
is a negative value passed to 'lseek', which leads to fail in io_read.

  ======================================================================
  ======================================================================
  ======================================================================
  Test on mtdram, fastmap enabled, VID header offset factor 1
  ======================================================================
  ======================================================================
  ======================================================================
  mtdram: 16MiB, PEB size 16KiB, fastmap enabled
  Running mkvol_basic /dev/ubi0
  Running mkvol_bad /dev/ubi0
  Running mkvol_paral /dev/ubi0
  Running rsvol /dev/ubi0
  Running io_basic /dev/ubi0
  Running io_read /dev/ubi0
  [io_basic] test_read3():189: function seek() failed with error 22
  (Invalid argument)
  [io_basic] test_read3():190: len = 1
  [io_basic] test_read2():237: offset = -26012
  [io_basic] test_read1():303: length = 1
  [io_basic] test_read():362: alignment = 7905
  Error: io_read failed
  FAILURE

Example 2: The data size of volume is 79035 bytes, offset = 2 *
MAX_NAND_PAGE_SIZE, where MAX_NAND_PAGE_SIZE is 65536. Here, offset is a
value exceeds volume size, which leads to fail in io_read.

  ======================================================================
  ======================================================================
  ======================================================================
  Test on mtdram, fastmap enabled, VID header offset factor 1
  ======================================================================
  ======================================================================
  ======================================================================
  mtdram: 16MiB, PEB size 16KiB, fastmap enabled
  Running mkvol_basic /dev/ubi0
  Running mkvol_bad /dev/ubi0
  Running mkvol_paral /dev/ubi0
  Running rsvol /dev/ubi0
  Running io_basic /dev/ubi0
  Running io_read /dev/ubi0
  [io_basic] test_read3():185: function seek() failed with error 22
  (Invalid argument)
  [io_basic] test_read3():186: len = 1
  [io_basic] test_read2():233: offset = 131072
  [io_basic] test_read1():299: length = 1
  [io_basic] test_read():358: alignment = 3
  Error: io_read failed
  FAILURE

This patch checks offset value before executing 'lseek', invalid offset
values are filtered.

----------------------------------------

Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agoubi-tests: ubi_mkvol_request: Fully initialize 'struct ubi_mkvol_request req'
Zhihao Cheng [Fri, 14 Jun 2019 12:14:38 +0000 (20:14 +0800)]
ubi-tests: ubi_mkvol_request: Fully initialize 'struct ubi_mkvol_request req'

'struct ubi_mkvol_request req' is one parameter of the function 'ubi_mkvol'
, this parameter will be passed to kernel and then be checked. It acts as a
local variable in many ubi tests, such as io_basic, io_read, mkvol_bad,
mkvol_basic, etc.

After commit c355aa465fce ("ubi: expose the volume CRC check skip flag") in
linux-stable, 'struct ubi_mkvol_request' supports a new configuration named
'flags', and req.flags will be checked in kernel function
'verify_mkvol_req'. Currently, there is no initialization for req.flags
before 'ubi_mkvol' invoked. So, req.flags can be an arbitrary number passed
to kernel. When we run ubi tests in qemu (x86_64, kernel image: 5.2.0-rc4),
the following errors may occur:

  ======================================================================
  ======================================================================
  ======================================================================
  Test on mtdram, fastmap enabled, VID header offset factor 1
  ======================================================================
  ======================================================================
  ======================================================================
  mtdram: 16MiB, PEB size 16KiB, fastmap enabled
  Running mkvol_basic /dev/ubi0
  Running mkvol_bad /dev/ubi0
  [mkvol_bad] test_mkvol():105: ubi_mkvol failed with error 22
  (Invalid argument), expected 28 (No space left on device)
  [mkvol_bad] test_mkvol():105: bytes = 16060929
  Error: mkvol_bad failed
  FAILURE

This patch fully initializes every 'struct ubi_mkvol_request req' passed to
'ubi_mkvol', which can fix the bug that the ubi test failed caused by that
req.flags was not initialized. And it is still compatible with old kernel
before kernel commit c355aa465fce ("ubi: expose the volume CRC check skip
flag").

----------------------------------------

Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agomkfs.ubifs: Add ZSTD compression
Sebastian Andrzej Siewior [Sat, 1 Jun 2019 10:43:23 +0000 (12:43 +0200)]
mkfs.ubifs: Add ZSTD compression

I added ZSTD support to mkfs.ubifs and compared the ZSTD results with
zlib/lzo and the available ZSTD compression levels. The results are in
the following table:

Comp    image MiB        time  image2 MiB        time
none          271   0m 0,723s         223   0m 0,589s
lzo           164   0m13,705s         116   0m11,636s
zlib          150   0m 7,654s         103   0m 6,347s
favor-lzo     158   0m21,137s         110   0m17,764s
zstd-01       154   0m 1,607s         106   0m 1,429s
zstd-02       153   0m 1,704s         105   0m 1,479s
zstd-03*      152   0m 1,888s         104   0m 1,668s
zstd-04       151   0m 2,741s         103   0m 2,391s
zstd-05       150   0m 3,257s         102   0m 2,916s
zstd-06       150   0m 3,735s         102   0m 3,356s
zstd-07       150   0m 4,066s         102   0m 3,705s
zstd-08       152   0m 1,857s         104   0m 1,644s
zstd-09       152   0m 1,855s         104   0m 1,639s
zstd-10       150   0m 6,654s         102   0m 6,195s
zstd-11       150   0m10,027s         102   0m 9,130s
zstd-12       149   0m14,724s         101   0m13,415s
zstd-13       148   0m18,232s         100   0m16,719s
zstd-14       148   0m20,859s         100   0m19,554s
zstd-15       148   0m25,033s         100   0m23,186s
zstd-16       148   0m38,837s         100   0m36,543s
zstd-17       148   0m46,051s         100   0m43,120s
zstd-18       148   0m49,157s         100   0m45,807s
zstd-19       148   0m49,421s         100   0m45,951s
zstd-20       148   0m51,271s         100   0m48,030s
zstd-21       148   0m51,015s         100   0m48,676s
zstd-22       148   0m52,575s         100   0m50,013s

The UBIFS image was created via
  mkfs.ubifs -x $Comp -m 512 -e 128KiB -c 2200 -r $image $out

I used "debootstrap sid" to create a basic RFS and the results are in
the `image' column. The image2 column denotes the results for the same
image but with .deb files removed.
The time column contains the output of the run time of the command.

ZSTD's compression level three is currently default. Based on the
compression results (for the default level) it outperforms LZO in
run time and compression and is almost as good as ZLIB in terms of
compression but quicker.
The higher compression levels make almost no difference in compression
but take a lot of time.

The compression level used is the default offered by ZSTD. It does not
make sense the higher levels.

Signed-off-by: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agoubiformat: Dont ignore sequence number CLI option
Amol Vengurlekar [Mon, 13 May 2019 00:59:19 +0000 (17:59 -0700)]
ubiformat: Dont ignore sequence number CLI option

Image sequence number for the UBI header can be specified for the
ubiformat tool according to the documentation and the help message for
ubiformat. The CLI option --image-seq for image sequence number is not
supported. -Q option for image sequence number is silently ignored.
This patch adds the CLI support for image sequence number.

Signed-off-by: Amol Vengurlekar <amol.sven@gmail.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
5 years agomtd-tests: nandbiterrs: Fix issue that just insert error at bit 7
Xiaolei Li [Mon, 29 Apr 2019 03:28:34 +0000 (11:28 +0800)]
mtd-tests: nandbiterrs: Fix issue that just insert error at bit 7

The function insert_biterror should be designed to insert error at
the first '1' bit starting at offset byte.

But now, only bit 7 of each byte is checked, because checking mask
is always 0x80.

So, do right shift for checking mask after each checking to check
the whole 8 bits of each bytes.

Signed-off-by: Xiaolei Li <xiaolei.li@mediatek.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
6 years agounittests: Define the use of _GNU_SOURCE
Olliver Schinagl [Mon, 15 Apr 2019 08:20:31 +0000 (10:20 +0200)]
unittests: Define the use of _GNU_SOURCE

The unittest suite actually makes use of some _GNU extensions during the
build (loff_t for example). So lets enable this in the makefile.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
6 years agounittests/libmtd_test: Include fcntl header
Olliver Schinagl [Mon, 15 Apr 2019 08:20:30 +0000 (10:20 +0200)]
unittests/libmtd_test: Include fcntl header

The test library for the mtd unit tests include various type's and
macro's that officially live in fcntl. Each file and header should
always properly include what they use, so lets add the fcntl headers.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
6 years agounittests/test_lib: Include proper header for _IOC_SIZE
Olliver Schinagl [Mon, 15 Apr 2019 08:20:29 +0000 (10:20 +0200)]
unittests/test_lib: Include proper header for _IOC_SIZE

The macro _IOC_SIZE is not part of sys/ioctl.h but lives in asm/ioctl.h
so we should include the proper header. If we do not, some systems
complain during linking that they cannot find the symbol _IOC_SIZE()
which was not expanded by the pre-compiler.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
6 years agomkfs.ubifs: fix regression when trying to store device special files
David Oberhollenzer [Wed, 3 Apr 2019 10:54:16 +0000 (12:54 +0200)]
mkfs.ubifs: fix regression when trying to store device special files

Commit a767dd30 added a check to add_inode that bails when trying to
store extra data in anything other than a symlink. The symlink
encryption support added by that commit relies on the assumption.

Unfortionately it was overlooked that device special files also store
the device number as additional data in the inode. The check added in
commit a767dd30 broke support for device files in mkfs.ubifs.

This commit adds a quick and dirty fix, moving the check into the
fscrypt branch, breaking only the fscrypt version but restoring old
functionality for unencrypted file systems.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
6 years agomkfs.ubifs: fix build without openssl
Baruch Siach [Fri, 29 Mar 2019 10:32:24 +0000 (13:32 +0300)]
mkfs.ubifs: fix build without openssl

Exclude openssl headers when WITH_CRYPTO is not defined.

Fixes this build failure:

In file included from ubifs-utils/mkfs.ubifs/mkfs.ubifs.c:25:0:
ubifs-utils/mkfs.ubifs/mkfs.ubifs.h:49:10: fatal error: openssl/rand.h: No such file or directory
 #include <openssl/rand.h>
          ^~~~~~~~~~~~~~~~

Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
6 years agoRelease mtd-utils-2.1.0 v2.1.0
David Oberhollenzer [Wed, 13 Mar 2019 16:42:12 +0000 (17:42 +0100)]
Release mtd-utils-2.1.0

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
6 years agomtd-utils: fixes verification percent display in flashcp
Andrij Abyzov [Mon, 11 Feb 2019 16:13:40 +0000 (17:13 +0100)]
mtd-utils: fixes verification percent display in flashcp

flashcp was always showing 0% progress due to incorrect
printf format specifier.

Signed-off-by: Andrij Abyzov <drolevar@gmail.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
6 years agomtd-utils: fixes double free in mkfs.ubifs
Yufen Yu [Thu, 24 Jan 2019 09:06:29 +0000 (17:06 +0800)]
mtd-utils: fixes double free in mkfs.ubifs

In inode_add_xattr(), it malloc a buffer for name, and then passes
the bufffer ptr to add_xattr(). The ptr will be used to create a new
idx_entry in add_to_index().

However, inode_add_xattr() will free the buffer before return.
which can cause double free in write_index(): free(idx_ptr[i]->name)

*** Error in `./mkfs.ubifs': double free or corruption (fasttop): 0x0000000000aae220 ***
======= Backtrace: =========
/lib64/libc.so.6(+0x7cbac)[0x7f4881ff5bac]
/lib64/libc.so.6(+0x87a59)[0x7f4882000a59]
/lib64/libc.so.6(cfree+0x16e)[0x7f48820063be]
./mkfs.ubifs[0x402fbf]
/lib64/libc.so.6(__libc_start_main+0xea)[0x7f4881f9988a]
./mkfs.ubifs[0x40356a]

Signed-off-by: Yufen Yu <yuyufen@huawei.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
6 years agomtd-utils: avoid to create two UBI_LAYOUT_VOLUME_ID volume
Yufen Yu [Fri, 25 Jan 2019 07:01:24 +0000 (15:01 +0800)]
mtd-utils: avoid to create two UBI_LAYOUT_VOLUME_ID volume

When we create a ubi image by ubinize, a UBI_LAYOUT_VOLUME_ID
volume will be created by ubigen_write_layout_vol().
However, after the commit 4c00cf2c5816 (ubiformat: remove
no-volume-table option), ubiformat remove novtbl args in format().
As a result, it will also create a layout volume.

When we attempt to do ubiattach, it will fail for ubi_compare_lebs error:
ubi0 error: ubi_compare_lebs: unsupported on-flash UBI format
ubi0 error: ubi_attach_mtd_dev: failed to attach mtd1, error -22

Signed-off-by: Yufen Yu <yuyufen@huawei.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
6 years agomkfs.ubifs: fix default cipher in help output
David Gstir [Mon, 3 Dec 2018 13:40:46 +0000 (14:40 +0100)]
mkfs.ubifs: fix default cipher in help output

AES-256-XTS is the default since dd0d9c623e22 ("mkfs.ubifs: Use AES-256-XTS as default"),
we want that to be correctly reflected in the help output as well.

Signed-off-by: David Gstir <david@sigma-star.at>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
6 years agomkfs.ubifs: Don't compress by default if filesystem is encrypted
Richard Weinberger [Wed, 7 Nov 2018 20:56:35 +0000 (21:56 +0100)]
mkfs.ubifs: Don't compress by default if filesystem is encrypted

Encryption and compression are not friends.
Enable compression in encryption mode only if the user explicitly
sets a compressor.

Signed-off-by: Richard Weinberger <richard@nod.at>
Tested-by: Heiko Schocher <hsdenx.de>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
6 years agomkfs.ubifs: Store compr_size in correct endianness.
Richard Weinberger [Wed, 7 Nov 2018 20:21:08 +0000 (21:21 +0100)]
mkfs.ubifs: Store compr_size in correct endianness.

compr_size has to be in LE16.

Signed-off-by: Richard Weinberger <richard@nod.at>
Tested-by: Heiko Schocher <hsdenx.de>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
6 years agomkfs.ubifs: Fix IV selection
Richard Weinberger [Wed, 7 Nov 2018 20:21:07 +0000 (21:21 +0100)]
mkfs.ubifs: Fix IV selection

We need to check for AES being in 128-cbc mode and not 256-cbc.
fscrypt supports only 128-cbc and 256-xts so far.

Signed-off-by: Richard Weinberger <richard@nod.at>
Tested-by: Heiko Schocher <hsdenx.de>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
6 years agomkfs.ubifs: Use AES-256-XTS as default
Richard Weinberger [Thu, 18 Oct 2018 14:37:18 +0000 (16:37 +0200)]
mkfs.ubifs: Use AES-256-XTS as default

AES-128-CBC should only being used when 256-XTS is too slow
on low end hardware.

Signed-off-by: Richard Weinberger <richard@nod.at>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
6 years agomkfs.ubifs: Print key descriptor only when generated
Richard Weinberger [Thu, 18 Oct 2018 14:37:17 +0000 (16:37 +0200)]
mkfs.ubifs: Print key descriptor only when generated

Signed-off-by: Richard Weinberger <richard@nod.at>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
6 years agomkfs.ubifs: Enable support for building without crypto
Richard Weinberger [Thu, 18 Oct 2018 14:37:16 +0000 (16:37 +0200)]
mkfs.ubifs: Enable support for building without crypto

Signed-off-by: Richard Weinberger <richard@nod.at>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
6 years agomkfs.ubifs: Move RAND_poll to crypto.c
Richard Weinberger [Thu, 18 Oct 2018 14:37:15 +0000 (16:37 +0200)]
mkfs.ubifs: Move RAND_poll to crypto.c

Signed-off-by: Richard Weinberger <richard@nod.at>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>