Skip to content

Instantly share code, notes, and snippets.

@yyolk
Last active January 28, 2024 22:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yyolk/84e81f9f6148538975a59ba060fb7b1f to your computer and use it in GitHub Desktop.
Save yyolk/84e81f9f6148538975a59ba060fb7b1f to your computer and use it in GitHub Desktop.
rust armv6 cross tools for ARMv6Z-based BCM2835

Run install_rust_armv6_target.sh

Rust is automatically installed with https://rustup.rs

sh ./install_rust_armv6_target.sh

Compile target from project directory

cd project_dir
cargo build --release --target=arm-unknown-linux-gnueabihf

Verify target is right arch

readelf --arch-specific target/arm-unknown-linux-gnueabihf/release/my_project

Alternative Toolchain

The raspberrypi/tools repository is out of date. The recommendation to install gcc-arm-linux-gnueabihf from the distributions apt repository would be fine for armv7.

For rpi0/1 the raspberrypi/tools repository mentions that it should be ./configured with --with-arch=armv6 --with-float=hard --with-fpu=vfp.

There are several options available, already compiled, through sourceforge, however they appear to have been abandoned. https://sourceforge.net/projects/raspberry-pi-cross-compilers/files/

see: https://github.com/abhiTronix/raspberry-pi-cross-compilers/wiki/Cross-Compiler:-Installation-Instructions

and also see: https://github.com/abhiTronix/raspberry-pi-cross-compilers for furhter details for using gcc-6 to gcc-10 or compiling the tool chain manually.

Another toolchain repository

GCC8/GCC9 https://github.com/Pro/raspi-toolchain

# Run this to build for 'arm-unknown-linux-gnueabihf'
cargo build --release --target=arm-unknown-linux-gnueabihf
# for reference
[target.arm-unknown-linux-gnueabihf]
#linker = "arm-linux-gnueabihf-gcc"
linker = "/root/cross-pi-gcc-10.3.0-0/bin/arm-linux-gnueabihf-gcc-10.3.0"
# these will never work if the tools aren't configured and built for these options
# but i didn't know how to pass options to the cross-tools, this does that.
#[build]
#rustflags = ["-C", "link-args=-march=armv6 -mfpu=vfp"]
#! /bin/bash
set -e
BUILDDIR="${HOME}/build-rpi"
mkdir -p "${BUILDDIR}"
test -d "${BUILDDIR}/tools" || git -C "${BUILDDIR}" clone --depth=1 https://github.com/raspberrypi/tools.git
test -d "${BUILDDIR}/ripgrep" || git -C "${BUILDDIR}" clone --depth=1 --branch=0.8.1 https://github.com/BurntSushi/ripgrep.git
sudo apt update && sudo apt install -y gcc
PATH="${HOME}/.cargo/bin:${PATH}"
rustc --version || curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain="stable"
rustup target add arm-unknown-linux-gnueabihf
cat <<EOF > "${HOME}"/.cargo/config
[target.arm-unknown-linux-gnueabihf]
linker = "${HOME}/build-rpi/tools/arm-bcm2708/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc"
EOF
cd "${BUILDDIR}/ripgrep"
cargo build --release --target=arm-unknown-linux-gnueabihf
cd -
ARMv6Z (32-bit):
- Raspberry Pi 1 Model A
- Raspberry Pi 1 Model A+
- Raspberry Pi 1 Model B
- Raspberry Pi 1 Model B+
- Compute Module 1
- Raspberry Pi Zero PCB v1.2
- Raspberry Pi Zero PCB v1.3
- Raspberry Pi Zero W
via: https://en.wikipedia.org/wiki/Raspberry_Pi#Specifications
# verify arm6 armhf binary
readelf --arch-specific '<target/arm-unknown-linux-gnueabihf/release/my_project>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment