2
2
# #
3
3
# # Copyright (c) 2018-2021 Andre Richter <[email protected] >
4
4
5
- include ../utils /color.mk.in
5
+ include ../common /color.mk.in
6
6
7
- # Default to the RPi3
7
+ # #--------------------------------------------------------------------------------------------------
8
+ # # Optional, user-provided configuration values
9
+ # #--------------------------------------------------------------------------------------------------
10
+
11
+ # Default to the RPi3.
8
12
BSP ?= rpi3
9
13
10
- # BSP-specific arguments
14
+
15
+
16
+ # #--------------------------------------------------------------------------------------------------
17
+ # # Hardcoded configuration values
18
+ # #--------------------------------------------------------------------------------------------------
19
+
20
+ # BSP-specific arguments.
11
21
ifeq ($(BSP ) ,rpi3)
12
22
TARGET = aarch64-unknown-none-softfloat
13
23
KERNEL_BIN = kernel8.img
@@ -32,11 +42,18 @@ else ifeq ($(BSP),rpi4)
32
42
RUSTC_MISC_ARGS = -C target-cpu=cortex-a72
33
43
endif
34
44
35
- # Export for build.rs
45
+ QEMU_MISSING_STRING = "This board is not yet supported for QEMU."
46
+
47
+ # Export for build.rs.
36
48
export LINKER_FILE
37
49
38
- QEMU_MISSING_STRING = "This board is not yet supported for QEMU."
50
+ KERNEL_ELF = target/$(TARGET ) /release/kernel
51
+
39
52
53
+
54
+ # #--------------------------------------------------------------------------------------------------
55
+ # # Command building blocks
56
+ # #--------------------------------------------------------------------------------------------------
40
57
RUSTFLAGS = -C link-arg=-T$(LINKER_FILE ) $(RUSTC_MISC_ARGS )
41
58
RUSTFLAGS_PEDANTIC = $(RUSTFLAGS ) -D warnings -D missing_docs
42
59
@@ -53,51 +70,84 @@ OBJCOPY_CMD = rust-objcopy \
53
70
--strip-all \
54
71
-O binary
55
72
56
- KERNEL_ELF = target/ $( TARGET ) /release/kernel
73
+ EXEC_QEMU = $( QEMU_BINARY ) -M $( QEMU_MACHINE_TYPE )
57
74
58
- DOCKER_IMAGE = rustembedded/osdev-utils
59
- DOCKER_CMD = docker run --rm -v $(shell pwd) :/work/tutorial -w /work/tutorial
60
- DOCKER_CMD_INTERACT = $(DOCKER_CMD ) -i -t
75
+ # #------------------------------------------------------------------------------
76
+ # # Dockerization
77
+ # #------------------------------------------------------------------------------
78
+ DOCKER_IMAGE = rustembedded/osdev-utils
79
+ DOCKER_CMD = docker run -t --rm -v $(shell pwd) :/work/tutorial -w /work/tutorial
80
+ DOCKER_CMD_INTERACT = $(DOCKER_CMD ) -i
61
81
62
82
DOCKER_QEMU = $(DOCKER_CMD_INTERACT ) $(DOCKER_IMAGE )
63
83
DOCKER_TOOLS = $(DOCKER_CMD ) $(DOCKER_IMAGE )
64
84
65
- EXEC_QEMU = $(QEMU_BINARY ) -M $(QEMU_MACHINE_TYPE )
66
85
86
+
87
+ # #--------------------------------------------------------------------------------------------------
88
+ # # Targets
89
+ # #--------------------------------------------------------------------------------------------------
67
90
.PHONY : all $(KERNEL_ELF ) $(KERNEL_BIN ) doc qemu clippy clean readelf objdump nm check
68
91
69
92
all : $(KERNEL_BIN )
70
93
94
+ # #------------------------------------------------------------------------------
95
+ # # Build the kernel ELF
96
+ # #------------------------------------------------------------------------------
71
97
$(KERNEL_ELF ) :
72
98
$(call colorecho, "\nCompiling kernel - $(BSP ) ")
73
99
@RUSTFLAGS=" $( RUSTFLAGS_PEDANTIC) " $(RUSTC_CMD )
74
100
101
+ # #------------------------------------------------------------------------------
102
+ # # Build the stripped kernel binary
103
+ # #------------------------------------------------------------------------------
75
104
$(KERNEL_BIN ) : $(KERNEL_ELF )
76
105
@$(OBJCOPY_CMD ) $(KERNEL_ELF ) $(KERNEL_BIN )
77
106
107
+ # #------------------------------------------------------------------------------
108
+ # # Build the documentation
109
+ # #------------------------------------------------------------------------------
78
110
doc :
79
111
$(call colorecho, "\nGenerating docs")
80
112
@$(DOC_CMD ) --document-private-items --open
81
113
82
- ifeq ($(QEMU_MACHINE_TYPE ) ,)
114
+ # #------------------------------------------------------------------------------
115
+ # # Run the kernel in QEMU
116
+ # #------------------------------------------------------------------------------
117
+ ifeq ($(QEMU_MACHINE_TYPE ) ,) # QEMU is not supported for the board.
118
+
83
119
qemu :
84
120
$(call colorecho, "\n$(QEMU_MISSING_STRING ) ")
85
- else
121
+
122
+ else # QEMU is supported.
123
+
86
124
qemu : $(KERNEL_BIN )
87
125
$(call colorecho, "\nLaunching QEMU")
88
126
@$(DOCKER_QEMU ) $(EXEC_QEMU ) $(QEMU_RELEASE_ARGS ) -kernel $(KERNEL_BIN )
89
127
endif
90
128
129
+ # #------------------------------------------------------------------------------
130
+ # # Run clippy
131
+ # #------------------------------------------------------------------------------
91
132
clippy :
92
133
@RUSTFLAGS=" $( RUSTFLAGS_PEDANTIC) " $(CLIPPY_CMD )
93
134
135
+ # #------------------------------------------------------------------------------
136
+ # # Clean
137
+ # #------------------------------------------------------------------------------
94
138
clean :
95
139
rm -rf target $(KERNEL_BIN )
96
140
141
+ # #------------------------------------------------------------------------------
142
+ # # Run readelf
143
+ # #------------------------------------------------------------------------------
97
144
readelf : $(KERNEL_ELF )
98
145
$(call colorecho, "\nLaunching readelf")
99
146
@$(DOCKER_TOOLS ) $(READELF_BINARY ) --headers $(KERNEL_ELF )
100
147
148
+ # #------------------------------------------------------------------------------
149
+ # # Run objdump
150
+ # #------------------------------------------------------------------------------
101
151
objdump : $(KERNEL_ELF )
102
152
$(call colorecho, "\nLaunching objdump")
103
153
@$(DOCKER_TOOLS ) $(OBJDUMP_BINARY ) --disassemble --demangle \
@@ -106,10 +156,15 @@ objdump: $(KERNEL_ELF)
106
156
--section .got \
107
157
$(KERNEL_ELF) | rustfilt
108
158
159
+ # #------------------------------------------------------------------------------
160
+ # # Run nm
161
+ # #------------------------------------------------------------------------------
109
162
nm : $(KERNEL_ELF )
110
163
$(call colorecho, "\nLaunching nm")
111
164
@$(DOCKER_TOOLS ) $(NM_BINARY ) --demangle --print-size $(KERNEL_ELF ) | sort | rustfilt
112
165
113
- # For rust-analyzer
166
+ # #------------------------------------------------------------------------------
167
+ # # Helper target for rust-analyzer
168
+ # #------------------------------------------------------------------------------
114
169
check :
115
170
@RUSTFLAGS=" $( RUSTFLAGS) " $(CHECK_CMD ) --message-format=json
0 commit comments