bcm2837linux编程_为树莓派 3 构建 64 位内核

225856ciizhnzt6l42hhok.jpg

树莓派 3 配有 Broadcom BCM2837 64 位 ARMv8 四核 Cortex A53 处理器,它是一个 64 位 CPU。如果你有一块,运行以下命令可能会让你感到惊讶:

uname-a

Linuxraspberrypi4.4.34-v7+#930SMPWedNov2315:20:41GMT2016armv7l GNU/Linux

是的,这是一个 32 位内核。这是因为树莓派基金会还没有为官方的树莓派系统 Raspbian 提供 64 位版本。然而你可以构建一个,多亏了 Electron752 提供的许多补丁。

构建内核

树莓派基金会维护着它们自己的 Linux 内核分支,它为它们的设备特别裁剪过,同时定期地从上游合并。

我们将会遵照这个页面的指导来构建一个 64 位内核。

我们不能使用“本地构建”的方法,因为它需要一块 64 位的树莓派,这个我们明显还没有。因此我们需要交叉编译它,Ubuntu 是推荐的系统。我个人没有 Ubuntu,因此我在一个有 2 个 CPU 的 Ubuntu 16.04 Digital Ocean 实例上构建,这应该花费我 $0.03。如果你也想这么做,你可以通过这个链接得到 $10 的免费额度。或者你可以通过使用 Virtualbox 中的 Ubuntu VM 作为实例。

首先,我们需要一些构建工具以及** aarch64 交叉编译器**:

apt-getupdate

apt-getinstall-y bc build-essentialgcc-aarch64-linux-gnugitunzip

接着我们可以下载 Linux 内核源码:

gitclone–depth=1-b rpi-4.8.y https://github.com/raspberrypi/linux.git

进入到创建的 git 目录。另外你可以为你的内核添加额外的版本标签,可以通过编辑 Makefile 的开始几行完成:

VERSION=4

PATCHLEVEL=8

SUBLEVEL=13

EXTRAVERSION=+bilal

为了构建它,运行下面的命令:

makeARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-bcmrpi3_defconfig

make-j3ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-

第一个应该很快。第二个则会完全不同,我没有精确计时,但是对我来说大概要半个小时。根据你的 CPU 数(nproc * 1.5)调整 -j 标志。

选择一个 Linux 发行版

在内核编译的时候,我们可以开始准备它的 Linux 发行版了。在本教程中为了简单我使用 Raspbian,即使这是一个只有 32 位的发行版。

如果你想要一直用 64 位系统,你应该选一个有 aarch64 支持的发行版,Debian 有一个健壮的 ARM64 移植版。得到它基本有三种方式:

下载一个预构建的根文件系统,这很可能会如页面中提到的那样给你一个过期的版本。

如果你熟悉 debootstrap,用它构建你自己的(这回比较棘手,因为它需要一些手工调整,它最初的目的是在已经运行的主机上进行 chroot,而不是为其他机器构建根文件系统)

我建议使用 multistrap,这里有一个很好的教程:http://free-electrons.com/blog/embdebian-with-multistrap/

回到 Raspbian,我们现在可以下载官方系统,并开始准备了。

打开一个新的 shell 会话并运行下面的命令:

wget-O raspbian.zip https://downloads.raspberrypi.org/raspbian_lite_latest

unzip raspbian.zip

我们用下面的命令审查:

fdisk-l2016-11-25-raspbian-jessie-lite.img

Disk2016-11-25-raspbian-jessie-lite.img:1.3GiB,1390411776bytes,2715648sectors

Units:sectors of1*512=512bytes

Sectorsize(logical/physical):512bytes/512bytes

I/Osize(minimum/optimal):512bytes/512bytes

Disklabeltype:dos

Diskidentifier:0x244b8248

DeviceBootStartEndSectorsSizeIdType

2016-11-25-raspbian-jessie-lite.img1819213721512902463Mc W95 FAT32(LBA)

2016-11-25-raspbian-jessie-lite.img2137216271564725784321.2G83Linux

我们可以看到它有两个分区。第一个是启动分区,它主要包含了 bootloader、Linux 内核以及少量配置文件。第二个是根分区。

我们可以在我们的文件系统上挂载这些分区,从根分区开始:

mount-o loop,offset=702545922016-11-25-raspbian-jessie-lite.img/mnt

offset 取决于扇区大小(512):70254592 = 512 * 137216

接着是启动分区:

mount-o loop,offset=4194304,sizelimit=660602882016-11-25-raspbian-jessie-lite.img/mnt/boot

