红联Linux门户
Linux帮助

尝试向树莓派3B引入Drbian 9 arm64-PART 1

发布时间:2017-06-19 11:35:40来源:linux网站作者:UMRInside
Stage 1:试图加入arm64软件包
笔者默认您清楚这些指令背后的意义以及其可能造成的后果,并默认您已备份重要资料
sudo dpkg --add-archietcture arm64
sudo apt update
尝试在树莓派上执行上述两条指令,结果如下(笔者的Raspbian已升级至Stretch):
Get:1 https://mirrors.ustc.edu.cn/raspbian/raspbian stretch InRelease [15.0 kB]
Get:2 https://mirrors.ustc.edu.cn/archive.raspberrypi.org jessie InRelease [22.9 kB]
Get:3 https://mirrors.ustc.edu.cn/raspbian/raspbian stretch/main armhf Packages [11.7 MB]
Get:4 https://mirrors.ustc.edu.cn/archive.raspberrypi.org jessie/main armhf Packages [163 kB] 
Fetched 11.9 MB in 1min 7s (177 kB/s) 
Reading package lists... Done
Building dependency tree 
Reading state information... Done
30 packages can be upgraded. Run 'apt list --upgradable' to see them.
N: Skipping acquire of configured file 'main/binary-arm64/Packages' as repository 'https://mirrors.ustc.edu.cn/raspbian/raspbian stretch InRelease' doesn't support architecture 'arm64'
N: Skipping acquire of configured file 'rpi/binary-arm64/Packages' as repository 'https://mirrors.ustc.edu.cn/raspbian/raspbian stretch InRelease' doesn't support architecture 'arm64'
N: Skipping acquire of configured file 'main/binary-arm64/Packages' as repository 'https://mirrors.ustc.edu.cn/archive.raspberrypi.org jessie InRelease' doesn't support architecture 'arm64'
N: Skipping acquire of configured file 'non-free/binary-arm64/Packages' as repository 'https://mirrors.ustc.edu.cn/archive.raspberrypi.org jessie InRelease' doesn't support architecture 'arm64'
N: Skipping acquire of configured file 'contrib/binary-arm64/Packages' as repository 'https://mirrors.ustc.edu.cn/archive.raspberrypi.org jessie InRelease' doesn't support architecture 'arm64'
N: Skipping acquire of configured file 'ui/binary-arm64/Packages' as repository 'https://mirrors.ustc.edu.cn/archive.raspberrypi.org jessie InRelease' doesn't support architecture 'arm64'
易得:Raspbian里并没有arm64的软件包——至少没有索引文件。
笔者遂修改sources.list:
deb https://mirrors.ustc.edu.cn/raspbian/raspbian/ stretch main rpi
deb https://mirrors.ustc.edu.cn/debian/debian/ stretch main
并执行:
wget https://mirrors.ustc.edu.cn/debian/pool/main/d/debian-archive-keyring/debian-archive-keyring_2017.5_all.deb
sudo dpkg -i debian-archive-keyring_2017.5_all.deb
sudo apt update
得:
Hit:1 https://mirrors.ustc.edu.cn/raspbian/raspbian stretch InRelease
Hit:3 https://mirrors.ustc.edu.cn/archive.raspberrypi.org jessie InRelease
Get:4 https://mirrors.ustc.edu.cn/debian stretch/main arm64 Packages [6,936 kB]
Get:5 https://mirrors.ustc.edu.cn/debian stretch/main armhf Packages [6,925 kB]
Get:6 https://mirrors.ustc.edu.cn/debian stretch/main Translation-en [5,395 kB]
Fetched 19.3 MB in 1min 30s (212 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
244 packages can be upgraded. Run 'apt list --upgradable' to see them.
N: Skipping acquire of configured file 'main/binary-arm64/Packages' as repository 'https://mirrors.ustc.edu.cn/raspbian/raspbian stretch InRelease' doesn't support architecture 'arm64'
N: Skipping acquire of configured file 'rpi/binary-arm64/Packages' as repository 'https://mirrors.ustc.edu.cn/raspbian/raspbian stretch InRelease' doesn't support architecture 'arm64'
N: Skipping acquire of configured file 'main/binary-arm64/Packages' as repository 'https://mirrors.ustc.edu.cn/archive.raspberrypi.org jessie InRelease' doesn't support architecture 'arm64'
N: Skipping acquire of configured file 'non-free/binary-arm64/Packages' as repository 'https://mirrors.ustc.edu.cn/archive.raspberrypi.org jessie InRelease' doesn't support architecture 'arm64'
N: Skipping acquire of configured file 'contrib/binary-arm64/Packages' as repository 'https://mirrors.ustc.edu.cn/archive.raspberrypi.org jessie InRelease' doesn't support architecture 'arm64'
N: Skipping acquire of configured file 'ui/binary-arm64/Packages' as repository 'https://mirrors.ustc.edu.cn/archive.raspberrypi.org jessie InRelease' doesn't support architecture 'arm64'
似乎是成功了。
然而,尝试选择安装一个arm64软件包,都会遇到不可描述的依赖问题:
pi@raspberry:~ $ sudo apt install libc6:arm64 libgcc1:arm64
Reading package lists... Done
Building dependency tree        
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
bluez : Depends: libc6 (>= 2.15) but it is not going to be installed
Depends: libdbus-1-3 (>= 1.1.1) but it is not going to be installed
Depends: libglib2.0-0 (>= 2.28.0) but it is not going to be installed
Depends: libreadline6 (>= 6.0) but it is not going to be installed
Depends: libudev1 (>= 196) but it is not going to be installed
Depends: init-system-helpers (>= 1.18~) but it is not going to be installed
Depends: kmod
Depends: udev (>= 170-1)
Depends: dbus
libgcc1:arm64 : Depends: gcc-6-base:arm64 (= 6.3.0-18) but it is not going to be installed
E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.
 
Stage 2:尝试在32位环境中执行64位程序
首先,口胡编写一个C程序,存为test64.c:
#include <time.h>
#include <stdio.h>
long long fastpow_m(long long base,long long power,long long k)
{
long long result = 1;
while (power!=0)
{
if (power%2 == 1)result = (result*base)%k;
base = (base*base)%k;
power /= 2;
}
return result;
}
int main()
{
long long b,p,faq;
long t1,t2;
scanf("%lld %lld %lld",&b,&p,&faq);
printf("%lld %lld\n",b,p,faq);
t1 = clock();
printf("result :%lld\n",fastpow_m(b,p,faq));
t2 = clock();
printf("fastpow_m(): %f s.\n",((double)(t2-t1)/(double)CLOCKS_PER_SEC));
t1 = clock();
long long r = 1;
for (int i=1;i<=p;i++)r*=b,r = r%faq;
printf("result :%lld\n",r);
t2 = clock();
printf("normal: %f s.\n",((double)(t2-t1)/(double)CLOCKS_PER_SEC));
return 0;
}
(参加过NOI/NOIP/ACM之类竞赛的人一眼就能看出:这是一个模意义下的二分快速幂计算程序:))
安装交叉编译工具链并编译:
sudo apt install gcc-aarch64-linux-gnu 
aarch64-linux-gnu-gcc fastpow.c -static -o /tmp/test64
file /tmp/test64
/tmp/test64
得:
/tmp/test64: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), statically linked, for GNU/Linux 3.7.0, BuildID[sha1]=a8009a666be247cfdf0b6d7827a8099dee36f1ba, not stripped
-bash: /tmp/test64: cannot execute binary file: Exec format error
看样子还是不行,我的程序白口胡写了。
 
