All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yann E. MORIN <yann.morin.1998@free.fr>
To: buildroot@busybox.net
Subject: [Buildroot] [PATCH 07/13] toolchain/external: check kernel headers version for custom toolchain
Date: Mon, 24 Feb 2014 00:40:54 +0100	[thread overview]
Message-ID: <f793dfe165744515544bad0af6fd22eb608ea13f.1393198603.git.yann.morin.1998@free.fr> (raw)
In-Reply-To: <cover.1393198603.git.yann.morin.1998@free.fr>

From: "Yann E. MORIN" <yann.morin.1998@free.fr>

Ensure the kernel headers version used in the custom external toolchain,
or the manually-specified kernel headers version, matches exactly the one
selected by the user.

We do not care about the patch-level, since headers are not supposed to
change between patchlevels. This applies only to kernels >= 3.0, but
those are actually the ones we do care about; we treat all 2.6.x kernels
as being a single version, since we do not support any 2.6 kernels for
packages with kernel-dependant features.

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Cc: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Cc: Arnout Vandecappelle <arnout@mind.be>
Cc: Thomas De Schampheleire <patrickdepinguin@gmail.com>
---
 support/scripts/check-kernel-headers.sh            | 22 ++++++++++++++++++++++
 toolchain/helpers.mk                               | 13 +++++++++++++
 toolchain/toolchain-common.in                      | 20 ++++++++++++++++++++
 toolchain/toolchain-external/toolchain-external.mk |  7 ++++++-
 4 files changed, 61 insertions(+), 1 deletion(-)
 create mode 100755 support/scripts/check-kernel-headers.sh

diff --git a/support/scripts/check-kernel-headers.sh b/support/scripts/check-kernel-headers.sh
new file mode 100755
index 0000000..4ce1a6d
--- /dev/null
+++ b/support/scripts/check-kernel-headers.sh
@@ -0,0 +1,22 @@
+#!/bin/sh
+
+CC="${1}"
+# Make sure we have enough version components
+HDR_VER="${2}.0.0"
+
+HDR_M="${HDR_VER%%.*}"
+HDR_V="${HDR_VER#*.}"
+HDR_m="${HDR_V%%.*}"
+
+# We do not want to account for the patchlevel, since headers
+# are not supposed to change in for different patchlevels,
+# so we mask it out.
+# This only applies to kernels >= 3.0, but that's the only one
+# we actually care about; we treat all 2.6.x kernels equally.
+
+exec ${CC} -E -x c -o - - >/dev/null 2>&1 <<_EOF_
+#include <linux/version.h>
+#if (LINUX_VERSION_CODE & ~0xFF) != KERNEL_VERSION(${HDR_M},${HDR_m},0)
+#error Incorrect kernel header version.
+#endif
+_EOF_
diff --git a/toolchain/helpers.mk b/toolchain/helpers.mk
index faa9d90..2182af2 100644
--- a/toolchain/helpers.mk
+++ b/toolchain/helpers.mk
@@ -163,6 +163,19 @@ copy_toolchain_sysroot = \
 	find $(STAGING_DIR) -type d | xargs chmod 755
 
 #
+# Check the specified kernel headers version actually matches the
+# version in the toolchain.
+#
+# $1: cross-gcc path
+# $2: kernel version string, in the form: X.Y
+#
+check_kernel_headers_version = \
+	if ! support/scripts/check-kernel-headers.sh $(1) $(2); then \
+		echo "Incorrect selection of kernel headers"; \
+	    exit 1; \
+	fi
+
+#
 # Check the availability of a particular glibc feature. This function
 # is used to check toolchain options that are always supported by
 # glibc, so we simply check that the corresponding option is properly
diff --git a/toolchain/toolchain-common.in b/toolchain/toolchain-common.in
index f0785a2..4d0ea2e 100644
--- a/toolchain/toolchain-common.in
+++ b/toolchain/toolchain-common.in
@@ -166,3 +166,23 @@ config BR2_TOOLCHAIN_HEADERS_AT_LEAST_3_12
 config BR2_TOOLCHAIN_HEADERS_AT_LEAST_3_13
 	bool
 	select BR2_TOOLCHAIN_HEADERS_AT_LEAST_3_12
