安装交叉编译器 arm-linux-gnueabihf-gcc


前言

在学习正点原子《ZYNQ-嵌入式Linux开发指南》第十四章 U-boot移植的时候,下载了Xlinux u-boot源码后编译,出现了错误:

root@ubuntu-GCP1820-SS:u-boot-xlnx-xilinx-v2019.2$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zynq_zc702_defconfig  
#
# configuration written to .config
#
root@ubuntu-GCP1820-SS:u-boot-xlnx-xilinx-v2019.2$ make V=1 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j8 # 执行make命令进行编译
make: arm-linux-gnueabihf-gcc: Command not found
/bin/sh: 1: arm-linux-gnueabihf-gcc: not found
dirname: missing operand
Try 'dirname --help' for more information.
make[1]: *** [u-boot.cfg] Error 1
  arm-linux-gnueabihf-gcc -E -Wall -Wstrict-prototypes -Wno-format-security -fno-builtin -ffreestanding -std=gnu11 -fshort-wchar -fno-strict-aliasing  -O2    -g    -D__KERNEL__ -D__UBOOT__   -D__ARM__             -ffunction-sections -
....
/bin/sh: 1: arm-linux-gnueabihf-gcc: not found
scripts/Makefile.autoconf:80: recipe for target 'spl/u-boot.cfg' failed
make[1]: *** [spl/u-boot.cfg] Error 1
make: *** No rule to make target 'include/config/auto.conf', needed by 'include/config/uboot.release'.  Stop.
root@ubuntu-GCP1820-SS:u-boot-xlnx-xilinx-v2019.2$ 
root@ubuntu-GCP1820-SS:u-boot-xlnx-xilinx-v2019.2$ 
root@ubuntu-GCP1820-SS:u-boot-xlnx-xilinx-v2019.2$ arm-linux-gnueabihf-gcc -v  # 查看 arm-linux- 版本
The program 'arm-linux-gnueabihf-gcc' is currently not installed. To run 'arm-linux-gnueabihf-gcc' please ask your administrator to install the package 'gcc-arm-linux-gnueabihf'

一、下载交叉编译器

这里主要记录一下怎么下载arm-linux-gnueabi-gcc交叉编译器,这个不像其他软件一样下载最新的就是好的。不同的开发版根文件系统的版本不同,高版本的编译器编译的程序在低版本的根文件系统中不能运行。如果出现不能运行的情况有两种办法,第一将自己交叉编译器的版本降低,第二升级开发版的根文件系统。在Linaro官网中下载arm-linux-gnueabi-gcc编译器,下载网址
https://www.linaro.org/downloads/
1.新版本的下载入口如下图所示:
安装交叉编译器 arm-linux-gnueabihf-gcc_第1张图片
下载流程如下:
“GNU Toolchain Integration Builds → 11.2-2021.10-1 → arm-linux-gnueabihf → gcc-linaro-11.2.1-2021.10-x86_64_arm-linux-gnueabihf.tar.xz”

二、安装交叉编译器

1.解压压缩包

