summaryrefslogtreecommitdiff
path: root/misc-utils
Commit message (Collapse)AuthorAgeFilesLines
* misc-utils: flashcp: correct casting for percent displayHEADmastercchoux2023-04-241-2/+2
| | | | | | | | | 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>
* misc-utils: mtdpart: document partition of size 0Brandon Maier2022-11-071-1/+1
| | | | | | | | | | | 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>
* misc-utils: flashcp: abort on --partition and --erase-allBrandon Maier2022-11-071-0/+3
| | | | | Signed-off-by: Brandon Maier <brandon.maier@collins.com> Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
* misc-utils: flashcp: verify data in --partitionBrandon Maier2022-11-071-0/+9
| | | | | | | | 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>
* misc-utils: flashcp: fix buffer overflowBrandon Maier2022-11-071-8/+13
| | | | | | | | | | | | | | 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>
* misc-utils: flashcp: simplify loggingBrandon Maier2022-11-071-96/+77
| | | | | | | | | | | | | | | | | 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>
* misc-utils: flashcp: add safe_memeraseBrandon Maier2022-11-071-23/+15
| | | | | Signed-off-by: Brandon Maier <brandon.maier@collins.com> Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
* misc-utils: flashcp: check for lseek errorsBrandon Maier2022-11-071-6/+16
| | | | | | | 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>
* misc-utils: flashcp: add safe_writeBrandon Maier2022-11-071-33/+25
| | | | | | | 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>
* mtd-utils: flash_otp_dump make offset optionalMichael Walle2022-09-271-1/+1
| | | | | | | | | | | | 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>
* fectest.c: fix buffer overrunRalph Siemsen2021-12-061-1/+1
| | | | | | | | | 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>
* misc-utils: flashcp: Add new function that copy only different blocksHarvey Wu2021-06-121-1/+92
| | | | | | | | | | | | - 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>
* mtd-utils: Add flash_otp_eraseMichael Walle2021-06-122-1/+67
| | | | | | | | 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>
* mtd-utils: flash_erase: Add flash erase chipLarisa Ileana Grigore2021-05-051-24/+71
| | | | | | | | | 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>
* Cleanup: Automake: remove single use variablesDavid Oberhollenzer2021-01-201-11/+4
| | | | | | | | | | | | | | 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>
* Remove headers from EXTRA_DISTDavid Oberhollenzer2021-01-201-12/+11
| | | | | | | | | | | 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>
* misc-utils: Add fectest to build systemBastian Germann2020-09-291-1/+4
| | | | | | | | 8f627247f6("mtd-utils: move libmtd source files to lib/ subdirectory") removed fectest.c from the build system 10 years ago. Add it again. Signed-off-by: Bastian Germann <bastiangermann@fishpost.de> Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
* Fix typos found by Debian's lintian toolBastian Germann2020-09-113-5/+5
| | | | | Signed-off-by: Bastian Germann <bastiangermann@fishpost.de> Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
* mtd-utils: Fix potentially unterminated stringsDavid Oberhollenzer2020-02-091-1/+3
| | | | | | | This commit fixes some uses of strncpy that could leave the destination buffer unterminated. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
* mtd-utils: Fix some simple cases of uninitialized value readsDavid Oberhollenzer2020-02-091-2/+1
| | | | | | | | | This patch modifies the internal helpers to read and parse integers from sysfs files by initializing them first and removes turns an obscure "a = open(...) if (a >= 0) {...} if (a == -1) {...}" inside recv_image into a more straight forward if/else branch. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
* mtd-utils: Fix various TOCTOU issuesDavid Oberhollenzer2020-02-092-12/+16
| | | | | | | This patch restructures various code parts that follow the pattern of "stat(x, &sb) ... makes_sense(&sb) ... open(x)". Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
* mtd-utils: Fix printf format specifiers with the wrong typeDavid Oberhollenzer2020-02-091-4/+4
| | | | Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
* mtd-utils: add optional offset parameter to flash_otp_dumpMichael Walle2020-01-131-4/+19
| | | | | | | | | | | There are flashes which have gaps between OTP regions and flashes where the regions don't start at 0 (for example the Winbond 25Q series, which has three 256 bytes OTP regions starting at 0x1000, 0x2000 and 0x3000). At the moment it is impossible to dump the OTP memory. Fix it by passing an optional offset parameter. Signed-off-by: Michael Walle <michael@walle.cc> Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
* mtd_debug: cleanup error handling in flash_to_fileDavid Oberhollenzer2019-11-101-12/+8
| | | | | | | | | | | | | | The existing code had multiple error handling labels and did things like checking if a buffer is not NULL before freeing it. This patch collapses all of this into a single label. We can do this, because the standard guarantees us that it is safe to call free() with a NULL pointer. This also has the side effect of removing the possibility of using the wrong error label and accidentally leaking something. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
* ftl_format: don't leak temporary buffersDavid Oberhollenzer2019-11-101-0/+4
| | | | Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
* ftl_check: don't leak temporary buffersDavid Oberhollenzer2019-11-101-4/+6
| | | | Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
* flashcp: Add option -A/--erase-allAndrij Abyzov2019-10-281-4/+19
| | | | | | | | | | | | Sometimes there's a need to erase the whole device when programming an image, and not just the area under the image itself. Therefore, option -A/--erase-all has been added which erases the whole device before writing the image. Signed-off-by: Andrij Abyzov <drolevar@gmail.com> Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
* mtd-utils: fixes verification percent display in flashcpAndrij Abyzov2019-02-261-1/+1
| | | | | | | | flashcp was always showing 0% progress due to incorrect printf format specifier. Signed-off-by: Andrij Abyzov <drolevar@gmail.com> Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
* mtd-utils: Instead of doing preprocessor magic, just output off_t as long longThorsten Glaser2018-10-025-9/+9
| | | | | | | | | | | | | | | | | | | | | | | Fix warnings abot PRIdoff_t in libmtd.c, in mtd_read (and mtd_write): In file included from ../git/lib/libmtd.c:40:0: ../git/lib/libmtd.c: In function 'mtd_read': ../git/include/common.h:110:18: warning: format '%ld' expects argument of type 'long int', but argument 5 has type 'off_t {aka long long int}' [-Wformat=] ../git/include/common.h:120:2: note: in expansion of macro 'errmsg' errmsg(fmt, ##__VA_ARGS__); \ ^~~~~~ ../git/lib/libmtd.c:1082:10: note: in expansion of macro 'sys_errmsg' return sys_errmsg("cannot seek mtd%d to offset %"PRIdoff_t, ^~~~~~~~~~ /usr/lib/klibc/include/inttypes.h:28:17: note: format string is defined here #define PRId32 "d" Signed-off-by: Thorsten Glaser <tg@mirbsd.org> Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
* Add configure switch to disable compiling/installing lsmtdDavid Oberhollenzer2018-06-181-7/+11
| | | | Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
* Add manpage for lsmtdDavid Oberhollenzer2018-06-183-0/+117
| | | | Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
* Add lsmtd programDavid Oberhollenzer2018-06-184-2/+1091
| | | | | | | | | | | | | | | | This patch adds a program called "lsmtd". The program produces a pretty printed list of the hierarchy of UBI and MTD devices on a system. It tries to imitate the lsblk program from util-linux as closely as possible. A number of command line switches are available to fine tune what information should be exposed and in what output format. The goal is to have a simple way of displaying the complete MTD stack on a system in a human readable form instead of piecing details together from proc files and various UBI utilities. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
* misc-utils: flash_erase: Fix Jffs2 type flash erase problemXiaolei Li2018-04-101-4/+5
| | | | | | | | | | | | Currently, Jffs2 clean marker is not written actually, because the oob write length is set to 0 when do mtd_write(). So, get OOB available size at first, and set the correct clean marker length, then program clean marker to free OOB area. Fixes: d7e86124d55b ("mtd-utils: Support jffs2 flash-erase for large OOB (>32b)") Signed-off-by: Xiaolei Li <xiaolei.li@mediatek.com> Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
* Enable further warning flags, address new warningsDavid Oberhollenzer2017-11-031-2/+0
| | | | | | | | | | | | | | | | mtd_debug: Remove a duplicate if case. MTD_CAP_NANDFLASH has only one flag set (MTD_WRITEABLE). Directly below, we had a check for MTD_WRITEABLE in the else branch which can't possible ever have triggered. Checking for MTD_WRITEABLE in addition to the CAP constants was probably not intended anyway, given the check for the individual flags if all else fails. integck: We already established that "r" is less than the number of elements in the list, so the loop condition doesn't need to check if w is NULL in addition. At least this way, the compiler "gets" that w cannot be NULL below and doesn't issue warnings. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
* Mark or fix switch cases that fall throughDavid Oberhollenzer2017-11-022-0/+3
| | | | | | | | | | | | | | | | | | | Now that C++17 introduced a special fallthrough keyword for explicitly tagging switch cases that are supposed to fall through, newer gcc versions also implement a feature request from 2002 to warn about maybe unwanted fall-throughs in switch cases in other languages (like C). For C code, we can either add a gcc specific attribute at the end of the switch case, or use a special comment that gcc checks for, indicating that the fall-through behaviour is indeed intended. This patch adds a "/* fall-through */" comment at the end of various case blocks to silence gcc warnings and in some cases a break, where fall-through was probably not intended. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
* Add no-return attribute to usage() style functionsDavid Oberhollenzer2017-11-023-5/+3
| | | | | | | | | | | | | | | | | A common pattern in command line processing is having a usage() function that prints out how to use the command line options and then terminates. The function is typically used inside a switch block for command line options like `-h' or unknown options. In a lot of places, the break keyword is omitted, because the function exits anyway. However, this triggers gcc warnings about implicit fall-through. Rather than adding a phony "/* fall-through */" this patch flags the usage() style function with a gcc attribute, indicating that they do not return and removes further superfluous break statements. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
* misc-utils: initialize "ip" in docfdisk to NULLDavid Oberhollenzer2017-10-051-1/+1
| | | | | | | | | | | | Technically it is initializied in the for loop right before being used. From the conditional above, we know that the for loop is executed at least once and the variable is always initialized, but gcc doesn't appear to perform the same reasoning. This patch adds an initialization of the variable for the sake of making the compiler happy. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
* Eliminate warnings about missing prototypesDavid Oberhollenzer2017-06-284-9/+10
| | | | | | | | | This patch eliminates warnings generated by the -Wmissing-prototypes option. With this flag set, we are now forced to have prototypes for all global, exported functions, that have to be made visible to the definitions and we are forced to mark all local functions as static. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
* Move libfec declarations to public header in global include directoryDavid Oberhollenzer2017-06-284-32/+3
| | | | Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
* ftl_format: Use return directly to leave main functionDaniel Wagner2017-06-141-2/+1
| | | | | | | | We can use return with the exit code instead of the sliglty odd exit, return pattern. Signed-off-by: Daniel Wagner <daniel.wagner@siemens.com> Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
* flashcp: Drop exit code definesDaniel Wagner2017-06-141-3/+0
| | | | | | | The EXIT_{FAILURE|SUCCESS} are already defined in stdlib.h. Signed-off-by: Daniel Wagner <daniel.wagner@siemens.com> Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
* Use defines for exit code valuesDaniel Wagner2017-06-141-5/+5
| | | | | | | | Make the usage of exit consist. That is use the pre defined exit values. Signed-off-by: Daniel Wagner <daniel.wagner@siemens.com> Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
* mtd-utils: Support jffs2 flash-erase for large OOB (>32b)Manikandan Ramachandran2017-02-211-34/+4
| | | | | | | | | | | | "flash_erase" fails on nand flash with JFFS2 that has OOB size greater than 32 bytes. "flash_erase" uses "MEMGETOOSEL" to determine OOB size. This ioctl call is obsolete and returns error if OOB size is more than 32 bytes. This patch fixes this issue by using "mtd_write" to update clean-marker instead of mtd_oob_write. This fix is based on the discussion: http://lists.infradead.org/pipermail/linux-mtd/2011-September/037958.html. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
* mtd-utils: serve_image: Use PRIdoff_t as format specifier.Torsten Fleischer2017-02-201-1/+3
| | | | | | | | To be independent on the size of off_t the format specifier determined of common.h should be used instead of PRIu64. Signed-off-by: Torsten Fleischer <torfl6749@gmail.com> Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
* mtd-utils: Correct casting for final status report in flashcpJonathan Fether2016-12-141-2/+2
| | | | | | | | | Add correct casting for filestat.st_size in flashcp.c. While the interim status updates had correct casting from commit 08b243, the final update was not. Signed-off-by: Jonathan Fether <jonf@mds.com> Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
* common: Fix 'unchecked return code' warningsBoris Brezillon2016-12-062-2/+6
| | | | | | | | | | | Several tools are simply not checking return code of functions marked with 'warn_unused_result'. Provide wrappers for the read/write functions to avoid patching old code and providing proper error handling. Fix the remaining ones (calls to fgets() and system()). Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
* Unify version string printingDavid Oberhollenzer2016-11-176-37/+60
| | | | | | | | | | | | | | | | When a program does sophisticated enough command line processing (i.e. getopt), make sure it responds to -V and --version. When a program prints a version string, make sure it uses the common_print_version macro to print out its name, that it is part of mtd-utils and the mtd-utils version from the build system in a fashion similar to common program packages like the GNU coreutils. When a program responds to -V/--version or -h/--help, make sure it reports success exit status. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at> Signed-off-by: Richard Weinberger <richard@nod.at>
* Change build system to autotoolsRichard Weinberger2016-11-171-0/+54
| | | | | | | | | | | | | | | | | | This patch is largely based on Richards original RFC. The major differences to the RFC patch are: - Add missing sumtools & mtdpart targets - Fix name of mkfs.jffs2 target - Add missing subdir-objects option for non-recursive make - Move all automake options to configure.ac - Add manpages to install target - Make XATTR & LZO support configurable - Install binaries to sbin directory like in the old build system - Install flash_erase wrapper script - Add files missing from distribution target Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at> Signed-off-by: Richard Weinberger <richard@nod.at>
* mtd-utils: mtd_debug: check amount of data read.Michal Suchanek2016-08-251-1/+4
| | | | | | | | | | | The kernel refuses to read more data from a MTD device than the device size. However, mtd_debug does not check the amount of data read as returned by read(2) and assumes the requested amount is always read when there is no error. Reading 8M data from a 4M flash chip results in 8M file containing the flash data at the start. Signed-off-by: Michal Suchanek <hramrach@gmail.com> Signed-off-by: Richard Weinberger <richard@nod.at>
* fix build warnings w/newer glibc & _BSD_SOURCEMike Frysinger2016-04-181-0/+1
| | | | | | | | | The _BSD_SOURCE define has been deprecated for a while now. Instead, code should be defining _DEFAULT_SOURCE. By defining both, it'll work with both new & old versions warning-free. Signed-off-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Brian Norris <computersforpeace@gmail.com>