gcc arm-none-eabi工具链从源代码编译

6ss1mwsb  于 2023-04-06  发布在  其他
关注(0)|答案(3)|浏览(203)

对于我目前的项目,我们有一个问题,如果我们能够从源代码重新编译arm工具链(gcc,c++stdlib,nanolibc等),我们就可以解决这个问题。
arm website我可以下载一个snapshot的源代码。我找到了一个blog,但它已经过时了。他所指的pdf在这个快照中已经不存在了。
浏览解压后的存档文件,我似乎找不到任何如何编译的说明。
我在哪里可以找到如何从源代码编译arm-none-eabi的文档?

sh7euo9m

sh7euo9m1#

download site上的发行说明包括从源代码构建的说明。
我在这里做了一个快速的转录,但未来的读者应该被警告它可能已经过时了。

如何从源代码构建工具链

您可以使用Linaro ABE(高级构建环境)和提供的ABE清单文件从源代码构建Arm GNU Toolchain。
下面的例子展示了如何使用Linaro ABE构建系统从源代码构建gcc-arm-aarch 64-none-elf工具链。
说明
ABE依赖于git-new-workdir,需要将此工具安装在/usr/local/bin目录中:

$ wget https://raw.githubusercontent.com/git/git/master/contrib/workdir/git-new-workdir
$ sudo mv git-new-workdir /usr/local/bin
$ sudo chmod +x /usr/local/bin/git-new-workdir

从下面的URL克隆ABE并 checkout stablebranch(参见Getting ABE):

$ git clone https://git.linaro.org/toolchain/abe.git

创建构建目录并切换到该目录。该目录的任何名称都可以使用:

$ mkdir build && cd build

配置ABE(从构建目录):

$ ../abe/configure

将工具链清单文件从https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/downloads下载到build文件夹中,用于所需的工具链,例如,gcc-arm-aarch 64-none-elf-abe-manifest.txt:

$  wget https://developer.arm.com/-/media/Files/downloads/gnu/11.2-2022.02/manifest/gcc-arm-aarch64-none-elf-abe-manifest.txt

构建工具链(从构建目录):

$ ../abe/abe.sh --manifest gcc-arm-aarch64-none-elf-abe-manifest.txt --build all

构建的工具链将安装在builds/destdir/x86_64-unknown-linux-gnu/bin/目录中,并可供使用。

gmxoilav

gmxoilav2#

# Usage
# sudo ./build_arm

# Setup vars
export TARGET=arm-none-eabi
export PREFIX=/opt/gnuarm
export PATH=$PATH:$PREFIX/bin
export JN='-j 8'

export GCCVER=11.2.0
export BINUVER=2.37

rm -rf build-*
rm -rf gcc-*
rm -rf binutils-*

# Get archives
wget https://ftp.gnu.org/gnu/binutils/binutils-$BINUVER.tar.gz
wget https://ftp.gnu.org/gnu/gcc/gcc-$GCCVER/gcc-$GCCVER.tar.gz

# Extract archives
tar xf binutils-$BINUVER.tar.gz
tar xf gcc-$GCCVER.tar.gz

# Build binutils
mkdir build-binutils
cd build-binutils
../binutils-$BINUVER/configure --target=$TARGET --prefix=$PREFIX
echo "MAKEINFO = :" >> Makefile
make $JN all
sudo make install

# Build GCC
mkdir ../build-gcc
cd ../build-gcc
../gcc-$GCCVER/configure --target=$TARGET --prefix=$PREFIX --without-headers --with-newlib  --with-gnu-as --with-gnu-ld --enable-languages='c' --enable-frame-pointer=no
make $JN all-gcc
sudo make install-gcc

# Build libgcc.a
make $JN all-target-libgcc CFLAGS_FOR_TARGET="-g -O2"
sudo make install-target-libgcc
hgqdbh6s

hgqdbh6s3#

对于那些遇到同样问题的人,我找到了一个针对arm工具链12.2的解决方案。它可能也适用于以前版本的工具链,我还没有检查。12.2带来了c++ 20支持。
我把它装进了集装箱

# install dependencies for python3.8
RUN apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget -y

# install arm toolchain
RUN ARM_TOOLCHAIN_VERSION=12.2.Rel1
RUN curl -Lo gcc-arm-none-eabi.tar.xz "https://developer.arm.com/-/media/Files/downloads/gnu/12.2.Rel1/binrel/arm-gnu-toolchain-12.2.Rel1-x86_64-arm-none-eabi.tar.xz"
RUN mkdir -p /opt/gcc-arm-none-eabi
RUN tar xf gcc-arm-none-eabi.tar.xz --strip-components=1 -C /opt/gcc-arm-none-eabi
ENV PATH="/opt/gcc-arm-none-eabi/bin:${PATH}"