zzz@ubuntu-GCP1820-SS:gcc-arm-linux$ pwd # 当前路径
/home/zzz/xilinx_petalinux/gcc-arm-linux
zzz@ubuntu-GCP1820-SS:gcc-arm-linux$ 
zzz@ubuntu-GCP1820-SS:gcc-arm-linux$ ls -lh # gcc 压缩包文件
total 139M
-rw-r--r-- 1 zzz zzz 139M 323 14:46 gcc-linaro-11.2.1-2021.10-x86_64_arm-linux-gnueabihf.tar.xz
zzz@ubuntu-GCP1820-SS:gcc-arm-linux$
zzz@ubuntu-GCP1820-SS:gcc-arm-linux$ tar -Jxvf gcc-linaro-11.2.1-2021.10-x86_64_arm-linux-gnueabihf.tar.xz  # 解压缩
zzz@ubuntu-GCP1820-SS:gcc-arm-linux$ ls -lh
total 139M
drwxrwxrwx 8 zzz zzz 4.0K 1011 18:20 gcc-linaro-11.2.1-2021.10-x86_64_arm-linux-gnueabihf
-rw-r--r-- 1 zzz zzz 139M 323 14:46 gcc-linaro-11.2.1-2021.10-x86_64_arm-linux-gnueabihf.tar.xz
zzz@ubuntu-GCP1820-SS:gcc-arm-linux$ 
zzz@ubuntu-GCP1820-SS:gcc-arm-linux$ 
zzz@ubuntu-GCP1820-SS:gcc-arm-linux$ cd gcc-linaro-11.2.1-2021.10-x86_64_arm-linux-gnueabihf/  # 进入解压后的目录
zzz@ubuntu-GCP1820-SS:gcc-linaro-11.2.1-2021.10-x86_64_arm-linux-gnueabihf$ 
zzz@ubuntu-GCP1820-SS:gcc-linaro-11.2.1-2021.10-x86_64_arm-linux-gnueabihf$ ls -lh  # 压缩包里的文件和目录
total 36K
drwxr-xr-x 7 zzz zzz 4.0K 1011 18:14 arm-linux-gnueabihf
drwxr-xr-x 2 zzz zzz 4.0K 1011 18:22 bin
-rw-r--r-- 1 zzz zzz  11K 1011 18:20 gcc-linaro-11.2.1-2021.10-linux-manifest.txt
drwxr-xr-x 3 zzz zzz 4.0K 1011 18:17 include
drwxr-xr-x 4 zzz zzz 4.0K 1011 18:22 lib
drwxr-xr-x 3 zzz zzz 4.0K 1011 17:59 libexec
drwxr-xr-x 8 zzz zzz 4.0K 1011 18:17 share
zzz@ubuntu-GCP1820-SS:gcc-linaro-11.2.1-2021.10-x86_64_arm-linux-gnueabihf$ 

2.设置环境变量

在多人协作的服务器上,为了不影响他人的环境,最好把环境变量设置在本用户上。但是,此处依然提供两种环境变量设置的方法。

关键的两条命令: 将交叉编译器的 bin 目录和 lib 目录加入到环境变量中

export PATH=$PATH:/usr/local/arm/gcc-3.4.5-glibc-2.3.6/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/arm/gcc-3.4.5-glibc-2.3.6/lib
1)设置当前用户的环境变量
zzz@ubuntu-GCP1820-SS:gcc-linaro-11.2.1-2021.10-x86_64_arm-linux-gnueabihf$ pwd  # 当前路径
/home/zzz/xilinx_petalinux/gcc-arm-linux/gcc-linaro-11.2.1-2021.10-x86_64_arm-linux-gnueabihf
zzz@ubuntu-GCP1820-SS:gcc-linaro-11.2.1-2021.10-x86_64_arm-linux-gnueabihf$ 
zzz@ubuntu-GCP1820-SS:gcc-linaro-11.2.1-2021.10-x86_64_arm-linux-gnueabihf$ ls -lh
total 36K
drwxr-xr-x 7 zzz zzz 4.0K 1011 18:14 arm-linux-gnueabihf
drwxr-xr-x 2 zzz zzz 4.0K 1011 18:22 bin
-rw-r--r-- 1 zzz zzz  11K 1011 18:20 gcc-linaro-11.2.1-2021.10-linux-manifest.txt
drwxr-xr-x 3 zzz zzz 4.0K 1011 18:17 include
drwxr-xr-x 4 zzz zzz 4.0K 1011 18:22 lib
drwxr-xr-x 3 zzz zzz 4.0K 1011 17:59 libexec
drwxr-xr-x 8 zzz zzz 4.0K 1011 18:17 share
zzz@ubuntu-GCP1820-SS:gcc-linaro-11.2.1-2021.10-x86_64_arm-linux-gnueabihf$ 

如上所示,我们需要把 bin目录和 lib目录添加到环境变量。
在文件最后添加两行,并输入以下代码:第一行是添加执行程序的环境变量,第二行是库文件的路径。

zzz@ubuntu-GCP1820-SS:gcc-linaro-11.2.1-2021.10-x86_64_arm-linux-gnueabihf$ vim ~/.bashrc 
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples


