]> www.infradead.org Git - mtd-utils.git/log
mtd-utils.git
6 months agomtd-tests: flash_speed: Generalize read_eraseblock_by_2pages()
Miquel Raynal [Mon, 26 Aug 2024 09:46:27 +0000 (11:46 +0200)]
mtd-tests: flash_speed: Generalize read_eraseblock_by_2pages()

Right now there are only 2 pages that may be read continuously, but why
not trying more? At least when the continuous feature is out, this type
of benchmarking will be interesting. In order to facilitate later
additions, lets make this helper more generic and accept a global
'npages' variable as parameter (because this function is called in a
macro, it is simpler like that).

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
6 months agomtd-tests: flash_speed: Clarify the number of pages in each set while measuring
Miquel Raynal [Mon, 26 Aug 2024 09:46:26 +0000 (11:46 +0200)]
mtd-tests: flash_speed: Clarify the number of pages in each set while measuring

So far speed calculations have only be done 1 page at a time or 2 pages
at a time in a block; so basically all the block was always read because
all blocks are multiple of 2. But in the future, if we want to extend
the number of pages in a single read, the final number of pages actually
read might be less than an erase block size, hence failing the throuput
calculations.

Make the number of pages in a set explicit.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
6 months agomtd-tests: flash_speed: Drop an apparently useless block
Miquel Raynal [Mon, 26 Aug 2024 09:46:25 +0000 (11:46 +0200)]
mtd-tests: flash_speed: Drop an apparently useless block

I know no device without a multiple of 2 number of pages in each
block. Even though it might be the case, it is clearly not a big deal
and we don't really care about reading the last page, we are doing a
speed benchmark; so as long as the throughput calculation knows how much
data has been read it's fine. Eitherway, I don't think we ever have
fallen in this block because we would read the content of two pages (so
one past the block) and put it in a page-wide buffer, which would
probably lead to an out-of-bound abort.

Just drop the block.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
6 months agomtd-tests: nandbiterrs: Add support for testing continuous reads
Miquel Raynal [Mon, 26 Aug 2024 09:46:24 +0000 (11:46 +0200)]
mtd-tests: nandbiterrs: Add support for testing continuous reads

In order to trigger a continuous read, the user needs to request at
least two pages at the same time. So far the tool would only read single
pages, so let's extend its capabilities to test continuous read output
when the -c option is passed.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
6 months agomtd-tests: nandbiterrs: Store the chunks size in an intermediate variable
Miquel Raynal [Mon, 26 Aug 2024 09:46:23 +0000 (11:46 +0200)]
mtd-tests: nandbiterrs: Store the chunks size in an intermediate variable

'pagesize' is used for two purposes:
- accessing the size of a page
- getting the size of the test buffer, which happen to be the size of a
  page for now.
Use an intermediate variable when getting the size of the test buffer,
as we will later increase its size.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
6 months agonand-utils: nanddump: Add support for testing continuous reads
Miquel Raynal [Mon, 26 Aug 2024 09:46:22 +0000 (11:46 +0200)]
nand-utils: nanddump: Add support for testing continuous reads

In order to trigger a continuous read, the user needs to request more
than one data page. So far the tool would split the length into page
chunks. This is no longer the case when the -C option is passed (-c is
already used for the canonical output style).

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
6 months agonand-utils: nanddump: Explicitely use the page size when relevant
Miquel Raynal [Mon, 26 Aug 2024 09:46:21 +0000 (11:46 +0200)]
nand-utils: nanddump: Explicitely use the page size when relevant

Using bs when skipping the bad sector is abusive as what we want is
using the size of a block and the size of a page. The fact that bs
currently is the size of a page is misleading here, has I intend to make
this amount grow.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
6 months agonand-utils: nanddump: Use a specific variable for the buffer size
Miquel Raynal [Mon, 26 Aug 2024 09:46:20 +0000 (11:46 +0200)]
nand-utils: nanddump: Use a specific variable for the buffer size

The read buffer size happen to be as big as the bs variable, but this is
going to change. When accessing the buffer size, use a specific variable
instead.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
6 months agoRelease mtd-utils-2.2.1 v2.2.1
David Oberhollenzer [Wed, 25 Sep 2024 13:17:19 +0000 (15:17 +0200)]
Release mtd-utils-2.2.1

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
6 months agoUpdate CHANGELOG
David Oberhollenzer [Wed, 25 Sep 2024 07:08:10 +0000 (09:08 +0200)]
Update CHANGELOG

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
6 months agomtd-utils: Extract rbtree implementation to common lib
Zhihao Cheng [Fri, 2 Feb 2024 02:38:52 +0000 (10:38 +0800)]
mtd-utils: Extract rbtree implementation to common lib

