Giter Site home page Giter Site logo

raspi-toolchain's Introduction

Rasperry PI Toolchains

Repository for Raspberry PI cross compiler using the new GCC8 and GCC9 for Raspbian Buster. This supports all new Raspberry PIs (ARMv7), and the older ones, including Zero, A, B, B+ (ARMv6) with newer GCCs.

You can probably also use this repository for any other ARMv6 and ARMv7 devices.

By default, newer GCC versions do not create correct binaries for ARMv6. Even though you pass the correct -mcpu= flag to gcc, it will create startup code for the newer ARMv7 architecture. Running them on your RasPI Zero will cause an "Illegal Instruction" exception.

See also: https://stackoverflow.com/questions/55465118/gcc-8-cross-compiler-outputs-armv7-executable-instead-of-armv6

This work is based on the great @tttapa and the Docker file here: https://gist.github.com/tttapa/534fb671c5f6cced0e1722d3e4aec987

A corresponding Blog post can be found here: https://solarianprogrammer.com/2018/05/06/building-gcc-cross-compiler-raspberry-pi/

A similar project can also be found here, but it only includes the compiled toolchains, which did not work out of the box for me: https://sourceforge.net/projects/raspberry-pi-cross-compilers

How to get the toolchain

You have two options:

  • Use the prebuilt toolchain attached to every github release (recommended)
  • Build the toolchain yourself

Use pre-built toolchain

Every github release has a pre-build toolchain attached. See

  1. Download the toolchain:
wget https://github.com/Pro/raspi-toolchain/releases/latest/download/raspi-toolchain.tar.gz
  1. Extract it. Note: The toolchain has to be in /opt/cross-pi-gcc since it's not location independent.
sudo tar xfz raspi-toolchain.tar.gz --strip-components=1 -C /opt
  1. You are done!

Build the toolchain from source

To build the toolchain, just clone this repository and then call:

docker build -f Dockerfile --network=host -t gcc9-rpi-zero .

This will take some time since it builds a docker container with the gcc compiler.

To run the docker container, use

docker run -it gcc9-rpi-zero bash

Install from source after building

To get the toolchain from the docker container into your host, just copy the files:

CONTAINER_ID=$(docker create gcc9-rpi-zero)
sudo docker cp $CONTAINER_ID:/opt/cross-pi-gcc /opt/cross-pi-gcc

It's important that you put the files into the same directory, since the toolchain has the paths hardcoded inside.

After that feel free to delete the docker container.

Test the toolchain

This repository contains a simple hello world example.

To cross-compile any executable after you installed the toolchain on your host, you need to get the current libraries and include files from your raspberry:

# Use the correct IP address here
rsync -vR --progress -rl --delete-after --safe-links [email protected]:/{lib,usr,etc/ld.so.conf.d,opt/vc/lib} $HOME/rpi/rootfs

Then call the script build_hello_world.sh.

To test the executable, copy it to your raspi:

scp build/hello [email protected]:/home/pi/hello
ssh [email protected]
./hello

raspi-toolchain's People

Contributors

pro avatar bernhard-guillon-copadata avatar jamesrusso avatar praxx avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.