From 7209afb7585a054a152ca25c60d50f5b735e1ca2 Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Thu, 24 Aug 2017 14:18:46 +0100 Subject: [PATCH] kernel: Enable custom kernel config additions For some use cases, we may want to add additional kernel configuration options (e.g. when adding AUFS). This commit enables it by: - renaming DEBUG to EXTRA - append kernel_config${EXTRA} to the kernel config - allowing passing in an EXTRA argument to the make file Signed-off-by: Rolf Neugebauer --- kernel/Dockerfile | 21 ++++++++++--------- kernel/Makefile | 15 ++++++++----- ...{kernel_config.debug => kernel_config-dbg} | 0 3 files changed, 21 insertions(+), 15 deletions(-) rename kernel/{kernel_config.debug => kernel_config-dbg} (100%) diff --git a/kernel/Dockerfile b/kernel/Dockerfile index 782ceb2fc..a4ecc1d32 100644 --- a/kernel/Dockerfile +++ b/kernel/Dockerfile @@ -31,7 +31,7 @@ RUN [ $(uname -m) == x86_64 ] && apk add libunwind-dev || true ARG KERNEL_VERSION ARG KERNEL_SERIES -ARG DEBUG +ARG EXTRA ENV KERNEL_SOURCE=https://www.kernel.org/pub/linux/kernel/v4.x/linux-${KERNEL_VERSION}.tar.xz ENV KERNEL_SHA256_SUMS=https://www.kernel.org/pub/linux/kernel/v4.x/sha256sums.asc @@ -66,8 +66,7 @@ RUN set -e && for patch in /patches/*.patch; do \ done # Kernel config -COPY kernel_config-${KERNEL_SERIES}* /linux/ -COPY kernel_config.debug /linux/debug_config +COPY kernel_config* /linux/ RUN case $(uname -m) in \ x86_64) \ @@ -78,15 +77,17 @@ RUN case $(uname -m) in \ ;; \ esac && \ cp /linux/kernel_config-${KERNEL_SERIES}-$(uname -m) ${KERNEL_DEF_CONF}; \ - if [ -n "${DEBUG}" ]; then \ - sed -i 's/CONFIG_PANIC_ON_OOPS=y/# CONFIG_PANIC_ON_OOPS is not set/' ${KERNEL_DEF_CONF}; \ - sed -i "s/CONFIG_LOCALVERSION=\"-linuxkit\"/CONFIG_LOCALVERSION=\"-linuxkit${DEBUG}\"/" ${KERNEL_DEF_CONF}; \ - cat /linux/debug_config >> ${KERNEL_DEF_CONF}; \ + if [ -n "${EXTRA}" ]; then \ + sed -i "s/CONFIG_LOCALVERSION=\"-linuxkit\"/CONFIG_LOCALVERSION=\"-linuxkit${EXTRA}\"/" ${KERNEL_DEF_CONF}; \ + if [ "${EXTRA}" = "-dbg" ]; then \ + sed -i 's/CONFIG_PANIC_ON_OOPS=y/# CONFIG_PANIC_ON_OOPS is not set/' ${KERNEL_DEF_CONF}; \ + fi && \ + cat /linux/kernel_config${EXTRA} >> ${KERNEL_DEF_CONF}; \ fi && \ - rm /linux/kernel_config-${KERNEL_SERIES}* && \ + rm /linux/kernel_config* && \ make defconfig && \ make oldconfig && \ - if [ -z "${DEBUG}" ]; then diff .config ${KERNEL_DEF_CONF}; fi + if [ -z "${EXTRA}" ]; then diff .config ${KERNEL_DEF_CONF}; fi RUN mkdir /out @@ -101,7 +102,7 @@ RUN make -j "$(getconf _NPROCESSORS_ONLN)" KCFLAGS="-fno-pie" && \ ;; \ esac && \ cp System.map /out && \ - ([ -n "${DEBUG}" ] && cp vmlinux /out || true) + ([ "${EXTRA}" = "-dbg" ] && cp vmlinux /out || true) # WireGuard RUN curl -sSL -o /wireguard.tar.xz "${WIREGUARD_URL}" && \ diff --git a/kernel/Makefile b/kernel/Makefile index 21d7e70d4..90a0e1a4f 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -17,6 +17,11 @@ ORG?=linuxkit IMAGE:=kernel IMAGE_PERF:=kernel-perf +# You can specify an extra options for the Makefile. This will: +# - append a kernel_config$(EXTRA) to the kernel config for your kernel/arch +# - append $(EXTRA) to the CONFIG_LOCALVERSION of your kernel +EXTRA?= + ifeq ($(HASH),) HASH_COMMIT?=HEAD # Setting this is only really useful with the show-tag target HASH?=$(shell git ls-tree --full-tree $(HASH_COMMIT) -- $(CURDIR) | awk '{print $$3}') @@ -87,12 +92,12 @@ sources/linux-$(1).tar.xz: Makefile | sources KERNEL_VERSIONS+=$(1) endif -build_$(2)$(3): Dockerfile Makefile $(wildcard patches-$(2)/*) $(wildcard kernel_config-$(2)*) kernel_config.debug | sources +build_$(2)$(3): Dockerfile Makefile $(wildcard patches-$(2)/*) $(wildcard kernel_config-$(2)*) kernel_config-dbg | sources docker pull $(ORG)/$(IMAGE):$(1)$(3)-$(TAG)$(SUFFIX) || \ docker build \ --build-arg KERNEL_VERSION=$(1) \ --build-arg KERNEL_SERIES=$(2) \ - --build-arg DEBUG=$(3) \ + --build-arg EXTRA=$(3) \ $(LABELS) \ --no-cache -t $(ORG)/$(IMAGE):$(1)$(3)-$(TAG)$(SUFFIX) . @@ -139,11 +144,11 @@ endef # Build Targets # Debug targets only for latest stable and LTS stable # -$(eval $(call kernel,4.12.8,4.12.x)) +$(eval $(call kernel,4.12.8,4.12.x,$(EXTRA))) $(eval $(call kernel,4.12.8,4.12.x,-dbg)) -$(eval $(call kernel,4.9.44,4.9.x)) +$(eval $(call kernel,4.9.44,4.9.x,$(EXTRA))) $(eval $(call kernel,4.9.44,4.9.x,-dbg)) -$(eval $(call kernel,4.4.83,4.4.x)) +$(eval $(call kernel,4.4.83,4.4.x,$(EXTRA))) # Target for kernel config kconfig: | sources diff --git a/kernel/kernel_config.debug b/kernel/kernel_config-dbg similarity index 100% rename from kernel/kernel_config.debug rename to kernel/kernel_config-dbg