export PATH=$PATH:/home/zzz/xilinx_petalinux/gcc-arm-linux/gcc-linaro-11.2.1-2021.10-x86_64_arm-linux-gnueabihf/bin  # 添加 bin 目录到环境变量
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/zzz/xilinx_petalinux/gcc-arm-linux/gcc-linaro-11.2.1-2021.10-x86_64_arm-linux-gnueabihf/lib        # 添加 lib 目录到环境变量                                                                                                                                                                                                                                                                                   
zzz@ubuntu-GCP1820-SS:gcc-linaro-11.2.1-2021.10-x86_64_arm-linux-gnueabihf$ 

保存设置,查看版本:

zzz@ubuntu-GCP1820-SS:gcc-linaro-11.2.1-2021.10-x86_64_arm-linux-gnueabihf$ source ~/.bashrc # 使环境变量生效
zzz@ubuntu-GCP1820-SS:gcc-arm-linux$ 
zzz@ubuntu-GCP1820-SS:gcc-arm-linux$ arm-linux-gnueabihf-gcc -v  # 查看 arm-linux 版本
Using built-in specs.
COLLECT_GCC=arm-linux-gnueabihf-gcc
COLLECT_LTO_WRAPPER=/home/zzz/xilinx_petalinux/gcc-arm-linux/gcc-linaro-11.2.1-2021.10-x86_64_arm-linux-gnueabihf/bin/../libexec/gcc/arm-linux-gnueabihf/11.2.1/lto-wrapper
Target: arm-linux-gnueabihf
....
  nfigured with: '/home/tcwg-buildslave/workspace/tcwg-gnu-build/snapshots/gcc.git~releases~gcc-。。。。
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 11.2.1 20211011 [releases/gcc-11 revision b3dfc8635d26b9c3cbe7731dd7b8be8a2242eab9] (GCC) 
zzz@ubuntu-GCP1820-SS:gcc-arm-linux$ 
2)设置全局用户的环境变量

步骤与设置当前用户环境变量相同,只是保存的文件不再是 ./bashrc,而是 /etc/profile。

zzz@ubuntu-GCP1820-SS:gcc-arm-linux$ sudo vi /etc/profile # 打开需要配置的文件

# 依旧是添加下面的两条命令
export PATH=$PATH:/home/zzz/xilinx_petalinux/gcc-arm-linux/gcc-linaro-11.2.1-2021.10-x86_64_arm-linux-gnueabihf/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/zzz/xilinx_petalinux/gcc-arm-linux/gcc-linaro-11.2.1-2021.10-x86_64_arm-linux-gnueabihf/lib  
zzz@ubuntu-GCP1820-SS:gcc-arm-linux$ source /etc/profile  # 使环境变量生效

3. 编译uboot

zzz@ubuntu-GCP1820-SS:~/xilinx_petalinux/u-boot-xlnx/u-boot-xlnx-xilinx-v2019.2$ ls
api   board  common     configs  doc            drivers  env       fs       Kbuild   lib       MAINTAINERS  net   README   spl   tools
arch  cmd    config.mk  disk     Documentation  dts      examples  include  Kconfig  Licenses  Makefile     post  scripts  test  u-boot.cfg
zzz@ubuntu-GCP1820-SS:~/xilinx_petalinux/u-boot-xlnx/u-boot-xlnx-xilinx-v2019.2$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zynq_zc702_defconfig
#
# configuration written to .config
#
zzz@ubuntu-GCP1820-SS:~/xilinx_petalinux/u-boot-xlnx/u-boot-xlnx-xilinx-v2019.2$ make V=1 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j8
make: arm-linux-gnueabihf-gcc: Command not found
make -f ./Makefile syncconfig
make -f ./scripts/Makefile.build obj=scripts/basic
rm -f .tmp_quiet_recordmcount
make -f ./scripts/Makefile.build obj=scripts/kconfig syncconfig
mkdir -p include/config include/generated
....
  ./tools/mkimage -T zynqimage -R ./"" -d spl/u-boot-spl-align.bin spl/boot.bin >/dev/null  && cat /dev/null
  ./scripts/check-config.sh u-boot.cfg ./scripts/config_whitelist.txt .
