aboutsummaryrefslogtreecommitdiffstats
path: root/tools/mtd-utils
diff options
context:
space:
mode:
Diffstat (limited to 'tools/mtd-utils')
-rw-r--r--tools/mtd-utils/Makefile57
-rw-r--r--tools/mtd-utils/patches/100-optional_lzo.patch0
-rw-r--r--tools/mtd-utils/patches/100-sscanf_fix.patch11
-rw-r--r--tools/mtd-utils/patches/101-ubifs-optional_lzo.patch0
-rw-r--r--tools/mtd-utils/patches/110-portability.patch91
-rw-r--r--tools/mtd-utils/patches/120-cygwin_fixes.patch457
-rw-r--r--tools/mtd-utils/patches/130-lzma_jffs2.patch144
-rw-r--r--tools/mtd-utils/patches/131-fix_lib_compile.patch11
-rw-r--r--tools/mtd-utils/patches/133-error-fix.patch20
-rw-r--r--tools/mtd-utils/patches/134-freebsd_loff_t.patch13
-rw-r--r--tools/mtd-utils/patches/135-mkubifs_optional_lzo.patch119
-rw-r--r--tools/mtd-utils/patches/136-mkfs.ubifs-xz-support.patch404
-rw-r--r--tools/mtd-utils/patches/200-libubigen-add-ubigen_write_terminator-function.patch89
-rw-r--r--tools/mtd-utils/patches/201-ubinize-add-terminator-support.patch68
-rw-r--r--tools/mtd-utils/patches/320-mkfs.jffs2-SOURCE_DATE_EPOCH.patch60
15 files changed, 389 insertions, 1155 deletions
diff --git a/tools/mtd-utils/Makefile b/tools/mtd-utils/Makefile
index 4763aad1918..ff000b99e3a 100644
--- a/tools/mtd-utils/Makefile
+++ b/tools/mtd-utils/Makefile
@@ -1,5 +1,5 @@
#
-# Copyright (C) 2006-2010 OpenWrt.org
+# Copyright (C) 2006-2015 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
@@ -7,52 +7,41 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=mtd-utils
-PKG_VERSION:=1.4.5
+PKG_VERSION:=2.0.2
-PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
-PKG_SOURCE_URL:=git://git.infradead.org/mtd-utils.git
-PKG_SOURCE_PROTO:=git
-PKG_SOURCE_VERSION:=5319b84974fcb71504aed2d1b8285e9c0a4a4bb8
-PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
-PKG_CAT:=zcat
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
+PKG_SOURCE_URL:=ftp://ftp.infradead.org/pub/mtd-utils/
+PKG_HASH:=fb3de61be8e932abb424e8ea3c30298f553d5f970ad158a737bb303bbf9660b8
-HOST_BUILD_DIR:=$(BUILD_DIR_HOST)/$(PKG_NAME)-$(PKG_VERSION)
+PKG_FIXUP:=autoreconf
include $(INCLUDE_DIR)/host-build.mk
-HOST_CFLAGS += -I$(STAGING_DIR_HOST)/include/e2fsprogs
-CFLAGS := $(HOST_CFLAGS) -I$(HOST_BUILD_DIR)/include -L$(HOST_BUILD_DIR) -L$(STAGING_DIR_HOST)/lib -DNO_NATIVE_SUPPORT
ifneq ($(HOST_OS),Linux)
-CFLAGS += -Dloff_t=off_t -D__BYTE_ORDER=BYTE_ORDER -include getline.h -include endian.h -I$(CURDIR)/include -include fls.h
+ HOST_CFLAGS += \
+ -I$(CURDIR)/include \
+ -Dloff_t=off_t \
+ -D__BYTE_ORDER=BYTE_ORDER \
+ -include endian.h \
+ -DNO_NATIVE_SUPPORT \
+ -include fls.h
endif
-MTD_MAKEOPTS = \
- CFLAGS="$(CFLAGS)" \
- WITHOUT_LZO=1 WITHOUT_XATTR=1 \
- LZMA_STATIC_LIB="$(STAGING_DIR_HOST)/lib/liblzma.a" \
- SUBDIRS="" \
- BUILDDIR="$(HOST_BUILD_DIR)"
+HOST_CONFIGURE_VARS+= \
+ UUID_CFLAGS="-I$(STAGING_DIR_HOST)/include/e2fsprogs/uuid"
-define Host/Compile
- $(MAKE) -C $(HOST_BUILD_DIR)/lib \
- $(MTD_MAKEOPTS) \
- TARGETS="libmtd.a libcrc32.a" \
- LIBS="libmtd libcrc32"
- $(MAKE) -C $(HOST_BUILD_DIR) \
- $(MTD_MAKEOPTS) \
- TARGETS=mkfs.jffs2
- $(MAKE) -C $(HOST_BUILD_DIR)/ubi-utils \
- $(MTD_MAKEOPTS) \
- TARGETS=ubinize
- $(MAKE) -C $(HOST_BUILD_DIR)/mkfs.ubifs \
- $(MTD_MAKEOPTS) \
- BUILDDIR="$(HOST_BUILD_DIR)/mkfs.ubifs"
-endef
+HOST_CONFIGURE_ARGS+= \
+ --disable-tests \
+ --without-xattr \
+ --without-lzo
+
+HOST_MAKE_FLAGS += \
+ PROGRAMS="mkfs.jffs2 ubinize mkfs.ubifs"
define Host/Install
$(CP) \
$(HOST_BUILD_DIR)/mkfs.jffs2 \
- $(HOST_BUILD_DIR)/mkfs.ubifs/mkfs.ubifs \
+ $(HOST_BUILD_DIR)/mkfs.ubifs \
$(HOST_BUILD_DIR)/ubinize \
$(STAGING_DIR_HOST)/bin/
endef
diff --git a/tools/mtd-utils/patches/100-optional_lzo.patch b/tools/mtd-utils/patches/100-optional_lzo.patch
deleted file mode 100644
index e69de29bb2d..00000000000
--- a/tools/mtd-utils/patches/100-optional_lzo.patch
+++ /dev/null
diff --git a/tools/mtd-utils/patches/100-sscanf_fix.patch b/tools/mtd-utils/patches/100-sscanf_fix.patch
new file mode 100644
index 00000000000..ae6f86722b9
--- /dev/null
+++ b/tools/mtd-utils/patches/100-sscanf_fix.patch
@@ -0,0 +1,11 @@
+--- a/jffsX-utils/mkfs.jffs2.c
++++ b/jffsX-utils/mkfs.jffs2.c
+@@ -427,7 +427,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/101-ubifs-optional_lzo.patch b/tools/mtd-utils/patches/101-ubifs-optional_lzo.patch
deleted file mode 100644
index e69de29bb2d..00000000000
--- a/tools/mtd-utils/patches/101-ubifs-optional_lzo.patch
+++ /dev/null
diff --git a/tools/mtd-utils/patches/110-portability.patch b/tools/mtd-utils/patches/110-portability.patch
index 5bf1b95bc21..a2942270d72 100644
--- a/tools/mtd-utils/patches/110-portability.patch
+++ b/tools/mtd-utils/patches/110-portability.patch
@@ -1,5 +1,5 @@
---- a/compr_lzo.c
-+++ b/compr_lzo.c
+--- a/jffsX-utils/compr_lzo.c
++++ b/jffsX-utils/compr_lzo.c
@@ -26,7 +26,6 @@
#include <string.h>
@@ -8,8 +8,8 @@
#include <linux/jffs2.h>
#include <lzo/lzo1x.h>
#include "compr.h"
---- a/compr_zlib.c
-+++ b/compr_zlib.c
+--- a/jffsX-utils/compr_zlib.c
++++ b/jffsX-utils/compr_zlib.c
@@ -39,7 +39,6 @@
#include <zlib.h>
#undef crc32
@@ -18,8 +18,8 @@
#include <linux/jffs2.h>
#include "common.h"
#include "compr.h"
---- a/rbtree.h
-+++ b/rbtree.h
+--- a/jffsX-utils/rbtree.h
++++ b/jffsX-utils/rbtree.h
@@ -94,8 +94,7 @@ static inline struct page * rb_insert_pa
#ifndef _LINUX_RBTREE_H
#define _LINUX_RBTREE_H
@@ -48,14 +48,17 @@
/* The version of UBI images supported by this implementation */
#define UBI_VERSION 1
---- a/mkfs.ubifs/mkfs.ubifs.h
-+++ b/mkfs.ubifs/mkfs.ubifs.h
-@@ -34,7 +34,14 @@
+--- a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.h
++++ b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.h
+@@ -32,7 +32,17 @@
#include <endian.h>
#include <byteswap.h>
#include <linux/types.h>
+#ifdef __linux__
#include <linux/fs.h>
++# if defined(__x86_64__) && defined(__ILP32__)
++# define llseek lseek64
++# endif
+#else
+# ifndef O_LARGEFILE
+# define O_LARGEFILE 0
@@ -65,20 +68,9 @@
#include <getopt.h>
#include <sys/types.h>
---- a/mkfs.ubifs/mkfs.ubifs.c
-+++ b/mkfs.ubifs/mkfs.ubifs.c
-@@ -821,8 +821,8 @@ int write_leb(int lnum, int len, void *b
- if (ubi_leb_change_start(ubi, out_fd, lnum, c->leb_size, dtype))
- return sys_err_msg("ubi_leb_change_start failed");
-
-- if (lseek64(out_fd, pos, SEEK_SET) != pos)
-- return sys_err_msg("lseek64 failed seeking %lld",
-+ if (llseek(out_fd, pos, SEEK_SET) != pos)
-+ return sys_err_msg("llseek failed seeking %lld",
- (long long)pos);
-
- if (write(out_fd, buf, c->leb_size) != c->leb_size)
-@@ -1079,6 +1079,7 @@ static int add_inode_with_data(struct st
+--- a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c
++++ b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c
+@@ -1219,6 +1219,7 @@ static int add_inode(struct stat *st, in
if (c->default_compr != UBIFS_COMPR_NONE)
use_flags |= UBIFS_COMPR_FL;
@@ -86,7 +78,7 @@
if (flags & FS_COMPR_FL)
use_flags |= UBIFS_COMPR_FL;
if (flags & FS_SYNC_FL)
-@@ -1089,6 +1090,7 @@ static int add_inode_with_data(struct st
+@@ -1229,6 +1230,7 @@ static int add_inode(struct stat *st, in
use_flags |= UBIFS_APPEND_FL;
if (flags & FS_DIRSYNC_FL && S_ISDIR(st->st_mode))
use_flags |= UBIFS_DIRSYNC_FL;
@@ -94,7 +86,7 @@
memset(ino, 0, UBIFS_INO_NODE_SZ);
-@@ -1158,7 +1160,9 @@ static int add_dir_inode(DIR *dir, ino_t
+@@ -1293,7 +1295,9 @@ static int add_dir_inode(const char *pat
fd = dirfd(dir);
if (fd == -1)
return sys_err_msg("dirfd failed");
@@ -104,20 +96,23 @@
flags = 0;
}
-@@ -1343,10 +1347,12 @@ static int add_file(const char *path_nam
+@@ -1476,6 +1480,7 @@ static int add_file(const char *path_nam
key_write(&key, &dn->key);
dn->size = cpu_to_le32(bytes_read);
out_len = NODE_BUFFER_SIZE - UBIFS_DATA_NODE_SZ;
+#ifndef NO_NATIVE_SUPPORT
if (c->default_compr == UBIFS_COMPR_NONE &&
(flags & FS_COMPR_FL))
+ #ifdef WITHOUT_LZO
+@@ -1484,6 +1489,7 @@ static int add_file(const char *path_nam
use_compr = UBIFS_COMPR_LZO;
+ #endif
else
+#endif
use_compr = c->default_compr;
compr_type = compress_data(buf, bytes_read, &dn->data,
&out_len, use_compr);
-@@ -1388,7 +1394,9 @@ static int add_non_dir(const char *path_
+@@ -1527,7 +1533,9 @@ static int add_non_dir(const char *path_
if (fd == -1)
return sys_err_msg("failed to open file '%s'",
path_name);
@@ -127,9 +122,9 @@
flags = 0;
if (close(fd) == -1)
return sys_err_msg("failed to close file '%s'",
---- a/mkfs.ubifs/devtable.c
-+++ b/mkfs.ubifs/devtable.c
-@@ -134,6 +134,7 @@ static int interpret_table_entry(const c
+--- 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;
@@ -137,14 +132,44 @@
if (sscanf(line, "%1023s %c %o %u %u %u %u %u %u %u",
buf, &type, &mode, &uid, &gid, &major, &minor,
&start, &increment, &count) < 0)
-@@ -144,8 +145,8 @@ static int interpret_table_entry(const c
+@@ -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);
-- if (len == 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 (!strcmp(buf, "/"))
+ if (buf[0] != '/')
+--- a/include/common.h
++++ b/include/common.h
+@@ -26,7 +26,6 @@
+ #include <string.h>
+ #include <fcntl.h>
+ #include <errno.h>
+-#include <features.h>
+ #include <inttypes.h>
+ #include <unistd.h>
+ #include <sys/sysmacros.h>
+--- a/include/mtd/ubifs-media.h
++++ b/include/mtd/ubifs-media.h
+@@ -33,7 +33,15 @@
+ #ifndef __UBIFS_MEDIA_H__
+ #define __UBIFS_MEDIA_H__
+
++#ifdef __linux__
+ #include <asm/byteorder.h>
++#else
++#include <stdint.h>
++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) */
+ #define UBIFS_NODE_MAGIC 0x06101831
diff --git a/tools/mtd-utils/patches/120-cygwin_fixes.patch b/tools/mtd-utils/patches/120-cygwin_fixes.patch
deleted file mode 100644
index 3dc21614b1f..00000000000
--- a/tools/mtd-utils/patches/120-cygwin_fixes.patch
+++ /dev/null
@@ -1,457 +0,0 @@
---- a/Makefile
-+++ b/Makefile
-@@ -12,6 +12,11 @@ else
- LZOLDLIBS = -llzo2
- endif
-
-+ifeq ($(shell uname -o),Cygwin)
-+CPPFLAGS += -I./include/cygwin
-+endif
-+
-+ifneq ($(shell uname -o),Cygwin)
- SUBDIRS = lib ubi-utils mkfs.ubifs
- TESTS = tests
-
-@@ -23,6 +28,10 @@ TARGETS = ftl_format flash_erase nanddum
- rfddump rfdformat \
- serve_image recv_image \
- sumtool #jffs2reader
-+else
-+SUBDIRS =
-+TARGETS = mkfs.jffs2
-+endif
- SCRIPTS = flash_eraseall
-
- SYMLINKS =
---- /dev/null
-+++ b/include/cygwin/bits-byteswap.h
-@@ -0,0 +1,132 @@
-+/* Macros to swap the order of bytes in integer values.
-+ Copyright (C) 1997, 1998, 2000, 2002 Free Software Foundation, Inc.
-+ This file is part of the GNU C Library.
-+
-+ The GNU C Library is free software; you can redistribute it and/or
-+ modify it under the terms of the GNU Lesser General Public
-+ License as published by the Free Software Foundation; either
-+ version 2.1 of the License, or (at your option) any later version.
-+
-+ The GNU C Library is distributed in the hope that it will be useful,
-+ but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-+ Lesser General Public License for more details.
-+
-+ You should have received a copy of the GNU Lesser General Public
-+ License along with the GNU C Library; if not, write to the Free
-+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-+ 02111-1307 USA. */
-+
-+#if !defined _BYTESWAP_H && !defined _NETINET_IN_H
-+# error "Never use <bits/byteswap.h> directly; include <byteswap.h> instead."
-+#endif
-+
-+#ifndef _BITS_BYTESWAP_H
-+#define _BITS_BYTESWAP_H 1
-+
-+/* Swap bytes in 16 bit value. */
-+#define __bswap_constant_16(x) \
-+ ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8))
-+
-+#ifdef __GNUC__
-+# if __GNUC__ >= 2
-+# define __bswap_16(x) \
-+ (__extension__ \
-+ ({ register unsigned short int __v, __x = (x); \
-+ if (__builtin_constant_p (__x)) \
-+ __v = __bswap_constant_16 (__x); \
-+ else \
-+ __asm__ ("rorw $8, %w0" \
-+ : "=r" (__v) \
-+ : "0" (__x) \
-+ : "cc"); \
-+ __v; }))
-+# else
-+/* This is better than nothing. */
-+# define __bswap_16(x) \
-+ (__extension__ \
-+ ({ register unsigned short int __x = (x); __bswap_constant_16 (__x); }))
-+# endif
-+#else
-+static __inline unsigned short int
-+__bswap_16 (unsigned short int __bsx)
-+{
-+ return __bswap_constant_16 (__bsx);
-+}
-+#endif
-+
-+/* Swap bytes in 32 bit value. */
-+#define __bswap_constant_32(x) \
-+ ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
-+ (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
-+
-+#ifdef __GNUC__
-+# if __GNUC__ >= 2
-+/* To swap the bytes in a word the i486 processors and up provide the
-+ `bswap' opcode. On i386 we have to use three instructions. */
-+# if !defined __i486__ && !defined __pentium__ && !defined __pentiumpro__
-+# define __bswap_32(x) \
-+ (__extension__ \
-+ ({ register unsigned int __v, __x = (x); \
-+ if (__builtin_constant_p (__x)) \
-+ __v = __bswap_constant_32 (__x); \
-+ else \
-+ __asm__ ("rorw $8, %w0;" \
-+ "rorl $16, %0;" \
-+ "rorw $8, %w0" \
-+ : "=r" (__v) \
-+ : "0" (__x) \
-+ : "cc"); \
-+ __v; }))
-+# else
-+# define __bswap_32(x) \
-+ (__extension__ \
-+ ({ register unsigned int __v, __x = (x); \
-+ if (__builtin_constant_p (__x)) \
-+ __v = __bswap_constant_32 (__x); \
-+ else \
-+ __asm__ ("bswap %0" : "=r" (__v) : "0" (__x)); \
-+ __v; }))
-+# endif
-+# else
-+# define __bswap_32(x) \
-+ (__extension__ \
-+ ({ register unsigned int __x = (x); __bswap_constant_32 (__x); }))
-+# endif
-+#else
-+static __inline unsigned int
-+__bswap_32 (unsigned int __bsx)
-+{
-+ return __bswap_constant_32 (__bsx);
-+}
-+#endif
-+
-+
-+#if defined __GNUC__ && __GNUC__ >= 2
-+/* Swap bytes in 64 bit value. */
-+#define __bswap_constant_64(x) \
-+ ((((x) & 0xff00000000000000ull) >> 56) \
-+ | (((x) & 0x00ff000000000000ull) >> 40) \
-+ | (((x) & 0x0000ff0000000000ull) >> 24) \
-+ | (((x) & 0x000000ff00000000ull) >> 8) \
-+ | (((x) & 0x00000000ff000000ull) << 8) \
-+ | (((x) & 0x0000000000ff0000ull) << 24) \
-+ | (((x) & 0x000000000000ff00ull) << 40) \
-+ | (((x) & 0x00000000000000ffull) << 56))
-+
-+# define __bswap_64(x) \
-+ (__extension__ \
-+ ({ union { __extension__ unsigned long long int __ll; \
-+ unsigned long int __l[2]; } __w, __r; \
-+ if (__builtin_constant_p (x)) \
-+ __r.__ll = __bswap_constant_64 (x); \
-+ else \
-+ { \
-+ __w.__ll = (x); \
-+ __r.__l[0] = __bswap_32 (__w.__l[1]); \
-+ __r.__l[1] = __bswap_32 (__w.__l[0]); \
-+ } \
-+ __r.__ll; }))
-+#endif
-+
-+#endif /* _BITS_BYTESWAP_H */
---- /dev/null
-+++ b/include/cygwin/byteswap.h
-@@ -0,0 +1,40 @@
-+/* Copyright (C) 1997 Free Software Foundation, Inc.
-+ This file is part of the GNU C Library.
-+
-+ The GNU C Library is free software; you can redistribute it and/or
-+ modify it under the terms of the GNU Lesser General Public
-+ License as published by the Free Software Foundation; either
-+ version 2.1 of the License, or (at your option) any later version.
-+
-+ The GNU C Library is distributed in the hope that it will be useful,
-+ but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-+ Lesser General Public License for more details.
-+
-+ You should have received a copy of the GNU Lesser General Public
-+ License along with the GNU C Library; if not, write to the Free
-+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-+ 02111-1307 USA. */
-+
-+#ifndef _BYTESWAP_H
-+#define _BYTESWAP_H 1
-+
-+/* Get the machine specific, optimized definitions. */
-+#include "bits-byteswap.h"
-+
-+
-+/* The following definitions must all be macros since otherwise some
-+ of the possible optimizations are not possible. */
-+
-+/* Return a value with all bytes in the 16 bit argument swapped. */
-+#define bswap_16(x) __bswap_16 (x)
-+
-+/* Return a value with all bytes in the 32 bit argument swapped. */
-+#define bswap_32(x) __bswap_32 (x)
-+
-+#if defined __GNUC__ && __GNUC__ >= 2
-+/* Return a value with all bytes in the 64 bit argument swapped. */
-+# define bswap_64(x) __bswap_64 (x)
-+#endif
-+
-+#endif /* byteswap.h */
---- /dev/null
-+++ b/include/cygwin/endian.h
-@@ -0,0 +1,26 @@
-+#ifndef _CYGENDIAN_H_
-+#define _CYGENDIAN_H_
-+
-+#ifdef __CYGWIN__
-+
-+#include <sys/param.h>
-+
-+#ifndef __BIG_ENDIAN
-+#define __BIG_ENDIAN 4321
-+#endif
-+
-+#ifndef __LITTLE_ENDIAN
-+#define __LITTLE_ENDIAN 1234
-+#endif
-+
-+#ifndef __BYTE_ORDER
-+#define __BYTE_ORDER __LITTLE_ENDIAN
-+#endif
-+
-+#ifndef BYTE_ORDER
-+#define BYTE_ORDER __LITTLE_ENDIAN
-+#endif
-+
-+#endif /* __CYGWIN__ */
-+
-+#endif /* _CYGENDIAN_H_ */
---- /dev/null
-+++ b/include/cygwin/ioctl.h
-@@ -0,0 +1,38 @@
-+#ifndef _CYGIOCTL_H_
-+#define _CYGIOCTL_H_
-+
-+#ifdef __CYGWIN__
-+
-+#define _IOC_NRBITS 8
-+#define _IOC_TYPEBITS 8
-+#define _IOC_SIZEBITS 14
-+#define _IOC_DIRBITS 2
-+
-+#define _IOC_NRMASK ((1 << _IOC_NRBITS)-1)
-+#define _IOC_TYPEMASK ((1 << _IOC_TYPEBITS)-1)
-+#define _IOC_SIZEMASK ((1 << _IOC_SIZEBITS)-1)
-+#define _IOC_DIRMASK ((1 << _IOC_DIRBITS)-1)
-+
-+#define _IOC_NRSHIFT 0
-+#define _IOC_TYPESHIFT (_IOC_NRSHIFT+_IOC_NRBITS)
-+#define _IOC_SIZESHIFT (_IOC_TYPESHIFT+_IOC_TYPEBITS)
-+#define _IOC_DIRSHIFT (_IOC_SIZESHIFT+_IOC_SIZEBITS)
-+
-+#define _IOC_NONE 0U
-+#define _IOC_WRITE 1U
-+#define _IOC_READ 2U
-+
-+#define _IOC(dir,type,nr,size) \
-+ (((dir) << _IOC_DIRSHIFT) | \
-+ ((type) << _IOC_TYPESHIFT) | \
-+ ((nr) << _IOC_NRSHIFT) | \
-+ ((size) << _IOC_SIZESHIFT))
-+
-+#define _IO(type,nr) _IOC(_IOC_NONE,(type),(nr),0)
-+#define _IOR(type,nr,size) _IOC(_IOC_READ,(type),(nr),sizeof(size))
-+#define _IOW(type,nr,size) _IOC(_IOC_WRITE,(type),(nr),sizeof(size))
-+#define _IOWR(type,nr,size) _IOC(_IOC_READ|_IOC_WRITE,(type),(nr),sizeof(size))
-+
-+#endif /* __CYGWIN__ */
-+
-+#endif /* _CYGIOCTL_H_ */
---- /dev/null
-+++ b/include/cygwin/pread.c
-@@ -0,0 +1,41 @@
-+#ifdef __CYGWIN__
-+
-+#include <errno.h>
-+
-+ssize_t
-+pread(int fd, void *p, size_t n, off_t off)
-+{
-+ off_t ooff;
-+ int oerrno;
-+
-+ if ((ooff = lseek(fd, off, SEEK_SET)) == -1)
-+ return -1;
-+
-+ n = read(fd, p, n);
-+
-+ oerrno = errno;
-+ lseek(fd, ooff, SEEK_SET);
-+ errno = oerrno;
-+
-+ return n;
-+}
-+
-+ssize_t
-+pwrite(int fd, const void *p, size_t n, off_t off)
-+{
-+ off_t ooff;
-+ int oerrno;
-+
-+ if ((ooff = lseek(fd, off, SEEK_SET)) == -1)
-+ return -1;
-+
-+ n = write(fd, p, n);
-+
-+ oerrno = errno;
-+ lseek(fd, ooff, SEEK_SET);
-+ errno = oerrno;
-+
-+ return n;
-+}
-+
-+#endif /* __CYGWIN__ */
---- /dev/null
-+++ b/lnconf.sh
-@@ -0,0 +1,53 @@
-+#!/bin/sh
-+#
-+# Generic configure replacement.
-+#
-+# $Id: lnconf.sh,v 1.1 2004/04/05 21:55:59 igor Exp $
-+#
-+# Copies all files from the script directory to the current one.
-+# Intended to replace 'configure' for packages that don't have one, to
-+# allow building outside of the source tree.
-+#
-+# Note: this does not do any fancy things with detecting shells and
-+# supporting other platforms. But it should work on Cygwin.
-+
-+# find out where the script is located
-+tdir=`echo "$0" | sed 's%[\\/][^\\/][^\\/]*$%%'`
-+test "x$tdir" = "x$0" && tdir=.
-+
-+a_srcdir=`cd $tdir; pwd`
-+a_destdir=`pwd`
-+
-+# sanity checks:
-+# are we in the script directory?
-+test "x$a_srcdir" = "x$a_destdir" && exit 0
-+# is there any chance that this is the script directory?
-+test "x`cd "$a_srcdir" && /bin/ls -id`" = "x`/bin/ls -id`" && exit 0
-+
-+# try to find lndir and use it if it's available
-+LNDIR="`which lndir 2>/dev/null`"
-+if [ "x$LNDIR" = "x" ]; then
-+ lndir() {
-+ test "x$1" = "x" && return 1
-+ # be careful of the current directory
-+ DINODE=`find . -maxdepth 0 -ls | sed 's/ .*$//'`
-+ case "`pwd`" in
-+ "`cd "$1" && pwd`"/*) CUR="-type d -inum $DINODE -prune -o";;
-+ esac
-+ # duplicate the directory structure
-+ (cd "$1" && find . $CUR -type d -mindepth 1 -print) | xargs -tr mkdir -p
-+ # copy all symbolic links
-+ (cd "$1" && find . $CUR -type l -mindepth 1 -print) | xargs -ri sh -c "ln -s \"\`readlink "$1/{}"\`\" \"{}\""
-+ # or simply
-+ #(cd "$1" && find . $CUR -type l -mindepth 1 -print) | xargs -ri ln -s "$1"/{} {}
-+ # link all files
-+ (cd "$1" && find . $CUR -type f -mindepth 1 -print) | xargs -ri ln -s "$1"/{} {}
-+ }
-+else
-+ lndir() {
-+ "$LNDIR" "$@"
-+ }
-+fi
-+
-+lndir "$tdir"
-+
---- a/mkfs.jffs2.c
-+++ b/mkfs.jffs2.c
-@@ -77,6 +77,14 @@
- #include "rbtree.h"
- #include "common.h"
-
-+#ifdef __CYGWIN__
-+#include <cygwin/ioctl.h>
-+#include <cygwin/endian.h>
-+#include <cygwin/pread.c>
-+# define IFTODT(mode) (((mode) & 0170000) >> 12)
-+# define DTTOIF(dirtype) ((dirtype) << 12)
-+#endif /* __CYGWIN__ */
-+
- /* Do not use the weird XPG version of basename */
- #undef basename
-
-@@ -376,7 +384,7 @@ static struct filesystem_entry *recursiv
- the following macros use it if available or use a hacky workaround...
- */
-
--#ifdef __GNUC__
-+#if defined __GNUC__ && !defined __CYGWIN__
- #define SCANF_PREFIX "a"
- #define SCANF_STRING(s) (&s)
- #define GETCWD_SIZE 0
-@@ -459,6 +467,14 @@ static int interpret_table_entry(struct
- }
- entry = find_filesystem_entry(root, name, mode);
- if (entry && !(count > 0 && (type == 'c' || type == 'b'))) {
-+ /* Check the type */
-+ if ((mode & S_IFMT) != (entry->sb.st_mode & S_IFMT)) {
-+ error_msg ("skipping device_table entry '%s': type mismatch!", name);
-+ free(name);
-+ free(hostpath);
-+ return 1;
-+ }
-+
- /* Ok, we just need to fixup the existing entry
- * and we will be all done... */
- entry->sb.st_uid = uid;
-@@ -468,11 +484,21 @@ static int interpret_table_entry(struct
- entry->sb.st_rdev = makedev(major, minor);
- }
- } else {
-+ if (type == 'f' || type == 'l') {
-+ error_msg ("skipping device_table entry '%s': file does not exist!", name);
-+ free(name);
-+ free(hostpath);
-+ return 1;
-+ }
- /* If parent is NULL (happens with device table entries),
- * try and find our parent now) */
- tmp = strdup(name);
- dir = dirname(tmp);
-- parent = find_filesystem_entry(root, dir, S_IFDIR);
-+ if (!strcmp(dir, "/")) {
-+ parent = root;
-+ } else {
-+ parent = find_filesystem_entry(root, dir, S_IFDIR);
-+ }
- free(tmp);
- if (parent == NULL) {
- errmsg ("skipping device_table entry '%s': no parent directory!", name);
-@@ -486,6 +512,7 @@ static int interpret_table_entry(struct
- add_host_filesystem_entry(name, hostpath, uid, gid, mode, 0, parent);
- break;
- case 'f':
-+ case 'l':
- add_host_filesystem_entry(name, hostpath, uid, gid, mode, 0, parent);
- break;
- case 'p':
---- a/ubi-utils/src/libubi.c
-+++ b/ubi-utils/src/libubi.c
-@@ -32,6 +32,9 @@
- #include <sys/ioctl.h>
- #include <sys/stat.h>
- #include <sys/types.h>
-+#ifdef __CYGWIN__
-+#include <cygwin/ioctl.h>
-+#endif
- #include <libubi.h>
- #include "libubi_int.h"
- #include "common.h"
diff --git a/tools/mtd-utils/patches/130-lzma_jffs2.patch b/tools/mtd-utils/patches/130-lzma_jffs2.patch
index be1c361fe1d..d9cbfeebec1 100644
--- a/tools/mtd-utils/patches/130-lzma_jffs2.patch
+++ b/tools/mtd-utils/patches/130-lzma_jffs2.patch
@@ -1,33 +1,35 @@
---- a/Makefile
-+++ b/Makefile
-@@ -1,7 +1,7 @@
+--- a/jffsX-utils/Makemodule.am
++++ b/jffsX-utils/Makemodule.am
+@@ -4,11 +4,19 @@ mkfs_jffs2_SOURCES = \
+ jffsX-utils/compr_zlib.c \
+ jffsX-utils/compr.h \
+ jffsX-utils/rbtree.c \
+- jffsX-utils/compr_lzo.c \
++ jffsX-utils/compr_lzma.c \
++ jffsX-utils/lzma/LzFind.c \
++ jffsX-utils/lzma/LzmaEnc.c \
++ jffsX-utils/lzma/LzmaDec.c \
+ jffsX-utils/compr.c \
+ jffsX-utils/compr_rtime.c
++
++if !WITHOUT_LZO
++mkfs_jffs2_SOURCES += jffsX-utils/compr_lzo.c
++endif
++
+ mkfs_jffs2_LDADD = libmtd.a $(ZLIB_LIBS) $(LZO_LIBS)
+-mkfs_jffs2_CPPFLAGS = $(AM_CPPFLAGS) $(ZLIB_CFLAGS) $(LZO_CFLAGS)
++mkfs_jffs2_CPPFLAGS = $(AM_CPPFLAGS) $(ZLIB_CFLAGS) $(LZO_CFLAGS) -I./include/linux/lzma
- # -*- sh -*-
-
--CPPFLAGS += -I./include $(ZLIBCPPFLAGS) $(LZOCPPFLAGS)
-+CPPFLAGS += -I./include $(ZLIBCPPFLAGS) $(LZOCPPFLAGS) -I./include/linux/lzma
-
- ifeq ($(WITHOUT_XATTR), 1)
- CPPFLAGS += -DWITHOUT_XATTR
-@@ -59,7 +59,9 @@ $(SYMLINKS):
- ln -sf ../fs/jffs2/$@ $@
-
- $(BUILDDIR)/mkfs.jffs2: $(addprefix $(BUILDDIR)/,\
-- compr_rtime.o mkfs.jffs2.o compr_zlib.o compr_lzo.o \
-+ compr_rtime.o mkfs.jffs2.o compr_zlib.o \
-+ $(if $(WITHOUT_LZO),,compr_lzo.o) \
-+ compr_lzma.o lzma/LzFind.o lzma/LzmaEnc.o lzma/LzmaDec.o \
- compr.o rbtree.o)
- LDFLAGS_mkfs.jffs2 = $(ZLIBLDFLAGS) $(LZOLDFLAGS)
- LDLIBS_mkfs.jffs2 = -lz $(LZOLDLIBS)
---- a/compr.c
-+++ b/compr.c
+ jffs2reader_SOURCES = jffsX-utils/jffs2reader.c
+ jffs2reader_LDADD = libmtd.a $(ZLIB_LIBS) $(LZO_LIBS)
+--- a/jffsX-utils/compr.c
++++ b/jffsX-utils/compr.c
@@ -520,6 +520,9 @@ int jffs2_compressors_init(void)
#ifdef CONFIG_JFFS2_LZO
jffs2_lzo_init();
#endif
+#ifdef CONFIG_JFFS2_LZMA
-+ jffs2_lzma_init();
++ jffs2_lzma_init();
+#endif
return 0;
}
@@ -37,12 +39,12 @@
jffs2_lzo_exit();
#endif
+#ifdef CONFIG_JFFS2_LZMA
-+ jffs2_lzma_exit();
++ jffs2_lzma_exit();
+#endif
return 0;
}
---- a/compr.h
-+++ b/compr.h
+--- a/jffsX-utils/compr.h
++++ b/jffsX-utils/compr.h
@@ -18,13 +18,14 @@
#define CONFIG_JFFS2_ZLIB
@@ -73,7 +75,7 @@
#endif /* __JFFS2_COMPR_H__ */
--- /dev/null
-+++ b/compr_lzma.c
++++ b/jffsX-utils/compr_lzma.c
@@ -0,0 +1,128 @@
+/*
+ * JFFS2 -- Journalling Flash File System, Version 2.
@@ -120,11 +122,11 @@
+ return -1;
+ }
+
-+ return 0;
++ return 0;
+}
+
+STATIC int jffs2_lzma_compress(unsigned char *data_in, unsigned char *cpage_out,
-+ uint32_t *sourcelen, uint32_t *dstlen, void *model)
++ uint32_t *sourcelen, uint32_t *dstlen)
+{
+ SizeT compress_size = (SizeT)(*dstlen);
+ int ret;
@@ -149,7 +151,7 @@
+}
+
+STATIC int jffs2_lzma_decompress(unsigned char *data_in, unsigned char *cpage_out,
-+ uint32_t srclen, uint32_t destlen, void *model)
++ uint32_t srclen, uint32_t destlen)
+{
+ int ret;
+ SizeT dl = (SizeT)destlen;
@@ -176,26 +178,26 @@
+
+int INIT jffs2_lzma_init(void)
+{
-+ int ret;
++ int ret;
+ CLzmaEncProps props;
+ LzmaEncProps_Init(&props);
+
-+ props.dictSize = LZMA_BEST_DICT(0x2000);
-+ props.level = LZMA_BEST_LEVEL;
-+ props.lc = LZMA_BEST_LC;
-+ props.lp = LZMA_BEST_LP;
-+ props.pb = LZMA_BEST_PB;
-+ props.fb = LZMA_BEST_FB;
++ props.dictSize = LZMA_BEST_DICT(0x2000);
++ props.level = LZMA_BEST_LEVEL;
++ props.lc = LZMA_BEST_LC;
++ props.lp = LZMA_BEST_LP;
++ props.pb = LZMA_BEST_PB;
++ props.fb = LZMA_BEST_FB;
+
+ ret = lzma_alloc_workspace(&props);
-+ if (ret < 0)
-+ return ret;
++ if (ret < 0)
++ return ret;
+
+ ret = jffs2_register_compressor(&jffs2_lzma_comp);
+ if (ret)
+ lzma_free_workspace();
+
-+ return ret;
++ return ret;
+}
+
+void jffs2_lzma_exit(void)
@@ -246,7 +248,7 @@
+ #define LZMA_FREE free
+ #define PRINT_ERROR(msg) fprintf(stderr, msg)
+ #define INIT
-+ #define STATIC
++ #define STATIC static
+#endif
+
+#include "lzma/LzmaDec.h"
@@ -262,16 +264,16 @@
+
+static void *p_lzma_malloc(void *p, size_t size)
+{
-+ if (size == 0)
-+ return NULL;
++ if (size == 0)
++ return NULL;
+
-+ return LZMA_MALLOC(size);
++ return LZMA_MALLOC(size);
+}
+
+static void p_lzma_free(void *p, void *address)
+{
-+ if (address != NULL)
-+ LZMA_FREE(address);
++ if (address != NULL)
++ LZMA_FREE(address);
+}
+
+static ISzAlloc lzma_alloc = {p_lzma_malloc, p_lzma_free};
@@ -901,7 +903,7 @@
+
+#endif
--- /dev/null
-+++ b/lzma/LzFind.c
++++ b/jffsX-utils/lzma/LzFind.c
@@ -0,0 +1,753 @@
+/* LzFind.c -- Match finder for LZ algorithms
+2008-04-04
@@ -950,9 +952,9 @@
+}
+
+Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; }
-+Byte MatchFinder_GetIndexByte(CMatchFinder *p, Int32 index) { return p->buffer[index]; }
++static Byte MatchFinder_GetIndexByte(CMatchFinder *p, Int32 index) { return p->buffer[index]; }
+
-+UInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; }
++static UInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; }
+
+void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue)
+{
@@ -1657,7 +1659,7 @@
+ }
+}
--- /dev/null
-+++ b/lzma/LzmaDec.c
++++ b/jffsX-utils/lzma/LzmaDec.c
@@ -0,0 +1,1014 @@
+/* LzmaDec.c -- LZMA Decoder
+2008-04-29
@@ -2358,7 +2360,7 @@
+ p->needFlush = 0;
+}
+
-+void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState)
++static void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState)
+{
+ p->needFlush = 1;
+ p->remainLen = 0;
@@ -2674,7 +2676,7 @@
+ return res;
+}
--- /dev/null
-+++ b/lzma/LzmaEnc.c
++++ b/jffsX-utils/lzma/LzmaEnc.c
@@ -0,0 +1,2335 @@
+/* LzmaEnc.c -- LZMA Encoder
+2008-04-28
@@ -2778,7 +2780,7 @@
+#define kNumLogBits (9 + (int)sizeof(size_t) / 2)
+#define kDicLogSizeMaxCompress ((kNumLogBits - 1) * 2 + 7)
+
-+void LzmaEnc_FastPosInit(Byte *g_FastPos)
++static void LzmaEnc_FastPosInit(Byte *g_FastPos)
+{
+ int c = 2, slotFast;
+ g_FastPos[0] = 0;
@@ -3032,7 +3034,7 @@
+ CSaveState saveState;
+} CLzmaEnc;
+
-+void LzmaEnc_SaveState(CLzmaEncHandle pp)
++static void LzmaEnc_SaveState(CLzmaEncHandle pp)
+{
+ CLzmaEnc *p = (CLzmaEnc *)pp;
+ CSaveState *dest = &p->saveState;
@@ -3058,7 +3060,7 @@
+ memcpy(dest->litProbs, p->litProbs, (0x300 << p->lclp) * sizeof(CLzmaProb));
+}
+
-+void LzmaEnc_RestoreState(CLzmaEncHandle pp)
++static void LzmaEnc_RestoreState(CLzmaEncHandle pp)
+{
+ CLzmaEnc *dest = (CLzmaEnc *)pp;
+ const CSaveState *p = &dest->saveState;
@@ -3301,7 +3303,7 @@
+ while (symbol < 0x10000);
+}
+
-+void LzmaEnc_InitPriceTables(UInt32 *ProbPrices)
++static void LzmaEnc_InitPriceTables(UInt32 *ProbPrices)
+{
+ UInt32 i;
+ for (i = (1 << kNumMoveReducingBits) / 2; i < kBitModelTotal; i += (1 << kNumMoveReducingBits))
@@ -4427,7 +4429,7 @@
+ p->matchPriceCount = 0;
+}
+
-+void LzmaEnc_Construct(CLzmaEnc *p)
++static void LzmaEnc_Construct(CLzmaEnc *p)
+{
+ RangeEnc_Construct(&p->rc);
+ MatchFinder_Construct(&p->matchFinderBase);
@@ -4460,7 +4462,7 @@
+ return p;
+}
+
-+void LzmaEnc_FreeLits(CLzmaEnc *p, ISzAlloc *alloc)
++static void LzmaEnc_FreeLits(CLzmaEnc *p, ISzAlloc *alloc)
+{
+ alloc->Free(alloc, p->litProbs);
+ alloc->Free(alloc, p->saveState.litProbs);
@@ -4468,7 +4470,7 @@
+ p->saveState.litProbs = 0;
+}
+
-+void LzmaEnc_Destruct(CLzmaEnc *p, ISzAlloc *alloc, ISzAlloc *allocBig)
++static void LzmaEnc_Destruct(CLzmaEnc *p, ISzAlloc *alloc, ISzAlloc *allocBig)
+{
+ #ifdef COMPRESS_MF_MT
+ MatchFinderMt_Destruct(&p->matchFinderMt, allocBig);
@@ -4699,7 +4701,7 @@
+ return SZ_OK;
+}
+
-+void LzmaEnc_Init(CLzmaEnc *p)
++static void LzmaEnc_Init(CLzmaEnc *p)
+{
+ UInt32 i;
+ p->state = 0;
@@ -4758,7 +4760,7 @@
+ p->lpMask = (1 << p->lp) - 1;
+}
+
-+void LzmaEnc_InitPrices(CLzmaEnc *p)
++static void LzmaEnc_InitPrices(CLzmaEnc *p)
+{
+ if (!p->fastMode)
+ {
@@ -4799,7 +4801,7 @@
+ return LzmaEnc_AllocAndInit(p, 0, alloc, allocBig);
+}
+
-+SRes LzmaEnc_PrepareForLzma2(CLzmaEncHandle pp,
++static SRes LzmaEnc_PrepareForLzma2(CLzmaEncHandle pp,
+ ISeqInStream *inStream, UInt32 keepWindowSize,
+ ISzAlloc *alloc, ISzAlloc *allocBig)
+{
@@ -4815,7 +4817,7 @@
+ p->seqBufInStream.rem = srcLen;
+}
+
-+SRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const Byte *src, SizeT srcLen,
++static SRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const Byte *src, SizeT srcLen,
+ UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)
+{
+ CLzmaEnc *p = (CLzmaEnc *)pp;
@@ -4824,7 +4826,7 @@
+ return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig);
+}
+
-+void LzmaEnc_Finish(CLzmaEncHandle pp)
++static void LzmaEnc_Finish(CLzmaEncHandle pp)
+{
+ #ifdef COMPRESS_MF_MT
+ CLzmaEnc *p = (CLzmaEnc *)pp;
@@ -4856,19 +4858,19 @@
+}
+
+
-+UInt32 LzmaEnc_GetNumAvailableBytes(CLzmaEncHandle pp)
++static UInt32 LzmaEnc_GetNumAvailableBytes(CLzmaEncHandle pp)
+{
+ const CLzmaEnc *p = (CLzmaEnc *)pp;
+ return p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);
+}
+
-+const Byte *LzmaEnc_GetCurBuf(CLzmaEncHandle pp)
++static const Byte *LzmaEnc_GetCurBuf(CLzmaEncHandle pp)
+{
+ const CLzmaEnc *p = (CLzmaEnc *)pp;
+ return p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset;
+}
+
-+SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, Bool reInit,
++static SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, Bool reInit,
+ Byte *dest, size_t *destLen, UInt32 desiredPackSize, UInt32 *unpackSize)
+{
+ CLzmaEnc *p = (CLzmaEnc *)pp;
@@ -5011,9 +5013,9 @@
+ LzmaEnc_Destroy(p, alloc, allocBig);
+ return res;
+}
---- a/mkfs.jffs2.c
-+++ b/mkfs.jffs2.c
-@@ -1685,11 +1685,11 @@ int main(int argc, char **argv)
+--- a/jffsX-utils/mkfs.jffs2.c
++++ b/jffsX-utils/mkfs.jffs2.c
+@@ -1666,11 +1666,11 @@ int main(int argc, char **argv)
}
erase_block_size *= units;
diff --git a/tools/mtd-utils/patches/131-fix_lib_compile.patch b/tools/mtd-utils/patches/131-fix_lib_compile.patch
deleted file mode 100644
index 8c977c1774d..00000000000
--- a/tools/mtd-utils/patches/131-fix_lib_compile.patch
+++ /dev/null
@@ -1,11 +0,0 @@
---- a/lib/Makefile
-+++ b/lib/Makefile
-@@ -7,7 +7,7 @@ SUBDIRS =
- # CFLAGS += -Werror
- CPPFLAGS += -I../include
- LIBS = libmtd
--TARGETS = libmtd.a
-+override TARGETS = libmtd.a
-
- include ../common.mk
-
diff --git a/tools/mtd-utils/patches/133-error-fix.patch b/tools/mtd-utils/patches/133-error-fix.patch
deleted file mode 100644
index 4854138d023..00000000000
--- a/tools/mtd-utils/patches/133-error-fix.patch
+++ /dev/null
@@ -1,20 +0,0 @@
---- a/mkfs.jffs2.c
-+++ b/mkfs.jffs2.c
-@@ -469,7 +469,7 @@ static int interpret_table_entry(struct
- if (entry && !(count > 0 && (type == 'c' || type == 'b'))) {
- /* Check the type */
- if ((mode & S_IFMT) != (entry->sb.st_mode & S_IFMT)) {
-- error_msg ("skipping device_table entry '%s': type mismatch!", name);
-+ sys_errmsg ("skipping device_table entry '%s': type mismatch!", name);
- free(name);
- free(hostpath);
- return 1;
-@@ -485,7 +485,7 @@ static int interpret_table_entry(struct
- }
- } else {
- if (type == 'f' || type == 'l') {
-- error_msg ("skipping device_table entry '%s': file does not exist!", name);
-+ sys_errmsg ("skipping device_table entry '%s': file does not exist!", name);
- free(name);
- free(hostpath);
- return 1;
diff --git a/tools/mtd-utils/patches/134-freebsd_loff_t.patch b/tools/mtd-utils/patches/134-freebsd_loff_t.patch
index 68a835292ca..2d141bd7a3a 100644
--- a/tools/mtd-utils/patches/134-freebsd_loff_t.patch
+++ b/tools/mtd-utils/patches/134-freebsd_loff_t.patch
@@ -1,13 +1,14 @@
--- a/include/mtd/mtd-abi.h
+++ b/include/mtd/mtd-abi.h
-@@ -114,8 +114,8 @@ struct otp_info {
- #define MEMGETREGIONINFO _IOWR('M', 8, struct region_info_user)
- #define MEMSETOOBSEL _IOW('M', 9, struct nand_oobinfo)
+@@ -171,9 +171,9 @@ struct otp_info {
+ /* Get info about OOB modes (e.g., RAW, PLACE, AUTO) - legacy interface */
#define MEMGETOOBSEL _IOR('M', 10, struct nand_oobinfo)
+ /* Check if an eraseblock is bad */
-#define MEMGETBADBLOCK _IOW('M', 11, __kernel_loff_t)
--#define MEMSETBADBLOCK _IOW('M', 12, __kernel_loff_t)
+#define MEMGETBADBLOCK _IOW('M', 11, loff_t)
+ /* Mark an eraseblock as bad */
+-#define MEMSETBADBLOCK _IOW('M', 12, __kernel_loff_t)
+#define MEMSETBADBLOCK _IOW('M', 12, loff_t)
+ /* Set OTP (One-Time Programmable) mode (factory vs. user) */
#define OTPSELECT _IOR('M', 13, int)
- #define OTPGETREGIONCOUNT _IOW('M', 14, int)
- #define OTPGETREGIONINFO _IOW('M', 15, struct otp_info)
+ /* Get number of OTP (One-Time Programmable) regions */
diff --git a/tools/mtd-utils/patches/135-mkubifs_optional_lzo.patch b/tools/mtd-utils/patches/135-mkubifs_optional_lzo.patch
deleted file mode 100644
index 82b6c2fe94e..00000000000
--- a/tools/mtd-utils/patches/135-mkubifs_optional_lzo.patch
+++ /dev/null
@@ -1,119 +0,0 @@
---- a/mkfs.ubifs/compr.c
-+++ b/mkfs.ubifs/compr.c
-@@ -24,7 +24,6 @@
- #include <stdio.h>
- #include <stdint.h>
- #include <string.h>
--#include <lzo/lzo1x.h>
- #include <linux/types.h>
-
- #define crc32 __zlib_crc32
-@@ -35,7 +34,6 @@
- #include "ubifs-media.h"
- #include "mkfs.ubifs.h"
-
--static void *lzo_mem;
- static unsigned long long errcnt = 0;
- static struct ubifs_info *c = &info_;
-
-@@ -86,6 +84,25 @@ static int zlib_deflate(void *in_buf, si
- return 0;
- }
-
-+#ifndef WITHOUT_LZO
-+#include <lzo/lzo1x.h>
-+
-+static void *lzo_mem;
-+
-+static int lzo_init(void)
-+{
-+ lzo_mem = malloc(LZO1X_999_MEM_COMPRESS);
-+ if (!lzo_mem)
-+ return -1;
-+
-+ return 0;
-+}
-+
-+static void lzo_fini(void)
-+{
-+ free(lzo_mem);
-+}
-+
- static int lzo_compress(void *in_buf, size_t in_len, void *out_buf,
- size_t *out_len)
- {
-@@ -103,6 +120,12 @@ static int lzo_compress(void *in_buf, si
-
- return 0;
- }
-+#else
-+static inline int lzo_compress(void *in_buf, size_t in_len, void *out_buf,
-+ size_t *out_len) { return -1; }
-+static inline int lzo_init(void) { return 0; }
-+static inline void lzo_fini(void) { }
-+#endif
-
- static int no_compress(void *in_buf, size_t in_len, void *out_buf,
- size_t *out_len)
-@@ -123,7 +146,6 @@ static int favor_lzo_compress(void *in_b
- lzo_len = zlib_len = *out_len;
- lzo_ret = lzo_compress(in_buf, in_len, out_buf, &lzo_len);
- zlib_ret = zlib_deflate(in_buf, in_len, zlib_buf, &zlib_len);
--
- if (lzo_ret && zlib_ret)
- /* Both compressors failed */
- return -1;
-@@ -198,23 +220,28 @@ int compress_data(void *in_buf, size_t i
-
- int init_compression(void)
- {
-- lzo_mem = malloc(LZO1X_999_MEM_COMPRESS);
-- if (!lzo_mem)
-- return -1;
-+ int ret;
-+
-+ ret = lzo_init();
-+ if (ret)
-+ goto err;
-
- zlib_buf = malloc(UBIFS_BLOCK_SIZE * WORST_COMPR_FACTOR);
-- if (!zlib_buf) {
-- free(lzo_mem);
-- return -1;
-- }
-+ if (!zlib_buf)
-+ goto err_lzo;
-
- return 0;
-+
-+err_lzo:
-+ lzo_fini();
-+err:
-+ return ret;
- }
-
- void destroy_compression(void)
- {
- free(zlib_buf);
-- free(lzo_mem);
-+ lzo_fini();
- if (errcnt)
- fprintf(stderr, "%llu compression errors occurred\n", errcnt);
- }
---- a/mkfs.ubifs/Makefile
-+++ b/mkfs.ubifs/Makefile
-@@ -6,7 +6,13 @@ ALL_SOURCES=*.[ch] hashtable/*.[ch]
-
- TARGETS = mkfs.ubifs
-
--LDLIBS_mkfs.ubifs = -lz -llzo2 -lm -luuid -L$(BUILDDIR)/../ubi-utils/ -lubi
-+ifeq ($(WITHOUT_LZO), 1)
-+ CPPFLAGS += -DWITHOUT_LZO
-+else
-+ LZOLDLIBS = -llzo2
-+endif
-+
-+LDLIBS_mkfs.ubifs = -lz $(LZOLDLIBS) -lm -luuid -L$(BUILDDIR)/../ubi-utils/ -lubi
- LDLIBS_mkfs.ubifs += -L$(BUILDDIR)/../lib -lmtd
- LDLIBS_mkfs.ubifs += $(ZLIBLDFLAGS) $(LZOLDFLAGS)
-
diff --git a/tools/mtd-utils/patches/136-mkfs.ubifs-xz-support.patch b/tools/mtd-utils/patches/136-mkfs.ubifs-xz-support.patch
deleted file mode 100644
index 1e44ba4c274..00000000000
--- a/tools/mtd-utils/patches/136-mkfs.ubifs-xz-support.patch
+++ /dev/null
@@ -1,404 +0,0 @@
---- a/Makefile
-+++ b/Makefile
-@@ -1,7 +1,7 @@
-
- # -*- sh -*-
-
--CPPFLAGS += -I./include $(ZLIBCPPFLAGS) $(LZOCPPFLAGS) -I./include/linux/lzma
-+CPPFLAGS += -I./include $(ZLIBCPPFLAGS) $(LZOCPPFLAGS) $(XZCPPFLAGS) -I./include/linux/lzma
-
- ifeq ($(WITHOUT_XATTR), 1)
- CPPFLAGS += -DWITHOUT_XATTR
---- a/mkfs.ubifs/compr.c
-+++ b/mkfs.ubifs/compr.c
-@@ -127,6 +127,114 @@ static inline int lzo_init(void) { retur
- static inline void lzo_fini(void) { }
- #endif
-
-+#ifndef WITHOUT_XZ
-+
-+#include <lzma.h>
-+
-+struct xz_ctx {
-+ lzma_filter filters[3];
-+ lzma_options_lzma opts;
-+};
-+
-+static struct xz_ctx *xz_ctx;
-+
-+#define LZMA_COMPRESSION_LEVEL 9
-+
-+static struct xz_ctx *xz_ctx_init(void)
-+{
-+ struct xz_ctx *ctx;
-+ lzma_options_lzma *opts_lzma;
-+ uint32_t preset;
-+ int ret;
-+
-+ ctx = malloc(sizeof(struct xz_ctx));
-+ if (ctx == NULL)
-+ goto err;
-+
-+ memset(ctx, 0, sizeof(struct xz_ctx));
-+
-+ opts_lzma = &ctx->opts;
-+
-+ preset = LZMA_COMPRESSION_LEVEL | LZMA_PRESET_EXTREME;
-+ ret = lzma_lzma_preset(opts_lzma, preset);
-+ if (ret)
-+ goto err_free_ctx;
-+
-+ /* TODO: allow to specify LZMA options via command line */
-+#if 0
-+ opts_lzma->lc = 3;
-+ opts_lzma->lp = 0;
-+ opts_lzma->pb = 2;
-+ opts_lzma->nice_len = 64;
-+#else
-+ opts_lzma->lc = 0;
-+ opts_lzma->lp = 2;
-+ opts_lzma->pb = 2;
-+ opts_lzma->nice_len = 64;
-+#endif
-+
-+ ctx->filters[0].id = LZMA_FILTER_LZMA2;
-+ ctx->filters[0].options = opts_lzma;
-+ ctx->filters[1].id = LZMA_VLI_UNKNOWN;
-+
-+ return ctx;
-+
-+err_free_ctx:
-+ free(ctx);
-+err:
-+ return NULL;
-+}
-+
-+static void xz_ctx_free(struct xz_ctx *ctx)
-+{
-+ free(ctx);
-+}
-+
-+static int xz_init(void)
-+{
-+ xz_ctx = xz_ctx_init();
-+ if (xz_ctx == NULL)
-+ return -1;
-+
-+ return 0;
-+}
-+
-+static void xz_fini(void)
-+{
-+ xz_ctx_free(xz_ctx);
-+}
-+
-+static int xz_compress(void *in_buf, size_t in_len, void *out_buf,
-+ size_t *out_len)
-+{
-+ size_t ret_len;
-+ lzma_ret ret_xz;
-+ int ret;
-+
-+ ret = -1;
-+
-+ ret_len = 0;
-+ ret_xz = lzma_stream_buffer_encode(xz_ctx->filters, LZMA_CHECK_CRC32,
-+ NULL, in_buf, in_len, out_buf,
-+ &ret_len, *out_len);
-+ if (ret_xz != LZMA_OK) {
-+ fprintf(stderr, "XZ error: %d\n", (int) ret_xz);
-+ goto out;
-+ }
-+
-+ *out_len = ret_len;
-+
-+ ret = 0;
-+out:
-+ return ret;
-+}
-+#else
-+static inline int xz_init(void) { return 0; }
-+static inline void xz_fini(void) { }
-+static inline int xz_compress(void *in_buf, size_t in_len, void *out_buf,
-+ size_t *out_len) { return -1; }
-+#endif
-+
- static int no_compress(void *in_buf, size_t in_len, void *out_buf,
- size_t *out_len)
- {
-@@ -199,6 +307,9 @@ int compress_data(void *in_buf, size_t i
- case MKFS_UBIFS_COMPR_LZO:
- ret = lzo_compress(in_buf, in_len, out_buf, out_len);
- break;
-+ case MKFS_UBIFS_COMPR_XZ:
-+ ret = xz_compress(in_buf, in_len, out_buf, out_len);
-+ break;
- case MKFS_UBIFS_COMPR_ZLIB:
- ret = zlib_deflate(in_buf, in_len, out_buf, out_len);
- break;
-@@ -226,12 +337,18 @@ int init_compression(void)
- if (ret)
- goto err;
-
-+ ret = xz_init();
-+ if (ret)
-+ goto err_lzo;
-+
- zlib_buf = malloc(UBIFS_BLOCK_SIZE * WORST_COMPR_FACTOR);
- if (!zlib_buf)
-- goto err_lzo;
-+ goto err_xz;
-
- return 0;
-
-+err_xz:
-+ xz_fini();
- err_lzo:
- lzo_fini();
- err:
-@@ -241,6 +358,7 @@ err:
- void destroy_compression(void)
- {
- free(zlib_buf);
-+ xz_fini();
- lzo_fini();
- if (errcnt)
- fprintf(stderr, "%llu compression errors occurred\n", errcnt);
---- a/mkfs.ubifs/compr.h
-+++ b/mkfs.ubifs/compr.h
-@@ -36,6 +36,7 @@ enum compression_type
- MKFS_UBIFS_COMPR_NONE,
- MKFS_UBIFS_COMPR_LZO,
- MKFS_UBIFS_COMPR_ZLIB,
-+ MKFS_UBIFS_COMPR_XZ,
- };
-
- int compress_data(void *in_buf, size_t in_len, void *out_buf, size_t *out_len,
---- a/mkfs.ubifs/Makefile
-+++ b/mkfs.ubifs/Makefile
-@@ -6,21 +6,33 @@ ALL_SOURCES=*.[ch] hashtable/*.[ch]
-
- TARGETS = mkfs.ubifs
-
-+MKFS_UBIFS_OBJS = $(addprefix $(BUILDDIR)/,\
-+ crc16.o lpt.o compr.o devtable.o \
-+ hashtable/hashtable.o hashtable/hashtable_itr.o)
-+
- ifeq ($(WITHOUT_LZO), 1)
- CPPFLAGS += -DWITHOUT_LZO
- else
- LZOLDLIBS = -llzo2
- endif
-
--LDLIBS_mkfs.ubifs = -lz $(LZOLDLIBS) -lm -luuid -L$(BUILDDIR)/../ubi-utils/ -lubi
-+ifeq ($(WITHOUT_XZ), 1)
-+ CPPFLAGS += -DWITHOUT_XZ
-+else
-+ifneq ($(LZMA_STATIC_LIB),)
-+ MKFS_UBIFS_OBJS += $(LZMA_STATIC_LIB)
-+else
-+ XZLDLIBS = -llzma
-+endif
-+endif
-+
-+LDLIBS_mkfs.ubifs = -lz $(LZOLDLIBS) $(XZLDLIBS) -lm -luuid -L$(BUILDDIR)/../ubi-utils/ -lubi
- LDLIBS_mkfs.ubifs += -L$(BUILDDIR)/../lib -lmtd
--LDLIBS_mkfs.ubifs += $(ZLIBLDFLAGS) $(LZOLDFLAGS)
-+LDLIBS_mkfs.ubifs += $(ZLIBLDFLAGS) $(LZOLDFLAGS) $(XZLDFLAGS)
-
- include ../common.mk
-
--$(BUILDDIR)/mkfs.ubifs: $(addprefix $(BUILDDIR)/,\
-- crc16.o lpt.o compr.o devtable.o \
-- hashtable/hashtable.o hashtable/hashtable_itr.o)
-+$(BUILDDIR)/mkfs.ubifs: $(MKFS_UBIFS_OBJS)
-
- clean::
- rm -f $(BUILDDIR)/hashtable/*.o cscope.*
---- a/mkfs.ubifs/mkfs.ubifs.c
-+++ b/mkfs.ubifs/mkfs.ubifs.c
-@@ -98,6 +98,9 @@ struct ubifs_info info_;
- static struct ubifs_info *c = &info_;
- static libubi_t ubi;
-
-+static int force_compr_set;
-+static int force_compr;
-+
- /* Debug levels are: 0 (none), 1 (statistics), 2 (files) ,3 (more details) */
- int debug_level;
- int verbose;
-@@ -132,7 +135,7 @@ static struct inum_mapping **hash_table;
- /* Inode creation sequence number */
- static unsigned long long creat_sqnum;
-
--static const char *optstring = "d:r:m:o:D:h?vVe:c:g:f:Fp:k:x:X:j:R:l:j:UQq";
-+static const char *optstring = "d:r:m:o:D:h?vVe:c:g:f:Fp:k:x:X:y:j:R:l:j:UQq";
-
- static const struct option longopts[] = {
- {"root", 1, NULL, 'r'},
-@@ -149,6 +152,7 @@ static const struct option longopts[] =
- {"reserved", 1, NULL, 'R'},
- {"compr", 1, NULL, 'x'},
- {"favor-percent", 1, NULL, 'X'},
-+ {"force-compr", 1, NULL, 'y'},
- {"fanout", 1, NULL, 'f'},
- {"space-fixup", 0, NULL, 'F'},
- {"keyhash", 1, NULL, 'k'},
-@@ -178,11 +182,13 @@ static const char *helptext =
- "-o, --output=FILE output to FILE\n"
- "-j, --jrn-size=SIZE journal size\n"
- "-R, --reserved=SIZE how much space should be reserved for the super-user\n"
--"-x, --compr=TYPE compression type - \"lzo\", \"favor_lzo\", \"zlib\" or\n"
--" \"none\" (default: \"lzo\")\n"
-+"-x, --compr=TYPE default compression type - \"lzo\", \"favor_lzo\",\n"
-+" \"zlib\" or \"none\" (default: \"lzo\")\n"
- "-X, --favor-percent may only be used with favor LZO compression and defines\n"
- " how many percent better zlib should compress to make\n"
- " mkfs.ubifs use zlib instead of LZO (default 20%)\n"
-+"-y, --force-compr=TYPE force to build the fs with different compression -\n"
-+" \"lzo\", \"zlib\" or \"none\"\n"
- "-f, --fanout=NUM fanout NUM (default: 8)\n"
- "-F, --space-fixup file-system free space has to be fixed up on first mount\n"
- " (requires kernel version 3.0 or greater)\n"
-@@ -530,6 +536,43 @@ static int open_ubi(const char *node)
- return 0;
- }
-
-+static const char *get_compr_str(int compr)
-+{
-+ switch (compr) {
-+ case UBIFS_COMPR_LZO:
-+ return "lzo";
-+ case UBIFS_COMPR_ZLIB:
-+ return "zlib";
-+ case UBIFS_COMPR_XZ:
-+ return "xz";
-+ case UBIFS_COMPR_NONE:
-+ return "none";
-+ }
-+
-+ return "unknown";
-+}
-+
-+static int get_compr_option(char *opt, int *compr_type, int *favor_lzo)
-+{
-+ *compr_type = UBIFS_COMPR_LZO;
-+
-+ if (favor_lzo)
-+ *favor_lzo = 0;
-+
-+ if (favor_lzo && strcmp(optarg, "favor_lzo") == 0)
-+ *favor_lzo = 1;
-+ else if (strcmp(optarg, "zlib") == 0)
-+ *compr_type = UBIFS_COMPR_ZLIB;
-+ else if (strcmp(optarg, "xz") == 0)
-+ *compr_type = UBIFS_COMPR_XZ;
-+ else if (strcmp(optarg, "none") == 0)
-+ *compr_type = UBIFS_COMPR_NONE;
-+ else if (strcmp(optarg, "lzo") != 0)
-+ return -1;
-+
-+ return 0;
-+}
-+
- static int get_options(int argc, char**argv)
- {
- int opt, i;
-@@ -649,14 +692,13 @@ static int get_options(int argc, char**a
- return err_msg("bad key hash");
- break;
- case 'x':
-- if (strcmp(optarg, "favor_lzo") == 0)
-- c->favor_lzo = 1;
-- else if (strcmp(optarg, "zlib") == 0)
-- c->default_compr = UBIFS_COMPR_ZLIB;
-- else if (strcmp(optarg, "none") == 0)
-- c->default_compr = UBIFS_COMPR_NONE;
-- else if (strcmp(optarg, "lzo") != 0)
-- return err_msg("bad compressor name");
-+ if (get_compr_option(optarg, &c->default_compr,
-+ &c->favor_lzo))
-+ return err_msg("bad compressor name '%s'",
-+ optarg);
-+ if (c->default_compr == UBIFS_COMPR_XZ)
-+ return err_msg("'%s' can't be used as default compressor",
-+ optarg);
- break;
- case 'X':
- c->favor_percent = strtol(optarg, &endp, 0);
-@@ -665,6 +707,12 @@ static int get_options(int argc, char**a
- return err_msg("bad favor LZO percent '%s'",
- optarg);
- break;
-+ case 'y':
-+ if (get_compr_option(optarg, &force_compr, NULL))
-+ return err_msg("bad forced compressor name '%s'",
-+ optarg);
-+ force_compr_set = 1;
-+ break;
- case 'j':
- c->max_bud_bytes = get_bytes(optarg);
- if (c->max_bud_bytes <= 0)
-@@ -749,6 +797,9 @@ static int get_options(int argc, char**a
- c->min_io_size = 8;
- c->rp_size = add_space_overhead(c->rp_size);
-
-+ if (force_compr_set == 0)
-+ force_compr = c->default_compr;
-+
- if (verbose) {
- printf("mkfs.ubifs\n");
- printf("\troot: %s\n", root);
-@@ -758,17 +809,10 @@ static int get_options(int argc, char**a
- printf("\toutput: %s\n", output);
- printf("\tjrn_size: %llu\n", c->max_bud_bytes);
- printf("\treserved: %llu\n", c->rp_size);
-- switch (c->default_compr) {
-- case UBIFS_COMPR_LZO:
-- printf("\tcompr: lzo\n");
-- break;
-- case UBIFS_COMPR_ZLIB:
-- printf("\tcompr: zlib\n");
-- break;
-- case UBIFS_COMPR_NONE:
-- printf("\tcompr: none\n");
-- break;
-- }
-+ printf("\tcompr: %s\n", get_compr_str(c->default_compr));
-+ if (force_compr_set)
-+ printf("\tforced compr: %s\n",
-+ get_compr_str(force_compr));
- printf("\tkeyhash: %s\n", (c->key_hash == key_r5_hash) ?
- "r5" : "test");
- printf("\tfanout: %d\n", c->fanout);
-@@ -1353,7 +1397,7 @@ static int add_file(const char *path_nam
- use_compr = UBIFS_COMPR_LZO;
- else
- #endif
-- use_compr = c->default_compr;
-+ use_compr = force_compr;
- compr_type = compress_data(buf, bytes_read, &dn->data,
- &out_len, use_compr);
- dn->compr_type = cpu_to_le16(compr_type);
---- a/mkfs.ubifs/mkfs.ubifs.h
-+++ b/mkfs.ubifs/mkfs.ubifs.h
-@@ -77,6 +77,9 @@
- #if MKFS_UBIFS_COMPR_ZLIB != UBIFS_COMPR_ZLIB
- #error MKFS_UBIFS_COMPR_ZLIB != UBIFS_COMPR_ZLIB
- #endif
-+#if MKFS_UBIFS_COMPR_XZ != UBIFS_COMPR_XZ
-+#error MKFS_UBIFS_COMPR_XZ != UBIFS_COMPR_XZ
-+#endif
-
- extern int verbose;
- extern int debug_level;
---- a/mkfs.ubifs/ubifs-media.h
-+++ b/mkfs.ubifs/ubifs-media.h
-@@ -303,6 +303,7 @@ enum {
- UBIFS_COMPR_NONE,
- UBIFS_COMPR_LZO,
- UBIFS_COMPR_ZLIB,
-+ UBIFS_COMPR_XZ,
- UBIFS_COMPR_TYPES_CNT,
- };
-
diff --git a/tools/mtd-utils/patches/200-libubigen-add-ubigen_write_terminator-function.patch b/tools/mtd-utils/patches/200-libubigen-add-ubigen_write_terminator-function.patch
new file mode 100644
index 00000000000..d95ece184c7
--- /dev/null
+++ b/tools/mtd-utils/patches/200-libubigen-add-ubigen_write_terminator-function.patch
@@ -0,0 +1,89 @@
+--- a/lib/libubigen.c
++++ b/lib/libubigen.c
+@@ -122,8 +122,9 @@ int ubigen_add_volume(const struct ubige
+ return 0;
+ }
+
+-void ubigen_init_ec_hdr(const struct ubigen_info *ui,
+- struct ubi_ec_hdr *hdr, long long ec)
++static void __ubigen_init_ec_hdr(const struct ubigen_info *ui,
++ struct ubi_ec_hdr *hdr, long long ec,
++ int eof)
+ {
+ uint32_t crc;
+
+@@ -136,10 +137,22 @@ void ubigen_init_ec_hdr(const struct ubi
+ hdr->data_offset = cpu_to_be32(ui->data_offs);
+ hdr->image_seq = cpu_to_be32(ui->image_seq);
+
++ if (eof) {
++ hdr->padding1[0] = 'E';
++ hdr->padding1[1] = 'O';
++ hdr->padding1[2] = 'F';
++ }
++
+ crc = mtd_crc32(UBI_CRC32_INIT, hdr, UBI_EC_HDR_SIZE_CRC);
+ hdr->hdr_crc = cpu_to_be32(crc);
+ }
+
++void ubigen_init_ec_hdr(const struct ubigen_info *ui,
++ struct ubi_ec_hdr *hdr, long long ec)
++{
++ __ubigen_init_ec_hdr(ui, hdr, ec, 0);
++}
++
+ void ubigen_init_vid_hdr(const struct ubigen_info *ui,
+ const struct ubigen_vol_info *vi,
+ struct ubi_vid_hdr *hdr, int lnum,
+@@ -307,6 +320,39 @@ int ubigen_write_layout_vol(const struct
+ }
+
+ free(outbuf);
++ return 0;
++
++out_free:
++ free(outbuf);
++ return -1;
++}
++
++int ubigen_write_eof_markers(const struct ubigen_info *ui, long long ec,
++ int count, int out_fd)
++{
++ char *outbuf;
++ int peb_size = ui->peb_size;
++
++ outbuf = malloc(peb_size);
++ if (!outbuf) {
++ sys_errmsg("cannot allocate %d bytes of memory", peb_size);
++ return -1;
++ }
++
++ memset(outbuf, 0xFF, peb_size);
++ __ubigen_init_ec_hdr(ui, (struct ubi_ec_hdr *)outbuf, ec, 1);
++
++ while (count) {
++ if (write(out_fd, outbuf, peb_size) != peb_size) {
++ sys_errmsg("cannot write %d bytes to the output file",
++ peb_size);
++ goto out_free;
++ }
++
++ count--;
++ }
++
++ free(outbuf);
+ return 0;
+
+ out_free:
+--- a/include/libubigen.h
++++ b/include/libubigen.h
+@@ -188,6 +188,9 @@ int ubigen_write_layout_vol(const struct
+ long long ec1, long long ec2,
+ struct ubi_vtbl_record *vtbl, int fd);
+
++int ubigen_write_eof_markers(const struct ubigen_info *ui, long long ec,
++ int count, int out_fd);
++
+ #ifdef __cplusplus
+ }
+ #endif
diff --git a/tools/mtd-utils/patches/201-ubinize-add-terminator-support.patch b/tools/mtd-utils/patches/201-ubinize-add-terminator-support.patch
new file mode 100644
index 00000000000..0da28b71f2e
--- /dev/null
+++ b/tools/mtd-utils/patches/201-ubinize-add-terminator-support.patch
@@ -0,0 +1,68 @@
+--- a/ubi-utils/ubinize.c
++++ b/ubi-utils/ubinize.c
+@@ -60,6 +60,8 @@ static const char optionsstr[] =
+ " (default is 1)\n"
+ "-Q, --image-seq=<num> 32-bit UBI image sequence number to use\n"
+ " (by default a random number is picked)\n"
++"-E, --eof-markers=<num> number of eof-markers to put at the end of the\n"
++" output image\n"
+ "-v, --verbose be verbose\n"
+ "-h, --help print help message\n"
+ "-V, --version print program version\n\n";
+@@ -79,6 +81,7 @@ static const struct option long_options[
+ { .name = "erase-counter", .has_arg = 1, .flag = NULL, .val = 'e' },
+ { .name = "ubi-ver", .has_arg = 1, .flag = NULL, .val = 'x' },
+ { .name = "image-seq", .has_arg = 1, .flag = NULL, .val = 'Q' },
++ { .name = "eof-markers", .has_arg = 1, .flag = NULL, .val = 'E' },
+ { .name = "verbose", .has_arg = 0, .flag = NULL, .val = 'v' },
+ { .name = "help", .has_arg = 0, .flag = NULL, .val = 'h' },
+ { .name = "version", .has_arg = 0, .flag = NULL, .val = 'V' },
+@@ -98,6 +101,7 @@ struct args {
+ uint32_t image_seq;
+ int verbose;
+ dictionary *dict;
++ int eof_markers;
+ };
+
+ static struct args args = {
+@@ -116,7 +120,7 @@ static int parse_opt(int argc, char * co
+ int key, error = 0;
+ unsigned long int image_seq;
+
+- key = getopt_long(argc, argv, "o:p:m:s:O:e:x:Q:vhV", long_options, NULL);
++ key = getopt_long(argc, argv, "o:p:m:s:O:e:x:Q:E:vhV", long_options, NULL);
+ if (key == -1)
+ break;
+
+@@ -176,6 +180,12 @@ static int parse_opt(int argc, char * co
+ args.image_seq = image_seq;
+ break;
+
++ case 'E':
++ args.eof_markers = simple_strtoul(optarg, &error);
++ if (error)
++ return errmsg("bad number of eof-markers: \"%s\"", optarg);
++ break;
++
+ case 'v':
+ args.verbose = 1;
+ break;
+@@ -559,6 +569,18 @@ int main(int argc, char * const argv[])
+ printf("\n");
+ }
+
++ if (args.eof_markers) {
++ verbose(args.verbose, "writing %d eof-marker blocks",
++ args.eof_markers);
++
++ err = ubigen_write_eof_markers(&ui, args.ec, args.eof_markers,
++ args.out_fd);
++ if (err) {
++ errmsg("cannot write eof-marker blocks");
++ goto out_free;
++ }
++ }
++
+ verbose(args.verbose, "writing layout volume");
+
+ err = ubigen_write_layout_vol(&ui, 0, 1, args.ec, args.ec, vtbl, args.out_fd);
diff --git a/tools/mtd-utils/patches/320-mkfs.jffs2-SOURCE_DATE_EPOCH.patch b/tools/mtd-utils/patches/320-mkfs.jffs2-SOURCE_DATE_EPOCH.patch
new file mode 100644
index 00000000000..8e580595769
--- /dev/null
+++ b/tools/mtd-utils/patches/320-mkfs.jffs2-SOURCE_DATE_EPOCH.patch
@@ -0,0 +1,60 @@
+--- a/jffsX-utils/mkfs.jffs2.c
++++ b/jffsX-utils/mkfs.jffs2.c
+@@ -109,7 +109,7 @@ static char *rootdir = default_rootdir;
+ static int verbose = 0;
+ static int squash_uids = 0;
+ static int squash_perms = 0;
+-static int fake_times = 0;
++static time_t fixed_timestamp = -1;
+ int target_endian = __BYTE_ORDER;
+
+ static uint32_t find_hardlink(struct filesystem_entry *e)
+@@ -250,8 +250,8 @@ static struct filesystem_entry *add_host
+ mode &= ~(S_ISUID | S_ISGID);
+ }
+ }
+- if (fake_times) {
+- timestamp = 0;
++ if (fixed_timestamp != -1) {
++ timestamp = fixed_timestamp;
+ }
+
+ entry = xcalloc(1, sizeof(struct filesystem_entry));
+@@ -1557,6 +1557,20 @@ static void parse_image(void){
+ close(in_fd);
+ }
+
++static void set_source_date_epoch() {
++ char *env = getenv("SOURCE_DATE_EPOCH");
++ char *endptr = env;
++ errno = 0;
++ if (env && *env) {
++ fixed_timestamp = strtoull(env, &endptr, 10);
++ if (errno || (endptr && *endptr != '\0')) {
++ fprintf(stderr, "Invalid SOURCE_DATE_EPOCH");
++ exit(1);
++ }
++ }
++}
++
++
+ int main(int argc, char **argv)
+ {
+ int c, opt;
+@@ -1575,6 +1589,7 @@ int main(int argc, char **argv)
+ warn_page_size = 1; /* warn user if page size not 4096 */
+
+ jffs2_compressors_init();
++ set_source_date_epoch();
+
+ while ((opt = getopt_long(argc, argv,
+ "D:d:r:s:o:qUPfh?vVe:lbp::nc:m:x:X:Lty:i:", long_options, &c)) >= 0)
+@@ -1625,7 +1640,7 @@ int main(int argc, char **argv)
+ break;
+
+ case 'f':
+- fake_times = 1;
++ fixed_timestamp = 0;
+ break;
+
+ case 'h':