Current rbtree implementation code is put under jffs utils, extract it
into common lib, and add more rbtree operations(eg. rb_first_postorder,
rb_next_postorder, etc.).

This is a preparation for replacing implementation of UBIFS utils with
linux kernel libs.

Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
6 months agomtd-utils: Extract list implementation to common lib and add list_sort support
Zhihao Cheng [Fri, 2 Feb 2024 02:22:53 +0000 (10:22 +0800)]
mtd-utils: Extract list implementation to common lib and add list_sort support

Current list implementation code is put under jffs utils, extract it into
common lib, and add more list operations(eg. list_move, list_splice, etc.).
Besides, add list sorting support in new source file lib/list_sort.c.

This is a preparation for replacing implementation of UBIFS utils with
linux kernel libs.

Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
7 months agomkfs.ubifs: Fix memleak for 'output' in error paths
Zhihao Cheng [Thu, 22 Feb 2024 12:37:40 +0000 (20:37 +0800)]
mkfs.ubifs: Fix memleak for 'output' in error paths

The 'output' is allocated in get_options(), don't forget to free it
in error paths, move 'output' freeing out of close_target(), which
simplifies the logic of close_target().

Fixes: 36ec51948e0ec ("Add mkfs.ubifs")
Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
7 months agomkfs.ubifs: Fix missed closing out_fd
Zhihao Cheng [Thu, 22 Feb 2024 12:27:58 +0000 (20:27 +0800)]
mkfs.ubifs: Fix missed closing out_fd

Closing 'out_fd' is missed in handling paths in open_target(), fix it
by adding closing operations before returning.

Fixes: a48340c335dab ("mkfs.ubifs: use libubi to format UBI volume")
Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
7 months agomkfs.ubifs: Close libubi in error handling paths
Zhihao Cheng [Thu, 22 Feb 2024 12:10:38 +0000 (20:10 +0800)]
mkfs.ubifs: Close libubi in error handling paths

The libubi could be opened in get_options(), don't forget to close it
in error handling paths in main(). Also close libubi in error handling
paths in open_ubi(). To implement that, extract libubi_close() into a
new helper function close_ubi().
Besides, invoke crypto_cleanup() in error handling paths in main().

Fixes: a48340c335dab ("mkfs.ubifs: use libubi to format UBI volume")
Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
7 months agomkfs.ubifs: Fix incorrect dir size calculation in encryption scenario
Zhihao Cheng [Thu, 9 May 2024 12:30:08 +0000 (20:30 +0800)]
mkfs.ubifs: Fix incorrect dir size calculation in encryption scenario

The size of directory should be the total length of encrypted entry name,
otherwise it could trigger errors while checking filesystem:
 dbg_check_filesystem [ubifs]: directory inode 89 size is 352, but
 calculated size is 400

Fixes: 4c55918dd747d ("Implement filename encryption")
Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
7 months agomkfs.ubifs: Fix wrong xattr entry type
Zhihao Cheng [Thu, 9 May 2024 11:41:28 +0000 (19:41 +0800)]
mkfs.ubifs: Fix wrong xattr entry type

The type of xattr entry should be regular file, otherwise xattr entry
and xattr inode have inconsistent types.

Fixes: 50044efbd6e713 ("mkfs.ubifs: Add extended attribute support")
Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
7 months agomkfs.ubifs: Initialize 'cipher_name' as NULL
Zhihao Cheng [Sun, 4 Feb 2024 02:21:44 +0000 (10:21 +0800)]
mkfs.ubifs: Initialize 'cipher_name' as NULL

Variable 'cipher_name' is defined on stack without initialization, when
an user invokes mkfs with '--key' and without '-C', 'cipher_name' is a
random value, which could cause init_fscrypt_context() failed to find a
valid cipher.
Fix it by initializing 'cipher_name' as NULL when it is declared.

Fixes: cc4c5e295f546 ("mkfs.ubifs: Enable support for building without crypto")
Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
7 months agomkfs.ubifs: Clear direct_write property when closing target
Zhihao Cheng [Wed, 7 Feb 2024 01:29:43 +0000 (09:29 +0800)]
mkfs.ubifs: Clear direct_write property when closing target

Direct writing is not allowd on an UBI volume, unless the volume is set
with direct_write property. The open_target sets direct_write property,
don't forget to clear direct_write property for UBI volume when closing
target.

Fixes: a48340c335dab ("mkfs.ubifs: use libubi to format UBI volume")
Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
7 months agomtd-utils: also check for static libuuid
Rosen Penev [Mon, 23 Sep 2024 20:45:02 +0000 (13:45 -0700)]
mtd-utils: also check for static libuuid

PKG_CHECK_MODULES confusingly does not check to see if a static version
of the library is available.

