Browse Source

mtd-utils: allow host-tools to compile on Darwin

Signed-off-by: Waldemar Brodkorb <wbx@openadk.org>
Waldemar Brodkorb 7 years ago
parent
commit
7d9d71e67f

+ 6 - 2
package/mtd-utils/Makefile

@@ -5,13 +5,13 @@ include $(ADK_TOPDIR)/rules.mk
 
 PKG_NAME:=		mtd-utils
 PKG_VERSION:=		2.0.0
-PKG_RELEASE:=		1
+PKG_RELEASE:=		2
 PKG_HASH:=		20a377aa86af4c102e930b0d0bb9859e3a10aeb16445f6a1273989b206a717c8
 PKG_DESCR:=		flash filesystem utilities
 PKG_SECTION:=		sys/fs
 PKG_DEPENDS:=		libuuid liblzo
 PKG_BUILDDEP:=		zlib util-linux liblzo
-HOST_BUILDDEP:=		liblzo-host zlib-host
+HOST_BUILDDEP:=		liblzo-host zlib-host util-linux-host
 PKG_URL:=		http://www.linux-mtd.infradead.org
 PKG_SITES:=		ftp://ftp.infradead.org/pub/mtd-utils/
 
@@ -44,8 +44,12 @@ $(eval $(call PKG_template,FLASH_OTP_DUMP,flash-otp-dump,$(PKG_VERSION)-${PKG_RE
 $(eval $(call PKG_template,FLASH_LOCK,flash-lock,$(PKG_VERSION)-${PKG_RELEASE},${PKG_DEPENDS},${PKGSD_FLASH_LOCK},${PKG_SECTION}))
 
 HOST_STYLE:=		auto
+HOST_CONFIGURE_ARGS+=	--disable-tests
 HOST_CPPFLAGS+=		-DWITHOUT_XATTR=1 -I./include
 HOST_MAKE_FLAGS+=	WITHOUT_LZO=1
+ifeq ($(OS_FOR_BUILD),Darwin)
+HOST_CPPFLAGS+=		-D_DARWIN_C_SOURCE
+endif
 
 host-build:
 	(cd ${WRKBUILD} && env ${HOST_MAKE_ENV} ${MAKE} -f ${MAKE_FILE} \

+ 11 - 0
package/mtd-utils/patches/patch-Makefile_in

@@ -0,0 +1,11 @@
+--- mtd-utils-2.0.0.orig/Makefile.in	2016-12-22 11:21:54.000000000 +0100
++++ mtd-utils-2.0.0/Makefile.in	2017-04-26 09:13:34.000000000 +0200
+@@ -232,7 +232,7 @@ am__EXEEXT_11 = ftl_format$(EXEEXT) doc_
+ 	flash_lock$(EXEEXT) flash_unlock$(EXEEXT) \
+ 	flash_otp_info$(EXEEXT) flash_otp_dump$(EXEEXT) \
+ 	flash_otp_lock$(EXEEXT) flash_otp_write$(EXEEXT) \
+-	flashcp$(EXEEXT) mtdpart$(EXEEXT)
++	flashcp$(EXEEXT)
+ am__EXEEXT_12 = nanddump$(EXEEXT) nandwrite$(EXEEXT) nandtest$(EXEEXT) \
+ 	nftldump$(EXEEXT) nftl_format$(EXEEXT)
+ am__EXEEXT_13 = rfddump$(EXEEXT) rfdformat$(EXEEXT)

+ 19 - 0
package/mtd-utils/patches/patch-include_common_h

@@ -0,0 +1,19 @@
+--- mtd-utils-2.0.0.orig/include/common.h	2016-12-14 10:06:35.000000000 +0100
++++ mtd-utils-2.0.0/include/common.h	2017-04-26 01:52:28.000000000 +0200
+@@ -26,10 +26,15 @@
+ #include <string.h>
+ #include <fcntl.h>
+ #include <errno.h>
++#ifndef __APPLE__
+ #include <features.h>
++#include <sys/sysmacros.h>
++#endif
+ #include <inttypes.h>
+ #include <unistd.h>
+-#include <sys/sysmacros.h>
++
++#include <time.h>
++#include "os-compat.h"
+ 
+ #include "config.h"
+ 

+ 11 - 0
package/mtd-utils/patches/patch-include_mtd_ubi-media_h

@@ -0,0 +1,11 @@
+--- mtd-utils-2.0.0.orig/include/mtd/ubi-media.h	2016-07-12 14:16:45.000000000 +0200
++++ mtd-utils-2.0.0/include/mtd/ubi-media.h	2017-04-25 21:14:34.000000000 +0200
+@@ -30,7 +30,7 @@
+ #ifndef __UBI_MEDIA_H__
+ #define __UBI_MEDIA_H__
+ 
+-#include <asm/byteorder.h>
++#include <linux/types.h>
+ 
+ /* The version of UBI images supported by this implementation */
+ #define UBI_VERSION 1

+ 11 - 0
package/mtd-utils/patches/patch-include_mtd_ubifs-media_h

@@ -0,0 +1,11 @@
+--- mtd-utils-2.0.0.orig/include/mtd/ubifs-media.h	2016-07-12 14:16:45.000000000 +0200
++++ mtd-utils-2.0.0/include/mtd/ubifs-media.h	2017-04-25 21:47:14.000000000 +0200
+@@ -33,7 +33,7 @@
+ #ifndef __UBIFS_MEDIA_H__
+ #define __UBIFS_MEDIA_H__
+ 
+-#include <asm/byteorder.h>
++#include <linux/types.h>
+ 
+ /* UBIFS node magic number (must not have the padding byte first or last) */
+ #define UBIFS_NODE_MAGIC  0x06101831

+ 11 - 0
package/mtd-utils/patches/patch-jffsX-utils_rbtree_h

@@ -0,0 +1,11 @@
+--- mtd-utils-2.0.0.orig/jffsX-utils/rbtree.h	2016-07-12 14:16:45.000000000 +0200
++++ mtd-utils-2.0.0/jffsX-utils/rbtree.h	2017-04-26 02:27:35.000000000 +0200
+@@ -94,7 +94,7 @@ static inline struct page * rb_insert_pa
+ #ifndef	_LINUX_RBTREE_H
+ #define	_LINUX_RBTREE_H
+ 
+-#include <linux/kernel.h>
++#include <endian.h>
+ #include <linux/stddef.h>
+ 
+ struct rb_node

+ 10 - 0
package/mtd-utils/patches/patch-misc-utils_docfdisk_c

@@ -0,0 +1,10 @@
+--- mtd-utils-2.0.0.orig/misc-utils/docfdisk.c	2016-12-14 10:06:35.000000000 +0100
++++ mtd-utils-2.0.0/misc-utils/docfdisk.c	2017-04-26 08:56:40.000000000 +0200
+@@ -19,6 +19,7 @@
+ #define PROGRAM_NAME "docfdisk"
+ 
+ #define _XOPEN_SOURCE 500 /* for pread/pwrite */
++#include <sys/types.h>
+ #include <unistd.h>
+ #include <stdlib.h>
+ #include <stdio.h>

+ 13 - 0
package/mtd-utils/patches/patch-misc-utils_recv_image_c

@@ -0,0 +1,13 @@
+--- mtd-utils-2.0.0.orig/misc-utils/recv_image.c	2016-07-12 14:16:45.000000000 +0200
++++ mtd-utils-2.0.0/misc-utils/recv_image.c	2017-04-26 09:06:48.000000000 +0200
+@@ -4,6 +4,10 @@
+ #define _BSD_SOURCE	/* struct ip_mreq */
+ #define _DEFAULT_SOURCE
+ 
++#ifndef IPV6_ADD_MEMBERSHIP
++#define IPV6_ADD_MEMBERSHIP	20
++#endif
++
+ #include <errno.h>
+ #include <stdio.h>
+ #include <netdb.h>

+ 10 - 0
package/mtd-utils/patches/patch-nand-utils_nftl_format_c

@@ -0,0 +1,10 @@
+--- mtd-utils-2.0.0.orig/nand-utils/nftl_format.c	2016-12-14 10:06:35.000000000 +0100
++++ mtd-utils-2.0.0/nand-utils/nftl_format.c	2017-04-26 08:57:07.000000000 +0200
+@@ -23,6 +23,7 @@
+ #define PROGRAM_NAME "nftl_format"
+ 
+ #define _XOPEN_SOURCE 500 /* for pread/pwrite */
++#include <sys/types.h>
+ #include <unistd.h>
+ #include <stdlib.h>
+ #include <stdio.h>

+ 18 - 0
package/mtd-utils/patches/patch-ubifs-utils_mkfs_ubifs_defs_h

@@ -0,0 +1,18 @@
+--- mtd-utils-2.0.0.orig/ubifs-utils/mkfs.ubifs/defs.h	2016-07-12 14:16:45.000000000 +0200
++++ mtd-utils-2.0.0/ubifs-utils/mkfs.ubifs/defs.h	2017-04-26 01:55:07.000000000 +0200
+@@ -39,6 +39,7 @@ struct qstr
+ 	size_t len;
+ };
+ 
++#ifndef __APPLE__
+ /**
+  * fls - find last (most-significant) bit set
+  * @x: the word to search
+@@ -74,6 +75,7 @@ static inline int fls(int x)
+ 	}
+ 	return r;
+ }
++#endif
+ 
+ #define do_div(n,base) ({ \
+ int __res; \

+ 28 - 0
package/mtd-utils/src/include/asm/types.h

@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) Bernhard Walle <bernhard@bwalle.de>, 2012
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Comatibility with BSD-like userland.
+ */
+#ifndef ASM_TYPES_H_
+#define ASM_TYPES_H_
+
+#ifdef __linux__
+#include_next <asm/types.h>
+#endif
+
+#endif /* ASM_TYPES_H_ */
+

+ 56 - 0
package/mtd-utils/src/include/byteswap.h

@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) Bernhard Walle <bernhard@bwalle.de>, 2012
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Comatibility with BSD-like userland.
+ */
+#ifndef BYTESWAP_H_
+#define BYTESWAP_H_
+
+#ifdef __linux__
+#include_next <byteswap.h>
+#else
+
+#include <stdint.h>
+
+static inline uint16_t bswap_16(uint16_t value)
+{
+    return ((value & 0xff00) >> 8) | ((value & 0xff) << 8);
+}
+
+static inline uint32_t bswap_32(uint32_t value)
+{
+    return ((value & 0xff000000) >> 24) |
+           ((value & 0x00ff0000) >>  8) |
+           ((value & 0x0000ff00) <<  8) |
+           ((value & 0x000000ff) << 24);
+}
+
+static inline uint64_t bswap_64(uint64_t value)
+{
+    return ((value & 0xff00000000000000ull) >> 56) |
+           ((value & 0x00ff000000000000ull) >> 40) |
+           ((value & 0x0000ff0000000000ull) >> 24) |
+           ((value & 0x000000ff00000000ull) >>  8) |
+           ((value & 0x00000000ff000000ull) <<  8) |
+           ((value & 0x0000000000ff0000ull) << 24) |
+           ((value & 0x000000000000ff00ull) << 40) |
+           ((value & 0x00000000000000ffull) << 56);
+}
+
+#endif
+
+#endif /* BYTESWAP_H_ */

+ 41 - 0
package/mtd-utils/src/include/endian.h

@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) Bernhard Walle <bernhard@bwalle.de>, 2012
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Comatibility with BSD-like userland.
+ */
+#ifndef ENDIAN_H_
+#define ENDIAN_H_
+
+#ifdef __linux__
+#include_next <endian.h>
+#elif __APPLE__
+
+#include <machine/endian.h>
+
+#ifndef __DARWIN_BYTE_ORDER
+#error "No __DARWIN_BYTE_ORDER defined"
+#endif
+
+#define __BYTE_ORDER		__DARWIN_BYTE_ORDER
+#define __LITTLE_ENDIAN		__DARWIN_LITTLE_ENDIAN
+#define __BIG_ENDIAN		__DARWIN_BIG_ENDIAN
+
+#else
+#error "No byteswap.h found"
+#endif
+
+#endif /* ENDIAN_H_ */

+ 71 - 0
package/mtd-utils/src/include/linux/fs.h

@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) Bernhard Walle <bernhard@bwalle.de>, 2012
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Comatibility with BSD-like userland.
+ */
+#ifndef LINUX_FS_H_
+#define LINUX_FS_H_
+
+#ifdef __linux__
+#include_next <linux/fs.h>
+#else
+
+#define FS_IOC_GETFLAGS                 _IOR('f', 1, long)
+#define FS_IOC_SETFLAGS                 _IOW('f', 2, long)
+#define FS_IOC_GETVERSION               _IOR('v', 1, long)
+#define FS_IOC_SETVERSION               _IOW('v', 2, long)
+#define FS_IOC_FIEMAP                   _IOWR('f', 11, struct fiemap)
+#define FS_IOC32_GETFLAGS               _IOR('f', 1, int)
+#define FS_IOC32_SETFLAGS               _IOW('f', 2, int)
+#define FS_IOC32_GETVERSION             _IOR('v', 1, int)
+#define FS_IOC32_SETVERSION             _IOW('v', 2, int)
+
+/*
+ * Inode flags (FS_IOC_GETFLAGS / FS_IOC_SETFLAGS)
+ */
+#define FS_SECRM_FL                     0x00000001 /* Secure deletion */
+#define FS_UNRM_FL                      0x00000002 /* Undelete */
+#define FS_COMPR_FL                     0x00000004 /* Compress file */
+#define FS_SYNC_FL                      0x00000008 /* Synchronous updates */
+#define FS_IMMUTABLE_FL                 0x00000010 /* Immutable file */
+#define FS_APPEND_FL                    0x00000020 /* writes to file may only append */
+#define FS_NODUMP_FL                    0x00000040 /* do not dump file */
+#define FS_NOATIME_FL                   0x00000080 /* do not update atime */
+/* Reserved for compression usage... */
+#define FS_DIRTY_FL                     0x00000100
+#define FS_COMPRBLK_FL                  0x00000200 /* One or more compressed clusters */
+#define FS_NOCOMP_FL                    0x00000400 /* Don't compress */
+#define FS_ECOMPR_FL                    0x00000800 /* Compression error */
+/* End compression flags --- maybe not all used */
+#define FS_BTREE_FL                     0x00001000 /* btree format dir */
+#define FS_INDEX_FL                     0x00001000 /* hash-indexed directory */
+#define FS_IMAGIC_FL                    0x00002000 /* AFS directory */
+#define FS_JOURNAL_DATA_FL              0x00004000 /* Reserved for ext3 */
+#define FS_NOTAIL_FL                    0x00008000 /* file tail should not be merged */
+#define FS_DIRSYNC_FL                   0x00010000 /* dirsync behaviour (directories only) */
+#define FS_TOPDIR_FL                    0x00020000 /* Top of directory hierarchies*/
+#define FS_EXTENT_FL                    0x00080000 /* Extents */
+#define FS_DIRECTIO_FL                  0x00100000 /* Use direct i/o */
+#define FS_NOCOW_FL                     0x00800000 /* Do not cow file */
+#define FS_RESERVED_FL                  0x80000000 /* reserved for ext2 lib */
+
+#define FS_FL_USER_VISIBLE              0x0003DFFF /* User visible flags */
+#define FS_FL_USER_MODIFIABLE           0x000380FF /* User modifiable flags */
+
+#endif
+
+#endif /* LINUX_FS_H_ */

