Zhihao Cheng [Mon, 11 Nov 2024 08:36:42 +0000 (16:36 +0800)]
ubifs-utils: Add linux type definitions
Add linux type definitions, because there are many types
(eg. u8/u16/u64) used in UBIFS linux kernel libs. Besides
move type conversions (eg. cpu_to_le16, cpu_to_le32, etc.)
into type definitions header file.
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>
Add compiler attributes implementations, such as __packed, __unused,
__const, etc., which could be used in linux kernel libs. Besides, change
some existing attributes into linux kernel style.
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>
Zhihao Cheng [Mon, 11 Nov 2024 08:36:40 +0000 (16:36 +0800)]
ubifs-utils: Import UBIFS libs from linux kernel
Import UBIFS libs from linux kernel. Next patches will replace ubifs
related source code with implementation of linux kernel, which makes
userspace implementation be same with linux kernel, then fsck.ubifs
can resuse the code.
Notice: lpt.c is modified with [1] applied. ubifs.h and orphan.c are
modified with [2] applied, journal.c is modified with [3] reverted(
because fsck runs in a single thread, so waitqueue is not needed to
be implemented in userspace.).
[1] https://lore.kernel.org/linux-mtd/20231228014112.2836317-13-chengzhihao1@huawei.com/
[2] https://lore.kernel.org/linux-mtd/20240410073751.2522830-1-chengzhihao1@huawei.com/
[3] https://lore.kernel.org/linux-mtd/20240122063103.359501-1-chengzhihao1@huawei.com/
Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com> Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Zhihao Cheng [Mon, 11 Nov 2024 08:36:38 +0000 (16:36 +0800)]
ubifs-utils: Add 'dev_fd' and 'libubi' into 'ubifs_info' structure
Embed new members 'dev_fd' and 'libubi' into ubifs_info structure, so
that global variable 'ubi', 'out_fd' and 'out_ubi' could be removed
from mkfs.ubifs.c. Besides, add parameter in check_volume_empty().
Next patch will extract UBI opening/closing/check_volume_empty functions
into a new source file, these functions will be used in fsck.
Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com> Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Zhihao Cheng [Mon, 11 Nov 2024 08:36:37 +0000 (16:36 +0800)]
ubifs-utils: Add 'dev_name' into 'ubifs_info' structure
Embed new member 'dev_name' into 'ubifs_info' structure, then global
variable 'output' can be removed from mkfs.ubifs.c. Next patches will
import UBIFS libs from linux kernel, which could print messages that
contain device information, so this patch can distinguish different
devices according to messages.
Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com> Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Zhihao Cheng [Mon, 11 Nov 2024 08:36:36 +0000 (16:36 +0800)]
ubifs-utils: Move 'debug_level' into ubifs_info structure
Embed new member 'debug_level' into 'ubifs_info' structure, then global
variable 'debug_level' can be removed from mkfs.ubifs.c. Next patches
will import UBIFS libs from linux kernel, which could print messages
with different levels, then 'debug_level' can be used to control which
level messages should be printed.
Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com> Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Zhihao Cheng [Mon, 11 Nov 2024 08:36:35 +0000 (16:36 +0800)]
ubifs-utils: Clean up error message printing functions
Functions 'err_msg' and 'sys_err_msg' are almost same with 'errmsg' and
'sys_errmsg', since 'errmsg' and 'sys_errmsg' can print programe name,
so replace error message printing functions (ubifs-utils) with common
lib functions(include/common.h).
Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com> Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Zhihao Cheng [Mon, 11 Nov 2024 08:36:34 +0000 (16:36 +0800)]
ubifs-utils: Define PROGRAM_NAME as variable
PROGRAM_NAME is defined as a const string "mkfs.ubifs", which won't be
suitable for fsck.ubifs. Add 'program_name' member in ubifs_info
structure, define PROGRAM_NAME as ubifs_info.program_name. Then, error
messages will display right program name if fsck.ubifs is supported.
Besides, add 'program_type' member in ubifs_info structure to identify
which current program type is, without comparing program name.
Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com> Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Zhihao Cheng [Mon, 11 Nov 2024 08:36:33 +0000 (16:36 +0800)]
ubifs-utils: Decouple mkfs.ubifs.h out of other modules
Header file mkfs.ubifs.h is included in other modules(eg. compr.c, lpt.c,
fscrypt.h, sign.c), decouple it out of other modules.
There are two parts in mkfs.ubifs.h:
1. common functions, for example dbg_msg, err_msg and write_leb, move
these functions into common/defs.h and common/ubifs.h.
2. devtable related definations, move them into a new header file
common/devtable.h.
Splitting common functions from mkfs.ubifs.h is also a preparation for
importing libubifs(from linux kernel) to replace current UBIFS libs.
Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com> Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Zhihao Cheng [Mon, 11 Nov 2024 08:36:32 +0000 (16:36 +0800)]
ubifs-utils: Split common source files from mkfs.ubifs
Split common source files into common dir from mkfs.ubifs, this is a
preparation for importing libubifs(from linux kernel) to replace
current UBIFS libs.
Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com> Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Currently the read throuput test tries:
- 1 page
- 2 pages
- 1 block (64 or more pages, usually)
But it might be interesting to see how the speed gradually increases,
eg. testing all number of pages from 1 to maybe 16, and then
arbitrarilly 32 and 64.
Let's add a -C parameter to enable this additional test.
The 2-page read/write tests are also moved under this new option.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Miquel Raynal [Mon, 26 Aug 2024 09:46:28 +0000 (11:46 +0200)]
mtd-tests: flash_speed: Drop read_eraseblock_by_page()
The read_eraseblock_by_2pages() has been generalized so it became
read_eraseblock_by_npages(), but there is no limitation (besides 0)
regarding the number of pages. Hence, drop the _by_page() helper and
replace it with the _by_npages(), using 'npages = 1'.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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().
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>
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>
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
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>
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>
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>
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().
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().
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>
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>
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>
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>
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>
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>
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>
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>
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>
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.
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].
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.
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>
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>
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>
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>
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>
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>
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>
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.
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>
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>
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>
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.
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>
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>
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>
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.
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>
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>
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>