Actually with older glibc, it might fail as lpthread needs to be passed
to linker flags (Libs.private in pc files) which can only be obtained if
--static is passed to pkg-config.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
7 months agofs-tests: integck: Refactor: split out common remount logic
Csókás, Bence [Mon, 26 Aug 2024 11:24:59 +0000 (13:24 +0200)]
fs-tests: integck: Refactor: split out common remount logic

remount_tested_fs() and recover_tested_fs() both have
almost the same code for remounting the target FS
RO then RW. Split this sequence into a new
function called remount_ro_rw().

Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
Link: https://lore.kernel.org/linux-mtd/5530437c-b564-461f-26af-85bde1a00cb3@huawei.com/T/#mad1d043095b3f64a1f1eddd2d87b1545e329e141
Signed-off-by: Csókás, Bence <csokas.bence@prolan.hu>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
7 months agofs-tests: integck: Refactor: split out common remount logic
Csókás, Bence [Mon, 26 Aug 2024 11:24:57 +0000 (13:24 +0200)]
fs-tests: integck: Refactor: split out common remount logic

remount_tested_fs() and recover_tested_fs() both have
almost the same code for umount'ing the target FS and
mount'ing it back. Split this sequence into a new
function called umount_and_remount().

Signed-off-by: Csókás, Bence <csokas.bence@prolan.hu>
Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
7 months agolibubi: ubi_update_start: slightly improve documentation
Christian Eggers [Wed, 10 Jul 2024 11:29:04 +0000 (13:29 +0200)]
libubi: ubi_update_start: slightly improve documentation

Calling ubi_update_start() may fail if exclusive access to the UBI
volume cannot be established by the kernel. This is likely to happen if
an UBI volume is updated directly after creation, because current
versions of (systemd-)udevd run their internal 'blkid' also for UBI
volumes as soon as they appear (trying to read the UBIFS UUID).

There are mainly to options for this case:
1. Don't allow udevd to read UBI volumes at all (means loosing
functionatlity)
2. Wait until udevd has finished accessing a new volume (requires
cooperation with udevd)
3. Simply retry after short time in case of EBUSY

For using option 3, the documentation should state that the concrete
error code can be read via errno (this has always been the case since
libubi has been introduced).

Link: https://groups.google.com/g/swupdate/c/8NVooKjD9oo
Signed-off-by: Christian Eggers <ceggers@arri.de>
Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
12 months agomtd-utils: fectest: Fix time formatting with _TIME_BITS=64 on 32-bit system
Ben Hutchings [Fri, 12 Apr 2024 20:55:05 +0000 (22:55 +0200)]
mtd-utils: fectest: Fix time formatting with _TIME_BITS=64 on 32-bit system

fectest.c formats a struct timeval with the assumption that time_t and
suseconds_t are aliases for long, but some 32-bit systems now define
them as long long in order to support timestamps beyond 2038.

As this is an elapsed time and not a timestamp, both fields should be
within the range of long, so cast them to long before formatting
rather than moving to long long.

Signed-off-by: Ben Hutchings <ben.hutchings@mind.be>
Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
12 months agoRelease mtd-utils-2.2.0 v2.2.0
David Oberhollenzer [Fri, 29 Mar 2024 14:34:32 +0000 (15:34 +0100)]
Release mtd-utils-2.2.0

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
12 months agoUpdate CHANGELOG.md
David Oberhollenzer [Tue, 12 Mar 2024 11:15:09 +0000 (12:15 +0100)]
Update CHANGELOG.md

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
14 months agoUpdate README.txt
David Oberhollenzer [Sun, 18 Feb 2024 15:05:32 +0000 (16:05 +0100)]
Update README.txt

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
14 months agoAdd a build summary to configure.ac
David Oberhollenzer [Sun, 28 Feb 2021 13:22:31 +0000 (14:22 +0100)]
Add a build summary to configure.ac

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
14 months agoUnify handling of configure switches
David Oberhollenzer [Sun, 28 Feb 2021 14:34:12 +0000 (15:34 +0100)]
Unify handling of configure switches

Remove the strict check of the with or enable value and use the
generated variable instead of our own.

Also, don't use WITH_GETRANDOM as an implicit WITH_UBIHEALTHD, split
the two autoconf/automake variables and handle them separately.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
14 months agoCleanup: Unify handling of OpenSSL dependency
David Oberhollenzer [Sun, 28 Feb 2021 14:18:33 +0000 (15:18 +0100)]
Cleanup: Unify handling of OpenSSL dependency

