forked from GrassLab/osc2021
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
134 lines (109 loc) · 3.44 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
.PHONY: shell clean export better
kernel_impl = impl-c
# kernel_impl = impl-rs
OPT_BUILD_BOOTLOADER = 0
bootloader_impl = bootloader
INIT_RAM_FS = res/initramfs.cpio
INIT_RAM_FS_SRC = res/rootfs
KERNEL_IMG = res/kernel/kernel8.img
BOOT_LOADER_IMG = res/bootloader/kernel8.img
QEMU = qemu-system-aarch64
CROSS_GDB = aarch64-linux-gdb
CROSS = ./dockcross-linux-aarch64
# define standard colors
RED := $(shell tput setaf 1)
GREEN := $(shell tput setaf 2)
YELLOW := $(shell tput setaf 3)
WHITE := $(shell tput setaf 7)
RESET := $(shell tput sgr0)
# == Commands
all: $(KERNEL_IMG) $(BOOT_LOADER_IMG) user_programs $(INIT_RAM_FS)
@echo "${YELLOW} 📦 Build Finished${RESET}"
shell:
@echo "${YELLOW} 🤖 Spawn shell inside docker ${RESET}"
$(CROSS) bash
clean:
@python3 scripts/builder.py $(kernel_impl) clean
ifeq ($(OPT_BUILD_BOOTLOADER), 1)
@python3 scripts/builder.py $(bootloader_impl) clean
endif
@python3 scripts/builder.py user_programs clean
$(RM) $(INIT_RAM_FS)
$(RM) -rf scripts/__pycache__
@echo "${YELLOW} 🚚 Finish cleanup${RESET}"
export:
poetry export -f requirements.txt --output requirements.txt
# LINTER_TARGET = scripts
LINTER_TARGET = algo
better:
poetry run autoflake --in-place --remove-unused-variables --recursive $(LINTER_TARGET)
poetry run isort $(LINTER_TARGET)
poetry run black $(LINTER_TARGET)
poetry run pylama $(LINTER_TARGET) --ignore E501
.PHONY: run-stdio
run: all
@echo "${YELLOW} 🚧 Start kernel(stdio)${RESET}"
@echo "${YELLOW} Use ${RED}ctrl-c${YELLOW} to quit session${RESET}"
@$(RUN_STDIO_KERNEL) $(KERNEL_IMG)
.PHONY: run-tty
tty: all
@echo "${YELLOW} 🚧 Start kernel(tty)${RESET}"
@echo "${YELLOW} Use ${RED}ctrl-c${YELLOW} to quit session${RESET}"
@$(RUN_TTY_KERNEL) $(KERNEL_IMG)
.PHONY: debug
debug: all
@echo "${YELLOW} 🐛 Start debugging kernel${RESET}"
@echo "${YELLOW}Open another terminal and use ${GREEN}make gdb${YELLOW} to connect to host${RESET}"
@$(DEBUG_KERNEL) $(KERNEL_IMG)
.PHONY: gdb
gdb: all
@echo "${YELLOW} 🕵️♀️ Using ${GREEN}${CROSS_GDB}${RESET}"
$(CROSS_GDB) --init-command $(kernel_impl)/gdbinit
# == Resources
$(BOOT_LOADER_IMG): $(shell find $(bootloader_impl))
ifeq ($(OPT_BUILD_BOOTLOADER), 1)
@python3 scripts/builder.py $(bootloader_impl) build
endif
$(KERNEL_IMG): $(shell find $(kernel_impl))
@python3 scripts/builder.py $(kernel_impl) build
$(INIT_RAM_FS): $(shell find $(INIT_RAM_FS_SRC))
@echo "${GREEN} 📦 Generate ramfs file from ${YELLOW}$(INIT_RAM_FS_SRC)${GREEN} to ${YELLOW}${INIT_RAM_FS}${RESET}"
cd $(INIT_RAM_FS_SRC) && find . | cpio -o -H newc> ../$(@F)
# always build
.PHONY: user_programs
user_programs:
@python3 scripts/builder.py user_programs build
# ==
# (Not called directly)
# Start qemu
define _run_qemu_base
$(QEMU) -M raspi3 \
-drive if=sd,file=./res/sdcard/sfn_nctuos.img,format=raw \
-initrd $(INIT_RAM_FS) \
-display none
endef
# (Not called directly)
# Start qemu with creating multiplexed tty port on host
define _run_qemu_mux_base
$(_run_qemu_base) \
-chardev pty,signal=on,id=char_mux \
-serial null -serial chardev:char_mux
endef
# Start qemu with stdio attached
define RUN_STDIO_KERNEL
$(_run_qemu_base) \
-serial null -serial stdio \
-kernel
endef
# Start qemu with tty opend on host
define RUN_TTY_KERNEL
$(_run_qemu_mux_base) \
-kernel
endef
# Start qemu with tty opend on host, waiting for gdb to connect
define DEBUG_KERNEL
$(_run_qemu_base) \
-serial null -serial stdio \
-s -S \
-kernel
endef