From: Hauke Mehrtens Date: Sat, 25 Oct 2025 12:40:21 +0000 (+0200) Subject: tools: mtd-utils: Update to version 2.3.0 X-Git-Url: http://git.openwrt.org/?a=commitdiff_plain;h=52c0e90bdc8a6b487a322b8180b65d3b69fbb47b;p=openwrt%2Fstaging%2Fblocktrron.git tools: mtd-utils: Update to version 2.3.0 See announcement mail for list of new features: https://lists.infradead.org/pipermail/linux-mtd/2025-February/108248.html The removed patch 100-sscanf_fix.patch was applied upstream, see: https://git.infradead.org/?p=mtd-utils.git;a=commitdiff;h=cba2d7875328b05a4a76f619de0ce7050f2df971 The patch 110-portability.patch was manually adapted. Cherry pick some upstream commits which fix build problems in some situations. Link: https://github.com/openwrt/openwrt/pull/20540 Signed-off-by: Hauke Mehrtens --- diff --git a/tools/mtd-utils/Makefile b/tools/mtd-utils/Makefile index cf7081fb5a..b94b690dab 100644 --- a/tools/mtd-utils/Makefile +++ b/tools/mtd-utils/Makefile @@ -7,12 +7,12 @@ include $(TOPDIR)/rules.mk PKG_NAME:=mtd-utils -PKG_VERSION:=2.2.1 +PKG_VERSION:=2.3.0 PKG_RELEASE:=1 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2 PKG_SOURCE_URL:=https://infraroot.at/pub/mtd/ -PKG_HASH:=f7ae20b2eb79ee83441468f0b99d897024cd96ff853eea59106fb1952065c803 +PKG_HASH:=2db102908b232406ccb20719c0f43b61196aef4534493419fbf98a273c598c10 PKG_CPE_ID:=cpe:/a:mtd-utils_project:mtd-utils PKG_FIXUP:=autoreconf diff --git a/tools/mtd-utils/patches/001-ubifs-utils-link-libmissing.a-in-case-execinfo.h-isn.patch b/tools/mtd-utils/patches/001-ubifs-utils-link-libmissing.a-in-case-execinfo.h-isn.patch new file mode 100644 index 0000000000..e43e34f533 --- /dev/null +++ b/tools/mtd-utils/patches/001-ubifs-utils-link-libmissing.a-in-case-execinfo.h-isn.patch @@ -0,0 +1,57 @@ +From 8a83b306db64d6f60186d4396b0b770163b85b6e Mon Sep 17 00:00:00 2001 +From: Ross Burton +Date: Wed, 26 Feb 2025 18:24:00 +0000 +Subject: ubifs-utils: link libmissing.a in case execinfo.h isn't present + +On musl execinfo.h doesn't exist, but ubifs-utils uses backtrace() when +reporting errors. This results in build failures under musl. + +Handily, libmissing.a already exists with a stub implementation of +backtrace(). + +Guard the execinfo.h include and if it isn't available instead include +libmissing.h, and link to libmissing.a to provide backtrace() if needed. + +Signed-off-by: Ross Burton +Reviewed-by: Zhihao Cheng +Signed-off-by: David Oberhollenzer +--- + ubifs-utils/Makemodule.am | 4 ++-- + ubifs-utils/common/defs.h | 5 ++++- + 2 files changed, 6 insertions(+), 3 deletions(-) + +--- a/ubifs-utils/Makemodule.am ++++ b/ubifs-utils/Makemodule.am +@@ -72,7 +72,7 @@ mkfs_ubifs_SOURCES = \ + ubifs-utils/mkfs.ubifs/mkfs.ubifs.c + + mkfs_ubifs_LDADD = libmtd.a libubi.a $(ZLIB_LIBS) $(LZO_LIBS) $(ZSTD_LIBS) $(UUID_LIBS) $(LIBSELINUX_LIBS) $(OPENSSL_LIBS) \ +- $(DUMP_STACK_LD) $(ASAN_LIBS) -lm -lpthread ++ $(DUMP_STACK_LD) $(ASAN_LIBS) -lm -lpthread libmissing.a + mkfs_ubifs_CPPFLAGS = $(AM_CPPFLAGS) $(ZLIB_CFLAGS) $(LZO_CFLAGS) $(ZSTD_CFLAGS) $(UUID_CFLAGS) $(LIBSELINUX_CFLAGS) \ + -I$(top_srcdir)/ubi-utils/include -I$(top_srcdir)/ubifs-utils/common -I $(top_srcdir)/ubifs-utils/libubifs + +@@ -90,7 +90,7 @@ fsck_ubifs_SOURCES = \ + ubifs-utils/fsck.ubifs/handle_disconnected.c + + fsck_ubifs_LDADD = libmtd.a libubi.a $(ZLIB_LIBS) $(LZO_LIBS) $(ZSTD_LIBS) $(UUID_LIBS) $(LIBSELINUX_LIBS) $(OPENSSL_LIBS) \ +- $(DUMP_STACK_LD) $(ASAN_LIBS) -lm -lpthread ++ $(DUMP_STACK_LD) $(ASAN_LIBS) -lm -lpthread libmissing.a + fsck_ubifs_CPPFLAGS = $(AM_CPPFLAGS) $(ZLIB_CFLAGS) $(LZO_CFLAGS) $(ZSTD_CFLAGS) $(UUID_CFLAGS) $(LIBSELINUX_CFLAGS) \ + -I$(top_srcdir)/ubi-utils/include -I$(top_srcdir)/ubifs-utils/common -I $(top_srcdir)/ubifs-utils/libubifs \ + -I$(top_srcdir)/ubifs-utils/fsck.ubifs +--- a/ubifs-utils/common/defs.h ++++ b/ubifs-utils/common/defs.h +@@ -13,8 +13,11 @@ + #include + #include + #include ++#if HAVE_EXECINFO_H + #include +- ++#else ++#include "libmissing.h" ++#endif + #include "ubifs.h" + + /* common.h requires the PROGRAM_NAME macro */ diff --git a/tools/mtd-utils/patches/002-ubifs-utils-common-fix-memory-leak-in-devtable.c.patch b/tools/mtd-utils/patches/002-ubifs-utils-common-fix-memory-leak-in-devtable.c.patch new file mode 100644 index 0000000000..4daaf45306 --- /dev/null +++ b/tools/mtd-utils/patches/002-ubifs-utils-common-fix-memory-leak-in-devtable.c.patch @@ -0,0 +1,32 @@ +From 2669111e3c60b8e146c174db5d2e7e9991f3dd87 Mon Sep 17 00:00:00 2001 +From: AntonMoryakov +Date: Thu, 24 Apr 2025 21:19:22 +0300 +Subject: ubifs-utils: common: fix memory leak in devtable.c + +Report of the static analyzer: +Dynamic memory, referenced by 'line', is allocated at devtable.c:356 +by calling function 'getline' and lost at devtable.c:388. +(line: while (getline(&line, &len, f) != -1) {) + +Correct explained: +Now line is freed in any exit scenario via out_close which eliminates this error. + +Triggers found by static analyzer Svace. + +Signed-off-by: Anton Moryakov +Signed-off-by: David Oberhollenzer +--- + ubifs-utils/common/devtable.c | 1 + + 1 file changed, 1 insertion(+) + +--- a/ubifs-utils/common/devtable.c ++++ b/ubifs-utils/common/devtable.c +@@ -392,6 +392,7 @@ int parse_devtable(const char *tbl_file) + + out_close: + fclose(f); ++ free(line); + free_devtable_info(); + return -1; + } diff --git a/tools/mtd-utils/patches/004-Improve-check-for-GCC-compiler-version.patch b/tools/mtd-utils/patches/004-Improve-check-for-GCC-compiler-version.patch new file mode 100644 index 0000000000..5b1870b1c1 --- /dev/null +++ b/tools/mtd-utils/patches/004-Improve-check-for-GCC-compiler-version.patch @@ -0,0 +1,32 @@ +From ac0ab65ebcd7b11739986b81343457469fbb43b0 Mon Sep 17 00:00:00 2001 +From: Khem Raj +Date: Sat, 22 Mar 2025 21:01:32 -0700 +Subject: Improve check for GCC compiler version + +When using unreleased compiler has version like +15.0.1 and that test fails because __GNUC_MINOR__ < 1 +becomes true, therefore check for full version string +which is more rubust. + +Signed-off-by: Khem Raj +Signed-off-by: David Oberhollenzer +--- + ubifs-utils/common/atomic.h | 6 +++++- + 1 file changed, 5 insertions(+), 1 deletion(-) + +--- a/ubifs-utils/common/atomic.h ++++ b/ubifs-utils/common/atomic.h +@@ -2,8 +2,12 @@ + #ifndef __ATOMIC_H__ + #define __ATOMIC_H__ + ++#define GCC_VERSION (__GNUC__ * 10000 \ ++ + __GNUC_MINOR__ * 100 \ ++ + __GNUC_PATCHLEVEL__) ++ + /* Check GCC version, just to be safe */ +-#if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC_MINOR__ < 1) ++#if GCC_VERSION < 40100 + # error atomic.h works only with GCC newer than version 4.1 + #endif /* GNUC >= 4.1 */ + diff --git a/tools/mtd-utils/patches/005-ubifs-utils-ubifs.h-Include-fcntl.h.patch b/tools/mtd-utils/patches/005-ubifs-utils-ubifs.h-Include-fcntl.h.patch new file mode 100644 index 0000000000..0bba423d7d --- /dev/null +++ b/tools/mtd-utils/patches/005-ubifs-utils-ubifs.h-Include-fcntl.h.patch @@ -0,0 +1,45 @@ +From 12bc9ad824bd8f18a5ec9c7154ad2374cf8c7ae3 Mon Sep 17 00:00:00 2001 +From: Fabio Estevam +Date: Wed, 19 Feb 2025 10:02:41 -0300 +Subject: ubifs-utils: ubifs.h: Include + +Include the header file to fix the following error +when building with musl: + +| In file included from ../git/ubifs-utils/common/compr.c:42: +| ../git/ubifs-utils/libubifs/ubifs.h:313:9: error: unknown type name 'loff_t'; did you mean 'off_t'? +| 313 | loff_t ui_size; +| | ^~~~~~ +| | off_t +| ../git/ubifs-utils/libubifs/ubifs.h:1341:9: error: unknown type name 'loff_t'; did you mean 'off_t'? +| 1341 | loff_t i_size; +| | ^~~~~~ +| | off_t +| ../git/ubifs-utils/libubifs/ubifs.h:1342:9: error: unknown type name 'loff_t'; did you mean 'off_t'? +| 1342 | loff_t d_size; +| | ^~~~~~ +| | off_t +| ../git/ubifs-utils/libubifs/ubifs.h:1899:44: error: unknown type name 'loff_t'; did you mean 'off_t'? +| 1899 | int deletion, loff_t new_size); +| | ^~~~~~ +| | off_t +| make: *** [Makefile:4878: ubifs-utils/common/mkfs_ubifs-compr.o] Error 1 + +Signed-off-by: Fabio Estevam +Reviewed-by: Zhihao Cheng +Reviewed-by: Khem Raj +Signed-off-by: David Oberhollenzer +--- + ubifs-utils/libubifs/ubifs.h | 1 + + 1 file changed, 1 insertion(+) + +--- a/ubifs-utils/libubifs/ubifs.h ++++ b/ubifs-utils/libubifs/ubifs.h +@@ -11,6 +11,7 @@ + #ifndef __UBIFS_H__ + #define __UBIFS_H__ + ++#include + #include + + #include "linux_types.h" diff --git a/tools/mtd-utils/patches/006-ubifs-utils-journal-Include-sys-stat.h.patch b/tools/mtd-utils/patches/006-ubifs-utils-journal-Include-sys-stat.h.patch new file mode 100644 index 0000000000..b43cef8119 --- /dev/null +++ b/tools/mtd-utils/patches/006-ubifs-utils-journal-Include-sys-stat.h.patch @@ -0,0 +1,33 @@ +From 173f9714c8da1d685bfa951d43b9310d16bbab3c Mon Sep 17 00:00:00 2001 +From: Fabio Estevam +Date: Wed, 19 Feb 2025 10:02:42 -0300 +Subject: ubifs-utils: journal: Include + +Include the header file to fix the following error +when building with musl: + +| ../git/ubifs-utils/libubifs/journal.c: In function 'ubifs_get_dent_type': +| ../git/ubifs-utils/libubifs/journal.c:414:24: error: 'S_IFMT' undeclared (first use in this function) +| 414 | switch (mode & S_IFMT) { +| | ^~~~~~ +| ../git/ubifs-utils/libubifs/journal.c:414:24: note: each undeclared identifier is reported only once for each function it appears in +| ../git/ubifs-utils/libubifs/journal.c:415:14: error: 'S_IFREG' undeclared (first use in this function) +| 415 | case S_IFREG: + +Signed-off-by: Fabio Estevam +Reviewed-by: Zhihao Cheng +Signed-off-by: David Oberhollenzer +--- + ubifs-utils/libubifs/journal.c | 1 + + 1 file changed, 1 insertion(+) + +--- a/ubifs-utils/libubifs/journal.c ++++ b/ubifs-utils/libubifs/journal.c +@@ -46,6 +46,7 @@ + * all the nodes. + */ + ++#include + #include "bitops.h" + #include "kmem.h" + #include "ubifs.h" diff --git a/tools/mtd-utils/patches/007-ubifs-utils-extract_files-Include-linux-limits.h.patch b/tools/mtd-utils/patches/007-ubifs-utils-extract_files-Include-linux-limits.h.patch new file mode 100644 index 0000000000..1e99ab6f94 --- /dev/null +++ b/tools/mtd-utils/patches/007-ubifs-utils-extract_files-Include-linux-limits.h.patch @@ -0,0 +1,33 @@ +From 77981a2888c711268b0e7f32af6af159c2288e23 Mon Sep 17 00:00:00 2001 +From: Fabio Estevam +Date: Wed, 19 Feb 2025 10:02:44 -0300 +Subject: ubifs-utils: extract_files: Include + +Include to fix the following build error when building +with musl: + +| ../git/ubifs-utils/fsck.ubifs/extract_files.c: In function 'parse_ino_node': +| ../git/ubifs-utils/fsck.ubifs/extract_files.c:144:47: error: 'XATTR_LIST_MAX' undeclared (first use in this function) +| 144 | if (ino_node->xnms + ino_node->xcnt > XATTR_LIST_MAX) { +| | ^~~~~~~~~~~~~~ +| ../git/ubifs-utils/fsck.ubifs/extract_files.c:144:47: note: each undeclared identifier is reported only once for each function it appears in +| make: *** [Makefile:4374: ubifs-utils/fsck.ubifs/fsck_ubifs-extract_files.o] Error 1 + +Signed-off-by: Fabio Estevam +Reviewed-by: Zhihao Cheng +Signed-off-by: David Oberhollenzer +--- + ubifs-utils/fsck.ubifs/extract_files.c | 2 ++ + 1 file changed, 2 insertions(+) + +--- a/ubifs-utils/fsck.ubifs/extract_files.c ++++ b/ubifs-utils/fsck.ubifs/extract_files.c +@@ -10,6 +10,8 @@ + #include + #include + ++#include ++ + #include "linux_err.h" + #include "bitops.h" + #include "kmem.h" diff --git a/tools/mtd-utils/patches/100-sscanf_fix.patch b/tools/mtd-utils/patches/100-sscanf_fix.patch deleted file mode 100644 index a36be078d5..0000000000 --- a/tools/mtd-utils/patches/100-sscanf_fix.patch +++ /dev/null @@ -1,11 +0,0 @@ ---- a/jffsX-utils/mkfs.jffs2.c -+++ b/jffsX-utils/mkfs.jffs2.c -@@ -428,7 +428,7 @@ static int interpret_table_entry(struct - - if (sscanf (line, "%" SCANF_PREFIX "s %c %lo %lu %lu %lu %lu %lu %lu %lu", - SCANF_STRING(name), &type, &mode, &uid, &gid, &major, &minor, -- &start, &increment, &count) < 0) -+ &start, &increment, &count) < 10) - { - return 1; - } diff --git a/tools/mtd-utils/patches/110-portability.patch b/tools/mtd-utils/patches/110-portability.patch index cf5f0c8d8e..cc4076acb1 100644 --- a/tools/mtd-utils/patches/110-portability.patch +++ b/tools/mtd-utils/patches/110-portability.patch @@ -48,12 +48,54 @@ /* The version of UBI images supported by this implementation */ #define UBI_VERSION 1 ---- a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.h -+++ b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.h -@@ -32,7 +32,17 @@ - #include - #include - #include +--- a/ubifs-utils/common/compiler_attributes.h ++++ b/ubifs-utils/common/compiler_attributes.h +@@ -1,6 +1,8 @@ + #ifndef __COMPILER_ATTRIBUTES_H__ + #define __COMPILER_ATTRIBUTES_H__ + ++#include ++ + #if __has_attribute(__fallthrough__) + #define fallthrough __attribute__((__fallthrough__)) + #else +@@ -11,6 +13,7 @@ + #define __unused __attribute__((__unused__)) + #define __const __attribute__((__const__)) + #define __must_check __attribute__((__warn_unused_result__)) ++#define __always_inline inline __attribute__((__always_inline__)) + #ifndef __force + #define __force + #endif +--- a/ubifs-utils/common/linux_types.h ++++ b/ubifs-utils/common/linux_types.h +@@ -14,7 +14,11 @@ typedef __u16 u16; + typedef __u32 u32; + typedef __u64 u64; + ++#ifdef __linux__ + typedef __s64 time64_t; ++#else ++typedef int64_t time64_t; ++#endif + + struct qstr { + const char *name; +@@ -89,4 +93,8 @@ static inline int int_log2(unsigned int + #undef PAGE_SHIFT + #define PAGE_SHIFT (int_log2(PAGE_SIZE)) + ++#ifndef EUCLEAN ++#define EUCLEAN 117 /* Structure needs cleaning */ ++#endif ++ + #endif +--- a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c ++++ b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c +@@ -29,7 +29,17 @@ + #include + #include + #include +#ifdef __linux__ #include +# if defined(__x86_64__) && defined(__ILP32__) @@ -65,12 +107,10 @@ +# endif +# define llseek lseek +#endif - - #include #include ---- a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c -+++ b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c -@@ -1568,6 +1568,7 @@ static int add_inode(struct stat *st, in + #include + #include +@@ -1459,6 +1469,7 @@ static int add_inode(struct stat *st, in if (c->default_compr != UBIFS_COMPR_NONE) use_flags |= UBIFS_COMPR_FL; @@ -78,33 +118,33 @@ if (flags & FS_COMPR_FL) use_flags |= UBIFS_COMPR_FL; if (flags & FS_SYNC_FL) -@@ -1580,6 +1581,7 @@ static int add_inode(struct stat *st, in +@@ -1471,6 +1482,7 @@ static int add_inode(struct stat *st, in use_flags |= UBIFS_DIRSYNC_FL; if (fctx) use_flags |= UBIFS_CRYPT_FL; +#endif memset(ino, 0, UBIFS_INO_NODE_SZ); - ino_key_init(&key, inum); -@@ -1665,7 +1667,9 @@ static int add_dir_inode(const char *pat + ino_key_init(c, &key, inum); +@@ -1556,7 +1568,9 @@ static int add_dir_inode(const char *pat fd = dirfd(dir); if (fd == -1) - return sys_err_msg("dirfd failed"); + return sys_errmsg("dirfd failed"); +#ifndef NO_NATIVE_SUPPORT if (ioctl(fd, FS_IOC_GETFLAGS, &flags) == -1) +#endif flags = 0; } -@@ -1878,6 +1882,7 @@ static int add_file(const char *path_nam +@@ -1772,6 +1786,7 @@ static int add_file(const char *path_nam dn->ch.node_type = UBIFS_DATA_NODE; - key_write(&key, &dn->key); + key_write(c, &key, &dn->key); out_len = NODE_BUFFER_SIZE - UBIFS_DATA_NODE_SZ; +#ifndef NO_NATIVE_SUPPORT if (c->default_compr == UBIFS_COMPR_NONE && !c->encrypted && (flags & FS_COMPR_FL)) #ifdef WITH_LZO -@@ -1888,6 +1893,7 @@ static int add_file(const char *path_nam +@@ -1782,6 +1797,7 @@ static int add_file(const char *path_nam use_compr = UBIFS_COMPR_NONE; #endif else @@ -112,39 +152,16 @@ use_compr = c->default_compr; compr_type = compress_data(buf, bytes_read, &dn->data, &out_len, use_compr); -@@ -1947,7 +1953,9 @@ static int add_non_dir(const char *path_ +@@ -1841,7 +1857,9 @@ static int add_non_dir(const char *path_ if (fd == -1) - return sys_err_msg("failed to open file '%s'", + return sys_errmsg("failed to open file '%s'", path_name); +#ifndef NO_NATIVE_SUPPORT if (ioctl(fd, FS_IOC_GETFLAGS, &flags) == -1) +#endif flags = 0; if (close(fd) == -1) - return sys_err_msg("failed to close file '%s'", ---- a/ubifs-utils/mkfs.ubifs/devtable.c -+++ b/ubifs-utils/mkfs.ubifs/devtable.c -@@ -135,6 +135,7 @@ static int interpret_table_entry(const c - unsigned int mode = 0755, uid = 0, gid = 0, major = 0, minor = 0; - unsigned int start = 0, increment = 0, count = 0; - -+ buf[1023] = 0; - if (sscanf(line, "%1023s %c %o %u %u %u %u %u %u %u", - buf, &type, &mode, &uid, &gid, &major, &minor, - &start, &increment, &count) < 0) -@@ -145,10 +146,10 @@ static int interpret_table_entry(const c - buf, type, mode, uid, gid, major, minor, start, - increment, count); - -- len = strnlen(buf, 1024); -+ len = strlen(buf); - if (len == 0) - return err_msg("empty path"); -- if (len == 1024) -+ if (len == 1023) - return err_msg("too long path"); - - if (buf[0] != '/') + return sys_errmsg("failed to close file '%s'", --- a/include/common.h +++ b/include/common.h @@ -26,7 +26,6 @@ @@ -155,9 +172,9 @@ #include #include #include ---- a/include/mtd/ubifs-media.h -+++ b/include/mtd/ubifs-media.h -@@ -33,7 +33,15 @@ +--- a/ubifs-utils/libubifs/ubifs-media.h ++++ b/ubifs-utils/libubifs/ubifs-media.h +@@ -33,7 +33,11 @@ #ifndef __UBIFS_MEDIA_H__ #define __UBIFS_MEDIA_H__ @@ -165,10 +182,6 @@ #include +#else +#include -+typedef uint8_t __u8; -+typedef uint16_t __be16; -+typedef uint32_t __be32; -+typedef uint64_t __be64; +#endif /* UBIFS node magic number (must not have the padding byte first or last) */ diff --git a/tools/mtd-utils/patches/130-lzma_jffs2.patch b/tools/mtd-utils/patches/130-lzma_jffs2.patch index b03265a380..f4981cce0e 100644 --- a/tools/mtd-utils/patches/130-lzma_jffs2.patch +++ b/tools/mtd-utils/patches/130-lzma_jffs2.patch @@ -5055,7 +5055,7 @@ AC_ARG_WITH([selinux], [AS_HELP_STRING([--with-selinux], [Support for selinux extended attributes])], -@@ -269,6 +273,7 @@ fi +@@ -283,6 +287,7 @@ fi AM_CONDITIONAL([WITH_LZO], [test "x$with_lzo" = "xyes"]) AM_CONDITIONAL([WITH_ZLIB], [test "x$with_zlib" = "xyes"]) AM_CONDITIONAL([WITH_ZSTD], [test "x$with_zstd" = "xyes"]) @@ -5063,7 +5063,7 @@ AM_CONDITIONAL([WITH_XATTR], [test "x$with_xattr" = "xyes"]) AM_CONDITIONAL([WITH_SELINUX], [test "x$with_selinux" = "xyes"]) AM_CONDITIONAL([WITH_CRYPTO], [test "x$with_crypto" = "xyes"]) -@@ -313,6 +318,7 @@ AC_MSG_RESULT([ +@@ -339,6 +344,7 @@ AC_MSG_RESULT([ lzo support: ${with_lzo} zlib support: ${with_zlib} zstd support: ${with_zstd}