This commit modifes the handling of the OpenSSL dependency to work the
same as the other optional dependencies, except that the variable
"with_crypto" is used instead of "with_openssl".

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
14 months agoMake zlib an optional dependency
David Oberhollenzer [Sat, 17 Feb 2024 15:37:56 +0000 (16:37 +0100)]
Make zlib an optional dependency

Now that we have plumbing in place for both jffsX-utils and mkfs.ubifs,
add the missing autoconf and automake changes to allow mtd-utils to be
built without a hard dependency on zlib.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
14 months agoMake it possible to compile mkfs.ubifs without zlib
David Oberhollenzer [Sun, 18 Feb 2024 13:22:08 +0000 (14:22 +0100)]
Make it possible to compile mkfs.ubifs without zlib

This one is a bit trickier than adding WITH_ZLIB ifdefs. Some parts
of the code assume that zlib is always present and have complicated
fallback behavior. Particularly the "favor_lzo" compression method
that uses either zlib or lzo, whichever produces the better result.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
14 months agoMake it possible to compile jffsX-utils without zlib
David Oberhollenzer [Sun, 18 Feb 2024 12:52:42 +0000 (13:52 +0100)]
Make it possible to compile jffsX-utils without zlib

The jffsX-utils already have a CONFIG_JFFS2_ZLIB define, but it is
statically defined in a header and not used consistently. This patch
first replaces it with a "WITH_ZLIB" define, provided via automake,
to bring it in line with the already existing "WITH_LZO". Then, the
missing checks and typedefs are added in jffs2reader.c.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
14 months agoFix optional compilation of lzo compressors
David Oberhollenzer [Sat, 17 Feb 2024 20:13:24 +0000 (21:13 +0100)]
Fix optional compilation of lzo compressors

 - Simple fixup in autoconf.ac
 - Make compilation of jffsX-utils compr_lzo.c optional. Simply
   don't compile it if we built without LZO and remove the place
   holders. They are not used anyway if we build without LZO.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
14 months agoCleanup handling of optional dependencies
David Oberhollenzer [Sun, 28 Feb 2021 12:50:57 +0000 (13:50 +0100)]
Cleanup handling of optional dependencies

Don't use super pedantic parsing of the argument and work with the
generated variable instead of assigning it to our own and set it
to "check" if not value is assigned. Then search for a dependency
if the with variable is anything other than "no" and fail if it
was set to "yes".

In addition, the WITHOUT_xxx defines are replaced with WITH_xxx defines.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
14 months agoAdd missing autoconf check for AR
David Oberhollenzer [Wed, 14 Feb 2024 12:58:36 +0000 (13:58 +0100)]
Add missing autoconf check for AR

After removing libtool, there is no more cross-check for AR. Because
some slightly older versions of autoconf don't have AC_PROG_AR, simply
insert the implementation one-liner.

We already tried bumping the minimum autoconf version once in the past,
but apparently that is an issue for a number of distros.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
16 months agomkfs.ubifs: fix xattr scanning for builds with selinux support
David Oberhollenzer [Fri, 15 Dec 2023 11:42:41 +0000 (12:42 +0100)]
mkfs.ubifs: fix xattr scanning for builds with selinux support

mkfs.uibfs can add Selinux xattrs from a labeling file using
libselinux to parse it. The commit that added this feature simply
introduced a separate function, inode_add_selinux_xattr, which is
called instead of inode_add_xattr. If no --selinux argument is
specified for mkfs.ubifs, this is a no-op.

The problem is, that this breaks xattr scanning for any build with
Selinux enabled. The Selinux version is always called and it does
not scan for xattrs on the filesystem, or dispatch to the original.

This commit fixes the xattr scanning behavior. We unconditionally call
both functions (they each have no-op implementations if the feature
is missing) and in the regular xattr scanning code, we skip selinux
attributes, if the --selinux option was given.

Fixes: f1feccec5ad8 ("mkfs.ubifs: Implement selinux labelling support")
Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
17 months agoubiattach: introduce need_resv_pool in UBI_IOCATT
Zhihao Cheng [Mon, 13 Nov 2023 09:48:12 +0000 (17:48 +0800)]
ubiattach: introduce need_resv_pool in UBI_IOCATT

The ioctl UBI_IOCATT has been extended with need_resv_pool parameter in
[1].

This parameter is used for deciding whether to reserve PEBs for filling
pool/wl_pool for target ubi device. This parameter will be effective
when fastmap is enabled, which will slow down the frequency of updating
fastmap by filling more free PEBs in pool/wl_pool. See details in [2].

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ac085cfe57df2cc1d7a5c4c5e64b8780c8ad452f
[2] https://bugzilla.kernel.org/show_bug.cgi?id=217787

Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
17 months agoubiattach: introduce disable_fm in UBI_IOCATT
Zhihao Cheng [Mon, 13 Nov 2023 09:48:11 +0000 (17:48 +0800)]
ubiattach: introduce disable_fm in UBI_IOCATT

The ioctl UBI_IOCATT has been extended with disable_fm parameter after
[1].

This parameter is used for disabling fastmap for target ubi device.
If 'disable_fm' is set, ubi doesn't create new fastmap even the module
param 'fm_autoconvert' is set, and existed old fastmap will be destroyed
after attaching process.

A simple test case in [2].

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=669d204469c46e91d99da24914130f78277a71d3
[2] https://bugzilla.kernel.org/show_bug.cgi?id=216278

Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
17 months agomtd-utils: flash_erase: Add an option for JFFS2 cleanmarker size
Takahiro Kuwano [Tue, 7 Nov 2023 09:23:57 +0000 (18:23 +0900)]
mtd-utils: flash_erase: Add an option for JFFS2 cleanmarker size

JFFS2 supports buffer mode for ECC'd NOR Flash that cleanmarker size
is rounded up to mtd->writesize, while the '-j' option in flash_erase
utility uses fixed 12 bytes. That makes flash program ops unaligned to
mtd->writesize and causes program error or disables ECC.

The mkfs.jffs2 utility supports '-c' option that allows users to specify
cleanmarker size. This patch implements '-c' option in the flash_erase
that can be used along with '-j' option.

Signed-off-by: Takahiro Kuwano <Takahiro.Kuwano@infineon.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
19 months agoflashcp: Add write last option.
Piotr Esden-Tempski [Fri, 1 Sep 2023 00:55:03 +0000 (17:55 -0700)]
flashcp: Add write last option.

This option is useful for power fail resilient bootloader updates, for
systems that check only the partition header for validity before
attempting to load the bootloader. For example zynq.

Postponing the write of a specified amount of bytes at the beginning of
a bootloader makes sure a written bootloader slot is not considered
valid until all the data is written.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
19 months agoCleanup: remove self assign
David Oberhollenzer [Mon, 4 Sep 2023 08:07:54 +0000 (10:07 +0200)]
Cleanup: remove self assign

This no-op was remarked by coverity. According to git-blame, it has
been this way since the initial commit in 2006.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
19 months agoAdd a README file
David Oberhollenzer [Sun, 3 Sep 2023 12:41:26 +0000 (14:41 +0200)]
Add a README file

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
19 months agoPull the bulk of the pre 2.0.0 changes from the git tree
David Oberhollenzer [Sun, 3 Sep 2023 02:04:28 +0000 (04:04 +0200)]
Pull the bulk of the pre 2.0.0 changes from the git tree

For the most part, this was straight forward. For the very old
releases, there were lots of changes that are not straight forward
to untangle.

The following two releases posed issues:

 - Version 1.4.1 does not have a tag. The release tarball on FTP
   is from 2010-10-19 and appears to contain 1.4.0 with commit
   b864c387e8f16273aad1453d6457d847e29c3d25 cherry-picked on top
   of it (except for one line that was fixed in the release, but
   broken in the repo).

 - Version 1.4.6 also does not have a tag. The release tarball
   is from 2011-08-19. This _presumably_ corresponds with commit
   b602ab59b9782003d1179488d8c1580bc8563738 that bumps the version
   number.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
19 months agoPiece together a CHANGELOG file from the release announcments
David Oberhollenzer [Sat, 2 Sep 2023 14:56:00 +0000 (16:56 +0200)]
Piece together a CHANGELOG file from the release announcments

The CHANGELOG tries to summarize the change history of the project
and currently contains changes from 2.0.0 onwards that could easily
be extracted from the release mails.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
19 months agojffs2dump: check return value of lseek
David Oberhollenzer [Sat, 2 Sep 2023 14:11:44 +0000 (16:11 +0200)]
jffs2dump: check return value of lseek

On error, lseek returns a negative value. We need to check for that
and abort, instead of passing -1 to malloc and later on to read_nocheck.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
19 months agoRelease mtd-utils-2.1.6 v2.1.6
David Oberhollenzer [Tue, 29 Aug 2023 22:20:53 +0000 (00:20 +0200)]
Release mtd-utils-2.1.6

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
20 months agoFix printf format specifiers for 64 bit integer types
David Oberhollenzer [Thu, 24 Aug 2023 08:28:42 +0000 (10:28 +0200)]
Fix printf format specifiers for 64 bit integer types

In nandflipbits, nandtest and ubiscan, uint64_t integers are printed
to stdout using "%llu" as a format specifier, but on platforms like
x86_64, uint64_t is actually typedef'd as `unsigned long` only.

