Raspberry 编译环境设置

Raspberry 2买回来吃了半年灰,惭愧,记录一下最初的经历。

首先从github上clone源码和工具,过程省略,速度比较慢,大概一晚上。

简单介绍一下git的常用操作:
使用git clone从远程服务器下载代码;
查看所有分支 $git branch -a 包括本地的和远程服务器的;
删除分支 $git branch –d/-D branch-name
例如删除名为”-r”的分支:git branch -D '-r'

获取远程分支的操作:
首先查看所有分支 $ git branch –a
查看本地分支 $ git branch
最后获取远程分支 $ git checkout -b new_branch remote_branch ,其中new_branch是本地分支名称,remote_branch是将要获取的远程分支名称,例如: $ git checkout –b rpi-3.18.y origin/rpi-3.18.y

切换分支使用:git checkout <branch_name>

$ git checkout rpi-3.18.y
Switched to branch 'rpi-3.18.y'

使用 $git fetch git://github.com/raspberrypi/linux.git 更新代码,需要在本地仓库的目录下执行,如果在其它目录下会出现以下错误提示:

fatal: Not a git repository (or any parent up to mount parent )
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).

设置raspberry使用的交叉编译工具

官方提供的编译工具中包含三套工具链

arm-bcm2708hardfp-linux-gnueabi
arm-bcm2708-linux-gnueabi
gcc-linaro-arm-linux-gnueabihf-raspbian

这里使用第一种交叉编译工具

首先打开~/.bashrc文件(~符号表示HOME路径,.bashrc为隐藏文件)

zfchen@zfchen-E440:~$ sudo gedit ~/.bashrc

然后在文件的最后面添加交叉编译工具的路径,如下:

export PATH=$PATH:/home/zfchen/my_repository/tools/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin

保存并退出文件,接下来需要更新当前控制台所包含的环境变量(使上面添加的path生效),有两种方法:

  1. 执行以下命令 source .bashrc
  2. 重新登录系统(不必重启机器, “开始->logout” 即可),使以上设置生效。(登陆linux,启动bash时,首先会去读取~/.bash_profile文件,这样~/.bashrc也就得到执行了,你的个性化设置也就生效了。)

然后使用 arm-bcm2708hardfp-linux-gnueabi-cc -v 命令来测试交叉编译工具的路径是否设置成功。

zfchen@zfchen-E440:/$ arm-bcm2708hardfp-linux-gnueabi-cc -v
Using built-in specs.
COLLECT_GCC=arm-bcm2708hardfp-linux-gnueabi-cc
COLLECT_LTO_WRAPPER=/home/zfchen/my_repository/tools/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/...
Target: arm-bcm2708hardfp-linux-gnueabi
Configured with: /home/extra/crosstool/staginghf/.build/src/gcc-linaro-4.7-2012.04/configure --build=i686-build_pc-linux-gnu --host=i686-build_pc-linux-gnu --target=arm-bcm2708hardfp-linux-gnueabi --prefix=/home/dc4/tools/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi --with-sysroot=/home/dc4/tools/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/arm-bcm2708hardfp-linux-gnueabi/sysroot --enable-languages=c,c++ --with-cpu=arm1176jzf-s --with-tune=arm1176jzf-s --with-float=hard --with-pkgversion='crosstool-NG 1.15.2' --enable-__cxa_atexit --disable-libmudflap --disable-libgomp --disable-libssp --with-gmp=/home/extra/crosstool/staginghf/.build/arm-bcm2708hardfp-linux-gnueabi/buildtools --with-mpfr=/home/extra/crosstool/staginghf/.build/arm-bcm2708hardfp-linux-gnueabi/buildtools --with-mpc=/home/extra/crosstool/staginghf/.build/arm-bcm2708hardfp-linux-gnueabi/buildtools --with-ppl=/home/extra/crosstool/staginghf/.build/arm-bcm2708hardfp-linux-gnueabi/buildtools --with-cloog=/home/extra/crosstool/staginghf/.build/arm-bcm2708hardfp-linux-gnueabi/buildtools --with-libelf=/home/extra/crosstool/staginghf/.build/arm-bcm2708hardfp-linux-gnueabi/buildtools --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm -L/home/extra/crosstool/staginghf/.build/arm-bcm2708hardfp-linux-gnueabi/buildtools/lib -lpwl' --enable-threads=posix --enable-target-optspace --disable-nls --disable-multilib --with-local-prefix=/home/dc4/tools/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/arm-bcm2708hardfp-linux-gnueabi/sysroot --enable-c99 --enable-long-long --with-float=hard
Thread model: posix
gcc version 4.7.1 20120402 (prerelease) (crosstool-NG 1.15.2) 

PS:在用户模式下设置的.bashrc环境变量只对当前用户有效(如果root直接运行arm-bcm2708hardfp-linux-gnueabi-cc -v,则会提示“命令未找到”)。

编译内核

(1)首先生成配置文件

$ make ARCH=arm CROSS_COMPILE=../tools/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/arm-bcm2708hardfp-linux-gnueabi- menuconfig

我尝试过的不同分支如下:
// rpi-3.18.y分支的内核版本为Linux/arm 3.18.16 Kernel
// rpi-3.18.y-rebase分支的内核版本为Linux/arm 3.18.9 Kernel Configuration

(2)编译内核

$ make ARCH=arm CROSS_COMPILE=../tools/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/arm-bcm2708hardfp-linux-gnueabi-

编译结果如下,说明成功

... ...
  AS      arch/arm/boot/compressed/ashldi3.o
  SHIPPED arch/arm/boot/compressed/bswapsdi2.S
  AS      arch/arm/boot/compressed/bswapsdi2.o
  LD      arch/arm/boot/compressed/vmlinux
  OBJCOPY arch/arm/boot/zImage
  Kernel: arch/arm/boot/zImage is ready

第一次make menuconfig时出错:

zfchen@zfchen-E440:~/my_repository/linux$ make menuconfig
  HOSTCC  scripts/basic/fixdep
  HOSTCC  scripts/kconfig/mconf.o
In file included from scripts/kconfig/mconf.c:23:0:
scripts/kconfig/lxdialog/dialog.h:38:20: 致命错误:curses.h:没有那个文件或目录编译中断。

原因:宿主机ubuntu系统中缺少一个套件 ncurses devel
解决方法,安装ncurses

$ sudo apt-get install libncurses5-dev

(注意:内核配置不对也会导致编译过程出错,例如“提示缺少XX文件”)

对于raspberry 2B,执行如下操作:

$ cp arch/arm/boot/zImage /boot/kernel7.img

(raspberry pi A/B/B+ 需要用imagetool-uncompressed.py工具生成*.img文件)

(3)提取modules

$ make ARCH=arm CROSS_COMPILE=../tools/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/arm-bcm2708hardfp-linux-gnueabi- modules_install INSTALL_MOD_PATH=../modules
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值