编译raspberry pi2内核

准备工作:

下载源码及工具:

内核源码:https://github.com/raspberrypi/linux.git

交叉编译工具:https://github.com/raspberrypi/tools.git

环境配置:

在~/.bashrc加入交叉编译工具的路径到环境变量,然后重启(本人电脑是64位):

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

测试交叉编译环境是否配置成功:

$arm-linux-gnueabihf-gcc -v

Using built-in specs.
COLLECT_GCC=arm-linux-gnueabihf-gcc
COLLECT_LTO_WRAPPER=/home/linjc/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/../libexec/gcc/arm-linux-gnueabihf/4.8.3/lto-wrapper
Target: arm-linux-gnueabihf
Configured with: /home/zhehe01/work/bzr/pi-build/builds/arm-linux-gnueabihf-raspbian-linux/.build/src/gcc-linaro-4.8-2014.03/configure --build=x86_64-build_unknown-linux-gnu --host=x86_64-build_unknown-linux-gnu --target=arm-linux-gnueabihf --prefix=/home/zhehe01/work/bzr/pi-build/builds/arm-linux-gnueabihf-raspbian-linux/install --with-sysroot=/home/zhehe01/work/bzr/pi-build/builds/arm-linux-gnueabihf-raspbian-linux/install/arm-linux-gnueabihf/libc --enable-languages=c,c++,fortran --disable-multilib --enable-multiarch --with-arch=armv6 --with-tune=arm1176jz-s --with-fpu=vfp --with-float=hard --with-pkgversion='crosstool-NG linaro-1.13.1+bzr2650 - Linaro GCC 2014.03' --with-bugurl=https://bugs.launchpad.net/gcc-linaro --enable-__cxa_atexit --enable-libmudflap --enable-libgomp --enable-libssp --with-gmp=/home/zhehe01/work/bzr/pi-build/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --with-mpfr=/home/zhehe01/work/bzr/pi-build/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --with-mpc=/home/zhehe01/work/bzr/pi-build/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --with-isl=/home/zhehe01/work/bzr/pi-build/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --with-cloog=/home/zhehe01/work/bzr/pi-build/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --with-libelf=/home/zhehe01/work/bzr/pi-build/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --enable-threads=posix --disable-libstdcxx-pch --enable-linker-build-id --enable-plugin --enable-gold --with-local-prefix=/home/zhehe01/work/bzr/pi-build/builds/arm-linux-gnueabihf-raspbian-linux/install/arm-linux-gnueabihf/libc --enable-c99 --enable-long-long --with-float=hard
Thread model: posix
gcc version 4.8.3 20140303 (prerelease) (crosstool-NG linaro-1.13.1+bzr2650 - Linaro GCC 2014.03)
如打印出以上信息则配置成功。

编译内核(参考:https://www.raspberrypi.org/documentation/linux/kernel/building.md):

编译前应安装bc:sudo apt-get install bc 或 pacman -S bc

编译前修改Makefile:

-ARCH           ?= $(SUBARCH)
-CROSS_COMPILE  ?= $(CONFIG_CROSS_COMPILE:"%"=%)
+ARCH           ?= arm
+CROSS_COMPILE  ?= arm-linux-gnueabihf-
编译:

$ cd linux
$ KERNEL=kernel7
$ make bcm2709_defconfig
$ make zImage modules dtbs
把编译结果写入SD卡:

之前使用NOOBS烧写完固件之后把SD卡插入电脑会多出两个盘,如:

/dev/sdc1

/dev/sdc2

我的电脑自动挂载为:

/run/media/linjc/boot/

/run/media/linjc/f24a4949-f4b2-4cad-a780-a138695079ec/

如果想要备份原来的内核,执行:

$ sudo cp /run/media/linjc/boot/$KERNEL.img /run/media/linjc/boot/$KERNEL-backup.img

然后执行:

$ sudo make INSTALL_MOD_PATH=/run/media/linjc/f24a4949-f4b2-4cad-a780-a138695079ec/ modules_install
$ sudo scripts/mkknlimg arch/arm/boot/zImage /run/media/linjc/boot/$KERNEL.img
$ sudo cp arch/arm/boot/dts/*.dtb /run/media/linjc/boot/
$ sudo cp arch/arm/boot/dts/overlays/*.dtb* /run/media/linjc/boot/overlays/
$ sudo cp arch/arm/boot/dts/overlays/README /run/media/linjc/boot/overlays/
$ sudo umount /run/media/linjc/boot/
$ sudo umount run/media/linjc/f24a4949-f4b2-4cad-a780-a138695079ec/

最后把SD卡插入paspberry pi2,重新上电即可。


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
从github.com/raspberrypi/tools完整下载的主分支,直接git太慢还容易失败,特意分享出来,实测在Ubuntu 18上安装x64工具链可用,gcc版本:4.8.3. 文件300M+,不能上传大于220M的,尝试过解压后分卷,会导致安装有问题,所以直接发一个链接,大家去那里下吧。 文件信息: └─tools-master ├─arm-bcm2708 │ ├─arm-bcm2708-linux-gnueabi │ │ ├─arm-bcm2708-linux-gnueabi │ │ │ ├─bin │ │ │ ├─debug-root │ │ │ │ └─usr │ │ │ │ └─bin │ │ │ ├─include │ │ │ │ └─c++ │ │ │ │ └─4.7.1 │ │ │ │ ├─arm-bcm2708-linux-gnueabi │ │ │ │ │ └─bits │ │ │ │ ├─backward │ │ │ │ ├─bits │ │ │ │ ├─debug │ │ │ │ ├─decimal │ │ │ │ ├─ext │ │ │ │ │ └─pb_ds │ │ │ │ │ └─detail │ │ │ │ │ ├─binary_heap_ │ │ │ │ │ ├─binomial_heap_ │ │ │ │ │ ├─binomial_heap_base_ │ │ │ │ │ ├─bin_search_tree_ │ │ │ │ │ ├─branch_policy │ │ │ │ │ ├─cc_hash_table_map_ │ │ │ │ │ ├─eq_fn │ │ │ │ │ ├─gp_hash_table_map_ │ │ │ │ │ ├─hash_fn │ │ │ │ │ ├─left_child_next_sibling_heap_ │ │ │ │ │ ├─list_update_map_ │ │ │ │ │ ├─list_update_policy │ │ │ │ │ ├─ov_tree_map_ │ │ │ │ │ ├─pairing_heap_ │ │ │ │ │ ├─pat_trie_ │ │ │ │ │ ├─rb_tree_map_ │ │ │ │ │ ├─rc_binomial_heap_ │ │ │ │ │ ├─resize_policy │ │ │ │ │ ├─splay_tree_ │ │ │ │ │ ├─thin_heap_ │ │ │ │ │ ├─tree_policy │ │ │ │ │ ├─trie_policy │ │ │ │ │ └─unordered_iterator │ │ │ │ ├─profile │ │ │ │ │ └─impl │ │ │ │ ├─tr1 │ │ │ │ └─tr2 │ │ │ └─sysroot │ │ │ ├─etc │ │ │ ├─lib │ │ │ ├─sbin │ │ │ └─usr │ │ │ ├─bin │ │ │ ├─include │ │ │ │ ├─arpa │ │ │ │ ├─asm │ │ │ │ ├─asm-generic │ │ │ │ ├─bits │ │ │ │ ├─drm │ │ │ │ ├─gnu │ │ │ │ ├─linux │ │ │ │ │ ├─byteorder │ │ │ │ │ ├─caif │ │ │ │ │ ├─can │ │ │ │ │ ├─dvb │ │ │ │ │ ├─hdlc │ │ │ │ │ ├─isdn │ │ │ │ │ ├─mmc │ │ │ │ │ ├─netfilter │ │ │ │ │ │ └─ipset │ │ │ │ │ ├─netfilter_arp │ │ │ │ │ ├─netfilter_bridge │ │ │ │ │ ├─netfilter_ipv4 │ │ │ │ │ ├─netfilter_ipv6 │ │ │ │ │ ├─nfsd │ │ │ │ │ ├─raid │ │ │ │ │ ├─spi │ │ │ │ │ ├─sunrpc │ │ │ │ │ ├─tc_act │ │ │ │ │ ├─tc_ematch │ │ │ │ │ ├─usb │ │ │ │ │ └─wimax │ │ │ │ ├─mtd │ │ │ │ ├─net │ │ │ │ ├─netash │ │ │ │ ├─netatalk │ │ │ │ ├─netax25 │ │ │ │ ├─neteconet │ │ │ │ ├─netinet │ │ │ │ ├─netipx │ │ │ │ ├─netiucv │ │ │ │ ├─netpacket │ │ │ │ ├─netrom │ │ │ │ ├─netrose │ │ │ │ ├─nfs │ │ │ │ ├─protocols │ │ │ │ ├─rdma │ │ │ │ ├─rpc │ │ │ │ ├─rpcsvc │ │ │ │ ├─scsi │ │ │ │ │ └─fc │ │ │ │ ├─sound │ │ │ │ ├─sys │ │ │ │ ├─video │ │ │ │ └─xen │ │ │ ├─lib │ │ │ │ └─gconv │ │ │ ├─libexec │ │ │ ├─sbin │ │ │ └─share │ │ │ ├─i18n │ │ │ │ ├─charmaps │ │ │ │ └─locales │ │ │ └─locale │ │ │ ├─be │ │ │ │ └─LC_MESSAGES │ │ │ ├─bg │ │ │ │ └─LC_MESSAGES │ │ │ ├─ca │ │ │ │ └─LC_MESSAGES │ │ │ ├─cs │ │ │ │ └─LC_MESSAGES │ │ │ ├─da │ │ │ │ └─LC_MESSAGES │ │ │ ├─de │ │ │ │ └─LC_MESSAGES │ │ │ ├─el │ │ │ │ └─LC_MESSAGES │ │ │ ├─en_GB │ │ │ │ └─LC_MESSAGES │ │ │ ├─es │ │ │ │ └─LC_

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值