从源码编译rpi的内核
Kernel Building
https://www.raspberrypi.org/documentation/linux/kernel/building.md
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 from the downloads page. 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 linux
$ KERNEL=kernel
$ make bcmrpi_defconfig
Raspberry Pi 2 Default Build Configuration
$ cd linux
$ KERNEL=kernel7
$ make bcm2709_defconfig
Build and install the kernel, modules and Device Tree blobs; this step takes a lot of time...
$ make zImage modules dtbs
$ sudo make modules_install
$ sudo 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
Cross-compiling
First you are going to require a suitable Linux cross-compilation host. We tend to use Ubuntu; since Raspbian is also a Debian distribution it means using similar command lines and so on.
You can either do this using VirtualBox (or VMWare) on Windows, or install it directly onto your computer. For reference you can follow instructions online at Wikihow.
Install toolchain
Use the following command:
$ git clone https://github.com/raspberrypi/tools
You can then copy the toolchain to a common location such as /tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian, and add /tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin to your $PATH in the .bashrc in your home directory. For 64bit, use /tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin. While this step is not 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 linux
$ KERNEL=kernel
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcmrpi_defconfig
For Pi 2:
$ cd linux
$ KERNEL=kernel7
$ make 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 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 which one it is; you should end up with something like this:
sdb
sdb1
sdb2
If it is a NOOBS card you should see something like this:
sdb
sdb1
sdb2
sdb3
sdb5
sdb6
In the first case sdb1/sdb5 is the FAT partition, and sdb2/sdb6 is the ext4 filesystem image (NOOBS).
Mount these first:
$ mkdir mnt/fat32
$ mkdir mnt/ext4
$ sudo mount /dev/sdb1 mnt/fat32
$ sudo mount /dev/sdb2 mnt/ext4
Adjust the partition numbers for the NOOBS images.
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.img
$ sudo scripts/mkknlimg arch/arm/boot/zImage mnt/fat32/$KERNEL.img
$ sudo 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/fat32
$ sudo 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!
Links
Building / cross-compiling on/for other operating systems
- Pidora
- ArchLinux
- RaspBMC
- OpenELEC
从源码编译rpi的内核的更多相关文章
- centos源码编译安装新版本内核
在工作中,很多时候由于需要使用新的技术方案,需要较新版本的内核来支持新的功能,而centos系统自带的内核版本普遍都比较旧,因此我们需要对系统的内核进行升级,安装新版的内核.本文以centos7系 ...
- Ubuntu 14.04 LTS 下 android 2.3.5 源码编译过程
Ubuntu 14.04 LTS 下 android 2.3.5 源码编译过程 在新的Ubuntu 64位系统下去编译早期的安卓源码是会出现很多问题的,因为64位系统在安装完成后,很多32位的兼容 ...
- wso2esb源码编译总结
最近花了两周的空闲时间帮朋友把wso2esb的4.0.3.4.6.0.4.7.0三个版本从源码编译出来了.以下是大概的一些体会. wso2esb是基于carbon的.carbon是个基于eclipse ...
- Android源码浅析(四)——我在Android开发中常用到的adb命令,Linux命令,源码编译命令
Android源码浅析(四)--我在Android开发中常用到的adb命令,Linux命令,源码编译命令 我自己平时开发的时候积累的一些命令,希望对你有所帮助 adb是什么?: adb的全称为Andr ...
- ifconfig源码分析之与内核交互数据
<ifconfig源码分析之与内核交互数据>本文档的Copyleft归rosetta所有,使用GPL发布,可以自由拷贝.转载,转载时请保持文档的完整性.参考资料:<Linux设备驱动 ...
- LNMP源码编译
LNMP源码编译 编译安装之前把开发包组安装了 [root@tiandong63 ~]# yum groupinstall "Development Tools" "De ...
- ubuntu上源码编译安装mysql5.7.27
一.查看操作系统环境和目录结构,并创建mysql用户和组,以及规划安装mysql所需要的目录. #cat /etc/issue 查看发行版本信息: #cat /proc/version 查看正在运行 ...
- 源码编译搭建LNMP环境
LNMP源码编译 1.LNMP介绍 LNMP=Linux Nginx Mysql PHP Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器.Ng ...
- 源码编译安装MySQL8.0.20
1 概述 本文章主要讲述了如何从源码编译安装MySQL社区版8.0.20,首先会介绍一些编译安装的相关知识,然后开始编译安装 2 源码编译安装的相关知识 2.1 make与configure make ...
随机推荐
- 使用WebBrowser的记录
第一:新建一个类,用了获取WebBrowser元素的类 //需要引用 Interop.SHDocVw 和 Microsoft.mshtmlpublic class Element { //根据Name ...
- CSS 响应式设计
响应式设计是指在不同分辨率的设备中,网页布局可以自适应的调整.这种弹性化的布局使网站在不同设备中的布局都比较合理,可以为不同终端的用户提供更加舒适的界面和更好的用户体验,其根本理念是使原本 PC 上的 ...
- poj 3185 The Water Bowls
The Water Bowls 题意:给定20个01串(最终的状态),每个点变化时会影响左右点,问最终是20个0所需最少操作数? 水题..直接修改增广矩阵即可:看来最优解不是用高斯消元(若是有Gaus ...
- 代码块(block)简介
代码块是对C语言中函数的扩展,由C语言实现,所以在以C为基础的语言内都是有效的,包括Objective_C,C++和Objective-C++,在Xcode的GCG与Clang工具中是有效的,但这不属 ...
- STM32系统时钟
一.时钟树 STM32有4个时钟源: 1)HSE(高速外部时钟源) 外部晶振作为时钟源,范围为4~16MHz,常取为8MHz 2)HSI(高速内部时钟源) 由内部RC振荡器产生,频率为8MHz,但不稳 ...
- hibernate配置文件详细解释
<!--标准的XML文件的起始行,version='1.0'表明XML的版本,encoding='gb2312'表明XML文件的编码方式--> <?xml version='1.0' ...
- JVM 找出最耗 cpu的线程 并打印线程栈
监控JVM中最占cpu的线程 top -Hp pid JVM中最占cpu的线程ID -o THREAD,tid,time | awk 'BEGIN {count=0; } { if($2>0.3 ...
- 在ios开发中有多少常用的加密解密方式(备用)
最常用的是MD5和base64编码,还有DES 3DES AES加密 ios怎么实现RAS加密解密 最近几天折腾了一下如何在iOS上使用RSA来加密.iOS上并没有直接的RSA加密API.但是iOS提 ...
- 移动web HTML5使用photoswipe模仿微信朋友圈图片放大浏览
先来几张效果图: 点击其中一张照片可放大,可支持图片文字描述: 同时支持分享功能: 支持手势放大缩小 使用js框架是PhotoSwipe. PhotoSwipe是一个图片放大插件,兼容pc和移动端,经 ...
- ECmall错误:Call to a member function get_users_count() on a non-object
问题描述: 在后台添加了一个app报错:Call to a member function get_users_count()Fatal error: Call to a member functio ...