-
Notifications
You must be signed in to change notification settings - Fork 9
/
Makefile
118 lines (85 loc) · 3.52 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#--------------------------------------------------------------------
# Build tools
#--------------------------------------------------------------------
RISCV_PREFIX=riscv64-unknown-elf-
CC = $(RISCV_PREFIX)gcc
LD = $(RISCV_PREFIX)ld
RISCV_COPY = $(RISCV_PREFIX)objcopy
RISCV_DUMP = $(RISCV_PREFIX)objdump
RISCV_COPY_FLAGS = --set-section-flags .bss=alloc,contents --set-section-flags .sbss=alloc,contents -O binary
#--------------------------------------------------------------------
# BBL variables
#--------------------------------------------------------------------
BBL_REPO_PATH = $(abspath .)
BBL_BUILD_PATH = ./build
BBL_BUILD_MAKEFILE = $(BBL_BUILD_PATH)/Makefile
BBL_ELF_BUILD = $(BBL_BUILD_PATH)/bbl
BBL_BIN = $(BBL_BUILD_PATH)/bbl.bin
BBL_PAYLOAD = $(LINUX_ELF)
#BBL_PAYLOAD = dummy_payload
BBL_CONFIG = --host=riscv64-unknown-elf --with-payload=$(BBL_PAYLOAD) \
--with-arch=rv64imac --enable-logo #--enable-print-device-tree
DTB = $(BBL_BUILD_PATH)/system.dtb
DTS = dts/system.dts
ifeq ($(MAKECMDGOALS),qemu)
BBL_ENV = CFLAGS=-D__QEMU__
endif
#--------------------------------------------------------------------
# Linux variables
#--------------------------------------------------------------------
LINUX_REPO_PATH = $(abspath ../riscv-linux)
LINUX_ELF = $(LINUX_REPO_PATH)/vmlinux
ROOTFS_PATH = $(abspath ../riscv-rootfs)
RFS_ENV = RISCV_ROOTFS_HOME=$(ROOTFS_PATH)
#--------------------------------------------------------------------
# BBL rules
#--------------------------------------------------------------------
bbl: $(BBL_BIN)
$(BBL_BIN): $(BBL_ELF_BUILD)
$(RISCV_COPY) $(RISCV_COPY_FLAGS) $< $@
$(RISCV_DUMP) -d $< > $<.txt
$(BBL_BUILD_MAKEFILE):
mkdir -p $(@D)
cd $(@D) && $(BBL_REPO_PATH)/configure $(BBL_CONFIG)
$(DTB): $(DTS)
mkdir -p $(@D)
dtc -O dtb -I dts -o $@ $<
dummy_payload:
$(BBL_ELF_BUILD): $(BBL_PAYLOAD) $(DTB) $(BBL_BUILD_MAKEFILE)
$(BBL_ENV) $(MAKE) -C $(BBL_BUILD_PATH)
bbl-clean:
-rm -rf build
.PHONY: bbl bbl-clean dummy_payload $(BBL_ELF_BUILD)
#--------------------------------------------------------------------
# Linux rules
#--------------------------------------------------------------------
$(LINUX_REPO_PATH):
mkdir -p $@
@/bin/echo -e "\033[1;31mBy default, a shallow clone with only 1 commit history is performed, since the commit history is very large.\nThis is enough for building the project.\nTo fetch full history, run 'git fetch --unshallow' under $(LINUX_REPO_PATH).\033[0m"
git clone --depth 1 -b noop https://github.com/LvNA-system/riscv-linux.git $@
$(RFS_ENV) $(MAKE) -C $@ ARCH=riscv emu_defconfig
$(ROOTFS_PATH):
mkdir -p $@
git clone https://github.com/LvNA-system/riscv-rootfs.git $@
linux: $(LINUX_ELF)
$(LINUX_ELF): | $(LINUX_REPO_PATH) $(ROOTFS_PATH)
$(RFS_ENV) $(MAKE) -C $(ROOTFS_PATH)
$(RFS_ENV) $(MAKE) -C $(@D) CROSS_COMPILE=riscv64-unknown-linux-gnu- ARCH=riscv vmlinux
$(RISCV_DUMP) -d $(LINUX_ELF) > $(BBL_BUILD_PATH)/vmlinux.txt
linux-clean:
-rm $(LINUX_ELF)
-$(RFS_ENV) $(MAKE) clean -C $(LINUX_REPO_PATH)
.PHONY: linux linux-clean $(LINUX_ELF)
#--------------------------------------------------------------------
# Top-level rules
#--------------------------------------------------------------------
default: bbl
nemu: bbl
$(MAKE) -C $(NEMU_HOME) ISA=riscv64 run ARGS="-b $(abspath $(BBL_BIN))"
nutshell: bbl
$(MAKE) -C $(NUTSHELL_HOME) emu IMAGE="$(abspath $(BBL_BIN))"
qemu: bbl
qemu-system-riscv64 -nographic -kernel $(BBL_ELF_BUILD) -machine virt
clean: bbl-clean #linux-clean
# -$(RFS_ENV) $(MAKE) -C $(ROOTFS_PATH) clean
.PHONY: default run clean