1、获取最新内核源码以及工具链
git clone 完成之后:
$ ls -l
total 8K
drwxr-xr-x 25 root root 4.0K Jun 21 11:21 linux/
drwxr-xr-x 8 root root 4.0K Jun 20 20:48 tools/ |
2、编译内核及模块
A、设置环境变量,添加交叉编译工具链的路径
export PATH=$PATH:/root/wk/raspberry/tools/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin | 验证环境变量是否正常
$ whereis arm-bcm2708hardfp-linux-gnueabi-gcc
arm-bcm2708hardfp-linux-gnueabi-gcc: /root/wk/raspberry/tools/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/arm-bcm2708hardfp-linux-gnueabi-gcc |
B、修改Makefile
$ cd linux
$ vi Makefile
将
ARCH ?= $(SUBARCH)
CROSS_COMPILE ?= $(CONFIG_CROSS_COMPILE:"%"=%)
改为
ARCH ?= arm
CROSS_COMPILE ?= arm-bcm2708hardfp-linux-gnueabi-
|
C、查看内核版本
$ make kernelrelease
3.12.22+ |
后面这个加号很别扭,试图去掉:
$ vi scripts/setlocalversion
注释第55行
即:
54 if $short; then
55 echo "+"
56 return
57 fi
改为
54 if $short; then
55 # echo "+"
56 return
57 fi
|
$ make kernelrelease
3.12.22 |
D、编译内核及模块
$ cp arch/arm/configs/bcmrpi_defconfig .config
$ make menuconfig
$ make -j 4
$ make modules –j 4 |
E、生成内核img,打包内核模块,并拷贝到树莓派上
$ cd tools/mkimage/
$ python2 ./imagetool-uncompressed.py ../../linux/arch/arm/boot/Image
$ ls kernel.img -l
-rw-r--r-- 1 root root 6.0M Jun 21 11:16 kernel.img | 打包内核模块
$ tar -cjvf modules.tar.bz2 /root/wk/raspberry/image/modules |
将modules.tar.bz2 和 kernel.img 拷贝到树莓派
3、在树莓派上更换内核及模块
$ ls -l
总用量 16924
-rw-r--r-- 1 pi pi 6289676 6月 21 2014 kernel.img
-rw-r--r-- 1 pi pi 11027407 6月 21 2014 modules.tar.bz2 |
换内核
$ mv kernel.img /boot/kernel_3.12.22.imag | 修改config.txt,指定使用的内核版本
$ vi /boot/config.txt 最后一行添加:
kernel=kernel_3.12.22.imag
|
换内核模块
$ tar -xjvm modules.tar.bz2
$ mv root/wk/raspberry/image/modules/lib/modules/3.12.22/ /lib/modules/
| 生成内核模块的依赖
4、验证内核及模块是否更换正常
重启前记录内核版本
$ uname -a
Linux raspberrypi 3.10.25+ #622 PREEMPT Fri Jan 3 18:41:00 GMT 2014 armv6l GNU/Linux |
重启之后
$ uname -a
Linux raspberrypi 3.12.22 #1 PREEMPT Fri Jun 20 21:14:17 UTC 2014 armv6l GNU/Linux
$ lsmod
Module Size Used by
snd_bcm2835 18169 0
snd_soc_bcm2708_i2s 5486 0
regmap_mmio 2818 1 snd_soc_bcm2708_i2s
snd_soc_core 128254 1 snd_soc_bcm2708_i2s
snd_compress 8168 1 snd_soc_core
regmap_i2c 1657 1 snd_soc_core
snd_pcm_dmaengine 5481 1 snd_soc_core
regmap_spi 1913 1 snd_soc_core
snd_pcm 81542 3 snd_bcm2835,snd_soc_core,snd_pcm_dmaengine
snd_page_alloc 5168 1 snd_pcm
snd_seq 54581 0
snd_seq_device 6485 1 snd_seq
snd_timer 20353 2 snd_pcm,snd_seq
leds_gpio 2055 0
led_class 4119 1 leds_gpio
snd 61526 7 snd_bcm2835,snd_soc_core,snd_timer,snd_pcm,snd_seq,snd_seq_device,snd_compress
|
|
|