-
Notifications
You must be signed in to change notification settings - Fork 48
/
Makefile
115 lines (94 loc) · 2.61 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
include mk/common.mk
CC ?= gcc
CFLAGS := -O2 -g -Wall -Wextra
CFLAGS += -include common.h
# clock frequency
CLOCK_FREQ ?= 65000000
DT_CFLAGS := -D CLOCK_FREQ=$(CLOCK_FREQ)
CFLAGS += $(DT_CFLAGS)
OBJS_EXTRA :=
# command line option
OPTS :=
# virtio-blk
ENABLE_VIRTIOBLK ?= 1
$(call set-feature, VIRTIOBLK)
DISKIMG_FILE :=
MKFS_EXT4 ?= mkfs.ext4
ifeq ($(call has, VIRTIOBLK), 1)
OBJS_EXTRA += virtio-blk.o
DISKIMG_FILE := ext4.img
OPTS += -d $(DISKIMG_FILE)
MKFS_EXT4 := $(shell which $(MKFS_EXT4))
ifndef MKFS_EXT4
MKFS_EXT4 := $(shell which $$(brew --prefix e2fsprogs)/sbin/mkfs.ext4)
endif
ifndef MKFS_EXT4
$(error "No mkfs.ext4 found.")
endif
endif
NETDEV ?= tap
# virtio-net
ENABLE_VIRTIONET ?= 1
ifneq ($(UNAME_S),Linux)
ENABLE_VIRTIONET := 0
endif
$(call set-feature, VIRTIONET)
ifeq ($(call has, VIRTIONET), 1)
OBJS_EXTRA += virtio-net.o
OBJS_EXTRA += netdev.o
endif
BIN = semu
all: $(BIN) minimal.dtb
OBJS := \
riscv.o \
ram.o \
utils.o \
plic.o \
uart.o \
main.o \
aclint.o \
$(OBJS_EXTRA)
deps := $(OBJS:%.o=.%.o.d)
$(BIN): $(OBJS)
$(VECHO) " LD\t$@\n"
$(Q)$(CC) -o $@ $^ $(LDFLAGS)
%.o: %.c
$(VECHO) " CC\t$@\n"
$(Q)$(CC) -o $@ $(CFLAGS) -c -MMD -MF [email protected] $<
DTC ?= dtc
# GNU Make treats the space character as a separator. The only way to handle
# filtering a pattern with space characters in a Makefile is by replacing spaces
# with another character that is guaranteed not to appear in the variable value.
# For instance, one can choose a character like '^' that is known not to be
# present in the variable value.
# Reference: https://stackoverflow.com/questions/40886386
E :=
S := $E $E
SMP ?= 1
.PHONY: riscv-harts.dtsi
riscv-harts.dtsi:
$(Q)python3 scripts/gen-hart-dts.py $@ $(SMP) $(CLOCK_FREQ)
minimal.dtb: minimal.dts riscv-harts.dtsi
$(VECHO) " DTC\t$@\n"
$(Q)$(CC) -nostdinc -E -P -x assembler-with-cpp -undef \
$(DT_CFLAGS) \
$(subst ^,$S,$(filter -D^SEMU_FEATURE_%, $(subst -D$(S)SEMU_FEATURE,-D^SEMU_FEATURE,$(CFLAGS)))) $< \
| $(DTC) - > $@
# Rules for downloading prebuilt Linux kernel image
include mk/external.mk
ext4.img:
$(Q)dd if=/dev/zero of=$@ bs=4k count=600
$(Q)$(MKFS_EXT4) -F $@
check: $(BIN) minimal.dtb $(KERNEL_DATA) $(INITRD_DATA) $(DISKIMG_FILE)
@$(call notice, Ready to launch Linux kernel. Please be patient.)
$(Q)./$(BIN) -k $(KERNEL_DATA) -c $(SMP) -b minimal.dtb -i $(INITRD_DATA) -n $(NETDEV) $(OPTS)
build-image:
scripts/build-image.sh
clean:
$(Q)$(RM) $(BIN) $(OBJS) $(deps)
distclean: clean
$(Q)$(RM) riscv-harts.dtsi
$(Q)$(RM) minimal.dtb
$(Q)$(RM) Image rootfs.cpio
$(Q)$(RM) ext4.img
-include $(deps)