Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kernel.mk - Add kernel module automated building feature #4526

Merged
merged 8 commits into from
Mar 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion kernel/syno-dakota-1.2/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ KERNEL_ARCH = dakota
KERNEL_VERS = 1.2
KERNEL_BUILD = 7742
KERNEL_EXT = tbz
KERNEL_DIST = source/linux-4.4.x
KERNEL_DIST = linux-4.4.x
KERNEL_BASE_ARCH = arm

include ../../mk/spksrc.kernel.mk
6 changes: 3 additions & 3 deletions kernel/syno-dakota-1.2/digests
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
synogpl-7742-dakota.tbz SHA1 2424a5d010114384b3a6f41e307199d9e1f120ba
synogpl-7742-dakota.tbz SHA256 68ead2d0e791b74b0a72ccfecdc2ab1801a25eb0102b0c517291064acb46abc5
synogpl-7742-dakota.tbz MD5 b9bee48e3dca579e02d02abd898ba940
dakota-linux-4.4.x.tbz SHA1 2424a5d010114384b3a6f41e307199d9e1f120ba
dakota-linux-4.4.x.tbz SHA256 68ead2d0e791b74b0a72ccfecdc2ab1801a25eb0102b0c517291064acb46abc5
dakota-linux-4.4.x.tbz MD5 b9bee48e3dca579e02d02abd898ba940
2 changes: 1 addition & 1 deletion kernel/syno-ipq806x-1.2/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ KERNEL_ARCH = ipq806x
KERNEL_VERS = 1.2
KERNEL_BUILD = 7742
KERNEL_EXT = tbz
KERNEL_DIST = source/linux-4.4.x
KERNEL_DIST = linux-4.4.x
KERNEL_BASE_ARCH = arm

include ../../mk/spksrc.kernel.mk
6 changes: 3 additions & 3 deletions kernel/syno-ipq806x-1.2/digests
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
synogpl-7742-ipq806x.tbz SHA1 a335c22c8bc67a795181c976b43ffee0ea07317d
synogpl-7742-ipq806x.tbz SHA256 e7a8bbc3129ce4dbaac5c1c054c710015d33cec448c74209805152554e9f95c3
synogpl-7742-ipq806x.tbz MD5 c92af5840b1296d6485fddd94ead4308
ipq806x-linux-4.4.x.tbz SHA1 a335c22c8bc67a795181c976b43ffee0ea07317d
ipq806x-linux-4.4.x.tbz SHA256 e7a8bbc3129ce4dbaac5c1c054c710015d33cec448c74209805152554e9f95c3
ipq806x-linux-4.4.x.tbz MD5 c92af5840b1296d6485fddd94ead4308
2 changes: 1 addition & 1 deletion kernel/syno-northstarplus-1.2/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ KERNEL_ARCH = northstarplus
KERNEL_VERS = 1.2
KERNEL_BUILD = 7742
KERNEL_EXT = tbz
KERNEL_DIST = source/linux-3.6.x
KERNEL_DIST = linux-3.6.x
KERNEL_CONFIG = synoconfigs/broadcom_northstarplus
KERNEL_BASE_ARCH = arm

Expand Down
6 changes: 3 additions & 3 deletions kernel/syno-northstarplus-1.2/digests
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
synogpl-7742-northstarplus.tbz SHA1 61da8ccf39672946aef45fcccb2c49a3d25e6fee
synogpl-7742-northstarplus.tbz SHA256 2f414eec8ec704a7a32b28d1aab18ebbaac65466526f3989f7b7fc73dad24078
synogpl-7742-northstarplus.tbz MD5 e8392cd130573fb272097a300b26fd24
northstarplus-linux-3.6.x.tbz SHA1 61da8ccf39672946aef45fcccb2c49a3d25e6fee
northstarplus-linux-3.6.x.tbz SHA256 2f414eec8ec704a7a32b28d1aab18ebbaac65466526f3989f7b7fc73dad24078
northstarplus-linux-3.6.x.tbz MD5 e8392cd130573fb272097a300b26fd24
4 changes: 4 additions & 0 deletions mk/spksrc.copy.mk
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ ifeq ($(strip $(PLIST_TRANSFORM)),)
PLIST_TRANSFORM= cat
endif

ifeq ($(strip $(REQUIRE_KERNEL)),1)
DEPENDS += kernel/syno-$(TC_ARCH)-$(TC_VERS)
endif

$(INSTALL_PLIST):
@(\
for depend in $(DEPENDS) ; \
Expand Down
2 changes: 2 additions & 0 deletions mk/spksrc.install.mk
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ post_install_target: $(INSTALL_TARGET)
$(INSTALL_PLIST):
find $(INSTALL_DIR)/$(INSTALL_PREFIX)/ \! -type d -printf '%P\n' | sort | \
diff $(PRE_INSTALL_PLIST) - | grep '>' | cut -d' ' -f2- > $@
# Generate $(PKG_NAME).plist.auto for newly added files (diff against .tmp)
comm -3 $(PRE_INSTALL_PLIST) $(INSTALL_PLIST) > $(INSTALL_PLIST).auto

install_correct_lib_files: $(INSTALL_PLIST)
@for pc_file in `grep -e "^lib/pkgconfig/.*\.pc$$" $(INSTALL_PLIST)` ; \
Expand Down
49 changes: 46 additions & 3 deletions mk/spksrc.kernel-flags.mk
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# if TC_TYPE is unset then it is being
# called directly from spksrc/kernel directory
ifeq ($(strip $(TC_TYPE)),)
include $(WORK_DIR)/tc_vars.mk
endif

ifeq ($(strip $(KERNEL_NAME)),)
KERNEL_NAME = syno-$(KERNEL_ARCH)-$(KERNEL_VERS)
endif
Expand All @@ -10,7 +16,22 @@ ifeq ($(strip $(KERNEL_DIST_FILE)),)
KERNEL_DIST_FILE = $(KERNEL_ARCH)-$(KERNEL_DIST).$(KERNEL_EXT)
endif

ifeq ($(strip $(KERNEL_CONFIG)),)
KERNEL_CONFIG = synoconfigs/$(KERNEL_ARCH)
endif

#
# For DSM
#
ifeq ($(strip $(TC_TYPE)),DSM)

ifeq ($(strip $(KERNEL_DIST_SITE)),)
KERNEL_DIST_SITE = https://sourceforge.net/projects/dsgpl/files/Synology%20NAS%20GPL%20Source/$(KERNEL_BUILD)branch/$(KERNEL_URL_DIR)
endif

#
# For DSM version >= 6.1
#
ifeq ($(shell expr "$(KERNEL_BUILD)" \>= 15152),1)
ifeq ($(strip $(KERNEL_DIST_NAME)),)
KERNEL_DIST_NAME = $(KERNEL_DIST).$(KERNEL_EXT)
Expand All @@ -28,7 +49,9 @@ ifeq ($(strip $(KERNEL_STRIP)),)
KERNEL_STRIP = 0
endif

#
# For DSM version = 5.2
#
else ifeq ($(shell expr "$(KERNEL_BUILD)" \>= 5565),1)
ifeq ($(strip $(KERNEL_DIST_NAME)),)
KERNEL_DIST_NAME = $(KERNEL_ARCH)-source.$(KERNEL_EXT)
Expand All @@ -46,7 +69,9 @@ ifeq ($(strip $(KERNEL_STRIP)),)
KERNEL_STRIP = 1
endif

#
# For DSM version <= 5.1
#
else ifeq ($(shell expr "$(KERNEL_BUILD)" \<= 5004),1)
ifeq ($(strip $(KERNEL_DIST_NAME)),)
KERNEL_DIST_NAME = synogpl-$(KERNEL_BUILD)-$(KERNEL_ARCH).$(KERNEL_EXT)
Expand All @@ -65,10 +90,28 @@ KERNEL_STRIP = 1
endif
endif

#
# SRM
#
else ifeq ($(strip $(TC_TYPE)),SRM)

ifeq ($(strip $(KERNEL_DIST_SITE)),)
KERNEL_DIST_SITE = https://sourceforge.net/projects/dsgpl/files/Synology%20NAS%20GPL%20Source/$(KERNEL_BUILD)branch/$(KERNEL_URL_DIR)
KERNEL_DIST_SITE = https://sourceforge.net/projects/dsgpl/files/Synology%20Router%20GPL%20Source/$(KERNEL_BUILD)branch/$(KERNEL_URL_DIR)
endif

ifeq ($(strip $(KERNEL_CONFIG)),)
KERNEL_CONFIG = synoconfigs/$(KERNEL_ARCH)
ifeq ($(strip $(KERNEL_DIST_NAME)),)
KERNEL_DIST_NAME = synogpl-$(KERNEL_BUILD)-$(KERNEL_ARCH).$(KERNEL_EXT)
endif

ifeq ($(strip $(KERNEL_URL_DIR)),)
KERNEL_URL_DIR = /
endif

ifeq ($(strip $(KERNEL_PREFIX)),)
KERNEL_PREFIX = source/$(KERNEL_DIST)
endif

ifeq ($(strip $(KERNEL_STRIP)),)
KERNEL_STRIP = 1
endif
endif
46 changes: 36 additions & 10 deletions mk/spksrc.kernel.mk
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ include ../../mk/spksrc.kernel-flags.mk
NAME = $(KERNEL_NAME)
COOKIE_PREFIX = linux-
URLS = $(KERNEL_DIST_SITE)/$(KERNEL_DIST_NAME)
PKG_DIR = linux
PKG_NAME = linux
PKG_DIR = $(PKG_NAME)
ifneq ($(KERNEL_DIST_FILE),)
LOCAL_FILE = $(KERNEL_DIST_FILE)
# download.mk uses PKG_DIST_FILE
Expand All @@ -28,8 +29,16 @@ EXTRACT_CMD = $(EXTRACT_CMD.$(KERNEL_EXT)) --skip-old-files --strip-components
PRE_CONFIGURE_TARGET = kernel_pre_configure_target
CONFIGURE_TARGET = kernel_configure_target
PRE_COMPILE_TARGET = kernel_module_prepare_target
ifeq ($(strip $(REQUIRE_KERNEL_MODULE)),)
COMPILE_TARGET = nop
COPY_TARGET = nop
else
COMPILE_TARGET = kernel_module_compile_target
endif
# spksrc.install.mk called for PRE_INSTALL_PLIST
# in order to generate a work*/linux.plist.auto
# later used by spksr.plist.mk to generate the
# diff based on .ko kernel objects
INSTALL_TARGET = nop

#####

Expand All @@ -56,10 +65,16 @@ include ../../mk/spksrc.configure.mk
compile: configure
include ../../mk/spksrc.compile.mk

install: compile
include ../../mk/spksrc.install.mk

plist: install
include ../../mk/spksrc.plist.mk

clean:
rm -fr work work-*

all: compile
all: install plist

### For make digests
include ../../mk/spksrc.generate-digests.mk
Expand All @@ -75,8 +90,8 @@ kernel_configure_target:
@$(MSG) "Updating kernel Makefile"
$(RUN) sed -i -r 's,^CROSS_COMPILE\s*.+,CROSS_COMPILE\t= $(TC_PATH)$(TC_PREFIX),' Makefile
$(RUN) sed -i -r 's,^ARCH\s*.+,ARCH\t= $(KERNEL_ARCH),' Makefile
# Add "+" to EXTRAVERSION for kernels version >= 4.x
ifeq ($(shell expr "$(word 1,$(subst ., ,$(TC_KERNEL)))" \>= 4),1)
# Add "+" to EXTRAVERSION for kernels version >= 4.4
ifeq ($(call version_ge, ${TC_KERNEL}, 4.4),1)
$(RUN) sed -i -r -e 's,^EXTRAVERSION\s*.+,&+,' -e 's,=\+,= \+,' Makefile
endif
test -e $(WORK_DIR)/arch/$(KERNEL_ARCH) || $(RUN) ln -sf $(KERNEL_BASE_ARCH) arch/$(KERNEL_ARCH)
Expand All @@ -85,9 +100,9 @@ endif
@$(MSG) "Applying $(KERNEL_CONFIG) configuration"
$(RUN) cp $(KERNEL_CONFIG) .config
@$(MSG) "Set any new symbols to their default value"
# olddefconfig is not available <= 3.2
ifeq ($(shell printf '%s\n' "$(TC_KERNEL)" "3.3" | sort -V | head -1),$(TC_KERNEL))
@$(MSG) "oldconfig OLD style... $(TC_KERNEL) <= 3.2"
# olddefconfig is not available < 3.8
ifeq ($(call version_lt, ${TC_KERNEL}, 3.8),1)
@$(MSG) "oldconfig OLD style... $(TC_KERNEL) < 3.8"
$(RUN) yes "" | $(MAKE) oldconfig
else
$(RUN) $(MAKE) olddefconfig
Expand All @@ -99,12 +114,23 @@ kernel_module_prepare_target:
@$(MSG) "DISTRIB_DIR = $(DISTRIB_DIR)"
@$(MSG) "Prepare kernel source for module build"
$(RUN) $(MAKE) modules_prepare
ifeq ($(shell expr "$(word 1,$(subst ., ,$(TC_KERNEL)))" \>= 3),1)
# Call to make kernelversion is not available for kernel <= 3.0
ifeq ($(call version_ge, ${TC_KERNEL}, 3),1)
@$(MSG) "Get kernel version"
$(RUN) $(MAKE) kernelversion
endif

.PHONY: kernel_module_compile_target

kernel_module_compile_target:
$(RUN) $(MAKE) modules
@for module in $(REQUIRE_KERNEL_MODULE); \
do \
$(MAKE) kernel_module_build module=$$module ; \
done

kernel_module_build:
@$(MSG) Building kernel module module=$(module)
$(RUN) LDFLAGS="" $(MAKE) -C $(WORK_DIR)/linux INSTALL_MOD_PATH=$(STAGING_INSTALL_PREFIX) modules M=$(word 2,$(subst :, ,$(module))) $(firstword $(subst :, ,$(module)))=m $(lastword $(subst :, ,$(module))).ko
$(RUN) cat $(word 2,$(subst :, ,$(module)))/modules.order >> $(WORK_DIR)/linux/modules.order
$(RUN) mkdir -p $(STAGING_INSTALL_PREFIX)/lib/modules/$(TC_KERNEL)/kernel/$(word 2,$(subst :, ,$(module)))
install -m 644 $(WORK_DIR)/linux/$(word 2,$(subst :, ,$(module)))/$(lastword $(subst :, ,$(module))).ko $(STAGING_INSTALL_PREFIX)/lib/modules/$(TC_KERNEL)/kernel/$(word 2,$(subst :, ,$(module)))
4 changes: 2 additions & 2 deletions mk/spksrc.patch.mk
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ endif

# find patches into the following directory order:
# patches/*.patch
# patches/kernel-$(TC_KERNEL)/*.patch
# patches/kernel-$(subst +,,$(TC_KERNEL))/*.patch ## Discard any ending +
# patches/DSM-$(TCVERSION)/*.patch
# patches/$(group)/*.patch
# patches/$(group)-$(TCVERSION)/*.patch
Expand All @@ -27,7 +27,7 @@ endif
ifeq ($(strip $(PATCHES)),)
PATCHES = $(foreach group,ARMv5_ARCHS ARMv7_ARCHS ARMv7L_ARCHS ARMv8_ARCHS PPC_ARCHS i686_ARCHS x64_ARCHS, \
$(foreach arch,$($(group)), \
$(if $(filter $(ARCH),$(arch)),$(sort $(wildcard patches/*.patch patches/kernel-$(TC_KERNEL)/*.patch patches/DSM-$(TCVERSION)/*.patch patches/$(shell echo ${group} | cut -f1 -d'_'| tr '[:upper:]' '[:lower:]')/*.patch patches/$(shell echo ${group} | cut -f1 -d'_'| tr '[:upper:]' '[:lower:]')-$(TCVERSION)/*.patch patches/$(arch)/*.patch patches/$(arch)-$(TCVERSION)/*.patch)),)))
$(if $(filter $(ARCH),$(arch)),$(sort $(wildcard patches/*.patch patches/kernel-$(subst +,,$(TC_KERNEL))/*.patch patches/DSM-$(TCVERSION)/*.patch patches/$(shell echo ${group} | cut -f1 -d'_'| tr '[:upper:]' '[:lower:]')/*.patch patches/$(shell echo ${group} | cut -f1 -d'_'| tr '[:upper:]' '[:lower:]')-$(TCVERSION)/*.patch patches/$(arch)/*.patch patches/$(arch)-$(TCVERSION)/*.patch)),)))
endif

PATCH_COOKIE = $(WORK_DIR)/.$(COOKIE_PREFIX)patch_done
Expand Down
17 changes: 16 additions & 1 deletion mk/spksrc.plist.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Variables:
# PLIST_TRANSFORM Command to transform PLIST (default: cat)

INSTALL_COOKIE = $(WORK_DIR)/.$(COOKIE_PREFIX)plist_done

ifeq ($(strip $(PLIST_TRANSFORM)),)
PLIST_TRANSFORM= cat
endif
Expand All @@ -16,7 +18,20 @@ cat_PLIST:
@if [ -f PLIST ] ; \
then \
$(PLIST_TRANSFORM) PLIST ; \
# If there is a PLIST.auto file or if parent directory is kernel \
elif [ -f PLIST.auto -o $$(basename $$(dirname $$(pwd))) = "kernel" ] ; \
then \
for file in $$(cat $(WORK_DIR)/$(PKG_NAME).plist.auto | sort) ; \
do \
type=$$(file -F, $(INSTALL_DIR)/$(INSTALL_PREFIX)/$$file | awk -F',[[:blank:]]' '{print $$2}') ; \
case $$type in \
ELF*LSB[[:space:]]executable ) echo "bin:$$file" ;; \
ELF* ) echo "lib:$$file" ;; \
symbolic[[:space:]]link* ) echo "lnk:$$file" ;; \
* ) echo "rsc:$$file" ;; \
esac \
done \
else \
$(MSG) "No PLIST for $(NAME)" >&2; \
fi

@touch -f $(INSTALL_COOKIE)
7 changes: 7 additions & 0 deletions mk/spksrc.tc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ default: all
WORK_DIR := $(shell pwd)/work
include ../../mk/spksrc.directories.mk

include ../../mk/spksrc.common.mk


# Configure the included makefiles
URLS = $(TC_DIST_SITE)/$(TC_DIST_NAME)
Expand Down Expand Up @@ -83,7 +85,12 @@ tc_vars: fix
@echo TC_BUILD := $(TC_BUILD)
@echo TC_OS_MIN_VER := $(TC_OS_MIN_VER)
@echo TC_ARCH := $(TC_ARCH)
# Add "+" to EXTRAVERSION for kernels version >= 4.4
ifeq ($(call version_ge, ${TC_KERNEL}, 4.4),1)
@echo TC_KERNEL := $(TC_KERNEL)+
else
@echo TC_KERNEL := $(TC_KERNEL)
endif
@echo TC_GCC := $(TC_GCC)
@echo TC_GLIBC := $(TC_GLIBC)

Expand Down