+
+# This order guarantees that the highest version is set, as kconfig
+# stops affecting a value on the first matching default.
+config BR2_TOOLCHAIN_HEADERS_AT_LEAST
+	string
+	default "3.13" if BR2_TOOLCHAIN_HEADERS_AT_LEAST_3_13
+	default "3.12" if BR2_TOOLCHAIN_HEADERS_AT_LEAST_3_12
+	default "3.11" if BR2_TOOLCHAIN_HEADERS_AT_LEAST_3_11
+	default "3.10" if BR2_TOOLCHAIN_HEADERS_AT_LEAST_3_10
+	default "3.9"  if BR2_TOOLCHAIN_HEADERS_AT_LEAST_3_9
+	default "3.8"  if BR2_TOOLCHAIN_HEADERS_AT_LEAST_3_8
+	default "3.7"  if BR2_TOOLCHAIN_HEADERS_AT_LEAST_3_7
+	default "3.6"  if BR2_TOOLCHAIN_HEADERS_AT_LEAST_3_6
+	default "3.5"  if BR2_TOOLCHAIN_HEADERS_AT_LEAST_3_5
+	default "3.4"  if BR2_TOOLCHAIN_HEADERS_AT_LEAST_3_4
+	default "3.3"  if BR2_TOOLCHAIN_HEADERS_AT_LEAST_3_3
+	default "3.2"  if BR2_TOOLCHAIN_HEADERS_AT_LEAST_3_2
+	default "3.1"  if BR2_TOOLCHAIN_HEADERS_AT_LEAST_3_1
+	default "3.0"  if BR2_TOOLCHAIN_HEADERS_AT_LEAST_3_0
+	default "2.6"
diff --git a/toolchain/toolchain-external/toolchain-external.mk b/toolchain/toolchain-external/toolchain-external.mk
index a7bfafc..8228468 100644
--- a/toolchain/toolchain-external/toolchain-external.mk
+++ b/toolchain/toolchain-external/toolchain-external.mk
@@ -410,7 +410,7 @@ endef
 # Checks for an already installed toolchain: check the toolchain
 # location, check that it supports sysroot, and then verify that it
 # matches the configuration provided in Buildroot: ABI, C++ support,
-# type of C library and all C library features.
+# kernel headers version, type of C library and all C library features.
 define TOOLCHAIN_EXTERNAL_CONFIGURE_CMDS
 	$(Q)$(call check_cross_compiler_exists,$(TOOLCHAIN_EXTERNAL_CC))
 	$(Q)$(call check_unusable_toolchain,$(TOOLCHAIN_EXTERNAL_CC))
@@ -419,6 +419,11 @@ define TOOLCHAIN_EXTERNAL_CONFIGURE_CMDS
 		@echo "External toolchain doesn't support --sysroot. Cannot use." ; \
 		exit 1 ; \
 	fi ; \
+	if [ "$(BR2_TOOLCHAIN_EXTERNAL_CUSTOM)" = "y" ]; then \
+		$(call check_kernel_headers_version,\
+			"$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS)",\
+			$(call qstrip,$(BR2_TOOLCHAIN_HEADERS_AT_LEAST))); \
+	fi ; \
 	if test "$(BR2_arm)" = "y" ; then \
 		$(call check_arm_abi,\
 			"$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS)",\
-- 
1.8.3.2

  parent reply	other threads:[~2014-02-23 23:40 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-23 23:40 [Buildroot] [PATCH 0/13 v2] Add dependency on kernel headers Yann E. MORIN
2014-02-23 23:40 ` [Buildroot] [PATCH 01/13] package/linux-headers: remove 2.6 snapshot Yann E. MORIN
2014-02-23 23:40 ` [Buildroot] [PATCH 02/13] toolchain/common: add minimum kernel headers options Yann E. MORIN
2014-02-23 23:40 ` [Buildroot] [PATCH 03/13] manual: document minimal kernel headers dependency Yann E. MORIN
2014-02-24 11:38   ` Thomas De Schampheleire
2014-02-24 19:18   ` Arnout Vandecappelle
2014-02-23 23:40 ` [Buildroot] [PATCH 04/13] toolchain/external/predefined: add choice to select 'AT_LEAST_XXX' header version Yann E. MORIN
2014-02-23 23:40 ` [Buildroot] [PATCH 05/13] toolchain/external/custom: " Yann E. MORIN
2014-02-23 23:40 ` [Buildroot] [PATCH 06/13] package/linux-headers: select appropriate " Yann E. MORIN
2014-02-23 23:40 ` Yann E. MORIN [this message]
2014-02-23 23:40 ` [Buildroot] [PATCH 08/13] toolchain/internal: check kernel headers version for manually-specified version Yann E. MORIN
2014-02-23 23:40 ` [Buildroot] [PATCH 09/13] package/dvb-apps: requires kernel headers >= 3.3 Yann E. MORIN
2014-02-23 23:40 ` [Buildroot] [PATCH 10/13] package/w_scan: requires kernel headers >= 3.0 Yann E. MORIN
2014-02-23 23:40 ` [Buildroot] [PATCH 11/13] package/weston: " Yann E. MORIN
2014-02-23 23:40 ` [Buildroot] [PATCH 12/13] package/tvheadend: requires kernel headers >= 3.2 Yann E. MORIN
2014-02-23 23:41 ` [Buildroot] [PATCH 13/13] package/mmc-utils: requires kernel headers >= 3.0 Yann E. MORIN
2014-02-25 17:24 ` [Buildroot] [PATCH 0/13 v2] Add dependency on kernel headers Arnout Vandecappelle

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f793dfe165744515544bad0af6fd22eb608ea13f.1393198603.git.yann.morin.1998@free.fr \
    --to=yann.morin.1998@free.fr \
    --cc=buildroot@busybox.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.