Merge pull request #5751 from geekpi/master

translated
This commit is contained in:
geekpi 2017-06-30 09:01:14 +08:00 committed by GitHub
commit fd8c2763aa
2 changed files with 142 additions and 143 deletions

View File

@ -1,143 +0,0 @@
translating---geekpi
BUILD A 64-BIT KERNEL FOR YOUR RASPBERRY PI 3
============================================================
> EDIT : After writing this blog post Ive started a 64-bit OS for the Raspberry Pi 3, based on Debian. You can [find it here][3].
The **Raspberry Pi 3** ships with a Broadcom BCM2837 64bit ARMv8 quad core Cortex A53 processor, which is a **64-bit CPU**. If you own one of these, running the following command might surprise you :
> > uname -a
> Linux raspberrypi 4.4.34-v7+ #930 SMP Wed Nov 23 15:20:41 GMT 2016 armv7l GNU/Linux
Yes, this is a **32-bit kernel**. The reason for this is that the Raspberry Pi foundation doesnt yet provides a 64-bit version of Raspbian, the official OS for Raspberry Pi. It is however possible to build one, thanks to the various patches sent by [Electron752][9].
# Build the Kernel
The Raspberry Pi foundation maintains [their own fork ][10]of the Linux Kernel which is especially tailored for their devices, while upstream gets merged regularly.
Were going to adapt instructions from [that page][11] to **build a 64-bit Kernel**.
We cannot use the “Local building” method as itd require a 64-bit Raspberry Pi, which we obviously dont have yet. So we have to **cross-compile** it, **Ubuntu**is the recommended OS for this. I personally dont have Ubuntu so Ill make my build on a 2 CPUs Ubuntu 16.04 Digital Ocean droplet, which should cost me $0.03\. If you also want to proceed like this, you can get $10 free credits through [this link][12]. Alternatively, you could use a Ubuntu VM through Virtualbox for instance.
First, wed need a few **build tools** and the **aarch64 cross-compiler** :
> > apt-get update
> > apt-get install -y bc build-essential gcc-aarch64-linux-gnu git unzip
Then we can download the **Linux Kernel sources** :
> > git clone depth=1 -b rpi-4.8.y https://github.com/raspberrypi/linux.git
Enter now inside the created git directory. Optionally, you can add an extra version tag for your kernel. This is done by editing the beginning of the Makefile :
> VERSION = 4
> PATCHLEVEL = 8
> SUBLEVEL = 13
> EXTRAVERSION = +bilal
In order to **build it**, run the following commands :
> > make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- bcmrpi3_defconfig
> > make -j 3 ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-
The first one should be pretty fast. For the second one its a whole different story, I havent timed it exactly but it was around 30 minutes for me. Make sure to adapt the -j flag depending on your number of CPUs (nproc * 1.5).
# Choose a Linux distribution
While the Kernel is being built, we can start preparing a Linux distribution for it. Ill be using **Raspbian** for simplicity in this tutorial, even though this is a 32-bit only distribution.
_If you want to go 64-bit all the way you should pick up a distribution available in aarch64, Debian has a robust [ARM64Port][4]. To grab it there are basically 3 options :_
_ download a pre-built root filesystem, this would most likely give you an outdated one as mentioned in that page_
_ build your own with debootstrap if youre familiar with it (otherwise it can be tricky as it requires some manual tweaks, the original purpose of it is to chroot from an already running host, not build a root filesystem for another machine)._
_ the one Id recommend, using multistrap, there seems to be a nice tutorial on this page : http://free-electrons.com/blog/embdebian-with-multistrap/_
Back to Raspbian, we can now download the official OS and start preparing it.
Open a new shell session and run the following commands :
> > wget -O raspbian.zip https://downloads.raspberrypi.org/raspbian_lite_latest
> > unzip raspbian.zip
We can inspect it with the following command :
> > fdisk -l 2016-11-25-raspbian-jessie-lite.img
> Disk 2016-11-25-raspbian-jessie-lite.img: 1.3 GiB, 1390411776 bytes, 2715648 sectors
> Units: sectors of 1 * 512 = 512 bytes
> Sector size (logical/physical): 512 bytes / 512 bytes
> I/O size (minimum/optimal): 512 bytes / 512 bytes
> Disklabel type: dos
> Disk identifier: 0x244b8248
>
> Device Boot Start End Sectors Size Id Type
> 2016-11-25-raspbian-jessie-lite.img1 8192 137215 129024 63M c W95 FAT32 (LBA)
> 2016-11-25-raspbian-jessie-lite.img2 137216 2715647 2578432 1.2G 83 Linux
We can see it has **two partitions**. The first one is the **boot partition**, it mainly contains the bootloader, the Linux Kernel and a few config files. The second one is the** root partition**.
We can **mount those partitions** on our filesystem, starting with the **root partition** :
> > mount -o loop,offset=70254592 2016-11-25-raspbian-jessie-lite.img /mnt
The offset depends on the sector size, which is 512 : 70254592 = 512 * 137216
Then the **boot partition** :
> > mount -o loop,offset=4194304,sizelimit=66060288 2016-11-25-raspbian-jessie-lite.img /mnt/boot
_(offset : 4194304 = 512 * 8192, sizelimit: _ _66060288 = 512 * 129024)_
The Raspbian OS can now be seen under /mnt. Were almost there.
# Wrapping it up
Once the Kernel build is finished, the last steps involve **copying the Linux Kernel** and the **device tree** to the boot partition :
> > cp arch/arm64/boot/Image /mnt/boot/kernel8.img
> > cp arch/arm64/boot/dts/broadcom/bcm2710-rpi-3-b.dtb /mnt/boot/
Tweaking **config.txt** :
> > echo “kernel=kernel8.img” >> /mnt/boot/config.txt
Installing **Kernel modules** :
> > make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu INSTALL_MOD_PATH=/mnt modules_install
> > umount /mnt/boot
> > umount /mnt
And… thats it, a freshly baked **ARM64 Linux Kernel** for our Raspberry Pi 3!
You can now compress the image, download it through scp for instance and follow the standard instructions to put it on your SD card.
Eventually youll get :
> > uname -a
> Linux raspberrypi 4.8.13+bilal-v8+ #1 SMP Wed Dec 14 14:09:38 UTC 2016 aarch64 GNU/Linux
[Twitter][5][LinkedIn][6][Google+][7][Share][8]
--------------------------------------------------------------------------------
via: https://devsidestory.com/build-a-64-bit-kernel-for-your-raspberry-pi-3/
作者:[Bilal Amarni][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:http://devsidestory.com/about-me
[1]:https://devsidestory.com/author/bamarni/
[2]:https://devsidestory.com/build-a-64-bit-kernel-for-your-raspberry-pi-3/
[3]:https://github.com/bamarni/pi64
[4]:https://wiki.debian.org/Arm64Port
[5]:https://devsidestory.com/#twitter
[6]:https://devsidestory.com/#linkedin
[7]:https://devsidestory.com/#google_plus
[8]:https://www.addtoany.com/share#url=https%3A%2F%2Fdevsidestory.com%2Fbuild-a-64-bit-kernel-for-your-raspberry-pi-3%2F&title=Build%20a%2064-bit%20Kernel%20for%20your%20Raspberry%20Pi%203
[9]:https://github.com/Electron752
[10]:https://github.com/raspberrypi/linux
[11]:https://www.raspberrypi.org/documentation/linux/kernel/building.md
[12]:https://m.do.co/c/8ef9c5832a9c

View File

@ -0,0 +1,142 @@
为树莓派 3 构建 64 位内核
============================================================
> 编辑:在写完这个这篇文章之后,我开始在树莓派 3 上开始 64 位基于 Debian 的系统。你可以[在这里找到][3]
**树莓派 3** 配有 Broadcom BCM2837 64 位 ARMv8 四核 Cortex A53 处理器,它是一个 **64 位 CPU**。如果你有一块,运行以下命令可能会让你感到惊讶:
> > uname -a
> Linux raspberrypi 4.4.34-v7+ #930 SMP Wed Nov 23 15:20:41 GMT 2016 armv7l GNU/Linux
是的,这是一个 **32 位内核**。这是因为树莓派基金会还没有为官方的树莓派系统 Raspbian 提供 64 位版本。然而可以构建一个,多亏了 [Electron752][9] 提供的许多补丁。
# 构建内核
树莓派基金会维护了[它们自己的 Linux 内核分支][10],它为它们的设备特别裁剪过,同时会有规律地从上游合并。
我们将会从[这个页面][11]接受指导来**构建一个 64 位内核**。
我么不能使用“本地构建”的方法,因为它需要一块 64 位的树莓派,这个我们明显还没有。因此我们需要**交叉编译**它,**Ubuntu** 是推荐的系统。我个人没有 Ubuntu因此我在一个有 2 个 CPU 的 Ubuntu 16.04 Digital Ocean 实例上构建,这应该花费我 $0.03。如果你也想这么做,你可以通过[这个链接][12]得到 $10 的免费额度。或者你可以通过使用 Virtualbox 中的 Ubuntu VM 作为实例。
首先,我们需要一些**构建工具**以及** aarch64 交叉编译器**
> > apt-get update
> > apt-get install -y bc build-essential gcc-aarch64-linux-gnu git unzip
接着我们可以下载** Linux 内核源码**
> > git clone depth=1 -b rpi-4.8.y https://github.com/raspberrypi/linux.git
在创建的 git 目录中输入。另外你可以为你的内核添加额外的版本标签,可以通过编辑 Makefile 的开始几行达到:
> VERSION = 4
> PATCHLEVEL = 8
> SUBLEVEL = 13
> EXTRAVERSION = +bilal
为了**构建它**,运行下面的命令:
> > make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- bcmrpi3_defconfig
> > make -j 3 ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-
第一个应该很快。第二个则会完全不同,我没有精确计时,但是对我大概有半个小时。根据你的 CPU 数nproc * 1.5)调整 -j 标志。
# 选择一个 Linux 发行版
在内核编译的时候,我们可以开始准备它的 Linux 发行版了。在本教程中为了简单我使用 **Raspbian**,即使这是一个只有 32 位的发行版。
_如果你想要一直只用 64 为系统,你应该选一个有 aarch64 支持的发行版Debian 有一个鲁棒的 [ARM64 移植版][4]。得到它基本有三种选择_
_- 下载一个预构建的根文件系统这很可能会如页面中提到的那样给你一个过期的版本。_
_- 如果你熟悉 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 -l 2016-11-25-raspbian-jessie-lite.img
> Disk 2016-11-25-raspbian-jessie-lite.img: 1.3 GiB, 1390411776 bytes, 2715648 sectors
> Units: sectors of 1 * 512 = 512 bytes
> Sector size (logical/physical): 512 bytes / 512 bytes
> I/O size (minimum/optimal): 512 bytes / 512 bytes
> Disklabel type: dos
> Disk identifier: 0x244b8248
>
> Device Boot Start End Sectors Size Id Type
> 2016-11-25-raspbian-jessie-lite.img1 8192 137215 129024 63M c W95 FAT32 (LBA)
> 2016-11-25-raspbian-jessie-lite.img2 137216 2715647 2578432 1.2G 83 Linux
我们可以看到它有**两个分区**。第一个是**启动分区**,它主要包含了 bootloader、Linux 内核以及少量配置文件。第二个是**根分区**。
我们可以在我们的文件系统上**挂载这些分区**,从**根分区**开始:
> > mount -o loop,offset=70254592 2016-11-25-raspbian-jessie-lite.img /mnt
offset 取决于扇区大小,它的大小是 51270254592 = 512 * 137216
接着是**启动分区**
> > mount -o loop,offset=4194304,sizelimit=66060288 2016-11-25-raspbian-jessie-lite.img /mnt/boot
_(offset : 4194304 = 512 * 8192, sizelimit: _ _66060288 = 512 * 129024)_
树莓派系统现在应该可以在 /mnt 中看到了。我们基本我要完成了。
# 打包内核
内核编译完成后,最后一步包括**复制 Linux 内核**以及**设备树**到启动分区中:
> > cp arch/arm64/boot/Image /mnt/boot/kernel8.img
> > cp arch/arm64/boot/dts/broadcom/bcm2710-rpi-3-b.dtb /mnt/boot/
调整 **config.txt** :
> > echo “kernel=kernel8.img” >> /mnt/boot/config.txt
安装**内核模块** :
> > make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu INSTALL_MOD_PATH=/mnt modules_install
> > umount /mnt/boot
> > umount /mnt
就是这样了,用于树莓派 3 的** ARM64 Linux 内核**诞生了!
现在你可以压缩镜像,从实例中通过 scp 下载下来,并按照标准的步骤放到你的 SD 卡中。
最后你会得到:
> > uname -a
> Linux raspberrypi 4.8.13+bilal-v8+ #1 SMP Wed Dec 14 14:09:38 UTC 2016 aarch64 GNU/Linux
[Twitter][5][LinkedIn][6][Google+][7][Share][8]
--------------------------------------------------------------------------------
via: https://devsidestory.com/build-a-64-bit-kernel-for-your-raspberry-pi-3/
作者:[Bilal Amarni][a]
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:http://devsidestory.com/about-me
[1]:https://devsidestory.com/author/bamarni/
[2]:https://devsidestory.com/build-a-64-bit-kernel-for-your-raspberry-pi-3/
[3]:https://github.com/bamarni/pi64
[4]:https://wiki.debian.org/Arm64Port
[5]:https://devsidestory.com/#twitter
[6]:https://devsidestory.com/#linkedin
[7]:https://devsidestory.com/#google_plus
[8]:https://www.addtoany.com/share#url=https%3A%2F%2Fdevsidestory.com%2Fbuild-a-64-bit-kernel-for-your-raspberry-pi-3%2F&title=Build%20a%2064-bit%20Kernel%20for%20your%20Raspberry%20Pi%203
[9]:https://github.com/Electron752
[10]:https://github.com/raspberrypi/linux
[11]:https://www.raspberrypi.org/documentation/linux/kernel/building.md
[12]:https://m.do.co/c/8ef9c5832a9c