Linux Driver

2016年6月16日 星期四

Quick guide for building Raspberry Pi kernel

For ITC Driver course (

1) 安裝toolchain (Cross compiler)

#32 位元linux kernel

export PATH=/home/student/pi/tools/arm-bcm2708/arm-bcm2708-linux-gnueabi/bin:$PATH

#64 位元linux kernel
export PATH=/home/student/pi/tools/arm-bcm2708/arm-bcm2708-linux-gnueabi-x64/bin:$PATH

root@ubuntu:/home/student/pi# arm-linux-gnueabihf-gcc -v

gcc version 4.8.3 20140303 (prerelease) (crosstool-NG linaro-1.13.1+bzr2650 - Linaro GCC 2014.03)

2) Linux kernel 編譯

#進入kernel source tree
cd linux  


# make config
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcm2709_defconfig

#Linux kernel 編譯, 同時編譯 kernel module 及 device tree
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage modules dtbs -j 2

#install  kernel module
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=../modules modules_install

#kernel mkknlim處理
./scripts/mkknlimg ./arch/arm/boot/zImage ../kernel7.img

#copy dtb
scp ./bcm2709-rpi-2-b.dtb  root@
$ sudo scripts/mkknlimg arch/arm/boot/zImage mnt/fat32/$KERNEL.img
$ sudo cp arch/arm/boot/dts/*.dtb mnt/fat32/
$ sudo cp arch/arm/boot/dts/overlays/*.dtb* mnt/fat32/overlays/
$ sudo cp arch/arm/boot/dts/overlays/README mnt/fat32/overlays/

#copy kernel source to pi
scp linux-rpi-3.18.y-joseph.tar.gz root@
tar zxvf linux-rpi-3.18.y.tar.gz

# redirect to kernel source

cd /lib/modules/3.18.16-v7
ln -s /root/linux-rpi-3.18.y build

#check out driver source code
svn co svn://


nano /boot/config.txt

3.18.16 以後(因使用device tree)要增加I2C Module 及SPI Module 要修改/boot/config.txt

#lsmod 會看見i2c_bcm2708 , spi_bcm2708

# Uncomment some or all of these to enable the optional hardware interfaces

sudo modprobe i2c-dev


沒有留言 :