从源码编译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
时间: 2024-10-01 03:52:36

从源码编译rpi的内核的相关文章

Centos 7 源码编译安装内核4.14.12

为什么要编译内核 需要新功能的支持: 在生产环境中,突然会需要使用一些新的功能,但是原有的内核并不支持此功能,这是就需要重新编译出一个新的内核来提供对此新功能的支持,比如虚拟化.iptables功能必须要在2.4.X以上版本的内核中才支持. 原核心太过于臃肿: 原来安装的内核中,有很多不常用甚至基本上用不到的功能支持,而这些功能又会使内核文件变得很大,这时要将此变成一个简化切功能够用的内核就需要进行重新编译. 与硬件搭配的稳定性: 很多情况下,系统内核中默认一般默认支持的CPU类型为Inter,

源码编译绕过反调试

参考师弟的贴子修改的, 基本我一次就弄好了, 没有遇到啥问题, 下面我主要是补充下他的帖子 http://bbs.pediy.com/showthread.php?t=213481 一. 环境搭建 (1). 环境介绍: 手机:nexus 5 ubuntu版本:15.10 android版本:4.4.4 android源码官网(这里有很多相关的资料,基本上按照官网的来就可以编译想编译的任何版本了) http://source.android.com/source/ (2). 环境配置 配置环境得好

获取Android源码跟官方Linux内核源码

最近在探索安卓源码跟ROM,有幸买了本书跟在网上看到一些交教程,先做一些笔记,以备不时之需... 1.了解git和repo 2.环境配置 首先最先的肯定是JDK和SDK的安装,网上教程很多,也可以参考Google官方提供的: https://source.android.com/source/initializing.html (a)安装git 和curl: apt-get install git-core curl (b)安装repo: 创建存放repo目录 # mkdir ~/bin  # 

学习日志---linuxの 源码编译使用及实例运行

程序包管理之编译安装: 源码:c, c++ perl源码: python源码: 应用程序:项目组 软件基金会:FSF,ASF 项目组:主导者,contributor 小项目:一个人维护 商业公司支持:开源版/企业版 SourceForge.net github.com code.google.com 源程序: 项目工程:把代码分散于多个源代码文件 GNU/make autoconf: configure脚本 检查编译环境是否编译需求,并定义当前程序编译时启用哪个特性或功能,以及安装路径的定义等等

Android源码编译

Android源码编译学习小结 内容 系统源码编译 笔者之前在学习安卓系统源码的编译,为了能够印象深刻,粗略的总结了以下内容,希望对我一样的初学者有一些帮助. 系统编译的初始化指令 对android编译环境进行初始化很简单,分为两步.第一步打开终端输入source build/envseup.sh加载所需的文件. $ source build/envseup.sh including device/asusource build/envseup.shs/grouper/vendorsetup.s

源码编译安装Heartbeat

一.Heartbeat介绍 官方站点:http://linux-ha.org/wiki/Main_Pageheartbeat可以资源(VIP地址及程序服务)从一台有故障的服务器快速的转移到另一台正常的服务器提供服务,heartbeat和keepalived相似,heartbeat可以实现failover功能,但不能实现对后端的健康检查. 二.简要规划 系统环境 系统 OEL6.6 系统位数 x86_64 内核版本 3.8.13-44.1.1.el6uek.x86_64 软件环境 Heartbea

cubie A20 android源码编译 小记

cubie 这个开发板已经购买额一年多,一直没有时间玩,最近感觉自己没啥进展,想多学点东西,翻箱倒柜终于找出来.费话不多说 1.源码下载路径方法 两种下载方法,我是直接到cubie百度网盘上下载的,网盘上分享代码和参考资料还是很全的. 1) 在 github 下载 git clone https://bitbucket.org/cubietech/a20-android4.2_lichee.git git clone https://bitbucket.org/cubietech/a20-and

Android介绍以及源码编译(一)

一. Android概况 1.1     简介 Android是一种基于Linux的自由及开放源代码的操作系统.主要用于移动设备,如智能手机.平板电脑.TV.穿戴设备,由Google公司和开放手机联盟领导及开发. Android操作系统最初由Andy Rubin开发,主要支持手机.2005年8月由Google收购注资Google以Apache开源许可证的授权方式,发布了Android的源代码. 第一部Android智能手机发布于2008年10月. 1.2     Android版本 Google

基于 cm-11 源码编译模拟器

以前对于cm的源码编译都是基于固定机型的,有的时候需要使用模拟器,这边就记录一下使用cm的源码来如何编译android 模拟器,不过在做这件事情前你最好评估一下自己的机器配置.这里给出的推荐的配置是,i5以上的cpu,硬盘要固态硬盘,否则模拟器的启动和加载的速度几乎不可以忍受. android源码编译完成以后生成的目录都是在源码目录下的out文件夹下 out/target 表示生成的是目标机器一般是手机上的各种程序,比如rom等 out/host   表示生成的是对于宿主机器上的各种工具,比如a