2016-07-09 01:29:55 +02:00
|
|
|
RISCV ?= $(CURDIR)/toolchain
|
|
|
|
PATH := $(RISCV)/bin:$(PATH)
|
2017-11-15 17:08:49 +01:00
|
|
|
ISA ?= rv64imafdc
|
|
|
|
ABI ?= lp64d
|
2016-06-17 20:38:33 +02:00
|
|
|
|
|
|
|
srcdir := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
|
|
|
|
srcdir := $(srcdir:/=)
|
|
|
|
confdir := $(srcdir)/conf
|
|
|
|
wrkdir := $(CURDIR)/work
|
|
|
|
|
2016-07-09 02:58:13 +02:00
|
|
|
toolchain_srcdir := $(srcdir)/riscv-gnu-toolchain
|
|
|
|
toolchain_wrkdir := $(wrkdir)/riscv-gnu-toolchain
|
|
|
|
toolchain_dest := $(CURDIR)/toolchain
|
|
|
|
|
2016-06-17 20:38:33 +02:00
|
|
|
buildroot_srcdir := $(srcdir)/buildroot
|
|
|
|
buildroot_wrkdir := $(wrkdir)/buildroot
|
|
|
|
buildroot_tar := $(buildroot_wrkdir)/images/rootfs.tar
|
|
|
|
|
|
|
|
sysroot_stamp := $(wrkdir)/.sysroot
|
|
|
|
sysroot := $(wrkdir)/sysroot
|
|
|
|
|
|
|
|
linux_srcdir := $(srcdir)/linux
|
|
|
|
linux_wrkdir := $(wrkdir)/linux
|
|
|
|
linux_defconfig := $(confdir)/linux_defconfig
|
|
|
|
|
|
|
|
vmlinux := $(linux_wrkdir)/vmlinux
|
|
|
|
vmlinux_stripped := $(linux_wrkdir)/vmlinux-stripped
|
|
|
|
|
|
|
|
pk_srcdir := $(srcdir)/riscv-pk
|
|
|
|
pk_wrkdir := $(wrkdir)/riscv-pk
|
|
|
|
bbl := $(pk_wrkdir)/bbl
|
|
|
|
bin := $(wrkdir)/bbl.bin
|
2016-07-08 02:16:54 +02:00
|
|
|
hex := $(wrkdir)/bbl.hex
|
2016-06-17 20:38:33 +02:00
|
|
|
|
2017-11-03 21:44:17 +01:00
|
|
|
fesvr_srcdir := $(srcdir)/riscv-fesvr
|
|
|
|
fesvr_wrkdir := $(wrkdir)/riscv-fesvr
|
|
|
|
libfesvr := $(fesvr_wrkdir)/prefix/lib/libfesvr.so
|
|
|
|
|
|
|
|
spike_srcdir := $(srcdir)/riscv-isa-sim
|
|
|
|
spike_wrkdir := $(wrkdir)/riscv-isa-sim
|
|
|
|
spike := $(spike_wrkdir)/prefix/bin/spike
|
|
|
|
|
2016-06-17 20:38:33 +02:00
|
|
|
target := riscv64-unknown-linux-gnu
|
|
|
|
|
|
|
|
.PHONY: all
|
2016-07-08 02:16:54 +02:00
|
|
|
all: $(hex)
|
2016-07-09 01:29:55 +02:00
|
|
|
@echo
|
2017-11-15 17:08:49 +01:00
|
|
|
@echo This image has been generated for an ISA of $(ISA) and an ABI of $(ABI)
|
2016-07-09 01:29:55 +02:00
|
|
|
@echo Find the SD-card image in work/bbl.bin
|
|
|
|
@echo Program it with: dd if=work/bbl.bin of=/dev/sd-your-card bs=1M
|
|
|
|
@echo
|
2016-06-17 20:38:33 +02:00
|
|
|
|
2016-07-09 02:58:13 +02:00
|
|
|
$(toolchain_dest)/bin/$(target)-gcc: $(toolchain_srcdir)
|
|
|
|
mkdir -p $(toolchain_wrkdir)
|
2017-11-15 17:08:49 +01:00
|
|
|
cd $(toolchain_wrkdir); $(toolchain_srcdir)/configure \
|
|
|
|
--prefix=$(toolchain_dest) \
|
2017-11-19 21:19:59 +01:00
|
|
|
--with-arch=$(ISA) \
|
2018-01-05 02:36:46 +01:00
|
|
|
--with-abi=$(ABI) \
|
|
|
|
--enable-linux
|
|
|
|
$(MAKE) -C $(toolchain_wrkdir)
|
2017-11-08 22:53:43 +01:00
|
|
|
sed 's/^#define LINUX_VERSION_CODE.*/#define LINUX_VERSION_CODE 263682/' -i $(toolchain_dest)/sysroot/usr/include/linux/version.h
|
2016-07-09 01:29:55 +02:00
|
|
|
|
|
|
|
$(buildroot_tar): $(buildroot_srcdir) $(RISCV)/bin/$(target)-gcc
|
2016-07-09 02:58:13 +02:00
|
|
|
$(MAKE) -C $< RISCV=$(RISCV) PATH=$(PATH) O=$(buildroot_wrkdir) riscv64_defconfig
|
|
|
|
$(MAKE) -C $< RISCV=$(RISCV) PATH=$(PATH) O=$(buildroot_wrkdir)
|
2016-06-17 20:38:33 +02:00
|
|
|
|
|
|
|
.PHONY: buildroot-menuconfig
|
|
|
|
buildroot-menuconfig: $(buildroot_srcdir)
|
|
|
|
$(MAKE) -C $< O=$(buildroot_wrkdir) menuconfig
|
|
|
|
|
|
|
|
$(sysroot_stamp): $(buildroot_tar)
|
|
|
|
mkdir -p $(sysroot)
|
2016-11-29 04:42:51 +01:00
|
|
|
tar -xpf $< -C $(sysroot) --exclude ./dev --exclude ./usr/share/locale
|
2016-06-17 20:38:33 +02:00
|
|
|
touch $@
|
|
|
|
|
2017-04-06 19:22:55 +02:00
|
|
|
$(linux_wrkdir)/.config: $(linux_defconfig) $(linux_srcdir)
|
2016-06-17 20:38:33 +02:00
|
|
|
mkdir -p $(dir $@)
|
|
|
|
cp -p $< $@
|
|
|
|
$(MAKE) -C $(linux_srcdir) O=$(linux_wrkdir) ARCH=riscv olddefconfig
|
2017-11-15 17:08:49 +01:00
|
|
|
echo $(ISA)
|
|
|
|
echo $(filter rv32%,$(ISA))
|
|
|
|
ifeq (,$(filter rv%c,$(ISA)))
|
|
|
|
sed 's/^.*CONFIG_RISCV_ISA_C.*$$/CONFIG_RISCV_ISA_C=n/' -i $@
|
|
|
|
$(MAKE) -C $(linux_srcdir) O=$(linux_wrkdir) ARCH=riscv olddefconfig
|
|
|
|
endif
|
|
|
|
ifeq ($(ISA),$(filter rv32%,$(ISA)))
|
|
|
|
sed 's/^.*CONFIG_ARCH_RV32I.*$$/CONFIG_ARCH_RV32I=y/' -i $@
|
|
|
|
sed 's/^.*CONFIG_ARCH_RV64I.*$$/CONFIG_ARCH_RV64I=n/' -i $@
|
|
|
|
$(MAKE) -C $(linux_srcdir) O=$(linux_wrkdir) ARCH=riscv olddefconfig
|
|
|
|
endif
|
2016-06-17 20:38:33 +02:00
|
|
|
|
|
|
|
$(vmlinux): $(linux_srcdir) $(linux_wrkdir)/.config $(sysroot_stamp)
|
|
|
|
$(MAKE) -C $< O=$(linux_wrkdir) \
|
|
|
|
CONFIG_INITRAMFS_SOURCE="$(confdir)/initramfs.txt $(sysroot)" \
|
|
|
|
CONFIG_INITRAMFS_ROOT_UID=$(shell id -u) \
|
|
|
|
CONFIG_INITRAMFS_ROOT_GID=$(shell id -g) \
|
|
|
|
ARCH=riscv \
|
|
|
|
vmlinux
|
|
|
|
|
|
|
|
$(vmlinux_stripped): $(vmlinux)
|
|
|
|
$(target)-strip -o $@ $<
|
|
|
|
|
|
|
|
.PHONY: linux-menuconfig
|
|
|
|
linux-menuconfig: $(linux_wrkdir)/.config
|
|
|
|
$(MAKE) -C $(linux_srcdir) O=$(dir $<) ARCH=riscv menuconfig savedefconfig
|
|
|
|
|
|
|
|
$(bbl): $(pk_srcdir) $(vmlinux_stripped)
|
|
|
|
rm -rf $(pk_wrkdir)
|
|
|
|
mkdir -p $(pk_wrkdir)
|
|
|
|
cd $(pk_wrkdir) && $</configure \
|
|
|
|
--host=$(target) \
|
2017-11-04 01:06:23 +01:00
|
|
|
--with-payload=$(vmlinux_stripped) \
|
|
|
|
--enable-logo \
|
|
|
|
--with-logo=$(abspath conf/sifive_logo.txt)
|
2017-11-15 17:08:49 +01:00
|
|
|
CFLAGS="-mabi=$(ABI) -march=$(ISA)" $(MAKE) -C $(pk_wrkdir)
|
2016-06-17 20:38:33 +02:00
|
|
|
|
|
|
|
$(bin): $(bbl)
|
|
|
|
$(target)-objcopy -S -O binary --change-addresses -0x80000000 $< $@
|
|
|
|
|
2016-07-08 02:16:54 +02:00
|
|
|
$(hex): $(bin)
|
|
|
|
xxd -c1 -p $< > $@
|
|
|
|
|
2017-11-03 21:44:17 +01:00
|
|
|
$(libfesvr): $(fesvr_srcdir)
|
|
|
|
rm -rf $(fesvr_wrkdir)
|
|
|
|
mkdir -p $(fesvr_wrkdir)
|
|
|
|
mkdir -p $(dir $@)
|
|
|
|
cd $(fesvr_wrkdir) && $</configure \
|
|
|
|
--prefix=$(dir $(abspath $(dir $@)))
|
|
|
|
$(MAKE) -C $(fesvr_wrkdir)
|
|
|
|
$(MAKE) -C $(fesvr_wrkdir) install
|
|
|
|
touch -c $@
|
|
|
|
|
|
|
|
$(spike): $(spike_srcdir) $(libfesvr)
|
|
|
|
rm -rf $(spike_wrkdir)
|
|
|
|
mkdir -p $(spike_wrkdir)
|
|
|
|
mkdir -p $(dir $@)
|
|
|
|
cd $(spike_wrkdir) && $</configure \
|
|
|
|
--prefix=$(dir $(abspath $(dir $@))) \
|
|
|
|
--with-fesvr=$(dir $(abspath $(dir $(libfesvr))))
|
|
|
|
$(MAKE) -C $(spike_wrkdir)
|
|
|
|
$(MAKE) -C $(spike_wrkdir) install
|
|
|
|
touch -c $@
|
|
|
|
|
2016-06-17 20:38:33 +02:00
|
|
|
.PHONY: sysroot vmlinux bbl
|
|
|
|
sysroot: $(sysroot)
|
|
|
|
vmlinux: $(vmlinux)
|
|
|
|
bbl: $(bbl)
|
|
|
|
|
|
|
|
.PHONY: clean
|
|
|
|
clean:
|
2016-07-09 02:58:13 +02:00
|
|
|
rm -rf -- $(wrkdir) $(toolchain_dest)
|
2017-11-03 21:44:17 +01:00
|
|
|
|
|
|
|
.PHONY: sim
|
|
|
|
sim: $(spike) $(bbl)
|
2017-11-15 17:08:49 +01:00
|
|
|
$(spike) --isa=$(ISA) -p4 $(bbl)
|