Bläddra i källkod

Add toolchain build via git submodules and Makefile

H. Peter Anvin 3 år sedan
förälder
incheckning
29838ba040
5 ändrade filer med 55 tillägg och 1 borttagningar
  1. 3 0
      .gitmodules
  2. 2 0
      fw/.gitignore
  3. 2 1
      fw/Makefile
  4. 47 0
      fw/tools/Makefile
  5. 1 0
      fw/tools/riscv-gnu-toolchain

+ 3 - 0
.gitmodules

@@ -0,0 +1,3 @@
+[submodule "fw/tools/riscv-gnu-toolchain"]
+	path = fw/tools/riscv-gnu-toolchain
+	url = https://github.com/riscv/riscv-gnu-toolchain

+ 2 - 0
fw/.gitignore

@@ -3,3 +3,5 @@
 *.s
 *.elf
 *.bin
+*.build/
+tools/gnu/

+ 2 - 1
fw/Makefile

@@ -9,13 +9,14 @@ INCLUDE   = -I. -I./include
 CPPFLAGS  = $(INCLUDE) \
 	     -march=rv32imc -mabi=ilp32 -mdiv -Os -ggdb3 \
 	     -fwrapv -fvisibility=hidden -fno-strict-aliasing \
+	     -fno-pic -mno-plt -msmall-data-limit=8192 \
 	     -frename-registers \
 	     -mshorten-memrefs -mno-strict-align
 # These require newlib to be built with the same options; would be nice
 CPPFLAGS_NOT = -fshort-enums -fshort-wchar
 CFLAGS    = $(CPPFLAGS)
 SFLAGS    = $(CPPFLAGS) -D__ASSEMBLY__
-LDFLAGS   = $(CFLAGS) --specs=nano.specs \
+LDFLAGS   = $(CFLAGS) \
 	    -Wl,--section-start=.init=0 -Wl,-q \
 	    -Wl,-z,common-page-size=16 -Wl,-z,max-page-size=16
 

+ 47 - 0
fw/tools/Makefile

@@ -0,0 +1,47 @@
+MAKEFLAGS += -R -r
+
+CROSS     = riscv32-unknown-elf-
+prefix   := $(CURDIR)
+target_flags = -fvisibility=hidden -fno-pic -mshorten-memrefs \
+	       -frename-registers -mdiv -mno-strict-align \
+	       -ffunction-sections -fdata-sections
+
+tooldir   = riscv-gnu-toolchain
+
+# --disable-gdb because the gdb with riscv-gnu-toolchain seems really broken
+config    = --prefix=$(prefix)/gnu \
+	    --with-arch=rv32imc --with-abi=ilp32 \
+	    --with-target-cflags='$(target_flags)' \
+	    --with-target-cxxflags='$(target_flags)' \
+	    --with-system-zlib \
+	    --disable-gdb \
+	    --enable-multilib --with-multilib-generator='rv32imc-ilp32--'
+
+# The tools don't seem to build correctly without buildin rules (sigh)
+# There isn't even an option to cancel them, so use this hideousness
+# to strip out the r and R option from MAKEFLAGS.
+_tail = $(wordlist 2,$(words $(1)),$(1))
+_strip_flags = $(if $(1),$(call _strip_flags,$(call _tail,$(1)),$(subst $(word 1,$(1)),,$(2))),$(2))
+strip_flags  = $(if $(findstring -,$(word 1,$(2))),$(2),$(call _strip_flags,$(1),$(word 1,$(2))) $(call _tail,$(2)))
+
+RMAKE = $(MAKE) MAKEFLAGS='$(call strip_flags,r R,$(MAKEFLAGS))'
+
+export target_configargs := --enable-lite-exit --disable-newlib-register-fini
+
+export PATH := $(prefix)/gnu/bin:$(PATH)
+
+all: gnu
+
+clean:
+	rm -rf gnu *.build
+
+# Note: the riscv-gnu-toolchain repo has bugs when building in
+# parallel, so spoon feed it a sequence to avoid dependency problems.
+.PHONY: gnu
+gnu:
+	[ ! -f ../../.gitmodules ] || \
+		git submodule update --init --recursive
+	mkdir -p gnu.build
+	cd gnu.build && ../$(tooldir)/configure $(config)
+	$(RMAKE) -C gnu.build build-binutils
+	$(RMAKE) -C gnu.build newlib

+ 1 - 0
fw/tools/riscv-gnu-toolchain

@@ -0,0 +1 @@
+Subproject commit b39e36160aa0649ba0dfb9aa314d375900d610fb