Search code examples
gccarm

arm-none-eabi toolchain compile from source


For my current project we are having an issue which we can solve if we are able to recompile the arm toolchain (gcc, c++stdlib, nanolibc, etc) from source.

From the arm website I can download a snapshot of the source. I found a blog but it's outdated. The pdf he refers to no longer exists in this snapshot anyway.

Browsing through the extracted archive I can't seem to find any instructions how to compile.

Where can I find documentation how to compile arm-none-eabi from source?


Solution

  • For those who are running into the same problem, I found a solution for the arm toolchain 12.2. It might also work for the previous version of the toolchain, I haven't checked. 12.2 brings c++ 20 support.

    I containerized this as follows

    # 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
    
    

    So it basically :

    • installs a bunch of dependencies,
    • downloads arm toolchain 12.2
    • compiles python3.8 from sources and installs python3.8 next to any existing python version.
    • tests if it can execute arm-none-eabi-gdb

    If you want to execute this on your host OS, remove the docker RUN commands and add some sudo's here and there :).

    If it's of any help, my full docker file (which installs a bunch more, like jlink support to be able to compile/run/debug from vscode when attached to this docker container)

    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