# test arm-none-gcc
RUN arm-none-eabi-gcc --version

# install python3.8
RUN wget https://www.python.org/ftp/python/3.8.12/Python-3.8.12.tgz
RUN tar -xf Python-3.8.12.tgz
WORKDIR /Python-3.8.12
RUN ./configure --enable-optimizations
RUN make -j 4
RUN make altinstall

#attempt to fix libncursesw.so.5
RUN apt install libncurses5 -y
RUN apt install libncursesw5 -y

# test arm-none-gdb
RUN arm-none-eabi-gdb --version

所以它基本上是:

  • 安装了一堆依赖项,
  • 下载arm toolchain 12.2
  • 从源代码编译python3.8,并将python3.8安装在任何现有python版本旁边。
  • 测试它是否可以执行arm-none-eabi-gdb

如果你想在你的主机操作系统上执行这个,删除docker RUN命令,并在这里和那里添加一些sudo:)。
如果有任何帮助,我的完整docker文件(安装了更多,比如jlink支持,以便能够在附加到这个docker容器时从vscode编译/运行/调试)

FROM ubuntu

ENV UDEV=on

RUN apt-get update -y
RUN apt-get upgrade -y

# Install dependencies for JLink
RUN apt install libxcb-render-util0-dev -y
RUN apt install libxrender1 libxcb-shape0 libxcb-randr0 libxcb-xfixes0 libxcb-sync1 libxcb-shm0 libxcb-icccm4 libxcb-keysyms1 libxcb-image0 libxkbcommon0 libxkbcommon-x11-0 libfontconfig1 libfreetype6 libxext6 libx11-xcb1 libsm6 libice6 libglib2.0-0 -y

# Install dependencies for JLinkServer
RUN apt install libxcursor-dev libxfixes3 libxrandr2 -y

# install jlink
RUN mkdir -p /home/Downloads
COPY JLink_Linux_V786b_x86_64.deb /home/Downloads/JLink_Linux_V786b_x86_64.deb
RUN dpkg --unpack /home/Downloads/JLink_Linux_V786b_x86_64.deb
RUN rm /var/lib/dpkg/info/jlink.postinst -f
RUN dpkg --configure jlink
RUN apt install -yf 

# Install curl
RUN apt install curl bzip2 -y

# install dependencies for arm-none-eabi-gdb
#RUN apt install libncurses5 -y

# install dependencies for python3.8
RUN apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget -y

# install arm toolchain
RUN ARM_TOOLCHAIN_VERSION=12.2.Rel1
RUN curl -Lo gcc-arm-none-eabi.tar.xz "https://developer.arm.com/-/media/Files/downloads/gnu/12.2.Rel1/binrel/arm-gnu-toolchain-12.2.Rel1-x86_64-arm-none-eabi.tar.xz"
RUN mkdir -p /opt/gcc-arm-none-eabi
RUN tar xf gcc-arm-none-eabi.tar.xz --strip-components=1 -C /opt/gcc-arm-none-eabi
ENV PATH="/opt/gcc-arm-none-eabi/bin:${PATH}"

# test arm-none-gcc
RUN arm-none-eabi-gcc --version

# install cmake
RUN apt install cmake -y
RUN apt install udev -y
RUN /lib/systemd/systemd-udevd --daemon

# install git
RUN apt install git -y

# install ninja
RUN apt install ninja-build python3 pip -y
RUN pip install meson

# install python3.8
RUN wget https://www.python.org/ftp/python/3.8.12/Python-3.8.12.tgz
RUN tar -xf Python-3.8.12.tgz
WORKDIR /Python-3.8.12
RUN ./configure --enable-optimizations
RUN make -j 4
RUN make altinstall

#attempt to fix libncursesw.so.5
RUN apt install libncurses5 -y
RUN apt install libncursesw5 -y

# test arm-none-gdb
RUN arm-none-eabi-gdb --version

ARG USER_ID
ARG GROUP_ID

RUN addgroup --gid $GROUP_ID user && adduser --disabled-password --gecos '' --uid $USER_ID --gid $GROUP_ID user
USER user

WORKDIR /home/dev/

CMD bash

相关问题