For compatibillity across platforms, simply use the C99 printfs
macros instead.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
20 months agoMake sure ubi-media structures are visible for libubigen
David Oberhollenzer [Thu, 24 Aug 2023 08:02:59 +0000 (10:02 +0200)]
Make sure ubi-media structures are visible for libubigen

The libubigen.h header relies on external declarations in ubi-media.h.
While not technically needed, it generates warnings in mtdinfo.c if
those are not visible. All other places where libubigen is used include
the header first. This is primarily to silence compiler warnings related
to the missing declrations.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
20 months agoRemove unused symbols
David Oberhollenzer [Thu, 24 Aug 2023 07:57:19 +0000 (09:57 +0200)]
Remove unused symbols

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
20 months agoUpdate ax_pthread
David Oberhollenzer [Thu, 24 Aug 2023 07:43:53 +0000 (09:43 +0200)]
Update ax_pthread

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
20 months agoRemove libtool usage from configure.ac
David Oberhollenzer [Thu, 24 Aug 2023 07:35:43 +0000 (09:35 +0200)]
Remove libtool usage from configure.ac

We do not build any shared libraries, there is no reason to use libtool
or disable static. We do build static libraries, for which we need ranlib.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
20 months agomtd-utils: nandtest: handle large nand devices
Christian Wendt he/him [Wed, 23 Aug 2023 11:09:28 +0000 (13:09 +0200)]
mtd-utils: nandtest: handle large nand devices

Running nandtest on devices with sizes of 4Gb or more does not work, as
the size returned in mtd_info_user is reported as 0 for 4Gb devices for
example.

The patch uses sysfs to figure out the size of the nand device (as
recommended in a comment in include/mtd/mtd-abi.h) and changes sizes
and offsets to 64 bit values.

[From: Christian Wendt <cw@brainaid.de>]
Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
22 months agomtd-utils: Add new syntax to get devices by name
Brandon Maier [Mon, 12 Dec 2022 18:01:58 +0000 (12:01 -0600)]
mtd-utils: Add new syntax to get devices by name

This introduces a new feature to the MTD command line utilities that
allows MTD devices to be referenced by name instead of device node. For
example this looks like:

> # Display info for the MTD device with name "data"
> mtdinfo mtd:data
> # Copy file to MTD device with name "data"
> flashcp /my/file mtd:data

This follows the syntax supported by the kernel which allows MTD
device's to be mounted by name[1].

Add the function mtd_find_dev_node() that accepts an MTD "identifier"
and returns the MTD's device node. The function accepts a string
starting with "mtd:" which it treats as the MTD's name. It then attempts
to search for the MTD, and if found maps it back to the /dev/mtdX device
node. If the string does not start with "mtd:", then assume it's the old
style and refers directly to a MTD device node.

The function is then hooked into existing tools like flashcp, mtdinfo,
flash_unlock, etc. To load in the new MTD parsing code in a consistent
way across programs.

[1] http://www.linux-mtd.infradead.org/faq/jffs2.html#L_mtdblock

Signed-off-by: Brandon Maier <brandon.maier@collins.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
22 months agolibmtd: Add function to get MTD info by device name
Brandon Maier [Mon, 12 Dec 2022 18:01:57 +0000 (12:01 -0600)]
libmtd: Add function to get MTD info by device name

This is a convenience function for end users. In some situations it's
easier to reference MTD device's by their name then by MTD number, as
the name may be more reliable if device partitioning is dynamic or for
porting between systems.

Signed-off-by: Brandon Maier <brandon.maier@collins.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
22 months agomkfs.ubifs: Fix mkfs.ubifs failure with option selinux
Zijun Hu [Fri, 26 May 2023 08:47:33 +0000 (16:47 +0800)]
mkfs.ubifs: Fix mkfs.ubifs failure with option selinux

Below failure happens when mkfs.ubifs --selinux=FILE ...
"Error: bad file context FILE 1"
"No such file or directory (error 2)"

It is fixed by this change.

Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
2 years agomisc-utils: flashcp: correct casting for percent display
cchoux [Sat, 22 Apr 2023 07:31:15 +0000 (15:31 +0800)]
misc-utils: flashcp: correct casting for percent display

Add correct casting for written to prevent overflow that size_t is
only 32 bits on a 32-bit platform.

Signed-off-by: cchoux <chou.cosmo@gmail.com>
Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
2 years agomtd-utils: flash_speed: Measure read while write latency
Miquel Raynal [Thu, 10 Nov 2022 15:59:38 +0000 (16:59 +0100)]
mtd-utils: flash_speed: Measure read while write latency

The Read While Write (RWW) feature allows to perform reads from the
flash array into cache while a program (from cache) or an erase
operation happens, provided that the two areas are located on different
banks.

The main benefit is the possible reduced latency when requesting to read
a page while a much longer operation is ongoing, like a write or an
erase.

