Skip to content

Instantly share code, notes, and snippets.

@mithro
Last active November 20, 2016 07:58
Show Gist options
  • Save mithro/1fcd4e6a8fcae9997e54f19efb3c5dcc to your computer and use it in GitHub Desktop.
Save mithro/1fcd4e6a8fcae9997e54f19efb3c5dcc to your computer and use it in GitHub Desktop.
#!/bin/bash
PREFIX=/opt/lm32
MAKE_ARGS=-j128
TARGET=lm32-elf
set -x
set -e
# Build binutils + gcc
# Following the approach at http://openrisc.io/newlib/building.html
mkdir -p toolchain
if [ ! -d toolchain -o ! -d $PREFIX/bin ]; then
(
cd toolchain
(
mkdir -p download
cd download
wget -c https://ftp.gnu.org/gnu/binutils/binutils-2.27.tar.gz
wget -c https://gmplib.org/download/gmp/gmp-6.1.1.tar.xz
wget -c ftp://ftp.gnu.org/gnu/mpc/mpc-1.0.2.tar.gz
wget -c http://www.mpfr.org/mpfr-current/mpfr-3.1.5.tar.xz
wget -c ftp://gcc.gnu.org/pub/gcc/infrastructure/isl-0.15.tar.bz2
wget -c ftp://sourceware.org/pub/newlib/newlib-2.4.0.20161025.tar.gz
wget -c https://ftp.gnu.org/gnu/gcc/gcc-6.2.0/gcc-6.2.0.tar.gz
)
for i in gmp mpc mpfr isl newlib gcc; do
echo "Extracting $i"
if [ -d ${i}-* ]; then rm -rf $PWD/${i}-*; fi
tar -xf ./download/${i}-*
done
rm -rf $PREFIX/*
export PATH=$PREFIX/bin:$PATH
(
cd binutils-*
./configure --prefix=$PREFIX --target=$TARGET --disable-sim
make $MAKE_ARGS
make install
)
(
cd gcc-*
for i in gmp mpc mpfr isl; do
ln -s $(realpath $PWD/../${i}-*) $i
done
)
(
rm -rf build-gcc-stage1
mkdir -p build-gcc-stage1
cd build-gcc-stage1
../gcc-*/configure \
--target=$TARGET \
--enable-languages=c \
--disable-shared \
--disable-libssp \
--prefix=$PREFIX \
make $MAKE_ARGS
make install-strip
)
${TARGET}-gcc --version
(
rm -rf build-newlib
mkdir -p build-newlib
cd build-newlib
../newlib-*/configure \
--target=$TARGET \
--prefix=$PREFIX \
--disable-multilib \
make $MAKE_ARGS
make install
)
(
rm -rf build-gcc-stage2
mkdir -p build-gcc-stage2
cd build-gcc-stage2
../gcc-*/configure \
--target=$TARGET \
--enable-languages=c,c++ \
--disable-shared \
--disable-libssp \
--with-newlib \
--prefix=$PREFIX \
make $MAKE_ARGS
make install-strip
)
${TARGET}-gcc --version
)
fi
if [ ! -d qemu-litex ]; then
git clone https://github.com/shenki/qemu-litex.git
else
cd qemu-litex
git pull
fi
(
cd qemu-litex
./configure --target-list=lm32-softmmu --prefix=$PREFIX
make $MAKE_ARGS
make install
)
if [ -d qemu-litex ]; then
git clone https://github.com/shenki/micropython.git -b lm32
else
cd micropython
git pull
fi
cd micropython/lm32
CROSS_COMPILE=$PREFIX/bin/${TARGET}- make deploy
echo Run with
echo PATH=$PREFIX/bin:\$PATH \
qemu-system-lm32 \
-M litex \
-nographic \
-nodefaults \
-serial stdio \
-kernel ./build/firmware.elf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment