树梅派1/2/3 编译
来源:互联网 发布:asp.net源码下载 编辑:程序博客网 时间:2024/06/07 09:50
https://www.raspberrypi.org/documentation/linux/kernel/building.md
Kernel building
There are two main methods for building the kernel. You can build locally on a Raspberry Pi, which will take a long time; or you can cross-compile, which is much quicker, but requires more setup.
Local building
On a Raspberry Pi, first install the latest version of Raspbian. Then boot your Pi, plug in Ethernet to give you access to the sources, and log in.
First get the sources, which will take some time:
git clone --depth=1 https://github.com/raspberrypi/linux
Add missing dependencies:
sudo apt-get install bc
Configure the kernel; as well as the default configuration, you may wish to configure your kernel in more detail or apply patches from another source, to add or remove required functionality:
Run the following commands, depending on your Raspberry Pi version.
Raspberry Pi 1 (or Compute Module) default build configuration
cd linuxKERNEL=kernelmake bcmrpi_defconfig
Raspberry Pi 2/3 default build configuration
cd linuxKERNEL=kernel7make bcm2709_defconfig
Build and install the kernel, modules, and Device Tree blobs; this step takes along time:
make -j4 zImage modules dtbssudo make modules_installsudo cp arch/arm/boot/dts/*.dtb /boot/sudo cp arch/arm/boot/dts/overlays/*.dtb* /boot/overlays/sudo cp arch/arm/boot/dts/overlays/README /boot/overlays/sudo scripts/mkknlimg arch/arm/boot/zImage /boot/$KERNEL.img
Note: On a Raspberry Pi 2/3, the -j4
flag splits the work between all four cores, speeding up compilation significantly.
Cross-compiling
First, you will need a suitable Linux cross-compilation host. We tend to use Ubuntu; since Raspbian isalso a Debian distribution, it means many aspects are similar, such as the command lines.
You can either do this using VirtualBox (or VMWare) on Windows, or install it directly onto your computer. For reference, you can follow instructions onlineat Wikihow.
Install toolchain
Use the following command to install the toolchain:
git clone https://github.com/raspberrypi/tools
You can then copy the /tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian
directory to a common location, and add/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin
to your $PATH in the.bashrc
in your home directory. For 64-bit host systems, use /tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin
. While this step isn't strictly necessary, it does make it easier for later command lines!
Get sources
To get the sources, refer to the original GitHub repository for the various branches.
$ git clone --depth=1 https://github.com/raspberrypi/linux
Build sources
To build the sources for cross-compilation, there may be extra dependencies beyond those you've installed by default with Ubuntu. If you find you need other things, please submit a pull request to change the documentation.
Enter the following commands to build the sources and Device Tree files:
For Pi 1 or Compute Module:
cd linuxKERNEL=kernelmake ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcmrpi_defconfig
For Pi 2/3:
cd linuxKERNEL=kernel7make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcm2709_defconfig
Then, for both:
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage modules dtbs
Note: To speed up compilation on multiprocessor systems, and get some improvement on single processor ones, use-j n
, where n is the number of processors * 1.5. Alternatively, feel free to experiment and see what works!
Install directly onto the SD card
Having built the kernel, you need to copy it onto your Raspberry Pi and install the modules; this is best done directly using an SD card reader.
First, use lsblk
before and after plugging in your SD card to identify it. You should end up with something like this:
sdb sdb1 sdb2
with sdb1
being the FAT (boot) partition, and sdb2
being the ext4 filesystem (root) partition.
If it's a NOOBS card, you should see something like this:
sdb sdb1 sdb2 sdb5 sdb6 sdb7
with sdb6
being the FAT (boot) partition, and sdb7
being the ext4 filesystem (root) partition.
Mount these first, adjusting the partition numbers for NOOBS cards:
mkdir mnt/fat32mkdir mnt/ext4sudo mount /dev/sdb1 mnt/fat32sudo mount /dev/sdb2 mnt/ext4
Next, install the modules:
sudo make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=mnt/ext4 modules_install
Finally, copy the kernel and Device Tree blobs onto the SD card, making sure to back up your old kernel:
sudo cp mnt/fat32/$KERNEL.img mnt/fat32/$KERNEL-backup.imgsudo scripts/mkknlimg arch/arm/boot/zImage mnt/fat32/$KERNEL.imgsudo 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/sudo umount mnt/fat32sudo umount mnt/ext4
Another option is to copy the kernel into the same place, but with a different filename - for instance, kernel-myconfig.img - rather than overwriting the kernel.img file. You can then edit the config.txt file to select the kernel that the Pi will boot into:
kernel=kernel-myconfig.img
This has the advantage of keeping your kernel separate from the kernel image managed by the system and any automatic update tools, and allowing you to easily revert to a stock kernel in the event that your kernel cannot boot.
Finally, plug the card into the Pi and boot it!
- 树梅派1/2/3 编译
- meshlab编译过程(3)-编译mpir-2.7.2
- 编译原理作业1,2
- 编译原理作业1、2
- 1005. 继续(3n+1)猜想 (25) Python 2 编译
- 1-1-2 交叉编译工具链
- CentOS6.2编译安装codelite5.3
- 编译 linux kernel & xenomai 2/3
- Opencv3.2 + mingw5.3+ win10编译
- CentOS7.3编译安装php7.1
- 1-3 Sass 语法、编译、调试
- 1-3 Sass 语法、编译、调试
- 1-3 Sass 语法、编译、调试
- vc++6.0编译环境介绍(1、2)
- R-3.1.1 编译安装2
- 编译Android2.2源码(1)
- 3.2.2 编译PC版本的 qtopia2.2.0;3.2.3 编译mini6410版本的 qtopia2.2.0;
- Gh0st编译免杀系列教程2_驱动文件编译方法1
- volga-ctf-quals-2016 pwn web_of_scicen_250 writeup
- IOS学习(九)UITabView使用及几种常见的创建方式
- HDOJ--1869|六度分离
- 数控车床指令初学
- Java 学习笔记 Day002
- 树梅派1/2/3 编译
- “ Hello World” Node.js Web Server
- UnityGUI系统之EventSystem
- ubuntu14.04安装OpenNI2+驱动XTion PRO Live
- QUTOJ-1359 小菜的难题(二分)
- rapidPHP 1.1.0 - 数据库配置
- rapidPHP 1.1.0 - 数据库表单跟实体配置
- 网页中添加QQ聊天代码
- HDU 2067 小兔的棋盘 (组合数学 卡特兰数)