Stage 3:编译64位内核:
偶然间发现一篇旧的文章:
尝试向树莓派3B引入Drbian 9 arm64-PART 1
阐述了自行编译内核的方法,笔者遂依葫芦画瓢编译内核。
至于编译内核用的工具链?这个自行解决。
git clone https://github.com/raspberrypi/linux
cd linux
#带##的是注释掉的原文指令
## make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcm2709_defconfig
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu bcmrpi3_defconfig
## make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -j 4
然后是就是漫长的等待(git clone 会产生1.54GiB的流量,消耗2G以上的磁盘空间;至于编译过程我想大家都懂得。)
工具链来源(可选):
sudo apt install gcc-aarch64-linux-gnu
接下来:
#设SD卡根分区位于/mnt/ext4,boot分区位于/mnt/boot
cp arch/arm/boot/Image mnt/fat32/kernel8.img
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- INSTALL_MOD_PATH=/mnt/ext4 modules
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- INSTALL_MOD_PATH=/mnt/ext4 modules_install
mv /mnt/boot/bcm2710-rpi-3-b.dtb bcm2710-rpi-3-b.dtb_32
cp arch/arm64/boot/dts/broadcom/bcm2710-rpi-3-b.dtb /mnt/boot
试着启动树莓派,一次成功,板载无线网卡以AP模式正常工作。
此时系统大部分组件仍为32位版本,RPi.GPIO无法正常使用,且无法使用硬浮点指令集(使用aarch64-linux-gnu-)。
 
本文永久更新地址:http://www.linuxdiyf.com/linux/31586.html