树莓派 zero w 4.19 内核头文件安装方法

本文详细介绍了如何在树莓派Zero w上手动安装4.19.118内核头文件,包括遇到的问题、解决步骤以及成功验证的方法,适合需要降级内核编译项目的读者参考。
摘要由CSDN通过智能技术生成

树莓派Zero w 4.19 内核头文件安装方法

本文介绍了树莓派 zero w 系统安装内核头文件的方法,理论上可以安装任意版本内核。文章介绍了起因,解决过程及结果,您也可以直接跳到文末看结论。

缘起

话说我为了安装M项目,将树莓派 zero w 内核手动降级到 4.19.118 版本,兴高采烈的去编译 M 项目,结果到最后依然出错,抱怨找不到头文件。

  APPLYING FLASHPATCHES gen/flashpatches.mk => brcmfmac43430-sdio.bin (details: log/flashpatches.log)
  APPLYING PATCHES gen/nexmon.mk => brcmfmac43430-sdio.bin (details: log/patches.log)
  BUILDING DRIVER for kernel 4.19 brcmfmac_4.19.y-nexmon/brcmfmac.ko (details: log/driver.log)
make[1]: *** /lib/modules/4.19.118+/build: No such file or directory.  Stop.
make: *** [Makefile:46: brcmfmac.ko] Error 2

手动检查头文件,果然不存在

$ ls /lib/modules/4.19.118+/build
ls: cannot access '/lib/modules/4.19.118+/build': No such file or directory

检查已安装的头文件,依然是 5.4.51-v7l

$ dpkg -S linux-headers
raspberrypi-kernel-headers: /usr/src/linux-headers-5.4.51+/arch/arm/mach-ixp4xx/Makefile
raspberrypi-kernel-headers: /usr/src/linux-headers-5.4.51-v7l+/drivers/phy/lantiq/Kconfig
raspberrypi-kernel-headers: /usr/src/linux-headers-5.4.51+/arch/x86/math-emu/Makefile
...

我只好又执行一遍安装指令,失败

sudo apt-get install --reinstall raspberrypi-kernel-headers
Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 0 not upgraded.
Need to get 26.2 MB of archives.
After this operation, 0 B of additional disk space will be used.
Get:1 http://mirrors.tuna.tsinghua.edu.cn/raspberrypi buster/main armhf raspberrypi-kernel-headers armhf 1.20200811-1 [26.2 MB]
Fetched 26.2 MB in 15s (1,704 kB/s)                                                                                                                        
(Reading database ... 213822 files and directories currently installed.)
Preparing to unpack .../raspberrypi-kernel-headers_1.20200811-1_armhf.deb ...
Unpacking raspberrypi-kernel-headers (1.20200811-1) over (1.20200811-1) ...
Setting up raspberrypi-kernel-headers (1.20200811-1) ...
W: Operation was interrupted before it could finish

尝试明确指明头文件版本,未发现安装包

$ sudo apt-get install linux-headers-$(uname -r)
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package linux-headers-4.19.118
E: Couldn't find any package by glob 'linux-headers-4.19.118'
E: Couldn't find any package by regex 'linux-headers-4.19.118'

全网搜索,终于找到手动安装内核头文件的方法,使用 rpi-source

$ sudo wget https://raw.githubusercontent.com/notro/rpi-source/master/rpi-source -O /usr/local/bin/rpi-source && sudo chmod +x /usr/local/bin/rpi-source && /usr/local/bin/rpi-source -q --tag-update

 *** SoC: BCM2835
ERROR:
bc is NOT installed. Needed by 'make modules_prepare'. On Raspbian, run 'sudo apt-get install bc' to install it.

Help: https://github.com/notro/rpi-source/wiki

看起来缺少 bc 包,安装之

$ sudo apt-get install bc
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  bc
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 101 kB of archives.
After this operation, 220 kB of additional disk space will be used.
Get:1 http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian buster/main armhf bc armhf 1.07.1-2 [101 kB]
Fetched 101 kB in 0s (228 kB/s)
Selecting previously unselected package bc.
(Reading database ... 205567 files and directories currently installed.)
Preparing to unpack .../archives/bc_1.07.1-2_armhf.deb ...
Unpacking bc (1.07.1-2) ...
Setting up bc (1.07.1-2) ...
Processing triggers for install-info (6.5.0.dfsg.1-4+b1) ...
Processing triggers for doc-base (0.10.8) ...
Processing 1 added doc-base file...
Processing triggers for man-db 
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值