We can try to compare the positive impact of such a feature by enhancing
the flash_speed test tool with the following test:
- Measure the time taken by an eraseblock write in parallel with an
  eraseblock read.
- Measure when the read operation ends.
- Compare the two to get the latency saved with the RWW feature.

To be sure the mtd_write actually starts (and acquires the necessary
locks) before the mtd_read does, we use SCHED_FIFO at rather high
(arbitrary) priorities, respectively 42 and 41.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
2 years agomtd-utils: flash_speed: Rework the time counting helpers
Miquel Raynal [Thu, 10 Nov 2022 15:59:37 +0000 (16:59 +0100)]
mtd-utils: flash_speed: Rework the time counting helpers

In order to be able to have interleaved measures, let's not use the
start and finish global variables from the time helpers directly,
provide parameters for these variables so that we can provide either the
global entries, or more specific ones when relevant.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
2 years agomisc-utils: mtdpart: document partition of size 0
Brandon Maier [Thu, 3 Nov 2022 14:12:17 +0000 (09:12 -0500)]
misc-utils: mtdpart: document partition of size 0

If the partition size passed in to the BLKPG_ADD_PARTITION ioctl is 0,
Linux will make the partition fill to the end of the device[1]. Document
this feature in the help.

[1] https://elixir.bootlin.com/linux/v6.0.6/source/drivers/mtd/mtdpart.c#L254

Signed-off-by: Brandon Maier <brandon.maier@collins.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
2 years agomisc-utils: flashcp: abort on --partition and --erase-all
Brandon Maier [Wed, 2 Nov 2022 22:47:57 +0000 (17:47 -0500)]
misc-utils: flashcp: abort on --partition and --erase-all

Signed-off-by: Brandon Maier <brandon.maier@collins.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
2 years agomisc-utils: flashcp: verify data in --partition
Brandon Maier [Wed, 2 Nov 2022 22:47:56 +0000 (17:47 -0500)]
misc-utils: flashcp: verify data in --partition

The --partition mode is not verifying that data is being written
successfully.

Signed-off-by: Brandon Maier <brandon.maier@collins.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
2 years agomisc-utils: flashcp: fix buffer overflow
Brandon Maier [Wed, 2 Nov 2022 22:47:55 +0000 (17:47 -0500)]
misc-utils: flashcp: fix buffer overflow

The DIFF_BLOCKS code requires that src and dest buffers be large enough
to hold one MTD erasesize. This is because each loop operates on one
eraseblock so that it can erase and write one whole sector. But the src
and dest buffers are fixed at BUFSIZE, so on platforms where the MTD
erasesize are larger then BUFSIZE it will overflow the buffers.

Instead allocate the buffers dynamically so that they can be sized to
fit the erasesize.

Signed-off-by: Brandon Maier <brandon.maier@collins.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
2 years agomisc-utils: flashcp: simplify logging
Brandon Maier [Wed, 2 Nov 2022 22:47:54 +0000 (17:47 -0500)]
misc-utils: flashcp: simplify logging

Most of the uses of log_printf fall into two styles

> if (flags & FLAG_VERBOSE)
>     log_printf(LOG_NORMAL, ...);

or

> log_printf(LOG_ERROR, ...)
> exit(EXIT_FAILURE);

Replace them with log_verbose and log_failure respectively.

Signed-off-by: Brandon Maier <brandon.maier@collins.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
2 years agomisc-utils: flashcp: add safe_memerase
Brandon Maier [Wed, 2 Nov 2022 22:47:53 +0000 (17:47 -0500)]
misc-utils: flashcp: add safe_memerase

Signed-off-by: Brandon Maier <brandon.maier@collins.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
2 years agomisc-utils: flashcp: check for lseek errors
Brandon Maier [Wed, 2 Nov 2022 22:47:52 +0000 (17:47 -0500)]
misc-utils: flashcp: check for lseek errors

Add a safe_lseek wrapper to check for lseek errors.

Signed-off-by: Brandon Maier <brandon.maier@collins.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
2 years agomisc-utils: flashcp: add safe_write
Brandon Maier [Wed, 2 Nov 2022 22:47:51 +0000 (17:47 -0500)]
misc-utils: flashcp: add safe_write

Share the writing code between the two write implementations.

Signed-off-by: Brandon Maier <brandon.maier@collins.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
2 years agoRelease mtd-utils-2.1.5 v2.1.5
David Oberhollenzer [Fri, 7 Oct 2022 11:02:04 +0000 (13:02 +0200)]
Release mtd-utils-2.1.5

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
2 years agoFix warning about unaligned pointer in jffs2reader
Frederic Germain [Tue, 9 Nov 2021 08:17:49 +0000 (08:17 +0000)]
Fix warning about unaligned pointer in jffs2reader

