ubuntu1604虚拟机下交叉编译树莓派3b+内核。文件系统使用原生raspian的
Step 1
下载 2020-02-13-raspbian-buster.img(地址)并使用rasp Imager将其烧录到sd卡。这个版本的系统貌似默认使用kernel7.img(kernel8就是64bit的系统了),不放心可以在/boot/config.txt中添加kernel=kernel7.img
Step2
安装必要的包
sudo apt-get update
sudo apt-get install bc build-essential git unzip
sudo apt-get install kernel-package libncurses5-dev
Step3
下载rasp使用的kernel以及工具链
git clone --depth=1 -b rpi-4.14.y https://github.com/raspberrypi/linux.git
git clone https://github.com/raspberrypi/tools
export PATH=$PATH:/home/fang/Desktop/raspberry2/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/
export PATH=$PATH:/home/fang/Desktop/raspberry2/tools/arm-bcm2708/arm-bcm2708-linux-gnueabi/bin
source ~/.bashrc
Step4
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcm2709_defconfig
如有必要,进一步进行定制
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig
编译
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage modules dtbs -j8
rasp3b+的设备树在?arch/arm/boot/dts/bcm2710-rpi-3-b-plus.dts
Step5
安装到sd卡
sudo scripts/mkknlimg arch/arm/boot/zImage /media/fang/boot/kernel7.img
sudo cp arch/arm/boot/dts/*.dtb /media/fang/boot/
sudo cp arch/arm/boot/dts/overlays/*.dtb* /media/fang/boot/overlays/
sudo cp arch/arm/boot/dts/overlays/README /media/fang/boot/overlays/
sudo make ARCH=arm INSTALL_MOD_PATH=/media/fang/rootfs/ modules_install
进入raspian后,uname -a查看是否是自己编译的系统。
后续kernel module编写,Makefile可以如下
##单文件module版本Makefile
obj-m := helloworld.o
#KERNELDIR ?= /lib/modules/$(shell uname -r)/build
KERNELDIR ?= /home/fang/Desktop/raspberry2/linux
all default: modules
install: modules_install
modules modules_install help clean:
$(MAKE) -C $(KERNELDIR) M=$(shell pwd) $@ CROSS_COMPILE=arm-linux-gnueabihf- ARCH=arm
##多文件module版本Makefile
#obj-m := helloworld.o
#helloworld-objs := file1.o file2.o file3.o ...
#
##KERNELDIR ?= /lib/modules/$(shell uname -r)/build
#KERNELDIR ?= /home/fang/Desktop/raspberry2/linux
#
#all default: modules
#install: modules_install
#
#modules modules_install help clean:
# $(MAKE) -C $(KERNELDIR) M=$(shell pwd) $@ CROSS_COMPILE=arm-linux-gnueabihf- ARCH=arm
参考
Raspberry Pi Documentation - The Linux kernel
https://blog.csdn.net/Blazar/article/details/88777101
|