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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>