如何在 Debian 上为 armv8 cortex-a53 安装 aarch64 工具链?

How to install the aarch64 toolchain for armv8 cortex-a53 on Debian?

我想在 ARM 芯片上开始低级编程。我已经安装了 qemu 并遵循了一些 hello world 类型的示例程序,但现在我想以最新的 Raspberry Pi 为目标,它具有 ARMv8 cortex-a53neon-fp-armv8 FPU。我目前 运行 Debian:

$ lsb_release -a
    No LSB modules are available.
    Distributor ID: BunsenLabs
    Description:    BunsenLabs GNU/Linux 8.5 (Hydrogen)
    Release:    8.5
    Codename:   bunsen-hydrogen

$ cat /etc/debian_version
    8.5

我目前安装了以下工具链:

binutils-arm-none-eabi
gcc-arm-none-eabi
gdb-arm-none-eabi

但是,当我尝试使用 -mcpu=cortex-a53 进行编译时,我收到以下错误:

arm-none-eabi-gcc: error: unrecognized argument in option '-mcpu=cortex-a53'

$ arm-none-eabi-gcc --version
    arm-none-eabi-gcc (4.8.4-1+11-1) 4.8.4 20141219 (release)

我假设我有一个不包含该目标的旧 GCC CPU,所以我尝试下载 binutils、gcc 和 gdb 的源代码,但我无法构建 binutils。尝试 make all 时总是失败。

binutils 配置:

$../../src/binutils-2.26.51/configure \
 --target=arm-none-eabi \
 --disable-nls

构建错误:

$make -j4
    checking for bison... /home/nathan/development/tools/arm/src/binutils-2.26.51/missing bison -y
    checking for flex... /home/nathan/development/tools/arm/src/binutils-2.26.51/missing flex
    checking lex output file root... configure: error: cannot find output from /home/nathan/development/tools/arm/src/binutils-2.26.51/missing flex; giving up
    Makefile:3545: recipe for target 'configure-binutils' failed
    make[1]: *** [configure-binutils] Error 1
    no
    checking for bison... /home/nathan/development/tools/arm/src/binutils-2.26.51/missing bison -y
    checking for flex... /home/nathan/development/tools/arm/src/binutils-2.26.51/missing flex
    checking lex output file root... configure: error: cannot find output from /home/nathan/development/tools/arm/src/binutils-2.26.51/missing flex; giving up
    Makefile:4834: recipe for target 'configure-gas' failed
    make[1]: *** [configure-gas] Error 1
    make[1]: Leaving directory '/home/nathan/development/tools/arm/build/binutils-2.26.51'
    Makefile:844: recipe for target 'all' failed
    make: *** [all] Error 2

我需要采取哪些正确的步骤来设置工具链以针对 aarch64 cortex-a53 架构进行编译?

编辑 1

通过评论发现,我需要安装aarch64工具链,而不是arm工具链。还是一头雾水

从 Ubuntu 18.04 开始,您可以:

sudo apt-get install gcc-aarch64-linux-gnu
aarch64-linux-gnu-gcc -mcpu=cortex-a53 hello_world.c

软件包 gcc-aarch64-linux-gnu 的版本为 4:7.3.0-3ubuntu2

但是,对于 Raspberry Pi,您应该只从 https://github.com/raspberrypi/tools which is the more reliable way to do it as explained at: https://raspberrypi.stackexchange.com/questions/64273/installing-raspberry-pi-cross-compiler/83215#83215

下载官方二进制文件

最后,对于裸机,我找不到 arm-none-eabi-gcc 的类似物,我想知道为什么:https://github.com/cirosantilli/cirosantilli.github.io/issues/68

您可以从这个 Github Project:

试用我最新的 Raspberry Pi 预构建开源 GCC 工具链

本项目摘要:本项目包含 Precompiled/Pre-Built Raspberry pi GCC Cross & Native Compilers Binaries 的 UpToDate 集,节省您大量时间(否需要任何编译或错误处理)。只需提取,Link 并在您的机器中享受完整的 GCC(Raspberry Pi) 功能。您可以将其本地编译器用于 Raspberry Pi(可以与旧的和慢速的 6.3.0 GCC 一起使用),或者在任何 Linux 机器上使用交叉编译器(在最新 Ubuntu/bionic 上测试x64) 为您的 Raspberry Pi 编译程序。所有这些编译器二进制文件都经过 Raspberry Pi 硬件优化以提高整体性能。

支持的 GCC 版本为:

  • 海湾合作委员会 6.3.0
  • 海湾合作委员会 7.4.0
  • 海湾合作委员会 8.2.0
  • 海湾合作委员会 8.3.0

支持的环境:

  • 交叉编译器: 当前支持所有 Linux 发行版 (x32/x64)。
  • Native-Compiler: 支持所有 Raspberry Pi version/model 和 Raspbian OS。其他 OS may/may-not 工作。

希望对您有所帮助! :)