offset :4194304 = 512 * 8192,sizelimit:66060288 = 512 * 129024 。

树莓派系统现在应该可以在 /mnt 中看到了。我们基本要完成了。

打包内核

内核编译完成后,最后一步包括复制 Linux 内核以及设备树到启动分区中:

cparch/arm64/boot/Image/mnt/boot/kernel8.img

cparch/arm64/boot/dts/broadcom/bcm2710-rpi-3-b.dtb/mnt/boot/

调整 config.txt :

echo“kernel=kernel8.img”>>/mnt/boot/config.txt

安装内核模块 :

makeARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu INSTALL_MOD_PATH=/mnt modules_install

umount/mnt/boot

umount/mnt

就是这样了,用于树莓派 3 的** ARM64 Linux 内核**诞生了!

现在你可以压缩镜像,通过 scp 下载下来,并按照标准的步骤放到你的 SD 卡中。

最后你会得到:

uname-a

Linuxraspberrypi4.8.13+bilal-v8+#1SMPWedDec1414:09:38UTC2016aarch64 GNU/Linux

Table of Contents 1 Introduction 4 1.1 Overview 4 1.2 Address map 4 1.2.1 Diagrammatic overview 4 1.2.2 ARM virtual addresses (standard Linux kernel only) 6 1.2.3 ARM physical addresses 6 1.2.4 Bus addresses 6 1.3 Peripheral access precautions for correct memory ordering 7 2 Auxiliaries: UART1 & SPI1, SPI2 8 2.1 Overview 8 2.1.1 AUX registers 9 2.2 Mini UART 10 2.2.1 Mini UART implementation details. 11 2.2.2 Mini UART register details. 11 2.3 Universal SPI Master (2x) 20 2.3.1 SPI implementation details 20 2.3.2 Interrupts 21 2.3.3 Long bit streams 21 2.3.4 SPI register details. 22 3 BSC 28 3.1 Introduction 28 3.2 Register View 28 3.3 10 Bit Addressing 36 4 DMA Controller 38 4.1 Overview 38 4.2 DMA Controller Registers 39 4.2.1 DMA Channel Register Address Map 40 4.3 AXI Bursts 63 4.4 Error Handling 63 4.5 DMA LITE Engines 63 5 External Mass Media Controller 65 o Introduction 65 o Registers 66 6 General Purpose I/O (GPIO) 89 6.1 Register View 90 6.2 Alternative Function Assignments 102 6.3 General Purpose GPIO Clocks 105 7 Interrupts 109 7.1 Introduction 109 7.2 Interrupt pending. 110 7.3 Fast Interrupt (FIQ). 110 7.4 Interrupt priority. 110 7.5 Registers 112 8 PCM / I2S Audio 119 8.1 Block Diagram 120 8.2 Typical Timing 120 8.3 Operation 121 8.4 Software Operation 122 8.4.1 Operating in Polled mode 122 8.4.2 Operating in Interrupt mode 123 8.4.3 DMA 123 8.5 Error Handling. 123 8.6 PDM Input Mode Operation 124 8.7 GRAY Code Input Mode Operation 124 8.8 PCM Register Map 125 9 Pulse Width Modulator 138 9.1 Overview 138 9.2 Block Diagram 138 9.3 PWM Implementation 139 9.4 Modes of Operation 139 9.5 Quick Reference 140 9.6 Control and Status Registers 141 10 SPI 148 10.1 Introduction 148 10.2 SPI Master Mode 148 10.2.1 Standard mode 148 10.2.2 Bidirectional mode 149 10.3 LoSSI mode 150 10.3.1 Command write 150 10.3.2 Parameter write 150 10.3.3 Byte read commands 151 10.3.4 24bit read command 151 10.3.5 32bit read command 151 10.4 Block Diagram 152 10.5 SPI Register Map 152 10.6 Software Operation 158 10.6.1 Polled 158 10.6.2 Interrupt 158 10.6.3 DMA 158 10.6.4 Notes 159 11 SPI/BSC SLAVE 160 11.1 Introduction 160 11.2 Registers 160 12 System Timer 172 12.1 System Timer Registers 172 13 UART 175 13.1 Variations from the 16C650 UART 175 13.2 Primary UART Inputs and Outputs 176 13.3 UART Interrupts 176 13.4 Register View 177 14 Timer (ARM side) 196 14.1 Introduction 196 14.2 Timer Registers: 196 15 USB 200 15.1 Configuration 200 15.2 Extra / Adapted registers. 202
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值