gcc 9.3.0-17ubuntu1~20.04 warning on time_t ctime value is :

Fix taking address of packed member of ‘struct jffs2_raw_inode’ may
result in an unaligned pointer value [-Waddress-of-packed-member].

Signed-off-by: Frederic Germain <frederic.germain@gmail.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
2 years ago.gitignore: add new ubiscan utility
Frederic Germain [Tue, 9 Nov 2021 08:17:48 +0000 (08:17 +0000)]
.gitignore: add new ubiscan utility

Signed-off-by: Frederic Germain <frederic.germain@gmail.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
2 years agonor-utils: fix memory leak
liaohua [Fri, 18 Feb 2022 03:22:19 +0000 (11:22 +0800)]
nor-utils: fix memory leak

This patch replace "free(rfd.sector_map)" with "free(rfd.header)"
to fix memory leak.

Signed-off-by: liaohua <liaohua4@huawei.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
2 years agolibmtd: do not ignore non-zero eraseblock size when MTD_NO_ERASE is set
Enrico Jorns [Fri, 19 Aug 2022 12:32:13 +0000 (14:32 +0200)]
libmtd: do not ignore non-zero eraseblock size when MTD_NO_ERASE is set

In 54d68799, mtd->eb_cnt was enforced to be '1' if MTD_NO_ERASE is set.
This was done with the aim of preventing divisions by zero.

However, even if MTD_NO_ERASE is set, mtd->eb_size (eraseblock size) can
still be set to a non-zero value which would not cause a division by
zero.

Instead, enforcing an eraseblock count of '1' here even leads to
inconsistent eraseblock counting in mtd-utils and lets for example a
'flash_erase' on an mtdnand device fail:

| # flash_erase /dev/mtd0 0 0
| Erasing 32768 Kibyte @ 0 --  0 % complete libmtd: error!: bad eraseblock number 255, mtd0 has 1 eraseblocks
| flash_erase: error!: /dev/mtd0: MTD Erase entire chip failureTrying one by one each sector.
|              error 22 (Invalid argument)
| Erasing 128 Kibyte @ 0 --  0 % complete libmtd: error!: bad eraseblock number 1, mtd0 has 1 eraseblocks
| flash_erase: error!: /dev/mtd0: MTD get bad block failed
|              error 22 (Invalid argument)

Also mtdinfo would look inconsistent (eraseblock size vs amount):

| # mtdinfo /dev/mtd0
| mtd0
| Name:                           mtdram test device
| Type:                           ram
| Eraseblock size:                131072 bytes, 128.0 KiB
| Amount of eraseblocks:          1 (33554432 bytes, 32.0 MiB)
| Minimum input/output unit size: 1 byte
| Sub-page size:                  1 byte
| Character device major/minor:   90:0
| Bad blocks are allowed:         false
| Device is writable:             true

Fix this by enforcing mtd->eb_cnt to be '1' only when mtd->eb_size is
actually zero and would lead to a division by zero otherwise.

Fixes: 54d68799 ("libmtd: avoid divide by zero")
Signed-off-by: Enrico Jorns <ejo@pengutronix.de>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
2 years agomtd-utils: flash_otp_dump make offset optional
Michael Walle [Thu, 18 Aug 2022 09:35:48 +0000 (11:35 +0200)]
mtd-utils: flash_otp_dump make offset optional

Commit 0a5e2fa5c1e4 ("mtd-utils: add optional offset parameter to
flash_otp_dump") introduced an offset parameter. This should have
been optional, but there was a typo. Fix it.

Reported-by: Sergei Antonov <saproj@gmail.com>
Fixes: 0a5e2fa5c1e4 ("mtd-utils: add optional offset parameter to flash_otp_dump")
Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Sergei Antonov <saproj@gmail.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
2 years agomkfs.jffs2: fix spelling of --compression-mode parameter in help text
Alex Henrie [Thu, 22 Sep 2022 03:14:40 +0000 (21:14 -0600)]
mkfs.jffs2: fix spelling of --compression-mode parameter in help text

--compr-mode is not accepted as an alias of --compression-mode.

Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
2 years agotests: Remove unused linux/fs.h header from includes
Khem Raj [Sun, 7 Aug 2022 03:21:39 +0000 (20:21 -0700)]
tests: Remove unused linux/fs.h header from includes

This header is not needed, moreover it includes linux/mount.h which is
now in conflict[1] with glibc provided sys/mount.h from glibc 2.36 onwards

[1] https://sourceware.org/glibc/wiki/Release/2.36

Signed-off-by: Khem Raj <raj.khem@gmail.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
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>