add post: openwrt kernel vermagic

This commit is contained in:
Tsanie Lily 2021-08-20 17:07:25 +08:00
parent 2f12cd1030
commit 4991712125

View File

@ -0,0 +1,59 @@
---
title: OpenWrt 自行编译的内核扩展安装失败的解决方法
date: 2021-08-20 16:53:07
tags:
---
## 现象 ##
拉取 `OpenWrt` 源码编译出来的内核扩展 `ipk` 拿到装有官方版本 `OpenWrt` 的路由器上无法安装,出现以下提示:
```shell
* satisfy_dependencies_for: Cannot satisfy the following dependencies for kmod-xxx:
* kernel (= 4.14.241-1-68143adfcb7fc62a239c4be112fe40de)
* opkg_install_cmd: Cannot install package kmod-xxx.
```
## 解决方案 ##
修改 `kernel vermagic` 从计算配置文件的 `md5 hash` 改为固定值。
<!-- more -->
* `OpenWrt` 源码根目录添加文件 `vermagic`
```shell
cat 68143adfcb7fc62a239c4be112fe40de ./vermagic
```
* 修改 `kernel-defaults.mk`
```diff
diff --git a/include/kernel-defaults.mk b/include/kernel-defaults.mk
index cc1e2361be..35ffc1fbba 100644
--- a/include/kernel-defaults.mk
+++ b/include/kernel-defaults.mk
@@ -105,7 +105,7 @@ define Kernel/Configure/Default
cp $(LINUX_DIR)/.config.set $(LINUX_DIR)/.config.prev; \
}
$(_SINGLE) [ -d $(LINUX_DIR)/user_headers ] || $(KERNEL_MAKE) INSTALL_HDR_PATH=$(LINUX_DIR)/user_headers headers_install
- grep '=[ym]' $(LINUX_DIR)/.config.set | LC_ALL=C sort | mkhash md5 > $(LINUX_DIR)/.vermagic
+ cp $(TOPDIR)/vermagic $(LINUX_DIR)/.vermagic
endef
```
* 修改 `package/kernel/linux/Makefile`
```diff
diff --git a/package/kernel/linux/Makefile b/package/kernel/linux/Makefile
index 39b9e82c27..6ff64b2939 100644
--- a/package/kernel/linux/Makefile
+++ b/package/kernel/linux/Makefile
@@ -24,7 +24,7 @@ export SHELL:=/bin/sh
include $(INCLUDE_DIR)/package.mk
ifeq ($(DUMP),)
- STAMP_BUILT:=$(STAMP_BUILT)_$(shell $(SCRIPT_DIR)/kconfig.pl $(LINUX_DIR)/.config | mkhash md5)
+ STAMP_BUILT:=$(STAMP_BUILT)_$(shell cat $(LINUX_DIR)/.vermagic)
-include $(LINUX_DIR)/.config
endif
```
## 重新编译 ##
```shell
$ make clean # 注意清除缓存
$ make -j1 V=s
```