From 63604809add5fe0e112e1a585c0083344bbe8e74 Mon Sep 17 00:00:00 2001 From: cgsfv Date: Tue, 6 Apr 2021 10:12:38 -0700 Subject: [PATCH] Going back to a monorepo --- Makefile | 68 +- README.md | 50 +- modules/freedom-binutils-metal.mk | 50 - modules/freedom-binutils-metal/Makefile | 122 ++ modules/freedom-binutils-metal/Metadata.mk | 8 + modules/freedom-binutils-metal/Monorepo.mk | 42 + .../scripts/build_binutils_target.mk | 35 + .../scripts/extra_binutils_target.mk | 33 + modules/freedom-gcc-metal.mk | 50 - modules/freedom-gcc-metal/Makefile | 464 +++++++ modules/freedom-gcc-metal/Metadata.mk | 10 + modules/freedom-gcc-metal/Monorepo.mk | 42 + modules/freedom-gdb-metal.mk | 50 - modules/freedom-gdb-metal/Makefile | 207 +++ modules/freedom-gdb-metal/Metadata.mk | 8 + modules/freedom-gdb-metal/Monorepo.mk | 42 + .../patches/pyconfig-x86_64-apple-darwin.sh | 18 + .../patches/pyconfig-x86_64-linux-centos6.sh | 18 + .../patches/pyconfig-x86_64-linux-ubuntu14.sh | 18 + .../patches/pyconfig-x86_64-w64-mingw32.sh | 18 + .../patches/python-c-gdb.sed | 1 + modules/freedom-openocd.mk | 38 - modules/freedom-openocd/Makefile | 173 +++ modules/freedom-openocd/Metadata.mk | 15 + modules/freedom-openocd/Monorepo.mk | 35 + .../freedom-openocd/patches/openocd-rtos.sed | 1 + modules/freedom-openocd/patches/openocd.sed | 4 + modules/freedom-qemu.mk | 38 - modules/freedom-qemu/Makefile | 421 ++++++ modules/freedom-qemu/Metadata.mk | 15 + modules/freedom-qemu/Monorepo.mk | 35 + .../patches/gettext-gnu-source.sed | 1 + .../freedom-qemu/patches/glib-dllmain-off.sed | 2 + .../freedom-qemu/patches/glib-var-extern.sed | 1 + modules/freedom-qemu/patches/qemu-common.sed | 1 + .../freedom-qemu/patches/qemu-configure.sed | 2 + .../patches/qemu-net-can-meson.build | 4 + modules/freedom-qemu/patches/qemu-riscv-cpu.c | 669 +++++++++ modules/freedom-qemu/patches/qemu-riscv-cpu.h | 537 ++++++++ modules/freedom-qemu/patches/qemu-sifive-e.c | 292 ++++ modules/freedom-qemu/patches/qemu-sifive-e.h | 94 ++ .../freedom-qemu/patches/qemu-sifive-test.c | 102 ++ modules/freedom-qemu/patches/qemu-sifive-u.c | 1195 +++++++++++++++++ modules/freedom-qemu/patches/qemu-sifive-u.h | 140 ++ .../patches/qemu-util-meson.build | 79 ++ modules/freedom-qemu/patches/qemu-vl.sed | 1 + modules/freedom-sdk-utilities.mk | 38 - modules/freedom-sdk-utilities/Makefile | 155 +++ modules/freedom-sdk-utilities/Metadata.mk | 19 + modules/freedom-sdk-utilities/Monorepo.mk | 35 + .../patches/dtc-fstree.sed | 1 + .../patches/dtc-lexer.sed | 1 + modules/freedom-sdk-utilities/patches/dtc.mk | 379 ++++++ .../patches/spike-dasm-config.h | 2 + .../patches/spike-dasm-extension.h | 18 + .../patches/spike-dasm-extensions.cc | 28 + .../patches/spike-dasm.mk | 51 + modules/freedom-toolchain-metal.mk | 68 - modules/freedom-toolchain-metal/Makefile | 179 +++ modules/freedom-toolchain-metal/Metadata.mk | 14 + modules/freedom-toolchain-metal/Monorepo.mk | 72 + modules/freedom-trace-decoder.mk | 38 - modules/freedom-trace-decoder/Makefile | 113 ++ modules/freedom-trace-decoder/Metadata.mk | 17 + modules/freedom-trace-decoder/Monorepo.mk | 35 + modules/freedom-xc3sprog.mk | 38 - modules/freedom-xc3sprog/Makefile | 191 +++ modules/freedom-xc3sprog/Metadata.mk | 15 + modules/freedom-xc3sprog/Monorepo.mk | 35 + .../patches/xc3sprog-cmake.sed | 1 + .../patches/xc3sprog-mingw32.sed | 1 + modules/freedom-xc3sprog/patches/xc3sprog.sed | 2 + scripts/Freedom.mk | 75 +- scripts/Package.mk | 165 ++- scripts/base_binutils_metadata.mk | 17 + scripts/base_gcc_metadata.mk | 17 + scripts/base_gdb_metadata.mk | 17 + scripts/base_newlib_metadata.mk | 5 + scripts/base_toolchain_metadata.mk | 5 + scripts/check-maximum-path-length.tcl | 43 + scripts/check-naming-and-version-syntax.tcl | 24 + scripts/check-same-name-different-case.tcl | 38 + scripts/dyn-lib-check-x86_64-apple-darwin.tcl | 53 + .../dyn-lib-check-x86_64-linux-centos6.tcl | 49 + .../dyn-lib-check-x86_64-linux-ubuntu14.tcl | 47 + scripts/dyn-lib-check-x86_64-w64-mingw32.tcl | 10 + 86 files changed, 6869 insertions(+), 491 deletions(-) delete mode 100644 modules/freedom-binutils-metal.mk create mode 100644 modules/freedom-binutils-metal/Makefile create mode 100644 modules/freedom-binutils-metal/Metadata.mk create mode 100644 modules/freedom-binutils-metal/Monorepo.mk create mode 100644 modules/freedom-binutils-metal/scripts/build_binutils_target.mk create mode 100644 modules/freedom-binutils-metal/scripts/extra_binutils_target.mk delete mode 100644 modules/freedom-gcc-metal.mk create mode 100644 modules/freedom-gcc-metal/Makefile create mode 100644 modules/freedom-gcc-metal/Metadata.mk create mode 100644 modules/freedom-gcc-metal/Monorepo.mk delete mode 100644 modules/freedom-gdb-metal.mk create mode 100644 modules/freedom-gdb-metal/Makefile create mode 100644 modules/freedom-gdb-metal/Metadata.mk create mode 100644 modules/freedom-gdb-metal/Monorepo.mk create mode 100755 modules/freedom-gdb-metal/patches/pyconfig-x86_64-apple-darwin.sh create mode 100755 modules/freedom-gdb-metal/patches/pyconfig-x86_64-linux-centos6.sh create mode 100755 modules/freedom-gdb-metal/patches/pyconfig-x86_64-linux-ubuntu14.sh create mode 100755 modules/freedom-gdb-metal/patches/pyconfig-x86_64-w64-mingw32.sh create mode 100644 modules/freedom-gdb-metal/patches/python-c-gdb.sed delete mode 100644 modules/freedom-openocd.mk create mode 100644 modules/freedom-openocd/Makefile create mode 100644 modules/freedom-openocd/Metadata.mk create mode 100644 modules/freedom-openocd/Monorepo.mk create mode 100644 modules/freedom-openocd/patches/openocd-rtos.sed create mode 100644 modules/freedom-openocd/patches/openocd.sed delete mode 100644 modules/freedom-qemu.mk create mode 100644 modules/freedom-qemu/Makefile create mode 100644 modules/freedom-qemu/Metadata.mk create mode 100644 modules/freedom-qemu/Monorepo.mk create mode 100644 modules/freedom-qemu/patches/gettext-gnu-source.sed create mode 100644 modules/freedom-qemu/patches/glib-dllmain-off.sed create mode 100644 modules/freedom-qemu/patches/glib-var-extern.sed create mode 100644 modules/freedom-qemu/patches/qemu-common.sed create mode 100644 modules/freedom-qemu/patches/qemu-configure.sed create mode 100644 modules/freedom-qemu/patches/qemu-net-can-meson.build create mode 100644 modules/freedom-qemu/patches/qemu-riscv-cpu.c create mode 100644 modules/freedom-qemu/patches/qemu-riscv-cpu.h create mode 100644 modules/freedom-qemu/patches/qemu-sifive-e.c create mode 100644 modules/freedom-qemu/patches/qemu-sifive-e.h create mode 100644 modules/freedom-qemu/patches/qemu-sifive-test.c create mode 100644 modules/freedom-qemu/patches/qemu-sifive-u.c create mode 100644 modules/freedom-qemu/patches/qemu-sifive-u.h create mode 100644 modules/freedom-qemu/patches/qemu-util-meson.build create mode 100644 modules/freedom-qemu/patches/qemu-vl.sed delete mode 100644 modules/freedom-sdk-utilities.mk create mode 100644 modules/freedom-sdk-utilities/Makefile create mode 100644 modules/freedom-sdk-utilities/Metadata.mk create mode 100644 modules/freedom-sdk-utilities/Monorepo.mk create mode 100644 modules/freedom-sdk-utilities/patches/dtc-fstree.sed create mode 100644 modules/freedom-sdk-utilities/patches/dtc-lexer.sed create mode 100644 modules/freedom-sdk-utilities/patches/dtc.mk create mode 100644 modules/freedom-sdk-utilities/patches/spike-dasm-config.h create mode 100644 modules/freedom-sdk-utilities/patches/spike-dasm-extension.h create mode 100644 modules/freedom-sdk-utilities/patches/spike-dasm-extensions.cc create mode 100644 modules/freedom-sdk-utilities/patches/spike-dasm.mk delete mode 100644 modules/freedom-toolchain-metal.mk create mode 100644 modules/freedom-toolchain-metal/Makefile create mode 100644 modules/freedom-toolchain-metal/Metadata.mk create mode 100644 modules/freedom-toolchain-metal/Monorepo.mk delete mode 100644 modules/freedom-trace-decoder.mk create mode 100644 modules/freedom-trace-decoder/Makefile create mode 100644 modules/freedom-trace-decoder/Metadata.mk create mode 100644 modules/freedom-trace-decoder/Monorepo.mk delete mode 100644 modules/freedom-xc3sprog.mk create mode 100644 modules/freedom-xc3sprog/Makefile create mode 100644 modules/freedom-xc3sprog/Metadata.mk create mode 100644 modules/freedom-xc3sprog/Monorepo.mk create mode 100644 modules/freedom-xc3sprog/patches/xc3sprog-cmake.sed create mode 100644 modules/freedom-xc3sprog/patches/xc3sprog-mingw32.sed create mode 100644 modules/freedom-xc3sprog/patches/xc3sprog.sed create mode 100644 scripts/base_binutils_metadata.mk create mode 100644 scripts/base_gcc_metadata.mk create mode 100644 scripts/base_gdb_metadata.mk create mode 100644 scripts/base_newlib_metadata.mk create mode 100644 scripts/base_toolchain_metadata.mk create mode 100644 scripts/check-maximum-path-length.tcl create mode 100644 scripts/check-naming-and-version-syntax.tcl create mode 100644 scripts/check-same-name-different-case.tcl create mode 100644 scripts/dyn-lib-check-x86_64-apple-darwin.tcl create mode 100644 scripts/dyn-lib-check-x86_64-linux-centos6.tcl create mode 100644 scripts/dyn-lib-check-x86_64-linux-ubuntu14.tcl create mode 100644 scripts/dyn-lib-check-x86_64-w64-mingw32.tcl diff --git a/Makefile b/Makefile index 5ed21e9..26bb092 100644 --- a/Makefile +++ b/Makefile @@ -1,31 +1,50 @@ -# Setup the Freedom build script environment -include scripts/Freedom.mk -include scripts/Package.mk +# Reuse the default target +.PHONY: package +package: all + +.PHONY: regress +regress: all + +.PHONY: cleanup +cleanup: all + +.PHONY: flushup +flushup: all + +# Make uses /bin/sh by default, ignoring the user's value of SHELL. +# Some systems now ship with /bin/sh pointing at dash, and this Makefile +# requires bash +SHELL = /bin/bash + +BINDIR_PREFIX ?= ./ +OBJDIR_PREFIX ?= ./ +BINDIR := $(BINDIR_PREFIX)bin +OBJDIR := $(OBJDIR_PREFIX)obj # The default target .PHONY: all all: - @echo " Makefile targets: *-package *-regress *-cleanup *-flushup clean flush help all" + @echo " Makefile modules: *-*package *-*regress *-*cleanup *-*flushup clean flush help all" .PHONY: help help: @echo "" - @echo " SiFive Freedom Tools - Makefile targets:" + @echo " SiFive Freedom Tools - Makefile modules:" @echo "" - @echo " *-package" + @echo " *-package, *-native-package, *-cross-package" @echo " Build the binary packages for * repo." @echo "" - @echo " *-regress" + @echo " *-regress, *-native-regress, *-cross-regress" @echo " Test the prebuilt packages for * repo." @echo "" - @echo " *-cleanup" + @echo " *-cleanup, *-native-cleanup, *-cross-cleanup" @echo " Clean the build artifacts for * repo." @echo "" - @echo " *-flushup" + @echo " *-flushup, *-native-flushup, *-cross-flushup" @echo " Flush the build artifacts for * repo." @echo "" @echo " clean" - @echo " Remove the src, obj and bin directories." + @echo " Remove the obj and bin directories." @echo "" @echo " flush" @echo " Remove the obj directory." @@ -34,7 +53,7 @@ help: @echo " Show this help." @echo "" @echo " all" - @echo " Show Makefile targets." + @echo " Show Makefile modules." @echo "" @echo " * refers to an item from the package list" @echo " toolchain-metal" @@ -52,12 +71,21 @@ help: @echo "" # Include Makefiles for all modules -include modules/freedom-binutils-metal.mk -include modules/freedom-gcc-metal.mk -include modules/freedom-gdb-metal.mk -include modules/freedom-toolchain-metal.mk -include modules/freedom-qemu.mk -include modules/freedom-sdk-utilities.mk -include modules/freedom-openocd.mk -include modules/freedom-trace-decoder.mk -include modules/freedom-xc3sprog.mk +include modules/freedom-binutils-metal/Monorepo.mk +include modules/freedom-gcc-metal/Monorepo.mk +include modules/freedom-gdb-metal/Monorepo.mk +include modules/freedom-toolchain-metal/Monorepo.mk +include modules/freedom-qemu/Monorepo.mk +include modules/freedom-sdk-utilities/Monorepo.mk +include modules/freedom-openocd/Monorepo.mk +include modules/freedom-trace-decoder/Monorepo.mk +include modules/freedom-xc3sprog/Monorepo.mk + +# Targets that don't build anything +.PHONY: clean +clean:: + rm -rf $(OBJDIR) $(BINDIR) + +.PHONY: flush +flush:: + rm -rf $(OBJDIR) diff --git a/README.md b/README.md index 24d2151..d2a32df 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,35 @@ -SiFive Freedom RISC-V Tools +SiFive Freedom RISC-V Tools for Embedded Development -------- -At SiFive we've been distributing binary release packages of the -tools that target our Freedom RISC-V platforms. This repository -contains the scripts we use to build these tools. - -### The packages: - -* https://github.com/sifive/freedom-toolchain-metal -* https://github.com/sifive/freedom-binutils-metal -* https://github.com/sifive/freedom-gcc-metal -* https://github.com/sifive/freedom-gdb-metal -* https://github.com/sifive/freedom-qemu -* https://github.com/sifive/freedom-sdk-utilities -* https://github.com/sifive/freedom-openocd -* https://github.com/sifive/freedom-trace-decoder -* https://github.com/sifive/freedom-xc3sprog +At SiFive we've been distributing binary release packages of the embedded development +tools that target our Freedom RISC-V platforms. This repository contains the scripts +we use to build these tools. + +### Packages and their contents + +* RISC-V GNU Newlib Toolchain (`riscv64-unknown-elf-*`) + * Binutils + * GCC + * GDB + * Newlib (and nano) + * LibExpat + * Python +* RISC-V OpenOCD (`riscv-openocd-*`) + * OpenOCD + * LibUSB, LibUSB-Compat, LibFTDI +* RISC-V QEMU (`riscv-qemu-*`) + * QEMU (riscv32-softmmu + riscv64-softmmu) + * ZLib, LibFFI, LibIConv, GetText, GLib, LibPNG, JPEG, PixMan +* SDK Utilities (`sdk-utilities-*`) + * DTC (Device Tree Compiler) + * Freedom Elf2Hex + * Spike DASM (Disassembler) +* Trace Decoder (`trace-decoder-*`) + * Trace Decoder + * SWIG, Binutils (bfd, opcodes, liberty, ZLib +* XC3SPROG (`xc3sprog-*`) + * XC3SPROG + * LibUSB, LibUSB-Compat, LibFTDI, LibIConv All the packages has a uniquely named root folder, making it easy to untar/unzip'ing multiple versions next to each other. @@ -40,6 +54,10 @@ On Ubuntu, executing the following command should suffice: $ sudo apt-get install cmake autoconf automake autotools-dev curl libmpc-dev libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo gperf patchutils bc zlib1g-dev libexpat-dev libtool pkg-config mingw-w64 mingw-w64-tools texlive zip python-dev gettext libglib2.0-dev libpixman-1-dev swig ninja-build python3 $ sudo pip3 install meson +On Ubuntu, for cross-building Windows packages you should use [Linuxbrew](https://docs.brew.sh/Homebrew-on-Linux) to install extra dependencies: + + $ brew install mingw-w64 + On OS X, you can use [Homebrew](http://brew.sh) to install most of the dependencies and then you also need [MacTex](http://www.tug.org/mactex/): $ brew install cmake autoconf automake gawk gnu-sed gnu-tar texinfo libtool pkg-config wget xz swig python3 ninja meson diff --git a/modules/freedom-binutils-metal.mk b/modules/freedom-binutils-metal.mk deleted file mode 100644 index a79e441..0000000 --- a/modules/freedom-binutils-metal.mk +++ /dev/null @@ -1,50 +0,0 @@ - -FREEDOM_BINUTILS_METAL_GITURL := git@github.com:sifive/freedom-binutils-metal.git -FREEDOM_BINUTILS_METAL_BRANCH := main -FREEDOM_BINUTILS_METAL_MODULE := $(SRCDIR)/freedom-binutils-metal - -ifneq ($(TARGET_GITURL),) -FREEDOM_BINUTILS_METAL_GITURL := $(TARGET_GITURL) -endif -ifneq ($(TARGET_BRANCH),) -FREEDOM_BINUTILS_METAL_BRANCH := $(TARGET_BRANCH) -endif - -ifneq ($(TOOLCHAIN_BINUTILS_GITURL),) -FREEDOM_BINUTILS_METAL_GITURL := $(TOOLCHAIN_BINUTILS_GITURL) -endif -ifneq ($(TOOLCHAIN_BINUTILS_BRANCH),) -FREEDOM_BINUTILS_METAL_BRANCH := $(TOOLCHAIN_BINUTILS_BRANCH) -endif - -.PHONY: binutils-metal binutils-metal-package binutils-metal-regress binutils-metal-cleanup binutils-metal-flushup -binutils-metal: binutils-metal-package - -.PHONY: binutils-only binutils-only-package binutils-only-regress -binutils-only-package: binutils-metal-package -binutils-only-regress: binutils-metal-regress -binutils-only: binutils-metal - -$(FREEDOM_BINUTILS_METAL_MODULE).$(FREEDOM_BINUTILS_METAL_BRANCH): - mkdir -p $(dir $@) - rm -rf $(FREEDOM_BINUTILS_METAL_MODULE) - rm -rf $(FREEDOM_BINUTILS_METAL_MODULE).* - git clone $(FREEDOM_BINUTILS_METAL_GITURL) $(FREEDOM_BINUTILS_METAL_MODULE) --single-branch -b $(FREEDOM_BINUTILS_METAL_BRANCH) - cd $(FREEDOM_BINUTILS_METAL_MODULE) && git submodule update --init --recursive - date > $@ - -binutils-metal-package: \ - $(FREEDOM_BINUTILS_METAL_MODULE).$(FREEDOM_BINUTILS_METAL_BRANCH) - $(MAKE) -C $(FREEDOM_BINUTILS_METAL_MODULE) package BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) - -binutils-metal-regress: \ - $(FREEDOM_BINUTILS_METAL_MODULE).$(FREEDOM_BINUTILS_METAL_BRANCH) - $(MAKE) -C $(FREEDOM_BINUTILS_METAL_MODULE) regress BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) - -binutils-metal-cleanup: - $(MAKE) -C $(FREEDOM_BINUTILS_METAL_MODULE) cleanup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ - rm -rf $(FREEDOM_BINUTILS_METAL_MODULE).* - rm -rf $(FREEDOM_BINUTILS_METAL_MODULE) - -binutils-metal-flushup: - $(MAKE) -C $(FREEDOM_BINUTILS_METAL_MODULE) flushup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ diff --git a/modules/freedom-binutils-metal/Makefile b/modules/freedom-binutils-metal/Makefile new file mode 100644 index 0000000..d64546b --- /dev/null +++ b/modules/freedom-binutils-metal/Makefile @@ -0,0 +1,122 @@ +# Setup the Freedom build script environment +include ../../scripts/Freedom.mk + +# Include version identifiers to build up the full version string +include Metadata.mk +PACKAGE_WORDING := Bare Metal Binutils +PACKAGE_HEADING := riscv64-unknown-elf-binutils +PACKAGE_VERSION := $(RISCV_BINUTILS_VERSION)-$(FREEDOM_BINUTILS_METAL_ID)$(EXTRA_SUFFIX) +PACKAGE_COMMENT := \# SiFive Freedom Package Properties File + +# Source code directory references +BARE_METAL_TUPLE := riscv64-unknown-elf +BARE_METAL_CC_FOR_TARGET ?= $(BARE_METAL_TUPLE)-gcc +BARE_METAL_CXX_FOR_TARGET ?= $(BARE_METAL_TUPLE)-g++ + +# Some special package configure flags for specific targets +$(WIN64)-binutils-host := --host=$(WIN64) +$(WIN64)-binutils-configure := --with-included-gettext +$(UBUNTU64)-binutils-host := --host=x86_64-linux-gnu +$(UBUNTU64)-binutils-configure := --with-included-gettext +$(DARWIN)-binutils-configure := --with-included-gettext +$(REDHAT)-binutils-configure := --with-included-gettext + +# Setup the package targets and switch into secondary makefile targets +# Targets $(PACKAGE_HEADING)/install.stamp and $(PACKAGE_HEADING)/libs.stamp +include ../../scripts/Package.mk + +$(OBJDIR)/%/build/$(PACKAGE_HEADING)/install.stamp: \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/build-binutils/build.stamp + $(eval $@_TARGET := $(patsubst $(OBJDIR)/%/build/$(PACKAGE_HEADING)/install.stamp,%,$@)) + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/install.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET),$@)) + $(eval $@_PROPERTIES := $(patsubst %/build/$(PACKAGE_HEADING)/install.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET).properties,$@)) + mkdir -p $(dir $@) + git log --format="[%ad] %s" > $(abspath $($@_INSTALL))/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET).changelog + rm -f $(abspath $($@_PROPERTIES)) + echo "$(PACKAGE_COMMENT)" > $(abspath $($@_PROPERTIES)) + echo "PACKAGE_TYPE = freedom-tools" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_DESC_SEG = $(PACKAGE_WORDING)" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_FIXED_ID = $(PACKAGE_HEADING)" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_BUILD_ID = $(FREEDOM_BINUTILS_METAL_ID)$(EXTRA_SUFFIX)" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_CORE_VER = $(RISCV_BINUTILS_VERSION)" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_TARGET = $($@_TARGET)" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_VENDOR = SiFive" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_RIGHTS = sifive-v00 eclipse-v20" >> $(abspath $($@_PROPERTIES)) + echo "RISCV_TAGS = $(FREEDOM_BINUTILS_METAL_RISCV_TAGS)" >> $(abspath $($@_PROPERTIES)) + echo "TOOLS_TAGS = $(FREEDOM_BINUTILS_METAL_TOOLS_TAGS)" >> $(abspath $($@_PROPERTIES)) + cp $(abspath $($@_PROPERTIES)) $(abspath $($@_INSTALL))/ + tclsh ../../scripts/check-maximum-path-length.tcl $(abspath $($@_INSTALL)) "$(PACKAGE_HEADING)" "$(RISCV_BINUTILS_VERSION)" "$(FREEDOM_BINUTILS_METAL_ID)$(EXTRA_SUFFIX)" + tclsh ../../scripts/check-same-name-different-case.tcl $(abspath $($@_INSTALL)) + echo $(PATH) + date > $@ + +# We might need some extra target libraries for this package +$(OBJ_NATIVE)/build/$(PACKAGE_HEADING)/libs.stamp: \ + $(OBJ_NATIVE)/build/$(PACKAGE_HEADING)/install.stamp + date > $@ + +$(OBJ_WIN64)/build/$(PACKAGE_HEADING)/libs.stamp: \ + $(OBJ_WIN64)/build/$(PACKAGE_HEADING)/install.stamp + -$(WIN64)-gcc -print-search-dirs | grep ^programs | cut -d= -f2- | tr : "\n" | xargs -I {} find {} -iname "libwinpthread*.dll" | xargs cp -t $(OBJDIR)/$(WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64)/bin + -$(WIN64)-gcc -print-search-dirs | grep ^libraries | cut -d= -f2- | tr : "\n" | xargs -I {} find {} -iname "libgcc_s_seh*.dll" | xargs cp -t $(OBJDIR)/$(WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64)/bin + -$(WIN64)-gcc -print-search-dirs | grep ^libraries | cut -d= -f2- | tr : "\n" | xargs -I {} find {} -iname "libstdc*.dll" | xargs cp -t $(OBJDIR)/$(WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64)/bin + -$(WIN64)-gcc -print-search-dirs | grep ^libraries | cut -d= -f2- | tr : "\n" | xargs -I {} find {} -iname "libssp*.dll" | xargs cp -t $(OBJDIR)/$(WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64)/bin + date > $@ + +$(OBJDIR)/%/build/$(PACKAGE_HEADING)/source.stamp: + $(eval $@_TARGET := $(patsubst $(OBJDIR)/%/build/$(PACKAGE_HEADING)/source.stamp,%,$@)) + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/source.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET),$@)) + $(eval $@_BUILDLOG := $(abspath $(patsubst %/build/$(PACKAGE_HEADING)/source.stamp,%/buildlog/$(PACKAGE_HEADING),$@))) + $(eval $@_SRCBALL := $(abspath $(BINDIR)/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET).src.tar.gz)) + tclsh ../../scripts/check-naming-and-version-syntax.tcl "$(PACKAGE_WORDING)" "$(PACKAGE_HEADING)" "$(RISCV_BINUTILS_VERSION)" "$(FREEDOM_BINUTILS_METAL_ID)$(EXTRA_SUFFIX)" + rm -rf $($@_INSTALL) + mkdir -p $($@_INSTALL) + rm -rf $($@_BUILDLOG) + mkdir -p $($@_BUILDLOG) + rm -rf $(dir $@) + mkdir -p $(dir $@) + git log > $($@_BUILDLOG)/$(PACKAGE_HEADING)-git-commit.log + git remote -v > $($@_BUILDLOG)/$(PACKAGE_HEADING)-git-remote.log + git clone --single-branch --branch $(RISCV_BINUTILS_BRANCH) $(RISCV_BINUTILS_GITURL) $(dir $@)/$(RISCV_BINUTILS_FOLDER) + cd $(dir $@)/$(RISCV_BINUTILS_FOLDER) && git checkout --detach $(RISCV_BINUTILS_COMMIT) + cd $(dir $@)/$(RISCV_BINUTILS_FOLDER) && git submodule update --init --recursive + mkdir -p $(dir $($@_SRCBALL)) + cd $(dir $@); $(TAR) --dereference --hard-dereference -c $(RISCV_BINUTILS_FOLDER) | gzip > $($@_SRCBALL) + date > $@ + +# Reusing binutils build script across binutils-metal, gcc-metal and trace-decoder +include scripts/build_binutils_target.mk + +$(OBJDIR)/%/build/$(PACKAGE_HEADING)/build-binutils/build.stamp: \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/build-binutils/support.stamp + $(eval $@_TARGET := $(patsubst $(OBJDIR)/%/build/$(PACKAGE_HEADING)/build-binutils/build.stamp,%,$@)) + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/build-binutils/build.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET),$@)) + $(eval $@_BUILDLOG := $(abspath $(patsubst %/build/$(PACKAGE_HEADING)/build-binutils/build.stamp,%/buildlog/$(PACKAGE_HEADING),$@))) + $(MAKE) -C $(dir $@) -j1 install install-pdf install-html &>$($@_BUILDLOG)/build-binutils-make-install.log + tclsh ../../scripts/dyn-lib-check-$($@_TARGET).tcl $(abspath $($@_INSTALL))/bin/riscv64-unknown-elf-addr2line + tclsh ../../scripts/dyn-lib-check-$($@_TARGET).tcl $(abspath $($@_INSTALL))/bin/riscv64-unknown-elf-ar + tclsh ../../scripts/dyn-lib-check-$($@_TARGET).tcl $(abspath $($@_INSTALL))/bin/riscv64-unknown-elf-as + tclsh ../../scripts/dyn-lib-check-$($@_TARGET).tcl $(abspath $($@_INSTALL))/bin/riscv64-unknown-elf-c++filt + tclsh ../../scripts/dyn-lib-check-$($@_TARGET).tcl $(abspath $($@_INSTALL))/bin/riscv64-unknown-elf-elfedit + tclsh ../../scripts/dyn-lib-check-$($@_TARGET).tcl $(abspath $($@_INSTALL))/bin/riscv64-unknown-elf-gprof + tclsh ../../scripts/dyn-lib-check-$($@_TARGET).tcl $(abspath $($@_INSTALL))/bin/riscv64-unknown-elf-ld + tclsh ../../scripts/dyn-lib-check-$($@_TARGET).tcl $(abspath $($@_INSTALL))/bin/riscv64-unknown-elf-ld.bfd + tclsh ../../scripts/dyn-lib-check-$($@_TARGET).tcl $(abspath $($@_INSTALL))/bin/riscv64-unknown-elf-nm + tclsh ../../scripts/dyn-lib-check-$($@_TARGET).tcl $(abspath $($@_INSTALL))/bin/riscv64-unknown-elf-objcopy + tclsh ../../scripts/dyn-lib-check-$($@_TARGET).tcl $(abspath $($@_INSTALL))/bin/riscv64-unknown-elf-objdump + tclsh ../../scripts/dyn-lib-check-$($@_TARGET).tcl $(abspath $($@_INSTALL))/bin/riscv64-unknown-elf-ranlib + tclsh ../../scripts/dyn-lib-check-$($@_TARGET).tcl $(abspath $($@_INSTALL))/bin/riscv64-unknown-elf-readelf + tclsh ../../scripts/dyn-lib-check-$($@_TARGET).tcl $(abspath $($@_INSTALL))/bin/riscv64-unknown-elf-size + tclsh ../../scripts/dyn-lib-check-$($@_TARGET).tcl $(abspath $($@_INSTALL))/bin/riscv64-unknown-elf-strings + tclsh ../../scripts/dyn-lib-check-$($@_TARGET).tcl $(abspath $($@_INSTALL))/bin/riscv64-unknown-elf-strip + date > $@ + +$(OBJDIR)/$(NATIVE)/test/$(PACKAGE_HEADING)/test.stamp: \ + $(OBJDIR)/$(NATIVE)/test/$(PACKAGE_HEADING)/launch.stamp + mkdir -p $(dir $@) + PATH=$(abspath $(OBJDIR)/$(NATIVE)/launch/$(PACKAGE_TARNAME)/bin):$(PATH) riscv64-unknown-elf-ld -v + PATH=$(abspath $(OBJDIR)/$(NATIVE)/launch/$(PACKAGE_TARNAME)/bin):$(PATH) riscv64-unknown-elf-objdump -v + PATH=$(abspath $(OBJDIR)/$(NATIVE)/launch/$(PACKAGE_TARNAME)/bin):$(PATH) riscv64-unknown-elf-readelf -v + PATH=$(abspath $(OBJDIR)/$(NATIVE)/launch/$(PACKAGE_TARNAME)/bin):$(PATH) riscv64-unknown-elf-size -v + @echo "Finished testing $(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(NATIVE).tar.gz tarball" + date > $@ diff --git a/modules/freedom-binutils-metal/Metadata.mk b/modules/freedom-binutils-metal/Metadata.mk new file mode 100644 index 0000000..5178893 --- /dev/null +++ b/modules/freedom-binutils-metal/Metadata.mk @@ -0,0 +1,8 @@ +include ../../scripts/base_binutils_metadata.mk + +# Customization ID, which should identify the customization added to the original by SiFive +FREEDOM_BINUTILS_METAL_ID := $(FREEDOM_BINUTILS_ID) + +# Characteristic tags, which should be usable for matching up providers and consumers +FREEDOM_BINUTILS_METAL_RISCV_TAGS := $(FREEDOM_BINUTILS_RISCV_TAGS) +FREEDOM_BINUTILS_METAL_TOOLS_TAGS := $(FREEDOM_BINUTILS_TAG_PREFIX)-metal diff --git a/modules/freedom-binutils-metal/Monorepo.mk b/modules/freedom-binutils-metal/Monorepo.mk new file mode 100644 index 0000000..e0e834b --- /dev/null +++ b/modules/freedom-binutils-metal/Monorepo.mk @@ -0,0 +1,42 @@ +.PHONY: binutils-metal binutils-metal-package binutils-metal-native-package binutils-metal-cross-package +.PHONY: binutils-metal-regress +.PHONY: binutils-metal-cleanup binutils-metal-native-cleanup binutils-metal-cross-cleanup +.PHONY: binutils-metal-flushup binutils-metal-native-flushup binutils-metal-cross-flushup +binutils-metal: binutils-metal-package + +.PHONY: binutils-only binutils-only-package binutils-only-native-package binutils-only-cross-package binutils-only-regress +binutils-only-package: binutils-metal-package +binutils-only-native-package: binutils-metal-native-package +binutils-only-cross-package: binutils-metal-cross-package +binutils-only-regress: binutils-metal-regress +binutils-only: binutils-metal + +binutils-metal-package: + $(MAKE) -C modules/freedom-binutils-metal package BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) + +binutils-metal-native-package: + $(MAKE) -C modules/freedom-binutils-metal native-package BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) + +binutils-metal-cross-package: + $(MAKE) -C modules/freedom-binutils-metal cross-package BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) + +binutils-metal-regress: + $(MAKE) -C modules/freedom-binutils-metal regress BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) + +binutils-metal-cleanup: + $(MAKE) -C modules/freedom-binutils-metal cleanup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + +binutils-metal-native-cleanup: + $(MAKE) -C modules/freedom-binutils-metal native-cleanup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + +binutils-metal-cross-cleanup: + $(MAKE) -C modules/freedom-binutils-metal cross-cleanup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + +binutils-metal-flushup: + $(MAKE) -C modules/freedom-binutils-metal flushup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + +binutils-metal-native-flushup: + $(MAKE) -C modules/freedom-binutils-metal native-flushup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + +binutils-metal-cross-flushup: + $(MAKE) -C modules/freedom-binutils-metal cross-flushup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ diff --git a/modules/freedom-binutils-metal/scripts/build_binutils_target.mk b/modules/freedom-binutils-metal/scripts/build_binutils_target.mk new file mode 100644 index 0000000..1f45ec3 --- /dev/null +++ b/modules/freedom-binutils-metal/scripts/build_binutils_target.mk @@ -0,0 +1,35 @@ +# Reused binutils build script across binutils-metal, gcc-metal and trace-decoder +$(OBJDIR)/%/build/$(PACKAGE_HEADING)/build-binutils/support.stamp: \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/source.stamp + $(eval $@_TARGET := $(patsubst $(OBJDIR)/%/build/$(PACKAGE_HEADING)/build-binutils/support.stamp,%,$@)) + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/build-binutils/support.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET),$@)) + $(eval $@_BUILD := $(patsubst %/build/$(PACKAGE_HEADING)/build-binutils/support.stamp,%/build/$(PACKAGE_HEADING),$@)) + $(eval $@_BUILDLOG := $(abspath $(patsubst %/build/$(PACKAGE_HEADING)/build-binutils/support.stamp,%/buildlog/$(PACKAGE_HEADING),$@))) + rm -rf $(dir $@) + mkdir -p $(dir $@) + # Workaround for CentOS random build fail issue + # + # Corresponding bugzilla entry on upstream: + # https://sourceware.org/bugzilla/show_bug.cgi?id=22941 + touch $(abspath $($@_BUILD))/$(RISCV_BINUTILS_FOLDER)/intl/plural.c +# CC_FOR_TARGET is required for the ld testsuite. + cd $(dir $@) && CC_FOR_TARGET=$(BARE_METAL_CC_FOR_TARGET) $(abspath $($@_BUILD))/$(RISCV_BINUTILS_FOLDER)/configure \ + --target=$(BARE_METAL_TUPLE) \ + $($($@_TARGET)-binutils-host) \ + --prefix=$(abspath $($@_INSTALL)) \ + --with-pkgversion="SiFive Binutils-Metal $(PACKAGE_VERSION)" \ + --with-bugurl="https://github.com/sifive/freedom-tools/issues" \ + --disable-werror \ + --disable-gdb \ + --disable-sim \ + --disable-libdecnumber \ + --disable-libreadline \ + --with-expat=no \ + --with-mpc=no \ + --with-mpfr=no \ + --with-gmp=no \ + $($($@_TARGET)-binutils-configure) \ + CFLAGS="-O2" \ + CXXFLAGS="-O2" &>$($@_BUILDLOG)/build-binutils-make-configure.log + $(MAKE) -C $(dir $@) &>$($@_BUILDLOG)/build-binutils-make-build.log + date > $@ diff --git a/modules/freedom-binutils-metal/scripts/extra_binutils_target.mk b/modules/freedom-binutils-metal/scripts/extra_binutils_target.mk new file mode 100644 index 0000000..a538cd5 --- /dev/null +++ b/modules/freedom-binutils-metal/scripts/extra_binutils_target.mk @@ -0,0 +1,33 @@ +$(OBJ_WIN64)/build/$(PACKAGE_HEADING)/extra-binutils/transit.stamp: \ + $(OBJ_WIN64)/build/$(PACKAGE_HEADING)/source.stamp + $(eval $@_EXTRA := $(patsubst %/build/$(PACKAGE_HEADING)/extra-binutils/transit.stamp,%/build/$(PACKAGE_HEADING)/extra-install,$@)) + $(eval $@_BUILD := $(patsubst %/build/$(PACKAGE_HEADING)/extra-binutils/transit.stamp,%/build/$(PACKAGE_HEADING),$@)) + $(eval $@_BUILDLOG := $(abspath $(patsubst %/build/$(PACKAGE_HEADING)/extra-binutils/transit.stamp,%/buildlog/$(PACKAGE_HEADING),$@))) + rm -rf $(dir $@) + mkdir -p $(dir $@) + # Workaround for CentOS random build fail issue + # + # Corresponding bugzilla entry on upstream: + # https://sourceware.org/bugzilla/show_bug.cgi?id=22941 + touch $(abspath $($@_BUILD))/$(RISCV_BINUTILS_FOLDER)/intl/plural.c +# CC_FOR_TARGET is required for the ld testsuite. + cd $(dir $@) && CC_FOR_TARGET=$(BARE_METAL_CC_FOR_TARGET) $(abspath $($@_BUILD))/$(RISCV_BINUTILS_FOLDER)/configure \ + --target=$(BARE_METAL_TUPLE) \ + $($(NATIVE)-binutils-host) \ + --prefix=$(abspath $($@_EXTRA)) \ + --with-pkgversion="SiFive Binutils-Metal $(PACKAGE_VERSION)" \ + --with-bugurl="https://github.com/sifive/freedom-tools/issues" \ + --disable-werror \ + --disable-gdb \ + --disable-sim \ + --disable-libdecnumber \ + --disable-libreadline \ + --with-expat=no \ + --with-mpc=no \ + --with-mpfr=no \ + --with-gmp=no \ + $($(NATIVE)-binutils-configure) \ + CFLAGS="-O2" \ + CXXFLAGS="-O2" &>$($@_BUILDLOG)/extra-binutils-make-configure.log + $(MAKE) -C $(dir $@) &>$($@_BUILDLOG)/extra-binutils-make-build.log + date > $@ diff --git a/modules/freedom-gcc-metal.mk b/modules/freedom-gcc-metal.mk deleted file mode 100644 index 270bd33..0000000 --- a/modules/freedom-gcc-metal.mk +++ /dev/null @@ -1,50 +0,0 @@ - -FREEDOM_GCC_METAL_GITURL := git@github.com:sifive/freedom-gcc-metal.git -FREEDOM_GCC_METAL_BRANCH := main -FREEDOM_GCC_METAL_MODULE := $(SRCDIR)/freedom-gcc-metal - -ifneq ($(TARGET_GITURL),) -FREEDOM_GCC_METAL_GITURL := $(TARGET_GITURL) -endif -ifneq ($(TARGET_BRANCH),) -FREEDOM_GCC_METAL_BRANCH := $(TARGET_BRANCH) -endif - -ifneq ($(TOOLCHAIN_GCC_GITURL),) -FREEDOM_GCC_METAL_GITURL := $(TOOLCHAIN_GCC_GITURL) -endif -ifneq ($(TOOLCHAIN_GCC_BRANCH),) -FREEDOM_GCC_METAL_BRANCH := $(TOOLCHAIN_GCC_BRANCH) -endif - -.PHONY: gcc-metal gcc-metal-package gcc-metal-regress gcc-metal-cleanup gcc-metal-flushup -gcc-metal: gcc-metal-package - -.PHONY: gcc-only gcc-only-package gcc-only-regress -gcc-only-package: gcc-metal-package -gcc-only-regress: gcc-metal-regress -gcc-only: gcc-metal - -$(FREEDOM_GCC_METAL_MODULE).$(FREEDOM_GCC_METAL_BRANCH): - mkdir -p $(dir $@) - rm -rf $(FREEDOM_GCC_METAL_MODULE) - rm -rf $(FREEDOM_GCC_METAL_MODULE).* - git clone $(FREEDOM_GCC_METAL_GITURL) $(FREEDOM_GCC_METAL_MODULE) --single-branch -b $(FREEDOM_GCC_METAL_BRANCH) - cd $(FREEDOM_GCC_METAL_MODULE) && git submodule update --init --recursive - date > $@ - -gcc-metal-package: \ - $(FREEDOM_GCC_METAL_MODULE).$(FREEDOM_GCC_METAL_BRANCH) - $(MAKE) -C $(FREEDOM_GCC_METAL_MODULE) package BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) - -gcc-metal-regress: \ - $(FREEDOM_GCC_METAL_MODULE).$(FREEDOM_GCC_METAL_BRANCH) - $(MAKE) -C $(FREEDOM_GCC_METAL_MODULE) regress BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) - -gcc-metal-cleanup: - $(MAKE) -C $(FREEDOM_GCC_METAL_MODULE) cleanup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ - rm -rf $(FREEDOM_GCC_METAL_MODULE).* - rm -rf $(FREEDOM_GCC_METAL_MODULE) - -gcc-metal-flushup: - $(MAKE) -C $(FREEDOM_GCC_METAL_MODULE) flushup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ diff --git a/modules/freedom-gcc-metal/Makefile b/modules/freedom-gcc-metal/Makefile new file mode 100644 index 0000000..2e86006 --- /dev/null +++ b/modules/freedom-gcc-metal/Makefile @@ -0,0 +1,464 @@ +# Setup the Freedom build script environment +include ../../scripts/Freedom.mk + +# Include version identifiers to build up the full version string +include Metadata.mk +PACKAGE_WORDING := Bare Metal GCC +PACKAGE_HEADING := riscv64-unknown-elf-gcc +PACKAGE_VERSION := $(RISCV_GCC_VERSION)-$(FREEDOM_GCC_METAL_ID)$(EXTRA_SUFFIX) +PACKAGE_COMMENT := \# SiFive Freedom Package Properties File + +# Source code directory references +BARE_METAL_ABI := lp64d +BARE_METAL_ARCH := rv64imafdc +BARE_METAL_CMODEL := medany +BARE_METAL_TUPLE := riscv64-unknown-elf +BARE_METAL_CC_FOR_TARGET ?= $(BARE_METAL_TUPLE)-gcc +BARE_METAL_CXX_FOR_TARGET ?= $(BARE_METAL_TUPLE)-g++ +BARE_METAL_CFLAGS_FOR_TARGET := -mcmodel=$(BARE_METAL_CMODEL) +BARE_METAL_CXXFLAGS_FOR_TARGET := -mcmodel=$(BARE_METAL_CMODEL) + +ifeq ($(EXTRA_OPTION),minimal) +BARE_METAL_MULTILIBS_GEN := \ + rv32emac-ilp32e-- \ + rv32imac-ilp32-- \ + rv32imafc-ilp32f-- \ + rv32imafdc-ilp32d-- \ + rv64imac-lp64-- \ + rv64imafc-lp64f-- \ + rv64imafdc-lp64d-- \ + --cmodel=compact +else ifeq ($(EXTRA_OPTION),basic) +BARE_METAL_MULTILIBS_GEN := \ + rv32e-ilp32e-- \ + rv32emac-ilp32e-- \ + rv32i-ilp32-- \ + rv32imac-ilp32-- \ + rv32if-ilp32f-- \ + rv32imafc-ilp32f-- \ + rv32ifd-ilp32d-- \ + rv32imafdc-ilp32d-- \ + rv64i-lp64-- \ + rv64imac-lp64-- \ + rv64if-lp64f-- \ + rv64imafc-lp64f-- \ + rv64ifd-lp64d-- \ + rv64imafdc-lp64d-- \ + --cmodel=compact +else +BARE_METAL_MULTILIBS_GEN := \ + rv32ec-ilp32e-- \ + rv32ec_zba_zbb-ilp32e-- \ + rv32eac-ilp32e-- \ + rv32eac_zba_zbb-ilp32e-- \ + rv32emc-ilp32e-- \ + rv32emc_zba_zbb-ilp32e-- \ + rv32emac-ilp32e-- \ + rv32emac_zba_zbb-ilp32e-- \ + rv32ic-ilp32-- \ + rv32ic_zba_zbb-ilp32-- \ + rv32iac-ilp32-- \ + rv32iac_zba_zbb-ilp32-- \ + rv32imc-ilp32-- \ + rv32imc_zba_zbb-ilp32-- \ + rv32imac-ilp32-- \ + rv32imac_zba_zbb-ilp32-- \ + rv32imfc-ilp32f-- \ + rv32imfc_zba_zbb-ilp32f-- \ + rv32imafc-ilp32f-- \ + rv32imafc_zba_zbb-ilp32f-- \ + rv32imfdc-ilp32d-- \ + rv32imfdc_zba_zbb-ilp32d-- \ + rv32imafdc-ilp32d-- \ + rv32imafdc_zba_zbb-ilp32d-- \ + rv64ic-lp64-- \ + rv64ic_zba_zbb-lp64-- \ + rv64iac-lp64-- \ + rv64iac_zba_zbb-lp64-- \ + rv64imc-lp64-- \ + rv64imc_zba_zbb-lp64-- \ + rv64imac-lp64-- \ + rv64imac_zba_zbb-lp64-- \ + rv64imfc-lp64f-- \ + rv64imfc_zba_zbb-lp64f-- \ + rv64imafc-lp64f-- \ + rv64imafc_zba_zbb-lp64f-- \ + rv64imfdc-lp64d-- \ + rv64imfdc_zba_zbb-lp64d-- \ + rv64imafdc-lp64d-- \ + rv64imafdc_zba_zbb-lp64d-- \ + --cmodel=compact +endif + +# Some special package configure flags for specific targets +$(WIN64)-binutils-host := --host=$(WIN64) +$(WIN64)-binutils-configure := --with-included-gettext +$(WIN64)-gcc-host := --host=$(WIN64) +$(WIN64)-gcc-configure := --without-system-zlib +$(UBUNTU64)-binutils-host := --host=x86_64-linux-gnu +$(UBUNTU64)-binutils-configure := --with-included-gettext +$(UBUNTU64)-gcc-host := --host=x86_64-linux-gnu +$(UBUNTU64)-gcc-configure := --with-system-zlib +$(DARWIN)-binutils-configure := --with-included-gettext +$(DARWIN)-gcc-configure := --with-system-zlib +$(REDHAT)-binutils-configure := --with-included-gettext +$(REDHAT)-gcc-configure := --with-system-zlib + +# Setup the package targets and switch into secondary makefile targets +# Targets $(PACKAGE_HEADING)/install.stamp and $(PACKAGE_HEADING)/libs.stamp +include ../../scripts/Package.mk + +# The package build needs the tools in the PATH, and the windows build might use the ubuntu (native) +PATH := $(abspath $(OBJ_WIN64)/build/$(PACKAGE_HEADING)/extra-install/bin):$(PATH) +export PATH + +$(OBJDIR)/%/build/$(PACKAGE_HEADING)/install.stamp: \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/build-gcc-stage2/build.stamp + $(eval $@_TARGET := $(patsubst $(OBJDIR)/%/build/$(PACKAGE_HEADING)/install.stamp,%,$@)) + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/install.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET),$@)) + $(eval $@_PROPERTIES := $(patsubst %/build/$(PACKAGE_HEADING)/install.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET).properties,$@)) + $(eval $@_BUILD := $(patsubst %/build/$(PACKAGE_HEADING)/install.stamp,%/build/$(PACKAGE_HEADING),$@)) + $(eval $@_BUILDLOG := $(abspath $(patsubst %/build/$(PACKAGE_HEADING)/install.stamp,%/buildlog/$(PACKAGE_HEADING),$@))) + mkdir -p $(dir $@) + git log --format="[%ad] %s" > $(abspath $($@_INSTALL))/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET).changelog + rm -f $(abspath $($@_PROPERTIES)) + echo "$(PACKAGE_COMMENT)" > $(abspath $($@_PROPERTIES)) + echo "PACKAGE_TYPE = freedom-tools" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_DESC_SEG = $(PACKAGE_WORDING)" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_FIXED_ID = $(PACKAGE_HEADING)" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_BUILD_ID = $(FREEDOM_GCC_METAL_ID)$(EXTRA_SUFFIX)" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_CORE_VER = $(RISCV_GCC_VERSION)" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_TARGET = $($@_TARGET)" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_VENDOR = SiFive" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_RIGHTS = sifive-v00 eclipse-v20" >> $(abspath $($@_PROPERTIES)) + echo "RISCV_TAGS = $(FREEDOM_GCC_METAL_RISCV_TAGS)" >> $(abspath $($@_PROPERTIES)) + echo "TOOLS_TAGS = $(FREEDOM_GCC_METAL_TOOLS_TAGS)" >> $(abspath $($@_PROPERTIES)) + cp $(abspath $($@_PROPERTIES)) $(abspath $($@_INSTALL))/ + tclsh ../../scripts/check-maximum-path-length.tcl $(abspath $($@_INSTALL)) "$(PACKAGE_HEADING)" "$(RISCV_GCC_VERSION)" "$(FREEDOM_GCC_METAL_ID)$(EXTRA_SUFFIX)" + tclsh ../../scripts/check-same-name-different-case.tcl $(abspath $($@_INSTALL)) + rm -rf $(abspath $($@_BUILD))/install-gcc + cp -a $(abspath $($@_INSTALL)) $(abspath $($@_BUILD))/install-gcc + cat $($@_BUILDLOG)/install-binutils-file-list | xargs rm -rf + echo $(PATH) + date > $@ + +# We might need some extra target libraries for this package +$(OBJ_NATIVE)/build/$(PACKAGE_HEADING)/libs.stamp: \ + $(OBJ_NATIVE)/build/$(PACKAGE_HEADING)/install.stamp + date > $@ + +$(OBJ_WIN64)/build/$(PACKAGE_HEADING)/libs.stamp: \ + $(OBJ_WIN64)/build/$(PACKAGE_HEADING)/install.stamp + -$(WIN64)-gcc -print-search-dirs | grep ^programs | cut -d= -f2- | tr : "\n" | xargs -I {} find {} -iname "libwinpthread*.dll" | xargs cp -t $(OBJDIR)/$(WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64)/bin + -$(WIN64)-gcc -print-search-dirs | grep ^libraries | cut -d= -f2- | tr : "\n" | xargs -I {} find {} -iname "libgcc_s_seh*.dll" | xargs cp -t $(OBJDIR)/$(WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64)/bin + -$(WIN64)-gcc -print-search-dirs | grep ^libraries | cut -d= -f2- | tr : "\n" | xargs -I {} find {} -iname "libstdc*.dll" | xargs cp -t $(OBJDIR)/$(WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64)/bin + -$(WIN64)-gcc -print-search-dirs | grep ^libraries | cut -d= -f2- | tr : "\n" | xargs -I {} find {} -iname "libssp*.dll" | xargs cp -t $(OBJDIR)/$(WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64)/bin + date > $@ + +$(OBJDIR)/%/build/$(PACKAGE_HEADING)/source.stamp: + $(eval $@_TARGET := $(patsubst $(OBJDIR)/%/build/$(PACKAGE_HEADING)/source.stamp,%,$@)) + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/source.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET),$@)) + $(eval $@_BUILDLOG := $(abspath $(patsubst %/build/$(PACKAGE_HEADING)/source.stamp,%/buildlog/$(PACKAGE_HEADING),$@))) + $(eval $@_SRCBALL := $(abspath $(BINDIR)/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET).src.tar.gz)) + tclsh ../../scripts/check-naming-and-version-syntax.tcl "$(PACKAGE_WORDING)" "$(PACKAGE_HEADING)" "$(RISCV_GCC_VERSION)" "$(FREEDOM_GCC_METAL_ID)$(EXTRA_SUFFIX)" + rm -rf $($@_INSTALL) + mkdir -p $($@_INSTALL) + rm -rf $($@_BUILDLOG) + mkdir -p $($@_BUILDLOG) + rm -rf $(dir $@) + mkdir -p $(dir $@) + git log > $($@_BUILDLOG)/$(PACKAGE_HEADING)-git-commit.log + git remote -v > $($@_BUILDLOG)/$(PACKAGE_HEADING)-git-remote.log + git clone --single-branch --branch $(RISCV_BINUTILS_BRANCH) $(RISCV_BINUTILS_GITURL) $(dir $@)/$(RISCV_BINUTILS_FOLDER) + cd $(dir $@)/$(RISCV_BINUTILS_FOLDER) && git checkout --detach $(RISCV_BINUTILS_COMMIT) + cd $(dir $@)/$(RISCV_BINUTILS_FOLDER) && git submodule update --init --recursive + git clone --single-branch --branch $(RISCV_GCC_BRANCH) $(RISCV_GCC_GITURL) $(dir $@)/$(RISCV_GCC_FOLDER) + cd $(dir $@)/$(RISCV_GCC_FOLDER) && git checkout --detach $(RISCV_GCC_COMMIT) + cd $(dir $@)/$(RISCV_GCC_FOLDER) && git submodule update --init --recursive + git clone --single-branch --branch $(RISCV_NEWLIB_BRANCH) $(RISCV_NEWLIB_GITURL) $(dir $@)/$(RISCV_NEWLIB_FOLDER) + cd $(dir $@)/$(RISCV_NEWLIB_FOLDER) && git checkout --detach $(RISCV_NEWLIB_COMMIT) + cd $(dir $@)/$(RISCV_NEWLIB_FOLDER) && git submodule update --init --recursive + cd $(dir $@)/riscv-gcc; ./contrib/download_prerequisites + cd $(dir $@)/riscv-gcc/gcc/config/riscv; rm t-elf-multilib; ./multilib-generator $(BARE_METAL_MULTILIBS_GEN) > t-elf-multilib + cp $(dir $@)/riscv-gcc/gcc/config/riscv/t-elf-multilib $($@_BUILDLOG)/riscv-gcc-t-elf-multilib + mkdir -p $(dir $($@_SRCBALL)) + cd $(dir $@); $(TAR) --dereference --hard-dereference -c $(RISCV_BINUTILS_FOLDER) $(RISCV_GCC_FOLDER) $(RISCV_NEWLIB_FOLDER) | gzip > $($@_SRCBALL) + date > $@ + +# Reusing binutils build script across binutils-metal, gcc-metal and trace-decoder +include ../freedom-binutils-metal/scripts/build_binutils_target.mk +include ../freedom-binutils-metal/scripts/extra_binutils_target.mk + +$(OBJ_WIN64)/build/$(PACKAGE_HEADING)/extra-binutils/extra.stamp: \ + $(OBJ_WIN64)/build/$(PACKAGE_HEADING)/extra-binutils/transit.stamp + $(eval $@_EXTRA := $(patsubst %/build/$(PACKAGE_HEADING)/extra-binutils/extra.stamp,%/build/$(PACKAGE_HEADING)/extra-install,$@)) + $(eval $@_BUILDLOG := $(abspath $(patsubst %/build/$(PACKAGE_HEADING)/extra-binutils/extra.stamp,%/buildlog/$(PACKAGE_HEADING),$@))) + $(MAKE) -C $(dir $@) -j1 install &>$($@_BUILDLOG)/extra-binutils-make-install.log + date > $@ + +$(OBJ_WIN64)/build/$(PACKAGE_HEADING)/extra-gcc-stage1/extra.stamp: \ + $(OBJ_WIN64)/build/$(PACKAGE_HEADING)/extra-binutils/extra.stamp + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/extra-gcc-stage1/extra.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64),$@)) + $(eval $@_EXTRA := $(patsubst %/build/$(PACKAGE_HEADING)/extra-gcc-stage1/extra.stamp,%/build/$(PACKAGE_HEADING)/extra-install,$@)) + $(eval $@_BUILD := $(patsubst %/build/$(PACKAGE_HEADING)/extra-gcc-stage1/extra.stamp,%/build/$(PACKAGE_HEADING),$@)) + $(eval $@_BUILDLOG := $(abspath $(patsubst %/build/$(PACKAGE_HEADING)/extra-gcc-stage1/extra.stamp,%/buildlog/$(PACKAGE_HEADING),$@))) + rm -rf $(dir $@) + mkdir -p $(dir $@) + # Workaround for CentOS random build fail issue + # + # Corresponding bugzilla entry on upstream: + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92008 + touch $(abspath $($@_BUILD))/riscv-gcc/intl/plural.c + cd $(dir $@) && $(abspath $($@_BUILD))/riscv-gcc/configure \ + --target=$(BARE_METAL_TUPLE) \ + $($(NATIVE)-gcc-host) \ + --prefix=$(abspath $($@_EXTRA)) \ + --with-pkgversion="SiFive GCC-Metal $(PACKAGE_VERSION)" \ + --with-bugurl="https://github.com/sifive/freedom-tools/issues" \ + --disable-shared \ + --disable-threads \ + --disable-tls \ + --enable-languages=c,c++ \ + --with-newlib \ + --with-sysroot=$(abspath $($@_EXTRA))/$(BARE_METAL_TUPLE) \ + --disable-libmudflap \ + --disable-libssp \ + --disable-libquadmath \ + --disable-libgomp \ + --disable-nls \ + --disable-tm-clone-registry \ + --src=../riscv-gcc \ + $($(NATIVE)-gcc-configure) \ + --enable-checking=yes \ + --enable-multilib \ + --with-abi=$(BARE_METAL_ABI) \ + --with-arch=$(BARE_METAL_ARCH) \ + CFLAGS="-O2" \ + CXXFLAGS="-O2" \ + CFLAGS_FOR_TARGET="-Os $(BARE_METAL_CFLAGS_FOR_TARGET)" \ + CXXFLAGS_FOR_TARGET="-Os $(BARE_METAL_CXXFLAGS_FOR_TARGET)" &>$($@_BUILDLOG)/extra-gcc-stage1-make-configure.log + $(MAKE) -C $(dir $@) all-gcc &>$($@_BUILDLOG)/extra-gcc-stage1-make-build.log + $(MAKE) -C $(dir $@) -j1 install-gcc &>$($@_BUILDLOG)/extra-gcc-stage1-make-install.log + mkdir -p $(abspath $($@_INSTALL))/$(BARE_METAL_TUPLE)/include + rm -rf $(abspath $($@_EXTRA))/$(BARE_METAL_TUPLE)/include + ln -s $(abspath $($@_INSTALL))/$(BARE_METAL_TUPLE)/include $(abspath $($@_EXTRA))/$(BARE_METAL_TUPLE)/include + mkdir -p $(abspath $($@_INSTALL))/$(BARE_METAL_TUPLE)/lib + rm -rf $(abspath $($@_EXTRA))/$(BARE_METAL_TUPLE)/lib + ln -s $(abspath $($@_INSTALL))/$(BARE_METAL_TUPLE)/lib $(abspath $($@_EXTRA))/$(BARE_METAL_TUPLE)/lib + rm -rf $(abspath $($@_EXTRA))/lib/gcc/$(BARE_METAL_TUPLE)/$(RISCV_GCC_VERSION)/include/unwind.h + ln -s $(abspath $($@_BUILD))/riscv-gcc/libgcc/unwind-generic.h $(abspath $($@_EXTRA))/lib/gcc/$(BARE_METAL_TUPLE)/$(RISCV_GCC_VERSION)/include/unwind.h + date > $@ + +$(OBJ_NATIVE)/build/$(PACKAGE_HEADING)/build-binutils/build.stamp: \ + $(OBJ_NATIVE)/build/$(PACKAGE_HEADING)/build-binutils/support.stamp + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/build-binutils/build.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(NATIVE),$@)) + $(eval $@_BUILDLOG := $(abspath $(patsubst %/build/$(PACKAGE_HEADING)/build-binutils/build.stamp,%/buildlog/$(PACKAGE_HEADING),$@))) + $(MAKE) -C $(dir $@) -j1 install &>$($@_BUILDLOG)/build-binutils-make-install.log + find $(abspath $($@_INSTALL)) -type f > $($@_BUILDLOG)/install-binutils-file-list + date > $@ + +$(OBJ_WIN64)/build/$(PACKAGE_HEADING)/build-binutils/build.stamp: \ + $(OBJ_WIN64)/build/$(PACKAGE_HEADING)/build-binutils/support.stamp \ + $(OBJ_WIN64)/build/$(PACKAGE_HEADING)/extra-gcc-stage1/extra.stamp + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/build-binutils/build.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64),$@)) + $(eval $@_BUILDLOG := $(abspath $(patsubst %/build/$(PACKAGE_HEADING)/build-binutils/build.stamp,%/buildlog/$(PACKAGE_HEADING),$@))) + $(MAKE) -C $(dir $@) -j1 install &>$($@_BUILDLOG)/build-binutils-make-install.log + find $(abspath $($@_INSTALL)) -type f > $($@_BUILDLOG)/install-binutils-file-list + date > $@ + +$(OBJDIR)/%/build/$(PACKAGE_HEADING)/build-gcc-stage1/build.stamp: \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/build-binutils/build.stamp + $(eval $@_TARGET := $(patsubst $(OBJDIR)/%/build/$(PACKAGE_HEADING)/build-gcc-stage1/build.stamp,%,$@)) + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/build-gcc-stage1/build.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET),$@)) + $(eval $@_BUILD := $(patsubst %/build/$(PACKAGE_HEADING)/build-gcc-stage1/build.stamp,%/build/$(PACKAGE_HEADING),$@)) + $(eval $@_BUILDLOG := $(abspath $(patsubst %/build/$(PACKAGE_HEADING)/build-gcc-stage1/build.stamp,%/buildlog/$(PACKAGE_HEADING),$@))) + rm -rf $(dir $@) + mkdir -p $(dir $@) + # Workaround for CentOS random build fail issue + # + # Corresponding bugzilla entry on upstream: + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92008 + touch $(abspath $($@_BUILD))/riscv-gcc/intl/plural.c + cd $(dir $@) && $(abspath $($@_BUILD))/riscv-gcc/configure \ + --target=$(BARE_METAL_TUPLE) \ + $($($@_TARGET)-gcc-host) \ + --prefix=$(abspath $($@_INSTALL)) \ + --with-pkgversion="SiFive GCC-Metal $(PACKAGE_VERSION)" \ + --with-bugurl="https://github.com/sifive/freedom-tools/issues" \ + --disable-shared \ + --disable-threads \ + --disable-tls \ + --enable-languages=c,c++ \ + --with-newlib \ + --with-sysroot=$(abspath $($@_INSTALL))/$(BARE_METAL_TUPLE) \ + --disable-libmudflap \ + --disable-libssp \ + --disable-libquadmath \ + --disable-libgomp \ + --disable-nls \ + --disable-tm-clone-registry \ + --src=../riscv-gcc \ + $($($@_TARGET)-gcc-configure) \ + --enable-checking=yes \ + --enable-multilib \ + --with-abi=$(BARE_METAL_ABI) \ + --with-arch=$(BARE_METAL_ARCH) \ + CFLAGS="-O2" \ + CXXFLAGS="-O2" \ + CFLAGS_FOR_TARGET="-Os $(BARE_METAL_CFLAGS_FOR_TARGET)" \ + CXXFLAGS_FOR_TARGET="-Os $(BARE_METAL_CXXFLAGS_FOR_TARGET)" &>$($@_BUILDLOG)/build-gcc-stage1-make-configure.log + $(MAKE) -C $(dir $@) all-gcc &>$($@_BUILDLOG)/build-gcc-stage1-make-build.log + $(MAKE) -C $(dir $@) -j1 install-gcc &>$($@_BUILDLOG)/build-gcc-stage1-make-install.log + date > $@ + +$(OBJDIR)/%/build/$(PACKAGE_HEADING)/build-newlib/build.stamp: \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/build-gcc-stage1/build.stamp + $(eval $@_TARGET := $(patsubst $(OBJDIR)/%/build/$(PACKAGE_HEADING)/build-newlib/build.stamp,%,$@)) + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/build-newlib/build.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET),$@)) + $(eval $@_BUILD := $(patsubst %/build/$(PACKAGE_HEADING)/build-newlib/build.stamp,%/build/$(PACKAGE_HEADING),$@)) + $(eval $@_BUILDLOG := $(abspath $(patsubst %/build/$(PACKAGE_HEADING)/build-newlib/build.stamp,%/buildlog/$(PACKAGE_HEADING),$@))) + rm -rf $(dir $@) + mkdir -p $(dir $@) + @echo "PATH: $(PATH)" + cd $(dir $@) && $(abspath $($@_BUILD))/riscv-newlib/configure \ + --target=$(BARE_METAL_TUPLE) \ + $($($@_TARGET)-gcc-host) \ + --prefix=$(abspath $($@_INSTALL)) \ + --enable-newlib-io-long-double \ + --enable-newlib-io-long-long \ + --enable-newlib-io-c99-formats \ + --enable-newlib-register-fini \ + CFLAGS_FOR_TARGET="-O2 -D_POSIX_MODE $(BARE_METAL_CFLAGS_FOR_TARGET)" \ + CXXFLAGS_FOR_TARGET="-O2 -D_POSIX_MODE $(BARE_METAL_CXXFLAGS_FOR_TARGET)" &>$($@_BUILDLOG)/build-newlib-make-configure.log + $(MAKE) -C $(dir $@) &>$($@_BUILDLOG)/build-newlib-make-build.log + $(MAKE) -C $(dir $@) -j1 install &>$($@_BUILDLOG)/build-newlib-make-install.log +# These install multiple copies of the same docs into the same destination +# for a multilib build. So we must not parallelize them. +# TODO: Rewrite so that we only install one copy of the docs. + $(MAKE) -j1 -C $(dir $@) install-pdf install-html &>$($@_BUILDLOG)/build-newlib-make-install-doc.log + date > $@ + +$(OBJDIR)/%/build/$(PACKAGE_HEADING)/build-newlib-nano/build.stamp: \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/build-gcc-stage1/build.stamp + $(eval $@_TARGET := $(patsubst $(OBJDIR)/%/build/$(PACKAGE_HEADING)/build-newlib-nano/build.stamp,%,$@)) + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/build-newlib-nano/build.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET),$@)) + $(eval $@_BUILD := $(patsubst %/build/$(PACKAGE_HEADING)/build-newlib-nano/build.stamp,%/build/$(PACKAGE_HEADING),$@)) + $(eval $@_BUILDLOG := $(abspath $(patsubst %/build/$(PACKAGE_HEADING)/build-newlib-nano/build.stamp,%/buildlog/$(PACKAGE_HEADING),$@))) + rm -rf $(dir $@) + mkdir -p $(dir $@) + @echo "PATH: $(PATH)" + cd $(dir $@) && $(abspath $($@_BUILD))/riscv-newlib/configure \ + --target=$(BARE_METAL_TUPLE) \ + $($($@_TARGET)-gcc-host) \ + --prefix=$(abspath $($@_BUILD)/build-newlib-nano-install) \ + --enable-newlib-reent-small \ + --disable-newlib-fvwrite-in-streamio \ + --disable-newlib-fseek-optimization \ + --disable-newlib-wide-orient \ + --enable-newlib-nano-malloc \ + --disable-newlib-unbuf-stream-opt \ + --enable-lite-exit \ + --enable-newlib-global-atexit \ + --enable-newlib-nano-formatted-io \ + --disable-newlib-supplied-syscalls \ + --disable-nls \ + CFLAGS_FOR_TARGET="-Os -ffunction-sections -fdata-sections $(BARE_METAL_CFLAGS_FOR_TARGET)" \ + CXXFLAGS_FOR_TARGET="-Os -ffunction-sections -fdata-sections $(BARE_METAL_CXXFLAGS_FOR_TARGET)" &>$($@_BUILDLOG)/build-newlib-nano-make-configure.log + $(MAKE) -C $(dir $@) &>$($@_BUILDLOG)/build-newlib-nano-make-build.log + $(MAKE) -C $(dir $@) -j1 install &>$($@_BUILDLOG)/build-newlib-nano-make-install.log + date > $@ + +$(OBJDIR)/%/build/$(PACKAGE_HEADING)/build-newlib-nano-install/build.stamp: \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/build-newlib-nano/build.stamp \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/build-newlib/build.stamp + $(eval $@_TARGET := $(patsubst $(OBJDIR)/%/build/$(PACKAGE_HEADING)/build-newlib-nano-install/build.stamp,%,$@)) + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/build-newlib-nano-install/build.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET),$@)) + $(eval $@_BUILD := $(patsubst %/build/$(PACKAGE_HEADING)/build-newlib-nano-install/build.stamp,%/build/$(PACKAGE_HEADING),$@)) + $(eval $@_BUILDLOG := $(abspath $(patsubst %/build/$(PACKAGE_HEADING)/build-newlib-nano-install/build.stamp,%/buildlog/$(PACKAGE_HEADING),$@))) +# Copy nano library files into newlib install dir. + set -e; \ + bnl="$(abspath $($@_BUILD))/build-newlib-nano-install/$(BARE_METAL_TUPLE)/lib"; \ + inl="$(abspath $($@_INSTALL))/$(BARE_METAL_TUPLE)/lib"; \ + for bnlc in `find $${bnl} -name libc.a`; \ + do \ + inlc=`echo $${bnlc} | $(SED) -e "s:$${bnl}::" | $(SED) -e "s:libc\.a:libc_nano.a:g"`; \ + cp -v $${bnlc} $${inl}$${inlc}; \ + done; \ + for bnlm in `find $${bnl} -name libm.a`; \ + do \ + inlm=`echo $${bnlm} | $(SED) -e "s:$${bnl}::" | $(SED) -e "s:libm\.a:libm_nano.a:g"`; \ + cp -v $${bnlm} $${inl}$${inlm}; \ + done; \ + for bnlg in `find $${bnl} -name libg.a`; \ + do \ + inlg=`echo $${bnlg} | $(SED) -e "s:$${bnl}::" | $(SED) -e "s:libg\.a:libg_nano.a:g"`; \ + cp -v $${bnlg} $${inl}$${inlg}; \ + done; \ + for bnls in `find $${bnl} -name libgloss.a`; \ + do \ + inls=`echo $${bnls} | $(SED) -e "s:$${bnl}::" | $(SED) -e "s:libgloss\.a:libgloss_nano.a:g"`; \ + cp -v $${bnls} $${inl}$${inls}; \ + done; \ + for bnls in `find $${bnl} -name crt0.o`; \ + do \ + inls=`echo $${bnls} | $(SED) -e "s:$${bnl}::"`; \ + cp -v $${bnls} $${inl}$${inls}; \ + done +# Copy nano header files into newlib install dir. + mkdir -p $(abspath $($@_INSTALL))/$(BARE_METAL_TUPLE)/include/newlib-nano; \ + cp $(abspath $($@_BUILD))/build-newlib-nano-install/$(BARE_METAL_TUPLE)/include/newlib.h \ + $(abspath $($@_INSTALL))/$(BARE_METAL_TUPLE)/include/newlib-nano/newlib.h; \ + date > $@ + +$(OBJDIR)/%/build/$(PACKAGE_HEADING)/build-gcc-stage2/build.stamp: \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/build-newlib-nano-install/build.stamp + $(eval $@_TARGET := $(patsubst $(OBJDIR)/%/build/$(PACKAGE_HEADING)/build-gcc-stage2/build.stamp,%,$@)) + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/build-gcc-stage2/build.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET),$@)) + $(eval $@_BUILD := $(patsubst %/build/$(PACKAGE_HEADING)/build-gcc-stage2/build.stamp,%/build/$(PACKAGE_HEADING),$@)) + $(eval $@_BUILDLOG := $(abspath $(patsubst %/build/$(PACKAGE_HEADING)/build-gcc-stage2/build.stamp,%/buildlog/$(PACKAGE_HEADING),$@))) + rm -rf $(dir $@) + mkdir -p $(dir $@) + cd $(dir $@) && $(abspath $($@_BUILD))/riscv-gcc/configure \ + --target=$(BARE_METAL_TUPLE) \ + $($($@_TARGET)-gcc-host) \ + --prefix=$(abspath $($@_INSTALL)) \ + --with-pkgversion="SiFive GCC-Metal $(PACKAGE_VERSION)" \ + --with-bugurl="https://github.com/sifive/freedom-tools/issues" \ + --disable-shared \ + --disable-threads \ + --enable-languages=c,c++ \ + --enable-tls \ + --with-newlib \ + --with-sysroot=$(abspath $($@_INSTALL))/$(BARE_METAL_TUPLE) \ + --with-native-system-header-dir=/include \ + --disable-libmudflap \ + --disable-libssp \ + --disable-libquadmath \ + --disable-libgomp \ + --disable-nls \ + --disable-tm-clone-registry \ + --src=../riscv-gcc \ + $($($@_TARGET)-gcc-configure) \ + --enable-checking=yes \ + --enable-multilib \ + --with-abi=$(BARE_METAL_ABI) \ + --with-arch=$(BARE_METAL_ARCH) \ + CFLAGS="-O2" \ + CXXFLAGS="-O2" \ + CFLAGS_FOR_TARGET="-Os $(BARE_METAL_CFLAGS_FOR_TARGET)" \ + CXXFLAGS_FOR_TARGET="-Os $(BARE_METAL_CXXFLAGS_FOR_TARGET)" &>$($@_BUILDLOG)/build-gcc-stage2-make-configure.log + $(MAKE) -C $(dir $@) &>$($@_BUILDLOG)/build-gcc-stage2-make-build.log + $(MAKE) -C $(dir $@) -j1 install install-pdf install-html &>$($@_BUILDLOG)/build-gcc-stage2-make-install.log + tclsh ../../scripts/dyn-lib-check-$($@_TARGET).tcl $(abspath $($@_INSTALL))/bin/riscv64-unknown-elf-c++ + tclsh ../../scripts/dyn-lib-check-$($@_TARGET).tcl $(abspath $($@_INSTALL))/bin/riscv64-unknown-elf-g++ + tclsh ../../scripts/dyn-lib-check-$($@_TARGET).tcl $(abspath $($@_INSTALL))/bin/riscv64-unknown-elf-gcc + date > $@ + +$(OBJDIR)/$(NATIVE)/test/$(PACKAGE_HEADING)/test.stamp: \ + $(OBJDIR)/$(NATIVE)/test/$(PACKAGE_HEADING)/launch.stamp + mkdir -p $(dir $@) + PATH=$(abspath $(OBJDIR)/$(NATIVE)/launch/$(PACKAGE_TARNAME)/bin):$(PATH) riscv64-unknown-elf-c++ -v + PATH=$(abspath $(OBJDIR)/$(NATIVE)/launch/$(PACKAGE_TARNAME)/bin):$(PATH) riscv64-unknown-elf-g++ -v + PATH=$(abspath $(OBJDIR)/$(NATIVE)/launch/$(PACKAGE_TARNAME)/bin):$(PATH) riscv64-unknown-elf-gcc -v + @echo "Finished testing $(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(NATIVE).tar.gz tarball" + date > $@ diff --git a/modules/freedom-gcc-metal/Metadata.mk b/modules/freedom-gcc-metal/Metadata.mk new file mode 100644 index 0000000..01dfdb7 --- /dev/null +++ b/modules/freedom-gcc-metal/Metadata.mk @@ -0,0 +1,10 @@ +include ../freedom-binutils-metal/Metadata.mk +include ../../scripts/base_gcc_metadata.mk +include ../../scripts/base_newlib_metadata.mk + +# Customization ID, which should identify the customization added to the original by SiFive +FREEDOM_GCC_METAL_ID := $(FREEDOM_GCC_ID) + +# Characteristic tags, which should be usable for matching up providers and consumers +FREEDOM_GCC_METAL_RISCV_TAGS := $(FREEDOM_GCC_RISCV_TAGS) +FREEDOM_GCC_METAL_TOOLS_TAGS := $(FREEDOM_GCC_TAG_PREFIX)-metal diff --git a/modules/freedom-gcc-metal/Monorepo.mk b/modules/freedom-gcc-metal/Monorepo.mk new file mode 100644 index 0000000..5efc0f3 --- /dev/null +++ b/modules/freedom-gcc-metal/Monorepo.mk @@ -0,0 +1,42 @@ +.PHONY: gcc-metal gcc-metal-package gcc-metal-native-package gcc-metal-cross-package +.PHONY: gcc-metal-regress +.PHONY: gcc-metal-cleanup gcc-metal-native-cleanup gcc-metal-cross-cleanup +.PHONY: gcc-metal-flushup gcc-metal-native-flushup gcc-metal-cross-flushup +gcc-metal: gcc-metal-package + +.PHONY: gcc-only gcc-only-package gcc-only-native-package gcc-only-cross-package gcc-only-regress +gcc-only-package: gcc-metal-package +gcc-only-native-package: gcc-metal-native-package +gcc-only-cross-package: gcc-metal-cross-package +gcc-only-regress: gcc-metal-regress +gcc-only: gcc-metal + +gcc-metal-package: + $(MAKE) -C modules/freedom-gcc-metal package BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) + +gcc-metal-native-package: + $(MAKE) -C modules/freedom-gcc-metal native-package BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) + +gcc-metal-cross-package: + $(MAKE) -C modules/freedom-gcc-metal cross-package BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) + +gcc-metal-regress: + $(MAKE) -C modules/freedom-gcc-metal regress BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) + +gcc-metal-cleanup: + $(MAKE) -C modules/freedom-gcc-metal cleanup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + +gcc-metal-native-cleanup: + $(MAKE) -C modules/freedom-gcc-metal native-cleanup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + +gcc-metal-cross-cleanup: + $(MAKE) -C modules/freedom-gcc-metal cross-cleanup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + +gcc-metal-flushup: + $(MAKE) -C modules/freedom-gcc-metal flushup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + +gcc-metal-native-flushup: + $(MAKE) -C modules/freedom-gcc-metal native-flushup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + +gcc-metal-cross-flushup: + $(MAKE) -C modules/freedom-gcc-metal cross-flushup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ diff --git a/modules/freedom-gdb-metal.mk b/modules/freedom-gdb-metal.mk deleted file mode 100644 index b4e567f..0000000 --- a/modules/freedom-gdb-metal.mk +++ /dev/null @@ -1,50 +0,0 @@ - -FREEDOM_GDB_METAL_GITURL := git@github.com:sifive/freedom-gdb-metal.git -FREEDOM_GDB_METAL_BRANCH := main -FREEDOM_GDB_METAL_MODULE := $(SRCDIR)/freedom-gdb-metal - -ifneq ($(TARGET_GITURL),) -FREEDOM_GDB_METAL_GITURL := $(TARGET_GITURL) -endif -ifneq ($(TARGET_BRANCH),) -FREEDOM_GDB_METAL_BRANCH := $(TARGET_BRANCH) -endif - -ifneq ($(TOOLCHAIN_GDB_GITURL),) -FREEDOM_GDB_METAL_GITURL := $(TOOLCHAIN_GDB_GITURL) -endif -ifneq ($(TOOLCHAIN_GDB_BRANCH),) -FREEDOM_GDB_METAL_BRANCH := $(TOOLCHAIN_GDB_BRANCH) -endif - -.PHONY: gdb-metal gdb-metal-package gdb-metal-regress gdb-metal-cleanup gdb-metal-flushup -gdb-metal: gdb-metal-package - -.PHONY: gdb-only gdb-only-package gdb-only-regress -gdb-only-package: gdb-metal-package -gdb-only-regress: gdb-metal-regress -gdb-only: gdb-metal - -$(FREEDOM_GDB_METAL_MODULE).$(FREEDOM_GDB_METAL_BRANCH): - mkdir -p $(dir $@) - rm -rf $(FREEDOM_GDB_METAL_MODULE) - rm -rf $(FREEDOM_GDB_METAL_MODULE).* - git clone $(FREEDOM_GDB_METAL_GITURL) $(FREEDOM_GDB_METAL_MODULE) --single-branch -b $(FREEDOM_GDB_METAL_BRANCH) - cd $(FREEDOM_GDB_METAL_MODULE) && git submodule update --init --recursive - date > $@ - -gdb-metal-package: \ - $(FREEDOM_GDB_METAL_MODULE).$(FREEDOM_GDB_METAL_BRANCH) - $(MAKE) -C $(FREEDOM_GDB_METAL_MODULE) package BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) - -gdb-metal-regress: \ - $(FREEDOM_GDB_METAL_MODULE).$(FREEDOM_GDB_METAL_BRANCH) - $(MAKE) -C $(FREEDOM_GDB_METAL_MODULE) regress BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) - -gdb-metal-cleanup: - $(MAKE) -C $(FREEDOM_GDB_METAL_MODULE) cleanup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ - rm -rf $(FREEDOM_GDB_METAL_MODULE).* - rm -rf $(FREEDOM_GDB_METAL_MODULE) - -gdb-metal-flushup: - $(MAKE) -C $(FREEDOM_GDB_METAL_MODULE) flushup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ diff --git a/modules/freedom-gdb-metal/Makefile b/modules/freedom-gdb-metal/Makefile new file mode 100644 index 0000000..42570bc --- /dev/null +++ b/modules/freedom-gdb-metal/Makefile @@ -0,0 +1,207 @@ +# Setup the Freedom build script environment +include ../../scripts/Freedom.mk + +# Include version identifiers to build up the full version string +include Metadata.mk +PACKAGE_WORDING := Bare Metal GDB +PACKAGE_HEADING := riscv64-unknown-elf-gdb +PACKAGE_VERSION := $(RISCV_GDB_VERSION)-$(FREEDOM_GDB_METAL_ID)$(EXTRA_SUFFIX) +PACKAGE_COMMENT := \# SiFive Freedom Package Properties File + +# Source code directory references +BARE_METAL_TUPLE := riscv64-unknown-elf +BARE_METAL_CC_FOR_TARGET ?= $(BARE_METAL_TUPLE)-gcc +BARE_METAL_CXX_FOR_TARGET ?= $(BARE_METAL_TUPLE)-g++ + +# Some special package configure flags for specific targets +$(WIN64)-gdb-host := --host=$(WIN64) +$(WIN64)-expat-configure := --host=$(WIN64) +$(UBUNTU64)-gdb-host := --host=x86_64-linux-gnu +$(UBUNTU64)-expat-configure := --host=x86_64-linux-gnu +$(DARWIN)-gdb-host := --with-liblzma-prefix=/usr +$(DARWIN)-expat-configure := --disable-shared --enable-static + +# Setup the package targets and switch into secondary makefile targets +# Targets $(PACKAGE_HEADING)/install.stamp and $(PACKAGE_HEADING)/libs.stamp +include ../../scripts/Package.mk + +$(OBJDIR)/%/build/$(PACKAGE_HEADING)/install.stamp: \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/build-gdb-py/build.stamp + $(eval $@_TARGET := $(patsubst $(OBJDIR)/%/build/$(PACKAGE_HEADING)/install.stamp,%,$@)) + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/install.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET),$@)) + $(eval $@_PROPERTIES := $(patsubst %/build/$(PACKAGE_HEADING)/install.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET).properties,$@)) + mkdir -p $(dir $@) + git log --format="[%ad] %s" > $(abspath $($@_INSTALL))/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET).changelog + rm -f $(abspath $($@_PROPERTIES)) + echo "$(PACKAGE_COMMENT)" > $(abspath $($@_PROPERTIES)) + echo "PACKAGE_TYPE = freedom-tools" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_DESC_SEG = $(PACKAGE_WORDING)" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_FIXED_ID = $(PACKAGE_HEADING)" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_BUILD_ID = $(FREEDOM_GDB_METAL_ID)$(EXTRA_SUFFIX)" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_CORE_VER = $(RISCV_GDB_VERSION)" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_TARGET = $($@_TARGET)" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_VENDOR = SiFive" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_RIGHTS = sifive-v00 eclipse-v20" >> $(abspath $($@_PROPERTIES)) + echo "RISCV_TAGS = $(FREEDOM_GDB_METAL_RISCV_TAGS)" >> $(abspath $($@_PROPERTIES)) + echo "TOOLS_TAGS = $(FREEDOM_GDB_METAL_TOOLS_TAGS)" >> $(abspath $($@_PROPERTIES)) + cp $(abspath $($@_PROPERTIES)) $(abspath $($@_INSTALL))/ + tclsh ../../scripts/check-maximum-path-length.tcl $(abspath $($@_INSTALL)) "$(PACKAGE_HEADING)" "$(RISCV_GDB_VERSION)" "$(FREEDOM_GDB_METAL_ID)$(EXTRA_SUFFIX)" + tclsh ../../scripts/check-same-name-different-case.tcl $(abspath $($@_INSTALL)) + echo $(PATH) + date > $@ + +# We might need some extra target libraries for this package +$(OBJ_NATIVE)/build/$(PACKAGE_HEADING)/libs.stamp: \ + $(OBJ_NATIVE)/build/$(PACKAGE_HEADING)/install.stamp + date > $@ + +$(OBJ_WIN64)/build/$(PACKAGE_HEADING)/libs.stamp: \ + $(OBJ_WIN64)/build/$(PACKAGE_HEADING)/install.stamp + -$(WIN64)-gcc -print-search-dirs | grep ^programs | cut -d= -f2- | tr : "\n" | xargs -I {} find {} -iname "libwinpthread*.dll" | xargs cp -t $(OBJDIR)/$(WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64)/bin + -$(WIN64)-gcc -print-search-dirs | grep ^libraries | cut -d= -f2- | tr : "\n" | xargs -I {} find {} -iname "libgcc_s_seh*.dll" | xargs cp -t $(OBJDIR)/$(WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64)/bin + -$(WIN64)-gcc -print-search-dirs | grep ^libraries | cut -d= -f2- | tr : "\n" | xargs -I {} find {} -iname "libstdc*.dll" | xargs cp -t $(OBJDIR)/$(WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64)/bin + -$(WIN64)-gcc -print-search-dirs | grep ^libraries | cut -d= -f2- | tr : "\n" | xargs -I {} find {} -iname "libssp*.dll" | xargs cp -t $(OBJDIR)/$(WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64)/bin + date > $@ + +$(OBJDIR)/%/build/$(PACKAGE_HEADING)/source.stamp: + $(eval $@_TARGET := $(patsubst $(OBJDIR)/%/build/$(PACKAGE_HEADING)/source.stamp,%,$@)) + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/source.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET),$@)) + $(eval $@_BUILDLOG := $(abspath $(patsubst %/build/$(PACKAGE_HEADING)/source.stamp,%/buildlog/$(PACKAGE_HEADING),$@))) + $(eval $@_SRCBALL := $(abspath $(BINDIR)/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET).src.tar.gz)) + tclsh ../../scripts/check-naming-and-version-syntax.tcl "$(PACKAGE_WORDING)" "$(PACKAGE_HEADING)" "$(RISCV_GDB_VERSION)" "$(FREEDOM_GDB_METAL_ID)$(EXTRA_SUFFIX)" + rm -rf $($@_INSTALL) + mkdir -p $($@_INSTALL) + rm -rf $($@_BUILDLOG) + mkdir -p $($@_BUILDLOG) + rm -rf $(dir $@) + mkdir -p $(dir $@) + git log > $($@_BUILDLOG)/$(PACKAGE_HEADING)-git-commit.log + git remote -v > $($@_BUILDLOG)/$(PACKAGE_HEADING)-git-remote.log + cd $(dir $@); curl -L -f -s -o expat-2.2.0.tar.bz2 https://github.com/libexpat/libexpat/releases/download/R_2_2_0/expat-2.2.0.tar.bz2 + cd $(dir $@); $(TAR) -xf expat-2.2.0.tar.bz2 + cd $(dir $@); mv expat-2.2.0 expat + mkdir -p $($@_INSTALL)/python + cd $(dir $@); curl -L -f -s -o python-3.7.7-$($@_TARGET).tar.gz https://github.com/sifive/freedom-tools-resources/releases/download/v0-test1/python-3.7.7-$($@_TARGET).tar.gz + cd $($@_INSTALL)/python; $(TAR) -xf $(abspath $(dir $@))/python-3.7.7-$($@_TARGET).tar.gz + cd $(dir $@); rm python-3.7.7-$($@_TARGET).tar.gz + cp patches/pyconfig-x86_64-apple-darwin.sh $($@_INSTALL)/python + cp patches/pyconfig-x86_64-linux-centos6.sh $($@_INSTALL)/python + cp patches/pyconfig-x86_64-linux-ubuntu14.sh $($@_INSTALL)/python + cp patches/pyconfig-x86_64-w64-mingw32.sh $($@_INSTALL)/python + git clone --single-branch --branch $(RISCV_GDB_BRANCH) $(RISCV_GDB_GITURL) $(dir $@)/$(RISCV_GDB_FOLDER) + cd $(dir $@)/$(RISCV_GDB_FOLDER) && git checkout --detach $(RISCV_GDB_COMMIT) + cd $(dir $@)/$(RISCV_GDB_FOLDER) && git submodule update --init --recursive + $(SED) -E -i -f patches/python-c-gdb.sed $(dir $@)/$(RISCV_GDB_FOLDER)/gdb/python/python.c + mkdir -p $(dir $($@_SRCBALL)) + cd $(dir $@); $(TAR) --dereference --hard-dereference -c $(RISCV_GDB_FOLDER) | gzip > $($@_SRCBALL) + date > $@ + +# OpenOCD requires a GDB that's been build with expat support so it can read +# the target XML files. +$(OBJDIR)/%/build/$(PACKAGE_HEADING)/expat/build.stamp: \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/source.stamp + $(eval $@_TARGET := $(patsubst $(OBJDIR)/%/build/$(PACKAGE_HEADING)/expat/build.stamp,%,$@)) + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/expat/build.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET),$@)) + $(eval $@_BUILDLOG := $(abspath $(patsubst %/build/$(PACKAGE_HEADING)/expat/build.stamp,%/buildlog/$(PACKAGE_HEADING),$@))) + cd $(dir $@); ./configure --prefix=$(abspath $($@_INSTALL)) $($($@_TARGET)-expat-configure) &>$($@_BUILDLOG)/expat-make-configure.log + $(MAKE) -C $(dir $@) buildlib &>$($@_BUILDLOG)/expat-make-buildlib.log + $(MAKE) -C $(dir $@) -j1 installlib &>$($@_BUILDLOG)/expat-make-installlib.log + rm -f $(abspath $($@_INSTALL))/lib/libexpat*.dylib* + rm -f $(abspath $($@_INSTALL))/lib/libexpat*.so* + rm -f $(abspath $($@_INSTALL))/lib64/libexpat*.so* + date > $@ + +$(OBJDIR)/%/build/$(PACKAGE_HEADING)/build-gdb/build.stamp: \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/expat/build.stamp \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/source.stamp + $(eval $@_TARGET := $(patsubst $(OBJDIR)/%/build/$(PACKAGE_HEADING)/build-gdb/build.stamp,%,$@)) + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/build-gdb/build.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET),$@)) + $(eval $@_BUILD := $(patsubst %/build/$(PACKAGE_HEADING)/build-gdb/build.stamp,%/build/$(PACKAGE_HEADING),$@)) + $(eval $@_BUILDLOG := $(abspath $(patsubst %/build/$(PACKAGE_HEADING)/build-gdb/build.stamp,%/buildlog/$(PACKAGE_HEADING),$@))) + rm -rf $(dir $@) + mkdir -p $(dir $@) + # Workaround for CentOS random build fail issue + # + # Corresponding bugzilla entry on upstream: + # https://sourceware.org/bugzilla/show_bug.cgi?id=22941 + touch $(abspath $($@_BUILD))/$(RISCV_GDB_FOLDER)/intl/plural.c +# CC_FOR_TARGET is required for the ld testsuite. + cd $(dir $@) && CC_FOR_TARGET=$(BARE_METAL_CC_FOR_TARGET) $(abspath $($@_BUILD))/$(RISCV_GDB_FOLDER)/configure \ + --target=$(BARE_METAL_TUPLE) \ + $($($@_TARGET)-gdb-host) \ + --prefix=$(abspath $($@_INSTALL)) \ + --with-pkgversion="SiFive GDB-Metal $(PACKAGE_VERSION)" \ + --with-bugurl="https://github.com/sifive/freedom-tools/issues" \ + --disable-werror \ + --with-python=no \ + --enable-gdb \ + --disable-gas \ + --disable-binutils \ + --disable-ld \ + --disable-gold \ + --disable-gprof \ + --with-included-gettext \ + --with-mpc=no \ + --with-mpfr=no \ + --with-gmp=no \ + --with-expat=yes \ + --with-guile=no \ + CFLAGS="-O2" \ + CXXFLAGS="-O2" &>$($@_BUILDLOG)/build-gdb-make-configure.log + $(MAKE) -C $(dir $@) &>$($@_BUILDLOG)/build-gdb-make-build.log + $(MAKE) -C $(dir $@) -j1 install install-pdf install-html &>$($@_BUILDLOG)/build-gdb-make-install.log + rm -f $(abspath $($@_INSTALL))/share/doc/gdb/frame-apply.html + tclsh ../../scripts/dyn-lib-check-$($@_TARGET).tcl $(abspath $($@_INSTALL))/bin/riscv64-unknown-elf-gdb + date > $@ + +$(OBJDIR)/%/build/$(PACKAGE_HEADING)/build-gdb-py/build.stamp: \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/build-gdb/build.stamp + $(eval $@_TARGET := $(patsubst $(OBJDIR)/%/build/$(PACKAGE_HEADING)/build-gdb-py/build.stamp,%,$@)) + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/build-gdb-py/build.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET),$@)) + $(eval $@_BUILD := $(patsubst %/build/$(PACKAGE_HEADING)/build-gdb-py/build.stamp,%/build/$(PACKAGE_HEADING),$@)) + $(eval $@_BUILDLOG := $(abspath $(patsubst %/build/$(PACKAGE_HEADING)/build-gdb-py/build.stamp,%/buildlog/$(PACKAGE_HEADING),$@))) + rm -rf $(dir $@) + mkdir -p $(dir $@) + # Workaround for CentOS random build fail issue + # + # Corresponding bugzilla entry on upstream: + # https://sourceware.org/bugzilla/show_bug.cgi?id=22941 + touch $(abspath $($@_BUILD))/$(RISCV_GDB_FOLDER)/intl/plural.c +# CC_FOR_TARGET is required for the ld testsuite. + cd $(dir $@) && CC_FOR_TARGET=$(BARE_METAL_CC_FOR_TARGET) $(abspath $($@_BUILD))/$(RISCV_GDB_FOLDER)/configure \ + --target=$(BARE_METAL_TUPLE) \ + $($($@_TARGET)-gdb-host) \ + --prefix=$(abspath $($@_INSTALL)) \ + --with-pkgversion="SiFive GDB-Metal $(PACKAGE_VERSION)" \ + --with-bugurl="https://github.com/sifive/freedom-tools/issues" \ + --disable-werror \ + --with-python="$(abspath $($@_INSTALL))/python/pyconfig-$($@_TARGET).sh" \ + --program-prefix="$(BARE_METAL_TUPLE)-" \ + --program-suffix="-py" \ + --enable-gdb \ + --disable-gas \ + --disable-binutils \ + --disable-ld \ + --disable-gold \ + --disable-gprof \ + --with-included-gettext \ + --with-mpc=no \ + --with-mpfr=no \ + --with-gmp=no \ + --with-expat=yes \ + --with-guile=no \ + CFLAGS="-O2" \ + CXXFLAGS="-O2" &>$($@_BUILDLOG)/build-gdb-py-make-configure.log + $(MAKE) -C $(dir $@) &>$($@_BUILDLOG)/build-gdb-py-make-build.log + $(MAKE) -C $(dir $@) -j1 install install-pdf install-html &>$($@_BUILDLOG)/build-gdb-py-make-install.log + rm -f $(abspath $($@_INSTALL))/share/doc/gdb/frame-apply.html + tclsh ../../scripts/dyn-lib-check-$($@_TARGET).tcl $(abspath $($@_INSTALL))/bin/riscv64-unknown-elf-gdb-py + date > $@ + +$(OBJDIR)/$(NATIVE)/test/$(PACKAGE_HEADING)/test.stamp: \ + $(OBJDIR)/$(NATIVE)/test/$(PACKAGE_HEADING)/launch.stamp + mkdir -p $(dir $@) + PATH=$(abspath $(OBJDIR)/$(NATIVE)/launch/$(PACKAGE_TARNAME)/bin):$(PATH) riscv64-unknown-elf-gdb -v + PATH=$(abspath $(OBJDIR)/$(NATIVE)/launch/$(PACKAGE_TARNAME)/bin):$(PATH) riscv64-unknown-elf-gdb-py -v + @echo "Finished testing $(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(NATIVE).tar.gz tarball" + date > $@ diff --git a/modules/freedom-gdb-metal/Metadata.mk b/modules/freedom-gdb-metal/Metadata.mk new file mode 100644 index 0000000..bfb00f5 --- /dev/null +++ b/modules/freedom-gdb-metal/Metadata.mk @@ -0,0 +1,8 @@ +include ../../scripts/base_gdb_metadata.mk + +# Customization ID, which should identify the customization added to the original by SiFive +FREEDOM_GDB_METAL_ID := $(FREEDOM_GDB_ID) + +# Characteristic tags, which should be usable for matching up providers and consumers +FREEDOM_GDB_METAL_RISCV_TAGS := $(FREEDOM_GDB_RISCV_TAGS) +FREEDOM_GDB_METAL_TOOLS_TAGS := $(FREEDOM_GDB_TAG_PREFIX)-metal diff --git a/modules/freedom-gdb-metal/Monorepo.mk b/modules/freedom-gdb-metal/Monorepo.mk new file mode 100644 index 0000000..c0c78bc --- /dev/null +++ b/modules/freedom-gdb-metal/Monorepo.mk @@ -0,0 +1,42 @@ +.PHONY: gdb-metal gdb-metal-package gdb-metal-native-package gdb-metal-cross-package +.PHONY: gdb-metal-regress +.PHONY: gdb-metal-cleanup gdb-metal-native-cleanup gdb-metal-cross-cleanup +.PHONY: gdb-metal-flushup gdb-metal-native-flushup gdb-metal-cross-flushup +gdb-metal: gdb-metal-package + +.PHONY: gdb-only gdb-only-package gdb-only-native-package gdb-only-cross-package gdb-only-regress +gdb-only-package: gdb-metal-package +gdb-only-native-package: gdb-metal-native-package +gdb-only-cross-package: gdb-metal-cross-package +gdb-only-regress: gdb-metal-regress +gdb-only: gdb-metal + +gdb-metal-package: + $(MAKE) -C modules/freedom-gdb-metal package BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) + +gdb-metal-native-package: + $(MAKE) -C modules/freedom-gdb-metal native-package BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) + +gdb-metal-cross-package: + $(MAKE) -C modules/freedom-gdb-metal cross-package BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) + +gdb-metal-regress: + $(MAKE) -C modules/freedom-gdb-metal regress BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) + +gdb-metal-cleanup: + $(MAKE) -C modules/freedom-gdb-metal cleanup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + +gdb-metal-native-cleanup: + $(MAKE) -C modules/freedom-gdb-metal native-cleanup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + +gdb-metal-cross-cleanup: + $(MAKE) -C modules/freedom-gdb-metal cross-cleanup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + +gdb-metal-flushup: + $(MAKE) -C modules/freedom-gdb-metal flushup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + +gdb-metal-native-flushup: + $(MAKE) -C modules/freedom-gdb-metal native-flushup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + +gdb-metal-cross-flushup: + $(MAKE) -C modules/freedom-gdb-metal cross-flushup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ diff --git a/modules/freedom-gdb-metal/patches/pyconfig-x86_64-apple-darwin.sh b/modules/freedom-gdb-metal/patches/pyconfig-x86_64-apple-darwin.sh new file mode 100755 index 0000000..ec51a67 --- /dev/null +++ b/modules/freedom-gdb-metal/patches/pyconfig-x86_64-apple-darwin.sh @@ -0,0 +1,18 @@ +#!/bin/sh +# Ignore first argument +pydir=$(dirname $0) +shift +for arg in $@; do + case $arg in + --prefix|--exec-prefix) + echo "${pydir}" + ;; + --includes) + echo "-I${pydir}/include/python3.7m" + ;; + --libs|--ldflags) + echo "-L${pydir}/lib/python3.7/config-3.7m-darwin -L${pydir}/lib -lpython3.7m -ldl -framework CoreFoundation" + ;; + esac + shift +done diff --git a/modules/freedom-gdb-metal/patches/pyconfig-x86_64-linux-centos6.sh b/modules/freedom-gdb-metal/patches/pyconfig-x86_64-linux-centos6.sh new file mode 100755 index 0000000..965d9a4 --- /dev/null +++ b/modules/freedom-gdb-metal/patches/pyconfig-x86_64-linux-centos6.sh @@ -0,0 +1,18 @@ +#!/bin/sh +# Ignore first argument +pydir=$(dirname $0) +shift +for arg in $@; do + case $arg in + --prefix|--exec-prefix) + echo "${pydir}" + ;; + --includes) + echo "-I${pydir}/include/python3.7m" + ;; + --libs|--ldflags) + echo "-L${pydir}/lib/python3.7/config-3.7m-x86_64-linux-gnu -L${pydir}/lib -lpython3.7m -lcrypt -lpthread -ldl -lutil -lrt -lm" + ;; + esac + shift +done diff --git a/modules/freedom-gdb-metal/patches/pyconfig-x86_64-linux-ubuntu14.sh b/modules/freedom-gdb-metal/patches/pyconfig-x86_64-linux-ubuntu14.sh new file mode 100755 index 0000000..d19503f --- /dev/null +++ b/modules/freedom-gdb-metal/patches/pyconfig-x86_64-linux-ubuntu14.sh @@ -0,0 +1,18 @@ +#!/bin/sh +# Ignore first argument +pydir=$(dirname $0) +shift +for arg in $@; do + case $arg in + --prefix|--exec-prefix) + echo "${pydir}" + ;; + --includes) + echo "-I${pydir}/include/python3.7m" + ;; + --libs|--ldflags) + echo "-L${pydir}/lib/python3.7/config-3.7m-x86_64-linux-gnu -L${pydir}/lib -lpython3.7m -lcrypt -lpthread -ldl -lutil -lm" + ;; + esac + shift +done diff --git a/modules/freedom-gdb-metal/patches/pyconfig-x86_64-w64-mingw32.sh b/modules/freedom-gdb-metal/patches/pyconfig-x86_64-w64-mingw32.sh new file mode 100755 index 0000000..3c7dc29 --- /dev/null +++ b/modules/freedom-gdb-metal/patches/pyconfig-x86_64-w64-mingw32.sh @@ -0,0 +1,18 @@ +#!/bin/sh +# Ignore first argument +pydir=$(dirname $0) +shift +for arg in $@; do + case $arg in + --prefix|--exec-prefix) + echo "${pydir}" + ;; + --includes) + echo "-I${pydir}/include" + ;; + --libs|--ldflags) + echo "-L${pydir}/libs -lpython37" + ;; + esac + shift +done diff --git a/modules/freedom-gdb-metal/patches/python-c-gdb.sed b/modules/freedom-gdb-metal/patches/python-c-gdb.sed new file mode 100644 index 0000000..d95d7e5 --- /dev/null +++ b/modules/freedom-gdb-metal/patches/python-c-gdb.sed @@ -0,0 +1 @@ +:a;N;$!ba;s/#ifndef _WIN32.*#endif \/\* _WIN32 \*\//PyRun_SimpleFile \(file, filename\)\;/ diff --git a/modules/freedom-openocd.mk b/modules/freedom-openocd.mk deleted file mode 100644 index 7aa2a77..0000000 --- a/modules/freedom-openocd.mk +++ /dev/null @@ -1,38 +0,0 @@ - -FREEDOM_OPENOCD_GITURL := git@github.com:sifive/freedom-openocd.git -FREEDOM_OPENOCD_BRANCH := main -FREEDOM_OPENOCD_MODULE := $(SRCDIR)/freedom-openocd - -ifneq ($(TARGET_GITURL),) -FREEDOM_OPENOCD_GITURL := $(TARGET_GITURL) -endif -ifneq ($(TARGET_BRANCH),) -FREEDOM_OPENOCD_BRANCH := $(TARGET_BRANCH) -endif - -.PHONY: openocd openocd-package openocd-regress openocd-cleanup openocd-flushup -openocd: openocd-package - -$(FREEDOM_OPENOCD_MODULE).$(FREEDOM_OPENOCD_BRANCH): - mkdir -p $(dir $@) - rm -rf $(FREEDOM_OPENOCD_MODULE) - rm -rf $(FREEDOM_OPENOCD_MODULE).* - git clone $(FREEDOM_OPENOCD_GITURL) $(FREEDOM_OPENOCD_MODULE) --single-branch -b $(FREEDOM_OPENOCD_BRANCH) - cd $(FREEDOM_OPENOCD_MODULE) && git submodule update --init --recursive - date > $@ - -openocd-package: \ - $(FREEDOM_OPENOCD_MODULE).$(FREEDOM_OPENOCD_BRANCH) - $(MAKE) -C $(FREEDOM_OPENOCD_MODULE) package BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) - -openocd-regress: \ - $(FREEDOM_OPENOCD_MODULE).$(FREEDOM_OPENOCD_BRANCH) - $(MAKE) -C $(FREEDOM_OPENOCD_MODULE) regress BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) - -openocd-cleanup: - $(MAKE) -C $(FREEDOM_OPENOCD_MODULE) cleanup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ - rm -rf $(FREEDOM_OPENOCD_MODULE).* - rm -rf $(FREEDOM_OPENOCD_MODULE) - -openocd-flushup: - $(MAKE) -C $(FREEDOM_OPENOCD_MODULE) flushup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ diff --git a/modules/freedom-openocd/Makefile b/modules/freedom-openocd/Makefile new file mode 100644 index 0000000..6f17cee --- /dev/null +++ b/modules/freedom-openocd/Makefile @@ -0,0 +1,173 @@ +# Setup the Freedom build script environment +include ../../scripts/Freedom.mk + +# Include version identifiers to build up the full version string +include Metadata.mk +PACKAGE_WORDING := OpenOCD +PACKAGE_HEADING := riscv-openocd +PACKAGE_VERSION := $(RISCV_OPENOCD_VERSION)-$(FREEDOM_OPENOCD_ID)$(EXTRA_SUFFIX) +PACKAGE_COMMENT := \# SiFive Freedom Package Properties File + +# Some special package configure flags for specific targets +$(WIN64)-rocd-host := --host=$(WIN64) +$(WIN64)-oftdi-configure := -DCMAKE_TOOLCHAIN_FILE="$(abspath $(OBJ_WIN64)/build/$(PACKAGE_HEADING)/libftdi/cmake/Toolchain-x86_64-w64-mingw32.cmake)" -DLIBUSB_LIBRARIES="$(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64)/bin/libusb-1.0.dll)" -DLIBUSB_INCLUDE_DIR="$(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64)/include/libusb-1.0)" +$(WIN64)-odeps-vars := PKG_CONFIG_PATH="$(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64))/lib/pkgconfig" CFLAGS="-L$(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64))/lib -I$(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64))/include" CPPFLAGS="-L$(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64))/lib -I$(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64))/include" +$(WIN64)-rocd-vars := PKG_CONFIG_PATH="$(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64))/lib/pkgconfig" CFLAGS="-L$(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64))/lib -I$(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64))/include" CPPFLAGS="-L$(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64))/lib -I$(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64))/include" +$(UBUNTU64)-ousb-configure := --disable-shared +$(UBUNTU64)-rocd-host := --host=x86_64-linux-gnu +$(UBUNTU64)-odeps-vars := PKG_CONFIG_PATH="$(abspath $(OBJ_UBUNTU64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(UBUNTU64))/lib/pkgconfig" CFLAGS="-I$(abspath $(OBJ_UBUNTU64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(UBUNTU64))/include -fPIC" LDFLAGS="-L$(abspath $(OBJ_UBUNTU64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(UBUNTU64))/lib -pthread" +$(UBUNTU64)-rocd-vars := PKG_CONFIG_PATH="$(abspath $(OBJ_UBUNTU64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(UBUNTU64))/lib/pkgconfig" CFLAGS="-I$(abspath $(OBJ_UBUNTU64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(UBUNTU64))/include" CPPFLAGS="-I$(abspath $(OBJ_UBUNTU64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(UBUNTU64))/include" LIBUSB_INCLUDE_DIRS="$(abspath $(OBJ_UBUNTU64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(UBUNTU64))/include" LDFLAGS="-L$(abspath $(OBJ_UBUNTU64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(UBUNTU64))/lib" +$(DARWIN)-ousb-configure := --disable-shared +$(DARWIN)-odeps-vars := PKG_CONFIG_PATH="$(abspath $(OBJ_DARWIN)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(DARWIN))/lib/pkgconfig" CFLAGS="-I$(abspath $(OBJ_DARWIN)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(DARWIN))/include" CPPFLAGS="-I$(abspath $(OBJ_DARWIN)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(DARWIN))/include" LDFLAGS="-L$(abspath $(OBJ_DARWIN)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(DARWIN))/lib -framework CoreFoundation -framework IOKit" +$(DARWIN)-rocd-vars := PKG_CONFIG_PATH="$(abspath $(OBJ_DARWIN)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(DARWIN))/lib/pkgconfig" CFLAGS="-I$(abspath $(OBJ_DARWIN)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(DARWIN))/include -O2" CPPFLAGS="-I$(abspath $(OBJ_DARWIN)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(DARWIN))/include" LDFLAGS="-L$(abspath $(OBJ_DARWIN)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(DARWIN))/lib -framework CoreFoundation -framework IOKit" +$(REDHAT)-ousb-configure := --disable-shared +$(REDHAT)-odeps-vars := PKG_CONFIG_PATH="$(abspath $(OBJ_REDHAT)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT))/lib/pkgconfig:$(abspath $(OBJ_REDHAT)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT))/lib64/pkgconfig" CFLAGS="-I$(abspath $(OBJ_REDHAT)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT))/include -fPIC" LDFLAGS="-L$(abspath $(OBJ_REDHAT)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT))/lib -L$(abspath $(OBJ_REDHAT)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT))/lib64 -lrt" +$(REDHAT)-rocd-vars := PKG_CONFIG_PATH="$(abspath $(OBJ_REDHAT)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT))/lib/pkgconfig:$(abspath $(OBJ_REDHAT)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT))/lib64/pkgconfig" CFLAGS="-I$(abspath $(OBJ_REDHAT)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT))/include -O2" CPPFLAGS="-I$(abspath $(OBJ_REDHAT)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT))/include" LIBUSB_INCLUDE_DIRS="$(abspath $(OBJ_REDHAT)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT))/include" LDFLAGS="-L$(abspath $(OBJ_REDHAT)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT))/lib -L$(abspath $(OBJ_REDHAT)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT))/lib64 -lrt" + +# Setup the package targets and switch into secondary makefile targets +# Targets $(PACKAGE_HEADING)/install.stamp and $(PACKAGE_HEADING)/libs.stamp +include ../../scripts/Package.mk + +$(OBJDIR)/%/build/$(PACKAGE_HEADING)/install.stamp: \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/$(RISCV_OPENOCD_FOLDER)/build.stamp + $(eval $@_TARGET := $(patsubst $(OBJDIR)/%/build/$(PACKAGE_HEADING)/install.stamp,%,$@)) + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/install.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET),$@)) + $(eval $@_PROPERTIES := $(patsubst %/build/$(PACKAGE_HEADING)/install.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET).properties,$@)) + mkdir -p $(dir $@) + git log --format="[%ad] %s" > $(abspath $($@_INSTALL))/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET).changelog + rm -f $(abspath $($@_PROPERTIES)) + echo "$(PACKAGE_COMMENT)" > $(abspath $($@_PROPERTIES)) + echo "PACKAGE_TYPE = freedom-tools" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_DESC_SEG = $(PACKAGE_WORDING)" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_FIXED_ID = $(PACKAGE_HEADING)" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_BUILD_ID = $(FREEDOM_OPENOCD_ID)$(EXTRA_SUFFIX)" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_CORE_VER = $(RISCV_OPENOCD_VERSION)" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_TARGET = $($@_TARGET)" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_VENDOR = SiFive" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_RIGHTS = sifive-v00 eclipse-v20" >> $(abspath $($@_PROPERTIES)) + echo "RISCV_TAGS = $(FREEDOM_OPENOCD_RISCV_TAGS)" >> $(abspath $($@_PROPERTIES)) + echo "TOOLS_TAGS = $(FREEDOM_OPENOCD_TOOLS_TAGS)" >> $(abspath $($@_PROPERTIES)) + cp $(abspath $($@_PROPERTIES)) $(abspath $($@_INSTALL))/ + tclsh ../../scripts/check-maximum-path-length.tcl $(abspath $($@_INSTALL)) "$(PACKAGE_HEADING)" "$(RISCV_OPENOCD_VERSION)" "$(FREEDOM_OPENOCD_ID)$(EXTRA_SUFFIX)" + tclsh ../../scripts/check-same-name-different-case.tcl $(abspath $($@_INSTALL)) + date > $@ + +# We might need some extra target libraries for this package +$(OBJDIR)/%/build/$(PACKAGE_HEADING)/libs.stamp: \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/install.stamp + date > $@ + +$(OBJ_WIN64)/build/$(PACKAGE_HEADING)/libs.stamp: \ + $(OBJ_WIN64)/build/$(PACKAGE_HEADING)/install.stamp + -$(WIN64)-gcc -print-search-dirs | grep ^programs | cut -d= -f2- | tr : "\n" | xargs -I {} find {} -iname "libwinpthread*.dll" | xargs cp -t $(OBJDIR)/$(WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64)/bin + -$(WIN64)-gcc -print-search-dirs | grep ^libraries | cut -d= -f2- | tr : "\n" | xargs -I {} find {} -iname "libgcc_s_seh*.dll" | xargs cp -t $(OBJDIR)/$(WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64)/bin + -$(WIN64)-gcc -print-search-dirs | grep ^libraries | cut -d= -f2- | tr : "\n" | xargs -I {} find {} -iname "libstdc*.dll" | xargs cp -t $(OBJDIR)/$(WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64)/bin + -$(WIN64)-gcc -print-search-dirs | grep ^libraries | cut -d= -f2- | tr : "\n" | xargs -I {} find {} -iname "libssp*.dll" | xargs cp -t $(OBJDIR)/$(WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64)/bin + date > $@ + +$(OBJDIR)/%/build/$(PACKAGE_HEADING)/source.stamp: + $(eval $@_TARGET := $(patsubst $(OBJDIR)/%/build/$(PACKAGE_HEADING)/source.stamp,%,$@)) + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/source.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET),$@)) + $(eval $@_BUILDLOG := $(abspath $(patsubst %/build/$(PACKAGE_HEADING)/source.stamp,%/buildlog/$(PACKAGE_HEADING),$@))) + $(eval $@_SRCBALL := $(abspath $(BINDIR)/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET).src.tar.gz)) + tclsh ../../scripts/check-naming-and-version-syntax.tcl "$(PACKAGE_WORDING)" "$(PACKAGE_HEADING)" "$(RISCV_OPENOCD_VERSION)" "$(FREEDOM_OPENOCD_ID)$(EXTRA_SUFFIX)" + rm -rf $($@_INSTALL) + mkdir -p $($@_INSTALL) + rm -rf $($@_BUILDLOG) + mkdir -p $($@_BUILDLOG) + rm -rf $(dir $@) + mkdir -p $(dir $@) + git log > $($@_BUILDLOG)/$(PACKAGE_HEADING)-git-commit.log + git remote -v > $($@_BUILDLOG)/$(PACKAGE_HEADING)-git-remote.log + cd $(dir $@); curl -L -f -s -o libusb-1.0.22.tar.bz2 https://github.com/libusb/libusb/releases/download/v1.0.22/libusb-1.0.22.tar.bz2 + cd $(dir $@); $(TAR) -xf libusb-1.0.22.tar.bz2 + cd $(dir $@); mv libusb-1.0.22 libusb + cd $(dir $@); curl -L -f -s -o libusb-compat-0.1.7.tar.bz2 https://github.com/libusb/libusb-compat-0.1/releases/download/v0.1.7/libusb-compat-0.1.7.tar.bz2 + cd $(dir $@); $(TAR) -xf libusb-compat-0.1.7.tar.bz2 + cd $(dir $@); mv libusb-compat-0.1.7 libusb-compat + cd $(dir $@); curl -L -f -s -o libftdi1-1.4.tar.bz2 https://www.intra2net.com/en/developer/libftdi/download/libftdi1-1.4.tar.bz2 + cd $(dir $@); $(TAR) -xf libftdi1-1.4.tar.bz2 + cd $(dir $@); mv libftdi1-1.4 libftdi + git clone --single-branch --branch $(RISCV_OPENOCD_BRANCH) $(RISCV_OPENOCD_GITURL) $(dir $@)/$(RISCV_OPENOCD_FOLDER) + cd $(dir $@)/$(RISCV_OPENOCD_FOLDER) && git checkout --detach $(RISCV_OPENOCD_COMMIT) + cd $(dir $@)/$(RISCV_OPENOCD_FOLDER) && git submodule update --init --recursive + $(SED) -i -f patches/openocd.sed -e "s/SIFIVE_PACKAGE_VERSION/SiFive OpenOCD $(PACKAGE_VERSION)/" $(dir $@)/$(RISCV_OPENOCD_FOLDER)/src/openocd.c + $(SED) -E -i -f patches/openocd-rtos.sed $(dir $@)/$(RISCV_OPENOCD_FOLDER)/src/rtos/rtos.c + mkdir -p $(dir $($@_SRCBALL)) + cd $(dir $@); $(TAR) --dereference --hard-dereference -c libusb libusb-compat libftdi $(RISCV_OPENOCD_FOLDER) | gzip > $($@_SRCBALL) + date > $@ + +$(OBJDIR)/%/build/$(PACKAGE_HEADING)/libusb/build.stamp: \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/source.stamp + $(eval $@_TARGET := $(patsubst $(OBJDIR)/%/build/$(PACKAGE_HEADING)/libusb/build.stamp,%,$@)) + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/libusb/build.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET),$@)) + $(eval $@_BUILDLOG := $(abspath $(patsubst %/build/$(PACKAGE_HEADING)/libusb/build.stamp,%/buildlog/$(PACKAGE_HEADING),$@))) + cd $(dir $@) && $($($@_TARGET)-odeps-vars) ./configure \ + $($($@_TARGET)-rocd-host) \ + --prefix=$(abspath $($@_INSTALL)) \ + --disable-udev \ + --enable-static \ + $($($@_TARGET)-ousb-configure) &>$($@_BUILDLOG)/libusb-make-configure.log + $(MAKE) -C $(dir $@) &>$($@_BUILDLOG)/libusb-make-build.log + $(MAKE) -C $(dir $@) -j1 install &>$($@_BUILDLOG)/libusb-make-install.log + date > $@ + +$(OBJDIR)/%/build/$(PACKAGE_HEADING)/libusb-compat/build.stamp: \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/libusb/build.stamp \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/source.stamp + $(eval $@_TARGET := $(patsubst $(OBJDIR)/%/build/$(PACKAGE_HEADING)/libusb-compat/build.stamp,%,$@)) + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/libusb-compat/build.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET),$@)) + $(eval $@_BUILDLOG := $(abspath $(patsubst %/build/$(PACKAGE_HEADING)/libusb-compat/build.stamp,%/buildlog/$(PACKAGE_HEADING),$@))) + cd $(dir $@) && $($($@_TARGET)-odeps-vars) ./configure \ + $($($@_TARGET)-rocd-host) \ + --prefix=$(abspath $($@_INSTALL)) \ + --enable-static \ + $($($@_TARGET)-ousb-configure) &>$($@_BUILDLOG)/libusb-compat-make-configure.log + $(MAKE) -C $(dir $@) &>$($@_BUILDLOG)/libusb-compat-make-build.log + $(MAKE) -C $(dir $@) -j1 install &>$($@_BUILDLOG)/libusb-compat-make-install.log + date > $@ + +$(OBJDIR)/%/build/$(PACKAGE_HEADING)/libftdi/build.stamp: \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/libusb-compat/build.stamp \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/source.stamp + $(eval $@_TARGET := $(patsubst $(OBJDIR)/%/build/$(PACKAGE_HEADING)/libftdi/build.stamp,%,$@)) + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/libftdi/build.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET),$@)) + $(eval $@_BUILDLOG := $(abspath $(patsubst %/build/$(PACKAGE_HEADING)/libftdi/build.stamp,%/buildlog/$(PACKAGE_HEADING),$@))) + cd $(dir $@) && $($($@_TARGET)-odeps-vars) cmake \ + -DCMAKE_INSTALL_PREFIX:PATH=$(abspath $($@_INSTALL)) \ + $($($@_TARGET)-oftdi-configure) . &>$($@_BUILDLOG)/libftdi-make-cmake.log + $(MAKE) -C $(dir $@) &>$($@_BUILDLOG)/libftdi-make-build.log + $(MAKE) -C $(dir $@) -j1 install &>$($@_BUILDLOG)/libftdi-make-install.log + date > $@ + +$(OBJDIR)/%/build/$(PACKAGE_HEADING)/$(RISCV_OPENOCD_FOLDER)/build.stamp: \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/libftdi/build.stamp \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/source.stamp + $(eval $@_TARGET := $(patsubst $(OBJDIR)/%/build/$(PACKAGE_HEADING)/$(RISCV_OPENOCD_FOLDER)/build.stamp,%,$@)) + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/$(RISCV_OPENOCD_FOLDER)/build.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET),$@)) + $(eval $@_BUILDLOG := $(abspath $(patsubst %/build/$(PACKAGE_HEADING)/$(RISCV_OPENOCD_FOLDER)/build.stamp,%/buildlog/$(PACKAGE_HEADING),$@))) + rm -f $(abspath $($@_INSTALL))/lib/lib*.dylib* + rm -f $(abspath $($@_INSTALL))/lib/lib*.so* + rm -f $(abspath $($@_INSTALL))/lib64/lib*.so* + find $(dir $@) -iname configure.ac | $(SED) s/configure.ac/m4/ | xargs mkdir -p + cd $(dir $@); ./bootstrap nosubmodule &>$($@_BUILDLOG)/$(RISCV_OPENOCD_FOLDER)-make-bootstrap.log + cd $(dir $@); $($($@_TARGET)-rocd-vars) ./configure \ + $($($@_TARGET)-rocd-host) \ + --prefix=$(abspath $($@_INSTALL)) \ + --enable-remote-bitbang \ + --disable-werror \ + --enable-ftdi \ + --enable-jtag_vpi \ + $($($@_TARGET)-rocd-configure) &>$($@_BUILDLOG)/$(RISCV_OPENOCD_FOLDER)-make-configure.log + $(MAKE) $($($@_TARGET)-rocd-vars) -C $(dir $@) &>$($@_BUILDLOG)/$(RISCV_OPENOCD_FOLDER)-make-build.log + $(MAKE) $($($@_TARGET)-rocd-vars) -C $(dir $@) pdf html &>$($@_BUILDLOG)/$(RISCV_OPENOCD_FOLDER)-make-build-doc.log + $(MAKE) $($($@_TARGET)-rocd-vars) -C $(dir $@) -j1 install install-pdf install-html &>$($@_BUILDLOG)/$(RISCV_OPENOCD_FOLDER)-make-install.log + tclsh ../../scripts/dyn-lib-check-$($@_TARGET).tcl $(abspath $($@_INSTALL))/bin/openocd + date > $@ + +$(OBJDIR)/$(NATIVE)/test/$(PACKAGE_HEADING)/test.stamp: \ + $(OBJDIR)/$(NATIVE)/test/$(PACKAGE_HEADING)/launch.stamp + mkdir -p $(dir $@) + PATH=$(abspath $(OBJDIR)/$(NATIVE)/launch/$(PACKAGE_TARNAME)/bin):$(PATH) openocd -v + @echo "Finished testing $(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(NATIVE).tar.gz tarball" + date > $@ diff --git a/modules/freedom-openocd/Metadata.mk b/modules/freedom-openocd/Metadata.mk new file mode 100644 index 0000000..ea97256 --- /dev/null +++ b/modules/freedom-openocd/Metadata.mk @@ -0,0 +1,15 @@ +# Git repos, branches, commits and folders to get source code for the tool we are building +RISCV_OPENOCD_GITURL := git@github.com:riscv/riscv-openocd.git +RISCV_OPENOCD_BRANCH := riscv +RISCV_OPENOCD_COMMIT := a83ac8102208fe43029e31a20ea00eb5f242f5e3 +RISCV_OPENOCD_FOLDER := riscv-openocd + +# Version number, which should match the official version of the tool we are building +RISCV_OPENOCD_VERSION := 0.10.0 + +# Customization ID, which should identify the customization added to the original by SiFive +FREEDOM_OPENOCD_ID := 2020.12.1 + +# Characteristic tags, which should be usable for matching up providers and consumers +FREEDOM_OPENOCD_RISCV_TAGS = +FREEDOM_OPENOCD_TOOLS_TAGS = openocd diff --git a/modules/freedom-openocd/Monorepo.mk b/modules/freedom-openocd/Monorepo.mk new file mode 100644 index 0000000..5e7aa80 --- /dev/null +++ b/modules/freedom-openocd/Monorepo.mk @@ -0,0 +1,35 @@ +.PHONY: openocd openocd-package openocd-native-package openocd-cross-package +.PHONY: openocd-regress +.PHONY: openocd-cleanup openocd-native-cleanup openocd-cross-cleanup +.PHONY: openocd-flushup openocd-native-flushup openocd-cross-flushup +openocd: openocd-package + +openocd-package: + $(MAKE) -C modules/freedom-openocd package BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) + +openocd-native-package: + $(MAKE) -C modules/freedom-openocd native-package BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) + +openocd-cross-package: + $(MAKE) -C modules/freedom-openocd cross-package BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) + +openocd-regress: + $(MAKE) -C modules/freedom-openocd regress BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) + +openocd-cleanup: + $(MAKE) -C modules/freedom-openocd cleanup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + +openocd-native-cleanup: + $(MAKE) -C modules/freedom-openocd native-cleanup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + +openocd-cross-cleanup: + $(MAKE) -C modules/freedom-openocd cross-cleanup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + +openocd-flushup: + $(MAKE) -C modules/freedom-openocd flushup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + +openocd-native-flushup: + $(MAKE) -C modules/freedom-openocd native-flushup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + +openocd-cross-flushup: + $(MAKE) -C modules/freedom-openocd cross-flushup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ diff --git a/modules/freedom-openocd/patches/openocd-rtos.sed b/modules/freedom-openocd/patches/openocd-rtos.sed new file mode 100644 index 0000000..266eea8 --- /dev/null +++ b/modules/freedom-openocd/patches/openocd-rtos.sed @@ -0,0 +1 @@ +s/LOG_ERROR\(\"RTOS: failed to get register/LOG_DEBUG\(\"RTOS: failed to get register/ diff --git a/modules/freedom-openocd/patches/openocd.sed b/modules/freedom-openocd/patches/openocd.sed new file mode 100644 index 0000000..c02d6a0 --- /dev/null +++ b/modules/freedom-openocd/patches/openocd.sed @@ -0,0 +1,4 @@ +s/.Open On-Chip Debugger . VERSION RELSTR . .. PKGBLDDATE .../\"Open On-Chip Debugger \" VERSION \" \(SIFIVE_PACKAGE_VERSION\)\"/ +s/.Open On-Chip Debugger . VERSION RELSTR/\"Open On-Chip Debugger \" VERSION \" \(SIFIVE_PACKAGE_VERSION\)\"/ +s/For bug reports, read/For bug reports:/ +s/http:\/\/openocd\.org\/doc\/doxygen\/bugs\.html/https:\/\/github.com\/sifive\/freedom-tools\/issues/ diff --git a/modules/freedom-qemu.mk b/modules/freedom-qemu.mk deleted file mode 100644 index a4952c6..0000000 --- a/modules/freedom-qemu.mk +++ /dev/null @@ -1,38 +0,0 @@ - -FREEDOM_QEMU_GITURL := git@github.com:sifive/freedom-qemu.git -FREEDOM_QEMU_BRANCH := main -FREEDOM_QEMU_MODULE := $(SRCDIR)/freedom-qemu - -ifneq ($(TARGET_GITURL),) -FREEDOM_QEMU_GITURL := $(TARGET_GITURL) -endif -ifneq ($(TARGET_BRANCH),) -FREEDOM_QEMU_BRANCH := $(TARGET_BRANCH) -endif - -.PHONY: qemu qemu-package qemu-regress qemu-cleanup qemu-flushup -qemu: qemu-package - -$(FREEDOM_QEMU_MODULE).$(FREEDOM_QEMU_BRANCH): - mkdir -p $(dir $@) - rm -rf $(FREEDOM_QEMU_MODULE) - rm -rf $(FREEDOM_QEMU_MODULE).* - git clone $(FREEDOM_QEMU_GITURL) $(FREEDOM_QEMU_MODULE) --single-branch -b $(FREEDOM_QEMU_BRANCH) - cd $(FREEDOM_QEMU_MODULE) && git submodule update --init --recursive - date > $@ - -qemu-package: \ - $(FREEDOM_QEMU_MODULE).$(FREEDOM_QEMU_BRANCH) - $(MAKE) -C $(FREEDOM_QEMU_MODULE) package BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) - -qemu-regress: \ - $(FREEDOM_QEMU_MODULE).$(FREEDOM_QEMU_BRANCH) - $(MAKE) -C $(FREEDOM_QEMU_MODULE) regress BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) - -qemu-cleanup: - $(MAKE) -C $(FREEDOM_QEMU_MODULE) cleanup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ - rm -rf $(FREEDOM_QEMU_MODULE).* - rm -rf $(FREEDOM_QEMU_MODULE) - -qemu-flushup: - $(MAKE) -C $(FREEDOM_QEMU_MODULE) flushup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ diff --git a/modules/freedom-qemu/Makefile b/modules/freedom-qemu/Makefile new file mode 100644 index 0000000..7464b54 --- /dev/null +++ b/modules/freedom-qemu/Makefile @@ -0,0 +1,421 @@ +# Setup the Freedom build script environment +include ../../scripts/Freedom.mk + +# Include version identifiers to build up the full version string +include Metadata.mk +PACKAGE_WORDING := QEMU +PACKAGE_HEADING := riscv-qemu +PACKAGE_VERSION := $(RISCV_QEMU_VERSION)-$(FREEDOM_QEMU_ID)$(EXTRA_SUFFIX) +PACKAGE_COMMENT := \# SiFive Freedom Package Properties File + +# Some special package configure flags for specific targets +$(WIN64)-rqemu-vars := PKG_CONFIG_PATH="$(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64))/lib/pkgconfig" CFLAGS="-L$(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64))/lib -I$(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64))/include" CPPFLAGS="-L$(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64))/lib -I$(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64))/include" +$(WIN64)-rqemu-vars-ext := PKG_CONFIG_PATH="$(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64))/lib/pkgconfig" CFLAGS="-L$(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64))/lib -I$(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64))/include" CPPFLAGS="-L$(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64))/lib -I$(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64))/include" +$(WIN64)-rqemu-host := --host=$(WIN64) +$(WIN64)-rqemu-cross := --cross-prefix=x86_64-w64-mingw32- +$(WIN64)-rqemu-bindir := /bin +$(WIN64)-gettext-configure := --enable-threads=windows +$(WIN64)-glib-configure := --enable-static --disable-shared +$(WIN64)-glib-vars := PKG_CONFIG_PATH="$(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64))/lib/pkgconfig" CFLAGS="-L$(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64))/lib -I$(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64))/include" +$(WIN64)-pixman-vars := PKG_CONFIG_PATH="$(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64))/lib/pkgconfig" CFLAGS="-L$(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64))/lib -I$(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64))/include" CPPFLAGS="-L$(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64))/lib -I$(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64))/include" +$(UBUNTU64)-rqemu-vars := PKG_CONFIG_LIBDIR="$(abspath $(OBJ_UBUNTU64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(UBUNTU64))/lib/pkgconfig" CFLAGS="-fPIC -I$(abspath $(OBJ_UBUNTU64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(UBUNTU64))/include -Wno-unused-result" CPPFLAGS="-fPIC -I$(abspath $(OBJ_UBUNTU64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(UBUNTU64))/include" QEMU_LDFLAGS="-L$(abspath $(OBJ_UBUNTU64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(UBUNTU64))/lib -L$(abspath $(OBJ_UBUNTU64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(UBUNTU64))/lib64" LIBS="-L$(abspath $(OBJ_UBUNTU64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(UBUNTU64))/lib -L$(abspath $(OBJ_UBUNTU64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(UBUNTU64))/lib64 -liconv" SIFIVE_LIBS_QGA="-L$(abspath $(OBJ_UBUNTU64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(UBUNTU64))/lib -L$(abspath $(OBJ_UBUNTU64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(UBUNTU64))/lib64 -liconv" +$(UBUNTU64)-rqemu-vars-ext := PKG_CONFIG_LIBDIR="$(abspath $(OBJ_UBUNTU64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(UBUNTU64))/lib/pkgconfig" CFLAGS="-fPIC -I$(abspath $(OBJ_UBUNTU64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(UBUNTU64))/include -Wno-unused-result" CPPFLAGS="-fPIC -I$(abspath $(OBJ_UBUNTU64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(UBUNTU64))/include" QEMU_LDFLAGS="-L$(abspath $(OBJ_UBUNTU64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(UBUNTU64))/lib -L$(abspath $(OBJ_UBUNTU64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(UBUNTU64))/lib64" LIBS="-L$(abspath $(OBJ_UBUNTU64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(UBUNTU64))/lib -L$(abspath $(OBJ_UBUNTU64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(UBUNTU64))/lib64 -lgmodule-2.0 -lffi -liconv -lresolv -ldl" SIFIVE_LIBS_QGA="-L$(abspath $(OBJ_UBUNTU64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(UBUNTU64))/lib -L$(abspath $(OBJ_UBUNTU64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(UBUNTU64))/lib64 -liconv" +$(UBUNTU64)-rqemu-host := --host=x86_64-linux-gnu +$(UBUNTU64)-zlib-configure := -static +$(UBUNTU64)-gettext-configure:= --enable-threads=posix +$(UBUNTU64)-glib-configure := --enable-static +$(UBUNTU64)-glib-vars := PKG_CONFIG_PATH="$(abspath $(OBJ_UBUNTU64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(UBUNTU64))/lib/pkgconfig" CFLAGS="-fPIC -L$(abspath $(OBJ_UBUNTU64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(UBUNTU64))/lib -I$(abspath $(OBJ_UBUNTU64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(UBUNTU64))/include" +$(UBUNTU64)-pixman-vars := CFLAGS="-fPIC" CPPFLAGS="-fPIC" +$(UBUNTU64)-deps-vars := CFLAGS="-fPIC" +$(DARWIN)-rqemu-vars := PKG_CONFIG_PATH="$(abspath $(OBJ_DARWIN)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(DARWIN))/lib/pkgconfig" CFLAGS="-I$(abspath $(OBJ_DARWIN)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(DARWIN))/include" CPPFLAGS="-I$(abspath $(OBJ_DARWIN)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(DARWIN))/include" QEMU_LDFLAGS="-L$(abspath $(OBJ_DARWIN)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(DARWIN))/lib" LIBS="-liconv -framework CoreFoundation -framework Carbon" SIFIVE_LIBS_QGA="-L$(abspath $(OBJ_DARWIN)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(DARWIN))/lib -liconv -framework CoreFoundation -framework Carbon" PATH=/usr/local/opt/gettext/bin:$(PATH) +$(DARWIN)-rqemu-vars-ext := PKG_CONFIG_PATH="$(abspath $(OBJ_DARWIN)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(DARWIN))/lib/pkgconfig" CFLAGS="-I$(abspath $(OBJ_DARWIN)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(DARWIN))/include" CPPFLAGS="-I$(abspath $(OBJ_DARWIN)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(DARWIN))/include" QEMU_LDFLAGS="-L$(abspath $(OBJ_DARWIN)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(DARWIN))/lib" LIBS="-lgmodule-2.0 -lffi -liconv -lresolv -framework CoreFoundation -framework Carbon" SIFIVE_LIBS_QGA="-L$(abspath $(OBJ_DARWIN)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(DARWIN))/lib -liconv -framework CoreFoundation -framework Carbon" PATH=/usr/local/opt/gettext/bin:$(PATH) +$(DARWIN)-gettext-configure := --enable-threads=posix +$(DARWIN)-glib-configure := --enable-static +$(DARWIN)-glib-vars := PKG_CONFIG_PATH="$(abspath $(OBJ_DARWIN)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(DARWIN))/lib/pkgconfig" CFLAGS="-L$(abspath $(OBJ_DARWIN)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(DARWIN))/lib -I$(abspath $(OBJ_DARWIN)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(DARWIN))/include" PATH=/usr/local/opt/gettext/bin:$(PATH) +$(REDHAT)-rqemu-vars := PKG_CONFIG_LIBDIR="$(abspath $(OBJ_REDHAT)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT))/lib/pkgconfig" CFLAGS="-fPIC -I$(abspath $(OBJ_REDHAT)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT))/include -Wno-unused-result" CPPFLAGS="-fPIC -I$(abspath $(OBJ_REDHAT)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT))/include" QEMU_LDFLAGS="-L$(abspath $(OBJ_REDHAT)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT))/lib -L$(abspath $(OBJ_REDHAT)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT))/lib64" LIBS="-L$(abspath $(OBJ_REDHAT)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT))/lib -L$(abspath $(OBJ_REDHAT)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT))/lib64 -liconv" SIFIVE_LIBS_QGA="-L$(abspath $(OBJ_REDHAT)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT))/lib -L$(abspath $(OBJ_REDHAT)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT))/lib64 -liconv" +$(REDHAT)-rqemu-vars-ext := PKG_CONFIG_LIBDIR="$(abspath $(OBJ_REDHAT)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT))/lib/pkgconfig" CFLAGS="-fPIC -I$(abspath $(OBJ_REDHAT)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT))/include -Wno-unused-result" CPPFLAGS="-fPIC -I$(abspath $(OBJ_REDHAT)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT))/include" QEMU_LDFLAGS="-L$(abspath $(OBJ_REDHAT)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT))/lib -L$(abspath $(OBJ_REDHAT)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT))/lib64" LIBS="-L$(abspath $(OBJ_REDHAT)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT))/lib -L$(abspath $(OBJ_REDHAT)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT))/lib64 -lgmodule-2.0 -lffi -liconv -lresolv -ldl" SIFIVE_LIBS_QGA="-L$(abspath $(OBJ_REDHAT)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT))/lib -L$(abspath $(OBJ_REDHAT)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT))/lib64 -liconv" +$(REDHAT)-zlib-configure := -static +$(REDHAT)-gettext-configure := --enable-threads=posix +$(REDHAT)-glib-configure := --enable-static +$(REDHAT)-glib-vars := PKG_CONFIG_PATH="$(abspath $(OBJ_REDHAT)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT))/lib/pkgconfig" CFLAGS="-fPIC -L$(abspath $(OBJ_REDHAT)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT))/lib -I$(abspath $(OBJ_REDHAT)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT))/include" +$(REDHAT)-pixman-vars := CFLAGS="-fPIC" CPPFLAGS="-fPIC" +$(REDHAT)-deps-vars := CFLAGS="-fPIC" + +# Setup the package targets and switch into secondary makefile targets +# Targets $(PACKAGE_HEADING)/install.stamp and $(PACKAGE_HEADING)/libs.stamp +include ../../scripts/Package.mk + +$(OBJDIR)/%/build/$(PACKAGE_HEADING)/install.stamp: \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/$(RISCV_QEMU_FOLDER)/build.stamp + $(eval $@_TARGET := $(patsubst $(OBJDIR)/%/build/$(PACKAGE_HEADING)/install.stamp,%,$@)) + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/install.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET),$@)) + $(eval $@_PROPERTIES := $(patsubst %/build/$(PACKAGE_HEADING)/install.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET).properties,$@)) + mkdir -p $(dir $@) + git log --format="[%ad] %s" > $(abspath $($@_INSTALL))/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET).changelog + rm -f $(abspath $($@_PROPERTIES)) + echo "$(PACKAGE_COMMENT)" > $(abspath $($@_PROPERTIES)) + echo "PACKAGE_TYPE = freedom-tools" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_DESC_SEG = $(PACKAGE_WORDING)" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_FIXED_ID = $(PACKAGE_HEADING)" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_BUILD_ID = $(FREEDOM_QEMU_ID)$(EXTRA_SUFFIX)" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_CORE_VER = $(RISCV_QEMU_VERSION)" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_TARGET = $($@_TARGET)" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_VENDOR = SiFive" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_RIGHTS = sifive-v00 eclipse-v20" >> $(abspath $($@_PROPERTIES)) + echo "RISCV_TAGS = $(FREEDOM_QEMU_RISCV_TAGS)" >> $(abspath $($@_PROPERTIES)) + echo "TOOLS_TAGS = $(FREEDOM_QEMU_TOOLS_TAGS)" >> $(abspath $($@_PROPERTIES)) + cp $(abspath $($@_PROPERTIES)) $(abspath $($@_INSTALL))/ + tclsh ../../scripts/check-maximum-path-length.tcl $(abspath $($@_INSTALL)) "$(PACKAGE_HEADING)" "$(RISCV_QEMU_VERSION)" "$(FREEDOM_QEMU_ID)$(EXTRA_SUFFIX)" + tclsh ../../scripts/check-same-name-different-case.tcl $(abspath $($@_INSTALL)) + date > $@ + +# We might need some extra target libraries for this package +$(OBJ_NATIVE)/build/$(PACKAGE_HEADING)/libs.stamp: \ + $(OBJ_NATIVE)/build/$(PACKAGE_HEADING)/install.stamp + date > $@ + +$(OBJ_WIN64)/build/$(PACKAGE_HEADING)/libs.stamp: \ + $(OBJ_WIN64)/build/$(PACKAGE_HEADING)/install.stamp + -$(WIN64)-gcc -print-search-dirs | grep ^programs | cut -d= -f2- | tr : "\n" | xargs -I {} find {} -iname "libwinpthread*.dll" | xargs cp -t $(OBJDIR)/$(WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64)/bin + -$(WIN64)-gcc -print-search-dirs | grep ^libraries | cut -d= -f2- | tr : "\n" | xargs -I {} find {} -iname "libgcc_s_seh*.dll" | xargs cp -t $(OBJDIR)/$(WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64)/bin + -$(WIN64)-gcc -print-search-dirs | grep ^libraries | cut -d= -f2- | tr : "\n" | xargs -I {} find {} -iname "libstdc*.dll" | xargs cp -t $(OBJDIR)/$(WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64)/bin + -$(WIN64)-gcc -print-search-dirs | grep ^libraries | cut -d= -f2- | tr : "\n" | xargs -I {} find {} -iname "libssp*.dll" | xargs cp -t $(OBJDIR)/$(WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64)/bin + date > $@ + +$(OBJDIR)/%/build/$(PACKAGE_HEADING)/source.stamp: + $(eval $@_TARGET := $(patsubst $(OBJDIR)/%/build/$(PACKAGE_HEADING)/source.stamp,%,$@)) + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/source.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET),$@)) + $(eval $@_BUILDLOG := $(abspath $(patsubst %/build/$(PACKAGE_HEADING)/source.stamp,%/buildlog/$(PACKAGE_HEADING),$@))) + $(eval $@_SRCBALL := $(abspath $(BINDIR)/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET).src.tar.gz)) + tclsh ../../scripts/check-naming-and-version-syntax.tcl "$(PACKAGE_WORDING)" "$(PACKAGE_HEADING)" "$(RISCV_QEMU_VERSION)" "$(FREEDOM_QEMU_ID)$(EXTRA_SUFFIX)" + rm -rf $($@_INSTALL) + mkdir -p $($@_INSTALL) + rm -rf $($@_BUILDLOG) + mkdir -p $($@_BUILDLOG) + rm -rf $(dir $@) + mkdir -p $(dir $@) + git log > $($@_BUILDLOG)/$(PACKAGE_HEADING)-git-commit.log + git remote -v > $($@_BUILDLOG)/$(PACKAGE_HEADING)-git-remote.log + cd $(dir $@); curl -L -f -s -o zlib-1.2.11.tar.gz http://zlib.net/fossils/zlib-1.2.11.tar.gz + cd $(dir $@); $(TAR) -xf zlib-1.2.11.tar.gz + cd $(dir $@); mv zlib-1.2.11 zlib + cd $(dir $@); curl -L -f -s -o libffi-3.2.1.tar.gz http://mirrors.kernel.org/sourceware/libffi/libffi-3.2.1.tar.gz + cd $(dir $@); $(TAR) -xf libffi-3.2.1.tar.gz + cd $(dir $@); mv libffi-3.2.1 libffi + cd $(dir $@); curl -L -f -s -o libiconv-1.15.tar.gz https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.15.tar.gz + cd $(dir $@); $(TAR) -xf libiconv-1.15.tar.gz + cd $(dir $@); mv libiconv-1.15 libiconv + cd $(dir $@); curl -L -f -s -o gettext-0.19.8.1.tar.gz https://ftp.gnu.org/pub/gnu/gettext/gettext-0.19.8.1.tar.gz + cd $(dir $@); $(TAR) -xf gettext-0.19.8.1.tar.gz + cd $(dir $@); mv gettext-0.19.8.1 gettext + cd $(dir $@); curl -L -f -s -o glib-2.56.4.tar.xz http://ftp.acc.umu.se/pub/GNOME/sources/glib/2.56/glib-2.56.4.tar.xz + cd $(dir $@); $(TAR) -xf glib-2.56.4.tar.xz + cd $(dir $@); mv glib-2.56.4 glib + cd $(dir $@); curl -L -f -s -o pixman-0.38.0.tar.gz https://cairographics.org/releases/pixman-0.38.0.tar.gz + cd $(dir $@); $(TAR) -xf pixman-0.38.0.tar.gz + cd $(dir $@); mv pixman-0.38.0 pixman + git clone --single-branch --branch $(RISCV_QEMU_BRANCH) $(RISCV_QEMU_GITURL) $(dir $@)/$(RISCV_QEMU_FOLDER) + cd $(dir $@)/$(RISCV_QEMU_FOLDER) && git checkout --detach $(RISCV_QEMU_COMMIT) + cd $(dir $@)/$(RISCV_QEMU_FOLDER) && git submodule update --init --recursive + rm -rf $(dir $@)/$(RISCV_QEMU_FOLDER)/target/riscv/cpu.c + cp -a patches/qemu-riscv-cpu.c $(dir $@)/$(RISCV_QEMU_FOLDER)/target/riscv/cpu.c + rm -rf $(dir $@)/$(RISCV_QEMU_FOLDER)/target/riscv/cpu.h + cp -a patches/qemu-riscv-cpu.h $(dir $@)/$(RISCV_QEMU_FOLDER)/target/riscv/cpu.h + rm -rf $(dir $@)/$(RISCV_QEMU_FOLDER)/hw/riscv/sifive_e.c + cp -a patches/qemu-sifive-e.c $(dir $@)/$(RISCV_QEMU_FOLDER)/hw/riscv/sifive_e.c + rm -rf $(dir $@)/$(RISCV_QEMU_FOLDER)/hw/riscv/sifive_test.c + cp -a patches/qemu-sifive-test.c $(dir $@)/$(RISCV_QEMU_FOLDER)/hw/misc/sifive_test.c + rm -rf $(dir $@)/$(RISCV_QEMU_FOLDER)/hw/riscv/sifive_u.c + cp -a patches/qemu-sifive-u.c $(dir $@)/$(RISCV_QEMU_FOLDER)/hw/riscv/sifive_u.c + rm -rf $(dir $@)/$(RISCV_QEMU_FOLDER)/include/hw/riscv/sifive_e.h + cp -a patches/qemu-sifive-e.h $(dir $@)/$(RISCV_QEMU_FOLDER)/include/hw/riscv/sifive_e.h + rm -rf $(dir $@)/$(RISCV_QEMU_FOLDER)/include/hw/riscv/sifive_u.h + cp -a patches/qemu-sifive-u.h $(dir $@)/$(RISCV_QEMU_FOLDER)/include/hw/riscv/sifive_u.h + rm -rf $(dir $@)/$(RISCV_QEMU_FOLDER)/util/meson.build + cp -a patches/qemu-util-meson.build $(dir $@)/$(RISCV_QEMU_FOLDER)/util/meson.build + rm -rf $(dir $@)/$(RISCV_QEMU_FOLDER)/net/can/meson.build + cp -a patches/qemu-net-can-meson.build $(dir $@)/$(RISCV_QEMU_FOLDER)/net/can/meson.build + $(SED) -i -f patches/qemu-configure.sed $(dir $@)/$(RISCV_QEMU_FOLDER)/configure + $(SED) -i -f patches/qemu-common.sed $(dir $@)/$(RISCV_QEMU_FOLDER)/include/qemu-common.h + $(SED) -i -f patches/qemu-vl.sed $(dir $@)/$(RISCV_QEMU_FOLDER)/softmmu/vl.c + mkdir -p $(dir $($@_SRCBALL)) + cd $(dir $@); $(TAR) --dereference --hard-dereference -c zlib libffi libiconv gettext glib pixman $(RISCV_QEMU_FOLDER) | gzip > $($@_SRCBALL) + date > $@ + +$(OBJ_NATIVE)/build/$(PACKAGE_HEADING)/zlib/build.stamp: \ + $(OBJ_NATIVE)/build/$(PACKAGE_HEADING)/source.stamp + $(eval $@_BUILDLOG := $(abspath $(patsubst %/build/$(PACKAGE_HEADING)/zlib/build.stamp,%/buildlog/$(PACKAGE_HEADING),$@))) + cd $(dir $@) && $($(NATIVE)-deps-vars) ./configure \ + --prefix=$(abspath $(OBJ_NATIVE)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(NATIVE)) \ + $($(NATIVE)-zlib-configure) &>$($@_BUILDLOG)/zlib-make-configure.log + $(MAKE) -C $(dir $@) &>$($@_BUILDLOG)/zlib-make-build.log + $(MAKE) -C $(dir $@) -j1 install &>$($@_BUILDLOG)/zlib-make-install.log + date > $@ + +$(OBJ_WIN64)/build/$(PACKAGE_HEADING)/zlib/build.stamp: \ + $(OBJ_WIN64)/build/$(PACKAGE_HEADING)/source.stamp + $(eval $@_BUILDLOG := $(abspath $(patsubst %/build/$(PACKAGE_HEADING)/zlib/build.stamp,%/buildlog/$(PACKAGE_HEADING),$@))) + $(MAKE) -C $(dir $@) -f win32/Makefile.gcc PREFIX=$(WIN64)- prefix=$(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64))/ &>$($@_BUILDLOG)/zlib-make-build.log + $(MAKE) -j1 -C $(dir $@) -f win32/Makefile.gcc SHARED_MODE=1 install DESTDIR=$(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64))/ INCLUDE_PATH=include LIBRARY_PATH=lib BINARY_PATH=bin &>$($@_BUILDLOG)/zlib-make-install.log + date > $@ + +$(OBJDIR)/%/build/$(PACKAGE_HEADING)/libffi/build.stamp: \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/zlib/build.stamp \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/source.stamp + $(eval $@_TARGET := $(patsubst $(OBJDIR)/%/build/$(PACKAGE_HEADING)/libffi/build.stamp,%,$@)) + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/libffi/build.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET),$@)) + $(eval $@_BUILD := $(patsubst %/build/$(PACKAGE_HEADING)/libffi/build.stamp,%/build/$(PACKAGE_HEADING),$@)) + $(eval $@_BUILDLOG := $(abspath $(patsubst %/build/$(PACKAGE_HEADING)/libffi/build.stamp,%/buildlog/$(PACKAGE_HEADING),$@))) + cd $(dir $@) && $($($@_TARGET)-deps-vars) ./configure \ + $($($@_TARGET)-rqemu-host) \ + --prefix=$(abspath $($@_INSTALL)) \ + --enable-static &>$($@_BUILDLOG)/libffi-make-configure.log + $(MAKE) -C $(dir $@) &>$($@_BUILDLOG)/libffi-make-build.log + $(MAKE) -C $(dir $@) -j1 install &>$($@_BUILDLOG)/libffi-make-install.log + date > $@ + +$(OBJDIR)/%/build/$(PACKAGE_HEADING)/libiconv/build.stamp: \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/libffi/build.stamp \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/source.stamp + $(eval $@_TARGET := $(patsubst $(OBJDIR)/%/build/$(PACKAGE_HEADING)/libiconv/build.stamp,%,$@)) + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/libiconv/build.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET),$@)) + $(eval $@_BUILD := $(patsubst %/build/$(PACKAGE_HEADING)/libiconv/build.stamp,%/build/$(PACKAGE_HEADING),$@)) + $(eval $@_BUILDLOG := $(abspath $(patsubst %/build/$(PACKAGE_HEADING)/libiconv/build.stamp,%/buildlog/$(PACKAGE_HEADING),$@))) + cd $(dir $@) && $($($@_TARGET)-deps-vars) ./configure \ + $($($@_TARGET)-rqemu-host) \ + --prefix=$(abspath $($@_INSTALL)) \ + --enable-static &>$($@_BUILDLOG)/libiconv-make-configure.log + $(MAKE) -C $(dir $@) &>$($@_BUILDLOG)/libiconv-make-build.log + $(MAKE) -C $(dir $@) -j1 install &>$($@_BUILDLOG)/libiconv-make-install.log + date > $@ + +$(OBJ_NATIVE)/build/$(PACKAGE_HEADING)/gettext/build.stamp: \ + $(OBJ_NATIVE)/build/$(PACKAGE_HEADING)/libiconv/build.stamp \ + $(OBJ_NATIVE)/build/$(PACKAGE_HEADING)/source.stamp + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/gettext/build.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(NATIVE),$@)) + $(eval $@_BUILD := $(patsubst %/build/$(PACKAGE_HEADING)/gettext/build.stamp,%/build/$(PACKAGE_HEADING),$@)) + $(eval $@_BUILDLOG := $(abspath $(patsubst %/build/$(PACKAGE_HEADING)/gettext/build.stamp,%/buildlog/$(PACKAGE_HEADING),$@))) + cd $(dir $@) && $($(NATIVE)-deps-vars) ./configure \ + $($(NATIVE)-rqemu-host) \ + --prefix=$(abspath $($@_INSTALL)) \ + --enable-static \ + $($(NATIVE)-gettext-configure) &>$($@_BUILDLOG)/gettext-make-configure.log + $(MAKE) -C $(dir $@) &>$($@_BUILDLOG)/gettext-make-build.log + $(MAKE) -C $(dir $@) -j1 install &>$($@_BUILDLOG)/gettext-make-install.log + date > $@ + +$(OBJ_WIN64)/build/$(PACKAGE_HEADING)/gettext/build.stamp: \ + $(OBJ_WIN64)/build/$(PACKAGE_HEADING)/libiconv/build.stamp \ + $(OBJ_WIN64)/build/$(PACKAGE_HEADING)/source.stamp + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/gettext/build.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64),$@)) + $(eval $@_BUILD := $(patsubst %/build/$(PACKAGE_HEADING)/gettext/build.stamp,%/build/$(PACKAGE_HEADING),$@)) + $(eval $@_BUILDLOG := $(abspath $(patsubst %/build/$(PACKAGE_HEADING)/gettext/build.stamp,%/buildlog/$(PACKAGE_HEADING),$@))) + # https://spacegit.unibe.ch/open-source/crosstool-ng/blob/a1b4ec3b176683817ba128ebb87117725cfa5d20/patches/gettext/0.19.6/110-Fix-linker-error-redefinition-of-vasprintf.patch + $(SED) -i -f patches/gettext-gnu-source.sed $(dir $@)/gettext-runtime/libasprintf/autosprintf.cc + $(SED) -i -f patches/gettext-gnu-source.sed $(dir $@)/gettext-runtime/libasprintf/vasnprintf.c + cd $(dir $@) && $($(WIN64)-deps-vars) ./configure \ + $($(WIN64)-rqemu-host) \ + --prefix=$(abspath $($@_INSTALL)) \ + --enable-static \ + $($(WIN64)-gettext-configure) &>$($@_BUILDLOG)/gettext-make-configure.log + $(MAKE) -C $(dir $@) &>$($@_BUILDLOG)/gettext-make-build.log + $(MAKE) -C $(dir $@) -j1 install &>$($@_BUILDLOG)/gettext-make-install.log + date > $@ + +$(OBJ_NATIVE)/build/$(PACKAGE_HEADING)/glib/build.stamp: \ + $(OBJ_NATIVE)/build/$(PACKAGE_HEADING)/gettext/build.stamp \ + $(OBJ_NATIVE)/build/$(PACKAGE_HEADING)/source.stamp + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/glib/build.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(NATIVE),$@)) + $(eval $@_BUILD := $(patsubst %/build/$(PACKAGE_HEADING)/glib/build.stamp,%/build/$(PACKAGE_HEADING),$@)) + $(eval $@_BUILDLOG := $(abspath $(patsubst %/build/$(PACKAGE_HEADING)/glib/build.stamp,%/buildlog/$(PACKAGE_HEADING),$@))) + mkdir -p $(dir $@)/gio/lib + cd $(dir $@) && $($(NATIVE)-glib-vars) ./configure \ + $($(NATIVE)-rqemu-host) \ + --prefix=$(abspath $($@_INSTALL)) \ + $($(NATIVE)-glib-configure) \ + --with-libiconv=gnu \ + --without-pcre \ + --disable-selinux \ + --disable-fam \ + --disable-xattr \ + --disable-libelf \ + --disable-libmount \ + --disable-dtrace \ + --disable-systemtap \ + --disable-coverage \ + --disable-Bsymbolic \ + --disable-znodelete \ + --disable-compile-warnings \ + --disable-installed-tests \ + --disable-always-build-tests &>$($@_BUILDLOG)/glib-make-configure.log + $(MAKE) -C $(dir $@) &>$($@_BUILDLOG)/glib-make-build.log + $(MAKE) -C $(dir $@) -j1 install &>$($@_BUILDLOG)/glib-make-install.log + rm -rf $(abspath $($@_INSTALL))/share/gdb + date > $@ + +$(OBJ_WIN64)/build/$(PACKAGE_HEADING)/glib/build.stamp: \ + $(OBJ_WIN64)/build/$(PACKAGE_HEADING)/gettext/build.stamp \ + $(OBJ_WIN64)/build/$(PACKAGE_HEADING)/source.stamp + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/glib/build.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64),$@)) + $(eval $@_BUILD := $(patsubst %/build/$(PACKAGE_HEADING)/glib/build.stamp,%/build/$(PACKAGE_HEADING),$@)) + $(eval $@_BUILDLOG := $(abspath $(patsubst %/build/$(PACKAGE_HEADING)/glib/build.stamp,%/buildlog/$(PACKAGE_HEADING),$@))) + mkdir -p $(dir $@)/gio/lib + $(SED) -i -f patches/glib-var-extern.sed $(dir $@)/glib/gtypes.h + # https://github.com/msys2/MINGW-packages/blob/master/mingw-w64-glib2/0001-win32-Make-the-static-build-work-with-MinGW-when-pos.patch + $(SED) -i -f patches/glib-dllmain-off.sed $(dir $@)/glib/glib-init.c + $(SED) -i -f patches/glib-dllmain-off.sed $(dir $@)/gobject/gtype.c + cd $(dir $@) && $($(WIN64)-glib-vars) ./configure \ + $($(WIN64)-rqemu-host) \ + --prefix=$(abspath $($@_INSTALL)) \ + $($(WIN64)-glib-configure) \ + --with-libiconv=gnu \ + --without-pcre \ + --disable-selinux \ + --disable-fam \ + --disable-xattr \ + --disable-libelf \ + --disable-libmount \ + --disable-dtrace \ + --disable-systemtap \ + --disable-coverage \ + --disable-Bsymbolic \ + --disable-znodelete \ + --disable-compile-warnings \ + --disable-installed-tests \ + --disable-always-build-tests &>$($@_BUILDLOG)/glib-make-configure.log + $(MAKE) -C $(dir $@) &>$($@_BUILDLOG)/glib-make-build.log + $(MAKE) -C $(dir $@) -j1 install &>$($@_BUILDLOG)/glib-make-install.log + rm -rf $(abspath $($@_INSTALL))/share/gdb + date > $@ + +$(OBJDIR)/%/build/$(PACKAGE_HEADING)/pixman/build.stamp: \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/libffi/build.stamp \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/source.stamp + $(eval $@_TARGET := $(patsubst $(OBJDIR)/%/build/$(PACKAGE_HEADING)/pixman/build.stamp,%,$@)) + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/pixman/build.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET),$@)) + $(eval $@_BUILD := $(patsubst %/build/$(PACKAGE_HEADING)/pixman/build.stamp,%/build/$(PACKAGE_HEADING),$@)) + $(eval $@_BUILDLOG := $(abspath $(patsubst %/build/$(PACKAGE_HEADING)/pixman/build.stamp,%/buildlog/$(PACKAGE_HEADING),$@))) + mkdir -p $(dir $@)/test/lib + cd $(dir $@) && $($($@_TARGET)-pixman-vars) ./configure \ + $($($@_TARGET)-rqemu-host) \ + --prefix=$(abspath $($@_INSTALL)) \ + --enable-static \ + --with-gnu-ld \ + --disable-static-testprogs &>$($@_BUILDLOG)/pixman-make-configure.log + $(MAKE) -C $(dir $@) &>$($@_BUILDLOG)/pixman-make-build.log + $(MAKE) -C $(dir $@) -j1 install &>$($@_BUILDLOG)/pixman-make-install.log + date > $@ + +$(OBJDIR)/%/build/$(PACKAGE_HEADING)/$(RISCV_QEMU_FOLDER)/build.stamp: \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/glib/build.stamp \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/pixman/build.stamp \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/source.stamp + $(eval $@_TARGET := $(patsubst $(OBJDIR)/%/build/$(PACKAGE_HEADING)/$(RISCV_QEMU_FOLDER)/build.stamp,%,$@)) + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/$(RISCV_QEMU_FOLDER)/build.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET),$@)) + $(eval $@_BUILD := $(patsubst %/build/$(PACKAGE_HEADING)/$(RISCV_QEMU_FOLDER)/build.stamp,%/build/$(PACKAGE_HEADING),$@)) + $(eval $@_BUILDLOG := $(abspath $(patsubst %/build/$(PACKAGE_HEADING)/$(RISCV_QEMU_FOLDER)/build.stamp,%/buildlog/$(PACKAGE_HEADING),$@))) + rm -f $(abspath $($@_INSTALL))/lib/lib*.dylib* + rm -f $(abspath $($@_INSTALL))/lib/lib*.so* + rm -f $(abspath $($@_INSTALL))/lib64/lib*.so* + cd $(dir $@) && $($($@_TARGET)-rqemu-vars) ./configure \ + $($($@_TARGET)-rqemu-cross) \ + --prefix=$(abspath $($@_INSTALL))$($($@_TARGET)-rqemu-bindir) \ + --with-pkgversion="SiFive QEMU $(PACKAGE_VERSION)" \ + --target-list=riscv32-softmmu,riscv64-softmmu \ + --interp-prefix=$(abspath $($@_INSTALL))/sysroot \ + --disable-docs \ + --disable-modules \ + --disable-module-upgrades \ + --disable-sparse \ + --disable-safe-stack \ + --disable-gnutls \ + --disable-nettle \ + --disable-gcrypt \ + --disable-auth-pam \ + --disable-sdl \ + --disable-sdl-image \ + --disable-gtk \ + --disable-vte \ + --disable-vnc-sasl \ + --disable-vnc-jpeg \ + --disable-vnc-png \ + --disable-virtfs \ + --disable-mpath \ + --disable-xen \ + --disable-xen-pci-passthrough \ + --disable-brlapi \ + --disable-curl \ + --disable-membarrier \ + --disable-rdma \ + --disable-pvrdma \ + --disable-vde \ + --disable-netmap \ + --disable-linux-aio \ + --disable-linux-io-uring \ + --disable-cap-ng \ + --disable-vhost-kernel \ + --disable-vhost-user \ + --disable-vhost-user-blk-server \ + --disable-vhost-vdpa \ + --disable-spice \ + --disable-rbd \ + --disable-libiscsi \ + --disable-libnfs \ + --disable-smartcard \ + --disable-libusb \ + --disable-usb-redir \ + --disable-lzo \ + --disable-snappy \ + --disable-bzip2 \ + --disable-lzfse \ + --disable-zstd \ + --disable-seccomp \ + --disable-glusterfs \ + --disable-tpm \ + --disable-libssh \ + --disable-numa \ + --disable-libxml2 \ + --disable-tcmalloc \ + --disable-jemalloc \ + --disable-avx2 \ + --disable-avx512f \ + --disable-opengl \ + --disable-virglrenderer \ + --disable-xfsctl \ + --disable-crypto-afalg \ + --disable-debug-mutex \ + --disable-libpmem \ + --disable-libdaxctl \ + --disable-curses \ + --disable-iconv \ + --enable-vnc \ + --enable-bochs \ + --enable-cloop \ + --enable-dmg \ + --enable-qcow1 \ + --enable-vdi \ + --enable-vvfat \ + --enable-qed \ + --enable-parallels \ + --enable-sheepdog \ + --enable-rng-none \ + --enable-fdt=git \ + &>$($@_BUILDLOG)/$(RISCV_QEMU_FOLDER)-make-configure.log + $($($@_TARGET)-rqemu-vars-ext) $(MAKE) -C $(dir $@) -j1 install &>$($@_BUILDLOG)/$(RISCV_QEMU_FOLDER)-make-install.log + tclsh ../../scripts/dyn-lib-check-$($@_TARGET).tcl $(abspath $($@_INSTALL))/bin/qemu-edid + tclsh ../../scripts/dyn-lib-check-$($@_TARGET).tcl $(abspath $($@_INSTALL))/bin/qemu-ga + tclsh ../../scripts/dyn-lib-check-$($@_TARGET).tcl $(abspath $($@_INSTALL))/bin/qemu-img + tclsh ../../scripts/dyn-lib-check-$($@_TARGET).tcl $(abspath $($@_INSTALL))/bin/qemu-io + tclsh ../../scripts/dyn-lib-check-$($@_TARGET).tcl $(abspath $($@_INSTALL))/bin/qemu-nbd + tclsh ../../scripts/dyn-lib-check-$($@_TARGET).tcl $(abspath $($@_INSTALL))/bin/qemu-storage-daemon + tclsh ../../scripts/dyn-lib-check-$($@_TARGET).tcl $(abspath $($@_INSTALL))/bin/qemu-system-riscv32 + tclsh ../../scripts/dyn-lib-check-$($@_TARGET).tcl $(abspath $($@_INSTALL))/bin/qemu-system-riscv64 + date > $@ + +$(OBJDIR)/$(NATIVE)/test/$(PACKAGE_HEADING)/test.stamp: \ + $(OBJDIR)/$(NATIVE)/test/$(PACKAGE_HEADING)/launch.stamp + mkdir -p $(dir $@) + PATH=$(abspath $(OBJDIR)/$(NATIVE)/launch/$(PACKAGE_TARNAME)/bin):$(PATH) qemu-system-riscv32 -version + PATH=$(abspath $(OBJDIR)/$(NATIVE)/launch/$(PACKAGE_TARNAME)/bin):$(PATH) qemu-system-riscv64 -version + @echo "Finished testing $(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(NATIVE).tar.gz tarball" + date > $@ diff --git a/modules/freedom-qemu/Metadata.mk b/modules/freedom-qemu/Metadata.mk new file mode 100644 index 0000000..7d39f09 --- /dev/null +++ b/modules/freedom-qemu/Metadata.mk @@ -0,0 +1,15 @@ +# Git repos, branches, commits and folders to get source code for the tool we are building +RISCV_QEMU_GITURL := git@github.com:sifive/qemu.git +RISCV_QEMU_BRANCH := v5.2.0-rvv-rvb-zfh +RISCV_QEMU_COMMIT := 3870dd3ef58a5c74673388785ad3bfa655af23a4 +RISCV_QEMU_FOLDER := riscv-qemu + +# Version number, which should match the official version of the tool we are building +RISCV_QEMU_VERSION := 5.2.0 + +# Customization ID, which should identify the customization added to the original by SiFive +FREEDOM_QEMU_ID := 2020.12.0-preview1 + +# Characteristic tags, which should be usable for matching up providers and consumers +FREEDOM_QEMU_RISCV_TAGS = rv32i rv64i m a f d c v zfh zba zbb +FREEDOM_QEMU_TOOLS_TAGS = qemu diff --git a/modules/freedom-qemu/Monorepo.mk b/modules/freedom-qemu/Monorepo.mk new file mode 100644 index 0000000..82bb650 --- /dev/null +++ b/modules/freedom-qemu/Monorepo.mk @@ -0,0 +1,35 @@ +.PHONY: qemu qemu-package qemu-native-package qemu-cross-package +.PHONY: qemu-regress +.PHONY: qemu-cleanup qemu-native-cleanup qemu-cross-cleanup +.PHONY: qemu-flushup qemu-native-flushup qemu-cross-flushup +qemu: qemu-package + +qemu-package: + $(MAKE) -C modules/freedom-qemu package BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) + +qemu-native-package: + $(MAKE) -C modules/freedom-qemu native-package BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) + +qemu-cross-package: + $(MAKE) -C modules/freedom-qemu cross-package BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) + +qemu-regress: + $(MAKE) -C modules/freedom-qemu regress BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) + +qemu-cleanup: + $(MAKE) -C modules/freedom-qemu cleanup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + +qemu-native-cleanup: + $(MAKE) -C modules/freedom-qemu native-cleanup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + +qemu-cross-cleanup: + $(MAKE) -C modules/freedom-qemu cross-cleanup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + +qemu-flushup: + $(MAKE) -C modules/freedom-qemu flushup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + +qemu-native-flushup: + $(MAKE) -C modules/freedom-qemu native-flushup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + +qemu-cross-flushup: + $(MAKE) -C modules/freedom-qemu cross-flushup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ diff --git a/modules/freedom-qemu/patches/gettext-gnu-source.sed b/modules/freedom-qemu/patches/gettext-gnu-source.sed new file mode 100644 index 0000000..ab38c4e --- /dev/null +++ b/modules/freedom-qemu/patches/gettext-gnu-source.sed @@ -0,0 +1 @@ +s/ifndef _GNU_SOURCE/if \!defined\(_GNU_SOURCE\) \&\& \!defined\(_WIN32\)/ diff --git a/modules/freedom-qemu/patches/glib-dllmain-off.sed b/modules/freedom-qemu/patches/glib-dllmain-off.sed new file mode 100644 index 0000000..bbc2b74 --- /dev/null +++ b/modules/freedom-qemu/patches/glib-dllmain-off.sed @@ -0,0 +1,2 @@ +s/if defined (G_OS_WIN32)/if defined \(G_OS_WIN32_NATIVE\)/ +s/G_DEFINE_CONSTRUCTOR(glib_init_ctor)/HMODULE glib_dll\; G_DEFINE_CONSTRUCTOR\(glib_init_ctor\)/ diff --git a/modules/freedom-qemu/patches/glib-var-extern.sed b/modules/freedom-qemu/patches/glib-var-extern.sed new file mode 100644 index 0000000..4b1cbc5 --- /dev/null +++ b/modules/freedom-qemu/patches/glib-var-extern.sed @@ -0,0 +1 @@ +s/define GLIB_VAR _GLIB_EXTERN/define GLIB_VAR extern/ diff --git a/modules/freedom-qemu/patches/qemu-common.sed b/modules/freedom-qemu/patches/qemu-common.sed new file mode 100644 index 0000000..64e95a9 --- /dev/null +++ b/modules/freedom-qemu/patches/qemu-common.sed @@ -0,0 +1 @@ +s/See for how to report bugs\./For bug reports: https:\/\/github.com\/sifive\/freedom-tools\/issues/ diff --git a/modules/freedom-qemu/patches/qemu-configure.sed b/modules/freedom-qemu/patches/qemu-configure.sed new file mode 100644 index 0000000..d30bf0a --- /dev/null +++ b/modules/freedom-qemu/patches/qemu-configure.sed @@ -0,0 +1,2 @@ +s/GLIB_LIBS=$glib_libs/GLIB_LIBS=$glib_libs $SIFIVE_LIBS_QGA/ +s/LIBS_QGA=$libs_qga/LIBS_QGA=$libs_qga $SIFIVE_LIBS_QGA/ diff --git a/modules/freedom-qemu/patches/qemu-net-can-meson.build b/modules/freedom-qemu/patches/qemu-net-can-meson.build new file mode 100644 index 0000000..cb7f7cd --- /dev/null +++ b/modules/freedom-qemu/patches/qemu-net-can-meson.build @@ -0,0 +1,4 @@ +can_ss = ss.source_set() +can_ss.add(files('can_core.c', 'can_host.c')) + +softmmu_ss.add_all(when: 'CONFIG_CAN_BUS', if_true: can_ss) diff --git a/modules/freedom-qemu/patches/qemu-riscv-cpu.c b/modules/freedom-qemu/patches/qemu-riscv-cpu.c new file mode 100644 index 0000000..a8e6878 --- /dev/null +++ b/modules/freedom-qemu/patches/qemu-riscv-cpu.c @@ -0,0 +1,669 @@ +/* + * QEMU RISC-V CPU + * + * Copyright (c) 2016-2017 Sagar Karandikar, sagark@eecs.berkeley.edu + * Copyright (c) 2017-2018 SiFive, Inc. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2 or later, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#include "qemu/osdep.h" +#include "qemu/qemu-print.h" +#include "qemu/ctype.h" +#include "qemu/log.h" +#include "cpu.h" +#include "internals.h" +#include "exec/exec-all.h" +#include "qapi/error.h" +#include "qemu/error-report.h" +#include "hw/qdev-properties.h" +#include "migration/vmstate.h" +#include "fpu/softfloat-helpers.h" + +/* RISC-V CPU definitions */ + +static const char riscv_exts[26] = "IEMAFDQCLBJTPVNSUHKORWXYZG"; + +const char * const riscv_int_regnames[] = { + "x0/zero", "x1/ra", "x2/sp", "x3/gp", "x4/tp", "x5/t0", "x6/t1", + "x7/t2", "x8/s0", "x9/s1", "x10/a0", "x11/a1", "x12/a2", "x13/a3", + "x14/a4", "x15/a5", "x16/a6", "x17/a7", "x18/s2", "x19/s3", "x20/s4", + "x21/s5", "x22/s6", "x23/s7", "x24/s8", "x25/s9", "x26/s10", "x27/s11", + "x28/t3", "x29/t4", "x30/t5", "x31/t6" +}; + +const char * const riscv_fpr_regnames[] = { + "f0/ft0", "f1/ft1", "f2/ft2", "f3/ft3", "f4/ft4", "f5/ft5", + "f6/ft6", "f7/ft7", "f8/fs0", "f9/fs1", "f10/fa0", "f11/fa1", + "f12/fa2", "f13/fa3", "f14/fa4", "f15/fa5", "f16/fa6", "f17/fa7", + "f18/fs2", "f19/fs3", "f20/fs4", "f21/fs5", "f22/fs6", "f23/fs7", + "f24/fs8", "f25/fs9", "f26/fs10", "f27/fs11", "f28/ft8", "f29/ft9", + "f30/ft10", "f31/ft11" +}; + +const char * const riscv_excp_names[] = { + "misaligned_fetch", + "fault_fetch", + "illegal_instruction", + "breakpoint", + "misaligned_load", + "fault_load", + "misaligned_store", + "fault_store", + "user_ecall", + "supervisor_ecall", + "hypervisor_ecall", + "machine_ecall", + "exec_page_fault", + "load_page_fault", + "reserved", + "store_page_fault", + "reserved", + "reserved", + "reserved", + "reserved", + "guest_exec_page_fault", + "guest_load_page_fault", + "reserved", + "guest_store_page_fault", +}; + +const char * const riscv_intr_names[] = { + "u_software", + "s_software", + "vs_software", + "m_software", + "u_timer", + "s_timer", + "vs_timer", + "m_timer", + "u_external", + "vs_external", + "h_external", + "m_external", + "reserved", + "reserved", + "reserved", + "reserved" +}; + +const char *riscv_cpu_get_trap_name(target_ulong cause, bool async) +{ + if (async) { + return (cause < ARRAY_SIZE(riscv_intr_names)) ? + riscv_intr_names[cause] : "(unknown)"; + } else { + return (cause < ARRAY_SIZE(riscv_excp_names)) ? + riscv_excp_names[cause] : "(unknown)"; + } +} + +static void set_misa(CPURISCVState *env, target_ulong misa) +{ + env->misa_mask = env->misa = misa; +} + +static void set_priv_version(CPURISCVState *env, int priv_ver) +{ + env->priv_ver = priv_ver; +} + +static void set_vext_version(CPURISCVState *env, int vext_ver) +{ + env->vext_ver = vext_ver; +} + +static void set_feature(CPURISCVState *env, int feature) +{ + env->features |= (1ULL << feature); +} + +static void set_resetvec(CPURISCVState *env, int resetvec) +{ +#ifndef CONFIG_USER_ONLY + env->resetvec = resetvec; +#endif +} + +static void riscv_any_cpu_init(Object *obj) +{ + CPURISCVState *env = &RISCV_CPU(obj)->env; + set_misa(env, RVXLEN | RVI | RVM | RVA | RVF | RVD | RVC | RVU); + set_priv_version(env, PRIV_VERSION_1_11_0); +} + +static void riscv_base_cpu_init(Object *obj) +{ + CPURISCVState *env = &RISCV_CPU(obj)->env; + /* We set this in the realise function */ + set_misa(env, 0); +} + +#if defined(TARGET_RISCV64) + +static void rvxx_sifive_viu_cpu_init(Object *obj) +{ + CPURISCVState *env = &RISCV_CPU(obj)->env; + set_misa(env, RVXLEN | RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU | RVB | RVV | RVZfh); + set_priv_version(env, PRIV_VERSION_1_10_0); + set_vext_version(env, VEXT_VERSION_1_00_0); +} + +#endif + +static void rvxx_sifive_u_cpu_init(Object *obj) +{ + CPURISCVState *env = &RISCV_CPU(obj)->env; + set_misa(env, RVXLEN | RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU | RVB); + set_priv_version(env, PRIV_VERSION_1_10_0); +} + +static void rvxx_sifive_e_cpu_init(Object *obj) +{ + CPURISCVState *env = &RISCV_CPU(obj)->env; + set_misa(env, RVXLEN | RVI | RVM | RVA | RVC | RVU | RVB); + set_priv_version(env, PRIV_VERSION_1_10_0); + qdev_prop_set_bit(DEVICE(obj), "mmu", false); +} + +#if defined(TARGET_RISCV32) + +static void rv32_ibex_cpu_init(Object *obj) +{ + CPURISCVState *env = &RISCV_CPU(obj)->env; + set_misa(env, RV32 | RVI | RVM | RVC | RVU); + set_priv_version(env, PRIV_VERSION_1_10_0); + qdev_prop_set_bit(DEVICE(obj), "mmu", false); +} + +static void rv32_imafcu_nommu_cpu_init(Object *obj) +{ + CPURISCVState *env = &RISCV_CPU(obj)->env; + set_misa(env, RV32 | RVI | RVM | RVA | RVF | RVC | RVU | RVB); + set_priv_version(env, PRIV_VERSION_1_10_0); + set_resetvec(env, DEFAULT_RSTVEC); + qdev_prop_set_bit(DEVICE(obj), "mmu", false); +} + +#endif + +static ObjectClass *riscv_cpu_class_by_name(const char *cpu_model) +{ + ObjectClass *oc; + char *typename; + char **cpuname; + + cpuname = g_strsplit(cpu_model, ",", 1); + typename = g_strdup_printf(RISCV_CPU_TYPE_NAME("%s"), cpuname[0]); + oc = object_class_by_name(typename); + g_strfreev(cpuname); + g_free(typename); + if (!oc || !object_class_dynamic_cast(oc, TYPE_RISCV_CPU) || + object_class_is_abstract(oc)) { + return NULL; + } + return oc; +} + +static void riscv_cpu_dump_state(CPUState *cs, FILE *f, int flags) +{ + RISCVCPU *cpu = RISCV_CPU(cs); + CPURISCVState *env = &cpu->env; + int i; + +#if !defined(CONFIG_USER_ONLY) + if (riscv_has_ext(env, RVH)) { + qemu_fprintf(f, " %s %d\n", "V = ", riscv_cpu_virt_enabled(env)); + } +#endif + qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "pc ", env->pc); +#ifndef CONFIG_USER_ONLY + qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mhartid ", env->mhartid); + qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mstatus ", (target_ulong)env->mstatus); +#ifdef TARGET_RISCV32 + qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mstatush ", + (target_ulong)(env->mstatus >> 32)); +#endif + if (riscv_has_ext(env, RVH)) { + qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "hstatus ", env->hstatus); + qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "vsstatus ", + (target_ulong)env->vsstatus); + } + qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mip ", env->mip); + qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mie ", env->mie); + qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mideleg ", env->mideleg); + if (riscv_has_ext(env, RVH)) { + qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "hideleg ", env->hideleg); + } + qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "medeleg ", env->medeleg); + if (riscv_has_ext(env, RVH)) { + qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "hedeleg ", env->hedeleg); + } + qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mtvec ", env->mtvec); + qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "stvec ", env->stvec); + if (riscv_has_ext(env, RVH)) { + qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "vstvec ", env->vstvec); + } + qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mepc ", env->mepc); + qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "sepc ", env->sepc); + if (riscv_has_ext(env, RVH)) { + qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "vsepc ", env->vsepc); + } + qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mcause ", env->mcause); + qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "scause ", env->scause); + if (riscv_has_ext(env, RVH)) { + qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "vscause ", env->vscause); + } + qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mtval ", env->mtval); + qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "stval ", env->sbadaddr); + if (riscv_has_ext(env, RVH)) { + qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "htval ", env->htval); + qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mtval2 ", env->mtval2); + } +#endif + + for (i = 0; i < 32; i++) { + qemu_fprintf(f, " %s " TARGET_FMT_lx, + riscv_int_regnames[i], env->gpr[i]); + if ((i & 3) == 3) { + qemu_fprintf(f, "\n"); + } + } + if (flags & CPU_DUMP_FPU) { + for (i = 0; i < 32; i++) { + qemu_fprintf(f, " %s %016" PRIx64, + riscv_fpr_regnames[i], env->fpr[i]); + if ((i & 3) == 3) { + qemu_fprintf(f, "\n"); + } + } + } +} + +static void riscv_cpu_set_pc(CPUState *cs, vaddr value) +{ + RISCVCPU *cpu = RISCV_CPU(cs); + CPURISCVState *env = &cpu->env; + env->pc = value; +} + +static void riscv_cpu_synchronize_from_tb(CPUState *cs, TranslationBlock *tb) +{ + RISCVCPU *cpu = RISCV_CPU(cs); + CPURISCVState *env = &cpu->env; + env->pc = tb->pc; +} + +static bool riscv_cpu_has_work(CPUState *cs) +{ +#ifndef CONFIG_USER_ONLY + RISCVCPU *cpu = RISCV_CPU(cs); + CPURISCVState *env = &cpu->env; + /* + * Definition of the WFI instruction requires it to ignore the privilege + * mode and delegation registers, but respect individual enables + */ + return (env->mip & env->mie) != 0; +#else + return true; +#endif +} + +void restore_state_to_opc(CPURISCVState *env, TranslationBlock *tb, + target_ulong *data) +{ + env->pc = data[0]; +} + +static void riscv_cpu_reset(DeviceState *dev) +{ + CPUState *cs = CPU(dev); + RISCVCPU *cpu = RISCV_CPU(cs); + RISCVCPUClass *mcc = RISCV_CPU_GET_CLASS(cpu); + CPURISCVState *env = &cpu->env; + + mcc->parent_reset(dev); +#ifndef CONFIG_USER_ONLY + env->priv = PRV_M; + env->mstatus &= ~(MSTATUS_MIE | MSTATUS_MPRV); + env->mcause = 0; + env->pc = env->resetvec; +#endif + cs->exception_index = EXCP_NONE; + env->load_res = -1; + set_default_nan_mode(1, &env->fp_status); +} + +static void riscv_cpu_disas_set_info(CPUState *s, disassemble_info *info) +{ +#if defined(TARGET_RISCV32) + info->print_insn = print_insn_riscv32; +#elif defined(TARGET_RISCV64) + info->print_insn = print_insn_riscv64; +#endif +} + +static void riscv_cpu_realize(DeviceState *dev, Error **errp) +{ + CPUState *cs = CPU(dev); + RISCVCPU *cpu = RISCV_CPU(dev); + CPURISCVState *env = &cpu->env; + RISCVCPUClass *mcc = RISCV_CPU_GET_CLASS(dev); + int priv_version = PRIV_VERSION_1_11_0; + int vext_version = VEXT_VERSION_1_00_0; + target_ulong target_misa = 0; + Error *local_err = NULL; + + cpu_exec_realizefn(cs, &local_err); + if (local_err != NULL) { + error_propagate(errp, local_err); + return; + } + + if (cpu->cfg.priv_spec) { + if (!g_strcmp0(cpu->cfg.priv_spec, "v1.11.0")) { + priv_version = PRIV_VERSION_1_11_0; + } else if (!g_strcmp0(cpu->cfg.priv_spec, "v1.10.0")) { + priv_version = PRIV_VERSION_1_10_0; + } else { + error_setg(errp, + "Unsupported privilege spec version '%s'", + cpu->cfg.priv_spec); + return; + } + } + + set_priv_version(env, priv_version); + set_vext_version(env, vext_version); + + if (cpu->cfg.mmu) { + set_feature(env, RISCV_FEATURE_MMU); + } + + if (cpu->cfg.pmp) { + set_feature(env, RISCV_FEATURE_PMP); + } + + set_resetvec(env, cpu->cfg.resetvec); + + /* If misa isn't set (rv32 and rv64 machines) set it here */ + if (!env->misa) { + /* Do some ISA extension error checking */ + if (cpu->cfg.ext_i && cpu->cfg.ext_e) { + error_setg(errp, + "I and E extensions are incompatible"); + return; + } + + if (!cpu->cfg.ext_i && !cpu->cfg.ext_e) { + error_setg(errp, + "Either I or E extension must be set"); + return; + } + + if (cpu->cfg.ext_g && !(cpu->cfg.ext_i & cpu->cfg.ext_m & + cpu->cfg.ext_a & cpu->cfg.ext_f & + cpu->cfg.ext_d)) { + warn_report("Setting G will also set IMAFD"); + cpu->cfg.ext_i = true; + cpu->cfg.ext_m = true; + cpu->cfg.ext_a = true; + cpu->cfg.ext_f = true; + cpu->cfg.ext_d = true; + } + + /* Set the ISA extensions, checks should have happened above */ + if (cpu->cfg.ext_i) { + target_misa |= RVI; + } + if (cpu->cfg.ext_e) { + target_misa |= RVE; + } + if (cpu->cfg.ext_m) { + target_misa |= RVM; + } + if (cpu->cfg.ext_a) { + target_misa |= RVA; + } + if (cpu->cfg.ext_f) { + target_misa |= RVF; + } + if (cpu->cfg.ext_d) { + target_misa |= RVD; + } + if (cpu->cfg.ext_c) { + target_misa |= RVC; + } + if (cpu->cfg.ext_s) { + target_misa |= RVS; + } + if (cpu->cfg.ext_u) { + target_misa |= RVU; + } + if (cpu->cfg.ext_h) { + target_misa |= RVH; + } + if (cpu->cfg.ext_b) { + target_misa |= RVB; + } + if (cpu->cfg.ext_v) { + target_misa |= RVV; + if (!is_power_of_2(cpu->cfg.vlen)) { + error_setg(errp, + "Vector extension VLEN must be power of 2"); + return; + } + if (cpu->cfg.vlen > RV_VLEN_MAX || cpu->cfg.vlen < 128) { + error_setg(errp, + "Vector extension implementation only supports VLEN " + "in the range [128, %d]", RV_VLEN_MAX); + return; + } + if (!is_power_of_2(cpu->cfg.elen)) { + error_setg(errp, + "Vector extension ELEN must be power of 2"); + return; + } + if (cpu->cfg.elen > 64 || cpu->cfg.vlen < 8) { + error_setg(errp, + "Vector extension implementation only supports ELEN " + "in the range [8, 64]"); + return; + } + if (cpu->cfg.vext_spec) { + if (!g_strcmp0(cpu->cfg.vext_spec, "v1.0")) { + vext_version = VEXT_VERSION_1_00_0; + } else { + error_setg(errp, + "Unsupported vector spec version '%s'", + cpu->cfg.vext_spec); + return; + } + } else { + qemu_log("vector version is not specified, " + "use the default value v1.0\n"); + } + set_vext_version(env, vext_version); + } + if (cpu->cfg.ext_k) { + target_misa |= RVZfh; + } + + set_misa(env, RVXLEN | target_misa); + } + + riscv_cpu_register_gdb_regs_for_features(cs); + + qemu_init_vcpu(cs); + cpu_reset(cs); + + mcc->parent_realize(dev, errp); +} + +static void riscv_cpu_init(Object *obj) +{ + RISCVCPU *cpu = RISCV_CPU(obj); + + cpu_set_cpustate_pointers(cpu); +} + +static Property riscv_cpu_properties[] = { + DEFINE_PROP_BOOL("i", RISCVCPU, cfg.ext_i, true), + DEFINE_PROP_BOOL("e", RISCVCPU, cfg.ext_e, false), + DEFINE_PROP_BOOL("g", RISCVCPU, cfg.ext_g, true), + DEFINE_PROP_BOOL("m", RISCVCPU, cfg.ext_m, true), + DEFINE_PROP_BOOL("a", RISCVCPU, cfg.ext_a, true), + DEFINE_PROP_BOOL("f", RISCVCPU, cfg.ext_f, true), + DEFINE_PROP_BOOL("d", RISCVCPU, cfg.ext_d, true), + DEFINE_PROP_BOOL("c", RISCVCPU, cfg.ext_c, true), + DEFINE_PROP_BOOL("s", RISCVCPU, cfg.ext_s, true), + DEFINE_PROP_BOOL("u", RISCVCPU, cfg.ext_u, true), + /* This is experimental so mark with 'x-' */ + DEFINE_PROP_BOOL("x-b", RISCVCPU, cfg.ext_b, false), + DEFINE_PROP_BOOL("x-h", RISCVCPU, cfg.ext_h, false), + DEFINE_PROP_BOOL("x-v", RISCVCPU, cfg.ext_v, false), + DEFINE_PROP_BOOL("x-k", RISCVCPU, cfg.ext_k, false), + DEFINE_PROP_BOOL("Counters", RISCVCPU, cfg.ext_counters, true), + DEFINE_PROP_BOOL("Zifencei", RISCVCPU, cfg.ext_ifencei, true), + DEFINE_PROP_BOOL("Zicsr", RISCVCPU, cfg.ext_icsr, true), + DEFINE_PROP_STRING("priv_spec", RISCVCPU, cfg.priv_spec), + DEFINE_PROP_STRING("vext_spec", RISCVCPU, cfg.vext_spec), + DEFINE_PROP_UINT16("vlen", RISCVCPU, cfg.vlen, 512), + DEFINE_PROP_UINT16("elen", RISCVCPU, cfg.elen, 64), + DEFINE_PROP_BOOL("mmu", RISCVCPU, cfg.mmu, true), + DEFINE_PROP_BOOL("pmp", RISCVCPU, cfg.pmp, true), + DEFINE_PROP_UINT64("resetvec", RISCVCPU, cfg.resetvec, DEFAULT_RSTVEC), + DEFINE_PROP_END_OF_LIST(), +}; + +static void riscv_cpu_class_init(ObjectClass *c, void *data) +{ + RISCVCPUClass *mcc = RISCV_CPU_CLASS(c); + CPUClass *cc = CPU_CLASS(c); + DeviceClass *dc = DEVICE_CLASS(c); + + device_class_set_parent_realize(dc, riscv_cpu_realize, + &mcc->parent_realize); + + device_class_set_parent_reset(dc, riscv_cpu_reset, &mcc->parent_reset); + + cc->class_by_name = riscv_cpu_class_by_name; + cc->has_work = riscv_cpu_has_work; + cc->do_interrupt = riscv_cpu_do_interrupt; + cc->cpu_exec_interrupt = riscv_cpu_exec_interrupt; + cc->dump_state = riscv_cpu_dump_state; + cc->set_pc = riscv_cpu_set_pc; + cc->synchronize_from_tb = riscv_cpu_synchronize_from_tb; + cc->gdb_read_register = riscv_cpu_gdb_read_register; + cc->gdb_write_register = riscv_cpu_gdb_write_register; + cc->gdb_num_core_regs = 33; +#if defined(TARGET_RISCV32) + cc->gdb_core_xml_file = "riscv-32bit-cpu.xml"; +#elif defined(TARGET_RISCV64) + cc->gdb_core_xml_file = "riscv-64bit-cpu.xml"; +#endif + cc->gdb_get_dynamic_xml = riscv_gdb_get_dynamic_xml; + cc->gdb_stop_before_watchpoint = true; + cc->disas_set_info = riscv_cpu_disas_set_info; +#ifndef CONFIG_USER_ONLY + cc->do_transaction_failed = riscv_cpu_do_transaction_failed; + cc->do_unaligned_access = riscv_cpu_do_unaligned_access; + cc->get_phys_page_debug = riscv_cpu_get_phys_page_debug; + /* For now, mark unmigratable: */ + cc->vmsd = &vmstate_riscv_cpu; +#endif +#ifdef CONFIG_TCG + cc->tcg_initialize = riscv_translate_init; + cc->tlb_fill = riscv_cpu_tlb_fill; +#endif + device_class_set_props(dc, riscv_cpu_properties); +} + +char *riscv_isa_string(RISCVCPU *cpu) +{ + int i; + const size_t maxlen = sizeof("rv128") + sizeof(riscv_exts) + 1; + char *isa_str = g_new(char, maxlen); + char *p = isa_str + snprintf(isa_str, maxlen, "rv%d", TARGET_LONG_BITS); + for (i = 0; i < sizeof(riscv_exts); i++) { + if (cpu->env.misa & RV(riscv_exts[i])) { + *p++ = qemu_tolower(riscv_exts[i]); + } + } + *p = '\0'; + return isa_str; +} + +static gint riscv_cpu_list_compare(gconstpointer a, gconstpointer b) +{ + ObjectClass *class_a = (ObjectClass *)a; + ObjectClass *class_b = (ObjectClass *)b; + const char *name_a, *name_b; + + name_a = object_class_get_name(class_a); + name_b = object_class_get_name(class_b); + return strcmp(name_a, name_b); +} + +static void riscv_cpu_list_entry(gpointer data, gpointer user_data) +{ + const char *typename = object_class_get_name(OBJECT_CLASS(data)); + int len = strlen(typename) - strlen(RISCV_CPU_TYPE_SUFFIX); + + qemu_printf("%.*s\n", len, typename); +} + +void riscv_cpu_list(void) +{ + GSList *list; + + list = object_class_get_list(TYPE_RISCV_CPU, false); + list = g_slist_sort(list, riscv_cpu_list_compare); + g_slist_foreach(list, riscv_cpu_list_entry, NULL); + g_slist_free(list); +} + +#define DEFINE_CPU(type_name, initfn) \ + { \ + .name = type_name, \ + .parent = TYPE_RISCV_CPU, \ + .instance_init = initfn \ + } + +static const TypeInfo riscv_cpu_type_infos[] = { + { + .name = TYPE_RISCV_CPU, + .parent = TYPE_CPU, + .instance_size = sizeof(RISCVCPU), + .instance_align = __alignof__(RISCVCPU), + .instance_init = riscv_cpu_init, + .abstract = true, + .class_size = sizeof(RISCVCPUClass), + .class_init = riscv_cpu_class_init, + }, + DEFINE_CPU(TYPE_RISCV_CPU_ANY, riscv_any_cpu_init), +#if defined(TARGET_RISCV32) + DEFINE_CPU(TYPE_RISCV_CPU_BASE32, riscv_base_cpu_init), + DEFINE_CPU(TYPE_RISCV_CPU_IBEX, rv32_ibex_cpu_init), + DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_E31, rvxx_sifive_e_cpu_init), + DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_E34, rv32_imafcu_nommu_cpu_init), + DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_U34, rvxx_sifive_u_cpu_init), +#elif defined(TARGET_RISCV64) + DEFINE_CPU(TYPE_RISCV_CPU_BASE64, riscv_base_cpu_init), + DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_E51, rvxx_sifive_e_cpu_init), + DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_U54, rvxx_sifive_u_cpu_init), + DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_VIU75, rvxx_sifive_viu_cpu_init), +#endif +}; + +DEFINE_TYPES(riscv_cpu_type_infos) diff --git a/modules/freedom-qemu/patches/qemu-riscv-cpu.h b/modules/freedom-qemu/patches/qemu-riscv-cpu.h new file mode 100644 index 0000000..581fc8a --- /dev/null +++ b/modules/freedom-qemu/patches/qemu-riscv-cpu.h @@ -0,0 +1,537 @@ +/* + * QEMU RISC-V CPU + * + * Copyright (c) 2016-2017 Sagar Karandikar, sagark@eecs.berkeley.edu + * Copyright (c) 2017-2018 SiFive, Inc. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2 or later, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#ifndef RISCV_CPU_H +#define RISCV_CPU_H + +#include "hw/core/cpu.h" +#include "hw/registerfields.h" +#include "exec/cpu-defs.h" +#include "fpu/softfloat-types.h" +#include "qom/object.h" + +#define TCG_GUEST_DEFAULT_MO 0 + +#define TYPE_RISCV_CPU "riscv-cpu" + +#define RISCV_CPU_TYPE_SUFFIX "-" TYPE_RISCV_CPU +#define RISCV_CPU_TYPE_NAME(name) (name RISCV_CPU_TYPE_SUFFIX) +#define CPU_RESOLVING_TYPE TYPE_RISCV_CPU + +#define TYPE_RISCV_CPU_ANY RISCV_CPU_TYPE_NAME("any") +#define TYPE_RISCV_CPU_BASE32 RISCV_CPU_TYPE_NAME("rv32") +#define TYPE_RISCV_CPU_BASE64 RISCV_CPU_TYPE_NAME("rv64") +#define TYPE_RISCV_CPU_IBEX RISCV_CPU_TYPE_NAME("lowrisc-ibex") +#define TYPE_RISCV_CPU_SIFIVE_E31 RISCV_CPU_TYPE_NAME("sifive-e31") +#define TYPE_RISCV_CPU_SIFIVE_E34 RISCV_CPU_TYPE_NAME("sifive-e34") +#define TYPE_RISCV_CPU_SIFIVE_E51 RISCV_CPU_TYPE_NAME("sifive-e51") +#define TYPE_RISCV_CPU_SIFIVE_U34 RISCV_CPU_TYPE_NAME("sifive-u34") +#define TYPE_RISCV_CPU_SIFIVE_U54 RISCV_CPU_TYPE_NAME("sifive-u54") +#define TYPE_RISCV_CPU_SIFIVE_VIU75 RISCV_CPU_TYPE_NAME("sifive-viu75") + +#define RV32 ((target_ulong)1 << (TARGET_LONG_BITS - 2)) +#define RV64 ((target_ulong)2 << (TARGET_LONG_BITS - 2)) + +#if defined(TARGET_RISCV32) +#define RVXLEN RV32 +#elif defined(TARGET_RISCV64) +#define RVXLEN RV64 +#endif + +#define RV(x) ((target_ulong)1 << (x - 'A')) + +#define RVI RV('I') +#define RVE RV('E') /* E and I are mutually exclusive */ +#define RVM RV('M') +#define RVA RV('A') +#define RVB RV('B') +#define RVF RV('F') +#define RVD RV('D') +#define RVV RV('V') +#define RVC RV('C') +#define RVS RV('S') +#define RVU RV('U') +#define RVH RV('H') +#define RVZfh RV('K') + +/* S extension denotes that Supervisor mode exists, however it is possible + to have a core that support S mode but does not have an MMU and there + is currently no bit in misa to indicate whether an MMU exists or not + so a cpu features bitfield is required, likewise for optional PMP support */ +enum { + RISCV_FEATURE_MMU, + RISCV_FEATURE_PMP, + RISCV_FEATURE_MISA +}; + +#define PRIV_VERSION_1_10_0 0x00011000 +#define PRIV_VERSION_1_11_0 0x00011100 + +#define VEXT_VERSION_1_00_0 0x00010000 + +enum { + TRANSLATE_SUCCESS, + TRANSLATE_FAIL, + TRANSLATE_PMP_FAIL, + TRANSLATE_G_STAGE_FAIL +}; + +#define MMU_USER_IDX 3 + +#define MAX_RISCV_PMPS (16) + +typedef struct CPURISCVState CPURISCVState; + +#include "pmp.h" + +#define RV_VLEN_MAX 1024 + +FIELD(VTYPE, VLMUL, 0, 3) +FIELD(VTYPE, VSEW, 3, 3) +FIELD(VTYPE, VTA, 6, 1) +FIELD(VTYPE, VMA, 7, 1) +FIELD(VTYPE, VEDIV, 8, 2) +FIELD(VTYPE, RESERVED, 10, sizeof(target_ulong) * 8 - 11) +FIELD(VTYPE, VILL, sizeof(target_ulong) * 8 - 1, 1) + +/** + * DynamicGDBXMLInfo: + * @desc: Contains the XML descriptions. + * @num: Number of the registers in this XML seen by GDB. + */ +typedef struct DynamicGDBXMLInfo { + char *desc; + int num; +} DynamicGDBXMLInfo; + +struct CPURISCVState { + target_ulong gpr[32]; + uint64_t fpr[32]; /* assume both F and D extensions */ + + /* vector coprocessor state. */ + uint64_t vreg[32 * RV_VLEN_MAX / 64] QEMU_ALIGNED(16); + target_ulong vxrm; + target_ulong vxsat; + target_ulong vl; + target_ulong vstart; + target_ulong vtype; + + target_ulong pc; + target_ulong load_res; + target_ulong load_val; + + target_ulong frm; + + target_ulong badaddr; + target_ulong guest_phys_fault_addr; + + target_ulong priv_ver; + target_ulong vext_ver; + target_ulong misa; + target_ulong misa_mask; + + uint32_t features; + +#ifdef CONFIG_USER_ONLY + uint32_t elf_flags; +#endif + +#ifndef CONFIG_USER_ONLY + target_ulong priv; + /* This contains QEMU specific information about the virt state. */ + target_ulong virt; + target_ulong resetvec; + + target_ulong mhartid; + /* + * For RV32 this is 32-bit mstatus and 32-bit mstatush. + * For RV64 this is a 64-bit mstatus. + */ + uint64_t mstatus; + + target_ulong mip; + + uint32_t miclaim; + + target_ulong mie; + target_ulong mideleg; + + target_ulong sptbr; /* until: priv-1.9.1 */ + target_ulong satp; /* since: priv-1.10.0 */ + target_ulong sbadaddr; + target_ulong mbadaddr; + target_ulong medeleg; + + target_ulong stvec; + target_ulong sepc; + target_ulong scause; + + target_ulong mtvec; + target_ulong mepc; + target_ulong mcause; + target_ulong mtval; /* since: priv-1.10.0 */ + + /* Hypervisor CSRs */ + target_ulong hstatus; + target_ulong hedeleg; + target_ulong hideleg; + target_ulong hcounteren; + target_ulong htval; + target_ulong htinst; + target_ulong hgatp; + uint64_t htimedelta; + + /* Virtual CSRs */ + /* + * For RV32 this is 32-bit vsstatus and 32-bit vsstatush. + * For RV64 this is a 64-bit vsstatus. + */ + uint64_t vsstatus; + target_ulong vstvec; + target_ulong vsscratch; + target_ulong vsepc; + target_ulong vscause; + target_ulong vstval; + target_ulong vsatp; + + target_ulong mtval2; + target_ulong mtinst; + + /* HS Backup CSRs */ + target_ulong stvec_hs; + target_ulong sscratch_hs; + target_ulong sepc_hs; + target_ulong scause_hs; + target_ulong stval_hs; + target_ulong satp_hs; + uint64_t mstatus_hs; + + target_ulong scounteren; + target_ulong mcounteren; + + target_ulong sscratch; + target_ulong mscratch; + + /* temporary htif regs */ + uint64_t mfromhost; + uint64_t mtohost; + uint64_t timecmp; + + /* physical memory protection */ + pmp_table_t pmp_state; + + /* machine specific rdtime callback */ + uint64_t (*rdtime_fn)(uint32_t); + uint32_t rdtime_fn_arg; + + /* True if in debugger mode. */ + bool debugger; +#endif + + float_status fp_status; + + /* Fields from here on are preserved across CPU reset. */ + QEMUTimer *timer; /* Internal timer */ +}; + +OBJECT_DECLARE_TYPE(RISCVCPU, RISCVCPUClass, + RISCV_CPU) + +/** + * RISCVCPUClass: + * @parent_realize: The parent class' realize handler. + * @parent_reset: The parent class' reset handler. + * + * A RISCV CPU model. + */ +struct RISCVCPUClass { + /*< private >*/ + CPUClass parent_class; + /*< public >*/ + DeviceRealize parent_realize; + DeviceReset parent_reset; +}; + +/** + * RISCVCPU: + * @env: #CPURISCVState + * + * A RISCV CPU. + */ +struct RISCVCPU { + /*< private >*/ + CPUState parent_obj; + /*< public >*/ + CPUNegativeOffsetState neg; + CPURISCVState env; + + /* Configuration Settings */ + struct { + bool ext_i; + bool ext_e; + bool ext_g; + bool ext_m; + bool ext_a; + bool ext_f; + bool ext_d; + bool ext_c; + bool ext_b; + bool ext_s; + bool ext_u; + bool ext_h; + bool ext_v; + bool ext_k; + bool ext_counters; + bool ext_ifencei; + bool ext_icsr; + + char *priv_spec; + char *user_spec; + char *vext_spec; + uint16_t vlen; + uint16_t elen; + bool mmu; + bool pmp; + uint64_t resetvec; + } cfg; + + DynamicGDBXMLInfo dyn_vreg_xml; +}; + +static inline int riscv_has_ext(CPURISCVState *env, target_ulong ext) +{ + return (env->misa & ext) != 0; +} + +static inline bool riscv_feature(CPURISCVState *env, int feature) +{ + return env->features & (1ULL << feature); +} + +#include "cpu_user.h" +#include "cpu_bits.h" + +extern const char * const riscv_int_regnames[]; +extern const char * const riscv_fpr_regnames[]; +extern const char * const riscv_excp_names[]; +extern const char * const riscv_intr_names[]; + +const char *riscv_cpu_get_trap_name(target_ulong cause, bool async); +void riscv_cpu_do_interrupt(CPUState *cpu); +int riscv_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); +int riscv_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); +bool riscv_cpu_exec_interrupt(CPUState *cs, int interrupt_request); +bool riscv_cpu_fp_enabled(CPURISCVState *env); +bool riscv_cpu_vector_enabled(CPURISCVState *env); +bool riscv_cpu_virt_enabled(CPURISCVState *env); +void riscv_cpu_set_virt_enabled(CPURISCVState *env, bool enable); +bool riscv_cpu_force_hs_excep_enabled(CPURISCVState *env); +void riscv_cpu_set_force_hs_excep(CPURISCVState *env, bool enable); +bool riscv_cpu_two_stage_lookup(int mmu_idx); +int riscv_cpu_mmu_index(CPURISCVState *env, bool ifetch); +hwaddr riscv_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr); +void riscv_cpu_do_unaligned_access(CPUState *cs, vaddr addr, + MMUAccessType access_type, int mmu_idx, + uintptr_t retaddr); +bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, + MMUAccessType access_type, int mmu_idx, + bool probe, uintptr_t retaddr); +void riscv_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr, + vaddr addr, unsigned size, + MMUAccessType access_type, + int mmu_idx, MemTxAttrs attrs, + MemTxResult response, uintptr_t retaddr); +char *riscv_isa_string(RISCVCPU *cpu); +void riscv_cpu_list(void); + +#define cpu_signal_handler riscv_cpu_signal_handler +#define cpu_list riscv_cpu_list +#define cpu_mmu_index riscv_cpu_mmu_index + +#ifndef CONFIG_USER_ONLY +void riscv_cpu_swap_hypervisor_regs(CPURISCVState *env); +int riscv_cpu_claim_interrupts(RISCVCPU *cpu, uint32_t interrupts); +uint32_t riscv_cpu_update_mip(RISCVCPU *cpu, uint32_t mask, uint32_t value); +#define BOOL_TO_MASK(x) (-!!(x)) /* helper for riscv_cpu_update_mip value */ +void riscv_cpu_set_rdtime_fn(CPURISCVState *env, uint64_t (*fn)(uint32_t), + uint32_t arg); +#endif +void riscv_cpu_set_mode(CPURISCVState *env, target_ulong newpriv); + +void riscv_translate_init(void); +int riscv_cpu_signal_handler(int host_signum, void *pinfo, void *puc); +void QEMU_NORETURN riscv_raise_exception(CPURISCVState *env, + uint32_t exception, uintptr_t pc); + +target_ulong riscv_cpu_get_fflags(CPURISCVState *env); +void riscv_cpu_set_fflags(CPURISCVState *env, target_ulong); + +#define TB_FLAGS_MMU_MASK 7 +#define TB_FLAGS_PRIV_MMU_MASK 3 +#define TB_FLAGS_PRIV_HYP_ACCESS_MASK (1 << 2) +#define TB_FLAGS_MSTATUS_FS MSTATUS_FS +#define TB_FLAGS_MSTATUS_VS MSTATUS_VS + +typedef CPURISCVState CPUArchState; +typedef RISCVCPU ArchCPU; +#include "exec/cpu-all.h" + +FIELD(TB_FLAGS, VL_EQ_VLMAX, 2, 1) +FIELD(TB_FLAGS, LMUL, 3, 3) +FIELD(TB_FLAGS, SEW, 6, 3) +/* Skip MSTATUS_VS (0x600) fields */ +FIELD(TB_FLAGS, VILL, 11, 1) +/* Is a Hypervisor instruction load/store allowed? */ +FIELD(TB_FLAGS, HLSX, 12, 1) + +/* + * Encode LMUL to lmul as follows: + * LMUL vlmul lmul + * 1 000 0 + * 2 001 1 + * 4 010 2 + * 8 011 3 + * - 100 - + * 1/8 101 -3 + * 1/4 110 -2 + * 1/2 111 -1 + * + * then, we can calculate VLMAX = vlen >> (vsew + 3 - lmul) + * e.g. vlen = 256 bits, SEW = 16, LMUL = 1/8 + * => VLMAX = vlen >> (1 + 3 - (-3)) + * = 256 >> 7 + * = 2 + */ +static inline uint32_t vext_get_vlmax(RISCVCPU *cpu, target_ulong vtype) +{ + uint8_t sew = FIELD_EX64(vtype, VTYPE, VSEW); + int8_t lmul = sextract32(FIELD_EX64(vtype, VTYPE, VLMUL), 0, 3); + return cpu->cfg.vlen >> (sew + 3 - lmul); +} + +static inline void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc, + target_ulong *cs_base, uint32_t *pflags) +{ + uint32_t flags = 0; + + *pc = env->pc; + *cs_base = 0; + + if (riscv_has_ext(env, RVV)) { + /* + * If env->vl equals to VLMAX, we can use generic vector operation + * expanders (GVEC) to accerlate the vector operations. + * However, as LMUL could be a fractional number. The maximum + * vector size can be operated might be less than 8 bytes, + * which is not supported by GVEC. So we set vl_eq_vlmax flag to true + * only when maxsz >= 8 bytes. + */ + uint32_t vlmax = vext_get_vlmax(env_archcpu(env), env->vtype); + uint32_t sew = FIELD_EX64(env->vtype, VTYPE, VSEW); + uint32_t maxsz = vlmax << sew; + bool vl_eq_vlmax = (env->vstart == 0) && (vlmax == env->vl) + && (maxsz >= 8); + flags = FIELD_DP32(flags, TB_FLAGS, VILL, + FIELD_EX64(env->vtype, VTYPE, VILL)); + flags = FIELD_DP32(flags, TB_FLAGS, SEW, sew); + flags = FIELD_DP32(flags, TB_FLAGS, LMUL, + FIELD_EX64(env->vtype, VTYPE, VLMUL)); + flags = FIELD_DP32(flags, TB_FLAGS, VL_EQ_VLMAX, vl_eq_vlmax); + } else { + flags = FIELD_DP32(flags, TB_FLAGS, VILL, 1); + } + +#ifdef CONFIG_USER_ONLY + flags |= TB_FLAGS_MSTATUS_FS; + flags |= TB_FLAGS_MSTATUS_VS; +#else + flags |= cpu_mmu_index(env, 0); + if (riscv_cpu_fp_enabled(env)) { + flags |= env->mstatus & MSTATUS_FS; + } + + if (riscv_has_ext(env, RVH)) { + if (env->priv == PRV_M || + (env->priv == PRV_S && !riscv_cpu_virt_enabled(env)) || + (env->priv == PRV_U && !riscv_cpu_virt_enabled(env) && + get_field(env->hstatus, HSTATUS_HU))) { + flags = FIELD_DP32(flags, TB_FLAGS, HLSX, 1); + } + } + + if (riscv_cpu_vector_enabled(env)) { + flags |= env->mstatus & MSTATUS_VS; + } +#endif + + *pflags = flags; +} + +int riscv_csrrw(CPURISCVState *env, int csrno, target_ulong *ret_value, + target_ulong new_value, target_ulong write_mask); +int riscv_csrrw_debug(CPURISCVState *env, int csrno, target_ulong *ret_value, + target_ulong new_value, target_ulong write_mask); + +static inline void riscv_csr_write(CPURISCVState *env, int csrno, + target_ulong val) +{ + riscv_csrrw(env, csrno, NULL, val, MAKE_64BIT_MASK(0, TARGET_LONG_BITS)); +} + +static inline target_ulong riscv_csr_read(CPURISCVState *env, int csrno) +{ + target_ulong val = 0; + riscv_csrrw(env, csrno, &val, 0, 0); + return val; +} + +typedef int (*riscv_csr_predicate_fn)(CPURISCVState *env, int csrno); +typedef int (*riscv_csr_read_fn)(CPURISCVState *env, int csrno, + target_ulong *ret_value); +typedef int (*riscv_csr_write_fn)(CPURISCVState *env, int csrno, + target_ulong new_value); +typedef int (*riscv_csr_op_fn)(CPURISCVState *env, int csrno, + target_ulong *ret_value, target_ulong new_value, target_ulong write_mask); + +typedef struct { + riscv_csr_predicate_fn predicate; + riscv_csr_read_fn read; + riscv_csr_write_fn write; + riscv_csr_op_fn op; +} riscv_csr_operations; + +void riscv_get_csr_ops(int csrno, riscv_csr_operations *ops); +void riscv_set_csr_ops(int csrno, riscv_csr_operations *ops); + +/* + * Helpers to dynamically generates XML descriptions of the + * vector registers. Returns the number of registers in each set. + */ +int ricsv_gen_dynamic_vector_xml(CPUState *cpu, int base_reg); + +/* + * Returns the dynamically generated XML for the gdb stub. + * Returns a pointer to the XML contents for the specified XML file or NULL + * if the XML name doesn't match the predefined one. + */ +const char *riscv_gdb_get_dynamic_xml(CPUState *cpu, const char *xmlname); + +void riscv_cpu_register_gdb_regs_for_features(CPUState *cs); + +#endif /* RISCV_CPU_H */ diff --git a/modules/freedom-qemu/patches/qemu-sifive-e.c b/modules/freedom-qemu/patches/qemu-sifive-e.c new file mode 100644 index 0000000..35f61e7 --- /dev/null +++ b/modules/freedom-qemu/patches/qemu-sifive-e.c @@ -0,0 +1,292 @@ +/* + * QEMU RISC-V Board Compatible with SiFive Freedom E SDK + * + * Copyright (c) 2017 SiFive, Inc. + * + * Provides a board compatible with the SiFive Freedom E SDK: + * + * 0) UART + * 1) CLINT (Core Level Interruptor) + * 2) PLIC (Platform Level Interrupt Controller) + * 3) PRCI (Power, Reset, Clock, Interrupt) + * 4) Registers emulated as RAM: AON, GPIO, QSPI, PWM + * 5) Flash memory emulated as RAM + * + * The Mask ROM reset vector jumps to the flash payload at 0x2040_0000. + * The OTP ROM and Flash boot code will be emulated in a future version. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2 or later, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "qemu/error-report.h" +#include "qapi/error.h" +#include "hw/boards.h" +#include "hw/loader.h" +#include "hw/sysbus.h" +#include "hw/char/serial.h" +#include "hw/misc/unimp.h" +#include "target/riscv/cpu.h" +#include "hw/riscv/riscv_hart.h" +#include "hw/riscv/sifive_e.h" +#include "hw/riscv/boot.h" +#include "hw/char/sifive_uart.h" +#include "hw/intc/sifive_clint.h" +#include "hw/intc/sifive_plic.h" +#include "hw/misc/sifive_e_prci.h" +#include "hw/misc/sifive_test.h" +#include "chardev/char.h" +#include "sysemu/arch_init.h" +#include "sysemu/sysemu.h" +#include "exec/address-spaces.h" + +static const struct MemmapEntry { + hwaddr base; + hwaddr size; +} sifive_e_memmap[] = { + [SIFIVE_E_DEV_DEBUG] = { 0x0, 0x1000 }, + [SIFIVE_E_DEV_MROM] = { 0x1000, 0x2000 }, + [SIFIVE_E_DEV_OTP] = { 0x20000, 0x2000 }, + [SIFIVE_E_DEV_TEST] = { 0x100000, 0x1000 }, + [SIFIVE_E_DEV_CLINT] = { 0x2000000, 0x10000 }, + [SIFIVE_E_DEV_PLIC] = { 0xc000000, 0x4000000 }, + [SIFIVE_E_DEV_AON] = { 0x10000000, 0x8000 }, + [SIFIVE_E_DEV_PRCI] = { 0x10008000, 0x8000 }, + [SIFIVE_E_DEV_OTP_CTRL] = { 0x10010000, 0x1000 }, + [SIFIVE_E_DEV_GPIO0] = { 0x10012000, 0x1000 }, + [SIFIVE_E_DEV_UART0] = { 0x10013000, 0x1000 }, + [SIFIVE_E_DEV_QSPI0] = { 0x10014000, 0x1000 }, + [SIFIVE_E_DEV_PWM0] = { 0x10015000, 0x1000 }, + [SIFIVE_E_DEV_UART1] = { 0x10023000, 0x1000 }, + [SIFIVE_E_DEV_QSPI1] = { 0x10024000, 0x1000 }, + [SIFIVE_E_DEV_PWM1] = { 0x10025000, 0x1000 }, + [SIFIVE_E_DEV_QSPI2] = { 0x10034000, 0x1000 }, + [SIFIVE_E_DEV_PWM2] = { 0x10035000, 0x1000 }, + [SIFIVE_E_DEV_XIP] = { 0x20000000, 0x20000000 }, + [SIFIVE_E_DEV_DTIM] = { 0x80000000, 0x400000 } +}; + +static void sifive_e_machine_init(MachineState *machine) +{ + const struct MemmapEntry *memmap = sifive_e_memmap; + + SiFiveEState *s = RISCV_E_MACHINE(machine); + MemoryRegion *sys_mem = get_system_memory(); + MemoryRegion *main_mem = g_new(MemoryRegion, 1); + int i; + + /* Initialize SoC */ + object_initialize_child(OBJECT(machine), "soc", &s->soc, TYPE_RISCV_E_SOC); + qdev_realize(DEVICE(&s->soc), NULL, &error_abort); + + /* Data Tightly Integrated Memory */ + memory_region_init_ram(main_mem, NULL, "riscv.sifive.e.ram", + memmap[SIFIVE_E_DEV_DTIM].size, &error_fatal); + memory_region_add_subregion(sys_mem, + memmap[SIFIVE_E_DEV_DTIM].base, main_mem); + + /* Mask ROM reset vector */ + uint32_t reset_vec[4]; + + if (s->revb) { + reset_vec[1] = 0x200102b7; /* 0x1004: lui t0,0x20010 */ + } else { + reset_vec[1] = 0x204002b7; /* 0x1004: lui t0,0x20400 */ + } + reset_vec[2] = 0x00028067; /* 0x1008: jr t0 */ + + reset_vec[0] = reset_vec[3] = 0; + + /* copy in the reset vector in little_endian byte order */ + for (i = 0; i < sizeof(reset_vec) >> 2; i++) { + reset_vec[i] = cpu_to_le32(reset_vec[i]); + } + rom_add_blob_fixed_as("mrom.reset", reset_vec, sizeof(reset_vec), + memmap[SIFIVE_E_DEV_MROM].base, &address_space_memory); + + if (machine->kernel_filename) { + riscv_load_kernel(machine->kernel_filename, + memmap[SIFIVE_E_DEV_DTIM].base, NULL); + } +} + +static bool sifive_e_machine_get_revb(Object *obj, Error **errp) +{ + SiFiveEState *s = RISCV_E_MACHINE(obj); + + return s->revb; +} + +static void sifive_e_machine_set_revb(Object *obj, bool value, Error **errp) +{ + SiFiveEState *s = RISCV_E_MACHINE(obj); + + s->revb = value; +} + +static void sifive_e_machine_instance_init(Object *obj) +{ + SiFiveEState *s = RISCV_E_MACHINE(obj); + + s->revb = false; +} + +static void sifive_e_machine_class_init(ObjectClass *oc, void *data) +{ + MachineClass *mc = MACHINE_CLASS(oc); + + mc->desc = "RISC-V Board compatible with SiFive E SDK"; + mc->init = sifive_e_machine_init; + mc->max_cpus = 1; + mc->default_cpu_type = SIFIVE_E_CPU; + + object_class_property_add_bool(oc, "revb", sifive_e_machine_get_revb, + sifive_e_machine_set_revb); + object_class_property_set_description(oc, "revb", + "Set on to tell QEMU that it should model " + "the revB HiFive1 board"); +} + +static const TypeInfo sifive_e_machine_typeinfo = { + .name = MACHINE_TYPE_NAME("sifive_e"), + .parent = TYPE_MACHINE, + .class_init = sifive_e_machine_class_init, + .instance_init = sifive_e_machine_instance_init, + .instance_size = sizeof(SiFiveEState), +}; + +static void sifive_e_machine_init_register_types(void) +{ + type_register_static(&sifive_e_machine_typeinfo); +} + +type_init(sifive_e_machine_init_register_types) + +static void sifive_e_soc_init(Object *obj) +{ + MachineState *ms = MACHINE(qdev_get_machine()); + SiFiveESoCState *s = RISCV_E_SOC(obj); + + object_initialize_child(obj, "cpus", &s->cpus, TYPE_RISCV_HART_ARRAY); + object_property_set_int(OBJECT(&s->cpus), "num-harts", ms->smp.cpus, + &error_abort); + object_property_set_int(OBJECT(&s->cpus), "resetvec", 0x1004, &error_abort); + object_initialize_child(obj, "riscv.sifive.e.gpio0", &s->gpio, + TYPE_SIFIVE_GPIO); +} + +static void sifive_e_soc_realize(DeviceState *dev, Error **errp) +{ + MachineState *ms = MACHINE(qdev_get_machine()); + const struct MemmapEntry *memmap = sifive_e_memmap; + SiFiveESoCState *s = RISCV_E_SOC(dev); + MemoryRegion *sys_mem = get_system_memory(); + + object_property_set_str(OBJECT(&s->cpus), "cpu-type", ms->cpu_type, + &error_abort); + sysbus_realize(SYS_BUS_DEVICE(&s->cpus), &error_abort); + + /* Mask ROM */ + memory_region_init_rom(&s->mask_rom, OBJECT(dev), "riscv.sifive.e.mrom", + memmap[SIFIVE_E_DEV_MROM].size, &error_fatal); + memory_region_add_subregion(sys_mem, + memmap[SIFIVE_E_DEV_MROM].base, &s->mask_rom); + + /* MMIO */ + s->plic = sifive_plic_create(memmap[SIFIVE_E_DEV_PLIC].base, + (char *)SIFIVE_E_PLIC_HART_CONFIG, 0, + SIFIVE_E_PLIC_NUM_SOURCES, + SIFIVE_E_PLIC_NUM_PRIORITIES, + SIFIVE_E_PLIC_PRIORITY_BASE, + SIFIVE_E_PLIC_PENDING_BASE, + SIFIVE_E_PLIC_ENABLE_BASE, + SIFIVE_E_PLIC_ENABLE_STRIDE, + SIFIVE_E_PLIC_CONTEXT_BASE, + SIFIVE_E_PLIC_CONTEXT_STRIDE, + memmap[SIFIVE_E_DEV_PLIC].size); + sifive_clint_create(memmap[SIFIVE_E_DEV_CLINT].base, + memmap[SIFIVE_E_DEV_CLINT].size, 0, ms->smp.cpus, + SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE, + SIFIVE_CLINT_TIMEBASE_FREQ, false); + create_unimplemented_device("riscv.sifive.e.aon", + memmap[SIFIVE_E_DEV_AON].base, memmap[SIFIVE_E_DEV_AON].size); + sifive_e_prci_create(memmap[SIFIVE_E_DEV_PRCI].base); + + /* GPIO */ + + if (!sysbus_realize(SYS_BUS_DEVICE(&s->gpio), errp)) { + return; + } + + /* Map GPIO registers */ + sysbus_mmio_map(SYS_BUS_DEVICE(&s->gpio), 0, memmap[SIFIVE_E_DEV_GPIO0].base); + + /* Pass all GPIOs to the SOC layer so they are available to the board */ + qdev_pass_gpios(DEVICE(&s->gpio), dev, NULL); + + /* Connect GPIO interrupts to the PLIC */ + for (int i = 0; i < 32; i++) { + sysbus_connect_irq(SYS_BUS_DEVICE(&s->gpio), i, + qdev_get_gpio_in(DEVICE(s->plic), + SIFIVE_E_GPIO0_IRQ0 + i)); + } + + sifive_uart_create(sys_mem, memmap[SIFIVE_E_DEV_UART0].base, + serial_hd(0), qdev_get_gpio_in(DEVICE(s->plic), SIFIVE_E_UART0_IRQ)); + create_unimplemented_device("riscv.sifive.e.qspi0", + memmap[SIFIVE_E_DEV_QSPI0].base, memmap[SIFIVE_E_DEV_QSPI0].size); + create_unimplemented_device("riscv.sifive.e.pwm0", + memmap[SIFIVE_E_DEV_PWM0].base, memmap[SIFIVE_E_DEV_PWM0].size); + sifive_uart_create(sys_mem, memmap[SIFIVE_E_DEV_UART1].base, + serial_hd(1), qdev_get_gpio_in(DEVICE(s->plic), SIFIVE_E_UART1_IRQ)); + create_unimplemented_device("riscv.sifive.e.qspi1", + memmap[SIFIVE_E_DEV_QSPI1].base, memmap[SIFIVE_E_DEV_QSPI1].size); + create_unimplemented_device("riscv.sifive.e.pwm1", + memmap[SIFIVE_E_DEV_PWM1].base, memmap[SIFIVE_E_DEV_PWM1].size); + create_unimplemented_device("riscv.sifive.e.qspi2", + memmap[SIFIVE_E_DEV_QSPI2].base, memmap[SIFIVE_E_DEV_QSPI2].size); + create_unimplemented_device("riscv.sifive.e.pwm2", + memmap[SIFIVE_E_DEV_PWM2].base, memmap[SIFIVE_E_DEV_PWM2].size); + sifive_test_create(memmap[SIFIVE_E_DEV_TEST].base); + + /* Flash memory */ + memory_region_init_rom(&s->xip_mem, OBJECT(dev), "riscv.sifive.e.xip", + memmap[SIFIVE_E_DEV_XIP].size, &error_fatal); + memory_region_add_subregion(sys_mem, memmap[SIFIVE_E_DEV_XIP].base, + &s->xip_mem); +} + +static void sifive_e_soc_class_init(ObjectClass *oc, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(oc); + + dc->realize = sifive_e_soc_realize; + /* Reason: Uses serial_hds in realize function, thus can't be used twice */ + dc->user_creatable = false; +} + +static const TypeInfo sifive_e_soc_type_info = { + .name = TYPE_RISCV_E_SOC, + .parent = TYPE_DEVICE, + .instance_size = sizeof(SiFiveESoCState), + .instance_init = sifive_e_soc_init, + .class_init = sifive_e_soc_class_init, +}; + +static void sifive_e_soc_register_types(void) +{ + type_register_static(&sifive_e_soc_type_info); +} + +type_init(sifive_e_soc_register_types) diff --git a/modules/freedom-qemu/patches/qemu-sifive-e.h b/modules/freedom-qemu/patches/qemu-sifive-e.h new file mode 100644 index 0000000..92bab6d --- /dev/null +++ b/modules/freedom-qemu/patches/qemu-sifive-e.h @@ -0,0 +1,94 @@ +/* + * SiFive E series machine interface + * + * Copyright (c) 2017 SiFive, Inc. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2 or later, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#ifndef HW_SIFIVE_E_H +#define HW_SIFIVE_E_H + +#include "hw/riscv/riscv_hart.h" +#include "hw/riscv/sifive_cpu.h" +#include "hw/gpio/sifive_gpio.h" + +#define TYPE_RISCV_E_SOC "riscv.sifive.e.soc" +#define RISCV_E_SOC(obj) \ + OBJECT_CHECK(SiFiveESoCState, (obj), TYPE_RISCV_E_SOC) + +typedef struct SiFiveESoCState { + /*< private >*/ + DeviceState parent_obj; + + /*< public >*/ + RISCVHartArrayState cpus; + DeviceState *plic; + SIFIVEGPIOState gpio; + MemoryRegion xip_mem; + MemoryRegion mask_rom; +} SiFiveESoCState; + +typedef struct SiFiveEState { + /*< private >*/ + SysBusDevice parent_obj; + + /*< public >*/ + SiFiveESoCState soc; + bool revb; +} SiFiveEState; + +#define TYPE_RISCV_E_MACHINE MACHINE_TYPE_NAME("sifive_e") +#define RISCV_E_MACHINE(obj) \ + OBJECT_CHECK(SiFiveEState, (obj), TYPE_RISCV_E_MACHINE) + +enum { + SIFIVE_E_DEV_DEBUG, + SIFIVE_E_DEV_MROM, + SIFIVE_E_DEV_OTP, + SIFIVE_E_DEV_TEST, + SIFIVE_E_DEV_CLINT, + SIFIVE_E_DEV_PLIC, + SIFIVE_E_DEV_AON, + SIFIVE_E_DEV_PRCI, + SIFIVE_E_DEV_OTP_CTRL, + SIFIVE_E_DEV_GPIO0, + SIFIVE_E_DEV_UART0, + SIFIVE_E_DEV_QSPI0, + SIFIVE_E_DEV_PWM0, + SIFIVE_E_DEV_UART1, + SIFIVE_E_DEV_QSPI1, + SIFIVE_E_DEV_PWM1, + SIFIVE_E_DEV_QSPI2, + SIFIVE_E_DEV_PWM2, + SIFIVE_E_DEV_XIP, + SIFIVE_E_DEV_DTIM +}; + +enum { + SIFIVE_E_UART0_IRQ = 3, + SIFIVE_E_UART1_IRQ = 4, + SIFIVE_E_GPIO0_IRQ0 = 8 +}; + +#define SIFIVE_E_PLIC_HART_CONFIG "M" +#define SIFIVE_E_PLIC_NUM_SOURCES 127 +#define SIFIVE_E_PLIC_NUM_PRIORITIES 7 +#define SIFIVE_E_PLIC_PRIORITY_BASE 0x04 +#define SIFIVE_E_PLIC_PENDING_BASE 0x1000 +#define SIFIVE_E_PLIC_ENABLE_BASE 0x2000 +#define SIFIVE_E_PLIC_ENABLE_STRIDE 0x80 +#define SIFIVE_E_PLIC_CONTEXT_BASE 0x200000 +#define SIFIVE_E_PLIC_CONTEXT_STRIDE 0x1000 + +#endif diff --git a/modules/freedom-qemu/patches/qemu-sifive-test.c b/modules/freedom-qemu/patches/qemu-sifive-test.c new file mode 100644 index 0000000..c9476d3 --- /dev/null +++ b/modules/freedom-qemu/patches/qemu-sifive-test.c @@ -0,0 +1,102 @@ +/* + * QEMU SiFive Test Finisher + * + * Copyright (c) 2018 SiFive, Inc. + * + * Test finisher memory mapped device used to exit simulation + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2 or later, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#include "qemu/osdep.h" +#include "qemu/error-report.h" +#include "hw/sysbus.h" +#include "qapi/error.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "sysemu/runstate.h" +#include "hw/hw.h" +#include "hw/misc/sifive_test.h" + +static uint64_t sifive_test_read(void *opaque, hwaddr addr, unsigned int size) +{ + return 0; +} + +static void sifive_test_write(void *opaque, hwaddr addr, + uint64_t val64, unsigned int size) +{ + if (addr == 0) { + int status = val64 & 0xffff; + int code = (val64 >> 16) & 0xffff; + switch (status) { + case FINISHER_FAIL: + error_report("QEMU: Program exited with code '%d'", code); + exit(code); + case FINISHER_PASS: + exit(0); + case FINISHER_RESET: + qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET); + return; + default: + break; + } + } + qemu_log_mask(LOG_GUEST_ERROR, "%s: write: addr=0x%x val=0x%016" PRIx64 "\n", + __func__, (int)addr, val64); +} + +static const MemoryRegionOps sifive_test_ops = { + .read = sifive_test_read, + .write = sifive_test_write, + .endianness = DEVICE_NATIVE_ENDIAN, + .valid = { + .min_access_size = 2, + .max_access_size = 4 + } +}; + +static void sifive_test_init(Object *obj) +{ + SiFiveTestState *s = SIFIVE_TEST(obj); + + memory_region_init_io(&s->mmio, obj, &sifive_test_ops, s, + TYPE_SIFIVE_TEST, 0x1000); + sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->mmio); +} + +static const TypeInfo sifive_test_info = { + .name = TYPE_SIFIVE_TEST, + .parent = TYPE_SYS_BUS_DEVICE, + .instance_size = sizeof(SiFiveTestState), + .instance_init = sifive_test_init, +}; + +static void sifive_test_register_types(void) +{ + type_register_static(&sifive_test_info); +} + +type_init(sifive_test_register_types) + + +/* + * Create Test device. + */ +DeviceState *sifive_test_create(hwaddr addr) +{ + DeviceState *dev = qdev_new(TYPE_SIFIVE_TEST); + sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); + sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr); + return dev; +} diff --git a/modules/freedom-qemu/patches/qemu-sifive-u.c b/modules/freedom-qemu/patches/qemu-sifive-u.c new file mode 100644 index 0000000..1c0898b --- /dev/null +++ b/modules/freedom-qemu/patches/qemu-sifive-u.c @@ -0,0 +1,1195 @@ +/* + * QEMU RISC-V Board Compatible with SiFive Freedom U SDK + * + * Copyright (c) 2016-2017 Sagar Karandikar, sagark@eecs.berkeley.edu + * Copyright (c) 2017 SiFive, Inc. + * Copyright (c) 2019 Bin Meng + * + * Provides a board compatible with the SiFive Freedom U SDK: + * + * 0) UART + * 1) CLINT (Core Level Interruptor) + * 2) PLIC (Platform Level Interrupt Controller) + * 3) PRCI (Power, Reset, Clock, Interrupt) + * 4) GPIO (General Purpose Input/Output Controller) + * 5) OTP (One-Time Programmable) memory with stored serial number + * 6) GEM (Gigabit Ethernet Controller) and management block + * + * This board currently generates devicetree dynamically that indicates at least + * one hart and up to four harts. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2 or later, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "qemu/error-report.h" +#include "qapi/error.h" +#include "qapi/visitor.h" +#include "hw/boards.h" +#include "hw/irq.h" +#include "hw/loader.h" +#include "hw/sysbus.h" +#include "hw/char/serial.h" +#include "hw/cpu/cluster.h" +#include "hw/misc/unimp.h" +#include "target/riscv/cpu.h" +#include "hw/riscv/riscv_hart.h" +#include "hw/riscv/sifive_u.h" +#include "hw/riscv/boot.h" +#include "hw/char/sifive_uart.h" +#include "hw/intc/sifive_clint.h" +#include "hw/intc/sifive_plic.h" +#include "hw/misc/sifive_test.h" +#include "chardev/char.h" +#include "net/eth.h" +#include "sysemu/arch_init.h" +#include "sysemu/device_tree.h" +#include "sysemu/runstate.h" +#include "sysemu/sysemu.h" + +#include + +#if defined(TARGET_RISCV32) +# define BIOS_FILENAME "opensbi-riscv32-generic-fw_dynamic.bin" +#else +# define BIOS_FILENAME "opensbi-riscv64-generic-fw_dynamic.bin" +#endif + +static const struct MemmapEntry { + hwaddr base; + hwaddr size; +} sifive_u_memmap[] = { + [SIFIVE_U_DEV_DEBUG] = { 0x0, 0x100 }, + [SIFIVE_U_DEV_MROM] = { 0x1000, 0xf000 }, + [SIFIVE_U_DEV_TEST] = { 0x100000, 0x1000 }, + [SIFIVE_U_DEV_CLINT] = { 0x2000000, 0x10000 }, + [SIFIVE_U_DEV_L2LIM] = { 0x8000000, 0x2000000 }, + [SIFIVE_U_DEV_PLIC] = { 0xc000000, 0x4000000 }, + [SIFIVE_U_DEV_PRCI] = { 0x10000000, 0x1000 }, + [SIFIVE_U_DEV_UART0] = { 0x10013000, 0x1000 }, + [SIFIVE_U_DEV_UART1] = { 0x10023000, 0x1000 }, + [SIFIVE_U_DEV_GPIO] = { 0x10060000, 0x1000 }, + [SIFIVE_U_DEV_OTP] = { 0x10070000, 0x1000 }, + [SIFIVE_U_DEV_GEM] = { 0x10090000, 0x2000 }, + [SIFIVE_U_DEV_GEM_MGMT] = { 0x100a0000, 0x1000 }, + [SIFIVE_U_DEV_DMC] = { 0x100b0000, 0x10000 }, + [SIFIVE_U_DEV_FLASH0] = { 0x20000000, 0x10000000 }, + [SIFIVE_U_DEV_DRAM] = { 0x80000000, 0x0 }, +}; + +#define OTP_SERIAL 1 +#define GEM_REVISION 0x10070109 + +static void create_fdt(SiFiveUState *s, const struct MemmapEntry *memmap, + uint64_t mem_size, const char *cmdline) +{ + MachineState *ms = MACHINE(qdev_get_machine()); + void *fdt; + int cpu; + uint32_t *cells; + char *nodename; + const char *dtb_filename; + char ethclk_names[] = "pclk\0hclk"; + uint32_t plic_phandle, prci_phandle, gpio_phandle, phandle = 1; + uint32_t hfclk_phandle, rtcclk_phandle, phy_phandle; + + dtb_filename = qemu_opt_get(qemu_get_machine_opts(), "dtb"); + if (dtb_filename) { + fdt = s->fdt = load_device_tree(dtb_filename, &s->fdt_size); + if (!fdt) { + error_report("load_device_tree() failed"); + exit(1); + } + goto update_bootargs; + } else { + fdt = s->fdt = create_device_tree(&s->fdt_size); + if (!fdt) { + error_report("create_device_tree() failed"); + exit(1); + } + } + + qemu_fdt_setprop_string(fdt, "/", "model", "ucbbar,spike-bare,qemu"); + qemu_fdt_setprop_string(fdt, "/", "compatible", "ucbbar,spike-bare-dev"); + qemu_fdt_setprop_cell(fdt, "/", "#size-cells", 0x2); + qemu_fdt_setprop_cell(fdt, "/", "#address-cells", 0x2); + + qemu_fdt_add_subnode(fdt, "/soc"); + qemu_fdt_setprop(fdt, "/soc", "ranges", NULL, 0); + qemu_fdt_setprop_string(fdt, "/soc", "compatible", "simple-bus"); + qemu_fdt_setprop_cell(fdt, "/soc", "#size-cells", 0x2); + qemu_fdt_setprop_cell(fdt, "/soc", "#address-cells", 0x2); + + hfclk_phandle = phandle++; + nodename = g_strdup_printf("/hfclk"); + qemu_fdt_add_subnode(fdt, nodename); + qemu_fdt_setprop_cell(fdt, nodename, "phandle", hfclk_phandle); + qemu_fdt_setprop_string(fdt, nodename, "clock-output-names", "hfclk"); + qemu_fdt_setprop_cell(fdt, nodename, "clock-frequency", + SIFIVE_U_HFCLK_FREQ); + qemu_fdt_setprop_string(fdt, nodename, "compatible", "fixed-clock"); + qemu_fdt_setprop_cell(fdt, nodename, "#clock-cells", 0x0); + g_free(nodename); + + rtcclk_phandle = phandle++; + nodename = g_strdup_printf("/rtcclk"); + qemu_fdt_add_subnode(fdt, nodename); + qemu_fdt_setprop_cell(fdt, nodename, "phandle", rtcclk_phandle); + qemu_fdt_setprop_string(fdt, nodename, "clock-output-names", "rtcclk"); + qemu_fdt_setprop_cell(fdt, nodename, "clock-frequency", + SIFIVE_U_RTCCLK_FREQ); + qemu_fdt_setprop_string(fdt, nodename, "compatible", "fixed-clock"); + qemu_fdt_setprop_cell(fdt, nodename, "#clock-cells", 0x0); + g_free(nodename); + + nodename = g_strdup_printf("/memory@%lx", + (long)memmap[SIFIVE_U_DEV_DRAM].base); + qemu_fdt_add_subnode(fdt, nodename); + qemu_fdt_setprop_cells(fdt, nodename, "reg", + memmap[SIFIVE_U_DEV_DRAM].base >> 32, memmap[SIFIVE_U_DEV_DRAM].base, + mem_size >> 32, mem_size); + qemu_fdt_setprop_string(fdt, nodename, "device_type", "memory"); + g_free(nodename); + + qemu_fdt_add_subnode(fdt, "/cpus"); + qemu_fdt_setprop_cell(fdt, "/cpus", "timebase-frequency", + SIFIVE_CLINT_TIMEBASE_FREQ); + qemu_fdt_setprop_cell(fdt, "/cpus", "#size-cells", 0x0); + qemu_fdt_setprop_cell(fdt, "/cpus", "#address-cells", 0x1); + + for (cpu = ms->smp.cpus - 1; cpu >= 0; cpu--) { + int cpu_phandle = phandle++; + nodename = g_strdup_printf("/cpus/cpu@%d", cpu); + char *intc = g_strdup_printf("/cpus/cpu@%d/interrupt-controller", cpu); + char *isa = riscv_isa_string(&s->soc.cpus.harts[cpu]); + qemu_fdt_add_subnode(fdt, nodename); + qemu_fdt_setprop_cell(fdt, nodename, "clock-frequency", + SIFIVE_U_CLOCK_FREQ); +#if defined(TARGET_RISCV32) + qemu_fdt_setprop_string(fdt, nodename, "mmu-type", "riscv,sv32"); +#else + qemu_fdt_setprop_string(fdt, nodename, "mmu-type", "riscv,sv48"); +#endif + qemu_fdt_setprop_string(fdt, nodename, "riscv,isa", isa); + qemu_fdt_setprop_string(fdt, nodename, "compatible", "riscv"); + qemu_fdt_setprop_string(fdt, nodename, "status", "okay"); + qemu_fdt_setprop_cell(fdt, nodename, "reg", cpu); + qemu_fdt_setprop_string(fdt, nodename, "device_type", "cpu"); + qemu_fdt_add_subnode(fdt, intc); + qemu_fdt_setprop_cell(fdt, intc, "phandle", cpu_phandle); + qemu_fdt_setprop_cell(fdt, intc, "linux,phandle", cpu_phandle); + qemu_fdt_setprop_string(fdt, intc, "compatible", "riscv,cpu-intc"); + qemu_fdt_setprop(fdt, intc, "interrupt-controller", NULL, 0); + qemu_fdt_setprop_cell(fdt, intc, "#interrupt-cells", 1); + g_free(isa); + g_free(intc); + g_free(nodename); + } + + cells = g_new0(uint32_t, ms->smp.cpus * 4); + for (cpu = 0; cpu < ms->smp.cpus; cpu++) { + nodename = + g_strdup_printf("/cpus/cpu@%d/interrupt-controller", cpu); + uint32_t intc_phandle = qemu_fdt_get_phandle(fdt, nodename); + cells[cpu * 4 + 0] = cpu_to_be32(intc_phandle); + cells[cpu * 4 + 1] = cpu_to_be32(IRQ_M_SOFT); + cells[cpu * 4 + 2] = cpu_to_be32(intc_phandle); + cells[cpu * 4 + 3] = cpu_to_be32(IRQ_M_TIMER); + g_free(nodename); + } + nodename = g_strdup_printf("/soc/clint@%lx", + (long)memmap[SIFIVE_U_DEV_CLINT].base); + qemu_fdt_add_subnode(fdt, nodename); + qemu_fdt_setprop_string(fdt, nodename, "compatible", "riscv,clint0"); + qemu_fdt_setprop_cells(fdt, nodename, "reg", + 0x0, memmap[SIFIVE_U_DEV_CLINT].base, + 0x0, memmap[SIFIVE_U_DEV_CLINT].size); + qemu_fdt_setprop_string(fdt, nodename, "reg-names", "control"); + qemu_fdt_setprop(fdt, nodename, "interrupts-extended", + cells, ms->smp.cpus * sizeof(uint32_t) * 4); + g_free(cells); + g_free(nodename); + + nodename = g_strdup_printf("/soc/otp@%lx", + (long)memmap[SIFIVE_U_DEV_OTP].base); + qemu_fdt_add_subnode(fdt, nodename); + qemu_fdt_setprop_cell(fdt, nodename, "fuse-count", SIFIVE_U_OTP_REG_SIZE); + qemu_fdt_setprop_cells(fdt, nodename, "reg", + 0x0, memmap[SIFIVE_U_DEV_OTP].base, + 0x0, memmap[SIFIVE_U_DEV_OTP].size); + qemu_fdt_setprop_string(fdt, nodename, "compatible", + "sifive,fu540-c000-otp"); + g_free(nodename); + + prci_phandle = phandle++; + nodename = g_strdup_printf("/soc/clock-controller@%lx", + (long)memmap[SIFIVE_U_DEV_PRCI].base); + qemu_fdt_add_subnode(fdt, nodename); + qemu_fdt_setprop_cell(fdt, nodename, "phandle", prci_phandle); + qemu_fdt_setprop_cell(fdt, nodename, "#clock-cells", 0x1); + qemu_fdt_setprop_cells(fdt, nodename, "clocks", + hfclk_phandle, rtcclk_phandle); + qemu_fdt_setprop_cells(fdt, nodename, "reg", + 0x0, memmap[SIFIVE_U_DEV_PRCI].base, + 0x0, memmap[SIFIVE_U_DEV_PRCI].size); + qemu_fdt_setprop_string(fdt, nodename, "reg-names", "mem"); + qemu_fdt_setprop_string(fdt, nodename, "compatible", + "sifive,fu540-c000-prci"); + g_free(nodename); + + plic_phandle = phandle++; + cells = g_new0(uint32_t, ms->smp.cpus * 4); + for (cpu = 0; cpu < ms->smp.cpus; cpu++) { + nodename = + g_strdup_printf("/cpus/cpu@%d/interrupt-controller", cpu); + uint32_t intc_phandle = qemu_fdt_get_phandle(fdt, nodename); + cells[cpu * 4 + 0] = cpu_to_be32(intc_phandle); + cells[cpu * 4 + 1] = cpu_to_be32(IRQ_M_EXT); + cells[cpu * 4 + 2] = cpu_to_be32(intc_phandle); + cells[cpu * 4 + 3] = cpu_to_be32(IRQ_S_EXT); + g_free(nodename); + } + nodename = g_strdup_printf("/soc/interrupt-controller@%lx", + (long)memmap[SIFIVE_U_DEV_PLIC].base); + qemu_fdt_add_subnode(fdt, nodename); + qemu_fdt_setprop_cell(fdt, nodename, "#interrupt-cells", 1); + qemu_fdt_setprop_string(fdt, nodename, "compatible", "riscv,plic0"); + qemu_fdt_setprop(fdt, nodename, "interrupt-controller", NULL, 0); + qemu_fdt_setprop(fdt, nodename, "interrupts-extended", + cells, ms->smp.cpus * sizeof(uint32_t) * 4); + qemu_fdt_setprop_cells(fdt, nodename, "reg", + 0x0, memmap[SIFIVE_U_DEV_PLIC].base, + 0x0, memmap[SIFIVE_U_DEV_PLIC].size); + qemu_fdt_setprop_string(fdt, nodename, "reg-names", "control"); + qemu_fdt_setprop_cell(fdt, nodename, "riscv,max-priority", 7); + qemu_fdt_setprop_cell(fdt, nodename, "riscv,ndev", 0x35); + qemu_fdt_setprop_cell(fdt, nodename, "phandle", plic_phandle); + qemu_fdt_setprop_cell(fdt, nodename, "linux,phandle", plic_phandle); + plic_phandle = qemu_fdt_get_phandle(fdt, nodename); + g_free(cells); + g_free(nodename); + + gpio_phandle = phandle++; + nodename = g_strdup_printf("/soc/gpio@%lx", + (long)memmap[SIFIVE_U_DEV_GPIO].base); + qemu_fdt_add_subnode(fdt, nodename); + qemu_fdt_setprop_cell(fdt, nodename, "phandle", gpio_phandle); + qemu_fdt_setprop_cell(fdt, nodename, "linux,phandle", gpio_phandle); + qemu_fdt_setprop_cells(fdt, nodename, "clocks", + prci_phandle, PRCI_CLK_TLCLK); + qemu_fdt_setprop_cell(fdt, nodename, "#interrupt-cells", 2); + qemu_fdt_setprop(fdt, nodename, "interrupt-controller", NULL, 0); + qemu_fdt_setprop_cell(fdt, nodename, "#gpio-cells", 2); + qemu_fdt_setprop(fdt, nodename, "gpio-controller", NULL, 0); + qemu_fdt_setprop_cells(fdt, nodename, "reg", + 0x0, memmap[SIFIVE_U_DEV_GPIO].base, + 0x0, memmap[SIFIVE_U_DEV_GPIO].size); + qemu_fdt_setprop_string(fdt, nodename, "reg-names", "control"); + qemu_fdt_setprop_cells(fdt, nodename, "interrupts", SIFIVE_U_GPIO_IRQ0, + SIFIVE_U_GPIO_IRQ1, SIFIVE_U_GPIO_IRQ2, SIFIVE_U_GPIO_IRQ3, + SIFIVE_U_GPIO_IRQ4, SIFIVE_U_GPIO_IRQ5, SIFIVE_U_GPIO_IRQ6, + SIFIVE_U_GPIO_IRQ7, SIFIVE_U_GPIO_IRQ8, SIFIVE_U_GPIO_IRQ9, + SIFIVE_U_GPIO_IRQ10, SIFIVE_U_GPIO_IRQ11, SIFIVE_U_GPIO_IRQ12, + SIFIVE_U_GPIO_IRQ13, SIFIVE_U_GPIO_IRQ14, SIFIVE_U_GPIO_IRQ15); + qemu_fdt_setprop_cell(fdt, nodename, "interrupt-parent", plic_phandle); + qemu_fdt_setprop_string(fdt, nodename, "compatible", "sifive,gpio0"); + g_free(nodename); + + nodename = g_strdup_printf("/gpio-restart"); + qemu_fdt_add_subnode(fdt, nodename); + qemu_fdt_setprop_cells(fdt, nodename, "gpios", gpio_phandle, 10, 1); + qemu_fdt_setprop_string(fdt, nodename, "compatible", "gpio-restart"); + g_free(nodename); + + phy_phandle = phandle++; + nodename = g_strdup_printf("/soc/ethernet@%lx", + (long)memmap[SIFIVE_U_DEV_GEM].base); + qemu_fdt_add_subnode(fdt, nodename); + qemu_fdt_setprop_string(fdt, nodename, "compatible", + "sifive,fu540-c000-gem"); + qemu_fdt_setprop_cells(fdt, nodename, "reg", + 0x0, memmap[SIFIVE_U_DEV_GEM].base, + 0x0, memmap[SIFIVE_U_DEV_GEM].size, + 0x0, memmap[SIFIVE_U_DEV_GEM_MGMT].base, + 0x0, memmap[SIFIVE_U_DEV_GEM_MGMT].size); + qemu_fdt_setprop_string(fdt, nodename, "reg-names", "control"); + qemu_fdt_setprop_string(fdt, nodename, "phy-mode", "gmii"); + qemu_fdt_setprop_cell(fdt, nodename, "phy-handle", phy_phandle); + qemu_fdt_setprop_cell(fdt, nodename, "interrupt-parent", plic_phandle); + qemu_fdt_setprop_cell(fdt, nodename, "interrupts", SIFIVE_U_GEM_IRQ); + qemu_fdt_setprop_cells(fdt, nodename, "clocks", + prci_phandle, PRCI_CLK_GEMGXLPLL, prci_phandle, PRCI_CLK_GEMGXLPLL); + qemu_fdt_setprop(fdt, nodename, "clock-names", ethclk_names, + sizeof(ethclk_names)); + qemu_fdt_setprop(fdt, nodename, "local-mac-address", + s->soc.gem.conf.macaddr.a, ETH_ALEN); + qemu_fdt_setprop_cell(fdt, nodename, "#address-cells", 1); + qemu_fdt_setprop_cell(fdt, nodename, "#size-cells", 0); + + qemu_fdt_add_subnode(fdt, "/aliases"); + qemu_fdt_setprop_string(fdt, "/aliases", "ethernet0", nodename); + + g_free(nodename); + + nodename = g_strdup_printf("/soc/ethernet@%lx/ethernet-phy@0", + (long)memmap[SIFIVE_U_DEV_GEM].base); + qemu_fdt_add_subnode(fdt, nodename); + qemu_fdt_setprop_cell(fdt, nodename, "phandle", phy_phandle); + qemu_fdt_setprop_cell(fdt, nodename, "reg", 0x0); + g_free(nodename); + + nodename = g_strdup_printf("/soc/test@%lx", + (long)memmap[SIFIVE_U_DEV_TEST].base); + qemu_fdt_add_subnode(fdt, nodename); + qemu_fdt_setprop_string(fdt, nodename, "compatible", "sifive,test0"); + qemu_fdt_setprop_cells(fdt, nodename, "reg", + 0x0, memmap[SIFIVE_U_DEV_TEST].base, + 0x0, memmap[SIFIVE_U_DEV_TEST].size); + qemu_fdt_setprop_string(fdt, nodename, "reg-names", "control"); + + nodename = g_strdup_printf("/soc/serial@%lx", + (long)memmap[SIFIVE_U_DEV_UART0].base); + qemu_fdt_add_subnode(fdt, nodename); + qemu_fdt_setprop_string(fdt, nodename, "compatible", "sifive,uart0"); + qemu_fdt_setprop_cells(fdt, nodename, "reg", + 0x0, memmap[SIFIVE_U_DEV_UART0].base, + 0x0, memmap[SIFIVE_U_DEV_UART0].size); + qemu_fdt_setprop_string(fdt, nodename, "reg-names", "control"); + qemu_fdt_setprop_cell(fdt, nodename, "clock-frequency", + SIFIVE_U_CLOCK_FREQ / 2); + qemu_fdt_setprop_cells(fdt, nodename, "clocks", + prci_phandle, PRCI_CLK_TLCLK); + qemu_fdt_setprop_cell(fdt, nodename, "interrupt-parent", plic_phandle); + qemu_fdt_setprop_cell(fdt, nodename, "interrupts", SIFIVE_U_UART0_IRQ); + + qemu_fdt_add_subnode(fdt, "/chosen"); + qemu_fdt_setprop_string(fdt, "/chosen", "stdout-path", nodename); + qemu_fdt_setprop_string(fdt, "/aliases", "serial0", nodename); + + g_free(nodename); + +update_bootargs: + if (cmdline) { + qemu_fdt_setprop_string(fdt, "/chosen", "bootargs", cmdline); + } +} + +static void sifive_u_machine_reset(void *opaque, int n, int level) +{ + /* gpio pin active low triggers reset */ + if (!level) { + qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET); + } +} + +static void sifive_u_machine_init(MachineState *machine) +{ + const struct MemmapEntry *memmap = sifive_u_memmap; + SiFiveUState *s = RISCV_U_MACHINE(machine); + MemoryRegion *system_memory = get_system_memory(); + MemoryRegion *main_mem = g_new(MemoryRegion, 1); + MemoryRegion *flash0 = g_new(MemoryRegion, 1); + target_ulong start_addr = memmap[SIFIVE_U_DEV_DRAM].base; + target_ulong firmware_end_addr, kernel_start_addr; + uint32_t start_addr_hi32 = 0x00000000; + int i; + uint32_t fdt_load_addr; + uint64_t kernel_entry; + + /* Initialize SoC */ + object_initialize_child(OBJECT(machine), "soc", &s->soc, TYPE_RISCV_U_SOC); + object_property_set_uint(OBJECT(&s->soc), "serial", s->serial, + &error_abort); + object_property_set_str(OBJECT(&s->soc), "cpu-type", machine->cpu_type, + &error_abort); + qdev_realize(DEVICE(&s->soc), NULL, &error_abort); + + /* register RAM */ + memory_region_init_ram(main_mem, NULL, "riscv.sifive.u.ram", + machine->ram_size, &error_fatal); + memory_region_add_subregion(system_memory, memmap[SIFIVE_U_DEV_DRAM].base, + main_mem); + + /* register QSPI0 Flash */ + memory_region_init_ram(flash0, NULL, "riscv.sifive.u.flash0", + memmap[SIFIVE_U_DEV_FLASH0].size, &error_fatal); + memory_region_add_subregion(system_memory, memmap[SIFIVE_U_DEV_FLASH0].base, + flash0); + + /* register gpio-restart */ + qdev_connect_gpio_out(DEVICE(&(s->soc.gpio)), 10, + qemu_allocate_irq(sifive_u_machine_reset, NULL, 0)); + + /* create device tree */ + create_fdt(s, memmap, machine->ram_size, machine->kernel_cmdline); + + if (s->start_in_flash) { + /* + * If start_in_flash property is given, assign s->msel to a value + * that representing booting from QSPI0 memory-mapped flash. + * + * This also means that when both start_in_flash and msel properties + * are given, start_in_flash takes the precedence over msel. + * + * Note this is to keep backward compatibility not to break existing + * users that use start_in_flash property. + */ + s->msel = MSEL_MEMMAP_QSPI0_FLASH; + } + + switch (s->msel) { + case MSEL_MEMMAP_QSPI0_FLASH: + start_addr = memmap[SIFIVE_U_DEV_FLASH0].base; + break; + case MSEL_L2LIM_QSPI0_FLASH: + case MSEL_L2LIM_QSPI2_SD: + start_addr = memmap[SIFIVE_U_DEV_L2LIM].base; + break; + default: + start_addr = memmap[SIFIVE_U_DEV_DRAM].base; + break; + } + + firmware_end_addr = riscv_find_and_load_firmware(machine, BIOS_FILENAME, + start_addr, NULL); + + if (machine->kernel_filename) { + kernel_start_addr = riscv_calc_kernel_start_addr(machine, + firmware_end_addr); + + kernel_entry = riscv_load_kernel(machine->kernel_filename, + kernel_start_addr, NULL); + + if (machine->initrd_filename) { + hwaddr start; + hwaddr end = riscv_load_initrd(machine->initrd_filename, + machine->ram_size, kernel_entry, + &start); + qemu_fdt_setprop_cell(s->fdt, "/chosen", + "linux,initrd-start", start); + qemu_fdt_setprop_cell(s->fdt, "/chosen", "linux,initrd-end", + end); + } + } else { + /* + * If dynamic firmware is used, it doesn't know where is the next mode + * if kernel argument is not set. + */ + kernel_entry = 0; + } + + /* Compute the fdt load address in dram */ + fdt_load_addr = riscv_load_fdt(memmap[SIFIVE_U_DEV_DRAM].base, + machine->ram_size, s->fdt); + #if defined(TARGET_RISCV64) + start_addr_hi32 = start_addr >> 32; + #endif + + /* reset vector */ + uint32_t reset_vec[11] = { + s->msel, /* MSEL pin state */ + 0x00000297, /* 1: auipc t0, %pcrel_hi(fw_dyn) */ + 0x02828613, /* addi a2, t0, %pcrel_lo(1b) */ + 0xf1402573, /* csrr a0, mhartid */ +#if defined(TARGET_RISCV32) + 0x0202a583, /* lw a1, 32(t0) */ + 0x0182a283, /* lw t0, 24(t0) */ +#elif defined(TARGET_RISCV64) + 0x0202b583, /* ld a1, 32(t0) */ + 0x0182b283, /* ld t0, 24(t0) */ +#endif + 0x00028067, /* jr t0 */ + start_addr, /* start: .dword */ + start_addr_hi32, + fdt_load_addr, /* fdt_laddr: .dword */ + 0x00000000, + /* fw_dyn: */ + }; + + /* copy in the reset vector in little_endian byte order */ + for (i = 0; i < ARRAY_SIZE(reset_vec); i++) { + reset_vec[i] = cpu_to_le32(reset_vec[i]); + } + rom_add_blob_fixed_as("mrom.reset", reset_vec, sizeof(reset_vec), + memmap[SIFIVE_U_DEV_MROM].base, &address_space_memory); + + riscv_rom_copy_firmware_info(memmap[SIFIVE_U_DEV_MROM].base, + memmap[SIFIVE_U_DEV_MROM].size, + sizeof(reset_vec), kernel_entry); +} + +static bool sifive_u_machine_get_start_in_flash(Object *obj, Error **errp) +{ + SiFiveUState *s = RISCV_U_MACHINE(obj); + + return s->start_in_flash; +} + +static void sifive_u_machine_set_start_in_flash(Object *obj, bool value, Error **errp) +{ + SiFiveUState *s = RISCV_U_MACHINE(obj); + + s->start_in_flash = value; +} + +static void sifive_u_machine_get_uint32_prop(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + visit_type_uint32(v, name, (uint32_t *)opaque, errp); +} + +static void sifive_u_machine_set_uint32_prop(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + visit_type_uint32(v, name, (uint32_t *)opaque, errp); +} + +static void sifive_u_machine_instance_init(Object *obj) +{ + SiFiveUState *s = RISCV_U_MACHINE(obj); + + s->start_in_flash = false; + s->msel = 0; + object_property_add(obj, "msel", "uint32", + sifive_u_machine_get_uint32_prop, + sifive_u_machine_set_uint32_prop, NULL, &s->msel); + object_property_set_description(obj, "msel", + "Mode Select (MSEL[3:0]) pin state"); + + s->serial = OTP_SERIAL; + object_property_add(obj, "serial", "uint32", + sifive_u_machine_get_uint32_prop, + sifive_u_machine_set_uint32_prop, NULL, &s->serial); + object_property_set_description(obj, "serial", "Board serial number"); +} + +static void sifive_u_machine_class_init(ObjectClass *oc, void *data) +{ + MachineClass *mc = MACHINE_CLASS(oc); + + mc->desc = "RISC-V Board compatible with SiFive U SDK"; + mc->init = sifive_u_machine_init; + mc->max_cpus = 4; + mc->min_cpus = 1; +#if defined(TARGET_RISCV32) + mc->default_cpu_type = TYPE_RISCV_CPU_SIFIVE_U34; +#elif defined(TARGET_RISCV64) + mc->default_cpu_type = TYPE_RISCV_CPU_SIFIVE_U54; +#endif + mc->default_cpus = mc->min_cpus; + + object_class_property_add_bool(oc, "start-in-flash", + sifive_u_machine_get_start_in_flash, + sifive_u_machine_set_start_in_flash); + object_class_property_set_description(oc, "start-in-flash", + "Set on to tell QEMU's ROM to jump to " + "flash. Otherwise QEMU will jump to DRAM " + "or L2LIM depending on the msel value"); +} + +static const TypeInfo sifive_u_machine_typeinfo = { + .name = MACHINE_TYPE_NAME("sifive_u"), + .parent = TYPE_MACHINE, + .class_init = sifive_u_machine_class_init, + .instance_init = sifive_u_machine_instance_init, + .instance_size = sizeof(SiFiveUState), +}; + +static void sifive_u_machine_init_register_types(void) +{ + type_register_static(&sifive_u_machine_typeinfo); +} + +type_init(sifive_u_machine_init_register_types) + +static void sifive_u_soc_instance_init(Object *obj) +{ + MachineState *ms = MACHINE(qdev_get_machine()); + SiFiveUSoCState *s = RISCV_U_SOC(obj); + + object_initialize_child(obj, "cpus", &s->cpus, + TYPE_RISCV_HART_ARRAY); + qdev_prop_set_uint32(DEVICE(&s->cpus), "num-harts", ms->smp.cpus); + qdev_prop_set_uint32(DEVICE(&s->cpus), "hartid-base", 0); + qdev_prop_set_string(DEVICE(&s->cpus), "cpu-type", SIFIVE_U_CPU); + qdev_prop_set_uint64(DEVICE(&s->cpus), "resetvec", 0x1004); + + object_initialize_child(obj, "prci", &s->prci, TYPE_SIFIVE_U_PRCI); + object_initialize_child(obj, "otp", &s->otp, TYPE_SIFIVE_U_OTP); + object_initialize_child(obj, "gem", &s->gem, TYPE_CADENCE_GEM); + object_initialize_child(obj, "gpio", &s->gpio, TYPE_SIFIVE_GPIO); +} + +static void sifive_u_soc_realize(DeviceState *dev, Error **errp) +{ + MachineState *ms = MACHINE(qdev_get_machine()); + SiFiveUSoCState *s = RISCV_U_SOC(dev); + const struct MemmapEntry *memmap = sifive_u_memmap; + MemoryRegion *system_memory = get_system_memory(); + MemoryRegion *mask_rom = g_new(MemoryRegion, 1); + MemoryRegion *l2lim_mem = g_new(MemoryRegion, 1); + char *plic_hart_config; + size_t plic_hart_config_len; + int i; + NICInfo *nd = &nd_table[0]; + + sysbus_realize(SYS_BUS_DEVICE(&s->cpus), &error_abort); + + /* boot rom */ + memory_region_init_rom(mask_rom, OBJECT(dev), "riscv.sifive.u.mrom", + memmap[SIFIVE_U_DEV_MROM].size, &error_fatal); + memory_region_add_subregion(system_memory, memmap[SIFIVE_U_DEV_MROM].base, + mask_rom); + + /* + * Add L2-LIM at reset size. + * This should be reduced in size as the L2 Cache Controller WayEnable + * register is incremented. Unfortunately I don't see a nice (or any) way + * to handle reducing or blocking out the L2 LIM while still allowing it + * be re returned to all enabled after a reset. For the time being, just + * leave it enabled all the time. This won't break anything, but will be + * too generous to misbehaving guests. + */ + memory_region_init_ram(l2lim_mem, NULL, "riscv.sifive.u.l2lim", + memmap[SIFIVE_U_DEV_L2LIM].size, &error_fatal); + memory_region_add_subregion(system_memory, memmap[SIFIVE_U_DEV_L2LIM].base, + l2lim_mem); + + /* create PLIC hart topology configuration string */ + plic_hart_config_len = (strlen(SIFIVE_U_PLIC_HART_CONFIG) + 1) * + ms->smp.cpus; + plic_hart_config = g_malloc0(plic_hart_config_len); + for (i = 0; i < ms->smp.cpus; i++) { + if (i != 0) { + strncat(plic_hart_config, "," SIFIVE_U_PLIC_HART_CONFIG, + plic_hart_config_len); + } else { + strncat(plic_hart_config, "M", plic_hart_config_len); + } + plic_hart_config_len -= (strlen(SIFIVE_U_PLIC_HART_CONFIG) + 1); + } + + /* MMIO */ + s->plic = sifive_plic_create(memmap[SIFIVE_U_DEV_PLIC].base, + plic_hart_config, 0, + SIFIVE_U_PLIC_NUM_SOURCES, + SIFIVE_U_PLIC_NUM_PRIORITIES, + SIFIVE_U_PLIC_PRIORITY_BASE, + SIFIVE_U_PLIC_PENDING_BASE, + SIFIVE_U_PLIC_ENABLE_BASE, + SIFIVE_U_PLIC_ENABLE_STRIDE, + SIFIVE_U_PLIC_CONTEXT_BASE, + SIFIVE_U_PLIC_CONTEXT_STRIDE, + memmap[SIFIVE_U_DEV_PLIC].size); + g_free(plic_hart_config); + sifive_uart_create(system_memory, memmap[SIFIVE_U_DEV_UART0].base, + serial_hd(0), qdev_get_gpio_in(DEVICE(s->plic), SIFIVE_U_UART0_IRQ)); + sifive_uart_create(system_memory, memmap[SIFIVE_U_DEV_UART1].base, + serial_hd(1), qdev_get_gpio_in(DEVICE(s->plic), SIFIVE_U_UART1_IRQ)); + sifive_clint_create(memmap[SIFIVE_U_DEV_CLINT].base, + memmap[SIFIVE_U_DEV_CLINT].size, 0, ms->smp.cpus, + SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE, + SIFIVE_CLINT_TIMEBASE_FREQ, false); + sifive_test_create(memmap[SIFIVE_U_DEV_TEST].base); + + if (!sysbus_realize(SYS_BUS_DEVICE(&s->prci), errp)) { + return; + } + sysbus_mmio_map(SYS_BUS_DEVICE(&s->prci), 0, memmap[SIFIVE_U_DEV_PRCI].base); + + qdev_prop_set_uint32(DEVICE(&s->gpio), "ngpio", 16); + if (!sysbus_realize(SYS_BUS_DEVICE(&s->gpio), errp)) { + return; + } + sysbus_mmio_map(SYS_BUS_DEVICE(&s->gpio), 0, memmap[SIFIVE_U_DEV_GPIO].base); + + /* Pass all GPIOs to the SOC layer so they are available to the board */ + qdev_pass_gpios(DEVICE(&s->gpio), dev, NULL); + + /* Connect GPIO interrupts to the PLIC */ + for (i = 0; i < 16; i++) { + sysbus_connect_irq(SYS_BUS_DEVICE(&s->gpio), i, + qdev_get_gpio_in(DEVICE(s->plic), + SIFIVE_U_GPIO_IRQ0 + i)); + } + + qdev_prop_set_uint32(DEVICE(&s->otp), "serial", s->serial); + if (!sysbus_realize(SYS_BUS_DEVICE(&s->otp), errp)) { + return; + } + sysbus_mmio_map(SYS_BUS_DEVICE(&s->otp), 0, memmap[SIFIVE_U_DEV_OTP].base); + + /* FIXME use qdev NIC properties instead of nd_table[] */ + if (nd->used) { + qemu_check_nic_model(nd, TYPE_CADENCE_GEM); + qdev_set_nic_properties(DEVICE(&s->gem), nd); + } + object_property_set_int(OBJECT(&s->gem), "revision", GEM_REVISION, + &error_abort); + if (!sysbus_realize(SYS_BUS_DEVICE(&s->gem), errp)) { + return; + } + sysbus_mmio_map(SYS_BUS_DEVICE(&s->gem), 0, memmap[SIFIVE_U_DEV_GEM].base); + sysbus_connect_irq(SYS_BUS_DEVICE(&s->gem), 0, + qdev_get_gpio_in(DEVICE(s->plic), SIFIVE_U_GEM_IRQ)); + + create_unimplemented_device("riscv.sifive.u.gem-mgmt", + memmap[SIFIVE_U_DEV_GEM_MGMT].base, memmap[SIFIVE_U_DEV_GEM_MGMT].size); + + create_unimplemented_device("riscv.sifive.u.dmc", + memmap[SIFIVE_U_DEV_DMC].base, memmap[SIFIVE_U_DEV_DMC].size); +} + +static Property sifive_u_soc_props[] = { + DEFINE_PROP_UINT32("serial", SiFiveUSoCState, serial, OTP_SERIAL), + DEFINE_PROP_STRING("cpu-type", SiFiveUSoCState, cpu_type), + DEFINE_PROP_END_OF_LIST() +}; + +static void sifive_u_soc_class_init(ObjectClass *oc, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(oc); + + device_class_set_props(dc, sifive_u_soc_props); + dc->realize = sifive_u_soc_realize; + /* Reason: Uses serial_hds in realize function, thus can't be used twice */ + dc->user_creatable = false; +} + +static const TypeInfo sifive_u_soc_type_info = { + .name = TYPE_RISCV_U_SOC, + .parent = TYPE_DEVICE, + .instance_size = sizeof(SiFiveUSoCState), + .instance_init = sifive_u_soc_instance_init, + .class_init = sifive_u_soc_class_init, +}; + +static void sifive_u_soc_register_types(void) +{ + type_register_static(&sifive_u_soc_type_info); +} + +type_init(sifive_u_soc_register_types) + + + + + + + + + + + + +static void sifive_viu_machine_reset(void *opaque, int n, int level) +{ + /* gpio pin active low triggers reset */ + if (!level) { + qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET); + } +} + +static void sifive_viu_machine_init(MachineState *machine) +{ + const struct MemmapEntry *memmap = sifive_u_memmap; + SiFiveUState *s = RISCV_VIU_MACHINE(machine); + MemoryRegion *system_memory = get_system_memory(); + MemoryRegion *main_mem = g_new(MemoryRegion, 1); + MemoryRegion *flash0 = g_new(MemoryRegion, 1); + target_ulong start_addr = memmap[SIFIVE_U_DEV_DRAM].base; + target_ulong firmware_end_addr, kernel_start_addr; + uint32_t start_addr_hi32 = 0x00000000; + int i; + uint32_t fdt_load_addr; + uint64_t kernel_entry; + + /* Initialize SoC */ + object_initialize_child(OBJECT(machine), "soc", &s->soc, TYPE_RISCV_VIU_SOC); + object_property_set_uint(OBJECT(&s->soc), "serial", s->serial, + &error_abort); + object_property_set_str(OBJECT(&s->soc), "cpu-type", machine->cpu_type, + &error_abort); + qdev_realize(DEVICE(&s->soc), NULL, &error_abort); + + /* register RAM */ + memory_region_init_ram(main_mem, NULL, "riscv.sifive.u.ram", + machine->ram_size, &error_fatal); + memory_region_add_subregion(system_memory, memmap[SIFIVE_U_DEV_DRAM].base, + main_mem); + + /* register QSPI0 Flash */ + memory_region_init_ram(flash0, NULL, "riscv.sifive.u.flash0", + memmap[SIFIVE_U_DEV_FLASH0].size, &error_fatal); + memory_region_add_subregion(system_memory, memmap[SIFIVE_U_DEV_FLASH0].base, + flash0); + + /* register gpio-restart */ + qdev_connect_gpio_out(DEVICE(&(s->soc.gpio)), 10, + qemu_allocate_irq(sifive_viu_machine_reset, NULL, 0)); + + /* create device tree */ + create_fdt(s, memmap, machine->ram_size, machine->kernel_cmdline); + + if (s->start_in_flash) { + /* + * If start_in_flash property is given, assign s->msel to a value + * that representing booting from QSPI0 memory-mapped flash. + * + * This also means that when both start_in_flash and msel properties + * are given, start_in_flash takes the precedence over msel. + * + * Note this is to keep backward compatibility not to break existing + * users that use start_in_flash property. + */ + s->msel = MSEL_MEMMAP_QSPI0_FLASH; + } + + switch (s->msel) { + case MSEL_MEMMAP_QSPI0_FLASH: + start_addr = memmap[SIFIVE_U_DEV_FLASH0].base; + break; + case MSEL_L2LIM_QSPI0_FLASH: + case MSEL_L2LIM_QSPI2_SD: + start_addr = memmap[SIFIVE_U_DEV_L2LIM].base; + break; + default: + start_addr = memmap[SIFIVE_U_DEV_DRAM].base; + break; + } + + firmware_end_addr = riscv_find_and_load_firmware(machine, BIOS_FILENAME, + start_addr, NULL); + + if (machine->kernel_filename) { + kernel_start_addr = riscv_calc_kernel_start_addr(machine, + firmware_end_addr); + + kernel_entry = riscv_load_kernel(machine->kernel_filename, + kernel_start_addr, NULL); + + if (machine->initrd_filename) { + hwaddr start; + hwaddr end = riscv_load_initrd(machine->initrd_filename, + machine->ram_size, kernel_entry, + &start); + qemu_fdt_setprop_cell(s->fdt, "/chosen", + "linux,initrd-start", start); + qemu_fdt_setprop_cell(s->fdt, "/chosen", "linux,initrd-end", + end); + } + } else { + /* + * If dynamic firmware is used, it doesn't know where is the next mode + * if kernel argument is not set. + */ + kernel_entry = 0; + } + + /* Compute the fdt load address in dram */ + fdt_load_addr = riscv_load_fdt(memmap[SIFIVE_U_DEV_DRAM].base, + machine->ram_size, s->fdt); + #if defined(TARGET_RISCV64) + start_addr_hi32 = start_addr >> 32; + #endif + + /* reset vector */ + uint32_t reset_vec[11] = { + s->msel, /* MSEL pin state */ + 0x00000297, /* 1: auipc t0, %pcrel_hi(fw_dyn) */ + 0x02828613, /* addi a2, t0, %pcrel_lo(1b) */ + 0xf1402573, /* csrr a0, mhartid */ +#if defined(TARGET_RISCV32) + 0x0202a583, /* lw a1, 32(t0) */ + 0x0182a283, /* lw t0, 24(t0) */ +#elif defined(TARGET_RISCV64) + 0x0202b583, /* ld a1, 32(t0) */ + 0x0182b283, /* ld t0, 24(t0) */ +#endif + 0x00028067, /* jr t0 */ + start_addr, /* start: .dword */ + start_addr_hi32, + fdt_load_addr, /* fdt_laddr: .dword */ + 0x00000000, + /* fw_dyn: */ + }; + + /* copy in the reset vector in little_endian byte order */ + for (i = 0; i < ARRAY_SIZE(reset_vec); i++) { + reset_vec[i] = cpu_to_le32(reset_vec[i]); + } + rom_add_blob_fixed_as("mrom.reset", reset_vec, sizeof(reset_vec), + memmap[SIFIVE_U_DEV_MROM].base, &address_space_memory); + + riscv_rom_copy_firmware_info(memmap[SIFIVE_U_DEV_MROM].base, + memmap[SIFIVE_U_DEV_MROM].size, + sizeof(reset_vec), kernel_entry); +} + +static bool sifive_viu_machine_get_start_in_flash(Object *obj, Error **errp) +{ + SiFiveUState *s = RISCV_VIU_MACHINE(obj); + + return s->start_in_flash; +} + +static void sifive_viu_machine_set_start_in_flash(Object *obj, bool value, Error **errp) +{ + SiFiveUState *s = RISCV_VIU_MACHINE(obj); + + s->start_in_flash = value; +} + +static void sifive_viu_machine_get_uint32_prop(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + visit_type_uint32(v, name, (uint32_t *)opaque, errp); +} + +static void sifive_viu_machine_set_uint32_prop(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + visit_type_uint32(v, name, (uint32_t *)opaque, errp); +} + +static void sifive_viu_machine_instance_init(Object *obj) +{ + SiFiveUState *s = RISCV_VIU_MACHINE(obj); + + s->start_in_flash = false; + s->msel = 0; + object_property_add(obj, "msel", "uint32", + sifive_viu_machine_get_uint32_prop, + sifive_viu_machine_set_uint32_prop, NULL, &s->msel); + object_property_set_description(obj, "msel", + "Mode Select (MSEL[3:0]) pin state"); + + s->serial = OTP_SERIAL; + object_property_add(obj, "serial", "uint32", + sifive_viu_machine_get_uint32_prop, + sifive_viu_machine_set_uint32_prop, NULL, &s->serial); + object_property_set_description(obj, "serial", "Board serial number"); +} + +static void sifive_viu_machine_class_init(ObjectClass *oc, void *data) +{ + MachineClass *mc = MACHINE_CLASS(oc); + + mc->desc = "RISC-V Board compatible with SiFive VIU SDK"; + mc->init = sifive_viu_machine_init; + mc->max_cpus = 4; + mc->min_cpus = 1; +#if defined(TARGET_RISCV32) + mc->default_cpu_type = TYPE_RISCV_CPU_SIFIVE_U34; +#elif defined(TARGET_RISCV64) + mc->default_cpu_type = TYPE_RISCV_CPU_SIFIVE_U54; +#endif + mc->default_cpus = mc->min_cpus; + + object_class_property_add_bool(oc, "start-in-flash", + sifive_viu_machine_get_start_in_flash, + sifive_viu_machine_set_start_in_flash); + object_class_property_set_description(oc, "start-in-flash", + "Set on to tell QEMU's ROM to jump to " + "flash. Otherwise QEMU will jump to DRAM " + "or L2LIM depending on the msel value"); +} + +static const TypeInfo sifive_viu_machine_typeinfo = { + .name = MACHINE_TYPE_NAME("sifive_viu"), + .parent = TYPE_MACHINE, + .class_init = sifive_viu_machine_class_init, + .instance_init = sifive_viu_machine_instance_init, + .instance_size = sizeof(SiFiveUState), +}; + +static void sifive_viu_machine_init_register_types(void) +{ + type_register_static(&sifive_viu_machine_typeinfo); +} + +type_init(sifive_viu_machine_init_register_types) + +static void sifive_viu_soc_instance_init(Object *obj) +{ + MachineState *ms = MACHINE(qdev_get_machine()); + SiFiveUSoCState *s = RISCV_VIU_SOC(obj); + + object_initialize_child(obj, "cpus", &s->cpus, + TYPE_RISCV_HART_ARRAY); + qdev_prop_set_uint32(DEVICE(&s->cpus), "num-harts", ms->smp.cpus); + qdev_prop_set_uint32(DEVICE(&s->cpus), "hartid-base", 0); + qdev_prop_set_string(DEVICE(&s->cpus), "cpu-type", TYPE_RISCV_CPU_SIFIVE_VIU75); + qdev_prop_set_uint64(DEVICE(&s->cpus), "resetvec", 0x1004); + + object_initialize_child(obj, "prci", &s->prci, TYPE_SIFIVE_U_PRCI); + object_initialize_child(obj, "otp", &s->otp, TYPE_SIFIVE_U_OTP); + object_initialize_child(obj, "gem", &s->gem, TYPE_CADENCE_GEM); + object_initialize_child(obj, "gpio", &s->gpio, TYPE_SIFIVE_GPIO); +} + +static void sifive_viu_soc_realize(DeviceState *dev, Error **errp) +{ + MachineState *ms = MACHINE(qdev_get_machine()); + SiFiveUSoCState *s = RISCV_VIU_SOC(dev); + const struct MemmapEntry *memmap = sifive_u_memmap; + MemoryRegion *system_memory = get_system_memory(); + MemoryRegion *mask_rom = g_new(MemoryRegion, 1); + MemoryRegion *l2lim_mem = g_new(MemoryRegion, 1); + char *plic_hart_config; + size_t plic_hart_config_len; + int i; + NICInfo *nd = &nd_table[0]; + + sysbus_realize(SYS_BUS_DEVICE(&s->cpus), &error_abort); + + /* boot rom */ + memory_region_init_rom(mask_rom, OBJECT(dev), "riscv.sifive.u.mrom", + memmap[SIFIVE_U_DEV_MROM].size, &error_fatal); + memory_region_add_subregion(system_memory, memmap[SIFIVE_U_DEV_MROM].base, + mask_rom); + + /* + * Add L2-LIM at reset size. + * This should be reduced in size as the L2 Cache Controller WayEnable + * register is incremented. Unfortunately I don't see a nice (or any) way + * to handle reducing or blocking out the L2 LIM while still allowing it + * be re returned to all enabled after a reset. For the time being, just + * leave it enabled all the time. This won't break anything, but will be + * too generous to misbehaving guests. + */ + memory_region_init_ram(l2lim_mem, NULL, "riscv.sifive.u.l2lim", + memmap[SIFIVE_U_DEV_L2LIM].size, &error_fatal); + memory_region_add_subregion(system_memory, memmap[SIFIVE_U_DEV_L2LIM].base, + l2lim_mem); + + /* create PLIC hart topology configuration string */ + plic_hart_config_len = (strlen(SIFIVE_U_PLIC_HART_CONFIG) + 1) * + ms->smp.cpus; + plic_hart_config = g_malloc0(plic_hart_config_len); + for (i = 0; i < ms->smp.cpus; i++) { + if (i != 0) { + strncat(plic_hart_config, "," SIFIVE_U_PLIC_HART_CONFIG, + plic_hart_config_len); + } else { + strncat(plic_hart_config, "M", plic_hart_config_len); + } + plic_hart_config_len -= (strlen(SIFIVE_U_PLIC_HART_CONFIG) + 1); + } + + /* MMIO */ + s->plic = sifive_plic_create(memmap[SIFIVE_U_DEV_PLIC].base, + plic_hart_config, 0, + SIFIVE_U_PLIC_NUM_SOURCES, + SIFIVE_U_PLIC_NUM_PRIORITIES, + SIFIVE_U_PLIC_PRIORITY_BASE, + SIFIVE_U_PLIC_PENDING_BASE, + SIFIVE_U_PLIC_ENABLE_BASE, + SIFIVE_U_PLIC_ENABLE_STRIDE, + SIFIVE_U_PLIC_CONTEXT_BASE, + SIFIVE_U_PLIC_CONTEXT_STRIDE, + memmap[SIFIVE_U_DEV_PLIC].size); + g_free(plic_hart_config); + sifive_uart_create(system_memory, memmap[SIFIVE_U_DEV_UART0].base, + serial_hd(0), qdev_get_gpio_in(DEVICE(s->plic), SIFIVE_U_UART0_IRQ)); + sifive_uart_create(system_memory, memmap[SIFIVE_U_DEV_UART1].base, + serial_hd(1), qdev_get_gpio_in(DEVICE(s->plic), SIFIVE_U_UART1_IRQ)); + sifive_clint_create(memmap[SIFIVE_U_DEV_CLINT].base, + memmap[SIFIVE_U_DEV_CLINT].size, 0, ms->smp.cpus, + SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE, + SIFIVE_CLINT_TIMEBASE_FREQ, false); + sifive_test_create(memmap[SIFIVE_U_DEV_TEST].base); + + if (!sysbus_realize(SYS_BUS_DEVICE(&s->prci), errp)) { + return; + } + sysbus_mmio_map(SYS_BUS_DEVICE(&s->prci), 0, memmap[SIFIVE_U_DEV_PRCI].base); + + qdev_prop_set_uint32(DEVICE(&s->gpio), "ngpio", 16); + if (!sysbus_realize(SYS_BUS_DEVICE(&s->gpio), errp)) { + return; + } + sysbus_mmio_map(SYS_BUS_DEVICE(&s->gpio), 0, memmap[SIFIVE_U_DEV_GPIO].base); + + /* Pass all GPIOs to the SOC layer so they are available to the board */ + qdev_pass_gpios(DEVICE(&s->gpio), dev, NULL); + + /* Connect GPIO interrupts to the PLIC */ + for (i = 0; i < 16; i++) { + sysbus_connect_irq(SYS_BUS_DEVICE(&s->gpio), i, + qdev_get_gpio_in(DEVICE(s->plic), + SIFIVE_U_GPIO_IRQ0 + i)); + } + + qdev_prop_set_uint32(DEVICE(&s->otp), "serial", s->serial); + if (!sysbus_realize(SYS_BUS_DEVICE(&s->otp), errp)) { + return; + } + sysbus_mmio_map(SYS_BUS_DEVICE(&s->otp), 0, memmap[SIFIVE_U_DEV_OTP].base); + + /* FIXME use qdev NIC properties instead of nd_table[] */ + if (nd->used) { + qemu_check_nic_model(nd, TYPE_CADENCE_GEM); + qdev_set_nic_properties(DEVICE(&s->gem), nd); + } + object_property_set_int(OBJECT(&s->gem), "revision", GEM_REVISION, + &error_abort); + if (!sysbus_realize(SYS_BUS_DEVICE(&s->gem), errp)) { + return; + } + sysbus_mmio_map(SYS_BUS_DEVICE(&s->gem), 0, memmap[SIFIVE_U_DEV_GEM].base); + sysbus_connect_irq(SYS_BUS_DEVICE(&s->gem), 0, + qdev_get_gpio_in(DEVICE(s->plic), SIFIVE_U_GEM_IRQ)); + + create_unimplemented_device("riscv.sifive.u.gem-mgmt", + memmap[SIFIVE_U_DEV_GEM_MGMT].base, memmap[SIFIVE_U_DEV_GEM_MGMT].size); + + create_unimplemented_device("riscv.sifive.u.dmc", + memmap[SIFIVE_U_DEV_DMC].base, memmap[SIFIVE_U_DEV_DMC].size); +} + +static Property sifive_viu_soc_props[] = { + DEFINE_PROP_UINT32("serial", SiFiveUSoCState, serial, OTP_SERIAL), + DEFINE_PROP_STRING("cpu-type", SiFiveUSoCState, cpu_type), + DEFINE_PROP_END_OF_LIST() +}; + +static void sifive_viu_soc_class_init(ObjectClass *oc, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(oc); + + device_class_set_props(dc, sifive_viu_soc_props); + dc->realize = sifive_viu_soc_realize; + /* Reason: Uses serial_hds in realize function, thus can't be used twice */ + dc->user_creatable = false; +} + +static const TypeInfo sifive_viu_soc_type_info = { + .name = TYPE_RISCV_VIU_SOC, + .parent = TYPE_DEVICE, + .instance_size = sizeof(SiFiveUSoCState), + .instance_init = sifive_viu_soc_instance_init, + .class_init = sifive_viu_soc_class_init, +}; + +static void sifive_viu_soc_register_types(void) +{ + type_register_static(&sifive_viu_soc_type_info); +} + +type_init(sifive_viu_soc_register_types) diff --git a/modules/freedom-qemu/patches/qemu-sifive-u.h b/modules/freedom-qemu/patches/qemu-sifive-u.h new file mode 100644 index 0000000..44781cc --- /dev/null +++ b/modules/freedom-qemu/patches/qemu-sifive-u.h @@ -0,0 +1,140 @@ +/* + * SiFive U series machine interface + * + * Copyright (c) 2017 SiFive, Inc. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2 or later, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#ifndef HW_SIFIVE_U_H +#define HW_SIFIVE_U_H + +#include "hw/net/cadence_gem.h" +#include "hw/riscv/riscv_hart.h" +#include "hw/riscv/sifive_cpu.h" +#include "hw/gpio/sifive_gpio.h" +#include "hw/misc/sifive_u_otp.h" +#include "hw/misc/sifive_u_prci.h" + +#define TYPE_RISCV_U_SOC "riscv.sifive.u.soc" +#define RISCV_U_SOC(obj) \ + OBJECT_CHECK(SiFiveUSoCState, (obj), TYPE_RISCV_U_SOC) + +#define TYPE_RISCV_VIU_SOC "riscv.sifive.viu.soc" +#define RISCV_VIU_SOC(obj) \ + OBJECT_CHECK(SiFiveUSoCState, (obj), TYPE_RISCV_VIU_SOC) + +typedef struct SiFiveUSoCState { + /*< private >*/ + DeviceState parent_obj; + + /*< public >*/ + RISCVHartArrayState cpus; + DeviceState *plic; + SiFiveUPRCIState prci; + SIFIVEGPIOState gpio; + SiFiveUOTPState otp; + CadenceGEMState gem; + + uint32_t serial; + char *cpu_type; +} SiFiveUSoCState; + +#define TYPE_RISCV_U_MACHINE MACHINE_TYPE_NAME("sifive_u") +#define RISCV_U_MACHINE(obj) \ + OBJECT_CHECK(SiFiveUState, (obj), TYPE_RISCV_U_MACHINE) + +#define TYPE_RISCV_VIU_MACHINE MACHINE_TYPE_NAME("sifive_viu") +#define RISCV_VIU_MACHINE(obj) \ + OBJECT_CHECK(SiFiveUState, (obj), TYPE_RISCV_VIU_MACHINE) + +typedef struct SiFiveUState { + /*< private >*/ + MachineState parent_obj; + + /*< public >*/ + SiFiveUSoCState soc; + + void *fdt; + int fdt_size; + + bool start_in_flash; + uint32_t msel; + uint32_t serial; +} SiFiveUState; + +enum { + SIFIVE_U_DEV_DEBUG, + SIFIVE_U_DEV_MROM, + SIFIVE_U_DEV_TEST, + SIFIVE_U_DEV_CLINT, + SIFIVE_U_DEV_L2LIM, + SIFIVE_U_DEV_PLIC, + SIFIVE_U_DEV_PRCI, + SIFIVE_U_DEV_UART0, + SIFIVE_U_DEV_UART1, + SIFIVE_U_DEV_GPIO, + SIFIVE_U_DEV_OTP, + SIFIVE_U_DEV_DMC, + SIFIVE_U_DEV_FLASH0, + SIFIVE_U_DEV_DRAM, + SIFIVE_U_DEV_GEM, + SIFIVE_U_DEV_GEM_MGMT +}; + +enum { + SIFIVE_U_UART0_IRQ = 3, + SIFIVE_U_UART1_IRQ = 4, + SIFIVE_U_GPIO_IRQ0 = 7, + SIFIVE_U_GPIO_IRQ1 = 8, + SIFIVE_U_GPIO_IRQ2 = 9, + SIFIVE_U_GPIO_IRQ3 = 10, + SIFIVE_U_GPIO_IRQ4 = 11, + SIFIVE_U_GPIO_IRQ5 = 12, + SIFIVE_U_GPIO_IRQ6 = 13, + SIFIVE_U_GPIO_IRQ7 = 14, + SIFIVE_U_GPIO_IRQ8 = 15, + SIFIVE_U_GPIO_IRQ9 = 16, + SIFIVE_U_GPIO_IRQ10 = 17, + SIFIVE_U_GPIO_IRQ11 = 18, + SIFIVE_U_GPIO_IRQ12 = 19, + SIFIVE_U_GPIO_IRQ13 = 20, + SIFIVE_U_GPIO_IRQ14 = 21, + SIFIVE_U_GPIO_IRQ15 = 22, + SIFIVE_U_GEM_IRQ = 0x35 +}; + +enum { + SIFIVE_U_CLOCK_FREQ = 1000000000, + SIFIVE_U_GEM_CLOCK_FREQ = 125000000, + SIFIVE_U_HFCLK_FREQ = 33333333, + SIFIVE_U_RTCCLK_FREQ = 1000000 +}; + +enum { + MSEL_MEMMAP_QSPI0_FLASH = 1, + MSEL_L2LIM_QSPI0_FLASH = 6, + MSEL_L2LIM_QSPI2_SD = 11 +}; + +#define SIFIVE_U_PLIC_HART_CONFIG "MS" +#define SIFIVE_U_PLIC_NUM_SOURCES 54 +#define SIFIVE_U_PLIC_NUM_PRIORITIES 7 +#define SIFIVE_U_PLIC_PRIORITY_BASE 0x04 +#define SIFIVE_U_PLIC_PENDING_BASE 0x1000 +#define SIFIVE_U_PLIC_ENABLE_BASE 0x2000 +#define SIFIVE_U_PLIC_ENABLE_STRIDE 0x80 +#define SIFIVE_U_PLIC_CONTEXT_BASE 0x200000 +#define SIFIVE_U_PLIC_CONTEXT_STRIDE 0x1000 + +#endif diff --git a/modules/freedom-qemu/patches/qemu-util-meson.build b/modules/freedom-qemu/patches/qemu-util-meson.build new file mode 100644 index 0000000..63f57ed --- /dev/null +++ b/modules/freedom-qemu/patches/qemu-util-meson.build @@ -0,0 +1,79 @@ +util_ss.add(dependency('threads')) +util_ss.add(files('osdep.c', 'cutils.c', 'unicode.c', 'qemu-timer-common.c')) +util_ss.add(when: 'CONFIG_ATOMIC64', if_false: files('atomic64.c')) +util_ss.add(when: 'CONFIG_POSIX', if_true: files('aio-posix.c')) +util_ss.add(when: 'CONFIG_POSIX', if_true: files('fdmon-poll.c')) +util_ss.add(when: 'CONFIG_EPOLL_CREATE1', if_true: files('fdmon-epoll.c')) +util_ss.add(when: ['CONFIG_LINUX_IO_URING', linux_io_uring], if_true: files('fdmon-io_uring.c')) +util_ss.add(when: 'CONFIG_POSIX', if_true: files('compatfd.c')) +util_ss.add(when: 'CONFIG_POSIX', if_true: files('event_notifier-posix.c')) +util_ss.add(when: 'CONFIG_POSIX', if_true: files('mmap-alloc.c')) +util_ss.add(when: 'CONFIG_POSIX', if_true: files('oslib-posix.c')) +util_ss.add(when: 'CONFIG_POSIX', if_true: [files('qemu-openpty.c'), util]) +util_ss.add(when: 'CONFIG_POSIX', if_true: files('qemu-thread-posix.c')) +util_ss.add(when: 'CONFIG_POSIX', if_true: files('memfd.c')) +util_ss.add(when: 'CONFIG_WIN32', if_true: files('aio-win32.c')) +util_ss.add(when: 'CONFIG_WIN32', if_true: files('event_notifier-win32.c')) +util_ss.add(when: 'CONFIG_WIN32', if_true: files('oslib-win32.c')) +util_ss.add(when: 'CONFIG_WIN32', if_true: files('qemu-thread-win32.c')) +util_ss.add(when: 'CONFIG_WIN32', if_true: winmm) +util_ss.add(files('envlist.c', 'path.c', 'module.c')) +util_ss.add(files('host-utils.c')) +util_ss.add(files('bitmap.c', 'bitops.c')) +util_ss.add(files('fifo8.c')) +util_ss.add(files('cacheinfo.c')) +util_ss.add(files('error.c', 'qemu-error.c')) +util_ss.add(files('qemu-print.c')) +util_ss.add(files('id.c')) +util_ss.add(files('qemu-config.c', 'notify.c')) +util_ss.add(files('qemu-option.c', 'qemu-progress.c')) +util_ss.add(files('keyval.c')) +util_ss.add(files('crc32c.c')) +util_ss.add(files('uuid.c')) +util_ss.add(files('getauxval.c')) +util_ss.add(files('rcu.c')) +util_ss.add(when: 'CONFIG_MEMBARRIER', if_true: files('sys_membarrier.c')) +util_ss.add(files('log.c')) +util_ss.add(files('pagesize.c')) +util_ss.add(files('qdist.c')) +util_ss.add(files('qht.c')) +util_ss.add(files('qsp.c')) +util_ss.add(files('range.c')) +util_ss.add(files('stats64.c')) +util_ss.add(files('systemd.c')) +util_ss.add(when: 'CONFIG_POSIX', if_true: files('drm.c')) +util_ss.add(files('guest-random.c')) + +if have_user + util_ss.add(files('selfmap.c')) +endif + +if have_system + util_ss.add(when: 'CONFIG_GIO', if_true: [files('dbus.c'), gio]) +endif + +if have_block + util_ss.add(files('aiocb.c', 'async.c', 'aio-wait.c')) + util_ss.add(files('base64.c')) + util_ss.add(files('buffer.c')) + util_ss.add(files('bufferiszero.c')) + util_ss.add(files('coroutine-@0@.c'.format(config_host['CONFIG_COROUTINE_BACKEND']))) + util_ss.add(files('hbitmap.c')) + util_ss.add(files('hexdump.c')) + util_ss.add(files('iova-tree.c')) + util_ss.add(files('iov.c', 'qemu-sockets.c', 'uri.c')) + util_ss.add(files('lockcnt.c')) + util_ss.add(files('main-loop.c')) + util_ss.add(files('nvdimm-utils.c')) + util_ss.add(files('qemu-coroutine.c', 'qemu-coroutine-lock.c', 'qemu-coroutine-io.c')) + util_ss.add(files('block-helpers.c')) + util_ss.add(files('qemu-coroutine-sleep.c')) + util_ss.add(files('qemu-co-shared-resource.c')) + util_ss.add(files('thread-pool.c', 'qemu-timer.c')) + util_ss.add(files('readline.c')) + util_ss.add(files('throttle.c')) + util_ss.add(files('timed-average.c')) + util_ss.add(when: 'CONFIG_INOTIFY1', if_true: files('filemonitor-inotify.c'), + if_false: files('filemonitor-stub.c')) + util_ss.add(when: 'CONFIG_LINUX', if_true: files('vfio-helpers.c')) +endif diff --git a/modules/freedom-qemu/patches/qemu-vl.sed b/modules/freedom-qemu/patches/qemu-vl.sed new file mode 100644 index 0000000..9d002b0 --- /dev/null +++ b/modules/freedom-qemu/patches/qemu-vl.sed @@ -0,0 +1 @@ +:a;N;$!ba;s/case QEMU_OPTION_version:.*case QEMU_OPTION_m:/case QEMU_OPTION_version: version\(\)\; fflush\(stdout\)\; if \(argc < 3\) \{ exit\(0\)\; \} break\; case QEMU_OPTION_m:/ diff --git a/modules/freedom-sdk-utilities.mk b/modules/freedom-sdk-utilities.mk deleted file mode 100644 index d563bbb..0000000 --- a/modules/freedom-sdk-utilities.mk +++ /dev/null @@ -1,38 +0,0 @@ - -FREEDOM_SDK_UTILITIES_GITURL := git@github.com:sifive/freedom-sdk-utilities.git -FREEDOM_SDK_UTILITIES_BRANCH := main -FREEDOM_SDK_UTILITIES_MODULE := $(SRCDIR)/freedom-sdk-utilities - -ifneq ($(TARGET_GITURL),) -FREEDOM_SDK_UTILITIES_GITURL := $(TARGET_GITURL) -endif -ifneq ($(TARGET_BRANCH),) -FREEDOM_SDK_UTILITIES_BRANCH := $(TARGET_BRANCH) -endif - -.PHONY: sdk-utilities sdk-utilities-package sdk-utilities-regress sdk-utilities-cleanup sdk-utilities-flushup -sdk-utilities: sdk-utilities-package - -$(FREEDOM_SDK_UTILITIES_MODULE).$(FREEDOM_SDK_UTILITIES_BRANCH): - mkdir -p $(dir $@) - rm -rf $(FREEDOM_SDK_UTILITIES_MODULE) - rm -rf $(FREEDOM_SDK_UTILITIES_MODULE).* - git clone $(FREEDOM_SDK_UTILITIES_GITURL) $(FREEDOM_SDK_UTILITIES_MODULE) --single-branch -b $(FREEDOM_SDK_UTILITIES_BRANCH) - cd $(FREEDOM_SDK_UTILITIES_MODULE) && git submodule update --init --recursive - date > $@ - -sdk-utilities-package: \ - $(FREEDOM_SDK_UTILITIES_MODULE).$(FREEDOM_SDK_UTILITIES_BRANCH) - $(MAKE) -C $(FREEDOM_SDK_UTILITIES_MODULE) package BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) - -sdk-utilities-regress: \ - $(FREEDOM_SDK_UTILITIES_MODULE).$(FREEDOM_SDK_UTILITIES_BRANCH) - $(MAKE) -C $(FREEDOM_SDK_UTILITIES_MODULE) regress BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) - -sdk-utilities-cleanup: - $(MAKE) -C $(FREEDOM_SDK_UTILITIES_MODULE) cleanup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ - rm -rf $(FREEDOM_SDK_UTILITIES_MODULE).* - rm -rf $(FREEDOM_SDK_UTILITIES_MODULE) - -sdk-utilities-flushup: - $(MAKE) -C $(FREEDOM_SDK_UTILITIES_MODULE) flushup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ diff --git a/modules/freedom-sdk-utilities/Makefile b/modules/freedom-sdk-utilities/Makefile new file mode 100644 index 0000000..f95b09b --- /dev/null +++ b/modules/freedom-sdk-utilities/Makefile @@ -0,0 +1,155 @@ +# Setup the Freedom build script environment +include ../../scripts/Freedom.mk + +# Include version identifiers to build up the full version string +include Metadata.mk +PACKAGE_WORDING := SDK Utilities +PACKAGE_HEADING := sdk-utilities +PACKAGE_VERSION := $(RISCV_ISA_SIM_VERSION)-$(FREEDOM_SDK_UTILITIES_ID)$(EXTRA_SUFFIX) +PACKAGE_COMMENT := \# SiFive Freedom Package Properties File + +# Some special package configure flags for specific targets +$(WIN64)-dtc-configure := CROSSPREFIX=x86_64-w64-mingw32- BINEXT=.exe CC=gcc +$(WIN64)-fe2h-configure := CROSSPREFIX=x86_64-w64-mingw32- BINEXT=.exe CC=gcc +$(WIN64)-sdasm-configure := CROSSPREFIX=x86_64-w64-mingw32- BINEXT=.exe CXX=g++ + +# Setup the package targets and switch into secondary makefile targets +# Targets $(PACKAGE_HEADING)/install.stamp and $(PACKAGE_HEADING)/libs.stamp +include ../../scripts/Package.mk + +$(OBJDIR)/%/build/$(PACKAGE_HEADING)/install.stamp: \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/$(RISCV_ISA_SIM_FOLDER)/build.stamp + $(eval $@_TARGET := $(patsubst $(OBJDIR)/%/build/$(PACKAGE_HEADING)/install.stamp,%,$@)) + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/install.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET),$@)) + $(eval $@_PROPERTIES := $(patsubst %/build/$(PACKAGE_HEADING)/install.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET).properties,$@)) + mkdir -p $(dir $@) + git log --format="[%ad] %s" > $(abspath $($@_INSTALL))/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET).changelog + rm -f $(abspath $($@_PROPERTIES)) + echo "$(PACKAGE_COMMENT)" > $(abspath $($@_PROPERTIES)) + echo "PACKAGE_TYPE = freedom-tools" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_DESC_SEG = $(PACKAGE_WORDING)" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_FIXED_ID = $(PACKAGE_HEADING)" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_BUILD_ID = $(FREEDOM_SDK_UTILITIES_ID)$(EXTRA_SUFFIX)" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_CORE_VER = $(RISCV_ISA_SIM_VERSION)" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_TARGET = $($@_TARGET)" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_VENDOR = SiFive" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_RIGHTS = sifive-v00 eclipse-v20" >> $(abspath $($@_PROPERTIES)) + echo "RISCV_TAGS = $(FREEDOM_SDK_UTILITIES_RISCV_TAGS)" >> $(abspath $($@_PROPERTIES)) + echo "TOOLS_TAGS = $(FREEDOM_SDK_UTILITIES_TOOLS_TAGS)" >> $(abspath $($@_PROPERTIES)) + cp $(abspath $($@_PROPERTIES)) $(abspath $($@_INSTALL))/ + tclsh ../../scripts/check-maximum-path-length.tcl $(abspath $($@_INSTALL)) "$(PACKAGE_HEADING)" "$(RISCV_ISA_SIM_VERSION)" "$(FREEDOM_SDK_UTILITIES_ID)$(EXTRA_SUFFIX)" + tclsh ../../scripts/check-same-name-different-case.tcl $(abspath $($@_INSTALL)) + date > $@ + +# We might need some extra target libraries for this package +$(OBJ_NATIVE)/build/$(PACKAGE_HEADING)/libs.stamp: \ + $(OBJ_NATIVE)/build/$(PACKAGE_HEADING)/install.stamp + date > $@ + +$(OBJ_WIN64)/build/$(PACKAGE_HEADING)/libs.stamp: \ + $(OBJ_WIN64)/build/$(PACKAGE_HEADING)/install.stamp + -$(WIN64)-gcc -print-search-dirs | grep ^programs | cut -d= -f2- | tr : "\n" | xargs -I {} find {} -iname "libwinpthread*.dll" | xargs cp -t $(OBJDIR)/$(WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64)/bin + -$(WIN64)-gcc -print-search-dirs | grep ^libraries | cut -d= -f2- | tr : "\n" | xargs -I {} find {} -iname "libgcc_s_seh*.dll" | xargs cp -t $(OBJDIR)/$(WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64)/bin + -$(WIN64)-gcc -print-search-dirs | grep ^libraries | cut -d= -f2- | tr : "\n" | xargs -I {} find {} -iname "libstdc*.dll" | xargs cp -t $(OBJDIR)/$(WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64)/bin + -$(WIN64)-gcc -print-search-dirs | grep ^libraries | cut -d= -f2- | tr : "\n" | xargs -I {} find {} -iname "libssp*.dll" | xargs cp -t $(OBJDIR)/$(WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64)/bin + date > $@ + +$(OBJDIR)/%/build/$(PACKAGE_HEADING)/source.stamp: + $(eval $@_TARGET := $(patsubst $(OBJDIR)/%/build/$(PACKAGE_HEADING)/source.stamp,%,$@)) + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/source.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET),$@)) + $(eval $@_BUILDLOG := $(abspath $(patsubst %/build/$(PACKAGE_HEADING)/source.stamp,%/buildlog/$(PACKAGE_HEADING),$@))) + $(eval $@_SRCBALL := $(abspath $(BINDIR)/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET).src.tar.gz)) + tclsh ../../scripts/check-naming-and-version-syntax.tcl "$(PACKAGE_WORDING)" "$(PACKAGE_HEADING)" "$(RISCV_ISA_SIM_VERSION)" "$(FREEDOM_SDK_UTILITIES_ID)$(EXTRA_SUFFIX)" + rm -rf $($@_INSTALL) + mkdir -p $($@_INSTALL) + rm -rf $($@_BUILDLOG) + mkdir -p $($@_BUILDLOG) + rm -rf $(dir $@) + mkdir -p $(dir $@) + git log > $($@_BUILDLOG)/$(PACKAGE_HEADING)-git-commit.log + git remote -v > $($@_BUILDLOG)/$(PACKAGE_HEADING)-git-remote.log + cd $(dir $@); curl -L -f -s -o dtc-1.5.0.tar.gz https://github.com/dgibson/dtc/archive/v1.5.0.tar.gz + cd $(dir $@); $(TAR) -xf dtc-1.5.0.tar.gz + cd $(dir $@); mv dtc-1.5.0 dtc + rm -rf $(dir $@)/dtc/Makefile + cp -a patches/dtc.mk $(dir $@)/dtc/Makefile + $(SED) -i -f patches/dtc-fstree.sed $(dir $@)/dtc/fstree.c + git clone --single-branch --branch $(RISCV_ISA_SIM_BRANCH) $(RISCV_ISA_SIM_GITURL) $(dir $@)/$(RISCV_ISA_SIM_FOLDER) + cd $(dir $@)/$(RISCV_ISA_SIM_FOLDER) && git checkout --detach $(RISCV_ISA_SIM_COMMIT) + cd $(dir $@)/$(RISCV_ISA_SIM_FOLDER) && git submodule update --init --recursive + git clone --single-branch --branch $(FREEDOM_ELF2HEX_BRANCH) $(FREEDOM_ELF2HEX_GITURL) $(dir $@)/$(FREEDOM_ELF2HEX_FOLDER) + cd $(dir $@)/$(FREEDOM_ELF2HEX_FOLDER) && git checkout --detach $(FREEDOM_ELF2HEX_COMMIT) + cd $(dir $@)/$(FREEDOM_ELF2HEX_FOLDER) && git submodule update --init --recursive + rm -rf $(dir $@)/$(RISCV_ISA_SIM_FOLDER)/Makefile + cp patches/spike-dasm.mk $(dir $@)/$(RISCV_ISA_SIM_FOLDER)/Makefile + rm -rf $(dir $@)/$(RISCV_ISA_SIM_FOLDER)/config.h + cp patches/spike-dasm-config.h $(dir $@)/$(RISCV_ISA_SIM_FOLDER)/config.h + rm -rf $(dir $@)/$(RISCV_ISA_SIM_FOLDER)/riscv/extension.h + cp patches/spike-dasm-extension.h $(dir $@)/$(RISCV_ISA_SIM_FOLDER)/riscv/extension.h + rm -rf $(dir $@)/$(RISCV_ISA_SIM_FOLDER)/riscv/extensions.cc + cp patches/spike-dasm-extensions.cc $(dir $@)/$(RISCV_ISA_SIM_FOLDER)/riscv/extensions.cc + mkdir -p $(dir $($@_SRCBALL)) + cd $(dir $@); $(TAR) --dereference --hard-dereference -c dtc $(RISCV_ISA_SIM_FOLDER) $(FREEDOM_ELF2HEX_FOLDER) | gzip > $($@_SRCBALL) + date > $@ + +$(OBJ_NATIVE)/build/$(PACKAGE_HEADING)/dtc/build.stamp: \ + $(OBJ_NATIVE)/build/$(PACKAGE_HEADING)/source.stamp + $(MAKE) -j1 -C $(dir $@) install PREFIX=$(abspath $(OBJ_NATIVE)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(NATIVE)) \ + $($(NATIVE)-dtc-configure) NO_PYTHON=1 NO_YAML=1 NO_VALGRIND=1 &>$(OBJ_NATIVE)/buildlog/$(PACKAGE_HEADING)/dtc-make-install.log + rm -f $(abspath $(OBJ_NATIVE)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(NATIVE))/lib/lib*.dylib* + rm -f $(abspath $(OBJ_NATIVE)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(NATIVE))/lib/lib*.so* + rm -f $(abspath $(OBJ_NATIVE)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(NATIVE))/lib64/lib*.so* + tclsh ../../scripts/dyn-lib-check-$(NATIVE).tcl $(abspath $(OBJ_NATIVE)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(NATIVE))/bin/dtc + tclsh ../../scripts/dyn-lib-check-$(NATIVE).tcl $(abspath $(OBJ_NATIVE)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(NATIVE))/bin/fdtdump + tclsh ../../scripts/dyn-lib-check-$(NATIVE).tcl $(abspath $(OBJ_NATIVE)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(NATIVE))/bin/fdtget + tclsh ../../scripts/dyn-lib-check-$(NATIVE).tcl $(abspath $(OBJ_NATIVE)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(NATIVE))/bin/fdtoverlay + tclsh ../../scripts/dyn-lib-check-$(NATIVE).tcl $(abspath $(OBJ_NATIVE)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(NATIVE))/bin/fdtput + date > $@ + +$(OBJ_WIN64)/build/$(PACKAGE_HEADING)/dtc/build.stamp: \ + $(OBJ_WIN64)/build/$(PACKAGE_HEADING)/source.stamp + $(SED) -i -f patches/dtc-lexer.sed $(dir $@)/dtc-lexer.l + $(MAKE) -j1 -C $(dir $@) install PREFIX=$(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64)) \ + $($(WIN64)-dtc-configure) NO_PYTHON=1 NO_YAML=1 NO_VALGRIND=1 &>$(OBJ_WIN64)/buildlog/$(PACKAGE_HEADING)/dtc-make-install.log + rm -f $(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64))/lib/lib*.dylib* + rm -f $(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64))/lib/lib*.so* + rm -f $(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64))/lib64/lib*.so* + tclsh ../../scripts/dyn-lib-check-$(WIN64).tcl $(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64))/bin/dtc + tclsh ../../scripts/dyn-lib-check-$(WIN64).tcl $(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64))/bin/fdtdump + tclsh ../../scripts/dyn-lib-check-$(WIN64).tcl $(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64))/bin/fdtget + tclsh ../../scripts/dyn-lib-check-$(WIN64).tcl $(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64))/bin/fdtoverlay + tclsh ../../scripts/dyn-lib-check-$(WIN64).tcl $(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64))/bin/fdtput + date > $@ + +$(OBJDIR)/%/build/$(PACKAGE_HEADING)/$(FREEDOM_ELF2HEX_FOLDER)/build.stamp: \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/source.stamp + $(eval $@_TARGET := $(patsubst $(OBJDIR)/%/build/$(PACKAGE_HEADING)/$(FREEDOM_ELF2HEX_FOLDER)/build.stamp,%,$@)) + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/$(FREEDOM_ELF2HEX_FOLDER)/build.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET),$@)) + $(eval $@_BUILDLOG := $(abspath $(patsubst %/build/$(PACKAGE_HEADING)/$(FREEDOM_ELF2HEX_FOLDER)/build.stamp,%/buildlog/$(PACKAGE_HEADING),$@))) + $(MAKE) -C $(dir $@) -j1 install INSTALL_PATH=$(abspath $($@_INSTALL)) \ + $($($@_TARGET)-fe2h-configure) &>$($@_BUILDLOG)/$(FREEDOM_ELF2HEX_FOLDER)-make-install.log + tclsh ../../scripts/dyn-lib-check-$($@_TARGET).tcl $(abspath $($@_INSTALL))/util/freedom-bin2hex + date > $@ + +$(OBJDIR)/%/build/$(PACKAGE_HEADING)/$(RISCV_ISA_SIM_FOLDER)/build.stamp: \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/dtc/build.stamp \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/$(FREEDOM_ELF2HEX_FOLDER)/build.stamp \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/source.stamp + $(eval $@_TARGET := $(patsubst $(OBJDIR)/%/build/$(PACKAGE_HEADING)/$(RISCV_ISA_SIM_FOLDER)/build.stamp,%,$@)) + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/$(RISCV_ISA_SIM_FOLDER)/build.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET),$@)) + $(eval $@_BUILDLOG := $(abspath $(patsubst %/build/$(PACKAGE_HEADING)/$(RISCV_ISA_SIM_FOLDER)/build.stamp,%/buildlog/$(PACKAGE_HEADING),$@))) + $(MAKE) -C $(dir $@) -j1 install \ + EXEC_PREFIX=z \ + SOURCE_PATH=$(abspath $(dir $@)) \ + INSTALL_PATH=$(abspath $($@_INSTALL)) \ + $($($@_TARGET)-sdasm-configure) &>$($@_BUILDLOG)/$(RISCV_ISA_SIM_FOLDER)-make-install.log + tclsh ../../scripts/dyn-lib-check-$($@_TARGET).tcl $(abspath $($@_INSTALL))/bin/zspike-dasm + date > $@ + +$(OBJDIR)/$(NATIVE)/test/$(PACKAGE_HEADING)/test.stamp: \ + $(OBJDIR)/$(NATIVE)/test/$(PACKAGE_HEADING)/launch.stamp + mkdir -p $(dir $@) +# PATH=$(abspath $(OBJDIR)/$(NATIVE)/launch/$(PACKAGE_TARNAME)/bin):$(PATH) zspike-dasm -h + @echo "zspike-dasm executable cannot be run with a -v option without failing!" + @echo "Finished testing $(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(NATIVE).tar.gz tarball" + date > $@ diff --git a/modules/freedom-sdk-utilities/Metadata.mk b/modules/freedom-sdk-utilities/Metadata.mk new file mode 100644 index 0000000..4542011 --- /dev/null +++ b/modules/freedom-sdk-utilities/Metadata.mk @@ -0,0 +1,19 @@ +# Git repos, branches, commits and folders to get source code for the tool we are building +RISCV_ISA_SIM_GITURL := git@github.com:riscv/riscv-isa-sim.git +RISCV_ISA_SIM_BRANCH := master +RISCV_ISA_SIM_COMMIT := f1bcfac7ebe334ebdef39a5d59e18e37eef813a5 +RISCV_ISA_SIM_FOLDER := riscv-isa-sim +FREEDOM_ELF2HEX_GITURL := git@github.com:sifive/freedom-elf2hex.git +FREEDOM_ELF2HEX_BRANCH := master +FREEDOM_ELF2HEX_COMMIT := 7bcc57b85fdb7002dffb6e7515d8b8ecac32cfcd +FREEDOM_ELF2HEX_FOLDER := freedom-elf2hex + +# Version number, which should match the official version of the tool we are building +RISCV_ISA_SIM_VERSION := 1.0.1 + +# Customization ID, which should identify the customization added to the original by SiFive +FREEDOM_SDK_UTILITIES_ID := 2020.12.1 + +# Characteristic tags, which should be usable for matching up providers and consumers +FREEDOM_SDK_UTILITIES_RISCV_TAGS = rv32i rv64i m a f d c v zfh zba zbb +FREEDOM_SDK_UTILITIES_TOOLS_TAGS = dtc libfdt elf2hex zspike-dasm diff --git a/modules/freedom-sdk-utilities/Monorepo.mk b/modules/freedom-sdk-utilities/Monorepo.mk new file mode 100644 index 0000000..d0dab24 --- /dev/null +++ b/modules/freedom-sdk-utilities/Monorepo.mk @@ -0,0 +1,35 @@ +.PHONY: sdk-utilities sdk-utilities-package sdk-utilities-native-package sdk-utilities-cross-package +.PHONY: sdk-utilities-regress +.PHONY: sdk-utilities-cleanup sdk-utilities-native-cleanup sdk-utilities-cross-cleanup +.PHONY: sdk-utilities-flushup sdk-utilities-native-flushup sdk-utilities-cross-flushup +sdk-utilities: sdk-utilities-package + +sdk-utilities-package: + $(MAKE) -C modules/freedom-sdk-utilities package BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) + +sdk-utilities-native-package: + $(MAKE) -C modules/freedom-sdk-utilities native-package BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) + +sdk-utilities-cross-package: + $(MAKE) -C modules/freedom-sdk-utilities cross-package BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) + +sdk-utilities-regress: + $(MAKE) -C modules/freedom-sdk-utilities regress BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) + +sdk-utilities-cleanup: + $(MAKE) -C modules/freedom-sdk-utilities cleanup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + +sdk-utilities-native-cleanup: + $(MAKE) -C modules/freedom-sdk-utilities native-cleanup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + +sdk-utilities-cross-cleanup: + $(MAKE) -C modules/freedom-sdk-utilities cross-cleanup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + +sdk-utilities-flushup: + $(MAKE) -C modules/freedom-sdk-utilities flushup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + +sdk-utilities-native-flushup: + $(MAKE) -C modules/freedom-sdk-utilities native-flushup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + +sdk-utilities-cross-flushup: + $(MAKE) -C modules/freedom-sdk-utilities cross-flushup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ diff --git a/modules/freedom-sdk-utilities/patches/dtc-fstree.sed b/modules/freedom-sdk-utilities/patches/dtc-fstree.sed new file mode 100644 index 0000000..cd3c901 --- /dev/null +++ b/modules/freedom-sdk-utilities/patches/dtc-fstree.sed @@ -0,0 +1 @@ +s/lstat/X_LSTAT / diff --git a/modules/freedom-sdk-utilities/patches/dtc-lexer.sed b/modules/freedom-sdk-utilities/patches/dtc-lexer.sed new file mode 100644 index 0000000..c340930 --- /dev/null +++ b/modules/freedom-sdk-utilities/patches/dtc-lexer.sed @@ -0,0 +1 @@ +s/YYLTYPE yylloc/extern YYLTYPE yylloc/ diff --git a/modules/freedom-sdk-utilities/patches/dtc.mk b/modules/freedom-sdk-utilities/patches/dtc.mk new file mode 100644 index 0000000..b8ed0d7 --- /dev/null +++ b/modules/freedom-sdk-utilities/patches/dtc.mk @@ -0,0 +1,379 @@ +# +# Device Tree Compiler +# + +# +# Version information will be constructed in this order: +# EXTRAVERSION might be "-rc", for example. +# LOCAL_VERSION is likely from command line. +# CONFIG_LOCALVERSION from some future config system. +# +VERSION = 1 +PATCHLEVEL = 5 +SUBLEVEL = 0 +EXTRAVERSION = +LOCAL_VERSION = +CONFIG_LOCALVERSION = + +CPPFLAGS = -I libfdt -I . +WARNINGS = -Wall -Wpointer-arith -Wcast-qual -Wnested-externs \ + -Wstrict-prototypes -Wmissing-prototypes -Wredundant-decls -Wshadow +CFLAGS = -g -Os $(SHAREDLIB_CFLAGS) $(WARNINGS) + +BISON = bison +LEX = flex +SWIG = swig +PKG_CONFIG ?= pkg-config +PYTHON ?= python2 + +INSTALL = /usr/bin/install +INSTALL_PROGRAM = $(INSTALL) +INSTALL_LIB = $(INSTALL) +INSTALL_DATA = $(INSTALL) -m 644 +INSTALL_SCRIPT = $(INSTALL) +DESTDIR = +PREFIX = $(HOME) +BINDIR = $(PREFIX)/bin +LIBDIR = $(PREFIX)/lib +INCLUDEDIR = $(PREFIX)/include + +HOSTOS := $(shell uname -s | tr '[:upper:]' '[:lower:]' | \ + sed -e 's/\(cygwin\|msys\).*/\1/') + +NO_VALGRIND := $(shell $(PKG_CONFIG) --exists valgrind; echo $$?) +ifeq ($(NO_VALGRIND),1) + CFLAGS += -DNO_VALGRIND +else + CFLAGS += $(shell $(PKG_CONFIG) --cflags valgrind) +endif + +NO_YAML := $(shell $(PKG_CONFIG) --exists yaml-0.1; echo $$?) +ifeq ($(NO_YAML),1) + CFLAGS += -DNO_YAML +else + LDLIBS += $(shell $(PKG_CONFIG) --libs yaml-0.1) +endif + +ifeq ($(HOSTOS),darwin) +SHAREDLIB_EXT = dylib +SHAREDLIB_CFLAGS = -fPIC +SHAREDLIB_LDFLAGS = -fPIC -dynamiclib -Wl,-install_name -Wl, +CFLAGS += -Werror -DX_LSTAT=lstat +else ifeq ($(HOSTOS),$(filter $(HOSTOS),msys cygwin)) +SHAREDLIB_EXT = so +SHAREDLIB_CFLAGS = +SHAREDLIB_LDFLAGS = -shared -Wl,--version-script=$(LIBFDT_version) -Wl,-soname, +CFLAGS += -Werror -DX_LSTAT=stat +else ifeq ($(BINEXT),.exe) +SHAREDLIB_EXT = so +SHAREDLIB_CFLAGS = +SHAREDLIB_LDFLAGS = -shared -Wl,--version-script=$(LIBFDT_version) -Wl,-soname, +CFLAGS += -DX_LSTAT=stat +else +SHAREDLIB_EXT = so +SHAREDLIB_CFLAGS = -fPIC +SHAREDLIB_LDFLAGS = -fPIC -shared -Wl,--version-script=$(LIBFDT_version) -Wl,-soname, +CFLAGS += -Werror -DX_LSTAT=lstat +endif + +# +# Overall rules +# +ifdef V +VECHO = : +else +VECHO = echo " " +ARFLAGS = rc +.SILENT: +endif + +NODEPTARGETS = clean +ifeq ($(MAKECMDGOALS),) +DEPTARGETS = all +else +DEPTARGETS = $(filter-out $(NODEPTARGETS),$(MAKECMDGOALS)) +endif + +# +# Rules for versioning +# + +DTC_VERSION = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION) +VERSION_FILE = version_gen.h + +CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \ + else if [ -x /bin/bash ]; then echo /bin/bash; \ + else echo sh; fi ; fi) + +nullstring := +space := $(nullstring) # end of line + +localver_config = $(subst $(space),, $(string) \ + $(patsubst "%",%,$(CONFIG_LOCALVERSION))) + +localver_cmd = $(subst $(space),, $(string) \ + $(patsubst "%",%,$(LOCALVERSION))) + +localver_scm = $(shell $(CONFIG_SHELL) ./scripts/setlocalversion) +localver_full = $(localver_config)$(localver_cmd)$(localver_scm) + +dtc_version = $(DTC_VERSION)$(localver_full) + +# Contents of the generated version file. +define filechk_version + (echo "#define DTC_VERSION \"DTC $(dtc_version)\""; ) +endef + +define filechk + set -e; \ + echo ' CHK $@'; \ + mkdir -p $(dir $@); \ + $(filechk_$(1)) < $< > $@.tmp; \ + if [ -r $@ ] && cmp -s $@ $@.tmp; then \ + rm -f $@.tmp; \ + else \ + echo ' UPD $@'; \ + mv -f $@.tmp $@; \ + fi; +endef + + +#include Makefile.convert-dtsv0 +include Makefile.dtc +include Makefile.utils + +#BIN += convert-dtsv0$(BINEXT) +BIN += dtc$(BINEXT) +BIN += fdtdump$(BINEXT) +BIN += fdtget$(BINEXT) +BIN += fdtput$(BINEXT) +BIN += fdtoverlay$(BINEXT) + +SCRIPTS = dtdiff + +all: $(BIN) libfdt + +# We need both Python and swig to build/install pylibfdt. +# This builds the given make ${target} if those deps are found. +check_python_deps = \ + if $(PKG_CONFIG) --cflags $(PYTHON) >/dev/null 2>&1; then \ + if which swig >/dev/null 2>&1; then \ + can_build=yes; \ + fi; \ + fi; \ + if [ "$${can_build}" = "yes" ]; then \ + $(MAKE) $${target}; \ + else \ + echo "\#\# Skipping pylibfdt (install python dev and swig to build)"; \ + fi ; + +.PHONY: maybe_pylibfdt +maybe_pylibfdt: FORCE + target=pylibfdt; $(check_python_deps) + +ifeq ($(NO_PYTHON),) +all: maybe_pylibfdt +endif + + +ifneq ($(DEPTARGETS),) +-include $(DTC_OBJS:%.o=%.d) +#-include $(CONVERT_OBJS:%.o=%.d) +-include $(FDTDUMP_OBJS:%.o=%.d) +-include $(FDTGET_OBJS:%.o=%.d) +-include $(FDTPUT_OBJS:%.o=%.d) +-include $(FDTOVERLAY_OBJS:%.o=%.d) +endif + + + +# +# Rules for libfdt +# +LIBFDT_dir = libfdt +LIBFDT_archive = $(LIBFDT_dir)/libfdt.a +LIBFDT_lib = $(LIBFDT_dir)/libfdt-$(DTC_VERSION).$(SHAREDLIB_EXT) +LIBFDT_include = $(addprefix $(LIBFDT_dir)/,$(LIBFDT_INCLUDES)) +LIBFDT_version = $(addprefix $(LIBFDT_dir)/,$(LIBFDT_VERSION)) + +include $(LIBFDT_dir)/Makefile.libfdt + +.PHONY: libfdt +libfdt: $(LIBFDT_archive) $(LIBFDT_lib) + +$(LIBFDT_archive): $(addprefix $(LIBFDT_dir)/,$(LIBFDT_OBJS)) +$(LIBFDT_lib): $(addprefix $(LIBFDT_dir)/,$(LIBFDT_OBJS)) + +ifneq ($(DEPTARGETS),) +-include $(LIBFDT_OBJS:%.o=$(LIBFDT_dir)/%.d) +endif + +# This stops make from generating the lex and bison output during +# auto-dependency computation, but throwing them away as an +# intermediate target and building them again "for real" +.SECONDARY: $(DTC_GEN_SRCS) #$(CONVERT_GEN_SRCS) + +install-bin: all $(SCRIPTS) + @$(VECHO) INSTALL-BIN + $(INSTALL) -d $(DESTDIR)$(BINDIR) + $(INSTALL_PROGRAM) $(BIN) $(DESTDIR)$(BINDIR) + $(INSTALL_SCRIPT) $(SCRIPTS) $(DESTDIR)$(BINDIR) + +install-lib: all + @$(VECHO) INSTALL-LIB + $(INSTALL) -d $(DESTDIR)$(LIBDIR) + $(INSTALL_LIB) $(LIBFDT_lib) $(DESTDIR)$(LIBDIR) + ln -sf $(notdir $(LIBFDT_lib)) $(DESTDIR)$(LIBDIR)/$(LIBFDT_soname) + ln -sf $(LIBFDT_soname) $(DESTDIR)$(LIBDIR)/libfdt.$(SHAREDLIB_EXT) + $(INSTALL_DATA) $(LIBFDT_archive) $(DESTDIR)$(LIBDIR) + +install-includes: + @$(VECHO) INSTALL-INC + $(INSTALL) -d $(DESTDIR)$(INCLUDEDIR) + $(INSTALL_DATA) $(LIBFDT_include) $(DESTDIR)$(INCLUDEDIR) + +install: install-bin install-lib install-includes + +.PHONY: maybe_install_pylibfdt +maybe_install_pylibfdt: FORCE + target=install_pylibfdt; $(check_python_deps) + +ifeq ($(NO_PYTHON),) +install: maybe_install_pylibfdt +endif + +$(VERSION_FILE): Makefile FORCE + $(call filechk,version) + + +dtc$(BINEXT): $(DTC_OBJS) + +#convert-dtsv0$(BINEXT): $(CONVERT_OBJS) +# @$(VECHO) LD $@ +# $(CROSSPREFIX)$(LINK.c) -o $@ $^ + +fdtdump$(BINEXT): $(FDTDUMP_OBJS) + +fdtget$(BINEXT): $(FDTGET_OBJS) $(LIBFDT_archive) + +fdtput$(BINEXT): $(FDTPUT_OBJS) $(LIBFDT_archive) + +fdtoverlay$(BINEXT): $(FDTOVERLAY_OBJS) $(LIBFDT_archive) + +dist: + git archive --format=tar --prefix=dtc-$(dtc_version)/ HEAD \ + > ../dtc-$(dtc_version).tar + cat ../dtc-$(dtc_version).tar | \ + gzip -9 > ../dtc-$(dtc_version).tar.gz + + +# +# Rules for pylibfdt +# +PYLIBFDT_dir = pylibfdt + +include $(PYLIBFDT_dir)/Makefile.pylibfdt + +.PHONY: pylibfdt +pylibfdt: $(PYLIBFDT_dir)/_libfdt.so + +# +# Release signing and uploading +# This is for maintainer convenience, don't try this at home. +# +ifeq ($(MAINTAINER),y) +GPG = gpg2 +KUP = kup +KUPDIR = /pub/software/utils/dtc + +kup: dist + $(GPG) --detach-sign --armor -o ../dtc-$(dtc_version).tar.sign \ + ../dtc-$(dtc_version).tar + $(KUP) put ../dtc-$(dtc_version).tar.gz ../dtc-$(dtc_version).tar.sign \ + $(KUPDIR)/dtc-$(dtc_version).tar.gz +endif + +tags: FORCE + rm -f tags + find . \( -name tests -type d -prune \) -o \ + \( ! -name '*.tab.[ch]' ! -name '*.lex.c' \ + -name '*.[chly]' -type f -print \) | xargs ctags -a + +# +# Testsuite rules +# +TESTS_PREFIX=tests/ + +TESTS_BIN += dtc$(BINEXT) +#TESTS_BIN += convert-dtsv0$(BINEXT) +TESTS_BIN += fdtput$(BINEXT) +TESTS_BIN += fdtget$(BINEXT) +TESTS_BIN += fdtdump$(BINEXT) +TESTS_BIN += fdtoverlay$(BINEXT) +ifeq ($(NO_PYTHON),) +TESTS_PYLIBFDT += maybe_pylibfdt +endif + +include tests/Makefile.tests + +# +# Clean rules +# +STD_CLEANFILES = *~ *.o *.$(SHAREDLIB_EXT) *.d *.a *.i *.s core a.out vgcore.* \ + *.tab.[ch] *.lex.c *.output + +clean: libfdt_clean pylibfdt_clean tests_clean + @$(VECHO) CLEAN + rm -f $(STD_CLEANFILES) + rm -f $(VERSION_FILE) + rm -f $(BIN) + rm -f dtc-*.tar dtc-*.tar.sign dtc-*.tar.asc + +# +# Generic compile rules +# +%$(BINEXT): %.o + @$(VECHO) LD $@ + $(CROSSPREFIX)$(LINK.c) -o $@ $^ $(LDLIBS) + +%.o: %.c + @$(VECHO) CC $@ + $(CROSSPREFIX)$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ -c $< + +%.o: %.S + @$(VECHO) AS $@ + $(CROSSPREFIX)$(CC) $(CPPFLAGS) $(AFLAGS) -D__ASSEMBLY__ -o $@ -c $< + +%.d: %.c + @$(VECHO) DEP $< + $(CROSSPREFIX)$(CC) $(CPPFLAGS) -MM -MG -MT "$*.o $@" $< > $@ + +%.d: %.S + @$(VECHO) DEP $< + $(CROSSPREFIX)$(CC) $(CPPFLAGS) -MM -MG -MT "$*.o $@" $< > $@ + +%.i: %.c + @$(VECHO) CPP $@ + $(CROSSPREFIX)$(CC) $(CPPFLAGS) -E $< > $@ + +%.s: %.c + @$(VECHO) CC -S $@ + $(CROSSPREFIX)$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ -S $< + +%.a: + @$(VECHO) AR $@ + $(CROSSPREFIX)$(AR) $(ARFLAGS) $@ $^ + +$(LIBFDT_lib): + @$(VECHO) LD $@ + $(CROSSPREFIX)$(CC) $(LDFLAGS) $(SHAREDLIB_LDFLAGS)$(LIBFDT_soname) -o $(LIBFDT_lib) $^ + +%.lex.c: %.l + @$(VECHO) LEX $@ + $(LEX) -o$@ $< + +%.tab.c %.tab.h %.output: %.y + @$(VECHO) BISON $@ + $(BISON) -d $< + +FORCE: diff --git a/modules/freedom-sdk-utilities/patches/spike-dasm-config.h b/modules/freedom-sdk-utilities/patches/spike-dasm-config.h new file mode 100644 index 0000000..5b6c14a --- /dev/null +++ b/modules/freedom-sdk-utilities/patches/spike-dasm-config.h @@ -0,0 +1,2 @@ + +#define DEFAULT_ISA "RV64IMAFDC" diff --git a/modules/freedom-sdk-utilities/patches/spike-dasm-extension.h b/modules/freedom-sdk-utilities/patches/spike-dasm-extension.h new file mode 100644 index 0000000..098c88c --- /dev/null +++ b/modules/freedom-sdk-utilities/patches/spike-dasm-extension.h @@ -0,0 +1,18 @@ +// See LICENSE for license details. + +#ifndef _RISCV_COPROCESSOR_H +#define _RISCV_COPROCESSOR_H + +#include "disasm.h" +#include +#include + +class extension_t +{ + public: + virtual std::vector get_disasms() = 0; +}; + +std::function find_extension(const char* name); + +#endif diff --git a/modules/freedom-sdk-utilities/patches/spike-dasm-extensions.cc b/modules/freedom-sdk-utilities/patches/spike-dasm-extensions.cc new file mode 100644 index 0000000..d07480c --- /dev/null +++ b/modules/freedom-sdk-utilities/patches/spike-dasm-extensions.cc @@ -0,0 +1,28 @@ +// See LICENSE for license details. + +#include "extension.h" +#include +#include + +static std::map>& extensions() +{ + static std::map> v; + return v; +} + +void register_extension(const char* name, std::function f) +{ + extensions()[name] = f; +} + +std::function find_extension(const char* name) +{ + if (!extensions().count(name)) { + std::string libname = std::string("lib") + name + ".so"; + fprintf(stderr, "does not support loading extension '%s' (or library '%s')\n", + name, libname.c_str()); + exit(-1); + } + + return extensions()[name]; +} diff --git a/modules/freedom-sdk-utilities/patches/spike-dasm.mk b/modules/freedom-sdk-utilities/patches/spike-dasm.mk new file mode 100644 index 0000000..cb70f8b --- /dev/null +++ b/modules/freedom-sdk-utilities/patches/spike-dasm.mk @@ -0,0 +1,51 @@ + +# which g++ compiler to use for compiling spike-dasm +CROSSPREFIX ?= + +# optional prefix for spike-asm executable +EXEC_PREFIX ?= + +# optional prefix for spike-asm executable +BINEXT ?= + +# which g++ compiler to use for compiling spike-dasm +CXX ?= + +# where to find the source files for a spike-dasm build +SOURCE_PATH ?=. + +# where to install all the artifacts of a spike-dasm build +INSTALL_PATH ?=./install + +# which source files to use for compiling spike-dasm +SOURCE_FILES = \ + $(SOURCE_PATH)/riscv/extensions.cc \ + $(SOURCE_PATH)/disasm/regnames.cc \ + $(SOURCE_PATH)/disasm/disasm.cc \ + $(SOURCE_PATH)/spike_dasm/spike_dasm_option_parser.cc \ + $(SOURCE_PATH)/spike_dasm/spike-dasm.cc + +# which include paths to use for compiling spike-dasm +INCLUDE_PATHS = \ + -I. \ + -I$(SOURCE_PATH) \ + -I$(SOURCE_PATH)/fesvr \ + -I$(SOURCE_PATH)/riscv \ + -I$(SOURCE_PATH)/softfloat + +# the full name of the spike-asm executable inluding all prefix and suffix +EXEC_ALLFIX = $(EXEC_PREFIX)spike-dasm$(BINEXT) + +.PHONY: all install +all: $(EXEC_ALLFIX) + +$(EXEC_ALLFIX): $(SOURCE_FILES) + $(CROSSPREFIX)$(CXX) -Wall -Wno-unused -std=c++11 $(INCLUDE_PATHS) -o $@ $(SOURCE_FILES) + +install: $(EXEC_ALLFIX) + rm -rf $(INSTALL_PATH)/bin/$(EXEC_ALLFIX) + mkdir -p $(INSTALL_PATH)/bin + cp $(EXEC_ALLFIX) $(INSTALL_PATH)/bin/$(EXEC_ALLFIX) + +clean: + rm -rf $(EXEC_ALLFIX) diff --git a/modules/freedom-toolchain-metal.mk b/modules/freedom-toolchain-metal.mk deleted file mode 100644 index 5269325..0000000 --- a/modules/freedom-toolchain-metal.mk +++ /dev/null @@ -1,68 +0,0 @@ - -FREEDOM_TOOLCHAIN_METAL_GITURL := git@github.com:sifive/freedom-toolchain-metal.git -FREEDOM_TOOLCHAIN_METAL_BRANCH := main -FREEDOM_TOOLCHAIN_METAL_MODULE := $(SRCDIR)/freedom-toolchain-metal - -ifneq ($(TARGET_GITURL),) -FREEDOM_TOOLCHAIN_METAL_GITURL := $(TARGET_GITURL) -endif -ifneq ($(TARGET_BRANCH),) -FREEDOM_TOOLCHAIN_METAL_BRANCH := $(TARGET_BRANCH) -endif - -ifneq ($(TOOLSUITE_TOOLCHAIN_GITURL),) -FREEDOM_TOOLCHAIN_METAL_GITURL := $(TOOLSUITE_TOOLCHAIN_GITURL) -endif -ifneq ($(TOOLSUITE_TOOLCHAIN_BRANCH),) -FREEDOM_TOOLCHAIN_METAL_BRANCH := $(TOOLSUITE_TOOLCHAIN_BRANCH) -endif - -.PHONY: toolchain-metal toolchain-metal-package toolchain-metal-regress toolchain-metal-cleanup toolchain-metal-flushup -toolchain-metal: toolchain-metal-package - -.PHONY: toolchain toolchain-package toolchain-regress -toolchain-package: toolchain-metal-package -toolchain-regress: toolchain-metal-regress -toolchain: toolchain-metal - -$(FREEDOM_TOOLCHAIN_METAL_MODULE).$(FREEDOM_TOOLCHAIN_METAL_BRANCH): - mkdir -p $(dir $@) - rm -rf $(FREEDOM_TOOLCHAIN_METAL_MODULE) - rm -rf $(FREEDOM_TOOLCHAIN_METAL_MODULE).* - git clone $(FREEDOM_TOOLCHAIN_METAL_GITURL) $(FREEDOM_TOOLCHAIN_METAL_MODULE) -b $(FREEDOM_TOOLCHAIN_METAL_BRANCH) - cd $(FREEDOM_TOOLCHAIN_METAL_MODULE) && git submodule update --init --recursive - date > $@ - -toolchain-metal-package: \ - $(FREEDOM_BINUTILS_METAL_MODULE).$(FREEDOM_BINUTILS_METAL_BRANCH) \ - $(FREEDOM_GCC_METAL_MODULE).$(FREEDOM_GCC_METAL_BRANCH) \ - $(FREEDOM_GDB_METAL_MODULE).$(FREEDOM_GDB_METAL_BRANCH) \ - $(FREEDOM_TOOLCHAIN_METAL_MODULE).$(FREEDOM_TOOLCHAIN_METAL_BRANCH) - $(MAKE) -C $(FREEDOM_BINUTILS_METAL_MODULE) package BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) - $(MAKE) -C $(FREEDOM_GCC_METAL_MODULE) package BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) - $(MAKE) -C $(FREEDOM_GDB_METAL_MODULE) package BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) - $(MAKE) -C $(FREEDOM_TOOLCHAIN_METAL_MODULE) package BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) - -toolchain-metal-regress: \ - $(FREEDOM_TOOLCHAIN_METAL_MODULE).$(FREEDOM_TOOLCHAIN_METAL_BRANCH) - $(MAKE) -C $(FREEDOM_TOOLCHAIN_METAL_MODULE) regress BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) - -toolchain-metal-cleanup: - $(MAKE) -C $(FREEDOM_BINTUILS_METAL_MODULE) cleanup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ - rm -rf $(FREEDOM_BINTUILS_METAL_MODULE).* - rm -rf $(FREEDOM_BINTUILS_METAL_MODULE) - $(MAKE) -C $(FREEDOM_GCC_METAL_MODULE) cleanup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ - rm -rf $(FREEDOM_GCC_METAL_MODULE).* - rm -rf $(FREEDOM_GCC_METAL_MODULE) - $(MAKE) -C $(FREEDOM_GDB_METAL_MODULE) cleanup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ - rm -rf $(FREEDOM_GDB_METAL_MODULE).* - rm -rf $(FREEDOM_GDB_METAL_MODULE) - $(MAKE) -C $(FREEDOM_TOOLCHAIN_METAL_MODULE) cleanup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ - rm -rf $(FREEDOM_TOOLCHAIN_METAL_MODULE).* - rm -rf $(FREEDOM_TOOLCHAIN_METAL_MODULE) - -toolchain-metal-flushup: - $(MAKE) -C $(FREEDOM_BINUTILS_METAL_MODULE) flushup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ - $(MAKE) -C $(FREEDOM_GCC_METAL_MODULE) flushup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ - $(MAKE) -C $(FREEDOM_GDB_METAL_MODULE) flushup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ - $(MAKE) -C $(FREEDOM_TOOLCHAIN_METAL_MODULE) flushup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ diff --git a/modules/freedom-toolchain-metal/Makefile b/modules/freedom-toolchain-metal/Makefile new file mode 100644 index 0000000..591494e --- /dev/null +++ b/modules/freedom-toolchain-metal/Makefile @@ -0,0 +1,179 @@ +# Setup the Freedom build script environment +include ../../scripts/Freedom.mk + +# Include version identifiers to build up the full version string +include Metadata.mk +PACKAGE_WORDING := Bare Metal Toolchain +PACKAGE_HEADING := riscv64-unknown-elf-toolchain +PACKAGE_VERSION := $(RISCV_TOOLCHAIN_VERSION)-$(FREEDOM_TOOLCHAIN_METAL_ID)$(EXTRA_SUFFIX) +PACKAGE_COMMENT := \# SiFive Freedom Package Properties File + +# Some special package references for specific targets +NATIVE_BINUTILS_TARBALL = $(wildcard $(BINDIR)/riscv64-unknown-elf-binutils-*-$(NATIVE).tar.gz) +NATIVE_GCC_TARBALL = $(wildcard $(BINDIR)/riscv64-unknown-elf-gcc-*-$(NATIVE).tar.gz) +NATIVE_GDB_TARBALL = $(wildcard $(BINDIR)/riscv64-unknown-elf-gdb-*-$(NATIVE).tar.gz) +WIN64_BINUTILS_TARBALL = $(wildcard $(BINDIR)/riscv64-unknown-elf-binutils-*-$(WIN64).tar.gz) +WIN64_GCC_TARBALL = $(wildcard $(BINDIR)/riscv64-unknown-elf-gcc-*-$(WIN64).tar.gz) +WIN64_GDB_TARBALL = $(wildcard $(BINDIR)/riscv64-unknown-elf-gdb-*-$(WIN64).tar.gz) + +# Setup the package targets and switch into secondary makefile targets +# Targets $(PACKAGE_HEADING)/install.stamp and $(PACKAGE_HEADING)/libs.stamp +include ../../scripts/Package.mk + +$(OBJDIR)/%/build/$(PACKAGE_HEADING)/install.stamp: \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/build-gdb/build.stamp + $(eval $@_TARGET := $(patsubst $(OBJDIR)/%/build/$(PACKAGE_HEADING)/install.stamp,%,$@)) + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/install.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET),$@)) + $(eval $@_PROPERTIES := $(patsubst %/build/$(PACKAGE_HEADING)/install.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET).properties,$@)) + $(eval $@_BUILDLOG := $(abspath $(patsubst %/build/$(PACKAGE_HEADING)/install.stamp,%/buildlog/$(PACKAGE_HEADING),$@))) + mkdir -p $(dir $@) + git log --format="[%ad] %s" > $(abspath $($@_INSTALL))/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET).changelog + rm -f $(abspath $($@_PROPERTIES)) + echo "$(PACKAGE_COMMENT)" > $(abspath $($@_PROPERTIES)) + echo "PACKAGE_TYPE = freedom-tools" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_DESC_SEG = $(PACKAGE_WORDING)" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_FIXED_ID = $(PACKAGE_HEADING)" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_BUILD_ID = $(FREEDOM_TOOLCHAIN_METAL_ID)$(EXTRA_SUFFIX)" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_CORE_VER = $(RISCV_TOOLCHAIN_VERSION)" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_TARGET = $($@_TARGET)" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_VENDOR = SiFive" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_RIGHTS = sifive-v00 eclipse-v20" >> $(abspath $($@_PROPERTIES)) + echo "RISCV_TAGS = $(FREEDOM_TOOLCHAIN_METAL_RISCV_TAGS)" >> $(abspath $($@_PROPERTIES)) + echo "TOOLS_TAGS = $(FREEDOM_TOOLCHAIN_METAL_TOOLS_TAGS)" >> $(abspath $($@_PROPERTIES)) + cp $(abspath $($@_PROPERTIES)) $(abspath $($@_INSTALL))/ + tclsh ../../scripts/check-maximum-path-length.tcl $(abspath $($@_INSTALL)) "$(PACKAGE_HEADING)" "$(RISCV_TOOLCHAIN_VERSION)" "$(FREEDOM_TOOLCHAIN_METAL_ID)$(EXTRA_SUFFIX)" + tclsh ../../scripts/check-same-name-different-case.tcl $(abspath $($@_INSTALL)) + echo $(PATH) + date > $@ + +# We might need some extra target libraries for this package +$(OBJ_NATIVE)/build/$(PACKAGE_HEADING)/libs.stamp: \ + $(OBJ_NATIVE)/build/$(PACKAGE_HEADING)/install.stamp + date > $@ + +$(OBJ_WIN64)/build/$(PACKAGE_HEADING)/libs.stamp: \ + $(OBJ_WIN64)/build/$(PACKAGE_HEADING)/install.stamp + date > $@ + +$(OBJDIR)/%/build/$(PACKAGE_HEADING)/source.stamp: + $(eval $@_TARGET := $(patsubst $(OBJDIR)/%/build/$(PACKAGE_HEADING)/source.stamp,%,$@)) + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/source.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET),$@)) + $(eval $@_BUILDLOG := $(abspath $(patsubst %/build/$(PACKAGE_HEADING)/source.stamp,%/buildlog/$(PACKAGE_HEADING),$@))) + tclsh ../../scripts/check-naming-and-version-syntax.tcl "$(PACKAGE_WORDING)" "$(PACKAGE_HEADING)" "$(RISCV_TOOLCHAIN_VERSION)" "$(FREEDOM_TOOLCHAIN_METAL_ID)$(EXTRA_SUFFIX)" + rm -rf $($@_INSTALL) + mkdir -p $($@_INSTALL) + rm -rf $($@_BUILDLOG) + mkdir -p $($@_BUILDLOG) + rm -rf $(dir $@) + mkdir -p $(dir $@) + git log > $($@_BUILDLOG)/$(PACKAGE_HEADING)-git-commit.log + git remote -v > $($@_BUILDLOG)/$(PACKAGE_HEADING)-git-remote.log + date > $@ + +$(OBJ_NATIVE)/build/$(PACKAGE_HEADING)/build-binutils/build.stamp: \ + $(OBJ_NATIVE)/build/$(PACKAGE_HEADING)/source.stamp +ifneq ($(NATIVE_BINUTILS_TARBALL),) + $(eval $@_TARNAME = $(basename $(basename $(notdir $(NATIVE_BINUTILS_TARBALL))))) + mkdir -p $(OBJ_NATIVE)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(NATIVE) + rm -rf $(OBJ_NATIVE)/install/$($@_TARNAME) + $(TAR) -xz -C $(OBJ_NATIVE)/install -f $(NATIVE_BINUTILS_TARBALL) + cp $(OBJ_NATIVE)/install/$($@_TARNAME)/$($@_TARNAME).properties $(OBJ_NATIVE)/buildlog/$(PACKAGE_HEADING)/ + rm -f $(OBJ_NATIVE)/install/$($@_TARNAME)/$($@_TARNAME).properties + cp -RL $(OBJ_NATIVE)/install/$($@_TARNAME)/* $(OBJ_NATIVE)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(NATIVE)/ + rm -rf $(BINDIR)/$($@_TARNAME).properties + rm -rf $(BINDIR)/$($@_TARNAME).tar.gz + rm -rf $(BINDIR)/$($@_TARNAME).zip +endif + mkdir -p $(dir $@) + date > $@ + +$(OBJ_NATIVE)/build/$(PACKAGE_HEADING)/build-gcc/build.stamp: \ + $(OBJ_NATIVE)/build/$(PACKAGE_HEADING)/build-binutils/build.stamp +ifneq ($(NATIVE_GCC_TARBALL),) + $(eval $@_TARNAME = $(basename $(basename $(notdir $(NATIVE_GCC_TARBALL))))) + mkdir -p $(OBJ_NATIVE)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(NATIVE) + rm -rf $(OBJ_NATIVE)/install/$($@_TARNAME) + $(TAR) -xz -C $(OBJ_NATIVE)/install -f $(NATIVE_GCC_TARBALL) + cp $(OBJ_NATIVE)/install/$($@_TARNAME)/$($@_TARNAME).properties $(OBJ_NATIVE)/buildlog/$(PACKAGE_HEADING)/ + rm -f $(OBJ_NATIVE)/install/$($@_TARNAME)/$($@_TARNAME).properties + cp -RL $(OBJ_NATIVE)/install/$($@_TARNAME)/* $(OBJ_NATIVE)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(NATIVE)/ + rm -rf $(BINDIR)/$($@_TARNAME).properties + rm -rf $(BINDIR)/$($@_TARNAME).tar.gz + rm -rf $(BINDIR)/$($@_TARNAME).zip +endif + mkdir -p $(dir $@) + date > $@ + +$(OBJ_NATIVE)/build/$(PACKAGE_HEADING)/build-gdb/build.stamp: \ + $(OBJ_NATIVE)/build/$(PACKAGE_HEADING)/build-gcc/build.stamp +ifneq ($(NATIVE_GDB_TARBALL),) + $(eval $@_TARNAME = $(basename $(basename $(notdir $(NATIVE_GDB_TARBALL))))) + mkdir -p $(OBJ_NATIVE)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(NATIVE) + rm -rf $(OBJ_NATIVE)/install/$($@_TARNAME) + $(TAR) -xz -C $(OBJ_NATIVE)/install -f $(NATIVE_GDB_TARBALL) + cp $(OBJ_NATIVE)/install/$($@_TARNAME)/$($@_TARNAME).properties $(OBJ_NATIVE)/buildlog/$(PACKAGE_HEADING)/ + rm -f $(OBJ_NATIVE)/install/$($@_TARNAME)/$($@_TARNAME).properties + cp -RL $(OBJ_NATIVE)/install/$($@_TARNAME)/* $(OBJ_NATIVE)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(NATIVE)/ + rm -rf $(BINDIR)/$($@_TARNAME).properties + rm -rf $(BINDIR)/$($@_TARNAME).tar.gz + rm -rf $(BINDIR)/$($@_TARNAME).zip +endif + mkdir -p $(dir $@) + date > $@ + +$(OBJ_WIN64)/build/$(PACKAGE_HEADING)/build-binutils/build.stamp: \ + $(OBJ_WIN64)/build/$(PACKAGE_HEADING)/source.stamp +ifneq ($(WIN64_BINUTILS_TARBALL),) + $(eval $@_TARNAME = $(basename $(basename $(notdir $(WIN64_BINUTILS_TARBALL))))) + mkdir -p $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64) + rm -rf $(OBJ_WIN64)/install/$($@_TARNAME) + $(TAR) -xz -C $(OBJ_WIN64)/install -f $(WIN64_BINUTILS_TARBALL) + cp $(OBJ_WIN64)/install/$($@_TARNAME)/$($@_TARNAME).properties $(OBJ_WIN64)/buildlog/$(PACKAGE_HEADING)/ + rm -f $(OBJ_WIN64)/install/$($@_TARNAME)/$($@_TARNAME).properties + cp -RL $(OBJ_WIN64)/install/$($@_TARNAME)/* $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64)/ + rm -rf $(BINDIR)/$($@_TARNAME).properties + rm -rf $(BINDIR)/$($@_TARNAME).tar.gz + rm -rf $(BINDIR)/$($@_TARNAME).zip +endif + mkdir -p $(dir $@) + date > $@ + +$(OBJ_WIN64)/build/$(PACKAGE_HEADING)/build-gcc/build.stamp: \ + $(OBJ_WIN64)/build/$(PACKAGE_HEADING)/build-binutils/build.stamp +ifneq ($(WIN64_GCC_TARBALL),) + $(eval $@_TARNAME = $(basename $(basename $(notdir $(WIN64_GCC_TARBALL))))) + mkdir -p $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64) + rm -rf $(OBJ_WIN64)/install/$($@_TARNAME) + $(TAR) -xz -C $(OBJ_WIN64)/install -f $(WIN64_GCC_TARBALL) + cp $(OBJ_WIN64)/install/$($@_TARNAME)/$($@_TARNAME).properties $(OBJ_WIN64)/buildlog/$(PACKAGE_HEADING)/ + rm -f $(OBJ_WIN64)/install/$($@_TARNAME)/$($@_TARNAME).properties + cp -RL $(OBJ_WIN64)/install/$($@_TARNAME)/* $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64)/ + rm -rf $(BINDIR)/$($@_TARNAME).properties + rm -rf $(BINDIR)/$($@_TARNAME).tar.gz + rm -rf $(BINDIR)/$($@_TARNAME).zip +endif + mkdir -p $(dir $@) + date > $@ + +$(OBJ_WIN64)/build/$(PACKAGE_HEADING)/build-gdb/build.stamp: \ + $(OBJ_WIN64)/build/$(PACKAGE_HEADING)/build-gcc/build.stamp +ifneq ($(WIN64_GDB_TARBALL),) + $(eval $@_TARNAME = $(basename $(basename $(notdir $(WIN64_GDB_TARBALL))))) + mkdir -p $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64) + rm -rf $(OBJ_WIN64)/install/$($@_TARNAME) + $(TAR) -xz -C $(OBJ_WIN64)/install -f $(WIN64_GDB_TARBALL) + cp $(OBJ_WIN64)/install/$($@_TARNAME)/$($@_TARNAME).properties $(OBJ_WIN64)/buildlog/$(PACKAGE_HEADING)/ + rm -f $(OBJ_WIN64)/install/$($@_TARNAME)/$($@_TARNAME).properties + cp -RL $(OBJ_WIN64)/install/$($@_TARNAME)/* $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64)/ + rm -rf $(BINDIR)/$($@_TARNAME).properties + rm -rf $(BINDIR)/$($@_TARNAME).tar.gz + rm -rf $(BINDIR)/$($@_TARNAME).zip +endif + mkdir -p $(dir $@) + date > $@ + +$(OBJDIR)/$(NATIVE)/test/$(PACKAGE_HEADING)/test.stamp: \ + $(OBJDIR)/$(NATIVE)/test/$(PACKAGE_HEADING)/launch.stamp + mkdir -p $(dir $@) + @echo "Finished testing $(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(NATIVE).tar.gz tarball" + date > $@ diff --git a/modules/freedom-toolchain-metal/Metadata.mk b/modules/freedom-toolchain-metal/Metadata.mk new file mode 100644 index 0000000..5783d7d --- /dev/null +++ b/modules/freedom-toolchain-metal/Metadata.mk @@ -0,0 +1,14 @@ +include ../freedom-binutils-metal/Metadata.mk +include ../freedom-gcc-metal/Metadata.mk +include ../freedom-gdb-metal/Metadata.mk +include ../../scripts/base_toolchain_metadata.mk + +# Version number, which should match the official version of the tool we are building +RISCV_TOOLCHAIN_VERSION := $(RISCV_GCC_VERSION) + +# Customization ID, which should identify the customization added to the original by SiFive +FREEDOM_TOOLCHAIN_METAL_ID := $(FREEDOM_TOOLCHAIN_ID) + +# Characteristic tags, which should be usable for matching up providers and consumers +FREEDOM_TOOLCHAIN_METAL_RISCV_TAGS := $(FREEDOM_TOOLCHAIN_RISCV_TAGS) +FREEDOM_TOOLCHAIN_METAL_TOOLS_TAGS := $(FREEDOM_BINUTILS_METAL_TOOLS_TAGS) $(FREEDOM_GCC_METAL_TOOLS_TAGS) $(FREEDOM_GDB_METAL_TOOLS_TAGS) diff --git a/modules/freedom-toolchain-metal/Monorepo.mk b/modules/freedom-toolchain-metal/Monorepo.mk new file mode 100644 index 0000000..2cad9c7 --- /dev/null +++ b/modules/freedom-toolchain-metal/Monorepo.mk @@ -0,0 +1,72 @@ +.PHONY: toolchain-metal toolchain-metal-package toolchain-metal-native-package toolchain-metal-cross-package +.PHONY: toolchain-metal-regress +.PHONY: toolchain-metal-cleanup toolchain-metal-native-cleanup toolchain-metal-cross-cleanup +.PHONY: toolchain-metal-flushup toolchain-metal-native-flushup toolchain-metal-cross-flushup +toolchain-metal: toolchain-metal-package + +.PHONY: toolchain toolchain-package toolchain-native-package toolchain-cross-package toolchain-regress +toolchain-package: toolchain-metal-package +toolchain-native-package: toolchain-metal-native-package +toolchain-cross-package: toolchain-metal-cross-package +toolchain-regress: toolchain-metal-regress +toolchain: toolchain-metal + +toolchain-metal-package: + $(MAKE) -C modules/freedom-binutils-metal package BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) + $(MAKE) -C modules/freedom-gcc-metal package BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) + $(MAKE) -C modules/freedom-gdb-metal package BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) + $(MAKE) -C modules/freedom-toolchain-metal package BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) + +toolchain-metal-native-package: + $(MAKE) -C modules/freedom-binutils-metal native-package BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) + $(MAKE) -C modules/freedom-gcc-metal native-package BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) + $(MAKE) -C modules/freedom-gdb-metal native-package BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) + $(MAKE) -C modules/freedom-toolchain-metal native-package BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) + +toolchain-metal-cross-package: + $(MAKE) -C modules/freedom-binutils-metal cross-package BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) + $(MAKE) -C modules/freedom-gcc-metal cross-package BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) + $(MAKE) -C modules/freedom-gdb-metal cross-package BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) + $(MAKE) -C modules/freedom-toolchain-metal cross-package BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) + +toolchain-metal-regress: + $(MAKE) -C modules/freedom-binutils-metal regress BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) + $(MAKE) -C modules/freedom-gcc-metal regress BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) + $(MAKE) -C modules/freedom-gdb-metal regress BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) + $(MAKE) -C modules/freedom-toolchain-metal regress BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) + +toolchain-metal-cleanup: + $(MAKE) -C modules/freedom-binutils-metal cleanup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + $(MAKE) -C modules/freedom-gcc-metal cleanup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + $(MAKE) -C modules/freedom-gdb-metal cleanup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + $(MAKE) -C modules/freedom-toolchain-metal cleanup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + +toolchain-metal-native-cleanup: + $(MAKE) -C modules/freedom-binutils-metal native-cleanup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + $(MAKE) -C modules/freedom-gcc-metal native-cleanup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + $(MAKE) -C modules/freedom-gdb-metal native-cleanup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + $(MAKE) -C modules/freedom-toolchain-metal native-cleanup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + +toolchain-metal-cross-cleanup: + $(MAKE) -C modules/freedom-binutils-metal cross-cleanup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + $(MAKE) -C modules/freedom-gcc-metal cross-cleanup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + $(MAKE) -C modules/freedom-gdb-metal cross-cleanup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + $(MAKE) -C modules/freedom-toolchain-metal cross-cleanup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + +toolchain-metal-flushup: + $(MAKE) -C modules/freedom-binutils-metal flushup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + $(MAKE) -C modules/freedom-gcc-metal flushup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + $(MAKE) -C modules/freedom-gdb-metal flushup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + $(MAKE) -C modules/freedom-toolchain-metal flushup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + +toolchain-metal-native-flushup: + $(MAKE) -C modules/freedom-binutils-metal native-flushup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + $(MAKE) -C modules/freedom-gcc-metal native-flushup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + $(MAKE) -C modules/freedom-gdb-metal native-flushup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + $(MAKE) -C modules/freedom-toolchain-metal native-flushup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + +toolchain-metal-cross-flushup: + $(MAKE) -C modules/freedom-binutils-metal cross-flushup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + $(MAKE) -C modules/freedom-gcc-metal cross-flushup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + $(MAKE) -C modules/freedom-gdb-metal cross-flushup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + $(MAKE) -C modules/freedom-toolchain-metal cross-flushup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ diff --git a/modules/freedom-trace-decoder.mk b/modules/freedom-trace-decoder.mk deleted file mode 100644 index 1b16f0b..0000000 --- a/modules/freedom-trace-decoder.mk +++ /dev/null @@ -1,38 +0,0 @@ - -FREEDOM_TRACE_DECODER_GITURL := git@github.com:sifive/freedom-trace-decoder.git -FREEDOM_TRACE_DECODER_BRANCH := main -FREEDOM_TRACE_DECODER_MODULE := $(SRCDIR)/freedom-trace-decoder - -ifneq ($(TARGET_GITURL),) -FREEDOM_TRACE_DECODER_GITURL := $(TARGET_GITURL) -endif -ifneq ($(TARGET_BRANCH),) -FREEDOM_TRACE_DECODER_BRANCH := $(TARGET_BRANCH) -endif - -.PHONY: trace-decoder trace-decoder-package trace-decoder-regress trace-decoder-cleanup trace-decoder-flushup -trace-decoder: trace-decoder-package - -$(FREEDOM_TRACE_DECODER_MODULE).$(FREEDOM_TRACE_DECODER_BRANCH): - mkdir -p $(dir $@) - rm -rf $(FREEDOM_TRACE_DECODER_MODULE) - rm -rf $(FREEDOM_TRACE_DECODER_MODULE).* - git clone $(FREEDOM_TRACE_DECODER_GITURL) $(FREEDOM_TRACE_DECODER_MODULE) --single-branch -b $(FREEDOM_TRACE_DECODER_BRANCH) - cd $(FREEDOM_TRACE_DECODER_MODULE) && git submodule update --init --recursive - date > $@ - -trace-decoder-package: \ - $(FREEDOM_TRACE_DECODER_MODULE).$(FREEDOM_TRACE_DECODER_BRANCH) - $(MAKE) -C $(FREEDOM_TRACE_DECODER_MODULE) package BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) - -trace-decoder-regress: \ - $(FREEDOM_TRACE_DECODER_MODULE).$(FREEDOM_TRACE_DECODER_BRANCH) - $(MAKE) -C $(FREEDOM_TRACE_DECODER_MODULE) regress BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) - -trace-decoder-cleanup: - $(MAKE) -C $(FREEDOM_TRACE_DECODER_MODULE) cleanup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ - rm -rf $(FREEDOM_TRACE_DECODER_MODULE).* - rm -rf $(FREEDOM_TRACE_DECODER_MODULE) - -trace-decoder-flushup: - $(MAKE) -C $(FREEDOM_TRACE_DECODER_MODULE) flushup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ diff --git a/modules/freedom-trace-decoder/Makefile b/modules/freedom-trace-decoder/Makefile new file mode 100644 index 0000000..35530b7 --- /dev/null +++ b/modules/freedom-trace-decoder/Makefile @@ -0,0 +1,113 @@ +# Setup the Freedom build script environment +include ../../scripts/Freedom.mk + +# Include version identifiers to build up the full version string +include Metadata.mk +PACKAGE_WORDING := Trace Decoder +PACKAGE_HEADING := trace-decoder +PACKAGE_VERSION := $(TRACE_DECODER_VERSION)-$(FREEDOM_TRACE_DECODER_ID)$(EXTRA_SUFFIX) +PACKAGE_COMMENT := \# SiFive Freedom Package Properties File + +# Source code directory references +BARE_METAL_TUPLE := riscv64-unknown-elf +BARE_METAL_CC_FOR_TARGET ?= $(BARE_METAL_TUPLE)-gcc +BARE_METAL_CXX_FOR_TARGET ?= $(BARE_METAL_TUPLE)-g++ + +# Some special package configure flags for specific targets +$(WIN64)-binutils-host := --host=$(WIN64) +$(WIN64)-tdc-cross := x86_64-w64-mingw32- +$(WIN64)-tdc-binext := .exe +$(UBUNTU64)-binutils-host := --host=x86_64-linux-gnu +$(UBUNTU64)-binutils-configure := --enable-shared --enable-static +$(DARWIN)-binutils-configure := --with-included-gettext +$(REDHAT)-binutils-configure := --enable-shared --enable-static + +# Setup the package targets and switch into secondary makefile targets +# Targets $(PACKAGE_HEADING)/install.stamp and $(PACKAGE_HEADING)/libs.stamp +include ../../scripts/Package.mk + +$(OBJDIR)/%/build/$(PACKAGE_HEADING)/install.stamp: \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/$(TRACE_DECODER_FOLDER)/build.stamp + $(eval $@_TARGET := $(patsubst $(OBJDIR)/%/build/$(PACKAGE_HEADING)/install.stamp,%,$@)) + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/install.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET),$@)) + $(eval $@_PROPERTIES := $(patsubst %/build/$(PACKAGE_HEADING)/install.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET).properties,$@)) + mkdir -p $(dir $@) + git log --format="[%ad] %s" > $(abspath $($@_INSTALL))/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET).changelog + rm -f $(abspath $($@_PROPERTIES)) + echo "$(PACKAGE_COMMENT)" > $(abspath $($@_PROPERTIES)) + echo "PACKAGE_TYPE = freedom-tools" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_DESC_SEG = $(PACKAGE_WORDING)" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_FIXED_ID = $(PACKAGE_HEADING)" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_BUILD_ID = $(FREEDOM_TRACE_DECODER_ID)$(EXTRA_SUFFIX)" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_CORE_VER = $(TRACE_DECODER_VERSION)" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_TARGET = $($@_TARGET)" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_VENDOR = SiFive" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_RIGHTS = sifive-v00 eclipse-v20" >> $(abspath $($@_PROPERTIES)) + echo "RISCV_TAGS = $(FREEDOM_TRACE_DECODER_RISCV_TAGS)" >> $(abspath $($@_PROPERTIES)) + echo "TOOLS_TAGS = $(FREEDOM_TRACE_DECODER_TOOLS_TAGS)" >> $(abspath $($@_PROPERTIES)) + cp $(abspath $($@_PROPERTIES)) $(abspath $($@_INSTALL))/ + tclsh ../../scripts/check-maximum-path-length.tcl $(abspath $($@_INSTALL)) "$(PACKAGE_HEADING)" "$(TRACE_DECODER_VERSION)" "$(FREEDOM_TRACE_DECODER_ID)$(EXTRA_SUFFIX)" + tclsh ../../scripts/check-same-name-different-case.tcl $(abspath $($@_INSTALL)) + date > $@ + +# We might need some extra target libraries for this package +$(OBJ_NATIVE)/build/$(PACKAGE_HEADING)/libs.stamp: \ + $(OBJ_NATIVE)/build/$(PACKAGE_HEADING)/install.stamp + date > $@ + +$(OBJ_WIN64)/build/$(PACKAGE_HEADING)/libs.stamp: \ + $(OBJ_WIN64)/build/$(PACKAGE_HEADING)/install.stamp + -$(WIN64)-gcc -print-search-dirs | grep ^programs | cut -d= -f2- | tr : "\n" | xargs -I {} find {} -iname "libwinpthread*.dll" | xargs cp -t $(OBJDIR)/$(WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64)/bin + -$(WIN64)-gcc -print-search-dirs | grep ^libraries | cut -d= -f2- | tr : "\n" | xargs -I {} find {} -iname "libgcc_s_seh*.dll" | xargs cp -t $(OBJDIR)/$(WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64)/bin + -$(WIN64)-gcc -print-search-dirs | grep ^libraries | cut -d= -f2- | tr : "\n" | xargs -I {} find {} -iname "libstdc*.dll" | xargs cp -t $(OBJDIR)/$(WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64)/bin + -$(WIN64)-gcc -print-search-dirs | grep ^libraries | cut -d= -f2- | tr : "\n" | xargs -I {} find {} -iname "libssp*.dll" | xargs cp -t $(OBJDIR)/$(WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64)/bin + date > $@ + +$(OBJDIR)/%/build/$(PACKAGE_HEADING)/source.stamp: + $(eval $@_TARGET := $(patsubst $(OBJDIR)/%/build/$(PACKAGE_HEADING)/source.stamp,%,$@)) + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/source.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET),$@)) + $(eval $@_BUILDLOG := $(abspath $(patsubst %/build/$(PACKAGE_HEADING)/source.stamp,%/buildlog/$(PACKAGE_HEADING),$@))) + $(eval $@_SRCBALL := $(abspath $(BINDIR)/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET).src.tar.gz)) + tclsh ../../scripts/check-naming-and-version-syntax.tcl "$(PACKAGE_WORDING)" "$(PACKAGE_HEADING)" "$(TRACE_DECODER_VERSION)" "$(FREEDOM_TRACE_DECODER_ID)$(EXTRA_SUFFIX)" + rm -rf $($@_INSTALL) + mkdir -p $($@_INSTALL) + rm -rf $($@_BUILDLOG) + mkdir -p $($@_BUILDLOG) + rm -rf $(dir $@) + mkdir -p $(dir $@) + git log > $($@_BUILDLOG)/$(PACKAGE_HEADING)-git-commit.log + git remote -v > $($@_BUILDLOG)/$(PACKAGE_HEADING)-git-remote.log + git clone --single-branch --branch $(RISCV_BINUTILS_BRANCH) $(RISCV_BINUTILS_GITURL) $(dir $@)/$(RISCV_BINUTILS_FOLDER) + cd $(dir $@)/$(RISCV_BINUTILS_FOLDER) && git checkout --detach $(RISCV_BINUTILS_COMMIT) + cd $(dir $@)/$(RISCV_BINUTILS_FOLDER) && git submodule update --init --recursive + git clone --single-branch --branch $(TRACE_DECODER_BRANCH) $(TRACE_DECODER_GITURL) $(dir $@)/$(TRACE_DECODER_FOLDER) + cd $(dir $@)/$(TRACE_DECODER_FOLDER) && git checkout --detach $(TRACE_DECODER_COMMIT) + cd $(dir $@)/$(TRACE_DECODER_FOLDER) && git submodule update --init --recursive + mkdir -p $(dir $($@_SRCBALL)) + cd $(dir $@); $(TAR) --dereference --hard-dereference -c $(RISCV_BINUTILS_FOLDER) $(TRACE_DECODER_FOLDER) | gzip > $($@_SRCBALL) + date > $@ + +# Reusing binutils build script across binutils-metal, gcc-metal and trace-decoder +include ../freedom-binutils-metal/scripts/build_binutils_target.mk + +$(OBJDIR)/%/build/$(PACKAGE_HEADING)/build-binutils/build.stamp: \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/build-binutils/support.stamp + date > $@ + +$(OBJDIR)/%/build/$(PACKAGE_HEADING)/$(TRACE_DECODER_FOLDER)/build.stamp: \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/build-binutils/build.stamp + $(eval $@_TARGET := $(patsubst $(OBJDIR)/%/build/$(PACKAGE_HEADING)/$(TRACE_DECODER_FOLDER)/build.stamp,%,$@)) + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/$(TRACE_DECODER_FOLDER)/build.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET),$@)) + $(eval $@_BINUTILS := $(patsubst %/build/$(PACKAGE_HEADING)/$(TRACE_DECODER_FOLDER)/build.stamp,%/build/$(PACKAGE_HEADING)/build-binutils,$@)) + $(eval $@_BUILDLOG := $(abspath $(patsubst %/build/$(PACKAGE_HEADING)/$(TRACE_DECODER_FOLDER)/build.stamp,%/buildlog/$(PACKAGE_HEADING),$@))) + $(MAKE) -C $(dir $@) BINUTILSPATH=$(abspath $($@_BINUTILS)) CROSSPREFIX=$($($@_TARGET)-tdc-cross) all &>$($@_BUILDLOG)/$(TRACE_DECODER_FOLDER)-make-build.log + $(MAKE) -j1 -C $(dir $@) INSTALLPATH=$(abspath $($@_INSTALL)) CROSSPREFIX=$($($@_TARGET)-tdc-cross) install &>$($@_BUILDLOG)/$(TRACE_DECODER_FOLDER)-make-install.log + tclsh ../../scripts/dyn-lib-check-$($@_TARGET).tcl $(abspath $($@_INSTALL))/bin/dqr + date > $@ + +$(OBJDIR)/$(NATIVE)/test/$(PACKAGE_HEADING)/test.stamp: \ + $(OBJDIR)/$(NATIVE)/test/$(PACKAGE_HEADING)/launch.stamp + mkdir -p $(dir $@) + PATH=$(abspath $(OBJDIR)/$(NATIVE)/launch/$(PACKAGE_TARNAME)/bin):$(PATH) dqr -v + @echo "Finished testing $(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(NATIVE).tar.gz tarball" + date > $@ diff --git a/modules/freedom-trace-decoder/Metadata.mk b/modules/freedom-trace-decoder/Metadata.mk new file mode 100644 index 0000000..17dc3fa --- /dev/null +++ b/modules/freedom-trace-decoder/Metadata.mk @@ -0,0 +1,17 @@ +include ../freedom-binutils-metal/Metadata.mk + +# Git repos, branches, commits and folders to get source code for the tool we are building +TRACE_DECODER_GITURL := git@github.com:sifive/trace-decoder.git +TRACE_DECODER_BRANCH := master +TRACE_DECODER_COMMIT := 7f39506b39e49320b6dd51a53abc08aedabfaf8b +TRACE_DECODER_FOLDER := trace-decoder + +# Version number, which should match the official version of the tool we are building +TRACE_DECODER_VERSION := 0.10.5 + +# Customization ID, which should identify the customization added to the original by SiFive +FREEDOM_TRACE_DECODER_ID := 2020.12.0-preview1 + +# Characteristic tags, which should be usable for matching up providers and consumers +FREEDOM_TRACE_DECODER_RISCV_TAGS = rv32i rv64i m a f d c v zfh zba zbb +FREEDOM_TRACE_DECODER_TOOLS_TAGS = trace-decoder diff --git a/modules/freedom-trace-decoder/Monorepo.mk b/modules/freedom-trace-decoder/Monorepo.mk new file mode 100644 index 0000000..52d7c18 --- /dev/null +++ b/modules/freedom-trace-decoder/Monorepo.mk @@ -0,0 +1,35 @@ +.PHONY: trace-decoder trace-decoder-package trace-decoder-native-package trace-decoder-cross-package +.PHONY: trace-decoder-regress +.PHONY: trace-decoder-cleanup trace-decoder-native-cleanup trace-decoder-cross-cleanup +.PHONY: trace-decoder-flushup trace-decoder-native-flushup trace-decoder-cross-flushup +trace-decoder: trace-decoder-package + +trace-decoder-package: + $(MAKE) -C modules/freedom-trace-decoder package BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) + +trace-decoder-native-package: + $(MAKE) -C modules/freedom-trace-decoder native-package BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) + +trace-decoder-cross-package: + $(MAKE) -C modules/freedom-trace-decoder cross-package BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) + +trace-decoder-regress: + $(MAKE) -C modules/freedom-trace-decoder regress BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) + +trace-decoder-cleanup: + $(MAKE) -C modules/freedom-trace-decoder cleanup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + +trace-decoder-native-cleanup: + $(MAKE) -C modules/freedom-trace-decoder native-cleanup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + +trace-decoder-cross-cleanup: + $(MAKE) -C modules/freedom-trace-decoder cross-cleanup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + +trace-decoder-flushup: + $(MAKE) -C modules/freedom-trace-decoder flushup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + +trace-decoder-native-flushup: + $(MAKE) -C modules/freedom-trace-decoder native-flushup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + +trace-decoder-cross-flushup: + $(MAKE) -C modules/freedom-trace-decoder cross-flushup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ diff --git a/modules/freedom-xc3sprog.mk b/modules/freedom-xc3sprog.mk deleted file mode 100644 index 55bea84..0000000 --- a/modules/freedom-xc3sprog.mk +++ /dev/null @@ -1,38 +0,0 @@ - -FREEDOM_XC3SPROG_GITURL := git@github.com:sifive/freedom-xc3sprog.git -FREEDOM_XC3SPROG_BRANCH := main -FREEDOM_XC3SPROG_MODULE := $(SRCDIR)/freedom-xc3sprog - -ifneq ($(TARGET_GITURL),) -FREEDOM_XC3SPROG_GITURL := $(TARGET_GITURL) -endif -ifneq ($(TARGET_BRANCH),) -FREEDOM_XC3SPROG_BRANCH := $(TARGET_BRANCH) -endif - -.PHONY: xc3sprog xc3sprog-package xc3sprog-regress xc3sprog-cleanup xc3sprog-flushup -xc3sprog: xc3sprog-package - -$(FREEDOM_XC3SPROG_MODULE).$(FREEDOM_XC3SPROG_BRANCH): - mkdir -p $(dir $@) - rm -rf $(FREEDOM_XC3SPROG_MODULE) - rm -rf $(FREEDOM_XC3SPROG_MODULE).* - git clone $(FREEDOM_XC3SPROG_GITURL) $(FREEDOM_XC3SPROG_MODULE) --single-branch -b $(FREEDOM_XC3SPROG_BRANCH) - cd $(FREEDOM_XC3SPROG_MODULE) && git submodule update --init --recursive - date > $@ - -xc3sprog-package: \ - $(FREEDOM_XC3SPROG_MODULE).$(FREEDOM_XC3SPROG_BRANCH) - $(MAKE) -C $(FREEDOM_XC3SPROG_MODULE) package BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) - -xc3sprog-regress: \ - $(FREEDOM_XC3SPROG_MODULE).$(FREEDOM_XC3SPROG_BRANCH) - $(MAKE) -C $(FREEDOM_XC3SPROG_MODULE) regress BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) - -xc3sprog-cleanup: - $(MAKE) -C $(FREEDOM_XC3SPROG_MODULE) cleanup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ - rm -rf $(FREEDOM_XC3SPROG_MODULE).* - rm -rf $(FREEDOM_XC3SPROG_MODULE) - -xc3sprog-flushup: - $(MAKE) -C $(FREEDOM_XC3SPROG_MODULE) flushup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ diff --git a/modules/freedom-xc3sprog/Makefile b/modules/freedom-xc3sprog/Makefile new file mode 100644 index 0000000..3e8a19d --- /dev/null +++ b/modules/freedom-xc3sprog/Makefile @@ -0,0 +1,191 @@ +# Setup the Freedom build script environment +include ../../scripts/Freedom.mk + +# Include version identifiers to build up the full version string +include Metadata.mk +PACKAGE_WORDING := XC3SPROG +PACKAGE_HEADING := xc3sprog +PACKAGE_VERSION := $(XC3SPROG_VERSION)-$(FREEDOM_XC3SPROG_ID)$(EXTRA_SUFFIX) +PACKAGE_COMMENT := \# SiFive Freedom Package Properties File + +# Some special package configure flags for specific targets +$(WIN64)-xc3sp-host := --host=$(WIN64) +$(WIN64)-xftdi-configure := -DCMAKE_TOOLCHAIN_FILE="$(abspath $(OBJ_WIN64)/build/$(PACKAGE_HEADING)/libftdi/cmake/Toolchain-x86_64-w64-mingw32.cmake)" -DLIBUSB_LIBRARIES="$(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64)/bin/libusb-1.0.dll)" -DLIBUSB_INCLUDE_DIR="$(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64)/include/libusb-1.0)" +$(WIN64)-xdeps-vars := PKG_CONFIG_PATH="$(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64))/lib/pkgconfig" CFLAGS="-L$(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64))/lib -I$(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64))/include" CPPFLAGS="-L$(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64))/lib -I$(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64))/include" +$(WIN64)-xc3sp-configure := -DCMAKE_TOOLCHAIN_FILE="$(abspath $(OBJ_WIN64)/build/$(PACKAGE_HEADING)/xc3sprog/Toolchain-mingw32.cmake)" -DLIBUSB_LIBRARIES="$(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64)/bin/libusb-1.0.dll)" -DLIBUSB_INCLUDE_DIR="$(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64)/include/libusb-1.0)" +$(WIN64)-xc3sp-vars := PKG_CONFIG_PATH="$(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64))/lib/pkgconfig" CFLAGS="-L$(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64))/lib -I$(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64))/include" CPPFLAGS="-L$(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64))/lib -I$(abspath $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64))/include" +$(UBUNTU64)-xc3sp-host := --host=x86_64-linux-gnu +$(UBUNTU64)-xdeps-vars := PKG_CONFIG_PATH="$(abspath $(OBJ_UBUNTU64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(UBUNTU64))/lib/pkgconfig" CFLAGS="-I$(abspath $(OBJ_UBUNTU64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(UBUNTU64))/include" LDFLAGS="-L$(abspath $(OBJ_UBUNTU64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(UBUNTU64))/lib" +$(UBUNTU64)-xc3sp-vars := PKG_CONFIG_PATH="$(abspath $(OBJ_UBUNTU64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(UBUNTU64))/lib/pkgconfig" CFLAGS="-I$(abspath $(OBJ_UBUNTU64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(UBUNTU64))/include" CPPFLAGS="-I$(abspath $(OBJ_UBUNTU64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(UBUNTU64))/include" LIBUSB_INCLUDE_DIRS="$(abspath $(OBJ_UBUNTU64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(UBUNTU64))/include" LDFLAGS="-L$(abspath $(OBJ_UBUNTU64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(UBUNTU64))/lib" +$(DARWIN)-xdeps-vars := PKG_CONFIG_PATH="$(abspath $(OBJ_DARWIN)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(DARWIN))/lib/pkgconfig" CFLAGS="-I$(abspath $(OBJ_DARWIN)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(DARWIN))/include" CPPFLAGS="-I$(abspath $(OBJ_DARWIN)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(DARWIN))/include" LDFLAGS="-L$(abspath $(OBJ_DARWIN)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(DARWIN))/lib -framework CoreFoundation -framework IOKit" +$(DARWIN)-xc3sp-vars := PKG_CONFIG_PATH="$(abspath $(OBJ_DARWIN)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(DARWIN))/lib/pkgconfig" CFLAGS="-I$(abspath $(OBJ_DARWIN)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(DARWIN))/include" CPPFLAGS="-I$(abspath $(OBJ_DARWIN)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(DARWIN))/include" LDFLAGS="-L$(abspath $(OBJ_DARWIN)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(DARWIN))/lib -liconv -framework CoreFoundation -framework IOKit" +$(DARWIN)-xc3sp-framework := -framework CoreFoundation -framework IOKit +$(REDHAT)-xdeps-vars := PKG_CONFIG_PATH="$(abspath $(OBJ_REDHAT)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT))/lib/pkgconfig:$(abspath $(OBJ_REDHAT)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT))/lib64/pkgconfig" CFLAGS="-I$(abspath $(OBJ_REDHAT)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT))/include" LDFLAGS="-L$(abspath $(OBJ_REDHAT)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT))/lib -L$(abspath $(OBJ_REDHAT)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT))/lib64 -lrt" +$(REDHAT)-xc3sp-vars := PKG_CONFIG_PATH="$(abspath $(OBJ_REDHAT)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT))/lib/pkgconfig:$(abspath $(OBJ_REDHAT)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT))/lib64/pkgconfig" CFLAGS="-I$(abspath $(OBJ_REDHAT)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT))/include" CPPFLAGS="-I$(abspath $(OBJ_REDHAT)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT))/include" LIBUSB_INCLUDE_DIRS="$(abspath $(OBJ_REDHAT)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT))/include" LDFLAGS="-L$(abspath $(OBJ_REDHAT)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT))/lib -L$(abspath $(OBJ_REDHAT)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT))/lib64 -lrt" +$(REDHAT)-xc3sp-configure := -DLIBRT_LIBRARIES="rt" + +# Setup the package targets and switch into secondary makefile targets +# Targets $(PACKAGE_HEADING)/install.stamp and $(PACKAGE_HEADING)/libs.stamp +include ../../scripts/Package.mk + +$(OBJDIR)/%/build/$(PACKAGE_HEADING)/install.stamp: \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/$(XC3SPROG_FOLDER)/build.stamp + $(eval $@_TARGET := $(patsubst $(OBJDIR)/%/build/$(PACKAGE_HEADING)/install.stamp,%,$@)) + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/install.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET),$@)) + $(eval $@_PROPERTIES := $(patsubst %/build/$(PACKAGE_HEADING)/install.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET).properties,$@)) + mkdir -p $(dir $@) + git log --format="[%ad] %s" > $(abspath $($@_INSTALL))/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET).changelog + rm -f $(abspath $($@_PROPERTIES)) + echo "$(PACKAGE_COMMENT)" > $(abspath $($@_PROPERTIES)) + echo "PACKAGE_TYPE = freedom-tools" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_DESC_SEG = $(PACKAGE_WORDING)" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_FIXED_ID = $(PACKAGE_HEADING)" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_BUILD_ID = $(FREEDOM_XC3SPROG_ID)$(EXTRA_SUFFIX)" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_CORE_VER = $(XC3SPROG_VERSION)" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_TARGET = $($@_TARGET)" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_VENDOR = SiFive" >> $(abspath $($@_PROPERTIES)) + echo "PACKAGE_RIGHTS = sifive-v00 eclipse-v20" >> $(abspath $($@_PROPERTIES)) + echo "RISCV_TAGS = $(FREEDOM_XC3SPROG_RISCV_TAGS)" >> $(abspath $($@_PROPERTIES)) + echo "TOOLS_TAGS = $(FREEDOM_XC3SPROG_TOOLS_TAGS)" >> $(abspath $($@_PROPERTIES)) + cp $(abspath $($@_PROPERTIES)) $(abspath $($@_INSTALL))/ + tclsh ../../scripts/check-maximum-path-length.tcl $(abspath $($@_INSTALL)) "$(PACKAGE_HEADING)" "$(XC3SPROG_VERSION)" "$(FREEDOM_XC3SPROG_ID)$(EXTRA_SUFFIX)" + tclsh ../../scripts/check-same-name-different-case.tcl $(abspath $($@_INSTALL)) + date > $@ + +# We might need some extra target libraries for this package +$(OBJ_NATIVE)/build/$(PACKAGE_HEADING)/libs.stamp: \ + $(OBJ_NATIVE)/build/$(PACKAGE_HEADING)/install.stamp + date > $@ + +$(OBJ_WIN64)/build/$(PACKAGE_HEADING)/libs.stamp: \ + $(OBJ_WIN64)/build/$(PACKAGE_HEADING)/install.stamp + -$(WIN64)-gcc -print-search-dirs | grep ^programs | cut -d= -f2- | tr : "\n" | xargs -I {} find {} -iname "libwinpthread*.dll" | xargs cp -t $(OBJDIR)/$(WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64)/bin + -$(WIN64)-gcc -print-search-dirs | grep ^libraries | cut -d= -f2- | tr : "\n" | xargs -I {} find {} -iname "libgcc_s_seh*.dll" | xargs cp -t $(OBJDIR)/$(WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64)/bin + -$(WIN64)-gcc -print-search-dirs | grep ^libraries | cut -d= -f2- | tr : "\n" | xargs -I {} find {} -iname "libstdc*.dll" | xargs cp -t $(OBJDIR)/$(WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64)/bin + -$(WIN64)-gcc -print-search-dirs | grep ^libraries | cut -d= -f2- | tr : "\n" | xargs -I {} find {} -iname "libssp*.dll" | xargs cp -t $(OBJDIR)/$(WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64)/bin + date > $@ + +$(OBJDIR)/%/build/$(PACKAGE_HEADING)/source.stamp: + $(eval $@_TARGET := $(patsubst $(OBJDIR)/%/build/$(PACKAGE_HEADING)/source.stamp,%,$@)) + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/source.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET),$@)) + $(eval $@_BUILDLOG := $(abspath $(patsubst %/build/$(PACKAGE_HEADING)/source.stamp,%/buildlog/$(PACKAGE_HEADING),$@))) + $(eval $@_SRCBALL := $(abspath $(BINDIR)/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET).src.tar.gz)) + tclsh ../../scripts/check-naming-and-version-syntax.tcl "$(PACKAGE_WORDING)" "$(PACKAGE_HEADING)" "$(XC3SPROG_VERSION)" "$(FREEDOM_XC3SPROG_ID)$(EXTRA_SUFFIX)" + rm -rf $($@_INSTALL) + mkdir -p $($@_INSTALL) + rm -rf $($@_BUILDLOG) + mkdir -p $($@_BUILDLOG) + rm -rf $(dir $@) + mkdir -p $(dir $@) + git log > $($@_BUILDLOG)/$(PACKAGE_HEADING)-git-commit.log + git remote -v > $($@_BUILDLOG)/$(PACKAGE_HEADING)-git-remote.log + cd $(dir $@); curl -L -f -s -o libusb-1.0.22.tar.bz2 https://github.com/libusb/libusb/releases/download/v1.0.22/libusb-1.0.22.tar.bz2 + cd $(dir $@); $(TAR) -xf libusb-1.0.22.tar.bz2 + cd $(dir $@); mv libusb-1.0.22 libusb + cd $(dir $@); curl -L -f -s -o libusb-compat-0.1.7.tar.bz2 https://github.com/libusb/libusb-compat-0.1/releases/download/v0.1.7/libusb-compat-0.1.7.tar.bz2 + cd $(dir $@); $(TAR) -xf libusb-compat-0.1.7.tar.bz2 + cd $(dir $@); mv libusb-compat-0.1.7 libusb-compat + cd $(dir $@); curl -L -f -s -o libftdi1-1.4.tar.bz2 https://www.intra2net.com/en/developer/libftdi/download/libftdi1-1.4.tar.bz2 + cd $(dir $@); $(TAR) -xf libftdi1-1.4.tar.bz2 + cd $(dir $@); mv libftdi1-1.4 libftdi + cd $(dir $@); curl -L -f -s -o libiconv-1.15.tar.gz https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.15.tar.gz + cd $(dir $@); $(TAR) -xf libiconv-1.15.tar.gz + cd $(dir $@); mv libiconv-1.15 libiconv + git clone --single-branch --branch $(XC3SPROG_BRANCH) $(XC3SPROG_GITURL) $(dir $@)/$(XC3SPROG_FOLDER) + cd $(dir $@)/$(XC3SPROG_FOLDER) && git checkout --detach $(XC3SPROG_COMMIT) + cd $(dir $@)/$(XC3SPROG_FOLDER) && git submodule update --init --recursive + $(SED) -i -f patches/xc3sprog.sed -e "s/SIFIVE_PACKAGE_VERSION/SiFive XC3SPROG $(PACKAGE_VERSION)/" $(dir $@)/$(XC3SPROG_FOLDER)/xc3sprog.cpp + $(SED) -i -f patches/xc3sprog-cmake.sed $(dir $@)/$(XC3SPROG_FOLDER)/CMakeLists.txt + $(SED) -i -f patches/xc3sprog-cmake.sed $(dir $@)/$(XC3SPROG_FOLDER)/javr/CMakeLists.txt + $(SED) -i -f patches/xc3sprog-mingw32.sed $(dir $@)/$(XC3SPROG_FOLDER)/Toolchain-mingw32.cmake + mkdir -p $(dir $($@_SRCBALL)) + cd $(dir $@); $(TAR) --dereference --hard-dereference -c libusb libusb-compat libftdi libiconv $(XC3SPROG_FOLDER) | gzip > $($@_SRCBALL) + date > $@ + +$(OBJDIR)/%/build/$(PACKAGE_HEADING)/libusb/build.stamp: \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/source.stamp + $(eval $@_TARGET := $(patsubst $(OBJDIR)/%/build/$(PACKAGE_HEADING)/libusb/build.stamp,%,$@)) + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/libusb/build.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET),$@)) + $(eval $@_BUILDLOG := $(abspath $(patsubst %/build/$(PACKAGE_HEADING)/libusb/build.stamp,%/buildlog/$(PACKAGE_HEADING),$@))) + cd $(dir $@) && ./configure \ + $($($@_TARGET)-xc3sp-host) \ + --prefix=$(abspath $($@_INSTALL)) \ + --disable-udev \ + --enable-static &>$($@_BUILDLOG)/libusb-make-configure.log + $(MAKE) -C $(dir $@) &>$($@_BUILDLOG)/libusb-make-build.log + $(MAKE) -C $(dir $@) -j1 install &>$($@_BUILDLOG)/libusb-make-install.log + date > $@ + +$(OBJDIR)/%/build/$(PACKAGE_HEADING)/libusb-compat/build.stamp: \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/libusb/build.stamp \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/source.stamp + $(eval $@_TARGET := $(patsubst $(OBJDIR)/%/build/$(PACKAGE_HEADING)/libusb-compat/build.stamp,%,$@)) + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/libusb-compat/build.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET),$@)) + $(eval $@_BUILDLOG := $(abspath $(patsubst %/build/$(PACKAGE_HEADING)/libusb-compat/build.stamp,%/buildlog/$(PACKAGE_HEADING),$@))) + cd $(dir $@) && $($($@_TARGET)-xdeps-vars) ./configure \ + $($($@_TARGET)-xc3sp-host) \ + --prefix=$(abspath $($@_INSTALL)) \ + --enable-static &>$($@_BUILDLOG)/libusb-compat-make-configure.log + $(MAKE) -C $(dir $@) &>$($@_BUILDLOG)/libusb-compat-make-build.log + $(MAKE) -C $(dir $@) -j1 install &>$($@_BUILDLOG)/libusb-compat-make-install.log + date > $@ + +$(OBJDIR)/%/build/$(PACKAGE_HEADING)/libftdi/build.stamp: \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/libusb-compat/build.stamp \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/source.stamp + $(eval $@_TARGET := $(patsubst $(OBJDIR)/%/build/$(PACKAGE_HEADING)/libftdi/build.stamp,%,$@)) + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/libftdi/build.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET),$@)) + $(eval $@_BUILDLOG := $(abspath $(patsubst %/build/$(PACKAGE_HEADING)/libftdi/build.stamp,%/buildlog/$(PACKAGE_HEADING),$@))) + cd $(dir $@) && $($($@_TARGET)-xdeps-vars) cmake \ + -DCMAKE_INSTALL_PREFIX:PATH=$(abspath $($@_INSTALL)) \ + $($($@_TARGET)-xftdi-configure) . &>$($@_BUILDLOG)/libftdi-make-cmake.log + $(MAKE) -C $(dir $@) &>$($@_BUILDLOG)/libftdi-make-build.log + $(MAKE) -C $(dir $@) -j1 install &>$($@_BUILDLOG)/libftdi-make-install.log + date > $@ + +$(OBJDIR)/%/build/$(PACKAGE_HEADING)/libiconv/build.stamp: \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/source.stamp + $(eval $@_TARGET := $(patsubst $(OBJDIR)/%/build/$(PACKAGE_HEADING)/libiconv/build.stamp,%,$@)) + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/libiconv/build.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET),$@)) + $(eval $@_BUILDLOG := $(abspath $(patsubst %/build/$(PACKAGE_HEADING)/libiconv/build.stamp,%/buildlog/$(PACKAGE_HEADING),$@))) + cd $(dir $@) && ./configure \ + $($($@_TARGET)-xc3sp-host) \ + --prefix=$(abspath $($@_INSTALL)) \ + --enable-static &>$($@_BUILDLOG)/libiconv-make-configure.log + $(MAKE) -C $(dir $@) &>$($@_BUILDLOG)/libiconv-make-build.log + $(MAKE) -C $(dir $@) -j1 install &>$($@_BUILDLOG)/libiconv-make-install.log + date > $@ + +$(OBJDIR)/%/build/$(PACKAGE_HEADING)/$(XC3SPROG_FOLDER)/build.stamp: \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/libftdi/build.stamp \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/libiconv/build.stamp \ + $(OBJDIR)/%/build/$(PACKAGE_HEADING)/source.stamp + $(eval $@_TARGET := $(patsubst $(OBJDIR)/%/build/$(PACKAGE_HEADING)/$(XC3SPROG_FOLDER)/build.stamp,%,$@)) + $(eval $@_INSTALL := $(patsubst %/build/$(PACKAGE_HEADING)/$(XC3SPROG_FOLDER)/build.stamp,%/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$($@_TARGET),$@)) + $(eval $@_BUILDLOG := $(abspath $(patsubst %/build/$(PACKAGE_HEADING)/$(XC3SPROG_FOLDER)/build.stamp,%/buildlog/$(PACKAGE_HEADING),$@))) + rm -f $(abspath $($@_INSTALL))/lib/lib*.dylib* + rm -f $(abspath $($@_INSTALL))/lib/lib*.so* + rm -f $(abspath $($@_INSTALL))/lib64/lib*.so* + cd $(dir $@) && $($($@_TARGET)-xc3sp-vars) cmake \ + -DCMAKE_INSTALL_PREFIX:PATH=$(abspath $($@_INSTALL)) \ + -DCMAKE_EXE_LINKER_FLAGS="-L$(abspath $($@_INSTALL))/lib -L$(abspath $($@_INSTALL))/lib64 -pthread $($($@_TARGET)-xc3sp-framework)" \ + -DLIBUSB_INCLUDE_DIRS=$(abspath $($@_INSTALL))/include \ + -DLIBFTDI_LIBRARIES=ftdi1 \ + $($($@_TARGET)-xc3sp-configure) \ + . &>$($@_BUILDLOG)/$(XC3SPROG_FOLDER)-make-cmake.log + $(MAKE) -C $(dir $@) &>$($@_BUILDLOG)/$(XC3SPROG_FOLDER)-make-build.log + $(MAKE) -C $(dir $@) -j1 install &>$($@_BUILDLOG)/$(XC3SPROG_FOLDER)-make-install.log + rm -f $(abspath $($@_INSTALL))/bin/iconv + rm -f $(abspath $($@_INSTALL))/bin/iconv.exe + rm -rf $(abspath $($@_INSTALL))/share + cp -R $(dir $@)/share $(abspath $($@_INSTALL)) + tclsh ../../scripts/dyn-lib-check-$($@_TARGET).tcl $(abspath $($@_INSTALL))/bin/xc3sprog + date > $@ + +$(OBJDIR)/$(NATIVE)/test/$(PACKAGE_HEADING)/test.stamp: \ + $(OBJDIR)/$(NATIVE)/test/$(PACKAGE_HEADING)/launch.stamp + mkdir -p $(dir $@) +# PATH=$(abspath $(OBJDIR)/$(NATIVE)/launch/$(PACKAGE_TARNAME)/bin):$(PATH) xc3sprog -h + @echo "xc3sprog executable cannot be run with a -v option without failing!" + @echo "Finished testing $(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(NATIVE).tar.gz tarball" + date > $@ diff --git a/modules/freedom-xc3sprog/Metadata.mk b/modules/freedom-xc3sprog/Metadata.mk new file mode 100644 index 0000000..b7b552b --- /dev/null +++ b/modules/freedom-xc3sprog/Metadata.mk @@ -0,0 +1,15 @@ +# Git repos, branches, commits and folders to get source code for the tool we are building +XC3SPROG_GITURL := git@github.com:sifive/xc3sprog.git +XC3SPROG_BRANCH := master +XC3SPROG_COMMIT := 893bd2463fecb5953f2603c8800ffd823861ce37 +XC3SPROG_FOLDER := xc3sprog + +# Version number, which should match the official version of the tool we are building +XC3SPROG_VERSION := 0.1.2 + +# Customization ID, which should identify the customization added to the original by SiFive +FREEDOM_XC3SPROG_ID := 2020.12.1 + +# Characteristic tags, which should be usable for matching up providers and consumers +FREEDOM_XC3SPROG_RISCV_TAGS = +FREEDOM_XC3SPROG_TOOLS_TAGS = xc3sprog diff --git a/modules/freedom-xc3sprog/Monorepo.mk b/modules/freedom-xc3sprog/Monorepo.mk new file mode 100644 index 0000000..447e3eb --- /dev/null +++ b/modules/freedom-xc3sprog/Monorepo.mk @@ -0,0 +1,35 @@ +.PHONY: xc3sprog xc3sprog-package xc3sprog-native-package xc3sprog-cross-package +.PHONY: xc3sprog-regress +.PHONY: xc3sprog-cleanup xc3sprog-native-cleanup xc3sprog-cross-cleanup +.PHONY: xc3sprog-flushup xc3sprog-native-flushup xc3sprog-cross-flushup +xc3sprog: xc3sprog-package + +xc3sprog-package: + $(MAKE) -C modules/freedom-xc3sprog package BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) + +xc3sprog-native-package: + $(MAKE) -C modules/freedom-xc3sprog native-package BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) + +xc3sprog-cross-package: + $(MAKE) -C modules/freedom-xc3sprog cross-package BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) + +xc3sprog-regress: + $(MAKE) -C modules/freedom-xc3sprog regress BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) + +xc3sprog-cleanup: + $(MAKE) -C modules/freedom-xc3sprog cleanup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + +xc3sprog-native-cleanup: + $(MAKE) -C modules/freedom-xc3sprog native-cleanup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + +xc3sprog-cross-cleanup: + $(MAKE) -C modules/freedom-xc3sprog cross-cleanup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + +xc3sprog-flushup: + $(MAKE) -C modules/freedom-xc3sprog flushup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + +xc3sprog-native-flushup: + $(MAKE) -C modules/freedom-xc3sprog native-flushup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ + +xc3sprog-cross-flushup: + $(MAKE) -C modules/freedom-xc3sprog cross-flushup BINDIR_PREFIX=$(abspath $(BINDIR_PREFIX))/ OBJDIR_PREFIX=$(abspath $(OBJDIR_PREFIX))/ diff --git a/modules/freedom-xc3sprog/patches/xc3sprog-cmake.sed b/modules/freedom-xc3sprog/patches/xc3sprog-cmake.sed new file mode 100644 index 0000000..352c984 --- /dev/null +++ b/modules/freedom-xc3sprog/patches/xc3sprog-cmake.sed @@ -0,0 +1 @@ +/target_link_libraries/s/${CONDITIONAL_LIBS}/${CONDITIONAL_LIBS} ${CMAKE_DL_LIBS} ${LIBRT_LIBRARIES}/g diff --git a/modules/freedom-xc3sprog/patches/xc3sprog-mingw32.sed b/modules/freedom-xc3sprog/patches/xc3sprog-mingw32.sed new file mode 100644 index 0000000..c5dc8b8 --- /dev/null +++ b/modules/freedom-xc3sprog/patches/xc3sprog-mingw32.sed @@ -0,0 +1 @@ +s/i686-w64-mingw32/x86_64-w64-mingw32/ diff --git a/modules/freedom-xc3sprog/patches/xc3sprog.sed b/modules/freedom-xc3sprog/patches/xc3sprog.sed new file mode 100644 index 0000000..b51dfc3 --- /dev/null +++ b/modules/freedom-xc3sprog/patches/xc3sprog.sed @@ -0,0 +1,2 @@ +s/xc3sprog project \$Rev\$ OS/xc3sprog project \(SIFIVE_PACKAGE_VERSION\)\ OS/ +s/http:\/\/sourceforge\.net\/mail\/?group_id=170565 /https:\/\/github.com\/sifive\/freedom-tools\/issues/ diff --git a/scripts/Freedom.mk b/scripts/Freedom.mk index a671da0..dce99cc 100644 --- a/scripts/Freedom.mk +++ b/scripts/Freedom.mk @@ -1,27 +1,55 @@ -# Reuse the default target -.PHONY: package -package: all +# The default target +.PHONY: all +all: + @echo " Makefile targets: package regress cleanup flushup clean flush help all" -.PHONY: regress -regress: all +.PHONY: help +help: + @echo "" + @echo " SiFive Freedom Tools - Makefile targets:" + @echo "" + @echo " package" + @echo " Build the binary packages for this repo." + @echo "" + @echo " regress" + @echo " Test the prebuilt packages for this repo." + @echo "" + @echo " cleanup" + @echo " Clean the build artifacts for this repo." + @echo "" + @echo " flushup" + @echo " Flush the build artifacts for this repo." + @echo "" + @echo " clean" + @echo " Remove the bin and obj directories." + @echo "" + @echo " flush" + @echo " Remove the obj directory." + @echo "" + @echo " help" + @echo " Show this help." + @echo "" + @echo " all" + @echo " Show Makefile targets." + @echo "" -.PHONY: cleanup -cleanup: all +.PHONY: package native-package cross-package +package: +native-package: +cross-package: -.PHONY: flushup -flushup: all +.PHONY: regress +regress: # Make uses /bin/sh by default, ignoring the user's value of SHELL. # Some systems now ship with /bin/sh pointing at dash, and this Makefile # requires bash SHELL = /bin/bash -BINDIR_PREFIX ?= ./ -OBJDIR_PREFIX ?= ./ -SRCDIR_PREFIX ?= ./ +BINDIR_PREFIX ?= ../../ +OBJDIR_PREFIX ?= ../../ BINDIR := $(BINDIR_PREFIX)bin OBJDIR := $(OBJDIR_PREFIX)obj -SRCDIR := $(SRCDIR_PREFIX)src UBUNTU64 ?= x86_64-linux-ubuntu14 REDHAT ?= x86_64-linux-centos6 @@ -32,21 +60,29 @@ DARWIN ?= x86_64-apple-darwin ifneq ($(wildcard /etc/redhat-release),) NATIVE ?= $(REDHAT) NINJA ?= ninja-build -#all: redhat +package: redhat-package +native-package: redhat-package +regress: native-regress else ifeq ($(DISTRIB_ID),Ubuntu) NATIVE ?= $(UBUNTU64) -#all: ubuntu64 -#all: win64 +CROSS ?= $(WIN64) +package: ubuntu64-package +native-package: ubuntu64-package +package: win64-package +cross-package: win64-package +regress: native-regress else ifeq ($(shell uname),Darwin) NATIVE ?= $(DARWIN) LIBTOOLIZE ?= glibtoolize TAR ?= gtar SED ?= gsed AWK ?= gawk -#all: darwin +package: darwin-package +native-package: darwin-package +regress: native-regress else ifneq ($(wildcard /mingw64/etc),) NATIVE ?= $(WIN64) -#all: win64 +regress: native-regress else $(error Unknown host) endif @@ -58,6 +94,7 @@ AWK ?= awk NINJA ?= ninja OBJ_NATIVE := $(OBJDIR)/$(NATIVE) +OBJ_CROSS := $(OBJDIR)/$(CROSS) OBJ_UBUNTU64 := $(OBJDIR)/$(UBUNTU64) OBJ_WIN64 := $(OBJDIR)/$(WIN64) OBJ_DARWIN := $(OBJDIR)/$(DARWIN) @@ -66,7 +103,7 @@ OBJ_REDHAT := $(OBJDIR)/$(REDHAT) # Targets that don't build anything .PHONY: clean clean:: - rm -rf $(SRCDIR) $(OBJDIR) $(BINDIR) + rm -rf $(OBJDIR) $(BINDIR) .PHONY: flush flush:: diff --git a/scripts/Package.mk b/scripts/Package.mk index 2cef3ec..461771a 100644 --- a/scripts/Package.mk +++ b/scripts/Package.mk @@ -1,38 +1,147 @@ -FREEDOM_CUSTOM_GITURL := https://github.com/sifive/freedom-sdk-utilities.git -FREEDOM_CUSTOM_BRANCH := main -FREEDOM_CUSTOM_MODULE := freedom-custom +# The package build needs the tools in the PATH, and the windows build might use the ubuntu (native) +PATH := $(abspath $(OBJ_NATIVE)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(NATIVE)/bin):$(PATH) +export PATH -ifneq ($(TARGET_GITURL),) -FREEDOM_CUSTOM_GITURL := $(TARGET_GITURL) -endif -ifneq ($(TARGET_BRANCH),) -FREEDOM_CUSTOM_BRANCH := $(TARGET_BRANCH) -endif +# The actual output of this repository is a set of tarballs. +.PHONY: win64-package +win64-package: $(BINDIR)/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64).zip +win64-package: $(BINDIR)/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64).tar.gz +win64-package: $(BINDIR)/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64).log.tar.gz +win64-package: $(BINDIR)/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64).cfg.tar.gz +win64-package: $(BINDIR)/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64).properties +.PHONY: ubuntu64-package +ubuntu64-package: $(BINDIR)/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(UBUNTU64).tar.gz +ubuntu64-package: $(BINDIR)/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(UBUNTU64).log.tar.gz +ubuntu64-package: $(BINDIR)/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(UBUNTU64).cfg.tar.gz +ubuntu64-package: $(BINDIR)/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(UBUNTU64).properties +.PHONY: redhat-package +redhat-package: $(BINDIR)/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT).tar.gz +redhat-package: $(BINDIR)/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT).log.tar.gz +redhat-package: $(BINDIR)/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT).cfg.tar.gz +redhat-package: $(BINDIR)/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(REDHAT).properties +.PHONY: darwin-package +darwin-package: $(BINDIR)/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(DARWIN).tar.gz +darwin-package: $(BINDIR)/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(DARWIN).log.tar.gz +darwin-package: $(BINDIR)/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(DARWIN).cfg.tar.gz +darwin-package: $(BINDIR)/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(DARWIN).properties -.PHONY: custom custom-package custom-regress custom-cleanup custom-flushup -custom: custom-package +# There's enough % rules that make starts blowing intermediate files away. +.SECONDARY: + +$(BINDIR)/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64).zip: \ + $(OBJDIR)/$(WIN64)/build/$(PACKAGE_HEADING)/install.stamp \ + $(OBJDIR)/$(WIN64)/build/$(PACKAGE_HEADING)/libs.stamp + mkdir -p $(dir $@) + cd $(OBJDIR)/$(WIN64)/install; zip -rq $(abspath $@) $(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64) -$(FREEDOM_CUSTOM_MODULE).$(FREEDOM_CUSTOM_BRANCH): +$(BINDIR)/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64).tar.gz: \ + $(OBJDIR)/$(WIN64)/build/$(PACKAGE_HEADING)/install.stamp \ + $(OBJDIR)/$(WIN64)/build/$(PACKAGE_HEADING)/libs.stamp mkdir -p $(dir $@) - rm -rf $(FREEDOM_CUSTOM_MODULE) - rm -rf $(FREEDOM_CUSTOM_MODULE).* - git clone $(FREEDOM_CUSTOM_GITURL) $(FREEDOM_CUSTOM_MODULE) --single-branch -b $(FREEDOM_CUSTOM_BRANCH) - cd $(FREEDOM_CUSTOM_MODULE) && git submodule update --init --recursive + cd $(OBJDIR)/$(WIN64)/install; $(TAR) --dereference --hard-dereference -c $(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64) | gzip > $(abspath $@) + +$(BINDIR)/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64).log.tar.gz: \ + $(OBJDIR)/$(WIN64)/build/$(PACKAGE_HEADING)/install.stamp \ + $(OBJDIR)/$(WIN64)/build/$(PACKAGE_HEADING)/libs.stamp + mkdir -p $(dir $@) + cd $(OBJDIR)/$(WIN64)/buildlog/$(PACKAGE_HEADING); $(TAR) --dereference --hard-dereference -c * | gzip > $(abspath $@) + +$(BINDIR)/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64).cfg.tar.gz: \ + $(OBJDIR)/$(WIN64)/build/$(PACKAGE_HEADING)/install.stamp \ + $(OBJDIR)/$(WIN64)/build/$(PACKAGE_HEADING)/libs.stamp + mkdir -p $(dir $@) + cd $(abspath ../../); $(TAR) --dereference --hard-dereference --exclude bin --exclude obj -c * | gzip > $(abspath $@) + +$(BINDIR)/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64).properties: \ + $(OBJDIR)/$(WIN64)/build/$(PACKAGE_HEADING)/install.stamp \ + $(OBJDIR)/$(WIN64)/build/$(PACKAGE_HEADING)/libs.stamp + mkdir -p $(dir $@) + cp $(OBJDIR)/$(WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64).properties $(abspath $@) + +$(BINDIR)/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(NATIVE).tar.gz: \ + $(OBJDIR)/$(NATIVE)/build/$(PACKAGE_HEADING)/install.stamp + mkdir -p $(dir $@) + cd $(OBJDIR)/$(NATIVE)/install; $(TAR) --dereference --hard-dereference -c $(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(NATIVE) | gzip > $(abspath $@) + +$(BINDIR)/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(NATIVE).log.tar.gz: \ + $(OBJDIR)/$(NATIVE)/build/$(PACKAGE_HEADING)/install.stamp + mkdir -p $(dir $@) + cd $(OBJDIR)/$(NATIVE)/buildlog/$(PACKAGE_HEADING); $(TAR) --dereference --hard-dereference -c * | gzip > $(abspath $@) + +$(BINDIR)/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(NATIVE).cfg.tar.gz: \ + $(OBJDIR)/$(NATIVE)/build/$(PACKAGE_HEADING)/install.stamp + mkdir -p $(dir $@) + cd $(abspath ../../); $(TAR) --dereference --hard-dereference --exclude bin --exclude obj -c * | gzip > $(abspath $@) + +$(BINDIR)/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(NATIVE).properties: \ + $(OBJDIR)/$(NATIVE)/build/$(PACKAGE_HEADING)/install.stamp + mkdir -p $(dir $@) + cp $(OBJDIR)/$(NATIVE)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(NATIVE).properties $(abspath $@) + +# Installs native package. +PACKAGE_TARBALL = $(wildcard $(BINDIR)/$(PACKAGE_HEADING)-*-$(NATIVE).tar.gz) +ifneq ($(PACKAGE_TARBALL),) +PACKAGE_TARNAME = $(basename $(basename $(notdir $(PACKAGE_TARBALL)))) + +$(OBJDIR)/$(NATIVE)/test/$(PACKAGE_HEADING)/launch.stamp: \ + $(PACKAGE_TARBALL) + mkdir -p $(dir $@) + rm -rf $(OBJDIR)/$(NATIVE)/launch/$(PACKAGE_TARNAME) + mkdir -p $(OBJDIR)/$(NATIVE)/launch + $(TAR) -xz -C $(OBJDIR)/$(NATIVE)/launch -f $(PACKAGE_TARBALL) date > $@ +else +$(OBJDIR)/$(NATIVE)/test/$(PACKAGE_HEADING)/launch.stamp: + $(error No $(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(NATIVE).tar.gz tarball available for testing!) +endif + +.PHONY: native-regress +native-regress: $(OBJDIR)/$(NATIVE)/test/$(PACKAGE_HEADING)/test.stamp + +.PHONY: cleanup native-cleanup cross-cleanup +cleanup: native-cleanup cross-cleanup + +native-cleanup: + rm -rf $(OBJ_NATIVE)/test/$(PACKAGE_HEADING) + rm -rf $(OBJ_NATIVE)/build/$(PACKAGE_HEADING) + rm -rf $(OBJ_NATIVE)/launch/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(NATIVE) + rm -rf $(OBJ_NATIVE)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(NATIVE) + rm -rf $(OBJ_NATIVE)/testlog/$(PACKAGE_HEADING) + rm -rf $(OBJ_NATIVE)/buildlog/$(PACKAGE_HEADING) + rm -rf $(BINDIR)/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(NATIVE).tar.gz + rm -rf $(BINDIR)/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(NATIVE).log.tar.gz + rm -rf $(BINDIR)/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(NATIVE).cfg.tar.gz + rm -rf $(BINDIR)/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(NATIVE).properties -custom-package: \ - $(FREEDOM_CUSTOM_MODULE).$(FREEDOM_CUSTOM_BRANCH) - $(MAKE) -C $(FREEDOM_CUSTOM_MODULE) package POSTFIXPATH=$(abspath $(POSTFIXPATH))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) +cross-cleanup: + rm -rf $(OBJ_WIN64)/test/$(PACKAGE_HEADING) + rm -rf $(OBJ_WIN64)/build/$(PACKAGE_HEADING) + rm -rf $(OBJ_WIN64)/launch/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64) + rm -rf $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64) + rm -rf $(OBJ_WIN64)/testlog/$(PACKAGE_HEADING) + rm -rf $(OBJ_WIN64)/buildlog/$(PACKAGE_HEADING) + rm -rf $(BINDIR)/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64).zip + rm -rf $(BINDIR)/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64).tar.gz + rm -rf $(BINDIR)/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64).log.tar.gz + rm -rf $(BINDIR)/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64).cfg.tar.gz + rm -rf $(BINDIR)/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64).properties -custom-regress: \ - $(FREEDOM_CUSTOM_MODULE).$(FREEDOM_CUSTOM_BRANCH) - $(MAKE) -C $(FREEDOM_CUSTOM_MODULE) regress POSTFIXPATH=$(abspath $(POSTFIXPATH))/ EXTRA_OPTION=$(EXTRA_OPTION) EXTRA_SUFFIX=$(EXTRA_SUFFIX) +.PHONY: flushup native-flushup cross-flushup +flushup: native-flushup cross-flushup -custom-cleanup: - $(MAKE) -C $(FREEDOM_CUSTOM_MODULE) cleanup POSTFIXPATH=$(abspath $(POSTFIXPATH))/ - rm -rf $(FREEDOM_CUSTOM_MODULE).* - rm -rf $(FREEDOM_CUSTOM_MODULE) +native-flushup: + rm -rf $(OBJ_NATIVE)/test/$(PACKAGE_HEADING) + rm -rf $(OBJ_NATIVE)/build/$(PACKAGE_HEADING) + rm -rf $(OBJ_NATIVE)/launch/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(NATIVE) + rm -rf $(OBJ_NATIVE)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(NATIVE) + rm -rf $(OBJ_NATIVE)/testlog/$(PACKAGE_HEADING) + rm -rf $(OBJ_NATIVE)/buildlog/$(PACKAGE_HEADING) -custom-flushup: - $(MAKE) -C $(FREEDOM_CUSTOM_MODULE) flushup POSTFIXPATH=$(abspath $(POSTFIXPATH))/ +cross-flushup: + rm -rf $(OBJ_WIN64)/test/$(PACKAGE_HEADING) + rm -rf $(OBJ_WIN64)/build/$(PACKAGE_HEADING) + rm -rf $(OBJ_WIN64)/launch/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64) + rm -rf $(OBJ_WIN64)/install/$(PACKAGE_HEADING)-$(PACKAGE_VERSION)-$(WIN64) + rm -rf $(OBJ_WIN64)/testlog/$(PACKAGE_HEADING) + rm -rf $(OBJ_WIN64)/buildlog/$(PACKAGE_HEADING) diff --git a/scripts/base_binutils_metadata.mk b/scripts/base_binutils_metadata.mk new file mode 100644 index 0000000..62869d6 --- /dev/null +++ b/scripts/base_binutils_metadata.mk @@ -0,0 +1,17 @@ +include ../../scripts/base_toolchain_metadata.mk + +# Git repos, branches, commits and folders to get source code for the tool we are building +RISCV_BINUTILS_GITURL := git@github.com:sifive/riscv-binutils-gdb.git +RISCV_BINUTILS_BRANCH := sifive-rvv-1.0.x-zfh-rvb +RISCV_BINUTILS_COMMIT := 75d2236ce26a3048f52bbd5186602e27bd635e2b +RISCV_BINUTILS_FOLDER := riscv-binutils + +# Version number, which should match the official version of the tool we are building +RISCV_BINUTILS_VERSION := 2.35.0 + +# Customization ID, which should identify the customization added to the original by SiFive +FREEDOM_BINUTILS_ID := $(FREEDOM_TOOLCHAIN_ID) + +# Characteristic tags, which should be usable for matching up providers and consumers +FREEDOM_BINUTILS_RISCV_TAGS := $(FREEDOM_TOOLCHAIN_RISCV_TAGS) +FREEDOM_BINUTILS_TAG_PREFIX := binutils diff --git a/scripts/base_gcc_metadata.mk b/scripts/base_gcc_metadata.mk new file mode 100644 index 0000000..165c391 --- /dev/null +++ b/scripts/base_gcc_metadata.mk @@ -0,0 +1,17 @@ +include ../../scripts/base_toolchain_metadata.mk + +# Git repos, branches, commits and folders to get source code for the tool we are building +RISCV_GCC_GITURL := git@github.com:sifive/riscv-gcc.git +RISCV_GCC_BRANCH := sifive-gcc-10.2.0 +RISCV_GCC_COMMIT := 37e9e5efeda593e0ff594105c83da67d2d2832e5 +RISCV_GCC_FOLDER := riscv-gcc + +# Version number, which should match the official version of the tool we are building +RISCV_GCC_VERSION := 10.2.0 + +# Customization ID, which should identify the customization added to the original by SiFive +FREEDOM_GCC_ID := $(FREEDOM_TOOLCHAIN_ID) + +# Characteristic tags, which should be usable for matching up providers and consumers +FREEDOM_GCC_RISCV_TAGS := $(FREEDOM_TOOLCHAIN_RISCV_TAGS) +FREEDOM_GCC_TAG_PREFIX := gcc10 diff --git a/scripts/base_gdb_metadata.mk b/scripts/base_gdb_metadata.mk new file mode 100644 index 0000000..e0bab5a --- /dev/null +++ b/scripts/base_gdb_metadata.mk @@ -0,0 +1,17 @@ +include ../../scripts/base_toolchain_metadata.mk + +# Git repos, branches, commits and folders to get source code for the tool we are building +RISCV_GDB_GITURL := git@github.com:sifive/riscv-binutils-gdb.git +RISCV_GDB_BRANCH := sifive-gdb-rvv-1.0.x-zfh-rvb-with-sim +RISCV_GDB_COMMIT := 1ac8c2ffcb4a0a98d0597e71f9313352bda11ee3 +RISCV_GDB_FOLDER := riscv-gdb + +# Version number, which should match the official version of the tool we are building +RISCV_GDB_VERSION := 10.1.0 + +# Customization ID, which should identify the customization added to the original by SiFive +FREEDOM_GDB_ID := $(FREEDOM_TOOLCHAIN_ID) + +# Characteristic tags, which should be usable for matching up providers and consumers +FREEDOM_GDB_RISCV_TAGS := $(FREEDOM_TOOLCHAIN_RISCV_TAGS) +FREEDOM_GDB_TAG_PREFIX := gdb diff --git a/scripts/base_newlib_metadata.mk b/scripts/base_newlib_metadata.mk new file mode 100644 index 0000000..07e8936 --- /dev/null +++ b/scripts/base_newlib_metadata.mk @@ -0,0 +1,5 @@ +# Git repos, branches, commits and folders to get source code for the tool we are building +RISCV_NEWLIB_GITURL := git@github.com:sifive/riscv-newlib.git +RISCV_NEWLIB_BRANCH := sifive-newlib-4.1.0-rvv +RISCV_NEWLIB_COMMIT := aa755e658de9fc74678bd63a6ae556e66f636c6c +RISCV_NEWLIB_FOLDER := riscv-newlib diff --git a/scripts/base_toolchain_metadata.mk b/scripts/base_toolchain_metadata.mk new file mode 100644 index 0000000..23f7bc9 --- /dev/null +++ b/scripts/base_toolchain_metadata.mk @@ -0,0 +1,5 @@ +# Customization ID, which should identify the customization added to the original by SiFive +FREEDOM_TOOLCHAIN_ID := 2020.12.8 + +# Characteristic tags, which should be usable for matching up providers and consumers +FREEDOM_TOOLCHAIN_RISCV_TAGS := rv32i rv64i m a f d c v zfh zba zbb diff --git a/scripts/check-maximum-path-length.tcl b/scripts/check-maximum-path-length.tcl new file mode 100644 index 0000000..cf6e823 --- /dev/null +++ b/scripts/check-maximum-path-length.tcl @@ -0,0 +1,43 @@ +#!/usr/bin/tclsh + +cd [lindex $argv 0] +set pathmax 200 +set rootlen [string length "[pwd]/"] +set res 0 + +set PACKAGE_HEADING [string length [lindex $argv 1]] +set ORIGINAL_VERSION [string length [lindex $argv 2]] +set FREEDOM_TOOLS_ID [string length [lindex $argv 3]] +set pathmax [expr ${pathmax}-${PACKAGE_HEADING}-${ORIGINAL_VERSION}-${FREEDOM_TOOLS_ID}-2] + +proc checkfiles {rd} { + global pathmax rootlen res + + set fs [lsort [glob -nocomplain -types f "$rd/*"]] + foreach f $fs { + set str [string range $f $rootlen end] + set len [string length $str] + if {$len > $pathmax} { + puts "Path exceeds maximum allowed length: \"$str\" has length $len larger than $pathmax" + set res 1 + } else { +# puts "Checking: \"$str\" has length $len with max $pathmax" + } + } + + set ds [lsort [glob -nocomplain -types d "$rd/*"]] + foreach d $ds { + set str [string range $d $rootlen end] + set len [string length $str] + if {$len > $pathmax} { + puts "Path exceeds maximum allowed length: \"$str\" has length $len larger than $pathmax" + set res 1 + } else { +# puts "Checking: \"$str\" has length $len with max $pathmax" + } + checkfiles $d + } +} + +checkfiles [pwd] +exit $res diff --git a/scripts/check-naming-and-version-syntax.tcl b/scripts/check-naming-and-version-syntax.tcl new file mode 100644 index 0000000..68c3f4b --- /dev/null +++ b/scripts/check-naming-and-version-syntax.tcl @@ -0,0 +1,24 @@ +#!/usr/bin/tclsh + +set PACKAGE_WORDING [lindex $argv 0] +set PACKAGE_HEADING [lindex $argv 1] +set ORIGINAL_VERSION [lindex $argv 2] +set FREEDOM_TOOLS_ID [lindex $argv 3] +set res 0 + +proc check_syntax {exp val txt} { + global res + if {![regexp $exp $val]} { + puts "\"$val\" does not match syntax \"$exp\" for $txt" + set res 1 + } else { +# puts "\"$val\" does match syntax \"$exp\" for $txt" + } +} + +check_syntax {^[0-9a-zA-Z_\-\.\ ]+$} $::PACKAGE_WORDING "PACKAGE_WORDING" +check_syntax {^[0-9a-z_\-\.]+$} $::PACKAGE_HEADING "PACKAGE_HEADING" +check_syntax {^[0-9]+\.[0-9]+\.[0-9]+$} $::ORIGINAL_VERSION "ORIGINAL_VERSION" +check_syntax {^[0-9a-z_\-\.]+$} $::FREEDOM_TOOLS_ID "FREEDOM_TOOLS_ID" + +exit $res diff --git a/scripts/check-same-name-different-case.tcl b/scripts/check-same-name-different-case.tcl new file mode 100644 index 0000000..5ae88ee --- /dev/null +++ b/scripts/check-same-name-different-case.tcl @@ -0,0 +1,38 @@ +#!/usr/bin/tclsh + +cd [lindex $argv 0] +set pathmap [dict create] +set rootlen [string length "[pwd]/"] +set res 0 + +proc checkfiles {rd} { + global pathmap rootlen res + + set fs [lsort [glob -nocomplain -types f "$rd/*"]] + foreach f $fs { + set fnc [string tolower [string range $f $rootlen end]] + if {[dict exists $pathmap $fnc]} { + puts "Multiple paths with different case exists for: $fnc" + set res 1 + } else { +# puts "Checking: $fnc" + } + dict set pathmap $fnc 1 + } + + set ds [lsort [glob -nocomplain -types d "$rd/*"]] + foreach d $ds { + set dnc [string tolower [string range $d $rootlen end]] + if {[dict exists $pathmap $dnc]} { + puts "Multiple paths with different case exists for: $dnc" + set res 1 + } else { +# puts "Checking: $dnc" + } + dict set pathmap $dnc 1 + checkfiles $d + } +} + +checkfiles [pwd] +exit $res diff --git a/scripts/dyn-lib-check-x86_64-apple-darwin.tcl b/scripts/dyn-lib-check-x86_64-apple-darwin.tcl new file mode 100644 index 0000000..9bb2355 --- /dev/null +++ b/scripts/dyn-lib-check-x86_64-apple-darwin.tcl @@ -0,0 +1,53 @@ +#!/usr/bin/tclsh + +set dlcode 0 +set dllist [list \ + "/System/Library/Frameworks/Hypervisor.framework" \ + "/System/Library/Frameworks/CoreFoundation.framework" \ + "/System/Library/Frameworks/IOKit.framework" \ + "/System/Library/Frameworks/CoreAudio.framework" \ + "/System/Library/Frameworks/Cocoa.framework" \ + "/System/Library/Frameworks/Carbon.framework" \ + "/System/Library/Frameworks/AppKit.framework" \ + "/System/Library/Frameworks/ApplicationServices.framework" \ + "/System/Library/Frameworks/CoreGraphics.framework" \ + "/System/Library/Frameworks/CoreServices.framework" \ + "/System/Library/Frameworks/Foundation.framework" \ + "/usr/lib/libresolv" \ + "/usr/lib/libiconv" \ + "/usr/lib/libc++" \ + "/usr/lib/libSystem" \ + "/usr/lib/libobjc" \ + "/usr/lib/libncurses" \ + "/usr/lib/liblzma" \ +] + +proc dlcheck {arg} { + global dlcode dllist + + set res [exec otool -L $arg] + set lns [split $res "\n"] + foreach ln $lns { + set txt [string trim $ln] + if {[string index $txt end] ne ":"} { + set fnd 0 + foreach dl $dllist { + if {[string first $dl $txt] >= 0} { + set fnd 1 + break + } + } + if {$fnd == 0} { + set dlcode 1 + puts " Illegal library used: $txt" + } + } + } +} + +foreach arg $argv { + puts "Checking dynamic library usage for: $arg" + dlcheck $arg +} + +exit $dlcode diff --git a/scripts/dyn-lib-check-x86_64-linux-centos6.tcl b/scripts/dyn-lib-check-x86_64-linux-centos6.tcl new file mode 100644 index 0000000..afd6c21 --- /dev/null +++ b/scripts/dyn-lib-check-x86_64-linux-centos6.tcl @@ -0,0 +1,49 @@ +#!/usr/bin/tclsh + +set dlcode 0 +set dllist [list \ + "linux-vdso.so" \ + "libutil.so" \ + "libresolv.so" \ + "libdl.so" \ + "librt.so" \ + "libm.so" \ + "libstdc++.so" \ + "libgcc_s.so" \ + "libpthread.so" \ + "libc.so" \ + "libcrypt.so" \ + "libfreebl3.so" \ + "libnsl.so" \ + "/lib64/ld-linux-x86-64.so" \ +] + +proc dlcheck {arg} { + global dlcode dllist + + set res [exec ldd $arg] + set lns [split $res "\n"] + foreach ln $lns { + set txt [string trim $ln] + if {[string index $txt end] ne ":"} { + set fnd 0 + foreach dl $dllist { + if {[string first $dl $txt] >= 0} { + set fnd 1 + break + } + } + if {$fnd == 0} { + set dlcode 1 + puts " Illegal library used: $txt" + } + } + } +} + +foreach arg $argv { + puts "Checking dynamic library usage for: $arg" + dlcheck $arg +} + +exit $dlcode diff --git a/scripts/dyn-lib-check-x86_64-linux-ubuntu14.tcl b/scripts/dyn-lib-check-x86_64-linux-ubuntu14.tcl new file mode 100644 index 0000000..ec7130b --- /dev/null +++ b/scripts/dyn-lib-check-x86_64-linux-ubuntu14.tcl @@ -0,0 +1,47 @@ +#!/usr/bin/tclsh + +set dlcode 0 +set dllist [list \ + "linux-vdso.so" \ + "libutil.so" \ + "libresolv.so" \ + "libdl.so" \ + "librt.so" \ + "libm.so" \ + "libstdc++.so" \ + "libgcc_s.so" \ + "libpthread.so" \ + "libc.so" \ + "libnsl.so" \ + "/lib64/ld-linux-x86-64.so" \ +] + +proc dlcheck {arg} { + global dlcode dllist + + set res [exec ldd $arg] + set lns [split $res "\n"] + foreach ln $lns { + set txt [string trim $ln] + if {[string index $txt end] ne ":"} { + set fnd 0 + foreach dl $dllist { + if {[string first $dl $txt] >= 0} { + set fnd 1 + break + } + } + if {$fnd == 0} { + set dlcode 1 + puts " Illegal library used: $txt" + } + } + } +} + +foreach arg $argv { + puts "Checking dynamic library usage for: $arg" + dlcheck $arg +} + +exit $dlcode diff --git a/scripts/dyn-lib-check-x86_64-w64-mingw32.tcl b/scripts/dyn-lib-check-x86_64-w64-mingw32.tcl new file mode 100644 index 0000000..149094e --- /dev/null +++ b/scripts/dyn-lib-check-x86_64-w64-mingw32.tcl @@ -0,0 +1,10 @@ +#!/usr/bin/tclsh + +# w64_mingw32 are not checked as there are no means to do it on linux +set dlcode 0 + +foreach arg $argv { + puts "Checking dynamic library usage for: $arg" +} + +exit $dlcode