summaryrefslogtreecommitdiff
path: root/cmd/mtd.c
AgeCommit message (Collapse)Author
2025-11-18cmd: mtd: benchmark: use lldiv() instead of 64-bit divisionMikhail Kshevetskiy
As was noted by Heinrich Schuchardt, some SoCs may not support 64-bit divisions. Fix an issue by using lldiv() instead. The code assumes that the benchmark never takes more than 4294 seconds and thus the difference will be less than U32_MAX. Also replace (speed / 1024) by (speed >> 10) to avoid potential 64-bit division. Signed-off-by: Mikhail Kshevetskiy <[email protected]>
2025-10-28cmd: mtd: Prevent use of uninitialised variableAndrew Goodbody
ret maybe used uninitialised in some cases so instead initialise it first to prevent this. This issue was found by Smatch. Fixes: 9671243e8d10 (cmd: mtd: Use the subcmd infrastructure to declare mtd sub-commands) Signed-off-by: Andrew Goodbody <[email protected]> Reviewed-by: Quentin Schulz <[email protected]>
2025-10-05cmd: mtd: add benchmark option to the helpMikhail Kshevetskiy
The patch adds benchmark option to the help of mtd command. For the 'mtd write' case the help line exceed 80 characters. Ignore this issue as modern terminals are capable to handle more characters. The patch also formats other command to make sure all device names starts on the same collumn. Fixes: d246e70cf81d0 ("cmd: mtd: Enable speed benchmarking") Signed-off-by: Mikhail Kshevetskiy <[email protected]> Reviewed-by: Miquel Raynal <[email protected]> Signed-off-by: Michael Trimarchi <[email protected]>
2025-10-05cmd: mtd: fix speed measurement in the speed benchmarkMikhail Kshevetskiy
The shown speed is inversely proportional to the data size. See the output: spi-nand: spi_nand nand@0: Micron SPI NAND was found. spi-nand: spi_nand nand@0: 256 MiB, block size: 128 KiB, page size: 2048, OOB size: 128 ... => mtd read.benchmark spi-nand0 $loadaddr 0 0x40000 Reading 262144 byte(s) (128 page(s)) at offset 0x00000000 Read speed: 63kiB/s => mtd read.benchmark spi-nand0 $loadaddr 0 0x20000 Reading 131072 byte(s) (64 page(s)) at offset 0x00000000 Read speed: 127kiB/s => mtd read.benchmark spi-nand0 $loadaddr 0 0x10000 Reading 65536 byte(s) (32 page(s)) at offset 0x00000000 Read speed: 254kiB/s In the spi-nand case 'io_op.len' is not always the same as 'len', thus we are using the wrong amount of data to derive the speed. Also make sure we are using 64-bit calculation to get a more precise results. Fixes: d246e70cf81d0 ("cmd: mtd: Enable speed benchmarking") Signed-off-by: Mikhail Kshevetskiy <[email protected]> Reviewed-by: Miquel Raynal <[email protected]> Signed-off-by: Michael Trimarchi <[email protected]>
2025-10-05cmd: mtd: add nand_read_test command supportMikhail Kshevetskiy
This patch implements read-only test of nand flash devices. Test reads blocks of NAND flash in normal and raw modes and compares results. The following statuses can be returned for a block: * non-ecc reading failed, * ecc reading failed, * block is bad, * bitflips is above maximum, * actual number of biflips above reported one, * bitflips reached it maximum value, * bitflips above threshold, * block is ok. Signed-off-by: Mikhail Kshevetskiy <[email protected]> Signed-off-by: Michael Trimarchi <[email protected]>
2025-10-05cmd: mtd: add nand_write_test command supportMikhail Kshevetskiy
Some nand flashes (like spi-nand one) are registered with mtd subsystem only, thus nand command can't be used to work with such flashes. As result some functionality is missing. This patch implements 'nand torture' functionality for mtd command. Signed-off-by: Mikhail Kshevetskiy <[email protected]> Reviewed-by: Miquel Raynal <[email protected]> Signed-off-by: Michael Trimarchi <[email protected]>
2025-10-05cmd: mtd: add markbad command supportMikhail Kshevetskiy
Some nand flashes (like spi-nand one) are registered with mtd subsystem only, thus nand command can't be used to work with such flashes. As result some functionality is missing. This patch implements 'nand markbad' functionality for mtd command. Signed-off-by: Mikhail Kshevetskiy <[email protected]> Reviewed-by: Miquel Raynal <[email protected]> Signed-off-by: Michael Trimarchi <[email protected]>
2025-08-23cmd: mtd: Enable speed benchmarkingMiquel Raynal
Linux features a flash_speed speed test from the mtd-utils suite, U-Boot does not. Benchmarks are useful for speed improvement developments as well as troubleshooting or regression testing sometimes. Enable a benchmark option to enable this feature. Example of output on a Nuvoton platform: MA35D1> mtd read nor0 0x81000000 0 0x10000 Reading 65536 byte(s) at offset 0x00000000 MA35D1> mtd read.benchmark nor0 0x81000000 0 0x10000 Reading 65536 byte(s) at offset 0x00000000 Read speed: 3752kiB/s Signed-off-by: Miquel Raynal <[email protected]> Signed-off-by: Michael Trimarchi <[email protected]>
2024-12-17cmd: mtd: simplify mtd_show_device()Heinrich Schuchardt
CONFIG_DM=y is always true. Signed-off-by: Heinrich Schuchardt <[email protected]> Reviewed-by: Miquel Raynal <[email protected]> Acked-by: Michael Trimarchi <[email protected]>
2024-10-10mtd: implement support for LED activityChristian Marangi
Implement support for LED activity. If the feature is enabled, make the defined ACTIVITY LED to signal mtd operations. LED activity is implemented HERE and not in the subsystem side to limit any performance degradation in case multiple call to MTD subsystem read/write are done. Signed-off-by: Christian Marangi <[email protected]> Reviewed-by: Simon Glass <[email protected]>
2024-05-20Restore patch series "arm: dts: am62-beagleplay: Fix Beagleplay Ethernet"Tom Rini
As part of bringing the master branch back in to next, we need to allow for all of these changes to exist here. Reported-by: Jonas Karlman <[email protected]> Signed-off-by: Tom Rini <[email protected]>
2024-05-19Revert "Merge patch series "arm: dts: am62-beagleplay: Fix Beagleplay Ethernet""Tom Rini
When bringing in the series 'arm: dts: am62-beagleplay: Fix Beagleplay Ethernet"' I failed to notice that b4 noticed it was based on next and so took that as the base commit and merged that part of next to master. This reverts commit c8ffd1356d42223cbb8c86280a083cc3c93e6426, reversing changes made to 2ee6f3a5f7550de3599faef9704e166e5dcace35. Reported-by: Jonas Karlman <[email protected]> Signed-off-by: Tom Rini <[email protected]>
2024-05-06cmd: Remove <common.h> and add needed includesTom Rini
Remove <common.h> from all "cmd/" files and when needed add missing include files directly. Signed-off-by: Tom Rini <[email protected]>
2024-04-14cmd: mtd: OTP access supportArseniy Krasnov
Add access to OTP region. It supports info, dump, write and lock operations. Usage example: 'mtd otpread nand0 u 0 1024' - dump 1024 bytes of user area starting from offset 0 of device 'nand0'. 'mtd otpwrite nand0 10 11223344' - write binary data 0x11, 0x22, 0x33, 0x44 to offset 10 to user area of device 'nand0'. 'mtd otplock nand0 0 1024' - lock 1024 bytes of user area starting from offset 0 of device 'nand0'. 'mtd otpinfo nand0 f' - show info about factory area of device 'nand0'. Link: https://lore.kernel.org/all/[email protected] Signed-off-by: Arseniy Krasnov <[email protected]> Signed-off-by: Dario Binacchi <[email protected]>
2024-01-15cmd: mtd: avoid unintentional integer overflowHeinrich Schuchardt
mtd dump beyond 4 GiB will show incorrect results. Multiplying two u32 will yield a u32. Add a missing cast. Fixes: 5db66b3aee6f ("cmd: mtd: add 'mtd' command") Addresses-Coverity-ID: 477205 ("Unintentional integer overflow") Signed-off-by: Heinrich Schuchardt <[email protected]> Reviewed-by: Miquel Raynal <[email protected]> Link: https://lore.kernel.org/all/[email protected] Signed-off-by: Dario Binacchi <[email protected]>
2023-10-16cmd: Convert existing long help messages to the new macroTom Rini
- Generally we just drop the #ifdef CONFIG_SYS_LONGHELP and endif lines and use U_BOOT_LONGHELP to declare the same variable name as before - In a few places, either rename the variable to follow convention or introduce the variable as it was being done inline before. Signed-off-by: Tom Rini <[email protected]> Reviewed-by: Simon Glass <[email protected]>
2022-12-10cmd: mtd: check if a block has to be skipped or erasedDario Binacchi
As reported by patch [1], the `mtd erase' command should not erase bad blocks. To force bad block erasing you have to use the `mtd erase.dontskipbad' command. This patch tries to fix the same issue without modifying code taken from the linux kernel, in order to make further upgrades easier. [1] https://lore.kernel.org/all/[email protected]/ Suggested-by: Michael Trimarchi <[email protected]> Co-developed-by: Michael Trimarchi <[email protected]> Signed-off-by: Michael Trimarchi <[email protected]> Co-developed-by: Mikhail Kshevetskiy <[email protected]> Signed-off-by: Mikhail Kshevetskiy <[email protected]> Tested-by: Mikhail Kshevetskiy <[email protected]> Signed-off-by: Dario Binacchi <[email protected]>
2021-08-02global: Convert simple_strtoul() with hex to hextoul()Simon Glass
It is a pain to have to specify the value 16 in each call. Add a new hextoul() function and update the code to use it. Add a proper comment to simple_strtoul() while we are here. Signed-off-by: Simon Glass <[email protected]>
2021-06-24cmd: mtd: expand <name> argument definition in command helpMarek Behún
The <name> argument can now also be MTD's DM device name or OF path. Mention this is command help. Signed-off-by: Marek Behún <[email protected]> Reviewed-by: Miquel Raynal <[email protected]> Tested-by: Patrice Chotard <[email protected]> Reviewed-by: Jagan Teki <[email protected]> Cc: Priyanka Jain <[email protected]> Cc: Simon Glass <[email protected]> Cc: Heiko Schocher <[email protected]> Cc: Patrick Delaunay <[email protected]>
2021-06-24cmd: mtd: print device OF path in listingMarek Behún
Print MTD's device OF path in the output of `mtd list` command. Signed-off-by: Marek Behún <[email protected]> Reviewed-by: Miquel Raynal <[email protected]> Tested-by: Patrice Chotard <[email protected]> Reviewed-by: Jagan Teki <[email protected]> Cc: Priyanka Jain <[email protected]> Cc: Simon Glass <[email protected]> Cc: Heiko Schocher <[email protected]> Cc: Patrick Delaunay <[email protected]>
2020-05-18command: Remove the cmd_tbl_t typedefSimon Glass
We should not use typedefs in U-Boot. They cannot be used as forward declarations which means that header files must include the full header to access them. Drop the typedef and rename the struct to remove the _s suffix which is now not useful. This requires quite a few header-file additions. Signed-off-by: Simon Glass <[email protected]>
2020-02-05dm: core: Require users of devres to include the headerSimon Glass
At present devres.h is included in all files that include dm.h but few make use of it. Also this pulls in linux/compat which adds several more headers. Drop the automatic inclusion and require files to include devres themselves. This provides a good indication of which files use devres. Signed-off-by: Simon Glass <[email protected]> Reviewed-by: Anatolij Gustschin <[email protected]>
2020-01-24cmd: mtd: solve bad block support in erase commandPatrick Delaunay
This patch modify the loop in mtd erase command to erase one by one the blocks in the requested area. It solves issue on "mtd erase" command on nand with existing bad block, the command is interrupted on the first bad block with the trace: "Skipping bad block at 0xffffffffffffffff" In MTD driver (nand/raw), when a bad block is present on the MTD device, the erase_op.fail_addr is not updated and we have the initial value MTD_FAIL_ADDR_UNKNOWN = (ULL)-1. This case seems normal in nand_base.c:nand_erase_nand(), we have the 2 exit cases during the loop: 1/ we have a bad block (nand_block_checkbad) instr->state = MTD_ERASE_FAILED loop interrupted (goto erase_exit) 2/ if block erase failed (status & NAND_STATUS_FAIL) instr->state = MTD_ERASE_FAILED; instr->fail_addr = ((loff_t)page << chip->page_shift); loop interrupted (goto erase_exit) So erase_op.fail_addr can't be used if bad blocks were present in the erased area; we need to use mtd_erase only one block to detect and skip these existing bad blocks (as it is done in nand_util.c). Signed-off-by: Patrick Delaunay <[email protected]> Reviewed-by: Miquel Raynal <[email protected]>
2019-01-18cmd: mtd: fix compilation warning for help when SYS_LONGHELP=nQuentin Schulz
cmd/mtd.c:447:13: warning: ‘mtd_help_text’ defined but not used [-Wunused-variable] static char mtd_help_text[] = ^~~~~~~~~~~~~ When SYS_LONGHELP is not defined. After looking at how other commands work, we should surround the whole help text (even its declaration) with an #ifdef CONFIG_SYS_LONGHELP, since it's compiled out when calling _CMD_HELP[1] on the help text variable argument to U_BOOT_CMD. [1] https://elixir.bootlin.com/u-boot/latest/source/include/command.h#L181 Signed-off-by: Quentin Schulz <[email protected]> Reviewed-by: Miquel Raynal <[email protected]>
2019-01-15cmd: mtd: Use the subcmd infrastructure to declare mtd sub-commandsBoris Brezillon
It's way simpler this way, and we also gain auto-completion support for free (MTD name auto-completion has been added with mtd_name_complete()) Signed-off-by: Boris Brezillon <[email protected]> Reviewed-by: Tom Rini <[email protected]>
2018-10-02cmd: mtd: add 'mtd' commandMiquel Raynal
There should not be a 'nand' command, a 'sf' command and certainly not a new 'spi-nand' command. Write a 'mtd' command instead to manage all MTD devices/partitions at once. This should be the preferred way to access any MTD device. Signed-off-by: Miquel Raynal <[email protected]> Acked-by: Jagan Teki <[email protected]> Reviewed-by: Stefan Roese <[email protected]> Reviewed-by: Boris Brezillon <[email protected]>