Nico Huber has submitted this change. ( https://review.coreboot.org/c/flashrom/+/58273 )
Change subject: buildsystem: Determine the endianness only in the buildsystem
......................................................................
buildsystem: Determine the endianness only in the buildsystem
Let the buildsystem (make / meson) handle the endianness determination
and set the __FLASHROM_LITTLE_ENDIAN__ or __FLASHROM_BIG_ENDIAN__ macro
as cflag.
Change-Id: I37093528ae55e712cc30a0267a8ceac332750e7d
Signed-off-by: Thomas Heijligen <thomas.heijligen(a)secunet.de>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/58273
Tested-by: build bot (Jenkins) <no-reply(a)coreboot.org>
Reviewed-by: Nico Huber <nico.h(a)gmx.de>
Reviewed-by: Felix Singer <felixsinger(a)posteo.net>
---
M Makefile
M meson.build
M platform.h
3 files changed, 14 insertions(+), 89 deletions(-)
Approvals:
build bot (Jenkins): Verified
Nico Huber: Looks good to me, approved
Felix Singer: Looks good to me, but someone else must approve
diff --git a/Makefile b/Makefile
index cea5c69..6de8f55 100644
--- a/Makefile
+++ b/Makefile
@@ -248,6 +248,13 @@
$(call mark_unsupported,CONFIG_INTERNAL)
endif
+ifeq ($(ENDIAN), little)
+FEATURE_CFLAGS += -D'__FLASHROM_LITTLE_ENDIAN__=1'
+endif
+ifeq ($(ENDIAN), big)
+FEATURE_CFLAGS += -D'__FLASHROM_BIG_ENDIAN__=1'
+endif
+
# PCI port I/O support is unimplemented on PPC/MIPS/SPARC and unavailable on ARM.
# Right now this means the drivers below only work on x86.
ifneq ($(ARCH), x86)
diff --git a/meson.build b/meson.build
index 1a36df8..02dedfc 100644
--- a/meson.build
+++ b/meson.build
@@ -29,6 +29,13 @@
add_project_arguments('-D_BSD_SOURCE', language : 'c') # required for glibc < v2.19
add_project_arguments('-DFLASHROM_VERSION="' + meson.project_version() + '"', language : 'c')
+if host_machine.endian() == 'little'
+ add_project_arguments('-D__FLASHROM_LITTLE_ENDIAN__=1', language : 'c')
+endif
+if host_machine.endian() == 'big'
+ add_project_arguments('-D__FLASHROM_BIG_ENDIAN__=1', language : 'c')
+endif
+
# get defaults from configure
config_atahpt = get_option('config_atahpt')
config_atapromise = get_option('config_atapromise')
diff --git a/platform.h b/platform.h
index cd8e54b..9bbde54 100644
--- a/platform.h
+++ b/platform.h
@@ -71,93 +71,4 @@
#error Unknown architecture
#endif
-/* The next big hunk tries to guess endianness from various preprocessor macros */
-/* First some error checking in case some weird header has defined both.
- * NB: OpenBSD always defines _BIG_ENDIAN and _LITTLE_ENDIAN. */
-#if defined (__LITTLE_ENDIAN__) && defined (__BIG_ENDIAN__)
-#error Conflicting endianness #define
-#endif
-
-#if IS_X86
-
-/* All x86 is little-endian. */
-#define __FLASHROM_LITTLE_ENDIAN__ 1
-
-#elif IS_MIPS
-
-/* MIPS can be either endian. */
-#if defined (__MIPSEL) || defined (__MIPSEL__) || defined (_MIPSEL) || defined (MIPSEL)
-#define __FLASHROM_LITTLE_ENDIAN__ 1
-#elif defined (__MIPSEB) || defined (__MIPSEB__) || defined (_MIPSEB) || defined (MIPSEB)
-#define __FLASHROM_BIG_ENDIAN__ 1
-#endif
-
-#elif IS_PPC
-
-/* PowerPC can be either endian. */
-#if defined (_BIG_ENDIAN) || defined (__BIG_ENDIAN__)
-#define __FLASHROM_BIG_ENDIAN__ 1
-#elif defined (_LITTLE_ENDIAN) || defined (__LITTLE_ENDIAN__)
-#define __FLASHROM_LITTLE_ENDIAN__ 1
-#endif
-
-#elif IS_ARM
-
-/* ARM can be either endian. */
-#if defined (__ARMEB__) || defined (__BIG_ENDIAN__)
-#define __FLASHROM_BIG_ENDIAN__ 1
-#elif defined (__ARMEL__) || defined (__LITTLE_ENDIAN__)
-#define __FLASHROM_LITTLE_ENDIAN__ 1
-#endif
-
-#elif IS_SPARC
-/* SPARC is big endian in general (but allows to access data in little endian too). */
-#define __FLASHROM_BIG_ENDIAN__ 1
-
-#elif IS_ARC
-#if defined(__BIG_ENDIAN__)
-#define __FLASHROM_BIG_ENDIAN__ 1
-#else
-#define __FLASHROM_LITTLE_ENDIAN__ 1
-#endif
-
-#endif /* IS_? */
-
-#if !defined (__FLASHROM_BIG_ENDIAN__) && !defined (__FLASHROM_LITTLE_ENDIAN__)
-
-/* If architecture-specific approaches fail try generic variants. First: BSD (works about everywhere). */
-#if !IS_WINDOWS
-#include <sys/param.h>
-
-#if defined (__BYTE_ORDER)
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-#define __FLASHROM_LITTLE_ENDIAN__
-#elif __BYTE_ORDER == __BIG_ENDIAN
-#define __FLASHROM_BIG_ENDIAN__
-#else
-#error Unknown byte order!
-#endif
-#endif /* defined __BYTE_ORDER */
-#endif /* !IS_WINDOWS */
-
-#if !defined (__FLASHROM_BIG_ENDIAN__) && !defined (__FLASHROM_LITTLE_ENDIAN__)
-
-/* Nonstandard libc-specific macros for determining endianness. */
-/* musl provides an endian.h as well... but it can not be detected from within C. */
-#if defined(__GLIBC__)
-#include <endian.h>
-#if BYTE_ORDER == LITTLE_ENDIAN
-#define __FLASHROM_LITTLE_ENDIAN__ 1
-#elif BYTE_ORDER == BIG_ENDIAN
-#define __FLASHROM_BIG_ENDIAN__ 1
-#endif
-#endif
-#endif
-
-#endif
-
-#if !defined (__FLASHROM_BIG_ENDIAN__) && !defined (__FLASHROM_LITTLE_ENDIAN__)
-#error Unable to determine endianness.
-#endif
-
#endif /* !__PLATFORM_H__ */
3 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the submitted one.
--
To view, visit https://review.coreboot.org/c/flashrom/+/58273
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I37093528ae55e712cc30a0267a8ceac332750e7d
Gerrit-Change-Number: 58273
Gerrit-PatchSet: 8
Gerrit-Owner: Thomas Heijligen <src(a)posteo.de>
Gerrit-Reviewer: Felix Singer <felixsinger(a)posteo.net>
Gerrit-Reviewer: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Reviewer: Nico Huber <nico.h(a)gmx.de>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-CC: Paul Menzel <paulepanter(a)mailbox.org>
Gerrit-MessageType: merged
Nico Huber has submitted this change. ( https://review.coreboot.org/c/flashrom/+/58270 )
Change subject: Makefile: copy determination test for the endian to Makefile.d
......................................................................
Makefile: copy determination test for the endian to Makefile.d
Copy the test code for endian detection in an extra directory to split
it from the main flashrom code.
Change-Id: I0c2420fd60d7d6a23c94c9962b06bfd7f3c86ad8
Signed-off-by: Thomas Heijligen <thomas.heijligen(a)secunet.de>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/58270
Reviewed-by: Nico Huber <nico.h(a)gmx.de>
Tested-by: build bot (Jenkins) <no-reply(a)coreboot.org>
---
M Makefile
A Makefile.d/endian_test.h
D endiantest.c
3 files changed, 92 insertions(+), 8 deletions(-)
Approvals:
build bot (Jenkins): Verified
Nico Huber: Looks good to me, approved
diff --git a/Makefile b/Makefile
index 1e96e8a..cea5c69 100644
--- a/Makefile
+++ b/Makefile
@@ -164,8 +164,7 @@
# the lines below use CC itself.
override TARGET_OS := $(call c_macro_test, Makefile.d/os_test.h)
override ARCH := $(call c_macro_test, Makefile.d/arch_test.h)
-override ENDIAN := $(strip $(call debug_shell,$(CC) $(CPPFLAGS) -E endiantest.c 2>/dev/null \
- | tail -1))
+override ENDIAN := $(call c_macro_test, Makefile.d/endian_test.h)
ifeq ($(TARGET_OS), $(filter $(TARGET_OS), FreeBSD OpenBSD DragonFlyBSD))
override CPPFLAGS += -I/usr/local/include
@@ -869,6 +868,8 @@
@if [ $(ARCH) = unknown ]; then echo Aborting.; exit 1; fi
@echo Target OS is $(TARGET_OS)
@if [ $(TARGET_OS) = unknown ]; then echo Aborting.; exit 1; fi
+ @echo Target endian is $(ENDIAN)
+ @if [ $(ENDIAN) = unknown ]; then echo Aborting.; exit 1; fi
ifeq ($(TARGET_OS), libpayload)
@$(CC) --version 2>&1 | grep -q coreboot || \
( echo "Warning: It seems you are not using coreboot's reference compiler."; \
diff --git a/Makefile.d/endian_test.h b/Makefile.d/endian_test.h
new file mode 100644
index 0000000..36658b3
--- /dev/null
+++ b/Makefile.d/endian_test.h
@@ -0,0 +1,89 @@
+/*
+ * This file is part of the flashrom project.
+ *
+ * Copyright (C) 2011 Carl-Daniel Hailfinger
+ *
+ * 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; version 2 of the License.
+ *
+ * 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.
+ */
+
+/*
+ * This file determinate the target endian. It should only be used my the Makefile
+ */
+
+#if defined (__i386__) || defined (__x86_64__) || defined(__amd64__)
+/* All x86 is little-endian. */
+#define __FLASHROM_LITTLE_ENDIAN__ 1
+#elif defined (__mips) || defined (__mips__) || defined (__MIPS__) || defined (mips)
+/* MIPS can be either endian. */
+#if defined (__MIPSEL) || defined (__MIPSEL__) || defined (_MIPSEL) || defined (MIPSEL)
+#define __FLASHROM_LITTLE_ENDIAN__ 1
+#elif defined (__MIPSEB) || defined (__MIPSEB__) || defined (_MIPSEB) || defined (MIPSEB)
+#define __FLASHROM_BIG_ENDIAN__ 1
+#endif
+#elif defined(__powerpc) || defined(__powerpc__) || defined(__powerpc64__) || defined(__POWERPC__) || \
+ defined(__ppc__) || defined(__ppc64__) || defined(_M_PPC) || defined(_ARCH_PPC) || \
+ defined(_ARCH_PPC64) || defined(__ppc)
+/* PowerPC can be either endian. */
+#if defined (_BIG_ENDIAN) || defined (__BIG_ENDIAN__)
+#define __FLASHROM_BIG_ENDIAN__ 1
+#elif defined (_LITTLE_ENDIAN) || defined (__LITTLE_ENDIAN__)
+#define __FLASHROM_LITTLE_ENDIAN__ 1
+#endif
+#elif defined(__arm__) || defined(__TARGET_ARCH_ARM) || defined(_ARM) || defined(_M_ARM) || defined(__arm) || \
+ defined(__aarch64__)
+/* ARM can be either endian. */
+#if defined (__ARMEB__) || defined (__BIG_ENDIAN__)
+#define __FLASHROM_BIG_ENDIAN__ 1
+#elif defined (__ARMEL__) || defined (__LITTLE_ENDIAN__)
+#define __FLASHROM_LITTLE_ENDIAN__ 1
+#endif
+#elif defined (__sparc__) || defined (__sparc)
+/* SPARC is big endian in general (but allows to access data in little endian too). */
+#define __FLASHROM_BIG_ENDIAN__ 1
+#elif defined(__arc__)
+#if defined(__BIG_ENDIAN__)
+#define __FLASHROM_BIG_ENDIAN__ 1
+#else
+#define __FLASHROM_LITTLE_ENDIAN__ 1
+#endif
+#endif
+
+#if !defined (__FLASHROM_BIG_ENDIAN__) && !defined (__FLASHROM_LITTLE_ENDIAN__)
+/* If architecture-specific approaches fail try generic variants. First: BSD (works about everywhere). */
+#if !(defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(__WINDOWS__))
+#include <sys/param.h>
+#if defined (__BYTE_ORDER)
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+#define __FLASHROM_LITTLE_ENDIAN__
+#elif __BYTE_ORDER == __BIG_ENDIAN
+#define __FLASHROM_BIG_ENDIAN__
+#else
+#error Unknown byte order!
+#endif
+#endif /* defined __BYTE_ORDER */
+#endif /* !IS_WINDOWS */
+#if !defined (__FLASHROM_BIG_ENDIAN__) && !defined (__FLASHROM_LITTLE_ENDIAN__)
+/* Nonstandard libc-specific macros for determining endianness. */
+/* musl provides an endian.h as well... but it can not be detected from within C. */
+#if defined(__GLIBC__)
+#include <endian.h>
+#if BYTE_ORDER == LITTLE_ENDIAN
+#define __FLASHROM_LITTLE_ENDIAN__ 1
+#elif BYTE_ORDER == BIG_ENDIAN
+#define __FLASHROM_BIG_ENDIAN__ 1
+#endif
+#endif
+#endif
+#endif
+#if defined(__FLASHROM_LITTLE_ENDIAN__)
+"little"
+#else
+"big"
+#endif
diff --git a/endiantest.c b/endiantest.c
deleted file mode 100644
index a73b908..0000000
--- a/endiantest.c
+++ /dev/null
@@ -1,6 +0,0 @@
-#include "platform.h"
-#if defined(__FLASHROM_LITTLE_ENDIAN__)
-little
-#else
-big
-#endif
--
To view, visit https://review.coreboot.org/c/flashrom/+/58270
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I0c2420fd60d7d6a23c94c9962b06bfd7f3c86ad8
Gerrit-Change-Number: 58270
Gerrit-PatchSet: 7
Gerrit-Owner: Thomas Heijligen <src(a)posteo.de>
Gerrit-Reviewer: Felix Singer <felixsinger(a)posteo.net>
Gerrit-Reviewer: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Reviewer: Nico Huber <nico.h(a)gmx.de>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-CC: Paul Menzel <paulepanter(a)mailbox.org>
Gerrit-MessageType: merged
Nico Huber has submitted this change. ( https://review.coreboot.org/c/flashrom/+/58248 )
Change subject: Makefile: move determination tests for target systems to one place
......................................................................
Makefile: move determination tests for target systems to one place
Change-Id: Ia1b3f0257aaeebb355700b65c51a2ba70b80d5ae
Signed-off-by: Thomas Heijligen <thomas.heijligen(a)secunet.de>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/58248
Tested-by: build bot (Jenkins) <no-reply(a)coreboot.org>
Reviewed-by: Nico Huber <nico.h(a)gmx.de>
---
M Makefile
1 file changed, 9 insertions(+), 17 deletions(-)
Approvals:
build bot (Jenkins): Verified
Nico Huber: Looks good to me, approved
diff --git a/Makefile b/Makefile
index bc0047f..a94f9f6 100644
--- a/Makefile
+++ b/Makefile
@@ -158,12 +158,17 @@
CC = gcc
endif
-# Determine the destination OS.
-# IMPORTANT: The following line must be placed before TARGET_OS is ever used
-# (of course), but should come after any lines setting CC because the line
-# below uses CC itself.
+# Determine the destination OS, architecture and endian
+# IMPORTANT: The following lines must be placed before TARGET_OS, ARCH or ENDIAN
+# is ever used (of course), but should come after any lines setting CC because
+# the lines below use CC itself.
override TARGET_OS := $(strip $(call debug_shell,$(CC) $(CPPFLAGS) -E os.h 2>/dev/null \
| tail -1 | cut -f 2 -d'"'))
+override ARCH := $(strip $(call debug_shell,$(CC) $(CPPFLAGS) -E archtest.c 2>/dev/null \
+ | tail -1 | cut -f 2 -d'"'))
+override ENDIAN := $(strip $(call debug_shell,$(CC) $(CPPFLAGS) -E endiantest.c 2>/dev/null \
+ | tail -1))
+
ifeq ($(TARGET_OS), $(filter $(TARGET_OS), FreeBSD OpenBSD DragonFlyBSD))
override CPPFLAGS += -I/usr/local/include
@@ -242,19 +247,6 @@
CONFIG_LINUX_I2C_HELPER = yes
endif
-###############################################################################
-# General architecture-specific settings.
-# Like above for the OS, below we verify user-supplied options depending on the target architecture.
-
-# Determine the destination processor architecture.
-# IMPORTANT: The following line must be placed before ARCH is ever used
-# (of course), but should come after any lines setting CC because the line
-# below uses CC itself.
-override ARCH := $(strip $(call debug_shell,$(CC) $(CPPFLAGS) -E archtest.c 2>/dev/null \
- | tail -1 | cut -f 2 -d'"'))
-override ENDIAN := $(strip $(call debug_shell,$(CC) $(CPPFLAGS) -E endiantest.c 2>/dev/null \
- | tail -1))
-
# Disable the internal programmer on unsupported architectures (everything but x86 and mipsel)
ifneq ($(ARCH)-little, $(filter $(ARCH),x86 mips)-$(ENDIAN))
$(call mark_unsupported,CONFIG_INTERNAL)
3 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the submitted one.
--
To view, visit https://review.coreboot.org/c/flashrom/+/58248
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Ia1b3f0257aaeebb355700b65c51a2ba70b80d5ae
Gerrit-Change-Number: 58248
Gerrit-PatchSet: 5
Gerrit-Owner: Thomas Heijligen <src(a)posteo.de>
Gerrit-Reviewer: Felix Singer <felixsinger(a)posteo.net>
Gerrit-Reviewer: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Reviewer: Nico Huber <nico.h(a)gmx.de>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-CC: Paul Menzel <paulepanter(a)mailbox.org>
Gerrit-MessageType: merged