+ 27 - 0
package/mtd-utils/src/include/linux/stddef.h

@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) Bernhard Walle <bernhard@bwalle.de>, 2012
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Comatibility with BSD-like userland.
+ */
+#ifndef LINUX_STDDEF_H_
+#define LINUX_STDDEF_H_
+
+#ifdef __linux__
+#include_next <linux/stddef.h>
+#endif
+
+#endif /* LINUX_STDDEF_H_ */

+ 62 - 0
package/mtd-utils/src/include/linux/types.h

@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) Bernhard Walle <bernhard@bwalle.de>, 2012
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Comatibility with BSD-like userland.
+ */
+#ifndef LINUX_TYPES_H_
+#define LINUX_TYPES_H_
+
+#ifdef __linux__
+#include_next <linux/types.h>
+#else
+
+#include <stdint.h>     /* get uint8_t etc. */
+#include <sys/types.h>  /* get u_long etc. */
+
+/* This types are provided to Linux userland */
+
+typedef uint8_t		__u8;
+typedef uint16_t	__u16;
+typedef uint32_t	__u32;
+typedef uint64_t	__u64;
+
+typedef int8_t		__s8;
+typedef int16_t		__s16;
+typedef int32_t		__s32;
+typedef int64_t		__s64;
+
+/*
+ * The type itself has no endianess. It's only used for code checkers
+ * but we don't need to run that checkers on non-Linux OSes
+ */
+typedef __u16       __le16;
+typedef __u16       __be16;
+typedef __u32       __le32;
+typedef __u32       __be32;
+typedef __u64       __le64;
+typedef __u64       __be64;
+
+/* from /usr/include/asm-generic/posix_types.h on Linux */
+typedef long        __kernel_off_t;
+typedef long long   __kernel_loff_t;
+
+typedef long long   loff_t;
+typedef long long   off64_t;
+
+#endif
+
+#endif /* LINUX_TYPES_H_ */

+ 31 - 0
package/mtd-utils/src/include/os-compat.h

@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) Bernhard Walle <bernhard@bwalle.de>, 2012
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Comatibility with BSD-like userland.
+ */
+#ifndef OS_COMPAT_H_
+#define OS_COMPAT_H_
+
+#ifdef __APPLE__
+
+/* off_t is already 64 bits wide, even on i386 */
+#define O_LARGEFILE 0
+#define lseek64(fd, offset, whence) lseek((fd), (offset), (whence))
+
+#endif /* __APPLE__ */
+
+#endif /* OS_COMPAT_H_ */