summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathaniel Graff <nathaniel.graff@sifive.com>2018-12-13 14:02:52 -0800
committerPalmer Dabbelt <palmer@sifive.com>2018-12-13 18:14:36 -0800
commitcc139c77212bd1c8bf306048539eef20ad955f9a (patch)
tree3a759945686fa29a016883946bf2780ad29783a3
parentb38973e0327f79d1c2ca2f86872a0954b0ad4c79 (diff)
Support Building of MEE and MEE examples
Signed-off-by: Nathaniel Graff <nathaniel.graff@sifive.com>
-rw-r--r--.gitignore7
-rw-r--r--Makefile140
-rwxr-xr-xscripts/debug34
-rwxr-xr-xscripts/upload34
4 files changed, 203 insertions, 12 deletions
diff --git a/.gitignore b/.gitignore
index 534c2dc..2f420c2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,8 +9,13 @@ software/demo_gpio/demo_gpio
software/dhrystone/dhrystone
software/double_tap_dontboot/double_tap_dontboot
software/global_interrupts/global_interrupts
-software/hello/hello
software/led_fade/led_fade
software/local_interrupts/local_interrupts
software/performance_counters/performance_counters
software/smp/smp
+
+bsp/*/build
+bsp/*/install
+
+/Makefile.local
+/enter.bash
diff --git a/Makefile b/Makefile
index 5b1b186..ec363a9 100644
--- a/Makefile
+++ b/Makefile
@@ -15,21 +15,32 @@ include $(extra_configs)
endif
# Default target
+
+# legacy for old e-sdk or mee
+BSP ?= legacy
+
+ifeq ($(BSP),legacy)
+BSP_SUBDIR ?= env
BOARD ?= freedom-e300-hifive1
PROGRAM ?= demo_gpio
LINK_TARGET ?= flash
GDB_PORT ?= 3333
-# Variables the user probably shouldn't override.
-builddir := work/build
+else # MEE
+BSP_SUBDIR ?=
+PROGRAM ?= hello
+BOARD ?= sifive-hifive1
+endif # $(BSP)
+
+# Variables the user probably shouldn't override.
#############################################################
# BSP Loading
#############################################################
# Finds the directory in which this BSP is located, ensuring that there is
# exactly one.
-board_dir := $(wildcard bsp/env/$(BOARD))
+board_dir := $(wildcard bsp/$(BSP_SUBDIR)/$(BOARD))
ifeq ($(words $(board_dir)),0)
$(error Unable to find BSP for $(BOARD), expected to find either "bsp/$(BOARD)" or "bsp-addons/$(BOARD)")
endif
@@ -37,10 +48,17 @@ ifneq ($(words $(board_dir)),1)
$(error Found multiple BSPs for $(BOARD): "$(board_dir)")
endif
+ifeq ($(BSP), mee)
+
+include $(board_dir)/settings.mk
+
+else
+
# There must be a settings makefile fragment in the BSP's board directory.
ifeq ($(wildcard $(board_dir)/settings.mk),)
$(error Unable to find BSP for $(BOARD), expected to find $(board_dir)/settings.mk)
endif
+
include $(board_dir)/settings.mk
ifeq ($(RISCV_ARCH),)
@@ -51,6 +69,8 @@ ifeq ($(RISCV_ABI),)
$(error $(board_dir)/board.mk must set RISCV_ABI, the ABI to target)
endif
+endif
+
# Determines the XLEN from the toolchain tuple
ifeq ($(patsubst rv32%,rv32,$(RISCV_ARCH)),rv32)
RISCV_XLEN := 32
@@ -68,10 +88,16 @@ help:
@echo " SiFive Freedom E Software Development Kit "
@echo " Makefile targets:"
@echo ""
- @echo " software [PROGRAM=$(PROGRAM) BOARD=$(BOARD)]:"
+ @echo " software BSP=legacy [PROGRAM=$(PROGRAM) BOARD=$(BOARD)]:"
@echo " Build a software program to load with the"
@echo " debugger."
@echo ""
+ @echo " mee BSP=mee [BOARD=$(BOARD)]"
+ @echo " Build the MEE library for BOARD"
+ @echo ""
+ @echo " examples BSP=mee [BOARD=$(BOARD)]"
+ @echo " Build all the examples for the given board."
+ @echo ""
@echo " clean [PROGRAM=$(PROGRAM) BOARD=$(BOARD)]:"
@echo " Clean compiled objects for a specified "
@echo " software program."
@@ -90,29 +116,112 @@ help:
@echo ""
@echo " For more information, visit dev.sifive.com"
+.PHONY: clean
+clean:
+
#############################################################
# This section is for tool configuration
#############################################################
-toolchain_builddir := $(builddir)/riscv-gnu-toolchain/riscv64-unknown-elf
-toolchain_prefix := $(toolchain_builddir)/prefix
-
-RISCV_PATH ?= $(toolchain_prefix)
-
+# If users don't specify RISCV_PATH then assume that the tools will just be in
+# their path.
+ifeq ($(RISCV_PATH),)
+RISCV_GCC := $(CROSS_COMPILE)-gcc
+RISCV_GXX := $(CROSS_COMPILE)-g++
+RISCV_OBJDUMP := $(CROSS_COMPILE)-objdump
+RISCV_GDB := $(CROSS_COMPILE)-gdb
+RISCV_AR := $(CROSS_COMPILE)-ar
+RISCV_OPENOCD := openocd
+else
RISCV_GCC := $(abspath $(RISCV_PATH)/bin/$(CROSS_COMPILE)-gcc)
RISCV_GXX := $(abspath $(RISCV_PATH)/bin/$(CROSS_COMPILE)-g++)
RISCV_OBJDUMP := $(abspath $(RISCV_PATH)/bin/$(CROSS_COMPILE)-objdump)
RISCV_GDB := $(abspath $(RISCV_PATH)/bin/$(CROSS_COMPILE)-gdb)
RISCV_AR := $(abspath $(RISCV_PATH)/bin/$(CROSS_COMPILE)-ar)
+RISCV_OPENOCD := $(abspath $(RISCV_PATH)/bin/openocd)
+PATH := $(abspath $(RISCV_PATH)/bin):$(PATH)
+endif
-PATH := $(abspath $(RISCV_PATH)/bin):$(PATH)
+#############################################################
+# Compiles an instance of the MEE targeted at $(BOARD)
+#############################################################
+ifeq ($(BSP),mee)
+MEE_SOURCE_PATH ?= freedom-mee
+MEE_BSP_PATH = bsp/$(BOARD)
+MEE_LDSCRIPT = $(MEE_BSP_PATH)/mee.lds
+MEE_HEADER = $(MEE_BSP_PATH)/mee.h
+
+.PHONY: mee
+mee: $(MEE_BSP_PATH)/install/stamp
+
+$(MEE_BSP_PATH)/build/Makefile:
+ @rm -rf $(dir $@)
+ @mkdir -p $(dir $@)
+ cd $(dir $@) && \
+ CFLAGS="-march=$(RISCV_ARCH) -mabi=$(RISCV_ABI) -g" \
+ $(abspath $(MEE_SOURCE_PATH)/configure) \
+ --host=$(CROSS_COMPILE) \
+ --prefix=$(abspath $(MEE_BSP_PATH)/install) \
+ --with-preconfigured \
+ --with-machine-name=$(BOARD) \
+ --with-machine-header=$(abspath $(MEE_HEADER)) \
+ --with-machine-ldscript=$(abspath $(MEE_LDSCRIPT)) \
+ --with-builtin-libgloss
+ touch -c $@
+
+$(MEE_BSP_PATH)/install/stamp: $(MEE_BSP_PATH)/build/Makefile
+ $(MAKE) -C $(abspath $(MEE_BSP_PATH)/build) install
+ date > $@
+
+$(MEE_BSP_PATH)/install/lib/libriscv%.a: $(MEE_BSP_PATH)/install/stamp ;@:
+
+$(MEE_BSP_PATH)/install/lib/libmee.a: $(MEE_BSP_PATH)/install/lib/libriscv__mmachine__$(BOARD).a
+ cp $< $@
+
+$(MEE_BSP_PATH)/install/lib/libmee-gloss.a: $(MEE_BSP_PATH)/install/lib/libriscv__menv__mee.a
+ cp $< $@
+
+.PHONY: clean-mee
+clean-mee:
+ rm -rf $(MEE_BSP_PATH)/install
+ rm -rf $(MEE_BSP_PATH)/build
+clean: clean-mee
+endif
+
+mee_install: mee
+ $(MAKE) -C $(MEE_SOURCE_PATH) install
#############################################################
# This Section is for Software Compilation
#############################################################
-PROGRAM_DIR = software/$(PROGRAM)
PROGRAM_ELF = software/$(PROGRAM)/$(PROGRAM)
+ifeq ($(BSP),mee)
+.PHONY: software
+software: $(PROGRAM_ELF)
+
+$(PROGRAM_ELF): \
+ $(shell find $(abspath $(dir $(PROGRAM_ELF))) -type f) \
+ $(MEE_BSP_PATH)/install/lib/libmee.a \
+ $(MEE_BSP_PATH)/install/lib/libmee-gloss.a \
+ $(MEE_BSP_PATH)/mee.lds
+ $(MAKE) -C $(dir $@) $(notdir $@) \
+ CC=$(RISCV_GCC) \
+ CXX=$(RISCV_GXX) \
+ CFLAGS="-Os -march=$(RISCV_ARCH) -mabi=$(RISCV_ABI) -g" \
+ CXXFLAGS="-Os -march=$(RISCV_ARCH) -mabi=$(RISCV_ABI) -g" \
+ LDFLAGS="-nostartfiles -nostdlib -L$(sort $(dir $(abspath $(filter %.a,$^)))) -T$(abspath $(filter %.lds,$^))" \
+ LDLIBS="-Wl,--start-group -lc -lmee -lmee-gloss -Wl,--end-group"
+ touch -c $@
+
+.PHONY: clean-software
+clean-software:
+ $(MAKE) -C $(dir $(PROGRAM_ELF)) clean
+clean: clean-software
+
+else
+PROGRAM_DIR=$(dir $(PROGRAM_ELF))
+
.PHONY: software_clean
clean: software_clean
software_clean:
@@ -124,10 +233,18 @@ software: software_clean
dasm: software $(RISCV_OBJDUMP)
$(RISCV_OBJDUMP) -D $(PROGRAM_ELF)
+endif
#############################################################
# This Section is for uploading a program to SPI Flash
#############################################################
+ifeq ($(BSP),mee)
+upload: $(PROGRAM_ELF)
+ scripts/upload --elf $(PROGRAM_ELF) --openocd $(RISCV_OPENOCD) --gdb $(RISCV_GDB) --openocd-config bsp/$(BOARD)/openocd.cfg
+
+debug: $(PROGRAM_ELF)
+ scripts/debug --elf $(PROGRAM_ELF) --openocd $(RISCV_OPENOCD) --gdb $(RISCV_GDB) --openocd-config bsp/$(BOARD)/openocd.cfg
+else
OPENOCDCFG ?= bsp/env/$(BOARD)/openocd.cfg
OPENOCDARGS += -f $(OPENOCDCFG)
@@ -146,6 +263,7 @@ upload:
$(RISCV_OPENOCD) $(OPENOCDARGS) & \
$(RISCV_GDB) $(PROGRAM_DIR)/$(PROGRAM) $(GDB_UPLOAD_ARGS) $(GDB_UPLOAD_CMDS) && \
echo "Successfully uploaded '$(PROGRAM)' to $(BOARD)."
+endif
#############################################################
# This Section is for launching the debugger
diff --git a/scripts/debug b/scripts/debug
new file mode 100755
index 0000000..d02c42c
--- /dev/null
+++ b/scripts/debug
@@ -0,0 +1,34 @@
+#!/bin/bash
+
+set -e
+set -o pipefail
+
+unset elf
+unset cfg
+unset openocd
+unset gdb
+while [[ "$1" != "" ]]
+do
+ case "$1"
+ in
+ --elf) elf="$2"; shift 2;;
+ --openocd) openocd="$2"; shift 2;;
+ --openocd-config) cfg="$2"; shift 2;;
+ --gdb) gdb="$2"; shift 2;;
+ *) echo "$0: Unknown argument $1"; exit 1;;
+ esac
+done
+
+if [[ "$elf" == "" ]]
+then
+ echo "$0: --elf is required" >&2
+ exit 1
+fi
+
+export GDB_PORT=3333
+
+$openocd -f $cfg &
+
+$gdb $elf -ex "set remotetimeout 240" -ex "target extended-remote localhost:${GDB_PORT}"
+
+kill %1
diff --git a/scripts/upload b/scripts/upload
new file mode 100755
index 0000000..66e9ed8
--- /dev/null
+++ b/scripts/upload
@@ -0,0 +1,34 @@
+#!/bin/bash
+
+set -e
+set -o pipefail
+
+unset elf
+unset cfg
+unset openocd
+unset gdb
+while [[ "$1" != "" ]]
+do
+ case "$1"
+ in
+ --elf) elf="$2"; shift 2;;
+ --openocd) openocd="$2"; shift 2;;
+ --openocd-config) cfg="$2"; shift 2;;
+ --gdb) gdb="$2"; shift 2;;
+ *) echo "$0: Unknown argument $1"; exit 1;;
+ esac
+done
+
+if [[ "$elf" == "" ]]
+then
+ echo "$0: --elf is required" >&2
+ exit 1
+fi
+
+export GDB_PORT=3333
+
+$openocd -f $cfg &
+
+$gdb $elf --batch -ex "set remotetimeout 240" -ex "target extended-remote localhost:${GDB_PORT}" -ex "monitor reset halt" -ex "monitor flash protect 0 64 last off" -ex "load" -ex "monitor resume" -ex "monitor shutdown" -ex "quit"
+
+kill %1