ILD

openwrt 内核打patch流程
作者:Yuan Jianpeng 邮箱:yuanjp89@163.com
发布时间:2019-11-2 站点:Inside Linux Development

内核的版本是在每个BOARD的Makefile中指定的,比如IPQ40XX。

1
2
3
$ ls target/linux/ipq40xx/
base-files  config-4.14  config-4.19  files-4.14  files-4.19  image  Makefile  
patches-4.14  patches-4.19  profiles



在上述Makefile中,定义了:

KERNEL_PATCHVER:=4.14


首先解压linux官方的tar包,然后拷贝files-4.14,然后打patch。

cp -fpR openwrt/target/linux/ipq40xx/files-4.14/ kernel/linux-4.14.120/

./scripts/patch-kernel.sh /work/openwrt/kernel/linux-4.14.120/ target/linux/ipq40xx/patches-4.14/


这个变量和脚本定义在include/kernel.mk和include/quilt.mk


上面的方法不全,内核打patch的代码,定义在quilt.mk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
 95 kernel_files=$(foreach fdir,$(GENERIC_FILES_DIR) $(FILES_DIR),$(fdir)/.) 
 96 define Kernel/Patch/Default
 97         $(if $(QUILT),rm -rf $(LINUX_DIR)/patches; mkdir -p $(LINUX_DIR)/patches)
 98         $(if $(kernel_files),$(CP) $(kernel_files) $(LINUX_DIR)/)
 99         find $(LINUX_DIR)/ -name \*.rej -or -name \*.orig | $(XARGS) rm -f
100         if [ -d $(GENERIC_PLATFORM_DIR)/patches$(if $(wildcard $(GENERIC_PLATFORM_DIR)/patches-$(KERNEL_PATCHVER)),-$(KERNEL_PATCHVER)) ]; then \
101                 echo "generic patches directory is present. please move your patches to the pending directory" ; \
102                 exit 1; \
103         fi
104         $(call PatchDir,$(LINUX_DIR),$(GENERIC_BACKPORT_DIR),generic-backport/)
105         $(call PatchDir,$(LINUX_DIR),$(GENERIC_PATCH_DIR),generic/)
106         $(call PatchDir,$(LINUX_DIR),$(GENERIC_HACK_DIR),generic-hack/)
107         $(call PatchDir,$(LINUX_DIR),$(PATCH_DIR),platform/)
108 endef

有好几个目录,files目录有:arget/linux/generic/files,target/linux/ipq40xx/files-4.14

patches目录有:

target/linux/generic/backport-4.14

inux/generic/pending-4.14

target/linux/generic/hack-4.14

target/linux/ipq40xx/patches-4.14


其实,只要执行 make target/linux/prepare,就可以了,这个目标只会额外多touch一个.prepared,删除即可。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 30 ifeq ($(strip $(CONFIG_EXTERNAL_KERNEL_TREE)),"")
 31   ifeq ($(strip $(CONFIG_KERNEL_GIT_CLONE_URI)),"")
 32     define Kernel/Prepare/Default
 33         $(LINUX_CAT) $(DL_DIR)/$(LINUX_SOURCE) | $(TAR) -C $(KERNEL_BUILD_DIR) $(TAR_OPTIONS)
 34         $(Kernel/Patch)
 35         $(if $(QUILT),touch $(LINUX_DIR)/.quilt_used)
 36     endef
 37   else
 38     define Kernel/Prepare/Default
 39         $(LINUX_CAT) $(DL_DIR)/$(LINUX_SOURCE) | $(TAR) -C $(KERNEL_BUILD_DIR) $(TAR_OPTIONS)
 40     endef
 41   endif
 42 else
 43   define Kernel/Prepare/Default
 44         mkdir -p $(KERNEL_BUILD_DIR)
 45         if [ -d $(LINUX_DIR) ]; then \
 46                 rmdir $(LINUX_DIR); \
 47         fi
 48         ln -s $(CONFIG_EXTERNAL_KERNEL_TREE) $(LINUX_DIR)
 49   endef
 50 endif


$(Kernel/Patch),就是$(Kernel/Patch/Default)



Copyright © linuxdev.cc 2017-2024. Some Rights Reserved.