zzz@ubuntu-GCP1820-SS:u-boot-xlnx-xilinx-v2019.2$ 
zzz@ubuntu-GCP1820-SS:u-boot-xlnx-xilinx-v2019.2$ 
zzz@ubuntu-GCP1820-SS:u-boot-xlnx-xilinx-v2019.2$ ls -lhtr
total 11M
drwxrwxr-x  12 zzz zzz 4.0K 1024  2019 test
drwxrwxr-x   6 zzz zzz 4.0K 1024  2019 scripts
-rw-rw-r--   1 zzz zzz 177K 1024  2019 README
drwxrwxr-x   5 zzz zzz 4.0K 1024  2019 post
-rwxrwxr-x   1 zzz zzz  66K 1024  2019 Makefile
-rw-rw-r--   1 zzz zzz  19K 1024  2019 MAINTAINERS
drwxrwxr-x   2 zzz zzz 4.0K 1024  2019 Licenses
-rw-rw-r--   1 zzz zzz  18K 1024  2019 Kconfig
-rw-rw-r--   1 zzz zzz 1.9K 1024  2019 Kbuild
drwxrwxr-x   4 zzz zzz 4.0K 1024  2019 examples
drwxrwxr-x   6 zzz zzz 4.0K 1024  2019 Documentation
drwxrwxr-x  10 zzz zzz  12K 1024  2019 doc
drwxrwxr-x   2 zzz zzz  68K 1024  2019 configs
-rw-rw-r--   1 zzz zzz 2.2K 1024  2019 config.mk
drwxrwxr-x 195 zzz zzz 4.0K 1024  2019 board
drwxrwxr-x  15 zzz zzz 4.0K 1024  2019 arch
drwxrwxr-x   2 zzz zzz 4.0K 1024  2019 api
drwxrwxr-x  31 zzz zzz  16K 323 15:15 include
-rw-rw-r--   1 zzz zzz  19K 323 15:15 u-boot.cfg
-rw-rw-r--   1 zzz zzz 1.6K 323 15:15 u-boot.lds
drwxrwxr-x  17 zzz zzz  12K 323 15:15 tools
drwxrwxr-x   2 zzz zzz 4.0K 323 15:15 disk
drwxrwxr-x   2 zzz zzz 4.0K 323 15:15 env
drwxrwxr-x   5 zzz zzz 4.0K 323 15:15 common
drwxrwxr-x  13 zzz zzz 4.0K 323 15:15 fs
drwxrwxr-x   5 zzz zzz  12K 323 15:15 cmd
drwxrwxr-x   2 zzz zzz 4.0K 323 15:15 net
drwxrwxr-x  62 zzz zzz 4.0K 323 15:15 drivers
drwxrwxr-x  17 zzz zzz 4.0K 323 15:15 lib
-rw-rw-r--   1 zzz zzz 668K 323 15:15 u-boot.map
-rwxrwxr-x   1 zzz zzz 3.8M 323 15:15 u-boot
-rw-rw-r--   1 zzz zzz 170K 323 15:15 u-boot.sym
-rwxrwxr-x   1 zzz zzz 1.7M 323 15:15 u-boot.srec
-rwxrwxr-x   1 zzz zzz 552K 323 15:15 u-boot-nodtb.bin
-rw-rw-r--   1 zzz zzz  82K 323 15:15 System.map
drwxrwxr-x   2 zzz zzz 4.0K 323 15:15 dts
-rw-rw-r--   1 zzz zzz 566K 323 15:15 u-boot-dtb.bin
-rw-rw-r--   1 zzz zzz  15K 323 15:15 u-boot.dtb
-rw-rw-r--   1 zzz zzz 566K 323 15:15 u-boot.bin
-rw-rw-r--   1 zzz zzz 567K 323 15:15 u-boot-elf.o
-rwxrwxr-x   1 zzz zzz 631K 323 15:15 u-boot.elf
-rw-rw-r--   1 zzz zzz 566K 323 15:15 u-boot.img
-rw-rw-r--   1 zzz zzz 566K 323 15:15 u-boot-dtb.img
drwxrwxr-x  13 zzz zzz 4.0K 323 15:15 spl
-rw-rw-r--   1 zzz zzz 8.3K 323 15:15 u-boot.cfg.configs
zzz@ubuntu-GCP1820-SS:u-boot-xlnx-xilinx-v2019.2$ 

https://cloud.tencent.com/developer/article/1826545?from=15425
https://www.cnblogs.com/jzcn/p/14889438.html


你可能感兴趣的:(linux,命令,linux,ubuntu,arm)