Difference between revisions of "Bare metal RISC-V GCC 9.3.0 cross compiler instructions"

From Aram's Wiki
Jump to: navigation, search
(Build and install riscv-openocd)
(Build and install gdb)
(6 intermediate revisions by the same user not shown)
Line 31: Line 31:
  
 
  cd $HOME/obj/gdb-build
 
  cd $HOME/obj/gdb-build
  ../../src/gdb-8.3/configure --prefix $HOME/riscv --target riscv64-unknown-elf --enable-multilib
+
  ../../src/gdb-8.3/configure --prefix $HOME/riscv --target riscv64-unknown-elf --enable-multilib --with-python=/usr/local/bin/python3
 
  make -j8 && make install
 
  make -j8 && make install
  
Line 37: Line 37:
  
 
  cd $HOME/obj/gcc-build
 
  cd $HOME/obj/gcc-build
  ../../src/gcc-9.2.0/configure --prefix $HOME/riscv --target riscv64-unknown-elf --enable-multilib --enable-languages=c --with-gnu-as --with-gnu-ld --without-headers --with-newlib
+
  ../../src/gcc-9.2.0/configure --prefix $HOME/riscv --target riscv64-unknown-elf --enable-multilib --enable-languages=c --without-headers
 
  make -j8 all-gcc && make install-gcc
 
  make -j8 all-gcc && make install-gcc
  
Line 50: Line 50:
 
  rm -rf $HOME/obj/gcc-build && mkdir -p $HOME/obj/gcc-build
 
  rm -rf $HOME/obj/gcc-build && mkdir -p $HOME/obj/gcc-build
 
  cd $HOME/obj/gcc-build
 
  cd $HOME/obj/gcc-build
  ../../src/gcc-9.2.0/configure --prefix $HOME/riscv --target riscv64-unknown-elf --enable-multilib --enable-languages=c --with-gnu-as --with-gnu-ld --with-newlib
+
  ../../src/gcc-9.2.0/configure --prefix $HOME/riscv --target riscv64-unknown-elf --enable-multilib --enable-languages=c --with-newlib
 
  make -j8 all && make install
 
  make -j8 all && make install
  
Line 56: Line 56:
  
 
  cd $HOME/src
 
  cd $HOME/src
  git clone git@github.com:riscv/riscv-openocd.git
+
  git clone --recursive git@github.com:riscv/riscv-openocd.git
 
  cd $HOME/src/riscv-openocd
 
  cd $HOME/src/riscv-openocd
 
  # brew install pkg-config libtool automake autoconf # required by bootstrap
 
  # brew install pkg-config libtool automake autoconf # required by bootstrap
Line 62: Line 62:
 
  ./configure --prefix=$HOME/riscv --enable-remote-bitbang --enable-jtag_vpi
 
  ./configure --prefix=$HOME/riscv --enable-remote-bitbang --enable-jtag_vpi
 
  make -j8 && make install
 
  make -j8 && make install
 +
 +
== Add tools to PATH and set RISCV ==
 +
 +
printf 'PATH=$HOME/riscv/bin:$PATH\nRISCV=$HOME/riscv\nexport RISCV\n' >> $HOME/lib/profile.local
 +
 +
Also, if you have installed spike from a repository, you might want to symlink it into <code>RISCV/bin</code>.
 +
 +
ln -s /usr/local/bin/spike $HOME/riscv/bin/spike

Revision as of 16:50, 13 November 2019


Introduction

We'll build a GCC 9.2.0 targeting bare metal RISC-V. Many RISC-V tools expect a $RISCV variable pointing at the toolchain, so we can't use split --prefix and --bindir as we usually use.

Create directories

cd $HOME
mkdir -p src obj/{binutils-build,gcc-build,gdb-build,newlib-build}

Get GCC, GDB and binutils

curl https://ftp.gnu.org/gnu/binutils/binutils-2.33.1.tar.gz | tar -C $HOME/src -xf -
curl https://ftp.gnu.org/gnu/gdb/gdb-8.3.tar.gz | tar -C $HOME/src -xf -
curl https://ftp.gnu.org/gnu/gcc/gcc-9.2.0/gcc-9.2.0.tar.gz | tar -C $HOME/src -xf -
curl ftp://sourceware.org/pub/newlib/newlib-3.1.0.tar.gz | tar -C $HOME/src -xf -

Download prerequisites

cd $HOME/src/gcc-9.2.0
./contrib/download_prerequisites

Build and install binutils

cd $HOME/obj/binutils-build
../../src/binutils-2.33.1/configure --prefix $HOME/riscv --target riscv64-unknown-elf --enable-multilib
make -j8 && make install

Build and install gdb

cd $HOME/obj/gdb-build
../../src/gdb-8.3/configure --prefix $HOME/riscv --target riscv64-unknown-elf --enable-multilib --with-python=/usr/local/bin/python3
make -j8 && make install

Build and install bare metal gcc

cd $HOME/obj/gcc-build
../../src/gcc-9.2.0/configure --prefix $HOME/riscv --target riscv64-unknown-elf --enable-multilib --enable-languages=c --without-headers
make -j8 all-gcc && make install-gcc

Build and install newlib

cd $HOME/obj/newlib-build
../../src/newlib-3.1.0/configure --prefix $HOME/riscv --target riscv64-unknown-elf --enable-multilib
make -j8 all && make install

Build and install newlib gcc

rm -rf $HOME/obj/gcc-build && mkdir -p $HOME/obj/gcc-build
cd $HOME/obj/gcc-build
../../src/gcc-9.2.0/configure --prefix $HOME/riscv --target riscv64-unknown-elf --enable-multilib --enable-languages=c --with-newlib
make -j8 all && make install

Build and install riscv-openocd

cd $HOME/src
git clone --recursive git@github.com:riscv/riscv-openocd.git
cd $HOME/src/riscv-openocd
# brew install pkg-config libtool automake autoconf # required by bootstrap
./bootstrap
./configure --prefix=$HOME/riscv --enable-remote-bitbang --enable-jtag_vpi
make -j8 && make install

Add tools to PATH and set RISCV

printf 'PATH=$HOME/riscv/bin:$PATH\nRISCV=$HOME/riscv\nexport RISCV\n' >> $HOME/lib/profile.local

Also, if you have installed spike from a repository, you might want to symlink it into RISCV/bin.

ln -s /usr/local/bin/spike $HOME/riscv/bin/spike