ubuntu php 树莓派,Ubuntu 16.04 (x64)树莓派B+(Raspberry Pi B+)源代码编译

树莓派上的操作

1.升级到最新版内核保证与下载的内核源码版本一致

$ sudo rpi-update

1

$sudorpi-update

2.升级完整后重启

$ sudo reboot

1

$sudoreboot

3.查看内核版本

$ uname -r

1

$uname-r

4.把最新版本的内核配置保存到.config中,以备以后编译内核使用

$ sudo modprobe configs

1

$sudomodprobeconfigs

文件被存储到了/proc/config.gz中。

目前最新版本是4.4.12,因此下面的编译都是针对4.4.y这个分支进行的。

Debian/Ubuntu下编译

1.获取内核源代码

$ cd ~

$ mkdir rpi

$ cd rpi

1

2

3

4

5

$cd~

$mkdirrpi

$cdrpi

2,以下步骤时间很长,可以在睡觉前执行,并且可能需要重试几次才行,建议同时开三个Shell一起执行。

$ git clone git://github.com/raspberrypi/firmware.git rpi-firmware

$ git clone git://github.com/raspberrypi/linux.git rpi-linux

$ git clone git://github.com/raspberrypi/tools.git rpi-tools

1

2

3

4

5

$gitclonegit://github.com/raspberrypi/firmware.gitrpi-firmware

$gitclonegit://github.com/raspberrypi/linux.gitrpi-linux

$gitclonegit://github.com/raspberrypi/tools.gitrpi-tools

3.给予整个rpi-tools目录执行权限,默认可能没有执行权限

$ chmod +x -R rpi-tools

1

$chmod+x-Rrpi-tools

4.整个的rpi-linux的文件夹的所有者更改为当前用户,否则存在一定程度的编译问题,特别是代码从其他系统上拷贝过来的情况

$ sudo chown -R `whoami` rpi-linux/

1

$sudochown-R`whoami`rpi-linux/

5.设置编译器的路径

$ export PATH=$PATH:~/rpi/rpi-tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin

1

$exportPATH=$PATH:~/rpi/rpi-tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin

6.配置编译类型

$ cd rpi-linux/

$ KERNEL=kernel

$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcmrpi_defconfig

1

2

3

4

5

$cdrpi-linux/

$KERNEL=kernel

$makeARCH=armCROSS_COMPILE=arm-linux-gnueabihf-bcmrpi_defconfig

如果提示是否增加新的驱动支持,默认全部选择否(输入大写的字母N,小写字母无效),否则会导致无法编译通过。

7.修正rpi-tools工具中的BUG,Ubuntu不支持一个文本文件中指明真正的可执行程序,这种操作会导致传递的参数丢失。

$ cp ../rpi-tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-gcc ../rpi-tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-gcc_old

$ cp ../rpi-tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-gcc-4.8.3 ../rpi-tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-gcc

$ cp ../rpi-tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-ld ../rpi-tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-ld_old

$ cp ../rpi-tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-ld.bfd ../rpi-tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-ld

1

2

3

4

5

6

7

$cp../rpi-tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-gcc../rpi-tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-gcc_old

$cp../rpi-tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-gcc-4.8.3../rpi-tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-gcc

$cp../rpi-tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-ld../rpi-tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-ld_old

$cp../rpi-tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-ld.bfd../rpi-tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-ld

8.开始正式编译内核,最后的数字改成比你的CPU核心数量+1以提交多线程编译效率。

$ make clean

$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage modules dtbs -j5

1

2

3

$makeclean

$makeARCH=armCROSS_COMPILE=arm-linux-gnueabihf-zImagemodulesdtbs-j5

9.编译错误修正,如果提示如下错误

DTC arch/arm/boot/dts/bcm2708-rpi-b.dtb

In file included from arch/arm/boot/dts/bcm2708.dtsi:1:0,

from arch/arm/boot/dts/bcm2708-rpi-b.dts:3:

arch/arm/boot/dts/bcm2708_common.dtsi:1:39: fatal error: dt-bindings/clock/bcm2835.h: 没有那个文件或目录

#include "dt-bindings/clock/bcm2835.h"

^

compilation terminated.

scripts/Makefile.lib:293: recipe for target 'arch/arm/boot/dts/bcm2708-rpi-b.dtb' failed

make[1]: *** [arch/arm/boot/dts/bcm2708-rpi-b.dtb] Error 1

arch/arm/Makefile:340: recipe for target 'dtbs' failed

make: *** [dtbs] Error 2

1

2

3

4

5

6

7

8

9

10

11

DTCarch/arm/boot/dts/bcm2708-rpi-b.dtb

Infileincludedfromarch/arm/boot/dts/bcm2708.dtsi:1:0,

fromarch/arm/boot/dts/bcm2708-rpi-b.dts:3:

arch/arm/boot/dts/bcm2708_common.dtsi:1:39:fatalerror:dt-bindings/clock/bcm2835.h:没有那个文件或目录

#include "dt-bindings/clock/bcm2835.h"

^

compilationterminated.

scripts/Makefile.lib:293:recipefortarget'arch/arm/boot/dts/bcm2708-rpi-b.dtb'failed

make[1]:***[arch/arm/boot/dts/bcm2708-rpi-b.dtb]Error1

arch/arm/Makefile:340:recipefortarget'dtbs'failed

make:***[dtbs]Error2

这个现象非常的奇怪,因为这个文件确实是存在的,并且确实在编译内核的时候是指定了包含路径的,但是在编译的时候一直是报告找不到,估计是编译过程中某些脚本修改了环境变量导致的,目前的解决方法是指定绝对路径。

$ vim arch/arm/boot/dts/bcm2708_common.dtsi

1

$vimarch/arm/boot/dts/bcm2708_common.dtsi

找到代码

#include "dt-bindings/clock/bcm2835.h"

#include

#include "dt-bindings/power/raspberrypi-power.h"

#include "dt-bindings/gpio/gpio.h"

#include "skeleton.dtsi"

1

2

3

4

5

#include "dt-bindings/clock/bcm2835.h"

#include

#include "dt-bindings/power/raspberrypi-power.h"

#include "dt-bindings/gpio/gpio.h"

#include "skeleton.dtsi"

修改为类似如下的形式,重新执行上面的命令即可

#include "/home/rpi/rpi-linux/include/dt-bindings/clock/bcm2835.h"

#include

#include "/home/rpi/rpi-linux/include/dt-bindings/power/raspberrypi-power.h"

#include "/home/rpi/rpi-linux/include/dt-bindings/gpio/gpio.h"

#include "skeleton.dtsi"

1

2

3

4

5

#include "/home/rpi/rpi-linux/include/dt-bindings/clock/bcm2835.h"

#include

#include "/home/rpi/rpi-linux/include/dt-bindings/power/raspberrypi-power.h"

#include "/home/rpi/rpi-linux/include/dt-bindings/gpio/gpio.h"

#include "skeleton.dtsi"

10.查看生成的内核镜像文件

$ cd rpi-linux/arch/arm/boot

1

$cdrpi-linux/arch/arm/boot

生成的zImage就是我们需要的kernel.img。

11.编译modules

$ cd ../..

$ mkdir modules

$ cd rpi-linux

$ make modules_install ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=../modules -j5

1

2

3

4

5

6

7

$cd../..

$mkdirmodules

$cdrpi-linux

$makemodules_installARCH=armCROSS_COMPILE=arm-linux-gnueabihf-INSTALL_MOD_PATH=../modules-j5

安装编译好的内核

Ubuntu下面,SD卡会自动挂载,默认挂载到了/media/目录下面,如果是使用NOOBS安装的话,系统目录是固定的,执行如下命令拷贝到目标SD卡上面

$ mv /media/`whoami`/boot/kernel.img /media/`whoami`/boot/kernel_old.img

$ cp rpi-linux/arch/arm/boot/zImage /media/`whoami`/boot/kernel.img

$ mv /media/`whoami`/boot/bootcode.bin /media/`whoami`/boot/bootcode_old.bin

$ mv /media/`whoami`/boot/fixup.dat /media/`whoami`/boot/fixup_old.dat

$ mv /media/`whoami`/boot/fixup_cd.dat /media/`whoami`/boot/fixup_cd_old.dat

$ mv /media/`whoami`/boot/start.elf /media/`whoami`/boot/start_old.elf

$ cd rpi-firmware/boot

$ cp bootcode.bin fixup.dat fixup_cd.dat start.elf /media/`whoami`/boot/

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

$mv/media/`whoami`/boot/kernel.img/media/`whoami`/boot/kernel_old.img

$cprpi-linux/arch/arm/boot/zImage/media/`whoami`/boot/kernel.img

$mv/media/`whoami`/boot/bootcode.bin/media/`whoami`/boot/bootcode_old.bin

$mv/media/`whoami`/boot/fixup.dat/media/`whoami`/boot/fixup_old.dat

$mv/media/`whoami`/boot/fixup_cd.dat/media/`whoami`/boot/fixup_cd_old.dat

$mv/media/`whoami`/boot/start.elf/media/`whoami`/boot/start_old.elf

$cdrpi-firmware/boot

$cpbootcode.binfixup.datfixup_cd.datstart.elf/media/`whoami`/boot/

参考链接

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值