* [PATCH 01/18] kbuild: suppress warnings from 'getconf LFS_*'
2019-05-27 9:57 [PATCH 00/18] scripts: enable compilation on macOS Ahmad Fatoum
@ 2019-05-27 9:57 ` Ahmad Fatoum
2019-05-27 9:57 ` [PATCH 02/18] kbuild: Use ls(1) instead of stat(1) to obtain file size Ahmad Fatoum
` (17 subsequent siblings)
18 siblings, 0 replies; 20+ messages in thread
From: Ahmad Fatoum @ 2019-05-27 9:57 UTC (permalink / raw)
To: barebox
From: Masahiro Yamada <yamada.masahiro@socionext.com>
Suppress warnings for systems that do not recognize LFS_*.
getconf: no such configuration parameter `LFS_CFLAGS'
getconf: no such configuration parameter `LFS_LDFLAGS'
getconf: no such configuration parameter `LFS_LIBS'
Fixes: d7f14c66c273 ("kbuild: Enable Large File Support for hostprogs")
Reported-by: Chen Feng <puck.chen@hisilicon.com>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Acked-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
Makefile | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/Makefile b/Makefile
index 29347b67803c..c09a58026af6 100644
--- a/Makefile
+++ b/Makefile
@@ -177,9 +177,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
else if [ -x /bin/bash ]; then echo /bin/bash; \
else echo sh; fi ; fi)
-HOST_LFS_CFLAGS := $(shell getconf LFS_CFLAGS)
-HOST_LFS_LDFLAGS := $(shell getconf LFS_LDFLAGS)
-HOST_LFS_LIBS := $(shell getconf LFS_LIBS)
+HOST_LFS_CFLAGS := $(shell getconf LFS_CFLAGS 2>/dev/null)
+HOST_LFS_LDFLAGS := $(shell getconf LFS_LDFLAGS 2>/dev/null)
+HOST_LFS_LIBS := $(shell getconf LFS_LIBS 2>/dev/null)
HOSTCC = gcc
HOSTCXX = g++
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH 02/18] kbuild: Use ls(1) instead of stat(1) to obtain file size
2019-05-27 9:57 [PATCH 00/18] scripts: enable compilation on macOS Ahmad Fatoum
2019-05-27 9:57 ` [PATCH 01/18] kbuild: suppress warnings from 'getconf LFS_*' Ahmad Fatoum
@ 2019-05-27 9:57 ` Ahmad Fatoum
2019-05-27 9:57 ` [PATCH 03/18] scripts: extract symbol offsets using target, not host, nm Ahmad Fatoum
` (16 subsequent siblings)
18 siblings, 0 replies; 20+ messages in thread
From: Ahmad Fatoum @ 2019-05-27 9:57 UTC (permalink / raw)
To: barebox
From: Michael Forney <forney@google.com>
stat(1) is not standardized and different implementations have their own
(conflicting) flags for querying the size of a file.
ls(1) provides the same information (value of st.st_size) in the 5th
column, except when the file is a character or block device. This output
is standardized[0]. The -n option turns on -l, which writes lines
formatted like
"%s %u %s %s %u %s %s\n", <file mode>, <number of links>,
<owner name>, <group name>, <size>, <date and time>,
<pathname>
but instead of writing the <owner name> and <group name>, it writes the
numeric owner and group IDs (this avoids /etc/passwd and /etc/group
lookups as well as potential field splitting issues).
The <size> field is specified as "the value that would be returned for
the file in the st_size field of struct stat".
To avoid duplicating logic in several locations in the tree, create
scripts/file-size.sh and update callers to use that instead of stat(1).
[0] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ls.html#tag_20_73_10
Signed-off-by: Michael Forney <forney@google.com>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
[afa: imported script and adjusted barebox stat(1) callsites]
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
defaultenv/Makefile | 3 ++-
scripts/Makefile.lib | 4 ++--
scripts/file-size.sh | 4 ++++
scripts/gen-dtb-s | 4 ++--
4 files changed, 10 insertions(+), 5 deletions(-)
create mode 100755 scripts/file-size.sh
diff --git a/defaultenv/Makefile b/defaultenv/Makefile
index 950ac29a3cee..e030355a4052 100644
--- a/defaultenv/Makefile
+++ b/defaultenv/Makefile
@@ -20,7 +20,8 @@ $(obj)/barebox_default_env: FORCE
quiet_cmd_env_h = ENVH $@
cmd_env_h = cat $< | (cd $(obj) && $(objtree)/scripts/bin2c "__aligned(4) default_environment") > $@; \
- echo "static const int default_environment_uncompress_size=`stat -c%s $(obj)/barebox_default_env`;" >> $@
+ echo "static const int default_environment_uncompress_size=`${CONFIG_SHELL} \"${srctree}/scripts/file-size.sh\" $(obj)/barebox_default_env`;" >> $@
+
$(obj)/barebox_default_env.h: $(obj)/barebox_default_env$(DEFAULT_COMPRESSION_SUFFIX) FORCE
$(call if_changed,env_h)
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 95eaf522abc9..87bff2d296e3 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -341,7 +341,7 @@ cmd_env=$(srctree)/scripts/genenv $(srctree) $(objtree) $@ $<
size_append = printf $(shell \
dec_size=0; \
for F in $1; do \
- fsize=$$(stat -c "%s" $$F); \
+ fsize=$$(${CONFIG_SHELL} "${srctree}/scripts/file-size.sh" $$F);\
dec_size=$$(expr $$dec_size + $$fsize); \
done; \
printf "%08x\n" $$dec_size | \
@@ -446,7 +446,7 @@ quiet_cmd_check_size = CHKSIZE $2
# Check size of a file
quiet_cmd_check_file_size = CHKFILESIZE $2
cmd_check_file_size = set -e; \
- size=`stat -c%s $2`; \
+ size=`${CONFIG_SHELL} "${srctree}/scripts/file-size.sh" $2`; \
max_size=`printf "%d" $3`; \
if [ $$size -gt $$max_size ] ; \
then \
diff --git a/scripts/file-size.sh b/scripts/file-size.sh
new file mode 100755
index 000000000000..7eb7423416b5
--- /dev/null
+++ b/scripts/file-size.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+set -- $(ls -dn "$1")
+printf '%s\n' "$5"
diff --git a/scripts/gen-dtb-s b/scripts/gen-dtb-s
index 307b1f68667e..b2dd253c274f 100755
--- a/scripts/gen-dtb-s
+++ b/scripts/gen-dtb-s
@@ -55,8 +55,8 @@ lzop -f -9 $dtb -o $dtb.lzo
if [ $? != 0 ]; then
exit 1
fi
-compressed=$(stat $dtb.lzo -c "%s")
-uncompressed=$(stat $dtb -c "%s")
+compressed=$(${CONFIG_SHELL} "${srctree}/scripts/file-size.sh" $dtb.lzo)
+uncompressed=$(${CONFIG_SHELL} "${srctree}/scripts/file-size.sh" $dtb)
echo ".section .dtbz.rodata.${name},\"a\""
echo ".balign STRUCT_ALIGNMENT"
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH 03/18] scripts: extract symbol offsets using target, not host, nm
2019-05-27 9:57 [PATCH 00/18] scripts: enable compilation on macOS Ahmad Fatoum
2019-05-27 9:57 ` [PATCH 01/18] kbuild: suppress warnings from 'getconf LFS_*' Ahmad Fatoum
2019-05-27 9:57 ` [PATCH 02/18] kbuild: Use ls(1) instead of stat(1) to obtain file size Ahmad Fatoum
@ 2019-05-27 9:57 ` Ahmad Fatoum
2019-05-27 9:57 ` [PATCH 04/18] scripts: includes: restrict strlcpy prototype to glibc Ahmad Fatoum
` (15 subsequent siblings)
18 siblings, 0 replies; 20+ messages in thread
From: Ahmad Fatoum @ 2019-05-27 9:57 UTC (permalink / raw)
To: barebox
The nm(1) on other platforms may be compiled without ELF support,
thus use the cross toolchain's nm instead if possible.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
scripts/check_size | 2 +-
| 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/scripts/check_size b/scripts/check_size
index 54f02a63c5ef..8530435d3a1b 100755
--- a/scripts/check_size
+++ b/scripts/check_size
@@ -5,7 +5,7 @@ file="$2"
max="$3"
# extract symbol offset from file, remove leading zeros
-ofs=$(nm -t d $file | grep "$symbol" | cut -d ' ' -f1 | sed "s/^[0]*//")
+ofs=$(${CROSS_COMPILE}nm -t d $file | grep "$symbol" | cut -d ' ' -f1 | sed "s/^[0]*//")
if [ -z "${ofs}" ]; then
echo "symbol $symbol not found in $file"
--git a/scripts/extract_symbol_offset b/scripts/extract_symbol_offset
index 1a1260f526e0..78b866830e56 100755
--- a/scripts/extract_symbol_offset
+++ b/scripts/extract_symbol_offset
@@ -4,7 +4,7 @@ symbol="$1"
file="$2"
# extract symbol offset from file, remove leading zeros
-ofs=$(nm -t d $file | grep "$symbol" | cut -d ' ' -f1 | sed "s/^[0]*//")
+ofs=$(${CROSS_COMPILE}nm -t d $file | grep "$symbol" | cut -d ' ' -f1 | sed "s/^[0]*//")
if [ -z "${ofs}" ]; then
echo "symbol $symbol not found in $file"
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH 04/18] scripts: includes: restrict strlcpy prototype to glibc
2019-05-27 9:57 [PATCH 00/18] scripts: enable compilation on macOS Ahmad Fatoum
` (2 preceding siblings ...)
2019-05-27 9:57 ` [PATCH 03/18] scripts: extract symbol offsets using target, not host, nm Ahmad Fatoum
@ 2019-05-27 9:57 ` Ahmad Fatoum
2019-05-27 9:57 ` [PATCH 05/18] scripts: compiler.h: don't include <stdint.h> twice Ahmad Fatoum
` (14 subsequent siblings)
18 siblings, 0 replies; 20+ messages in thread
From: Ahmad Fatoum @ 2019-05-27 9:57 UTC (permalink / raw)
To: barebox
Defining strlcpy here clashes on macOS, which has some compiler magic
around their strlcpy declaration. Fix this by inverting the check
to declare the prototype only if we are on __GLIBC__. As uClibc may
define __GLIBC__ as well, check for absence of its __UCLIBC__.
This is in-line with what Linux has been doing since 0215d59b15
("tools lib: Reinstate strlcpy() header guard with __UCLIBC__").
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
scripts/include/linux/string.h | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/scripts/include/linux/string.h b/scripts/include/linux/string.h
index e26223f1f287..649287b80a8c 100644
--- a/scripts/include/linux/string.h
+++ b/scripts/include/linux/string.h
@@ -8,7 +8,11 @@ void *memdup(const void *src, size_t len);
int strtobool(const char *s, bool *res);
-#ifndef __UCLIBC__
+/*
+ * glibc based builds needs the extern while uClibc doesn't.
+ * However uClibc headers also define __GLIBC__ hence the hack below
+ */
+#if defined(__GLIBC) && !defined(__UCLIBC__)
extern size_t strlcpy(char *dest, const char *src, size_t size);
#endif
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH 05/18] scripts: compiler.h: don't include <stdint.h> twice
2019-05-27 9:57 [PATCH 00/18] scripts: enable compilation on macOS Ahmad Fatoum
` (3 preceding siblings ...)
2019-05-27 9:57 ` [PATCH 04/18] scripts: includes: restrict strlcpy prototype to glibc Ahmad Fatoum
@ 2019-05-27 9:57 ` Ahmad Fatoum
2019-05-27 9:57 ` [PATCH 06/18] scripts: don't depend on system <asm/types.h> Ahmad Fatoum
` (13 subsequent siblings)
18 siblings, 0 replies; 20+ messages in thread
From: Ahmad Fatoum @ 2019-05-27 9:57 UTC (permalink / raw)
To: barebox
We already include it a few lines further down, so drop it at this
location.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
scripts/compiler.h | 2 --
1 file changed, 2 deletions(-)
diff --git a/scripts/compiler.h b/scripts/compiler.h
index 4cf179bb9b13..bd73c7a9a8d3 100644
--- a/scripts/compiler.h
+++ b/scripts/compiler.h
@@ -13,8 +13,6 @@
defined(__sun__) || \
defined(__APPLE__)
# include <inttypes.h>
-#elif defined(__linux__) || defined(__WIN32__) || defined(__MINGW32__)
-# include <stdint.h>
#endif
#include <errno.h>
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH 06/18] scripts: don't depend on system <asm/types.h>
2019-05-27 9:57 [PATCH 00/18] scripts: enable compilation on macOS Ahmad Fatoum
` (4 preceding siblings ...)
2019-05-27 9:57 ` [PATCH 05/18] scripts: compiler.h: don't include <stdint.h> twice Ahmad Fatoum
@ 2019-05-27 9:57 ` Ahmad Fatoum
2019-05-27 9:57 ` [PATCH 07/18] scripts: bareboxcrc32: remove usage of loff_t Ahmad Fatoum
` (12 subsequent siblings)
18 siblings, 0 replies; 20+ messages in thread
From: Ahmad Fatoum @ 2019-05-27 9:57 UTC (permalink / raw)
To: barebox
If we compile on non-Linux hosts, we can't assume this header to be
available. Thus typedef loff_t and [su](8|16|32|64) ourselves.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
scripts/include/linux/types.h | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/scripts/include/linux/types.h b/scripts/include/linux/types.h
index 8ebf6278b2ef..e81d7e810126 100644
--- a/scripts/include/linux/types.h
+++ b/scripts/include/linux/types.h
@@ -5,8 +5,18 @@
#include <stddef.h>
#include <stdint.h>
-#define __SANE_USERSPACE_TYPES__ /* For PPC64, to get LL64 types */
-#include <asm/types.h>
+typedef uint64_t __u64;
+typedef int64_t __s64;
+typedef uint32_t __u32;
+typedef int32_t __s32;
+typedef uint16_t __u16;
+typedef int16_t __s16;
+typedef uint8_t __u8;
+typedef int8_t __s8;
+
+#ifndef __linux__
+typedef long long loff_t;
+#endif
struct page;
struct kmem_cache;
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH 07/18] scripts: bareboxcrc32: remove usage of loff_t
2019-05-27 9:57 [PATCH 00/18] scripts: enable compilation on macOS Ahmad Fatoum
` (5 preceding siblings ...)
2019-05-27 9:57 ` [PATCH 06/18] scripts: don't depend on system <asm/types.h> Ahmad Fatoum
@ 2019-05-27 9:57 ` Ahmad Fatoum
2019-05-27 9:57 ` [PATCH 08/18] scripts: bareboximd: " Ahmad Fatoum
` (11 subsequent siblings)
18 siblings, 0 replies; 20+ messages in thread
From: Ahmad Fatoum @ 2019-05-27 9:57 UTC (permalink / raw)
To: barebox
loff_t is Linux-specific and unneeded at this place, as it's directly
passed into a parameter that's a ulong anyway. Thus use a ulong.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
scripts/bareboxcrc32.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/scripts/bareboxcrc32.c b/scripts/bareboxcrc32.c
index e00ffafeb7b5..1b105a452bd2 100644
--- a/scripts/bareboxcrc32.c
+++ b/scripts/bareboxcrc32.c
@@ -38,7 +38,7 @@
int main(int argc, char *argv[])
{
- loff_t start = 0, size = ~0;
+ ulong start = 0, size = ~0;
ulong crc = 0, total = 0;
char *filename = NULL;
int i;
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH 08/18] scripts: bareboximd: remove usage of loff_t
2019-05-27 9:57 [PATCH 00/18] scripts: enable compilation on macOS Ahmad Fatoum
` (6 preceding siblings ...)
2019-05-27 9:57 ` [PATCH 07/18] scripts: bareboxcrc32: remove usage of loff_t Ahmad Fatoum
@ 2019-05-27 9:57 ` Ahmad Fatoum
2019-05-27 9:57 ` [PATCH 09/18] scripts: compiler.h: add endianness helpers for macOS Ahmad Fatoum
` (10 subsequent siblings)
18 siblings, 0 replies; 20+ messages in thread
From: Ahmad Fatoum @ 2019-05-27 9:57 UTC (permalink / raw)
To: barebox
loff_t is Linux-specific and unneeded at this place, as sizes are usually
denoted with a size_t. As the signedness of max_size isn't relied on
anywhere, replace it with a size_t.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
scripts/bareboximd.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/scripts/bareboximd.c b/scripts/bareboximd.c
index 7d4cbeb9a83f..81a59ec63c23 100644
--- a/scripts/bareboximd.c
+++ b/scripts/bareboximd.c
@@ -58,7 +58,7 @@ int imd_command_setenv(const char *variable_name, const char *value)
return -EINVAL;
}
-static int read_file_2(const char *filename, size_t *size, void **outbuf, loff_t max_size)
+static int read_file_2(const char *filename, size_t *size, void **outbuf, size_t max_size)
{
off_t fsize;
ssize_t rsize;
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH 09/18] scripts: compiler.h: add endianness helpers for macOS
2019-05-27 9:57 [PATCH 00/18] scripts: enable compilation on macOS Ahmad Fatoum
` (7 preceding siblings ...)
2019-05-27 9:57 ` [PATCH 08/18] scripts: bareboximd: " Ahmad Fatoum
@ 2019-05-27 9:57 ` Ahmad Fatoum
2019-05-27 9:57 ` [PATCH 10/18] scripts: use "compiler.h" endianness helpers Ahmad Fatoum
` (9 subsequent siblings)
18 siblings, 0 replies; 20+ messages in thread
From: Ahmad Fatoum @ 2019-05-27 9:57 UTC (permalink / raw)
To: barebox
These are taken from Mathias Panzenböck's portable_endian.h[1]
which he had released it into the public domain.
[1]: https://gist.github.com/panzi/6856583
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
scripts/compiler.h | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/scripts/compiler.h b/scripts/compiler.h
index bd73c7a9a8d3..ee2097aa3691 100644
--- a/scripts/compiler.h
+++ b/scripts/compiler.h
@@ -42,7 +42,23 @@
# include <endian.h>
# include <byteswap.h>
#elif defined(__MACH__)
-# include <machine/endian.h>
+# ifdef __APPLE__
+# include <libkern/OSByteOrder.h>
+# define htobe16(x) OSSwapHostToBigInt16(x)
+# define htole16(x) OSSwapHostToLittleInt16(x)
+# define be16toh(x) OSSwapBigToHostInt16(x)
+# define le16toh(x) OSSwapLittleToHostInt16(x)
+# define htobe32(x) OSSwapHostToBigInt32(x)
+# define htole32(x) OSSwapHostToLittleInt32(x)
+# define be32toh(x) OSSwapBigToHostInt32(x)
+# define le32toh(x) OSSwapLittleToHostInt32(x)
+# define htobe64(x) OSSwapHostToBigInt64(x)
+# define htole64(x) OSSwapHostToLittleInt64(x)
+# define be64toh(x) OSSwapBigToHostInt64(x)
+# define le64toh(x) OSSwapLittleToHostInt64(x)
+# else /* non apple __MACH__ */
+# include <machine/endian.h>
+# endif /* __APPLE__ */
# define __BYTE_ORDER BYTE_ORDER
# define __LITTLE_ENDIAN LITTLE_ENDIAN
# define __BIG_ENDIAN BIG_ENDIAN
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH 10/18] scripts: use "compiler.h" endianness helpers
2019-05-27 9:57 [PATCH 00/18] scripts: enable compilation on macOS Ahmad Fatoum
` (8 preceding siblings ...)
2019-05-27 9:57 ` [PATCH 09/18] scripts: compiler.h: add endianness helpers for macOS Ahmad Fatoum
@ 2019-05-27 9:57 ` Ahmad Fatoum
2019-05-27 9:57 ` [PATCH 11/18] scripts: mkimage: s/fdatasync/fsync/ on macOS & OpenBSD Ahmad Fatoum
` (8 subsequent siblings)
18 siblings, 0 replies; 20+ messages in thread
From: Ahmad Fatoum @ 2019-05-27 9:57 UTC (permalink / raw)
To: barebox
<endian.h> may not exist on other systems, don't include it
directly, but include "compiler.h", which either includes
it or provides a suitable alternative if possible.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
scripts/fix_size.c | 3 ++-
scripts/imx/imx-image.c | 2 +-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/scripts/fix_size.c b/scripts/fix_size.c
index cb074e3cbc85..e33edecf6591 100644
--- a/scripts/fix_size.c
+++ b/scripts/fix_size.c
@@ -9,7 +9,8 @@
#include <unistd.h>
#include <stdint.h>
#include <fcntl.h>
-#include <endian.h>
+
+#include "compiler.h"
int main(int argc, char**argv)
{
diff --git a/scripts/imx/imx-image.c b/scripts/imx/imx-image.c
index a7f1421fa371..3a7b1c0ab2e1 100644
--- a/scripts/imx/imx-image.c
+++ b/scripts/imx/imx-image.c
@@ -26,10 +26,10 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
-#include <endian.h>
#include <linux/kernel.h>
#include <sys/file.h>
#include <mach/imx_cpu_types.h>
+#include "../compiler.h"
#include "imx.h"
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH 11/18] scripts: mkimage: s/fdatasync/fsync/ on macOS & OpenBSD
2019-05-27 9:57 [PATCH 00/18] scripts: enable compilation on macOS Ahmad Fatoum
` (9 preceding siblings ...)
2019-05-27 9:57 ` [PATCH 10/18] scripts: use "compiler.h" endianness helpers Ahmad Fatoum
@ 2019-05-27 9:57 ` Ahmad Fatoum
2019-05-27 9:57 ` [PATCH 12/18] scripts: removes uses of <asm*/errno.h> in favor of <errno.h> Ahmad Fatoum
` (7 subsequent siblings)
18 siblings, 0 replies; 20+ messages in thread
From: Ahmad Fatoum @ 2019-05-27 9:57 UTC (permalink / raw)
To: barebox
fdatasync is an optional part of POSIX and mkimage uses the more general
fsync on Sun and FreeBSD as an alternative. Add macOS[1] and OpenBSD to the
list as well.
This is in-line with what U-Boot does since 31cbe80c33
("mkimage: fix compilation issues on OpenBSD").
[1]: macOS >=10.7 does indeed define (but not declare anywhere) a seemingly
working fdatasync, but we won't consider this here.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
scripts/mkimage.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/scripts/mkimage.c b/scripts/mkimage.c
index 891d7b6de71c..7d283c550930 100644
--- a/scripts/mkimage.c
+++ b/scripts/mkimage.c
@@ -572,7 +572,11 @@ NXTARG: ;
}
/* We're a bit of paranoid */
-#if defined(_POSIX_SYNCHRONIZED_IO) && !defined(__sun__) && !defined(__FreeBSD__)
+#if defined(_POSIX_SYNCHRONIZED_IO) && \
+ !defined(__sun__) && \
+ !defined(__FreeBSD__) && \
+ !defined(__OpenBSD__) && \
+ !defined(__APPLE__)
(void) fdatasync (ifd);
#else
(void) fsync (ifd);
@@ -622,7 +626,11 @@ NXTARG: ;
(void) munmap((void *)ptr, sbuf.st_size);
/* We're a bit of paranoid */
-#if defined(_POSIX_SYNCHRONIZED_IO) && !defined(__sun__) && !defined(__FreeBSD__)
+#if defined(_POSIX_SYNCHRONIZED_IO) && \
+ !defined(__sun__) && \
+ !defined(__FreeBSD__) && \
+ !defined(__OpenBSD__) && \
+ !defined(__APPLE__)
(void) fdatasync (ifd);
#else
(void) fsync (ifd);
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH 12/18] scripts: removes uses of <asm*/errno.h> in favor of <errno.h>
2019-05-27 9:57 [PATCH 00/18] scripts: enable compilation on macOS Ahmad Fatoum
` (10 preceding siblings ...)
2019-05-27 9:57 ` [PATCH 11/18] scripts: mkimage: s/fdatasync/fsync/ on macOS & OpenBSD Ahmad Fatoum
@ 2019-05-27 9:57 ` Ahmad Fatoum
2019-05-27 9:57 ` [PATCH 13/18] scripts: omap3-usb-loader: don't depend on unportable le32toh Ahmad Fatoum
` (6 subsequent siblings)
18 siblings, 0 replies; 20+ messages in thread
From: Ahmad Fatoum @ 2019-05-27 9:57 UTC (permalink / raw)
To: barebox
We can't assume <asm/errno.h> to be available on non-Linux hosts.
Furthermore, errno constants values aren't fixed and passing them
to libc perror(3)/strerror (3) would yield wrong results.
Fix this by using the standard <errno.h> header instead.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
scripts/bareboximd.c | 1 -
scripts/include/linux/err.h | 2 +-
2 files changed, 1 insertion(+), 2 deletions(-)
diff --git a/scripts/bareboximd.c b/scripts/bareboximd.c
index 81a59ec63c23..5ef91831c457 100644
--- a/scripts/bareboximd.c
+++ b/scripts/bareboximd.c
@@ -23,7 +23,6 @@
#include <stdio.h>
#include <sys/types.h>
#include <stdint.h>
-#include <asm-generic/errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
diff --git a/scripts/include/linux/err.h b/scripts/include/linux/err.h
index bdc3dd8131d4..9982ab17babe 100644
--- a/scripts/include/linux/err.h
+++ b/scripts/include/linux/err.h
@@ -4,7 +4,7 @@
#include <linux/compiler.h>
#include <linux/types.h>
-#include <asm/errno.h>
+#include <errno.h>
/*
* Original kernel header comment:
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH 13/18] scripts: omap3-usb-loader: don't depend on unportable le32toh
2019-05-27 9:57 [PATCH 00/18] scripts: enable compilation on macOS Ahmad Fatoum
` (11 preceding siblings ...)
2019-05-27 9:57 ` [PATCH 12/18] scripts: removes uses of <asm*/errno.h> in favor of <errno.h> Ahmad Fatoum
@ 2019-05-27 9:57 ` Ahmad Fatoum
2019-05-27 9:57 ` [PATCH 14/18] scripts: omap3-usb-loader: drop unneeded header Ahmad Fatoum
` (5 subsequent siblings)
18 siblings, 0 replies; 20+ messages in thread
From: Ahmad Fatoum @ 2019-05-27 9:57 UTC (permalink / raw)
To: barebox
The file already defines le32_to_cpu(), which does the same, so
use it.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
scripts/omap3-usb-loader.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/scripts/omap3-usb-loader.c b/scripts/omap3-usb-loader.c
index 3ba9af06527c..73c5a6d97a53 100644
--- a/scripts/omap3-usb-loader.c
+++ b/scripts/omap3-usb-loader.c
@@ -403,7 +403,7 @@ static int transfer_first_stage(libusb_device_handle * handle, struct arg_state
data = file->data;
dbuf = data;
- if (le32toh(dbuf[5]) == 0x45534843) {
+ if (le32_to_cpu(dbuf[5]) == 0x45534843) {
int chsettingssize = 512 + 2 * sizeof(uint32_t);
log_info("CHSETTINGS image detected. Skipping header\n");
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH 14/18] scripts: omap3-usb-loader: drop unneeded header
2019-05-27 9:57 [PATCH 00/18] scripts: enable compilation on macOS Ahmad Fatoum
` (12 preceding siblings ...)
2019-05-27 9:57 ` [PATCH 13/18] scripts: omap3-usb-loader: don't depend on unportable le32toh Ahmad Fatoum
@ 2019-05-27 9:57 ` Ahmad Fatoum
2019-05-27 9:57 ` [PATCH 15/18] scripts: imx-usb-loader: don't depend on unportable headers Ahmad Fatoum
` (4 subsequent siblings)
18 siblings, 0 replies; 20+ messages in thread
From: Ahmad Fatoum @ 2019-05-27 9:57 UTC (permalink / raw)
To: barebox
Declarations from the header aren't used anywhere, so drop it.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
scripts/omap3-usb-loader.c | 4 ----
1 file changed, 4 deletions(-)
diff --git a/scripts/omap3-usb-loader.c b/scripts/omap3-usb-loader.c
index 73c5a6d97a53..ae6f1258df05 100644
--- a/scripts/omap3-usb-loader.c
+++ b/scripts/omap3-usb-loader.c
@@ -33,10 +33,6 @@
#define OMAP_IS_BIG_ENDIAN
#endif
-#ifdef OMAP_IS_BIG_ENDIAN
-#include <arpa/inet.h>
-#endif
-
#include <unistd.h> /* for usleep and friends */
#include <getopt.h>
#include <errno.h>
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH 15/18] scripts: imx-usb-loader: don't depend on unportable headers
2019-05-27 9:57 [PATCH 00/18] scripts: enable compilation on macOS Ahmad Fatoum
` (13 preceding siblings ...)
2019-05-27 9:57 ` [PATCH 14/18] scripts: omap3-usb-loader: drop unneeded header Ahmad Fatoum
@ 2019-05-27 9:57 ` Ahmad Fatoum
2019-05-27 9:57 ` [PATCH 16/18] scripts: kwbimage: fix build with non-glibc systems Ahmad Fatoum
` (3 subsequent siblings)
18 siblings, 0 replies; 20+ messages in thread
From: Ahmad Fatoum @ 2019-05-27 9:57 UTC (permalink / raw)
To: barebox
<sys/io.h> is non-standard and even unavailable on some Linux
systems, like arm64. Drop it as it's unused anyway.
<endian.h> is Linux-specific, so don't include it directly, but
let "compiler.h" figure out, whether it should be included.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
scripts/imx/imx-usb-loader.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/scripts/imx/imx-usb-loader.c b/scripts/imx/imx-usb-loader.c
index d4fba0ce54e8..cc26cdd8afb6 100644
--- a/scripts/imx/imx-usb-loader.c
+++ b/scripts/imx/imx-usb-loader.c
@@ -26,16 +26,15 @@
#include <unistd.h>
#include <ctype.h>
-#include <sys/io.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <libusb.h>
#include <getopt.h>
-#include <endian.h>
#include <arpa/inet.h>
#include <linux/kernel.h>
+#include "../compiler.h"
#include "imx.h"
#define get_min(a, b) (((a) < (b)) ? (a) : (b))
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH 16/18] scripts: kwbimage: fix build with non-glibc systems
2019-05-27 9:57 [PATCH 00/18] scripts: enable compilation on macOS Ahmad Fatoum
` (14 preceding siblings ...)
2019-05-27 9:57 ` [PATCH 15/18] scripts: imx-usb-loader: don't depend on unportable headers Ahmad Fatoum
@ 2019-05-27 9:57 ` Ahmad Fatoum
2019-05-27 9:57 ` [PATCH 17/18] scripts: compiler.h: use Linux <endian.h> as default Ahmad Fatoum
` (2 subsequent siblings)
18 siblings, 0 replies; 20+ messages in thread
From: Ahmad Fatoum @ 2019-05-27 9:57 UTC (permalink / raw)
To: barebox
get_current_dir_name is a glibc extension, thus replace it
with a call to standard POSIX pathconf/malloc/gecwd.
The result slightly differs, because get_current_dir_name consults
the $PWD environment variable as as well, but that's ok, as it's
just an error message.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
scripts/kwbimage.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/scripts/kwbimage.c b/scripts/kwbimage.c
index 2a052a7ff385..6ba4abaa3076 100644
--- a/scripts/kwbimage.c
+++ b/scripts/kwbimage.c
@@ -860,12 +860,16 @@ static void *image_create_v1(struct image_cfg_element *image_cfg,
ret = stat(binarye->binary.file, &s);
if (ret < 0) {
- char *cwd = get_current_dir_name();
+ char *buf, *cwd = NULL;
+ size_t size = (size_t)pathconf(".", _PC_PATH_MAX);
+ buf = malloc(size);
+ if (buf)
+ cwd = getcwd(buf, size);
fprintf(stderr,
"Didn't find the file '%s' in '%s' which is mandatory to generate the image\n"
"This file generally contains the DDR3 training code, and should be extracted from an existing bootable\n"
"image for your board. See 'kwbimage -x' to extract it from an existing image.\n",
- binarye->binary.file, cwd);
+ binarye->binary.file, cwd ? cwd : "current working directory");
free(cwd);
return NULL;
}
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH 17/18] scripts: compiler.h: use Linux <endian.h> as default
2019-05-27 9:57 [PATCH 00/18] scripts: enable compilation on macOS Ahmad Fatoum
` (15 preceding siblings ...)
2019-05-27 9:57 ` [PATCH 16/18] scripts: kwbimage: fix build with non-glibc systems Ahmad Fatoum
@ 2019-05-27 9:57 ` Ahmad Fatoum
2019-05-27 9:57 ` [PATCH 18/18] scripts: compiler.h: support BSDs as well Ahmad Fatoum
2019-05-28 8:36 ` [PATCH 00/18] scripts: enable compilation on macOS Sascha Hauer
18 siblings, 0 replies; 20+ messages in thread
From: Ahmad Fatoum @ 2019-05-27 9:57 UTC (permalink / raw)
To: barebox
Other systems mimic the GNU endianness headers, e.g. Cygwin. Instead of
explicitly listing them, just make the Linux case the default case by
moving it into the #else clause.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
scripts/compiler.h | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/scripts/compiler.h b/scripts/compiler.h
index ee2097aa3691..01b0de44f18a 100644
--- a/scripts/compiler.h
+++ b/scripts/compiler.h
@@ -38,10 +38,7 @@
#define O_BINARY 0
#endif
-#ifdef __linux__
-# include <endian.h>
-# include <byteswap.h>
-#elif defined(__MACH__)
+#if defined(__MACH__)
# ifdef __APPLE__
# include <libkern/OSByteOrder.h>
# define htobe16(x) OSSwapHostToBigInt16(x)
@@ -64,6 +61,9 @@
# define __BIG_ENDIAN BIG_ENDIAN
typedef unsigned long ulong;
typedef unsigned int uint;
+#else /* assume Linux */
+# include <endian.h>
+# include <byteswap.h>
#endif
typedef uint8_t __u8;
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH 18/18] scripts: compiler.h: support BSDs as well
2019-05-27 9:57 [PATCH 00/18] scripts: enable compilation on macOS Ahmad Fatoum
` (16 preceding siblings ...)
2019-05-27 9:57 ` [PATCH 17/18] scripts: compiler.h: use Linux <endian.h> as default Ahmad Fatoum
@ 2019-05-27 9:57 ` Ahmad Fatoum
2019-05-28 8:36 ` [PATCH 00/18] scripts: enable compilation on macOS Sascha Hauer
18 siblings, 0 replies; 20+ messages in thread
From: Ahmad Fatoum @ 2019-05-27 9:57 UTC (permalink / raw)
To: barebox
The BSDs have their endianness changing functions in <sys/endian.h> and
define both _BYTE_ORDER as well as BYTE_ORDER (if strict POSIX conformance
isn't requested). Extend the header to compile, so it supports these
platforms as well.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
scripts/compiler.h | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/scripts/compiler.h b/scripts/compiler.h
index 01b0de44f18a..0ad25f9e8da9 100644
--- a/scripts/compiler.h
+++ b/scripts/compiler.h
@@ -56,16 +56,22 @@
# else /* non apple __MACH__ */
# include <machine/endian.h>
# endif /* __APPLE__ */
-# define __BYTE_ORDER BYTE_ORDER
-# define __LITTLE_ENDIAN LITTLE_ENDIAN
-# define __BIG_ENDIAN BIG_ENDIAN
typedef unsigned long ulong;
typedef unsigned int uint;
+#elif defined(__OpenBSD__) || defined(__FreeBSD__) || \
+ defined(__NetBSD__) || defined(__DragonFly__)
+# include <sys/endian.h>
#else /* assume Linux */
# include <endian.h>
# include <byteswap.h>
#endif
+#if defined(__BYTE_ORDER) && !defined(BYTE_ORDER)
+# define __BYTE_ORDER BYTE_ORDER
+# define __BIG_ENDIAN BIG_ENDIAN
+# define __LITTLE_ENDIAN LITTLE_ENDIAN
+#endif
+
typedef uint8_t __u8;
typedef uint16_t __u16;
typedef uint32_t __u32;
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 00/18] scripts: enable compilation on macOS
2019-05-27 9:57 [PATCH 00/18] scripts: enable compilation on macOS Ahmad Fatoum
` (17 preceding siblings ...)
2019-05-27 9:57 ` [PATCH 18/18] scripts: compiler.h: support BSDs as well Ahmad Fatoum
@ 2019-05-28 8:36 ` Sascha Hauer
18 siblings, 0 replies; 20+ messages in thread
From: Sascha Hauer @ 2019-05-28 8:36 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox
On Mon, May 27, 2019 at 11:57:26AM +0200, Ahmad Fatoum wrote:
> With this patch series applied, imx_v7_defconfig along with the host
> tools can be built on macOS. It should also pave the way for building
> on the BSDs. Currently it still fails on NetBSD though:
>
> In file included from scripts/mod/modpost.c:15:0:
> scripts/mod/modpost.h:16:0: warning: "Elf_Ehdr" redefined
> #define Elf_Ehdr Elf32_Ehdr
> ^
> In file included from scripts/mod/modpost.h:10:0,
> from scripts/mod/modpost.c:15:
> /usr/include/elf.h:1093:0: note: this is the location of the previous definition
> #define Elf_Ehdr Elf64_Ehdr
> ^
>
> Issues addressed in the series can be split into three groups:
>
> - host tools depend on glibc or Linux headers
> replaced where appropriate with standard ISO/POSIX functionality
> - build depends on GNU utilites:
> only stat(1). fixed by importing the linux patch that uses ls
> instead.
> - endianness helpers
> These aren't (yet) POSIX-standardized, so I extended compiler.h
> to support macOS and the BSDs.
>
> Only thing I can't yet compile is MXS_HOSTTOOLS, which depends on
> pkg-config finding OpenSSL, but I guess that's something I need to fix
> at my side.
Applied, thanks
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 20+ messages in thread