Non-phony kernel targets

Saves time on various targets that depend on the kernel ELF because calling
cargo can be completely skipped if nothing changed.
pull/154/head
Andre Richter 2 years ago
parent cb4ae40ac2
commit b7cecafa1e
No known key found for this signature in database
GPG Key ID: 2116C1AB102F615E

@ -2,7 +2,7 @@
## ##
## Copyright (c) 2018-2022 Andre Richter <andre.o.richter@gmail.com> ## Copyright (c) 2018-2022 Andre Richter <andre.o.richter@gmail.com>
include ../common/color.mk include ../common/format.mk
include ../common/docker.mk include ../common/docker.mk
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
@ -49,10 +49,16 @@ export LD_SCRIPT_PATH
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
## Generic configuration values ## Targets and Prerequisites
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
KERNEL_LINKER_SCRIPT = link.ld KERNEL_LINKER_SCRIPT = link.ld
KERNEL_ELF = target/$(TARGET)/release/kernel
LAST_BUILD_CONFIG = target/$(BSP).build_config
KERNEL_ELF = target/$(TARGET)/release/kernel
# This parses cargo's dep-info file.
# https://doc.rust-lang.org/cargo/guide/build-cache.html#dep-info-files
KERNEL_ELF_DEPS = $(filter-out %: ,$(file < $(KERNEL_ELF_RAW).d)) $(LAST_BUILD_CONFIG)
@ -97,28 +103,41 @@ DOCKER_TOOLS = $(DOCKER_CMD) $(DOCKER_IMAGE)
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
## Targets ## Targets
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
.PHONY: all $(KERNEL_ELF) $(KERNEL_BIN) doc qemu clippy clean readelf objdump nm check .PHONY: all doc qemu clippy clean readelf objdump nm check
all: $(KERNEL_BIN) all: $(KERNEL_BIN)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the kernel ELF ## Save the configuration as a file, so make understands if it changed.
##------------------------------------------------------------------------------
$(LAST_BUILD_CONFIG):
@rm -f target/*.build_config
@mkdir -p target
@touch $(LAST_BUILD_CONFIG)
##------------------------------------------------------------------------------
## Compile the kernel ELF
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
$(KERNEL_ELF): $(KERNEL_ELF): $(KERNEL_ELF_DEPS)
$(call colorecho, "\nCompiling kernel - $(BSP)") $(call color_header, "Compiling kernel ELF - $(BSP)")
@RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD) @RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the stripped kernel binary ## Generate the stripped kernel binary
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
$(KERNEL_BIN): $(KERNEL_ELF) $(KERNEL_BIN): $(KERNEL_ELF)
$(call color_header, "Generating stripped binary")
@$(OBJCOPY_CMD) $(KERNEL_ELF) $(KERNEL_BIN) @$(OBJCOPY_CMD) $(KERNEL_ELF) $(KERNEL_BIN)
$(call color_progress_prefix, "Name")
@echo $(KERNEL_BIN)
$(call color_progress_prefix, "Size")
@printf '%s KiB\n' `du -k $(KERNEL_BIN) | cut -f1`
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the documentation ## Generate the documentation
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
doc: doc:
$(call colorecho, "\nGenerating docs") $(call color_header, "Generating docs")
@$(DOC_CMD) --document-private-items --open @$(DOC_CMD) --document-private-items --open
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
@ -127,12 +146,12 @@ doc:
ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board. ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board.
qemu: qemu:
$(call colorecho, "\n$(QEMU_MISSING_STRING)") $(call color_header, "$(QEMU_MISSING_STRING)")
else # QEMU is supported. else # QEMU is supported.
qemu: $(KERNEL_BIN) qemu: $(KERNEL_BIN)
$(call colorecho, "\nLaunching QEMU") $(call color_header, "Launching QEMU")
@$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN) @$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN)
endif endif
@ -152,14 +171,14 @@ clean:
## Run readelf ## Run readelf
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
readelf: $(KERNEL_ELF) readelf: $(KERNEL_ELF)
$(call colorecho, "\nLaunching readelf") $(call color_header, "Launching readelf")
@$(DOCKER_TOOLS) $(READELF_BINARY) --headers $(KERNEL_ELF) @$(DOCKER_TOOLS) $(READELF_BINARY) --headers $(KERNEL_ELF)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Run objdump ## Run objdump
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
objdump: $(KERNEL_ELF) objdump: $(KERNEL_ELF)
$(call colorecho, "\nLaunching objdump") $(call color_header, "Launching objdump")
@$(DOCKER_TOOLS) $(OBJDUMP_BINARY) --disassemble --demangle \ @$(DOCKER_TOOLS) $(OBJDUMP_BINARY) --disassemble --demangle \
--section .text \ --section .text \
$(KERNEL_ELF) | rustfilt $(KERNEL_ELF) | rustfilt
@ -168,7 +187,7 @@ objdump: $(KERNEL_ELF)
## Run nm ## Run nm
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
nm: $(KERNEL_ELF) nm: $(KERNEL_ELF)
$(call colorecho, "\nLaunching nm") $(call color_header, "Launching nm")
@$(DOCKER_TOOLS) $(NM_BINARY) --demangle --print-size $(KERNEL_ELF) | sort | rustfilt @$(DOCKER_TOOLS) $(NM_BINARY) --demangle --print-size $(KERNEL_ELF) | sort | rustfilt
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------

@ -2,7 +2,7 @@
## ##
## Copyright (c) 2018-2022 Andre Richter <andre.o.richter@gmail.com> ## Copyright (c) 2018-2022 Andre Richter <andre.o.richter@gmail.com>
include ../common/color.mk include ../common/format.mk
include ../common/docker.mk include ../common/docker.mk
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
@ -49,10 +49,16 @@ export LD_SCRIPT_PATH
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
## Generic configuration values ## Targets and Prerequisites
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
KERNEL_LINKER_SCRIPT = link.ld KERNEL_LINKER_SCRIPT = link.ld
KERNEL_ELF = target/$(TARGET)/release/kernel
LAST_BUILD_CONFIG = target/$(BSP).build_config
KERNEL_ELF = target/$(TARGET)/release/kernel
# This parses cargo's dep-info file.
# https://doc.rust-lang.org/cargo/guide/build-cache.html#dep-info-files
KERNEL_ELF_DEPS = $(filter-out %: ,$(file < $(KERNEL_ELF_RAW).d)) $(LAST_BUILD_CONFIG)
@ -97,28 +103,41 @@ DOCKER_TOOLS = $(DOCKER_CMD) $(DOCKER_IMAGE)
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
## Targets ## Targets
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
.PHONY: all $(KERNEL_ELF) $(KERNEL_BIN) doc qemu clippy clean readelf objdump nm check .PHONY: all doc qemu clippy clean readelf objdump nm check
all: $(KERNEL_BIN) all: $(KERNEL_BIN)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the kernel ELF ## Save the configuration as a file, so make understands if it changed.
##------------------------------------------------------------------------------
$(LAST_BUILD_CONFIG):
@rm -f target/*.build_config
@mkdir -p target
@touch $(LAST_BUILD_CONFIG)
##------------------------------------------------------------------------------
## Compile the kernel ELF
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
$(KERNEL_ELF): $(KERNEL_ELF): $(KERNEL_ELF_DEPS)
$(call colorecho, "\nCompiling kernel - $(BSP)") $(call color_header, "Compiling kernel ELF - $(BSP)")
@RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD) @RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the stripped kernel binary ## Generate the stripped kernel binary
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
$(KERNEL_BIN): $(KERNEL_ELF) $(KERNEL_BIN): $(KERNEL_ELF)
$(call color_header, "Generating stripped binary")
@$(OBJCOPY_CMD) $(KERNEL_ELF) $(KERNEL_BIN) @$(OBJCOPY_CMD) $(KERNEL_ELF) $(KERNEL_BIN)
$(call color_progress_prefix, "Name")
@echo $(KERNEL_BIN)
$(call color_progress_prefix, "Size")
@printf '%s KiB\n' `du -k $(KERNEL_BIN) | cut -f1`
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the documentation ## Generate the documentation
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
doc: doc:
$(call colorecho, "\nGenerating docs") $(call color_header, "Generating docs")
@$(DOC_CMD) --document-private-items --open @$(DOC_CMD) --document-private-items --open
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
@ -127,12 +146,12 @@ doc:
ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board. ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board.
qemu: qemu:
$(call colorecho, "\n$(QEMU_MISSING_STRING)") $(call color_header, "$(QEMU_MISSING_STRING)")
else # QEMU is supported. else # QEMU is supported.
qemu: $(KERNEL_BIN) qemu: $(KERNEL_BIN)
$(call colorecho, "\nLaunching QEMU") $(call color_header, "Launching QEMU")
@$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN) @$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN)
endif endif
@ -152,14 +171,14 @@ clean:
## Run readelf ## Run readelf
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
readelf: $(KERNEL_ELF) readelf: $(KERNEL_ELF)
$(call colorecho, "\nLaunching readelf") $(call color_header, "Launching readelf")
@$(DOCKER_TOOLS) $(READELF_BINARY) --headers $(KERNEL_ELF) @$(DOCKER_TOOLS) $(READELF_BINARY) --headers $(KERNEL_ELF)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Run objdump ## Run objdump
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
objdump: $(KERNEL_ELF) objdump: $(KERNEL_ELF)
$(call colorecho, "\nLaunching objdump") $(call color_header, "Launching objdump")
@$(DOCKER_TOOLS) $(OBJDUMP_BINARY) --disassemble --demangle \ @$(DOCKER_TOOLS) $(OBJDUMP_BINARY) --disassemble --demangle \
--section .text \ --section .text \
--section .rodata \ --section .rodata \
@ -170,7 +189,7 @@ objdump: $(KERNEL_ELF)
## Run nm ## Run nm
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
nm: $(KERNEL_ELF) nm: $(KERNEL_ELF)
$(call colorecho, "\nLaunching nm") $(call color_header, "Launching nm")
@$(DOCKER_TOOLS) $(NM_BINARY) --demangle --print-size $(KERNEL_ELF) | sort | rustfilt @$(DOCKER_TOOLS) $(NM_BINARY) --demangle --print-size $(KERNEL_ELF) | sort | rustfilt
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------

@ -52,8 +52,8 @@ diff -uNr 01_wait_forever/Cargo.toml 02_runtime_init/Cargo.toml
diff -uNr 01_wait_forever/Makefile 02_runtime_init/Makefile diff -uNr 01_wait_forever/Makefile 02_runtime_init/Makefile
--- 01_wait_forever/Makefile --- 01_wait_forever/Makefile
+++ 02_runtime_init/Makefile +++ 02_runtime_init/Makefile
@@ -162,6 +162,8 @@ @@ -181,6 +181,8 @@
$(call colorecho, "\nLaunching objdump") $(call color_header, "Launching objdump")
@$(DOCKER_TOOLS) $(OBJDUMP_BINARY) --disassemble --demangle \ @$(DOCKER_TOOLS) $(OBJDUMP_BINARY) --disassemble --demangle \
--section .text \ --section .text \
+ --section .rodata \ + --section .rodata \

@ -2,7 +2,7 @@
## ##
## Copyright (c) 2018-2022 Andre Richter <andre.o.richter@gmail.com> ## Copyright (c) 2018-2022 Andre Richter <andre.o.richter@gmail.com>
include ../common/color.mk include ../common/format.mk
include ../common/docker.mk include ../common/docker.mk
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
@ -49,10 +49,16 @@ export LD_SCRIPT_PATH
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
## Generic configuration values ## Targets and Prerequisites
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
KERNEL_LINKER_SCRIPT = link.ld KERNEL_LINKER_SCRIPT = link.ld
KERNEL_ELF = target/$(TARGET)/release/kernel
LAST_BUILD_CONFIG = target/$(BSP).build_config
KERNEL_ELF = target/$(TARGET)/release/kernel
# This parses cargo's dep-info file.
# https://doc.rust-lang.org/cargo/guide/build-cache.html#dep-info-files
KERNEL_ELF_DEPS = $(filter-out %: ,$(file < $(KERNEL_ELF_RAW).d)) $(LAST_BUILD_CONFIG)
@ -100,28 +106,41 @@ DOCKER_TEST = $(DOCKER_CMD) $(DOCKER_ARG_DIR_COMMON) $(DOCKER_IMAGE)
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
## Targets ## Targets
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
.PHONY: all $(KERNEL_ELF) $(KERNEL_BIN) doc qemu clippy clean readelf objdump nm check .PHONY: all doc qemu clippy clean readelf objdump nm check
all: $(KERNEL_BIN) all: $(KERNEL_BIN)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the kernel ELF ## Save the configuration as a file, so make understands if it changed.
##------------------------------------------------------------------------------
$(LAST_BUILD_CONFIG):
@rm -f target/*.build_config
@mkdir -p target
@touch $(LAST_BUILD_CONFIG)
##------------------------------------------------------------------------------
## Compile the kernel ELF
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
$(KERNEL_ELF): $(KERNEL_ELF): $(KERNEL_ELF_DEPS)
$(call colorecho, "\nCompiling kernel - $(BSP)") $(call color_header, "Compiling kernel ELF - $(BSP)")
@RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD) @RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the stripped kernel binary ## Generate the stripped kernel binary
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
$(KERNEL_BIN): $(KERNEL_ELF) $(KERNEL_BIN): $(KERNEL_ELF)
$(call color_header, "Generating stripped binary")
@$(OBJCOPY_CMD) $(KERNEL_ELF) $(KERNEL_BIN) @$(OBJCOPY_CMD) $(KERNEL_ELF) $(KERNEL_BIN)
$(call color_progress_prefix, "Name")
@echo $(KERNEL_BIN)
$(call color_progress_prefix, "Size")
@printf '%s KiB\n' `du -k $(KERNEL_BIN) | cut -f1`
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the documentation ## Generate the documentation
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
doc: doc:
$(call colorecho, "\nGenerating docs") $(call color_header, "Generating docs")
@$(DOC_CMD) --document-private-items --open @$(DOC_CMD) --document-private-items --open
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
@ -130,12 +149,12 @@ doc:
ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board. ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board.
qemu: qemu:
$(call colorecho, "\n$(QEMU_MISSING_STRING)") $(call color_header, "$(QEMU_MISSING_STRING)")
else # QEMU is supported. else # QEMU is supported.
qemu: $(KERNEL_BIN) qemu: $(KERNEL_BIN)
$(call colorecho, "\nLaunching QEMU") $(call color_header, "Launching QEMU")
@$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN) @$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN)
endif endif
@ -155,14 +174,14 @@ clean:
## Run readelf ## Run readelf
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
readelf: $(KERNEL_ELF) readelf: $(KERNEL_ELF)
$(call colorecho, "\nLaunching readelf") $(call color_header, "Launching readelf")
@$(DOCKER_TOOLS) $(READELF_BINARY) --headers $(KERNEL_ELF) @$(DOCKER_TOOLS) $(READELF_BINARY) --headers $(KERNEL_ELF)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Run objdump ## Run objdump
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
objdump: $(KERNEL_ELF) objdump: $(KERNEL_ELF)
$(call colorecho, "\nLaunching objdump") $(call color_header, "Launching objdump")
@$(DOCKER_TOOLS) $(OBJDUMP_BINARY) --disassemble --demangle \ @$(DOCKER_TOOLS) $(OBJDUMP_BINARY) --disassemble --demangle \
--section .text \ --section .text \
--section .rodata \ --section .rodata \
@ -173,7 +192,7 @@ objdump: $(KERNEL_ELF)
## Run nm ## Run nm
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
nm: $(KERNEL_ELF) nm: $(KERNEL_ELF)
$(call colorecho, "\nLaunching nm") $(call color_header, "Launching nm")
@$(DOCKER_TOOLS) $(NM_BINARY) --demangle --print-size $(KERNEL_ELF) | sort | rustfilt @$(DOCKER_TOOLS) $(NM_BINARY) --demangle --print-size $(KERNEL_ELF) | sort | rustfilt
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
@ -191,8 +210,8 @@ check:
ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board. ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board.
test_boot test : test_boot test:
$(call colorecho, "\n$(QEMU_MISSING_STRING)") $(call color_header, "$(QEMU_MISSING_STRING)")
else # QEMU is supported. else # QEMU is supported.
@ -200,7 +219,7 @@ else # QEMU is supported.
## Run boot test ## Run boot test
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
test_boot: $(KERNEL_BIN) test_boot: $(KERNEL_BIN)
$(call colorecho, "\nBoot test - $(BSP)") $(call color_header, "Boot test - $(BSP)")
@$(DOCKER_TEST) $(EXEC_TEST_DISPATCH) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN) @$(DOCKER_TEST) $(EXEC_TEST_DISPATCH) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN)
test: test_boot test: test_boot

@ -70,7 +70,7 @@ diff -uNr 02_runtime_init/Makefile 03_hacky_hello_world/Makefile
OBJDUMP_BINARY = aarch64-none-elf-objdump OBJDUMP_BINARY = aarch64-none-elf-objdump
NM_BINARY = aarch64-none-elf-nm NM_BINARY = aarch64-none-elf-nm
READELF_BINARY = aarch64-none-elf-readelf READELF_BINARY = aarch64-none-elf-readelf
@@ -80,17 +80,20 @@ @@ -86,17 +86,20 @@
--strip-all \ --strip-all \
-O binary -O binary
@ -94,7 +94,7 @@ diff -uNr 02_runtime_init/Makefile 03_hacky_hello_world/Makefile
@@ -178,3 +181,28 @@ @@ -197,3 +200,28 @@
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
check: check:
@RUSTFLAGS="$(RUSTFLAGS)" $(CHECK_CMD) --message-format=json @RUSTFLAGS="$(RUSTFLAGS)" $(CHECK_CMD) --message-format=json
@ -108,8 +108,8 @@ diff -uNr 02_runtime_init/Makefile 03_hacky_hello_world/Makefile
+ +
+ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board. +ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board.
+ +
+test_boot test : +test_boot test:
+ $(call colorecho, "\n$(QEMU_MISSING_STRING)") + $(call color_header, "$(QEMU_MISSING_STRING)")
+ +
+else # QEMU is supported. +else # QEMU is supported.
+ +
@ -117,7 +117,7 @@ diff -uNr 02_runtime_init/Makefile 03_hacky_hello_world/Makefile
+## Run boot test +## Run boot test
+##------------------------------------------------------------------------------ +##------------------------------------------------------------------------------
+test_boot: $(KERNEL_BIN) +test_boot: $(KERNEL_BIN)
+ $(call colorecho, "\nBoot test - $(BSP)") + $(call color_header, "Boot test - $(BSP)")
+ @$(DOCKER_TEST) $(EXEC_TEST_DISPATCH) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN) + @$(DOCKER_TEST) $(EXEC_TEST_DISPATCH) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN)
+ +
+test: test_boot +test: test_boot

@ -2,7 +2,7 @@
## ##
## Copyright (c) 2018-2022 Andre Richter <andre.o.richter@gmail.com> ## Copyright (c) 2018-2022 Andre Richter <andre.o.richter@gmail.com>
include ../common/color.mk include ../common/format.mk
include ../common/docker.mk include ../common/docker.mk
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
@ -49,10 +49,16 @@ export LD_SCRIPT_PATH
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
## Generic configuration values ## Targets and Prerequisites
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
KERNEL_LINKER_SCRIPT = link.ld KERNEL_LINKER_SCRIPT = link.ld
KERNEL_ELF = target/$(TARGET)/release/kernel
LAST_BUILD_CONFIG = target/$(BSP).build_config
KERNEL_ELF = target/$(TARGET)/release/kernel
# This parses cargo's dep-info file.
# https://doc.rust-lang.org/cargo/guide/build-cache.html#dep-info-files
KERNEL_ELF_DEPS = $(filter-out %: ,$(file < $(KERNEL_ELF_RAW).d)) $(LAST_BUILD_CONFIG)
@ -100,28 +106,41 @@ DOCKER_TEST = $(DOCKER_CMD) $(DOCKER_ARG_DIR_COMMON) $(DOCKER_IMAGE)
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
## Targets ## Targets
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
.PHONY: all $(KERNEL_ELF) $(KERNEL_BIN) doc qemu clippy clean readelf objdump nm check .PHONY: all doc qemu clippy clean readelf objdump nm check
all: $(KERNEL_BIN) all: $(KERNEL_BIN)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the kernel ELF ## Save the configuration as a file, so make understands if it changed.
##------------------------------------------------------------------------------
$(LAST_BUILD_CONFIG):
@rm -f target/*.build_config
@mkdir -p target
@touch $(LAST_BUILD_CONFIG)
##------------------------------------------------------------------------------
## Compile the kernel ELF
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
$(KERNEL_ELF): $(KERNEL_ELF): $(KERNEL_ELF_DEPS)
$(call colorecho, "\nCompiling kernel - $(BSP)") $(call color_header, "Compiling kernel ELF - $(BSP)")
@RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD) @RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the stripped kernel binary ## Generate the stripped kernel binary
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
$(KERNEL_BIN): $(KERNEL_ELF) $(KERNEL_BIN): $(KERNEL_ELF)
$(call color_header, "Generating stripped binary")
@$(OBJCOPY_CMD) $(KERNEL_ELF) $(KERNEL_BIN) @$(OBJCOPY_CMD) $(KERNEL_ELF) $(KERNEL_BIN)
$(call color_progress_prefix, "Name")
@echo $(KERNEL_BIN)
$(call color_progress_prefix, "Size")
@printf '%s KiB\n' `du -k $(KERNEL_BIN) | cut -f1`
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the documentation ## Generate the documentation
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
doc: doc:
$(call colorecho, "\nGenerating docs") $(call color_header, "Generating docs")
@$(DOC_CMD) --document-private-items --open @$(DOC_CMD) --document-private-items --open
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
@ -130,12 +149,12 @@ doc:
ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board. ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board.
qemu: qemu:
$(call colorecho, "\n$(QEMU_MISSING_STRING)") $(call color_header, "$(QEMU_MISSING_STRING)")
else # QEMU is supported. else # QEMU is supported.
qemu: $(KERNEL_BIN) qemu: $(KERNEL_BIN)
$(call colorecho, "\nLaunching QEMU") $(call color_header, "Launching QEMU")
@$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN) @$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN)
endif endif
@ -155,14 +174,14 @@ clean:
## Run readelf ## Run readelf
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
readelf: $(KERNEL_ELF) readelf: $(KERNEL_ELF)
$(call colorecho, "\nLaunching readelf") $(call color_header, "Launching readelf")
@$(DOCKER_TOOLS) $(READELF_BINARY) --headers $(KERNEL_ELF) @$(DOCKER_TOOLS) $(READELF_BINARY) --headers $(KERNEL_ELF)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Run objdump ## Run objdump
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
objdump: $(KERNEL_ELF) objdump: $(KERNEL_ELF)
$(call colorecho, "\nLaunching objdump") $(call color_header, "Launching objdump")
@$(DOCKER_TOOLS) $(OBJDUMP_BINARY) --disassemble --demangle \ @$(DOCKER_TOOLS) $(OBJDUMP_BINARY) --disassemble --demangle \
--section .text \ --section .text \
--section .rodata \ --section .rodata \
@ -173,7 +192,7 @@ objdump: $(KERNEL_ELF)
## Run nm ## Run nm
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
nm: $(KERNEL_ELF) nm: $(KERNEL_ELF)
$(call colorecho, "\nLaunching nm") $(call color_header, "Launching nm")
@$(DOCKER_TOOLS) $(NM_BINARY) --demangle --print-size $(KERNEL_ELF) | sort | rustfilt @$(DOCKER_TOOLS) $(NM_BINARY) --demangle --print-size $(KERNEL_ELF) | sort | rustfilt
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
@ -191,8 +210,8 @@ check:
ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board. ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board.
test_boot test : test_boot test:
$(call colorecho, "\n$(QEMU_MISSING_STRING)") $(call color_header, "$(QEMU_MISSING_STRING)")
else # QEMU is supported. else # QEMU is supported.
@ -200,7 +219,7 @@ else # QEMU is supported.
## Run boot test ## Run boot test
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
test_boot: $(KERNEL_BIN) test_boot: $(KERNEL_BIN)
$(call colorecho, "\nBoot test - $(BSP)") $(call color_header, "Boot test - $(BSP)")
@$(DOCKER_TEST) $(EXEC_TEST_DISPATCH) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN) @$(DOCKER_TEST) $(EXEC_TEST_DISPATCH) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN)
test: test_boot test: test_boot

@ -2,7 +2,7 @@
## ##
## Copyright (c) 2018-2022 Andre Richter <andre.o.richter@gmail.com> ## Copyright (c) 2018-2022 Andre Richter <andre.o.richter@gmail.com>
include ../common/color.mk include ../common/format.mk
include ../common/docker.mk include ../common/docker.mk
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
@ -52,10 +52,16 @@ export LD_SCRIPT_PATH
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
## Generic configuration values ## Targets and Prerequisites
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
KERNEL_LINKER_SCRIPT = link.ld KERNEL_LINKER_SCRIPT = link.ld
KERNEL_ELF = target/$(TARGET)/release/kernel
LAST_BUILD_CONFIG = target/$(BSP).build_config
KERNEL_ELF = target/$(TARGET)/release/kernel
# This parses cargo's dep-info file.
# https://doc.rust-lang.org/cargo/guide/build-cache.html#dep-info-files
KERNEL_ELF_DEPS = $(filter-out %: ,$(file < $(KERNEL_ELF_RAW).d)) $(LAST_BUILD_CONFIG)
@ -112,28 +118,41 @@ endif
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
## Targets ## Targets
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
.PHONY: all $(KERNEL_ELF) $(KERNEL_BIN) doc qemu miniterm clippy clean readelf objdump nm check .PHONY: all doc qemu miniterm clippy clean readelf objdump nm check
all: $(KERNEL_BIN) all: $(KERNEL_BIN)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the kernel ELF ## Save the configuration as a file, so make understands if it changed.
##------------------------------------------------------------------------------
$(LAST_BUILD_CONFIG):
@rm -f target/*.build_config
@mkdir -p target
@touch $(LAST_BUILD_CONFIG)
##------------------------------------------------------------------------------
## Compile the kernel ELF
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
$(KERNEL_ELF): $(KERNEL_ELF): $(KERNEL_ELF_DEPS)
$(call colorecho, "\nCompiling kernel - $(BSP)") $(call color_header, "Compiling kernel ELF - $(BSP)")
@RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD) @RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the stripped kernel binary ## Generate the stripped kernel binary
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
$(KERNEL_BIN): $(KERNEL_ELF) $(KERNEL_BIN): $(KERNEL_ELF)
$(call color_header, "Generating stripped binary")
@$(OBJCOPY_CMD) $(KERNEL_ELF) $(KERNEL_BIN) @$(OBJCOPY_CMD) $(KERNEL_ELF) $(KERNEL_BIN)
$(call color_progress_prefix, "Name")
@echo $(KERNEL_BIN)
$(call color_progress_prefix, "Size")
@printf '%s KiB\n' `du -k $(KERNEL_BIN) | cut -f1`
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the documentation ## Generate the documentation
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
doc: doc:
$(call colorecho, "\nGenerating docs") $(call color_header, "Generating docs")
@$(DOC_CMD) --document-private-items --open @$(DOC_CMD) --document-private-items --open
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
@ -142,13 +161,14 @@ doc:
ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board. ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board.
qemu: qemu:
$(call colorecho, "\n$(QEMU_MISSING_STRING)") $(call color_header, "$(QEMU_MISSING_STRING)")
else # QEMU is supported. else # QEMU is supported.
qemu: $(KERNEL_BIN) qemu: $(KERNEL_BIN)
$(call colorecho, "\nLaunching QEMU") $(call color_header, "Launching QEMU")
@$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN) @$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN)
endif endif
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
@ -173,14 +193,14 @@ clean:
## Run readelf ## Run readelf
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
readelf: $(KERNEL_ELF) readelf: $(KERNEL_ELF)
$(call colorecho, "\nLaunching readelf") $(call color_header, "Launching readelf")
@$(DOCKER_TOOLS) $(READELF_BINARY) --headers $(KERNEL_ELF) @$(DOCKER_TOOLS) $(READELF_BINARY) --headers $(KERNEL_ELF)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Run objdump ## Run objdump
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
objdump: $(KERNEL_ELF) objdump: $(KERNEL_ELF)
$(call colorecho, "\nLaunching objdump") $(call color_header, "Launching objdump")
@$(DOCKER_TOOLS) $(OBJDUMP_BINARY) --disassemble --demangle \ @$(DOCKER_TOOLS) $(OBJDUMP_BINARY) --disassemble --demangle \
--section .text \ --section .text \
--section .rodata \ --section .rodata \
@ -191,7 +211,7 @@ objdump: $(KERNEL_ELF)
## Run nm ## Run nm
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
nm: $(KERNEL_ELF) nm: $(KERNEL_ELF)
$(call colorecho, "\nLaunching nm") $(call color_header, "Launching nm")
@$(DOCKER_TOOLS) $(NM_BINARY) --demangle --print-size $(KERNEL_ELF) | sort | rustfilt @$(DOCKER_TOOLS) $(NM_BINARY) --demangle --print-size $(KERNEL_ELF) | sort | rustfilt
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
@ -209,8 +229,8 @@ check:
ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board. ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board.
test_boot test : test_boot test:
$(call colorecho, "\n$(QEMU_MISSING_STRING)") $(call color_header, "$(QEMU_MISSING_STRING)")
else # QEMU is supported. else # QEMU is supported.
@ -218,7 +238,7 @@ else # QEMU is supported.
## Run boot test ## Run boot test
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
test_boot: $(KERNEL_BIN) test_boot: $(KERNEL_BIN)
$(call colorecho, "\nBoot test - $(BSP)") $(call color_header, "Boot test - $(BSP)")
@$(DOCKER_TEST) $(EXEC_TEST_DISPATCH) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN) @$(DOCKER_TEST) $(EXEC_TEST_DISPATCH) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN)
test: test_boot test: test_boot

@ -155,7 +155,7 @@ diff -uNr 04_safe_globals/Makefile 05_drivers_gpio_uart/Makefile
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
@@ -82,6 +85,7 @@ @@ -88,6 +91,7 @@
EXEC_QEMU = $(QEMU_BINARY) -M $(QEMU_MACHINE_TYPE) EXEC_QEMU = $(QEMU_BINARY) -M $(QEMU_MACHINE_TYPE)
EXEC_TEST_DISPATCH = ruby ../common/tests/dispatch.rb EXEC_TEST_DISPATCH = ruby ../common/tests/dispatch.rb
@ -163,7 +163,7 @@ diff -uNr 04_safe_globals/Makefile 05_drivers_gpio_uart/Makefile
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Dockerization ## Dockerization
@@ -89,18 +93,26 @@ @@ -95,18 +99,26 @@
DOCKER_CMD = docker run -t --rm -v $(shell pwd):/work/tutorial -w /work/tutorial DOCKER_CMD = docker run -t --rm -v $(shell pwd):/work/tutorial -w /work/tutorial
DOCKER_CMD_INTERACT = $(DOCKER_CMD) -i DOCKER_CMD_INTERACT = $(DOCKER_CMD) -i
DOCKER_ARG_DIR_COMMON = -v $(shell pwd)/../common:/work/common DOCKER_ARG_DIR_COMMON = -v $(shell pwd)/../common:/work/common
@ -186,12 +186,16 @@ diff -uNr 04_safe_globals/Makefile 05_drivers_gpio_uart/Makefile
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
## Targets ## Targets
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
-.PHONY: all $(KERNEL_ELF) $(KERNEL_BIN) doc qemu clippy clean readelf objdump nm check -.PHONY: all doc qemu clippy clean readelf objdump nm check
+.PHONY: all $(KERNEL_ELF) $(KERNEL_BIN) doc qemu miniterm clippy clean readelf objdump nm check +.PHONY: all doc qemu miniterm clippy clean readelf objdump nm check
all: $(KERNEL_BIN) all: $(KERNEL_BIN)
@@ -140,6 +152,12 @@ @@ -156,9 +168,16 @@
qemu: $(KERNEL_BIN)
$(call color_header, "Launching QEMU")
@$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN)
+
endif endif
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------

@ -2,7 +2,7 @@
## ##
## Copyright (c) 2018-2022 Andre Richter <andre.o.richter@gmail.com> ## Copyright (c) 2018-2022 Andre Richter <andre.o.richter@gmail.com>
include ../common/color.mk include ../common/format.mk
include ../common/docker.mk include ../common/docker.mk
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
@ -54,10 +54,16 @@ export LD_SCRIPT_PATH
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
## Generic configuration values ## Targets and Prerequisites
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
KERNEL_LINKER_SCRIPT = link.ld KERNEL_LINKER_SCRIPT = link.ld
KERNEL_ELF = target/$(TARGET)/release/kernel
LAST_BUILD_CONFIG = target/$(BSP).build_config
KERNEL_ELF = target/$(TARGET)/release/kernel
# This parses cargo's dep-info file.
# https://doc.rust-lang.org/cargo/guide/build-cache.html#dep-info-files
KERNEL_ELF_DEPS = $(filter-out %: ,$(file < $(KERNEL_ELF_RAW).d)) $(LAST_BUILD_CONFIG)
@ -114,28 +120,41 @@ endif
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
## Targets ## Targets
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
.PHONY: all $(KERNEL_ELF) $(KERNEL_BIN) doc qemu chainboot clippy clean readelf objdump nm check .PHONY: all doc qemu chainboot clippy clean readelf objdump nm check
all: $(KERNEL_BIN) all: $(KERNEL_BIN)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the kernel ELF ## Save the configuration as a file, so make understands if it changed.
##------------------------------------------------------------------------------
$(LAST_BUILD_CONFIG):
@rm -f target/*.build_config
@mkdir -p target
@touch $(LAST_BUILD_CONFIG)
##------------------------------------------------------------------------------
## Compile the kernel ELF
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
$(KERNEL_ELF): $(KERNEL_ELF): $(KERNEL_ELF_DEPS)
$(call colorecho, "\nCompiling kernel - $(BSP)") $(call color_header, "Compiling kernel ELF - $(BSP)")
@RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD) @RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the stripped kernel binary ## Generate the stripped kernel binary
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
$(KERNEL_BIN): $(KERNEL_ELF) $(KERNEL_BIN): $(KERNEL_ELF)
$(call color_header, "Generating stripped binary")
@$(OBJCOPY_CMD) $(KERNEL_ELF) $(KERNEL_BIN) @$(OBJCOPY_CMD) $(KERNEL_ELF) $(KERNEL_BIN)
$(call color_progress_prefix, "Name")
@echo $(KERNEL_BIN)
$(call color_progress_prefix, "Size")
@printf '%s KiB\n' `du -k $(KERNEL_BIN) | cut -f1`
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the documentation ## Generate the documentation
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
doc: doc:
$(call colorecho, "\nGenerating docs") $(call color_header, "Generating docs")
@$(DOC_CMD) --document-private-items --open @$(DOC_CMD) --document-private-items --open
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
@ -144,16 +163,16 @@ doc:
ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board. ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board.
qemu qemuasm: qemu qemuasm:
$(call colorecho, "\n$(QEMU_MISSING_STRING)") $(call color_header, "$(QEMU_MISSING_STRING)")
else # QEMU is supported. else # QEMU is supported.
qemu: $(KERNEL_BIN) qemu: $(KERNEL_BIN)
$(call colorecho, "\nLaunching QEMU") $(call color_header, "Launching QEMU")
@$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN) @$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN)
qemuasm: $(KERNEL_BIN) qemuasm: $(KERNEL_BIN)
$(call colorecho, "\nLaunching QEMU with ASM output") $(call color_header, "Launching QEMU with ASM output")
@$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN) -d in_asm @$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN) -d in_asm
endif endif
@ -180,14 +199,14 @@ clean:
## Run readelf ## Run readelf
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
readelf: $(KERNEL_ELF) readelf: $(KERNEL_ELF)
$(call colorecho, "\nLaunching readelf") $(call color_header, "Launching readelf")
@$(DOCKER_TOOLS) $(READELF_BINARY) --headers $(KERNEL_ELF) @$(DOCKER_TOOLS) $(READELF_BINARY) --headers $(KERNEL_ELF)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Run objdump ## Run objdump
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
objdump: $(KERNEL_ELF) objdump: $(KERNEL_ELF)
$(call colorecho, "\nLaunching objdump") $(call color_header, "Launching objdump")
@$(DOCKER_TOOLS) $(OBJDUMP_BINARY) --disassemble --demangle \ @$(DOCKER_TOOLS) $(OBJDUMP_BINARY) --disassemble --demangle \
--section .text \ --section .text \
--section .rodata \ --section .rodata \
@ -198,7 +217,7 @@ objdump: $(KERNEL_ELF)
## Run nm ## Run nm
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
nm: $(KERNEL_ELF) nm: $(KERNEL_ELF)
$(call colorecho, "\nLaunching nm") $(call color_header, "Launching nm")
@$(DOCKER_TOOLS) $(NM_BINARY) --demangle --print-size $(KERNEL_ELF) | sort | rustfilt @$(DOCKER_TOOLS) $(NM_BINARY) --demangle --print-size $(KERNEL_ELF) | sort | rustfilt
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
@ -216,8 +235,8 @@ check:
ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board. ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board.
test_boot test : test_boot test:
$(call colorecho, "\n$(QEMU_MISSING_STRING)") $(call color_header, "$(QEMU_MISSING_STRING)")
else # QEMU is supported. else # QEMU is supported.
@ -225,7 +244,7 @@ else # QEMU is supported.
## Run boot test ## Run boot test
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
test_boot: $(KERNEL_BIN) test_boot: $(KERNEL_BIN)
$(call colorecho, "\nBoot test - $(BSP)") $(call color_header, "Boot test - $(BSP)")
@$(DOCKER_TEST) $(EXEC_TEST_MINIPUSH) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) \ @$(DOCKER_TEST) $(EXEC_TEST_MINIPUSH) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) \
-kernel $(KERNEL_BIN) $(CHAINBOOT_DEMO_PAYLOAD) -kernel $(KERNEL_BIN) $(CHAINBOOT_DEMO_PAYLOAD)

@ -186,7 +186,7 @@ diff -uNr 05_drivers_gpio_uart/Makefile 06_uart_chainloader/Makefile
endif endif
# Export for build.rs. # Export for build.rs.
@@ -84,8 +86,8 @@ @@ -90,8 +92,8 @@
-O binary -O binary
EXEC_QEMU = $(QEMU_BINARY) -M $(QEMU_MACHINE_TYPE) EXEC_QEMU = $(QEMU_BINARY) -M $(QEMU_MACHINE_TYPE)
@ -197,7 +197,7 @@ diff -uNr 05_drivers_gpio_uart/Makefile 06_uart_chainloader/Makefile
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Dockerization ## Dockerization
@@ -104,7 +106,7 @@ @@ -110,7 +112,7 @@
ifeq ($(shell uname -s),Linux) ifeq ($(shell uname -s),Linux)
DOCKER_CMD_DEV = $(DOCKER_CMD_INTERACT) $(DOCKER_ARG_DEV) DOCKER_CMD_DEV = $(DOCKER_CMD_INTERACT) $(DOCKER_ARG_DEV)
@ -206,31 +206,30 @@ diff -uNr 05_drivers_gpio_uart/Makefile 06_uart_chainloader/Makefile
endif endif
@@ -112,7 +114,7 @@ @@ -118,7 +120,7 @@
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
## Targets ## Targets
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
-.PHONY: all $(KERNEL_ELF) $(KERNEL_BIN) doc qemu miniterm clippy clean readelf objdump nm check -.PHONY: all doc qemu miniterm clippy clean readelf objdump nm check
+.PHONY: all $(KERNEL_ELF) $(KERNEL_BIN) doc qemu chainboot clippy clean readelf objdump nm check +.PHONY: all doc qemu chainboot clippy clean readelf objdump nm check
all: $(KERNEL_BIN) all: $(KERNEL_BIN)
@@ -141,7 +143,7 @@ @@ -160,7 +162,7 @@
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board. ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board.
-qemu: -qemu:
+qemu qemuasm: +qemu qemuasm:
$(call colorecho, "\n$(QEMU_MISSING_STRING)") $(call color_header, "$(QEMU_MISSING_STRING)")
else # QEMU is supported. else # QEMU is supported.
@@ -149,13 +151,18 @@ @@ -169,13 +171,17 @@
qemu: $(KERNEL_BIN) $(call color_header, "Launching QEMU")
$(call colorecho, "\nLaunching QEMU")
@$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN) @$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN)
+
+qemuasm: $(KERNEL_BIN) +qemuasm: $(KERNEL_BIN)
+ $(call colorecho, "\nLaunching QEMU with ASM output") + $(call color_header, "Launching QEMU with ASM output")
+ @$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN) -d in_asm + @$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN) -d in_asm
+ +
endif endif
@ -246,10 +245,10 @@ diff -uNr 05_drivers_gpio_uart/Makefile 06_uart_chainloader/Makefile
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Run clippy ## Run clippy
@@ -219,7 +226,8 @@ @@ -239,7 +245,8 @@
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
test_boot: $(KERNEL_BIN) test_boot: $(KERNEL_BIN)
$(call colorecho, "\nBoot test - $(BSP)") $(call color_header, "Boot test - $(BSP)")
- @$(DOCKER_TEST) $(EXEC_TEST_DISPATCH) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN) - @$(DOCKER_TEST) $(EXEC_TEST_DISPATCH) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN)
+ @$(DOCKER_TEST) $(EXEC_TEST_MINIPUSH) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) \ + @$(DOCKER_TEST) $(EXEC_TEST_MINIPUSH) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) \
+ -kernel $(KERNEL_BIN) $(CHAINBOOT_DEMO_PAYLOAD) + -kernel $(KERNEL_BIN) $(CHAINBOOT_DEMO_PAYLOAD)

@ -2,7 +2,7 @@
## ##
## Copyright (c) 2018-2022 Andre Richter <andre.o.richter@gmail.com> ## Copyright (c) 2018-2022 Andre Richter <andre.o.richter@gmail.com>
include ../common/color.mk include ../common/format.mk
include ../common/docker.mk include ../common/docker.mk
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
@ -52,10 +52,16 @@ export LD_SCRIPT_PATH
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
## Generic configuration values ## Targets and Prerequisites
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
KERNEL_LINKER_SCRIPT = link.ld KERNEL_LINKER_SCRIPT = link.ld
KERNEL_ELF = target/$(TARGET)/release/kernel
LAST_BUILD_CONFIG = target/$(BSP).build_config
KERNEL_ELF = target/$(TARGET)/release/kernel
# This parses cargo's dep-info file.
# https://doc.rust-lang.org/cargo/guide/build-cache.html#dep-info-files
KERNEL_ELF_DEPS = $(filter-out %: ,$(file < $(KERNEL_ELF_RAW).d)) $(LAST_BUILD_CONFIG)
@ -112,28 +118,41 @@ endif
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
## Targets ## Targets
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
.PHONY: all $(KERNEL_ELF) $(KERNEL_BIN) doc qemu chainboot clippy clean readelf objdump nm check .PHONY: all doc qemu chainboot clippy clean readelf objdump nm check
all: $(KERNEL_BIN) all: $(KERNEL_BIN)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the kernel ELF ## Save the configuration as a file, so make understands if it changed.
##------------------------------------------------------------------------------
$(LAST_BUILD_CONFIG):
@rm -f target/*.build_config
@mkdir -p target
@touch $(LAST_BUILD_CONFIG)
##------------------------------------------------------------------------------
## Compile the kernel ELF
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
$(KERNEL_ELF): $(KERNEL_ELF): $(KERNEL_ELF_DEPS)
$(call colorecho, "\nCompiling kernel - $(BSP)") $(call color_header, "Compiling kernel ELF - $(BSP)")
@RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD) @RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the stripped kernel binary ## Generate the stripped kernel binary
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
$(KERNEL_BIN): $(KERNEL_ELF) $(KERNEL_BIN): $(KERNEL_ELF)
$(call color_header, "Generating stripped binary")
@$(OBJCOPY_CMD) $(KERNEL_ELF) $(KERNEL_BIN) @$(OBJCOPY_CMD) $(KERNEL_ELF) $(KERNEL_BIN)
$(call color_progress_prefix, "Name")
@echo $(KERNEL_BIN)
$(call color_progress_prefix, "Size")
@printf '%s KiB\n' `du -k $(KERNEL_BIN) | cut -f1`
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the documentation ## Generate the documentation
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
doc: doc:
$(call colorecho, "\nGenerating docs") $(call color_header, "Generating docs")
@$(DOC_CMD) --document-private-items --open @$(DOC_CMD) --document-private-items --open
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
@ -142,12 +161,12 @@ doc:
ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board. ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board.
qemu: qemu:
$(call colorecho, "\n$(QEMU_MISSING_STRING)") $(call color_header, "$(QEMU_MISSING_STRING)")
else # QEMU is supported. else # QEMU is supported.
qemu: $(KERNEL_BIN) qemu: $(KERNEL_BIN)
$(call colorecho, "\nLaunching QEMU") $(call color_header, "Launching QEMU")
@$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN) @$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN)
endif endif
@ -174,14 +193,14 @@ clean:
## Run readelf ## Run readelf
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
readelf: $(KERNEL_ELF) readelf: $(KERNEL_ELF)
$(call colorecho, "\nLaunching readelf") $(call color_header, "Launching readelf")
@$(DOCKER_TOOLS) $(READELF_BINARY) --headers $(KERNEL_ELF) @$(DOCKER_TOOLS) $(READELF_BINARY) --headers $(KERNEL_ELF)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Run objdump ## Run objdump
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
objdump: $(KERNEL_ELF) objdump: $(KERNEL_ELF)
$(call colorecho, "\nLaunching objdump") $(call color_header, "Launching objdump")
@$(DOCKER_TOOLS) $(OBJDUMP_BINARY) --disassemble --demangle \ @$(DOCKER_TOOLS) $(OBJDUMP_BINARY) --disassemble --demangle \
--section .text \ --section .text \
--section .rodata \ --section .rodata \
@ -192,7 +211,7 @@ objdump: $(KERNEL_ELF)
## Run nm ## Run nm
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
nm: $(KERNEL_ELF) nm: $(KERNEL_ELF)
$(call colorecho, "\nLaunching nm") $(call color_header, "Launching nm")
@$(DOCKER_TOOLS) $(NM_BINARY) --demangle --print-size $(KERNEL_ELF) | sort | rustfilt @$(DOCKER_TOOLS) $(NM_BINARY) --demangle --print-size $(KERNEL_ELF) | sort | rustfilt
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
@ -210,8 +229,8 @@ check:
ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board. ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board.
test_boot test : test_boot test:
$(call colorecho, "\n$(QEMU_MISSING_STRING)") $(call color_header, "$(QEMU_MISSING_STRING)")
else # QEMU is supported. else # QEMU is supported.
@ -219,7 +238,7 @@ else # QEMU is supported.
## Run boot test ## Run boot test
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
test_boot: $(KERNEL_BIN) test_boot: $(KERNEL_BIN)
$(call colorecho, "\nBoot test - $(BSP)") $(call color_header, "Boot test - $(BSP)")
@$(DOCKER_TEST) $(EXEC_TEST_DISPATCH) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN) @$(DOCKER_TEST) $(EXEC_TEST_DISPATCH) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN)
test: test_boot test: test_boot

@ -110,7 +110,7 @@ diff -uNr 06_uart_chainloader/Makefile 07_timestamps/Makefile
endif endif
# Export for build.rs. # Export for build.rs.
@@ -86,7 +84,7 @@ @@ -92,7 +90,7 @@
-O binary -O binary
EXEC_QEMU = $(QEMU_BINARY) -M $(QEMU_MACHINE_TYPE) EXEC_QEMU = $(QEMU_BINARY) -M $(QEMU_MACHINE_TYPE)
@ -119,21 +119,21 @@ diff -uNr 06_uart_chainloader/Makefile 07_timestamps/Makefile
EXEC_MINIPUSH = ruby ../common/serial/minipush.rb EXEC_MINIPUSH = ruby ../common/serial/minipush.rb
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
@@ -143,7 +141,7 @@ @@ -162,7 +160,7 @@
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board. ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board.
-qemu qemuasm: -qemu qemuasm:
+qemu: +qemu:
$(call colorecho, "\n$(QEMU_MISSING_STRING)") $(call color_header, "$(QEMU_MISSING_STRING)")
else # QEMU is supported. else # QEMU is supported.
@@ -152,17 +150,13 @@ @@ -171,17 +169,13 @@
$(call colorecho, "\nLaunching QEMU") $(call color_header, "Launching QEMU")
@$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN) @$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN)
-qemuasm: $(KERNEL_BIN) -qemuasm: $(KERNEL_BIN)
- $(call colorecho, "\nLaunching QEMU with ASM output") - $(call color_header, "Launching QEMU with ASM output")
- @$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN) -d in_asm - @$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN) -d in_asm
- -
endif endif
@ -147,10 +147,10 @@ diff -uNr 06_uart_chainloader/Makefile 07_timestamps/Makefile
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Run clippy ## Run clippy
@@ -226,8 +220,7 @@ @@ -245,8 +239,7 @@
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
test_boot: $(KERNEL_BIN) test_boot: $(KERNEL_BIN)
$(call colorecho, "\nBoot test - $(BSP)") $(call color_header, "Boot test - $(BSP)")
- @$(DOCKER_TEST) $(EXEC_TEST_MINIPUSH) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) \ - @$(DOCKER_TEST) $(EXEC_TEST_MINIPUSH) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) \
- -kernel $(KERNEL_BIN) $(CHAINBOOT_DEMO_PAYLOAD) - -kernel $(KERNEL_BIN) $(CHAINBOOT_DEMO_PAYLOAD)
+ @$(DOCKER_TEST) $(EXEC_TEST_DISPATCH) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN) + @$(DOCKER_TEST) $(EXEC_TEST_DISPATCH) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN)

@ -2,7 +2,7 @@
## ##
## Copyright (c) 2018-2022 Andre Richter <andre.o.richter@gmail.com> ## Copyright (c) 2018-2022 Andre Richter <andre.o.richter@gmail.com>
include ../common/color.mk include ../common/format.mk
include ../common/docker.mk include ../common/docker.mk
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
@ -56,10 +56,16 @@ export LD_SCRIPT_PATH
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
## Generic configuration values ## Targets and Prerequisites
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
KERNEL_LINKER_SCRIPT = link.ld KERNEL_LINKER_SCRIPT = link.ld
KERNEL_ELF = target/$(TARGET)/release/kernel
LAST_BUILD_CONFIG = target/$(BSP).build_config
KERNEL_ELF = target/$(TARGET)/release/kernel
# This parses cargo's dep-info file.
# https://doc.rust-lang.org/cargo/guide/build-cache.html#dep-info-files
KERNEL_ELF_DEPS = $(filter-out %: ,$(file < $(KERNEL_ELF_RAW).d)) $(LAST_BUILD_CONFIG)
@ -123,28 +129,41 @@ endif
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
## Targets ## Targets
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
.PHONY: all $(KERNEL_ELF) $(KERNEL_BIN) doc qemu chainboot clippy clean readelf objdump nm check .PHONY: all doc qemu chainboot clippy clean readelf objdump nm check
all: $(KERNEL_BIN) all: $(KERNEL_BIN)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the kernel ELF ## Save the configuration as a file, so make understands if it changed.
##------------------------------------------------------------------------------
$(LAST_BUILD_CONFIG):
@rm -f target/*.build_config
@mkdir -p target
@touch $(LAST_BUILD_CONFIG)
##------------------------------------------------------------------------------
## Compile the kernel ELF
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
$(KERNEL_ELF): $(KERNEL_ELF): $(KERNEL_ELF_DEPS)
$(call colorecho, "\nCompiling kernel - $(BSP)") $(call color_header, "Compiling kernel ELF - $(BSP)")
@RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD) @RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the stripped kernel binary ## Generate the stripped kernel binary
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
$(KERNEL_BIN): $(KERNEL_ELF) $(KERNEL_BIN): $(KERNEL_ELF)
$(call color_header, "Generating stripped binary")
@$(OBJCOPY_CMD) $(KERNEL_ELF) $(KERNEL_BIN) @$(OBJCOPY_CMD) $(KERNEL_ELF) $(KERNEL_BIN)
$(call color_progress_prefix, "Name")
@echo $(KERNEL_BIN)
$(call color_progress_prefix, "Size")
@printf '%s KiB\n' `du -k $(KERNEL_BIN) | cut -f1`
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the documentation ## Generate the documentation
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
doc: doc:
$(call colorecho, "\nGenerating docs") $(call color_header, "Generating docs")
@$(DOC_CMD) --document-private-items --open @$(DOC_CMD) --document-private-items --open
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
@ -153,12 +172,12 @@ doc:
ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board. ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board.
qemu: qemu:
$(call colorecho, "\n$(QEMU_MISSING_STRING)") $(call color_header, "$(QEMU_MISSING_STRING)")
else # QEMU is supported. else # QEMU is supported.
qemu: $(KERNEL_BIN) qemu: $(KERNEL_BIN)
$(call colorecho, "\nLaunching QEMU") $(call color_header, "Launching QEMU")
@$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN) @$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN)
endif endif
@ -185,14 +204,14 @@ clean:
## Run readelf ## Run readelf
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
readelf: $(KERNEL_ELF) readelf: $(KERNEL_ELF)
$(call colorecho, "\nLaunching readelf") $(call color_header, "Launching readelf")
@$(DOCKER_TOOLS) $(READELF_BINARY) --headers $(KERNEL_ELF) @$(DOCKER_TOOLS) $(READELF_BINARY) --headers $(KERNEL_ELF)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Run objdump ## Run objdump
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
objdump: $(KERNEL_ELF) objdump: $(KERNEL_ELF)
$(call colorecho, "\nLaunching objdump") $(call color_header, "Launching objdump")
@$(DOCKER_TOOLS) $(OBJDUMP_BINARY) --disassemble --demangle \ @$(DOCKER_TOOLS) $(OBJDUMP_BINARY) --disassemble --demangle \
--section .text \ --section .text \
--section .rodata \ --section .rodata \
@ -203,7 +222,7 @@ objdump: $(KERNEL_ELF)
## Run nm ## Run nm
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
nm: $(KERNEL_ELF) nm: $(KERNEL_ELF)
$(call colorecho, "\nLaunching nm") $(call color_header, "Launching nm")
@$(DOCKER_TOOLS) $(NM_BINARY) --demangle --print-size $(KERNEL_ELF) | sort | rustfilt @$(DOCKER_TOOLS) $(NM_BINARY) --demangle --print-size $(KERNEL_ELF) | sort | rustfilt
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
@ -229,7 +248,7 @@ jtagboot:
## Start OpenOCD session ## Start OpenOCD session
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
openocd: openocd:
$(call colorecho, "\nLaunching OpenOCD") $(call color_header, "Launching OpenOCD")
@$(DOCKER_OPENOCD) openocd $(OPENOCD_ARG) @$(DOCKER_OPENOCD) openocd $(OPENOCD_ARG)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
@ -238,7 +257,7 @@ openocd:
gdb: RUSTC_MISC_ARGS += -C debuginfo=2 gdb: RUSTC_MISC_ARGS += -C debuginfo=2
gdb-opt0: RUSTC_MISC_ARGS += -C debuginfo=2 -C opt-level=0 gdb-opt0: RUSTC_MISC_ARGS += -C debuginfo=2 -C opt-level=0
gdb gdb-opt0: $(KERNEL_ELF) gdb gdb-opt0: $(KERNEL_ELF)
$(call colorecho, "\nLaunching GDB") $(call color_header, "Launching GDB")
@$(DOCKER_GDB) gdb-multiarch -q $(KERNEL_ELF) @$(DOCKER_GDB) gdb-multiarch -q $(KERNEL_ELF)
@ -250,8 +269,8 @@ gdb gdb-opt0: $(KERNEL_ELF)
ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board. ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board.
test_boot test : test_boot test:
$(call colorecho, "\n$(QEMU_MISSING_STRING)") $(call color_header, "$(QEMU_MISSING_STRING)")
else # QEMU is supported. else # QEMU is supported.
@ -259,7 +278,7 @@ else # QEMU is supported.
## Run boot test ## Run boot test
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
test_boot: $(KERNEL_BIN) test_boot: $(KERNEL_BIN)
$(call colorecho, "\nBoot test - $(BSP)") $(call color_header, "Boot test - $(BSP)")
@$(DOCKER_TEST) $(EXEC_TEST_DISPATCH) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN) @$(DOCKER_TEST) $(EXEC_TEST_DISPATCH) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN)
test: test_boot test: test_boot

@ -338,7 +338,7 @@ diff -uNr 07_timestamps/Makefile 08_hw_debug_JTAG/Makefile
LD_SCRIPT_PATH = src/bsp/raspberrypi LD_SCRIPT_PATH = src/bsp/raspberrypi
RUSTC_MISC_ARGS = -C target-cpu=cortex-a72 RUSTC_MISC_ARGS = -C target-cpu=cortex-a72
endif endif
@@ -93,18 +97,25 @@ @@ -99,18 +103,25 @@
DOCKER_CMD = docker run -t --rm -v $(shell pwd):/work/tutorial -w /work/tutorial DOCKER_CMD = docker run -t --rm -v $(shell pwd):/work/tutorial -w /work/tutorial
DOCKER_CMD_INTERACT = $(DOCKER_CMD) -i DOCKER_CMD_INTERACT = $(DOCKER_CMD) -i
DOCKER_ARG_DIR_COMMON = -v $(shell pwd)/../common:/work/common DOCKER_ARG_DIR_COMMON = -v $(shell pwd)/../common:/work/common
@ -364,7 +364,7 @@ diff -uNr 07_timestamps/Makefile 08_hw_debug_JTAG/Makefile
endif endif
@@ -203,6 +214,35 @@ @@ -222,6 +233,35 @@
@ -383,7 +383,7 @@ diff -uNr 07_timestamps/Makefile 08_hw_debug_JTAG/Makefile
+## Start OpenOCD session +## Start OpenOCD session
+##------------------------------------------------------------------------------ +##------------------------------------------------------------------------------
+openocd: +openocd:
+ $(call colorecho, "\nLaunching OpenOCD") + $(call color_header, "Launching OpenOCD")
+ @$(DOCKER_OPENOCD) openocd $(OPENOCD_ARG) + @$(DOCKER_OPENOCD) openocd $(OPENOCD_ARG)
+ +
+##------------------------------------------------------------------------------ +##------------------------------------------------------------------------------
@ -392,7 +392,7 @@ diff -uNr 07_timestamps/Makefile 08_hw_debug_JTAG/Makefile
+gdb: RUSTC_MISC_ARGS += -C debuginfo=2 +gdb: RUSTC_MISC_ARGS += -C debuginfo=2
+gdb-opt0: RUSTC_MISC_ARGS += -C debuginfo=2 -C opt-level=0 +gdb-opt0: RUSTC_MISC_ARGS += -C debuginfo=2 -C opt-level=0
+gdb gdb-opt0: $(KERNEL_ELF) +gdb gdb-opt0: $(KERNEL_ELF)
+ $(call colorecho, "\nLaunching GDB") + $(call color_header, "Launching GDB")
+ @$(DOCKER_GDB) gdb-multiarch -q $(KERNEL_ELF) + @$(DOCKER_GDB) gdb-multiarch -q $(KERNEL_ELF)
+ +
+ +

@ -2,7 +2,7 @@
## ##
## Copyright (c) 2018-2022 Andre Richter <andre.o.richter@gmail.com> ## Copyright (c) 2018-2022 Andre Richter <andre.o.richter@gmail.com>
include ../common/color.mk include ../common/format.mk
include ../common/docker.mk include ../common/docker.mk
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
@ -56,10 +56,16 @@ export LD_SCRIPT_PATH
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
## Generic configuration values ## Targets and Prerequisites
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
KERNEL_LINKER_SCRIPT = link.ld KERNEL_LINKER_SCRIPT = link.ld
KERNEL_ELF = target/$(TARGET)/release/kernel
LAST_BUILD_CONFIG = target/$(BSP).build_config
KERNEL_ELF = target/$(TARGET)/release/kernel
# This parses cargo's dep-info file.
# https://doc.rust-lang.org/cargo/guide/build-cache.html#dep-info-files
KERNEL_ELF_DEPS = $(filter-out %: ,$(file < $(KERNEL_ELF_RAW).d)) $(LAST_BUILD_CONFIG)
@ -123,28 +129,41 @@ endif
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
## Targets ## Targets
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
.PHONY: all $(KERNEL_ELF) $(KERNEL_BIN) doc qemu chainboot clippy clean readelf objdump nm check .PHONY: all doc qemu chainboot clippy clean readelf objdump nm check
all: $(KERNEL_BIN) all: $(KERNEL_BIN)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the kernel ELF ## Save the configuration as a file, so make understands if it changed.
##------------------------------------------------------------------------------
$(LAST_BUILD_CONFIG):
@rm -f target/*.build_config
@mkdir -p target
@touch $(LAST_BUILD_CONFIG)
##------------------------------------------------------------------------------
## Compile the kernel ELF
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
$(KERNEL_ELF): $(KERNEL_ELF): $(KERNEL_ELF_DEPS)
$(call colorecho, "\nCompiling kernel - $(BSP)") $(call color_header, "Compiling kernel ELF - $(BSP)")
@RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD) @RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the stripped kernel binary ## Generate the stripped kernel binary
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
$(KERNEL_BIN): $(KERNEL_ELF) $(KERNEL_BIN): $(KERNEL_ELF)
$(call color_header, "Generating stripped binary")
@$(OBJCOPY_CMD) $(KERNEL_ELF) $(KERNEL_BIN) @$(OBJCOPY_CMD) $(KERNEL_ELF) $(KERNEL_BIN)
$(call color_progress_prefix, "Name")
@echo $(KERNEL_BIN)
$(call color_progress_prefix, "Size")
@printf '%s KiB\n' `du -k $(KERNEL_BIN) | cut -f1`
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the documentation ## Generate the documentation
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
doc: doc:
$(call colorecho, "\nGenerating docs") $(call color_header, "Generating docs")
@$(DOC_CMD) --document-private-items --open @$(DOC_CMD) --document-private-items --open
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
@ -153,12 +172,12 @@ doc:
ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board. ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board.
qemu: qemu:
$(call colorecho, "\n$(QEMU_MISSING_STRING)") $(call color_header, "$(QEMU_MISSING_STRING)")
else # QEMU is supported. else # QEMU is supported.
qemu: $(KERNEL_BIN) qemu: $(KERNEL_BIN)
$(call colorecho, "\nLaunching QEMU") $(call color_header, "Launching QEMU")
@$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN) @$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN)
endif endif
@ -185,14 +204,14 @@ clean:
## Run readelf ## Run readelf
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
readelf: $(KERNEL_ELF) readelf: $(KERNEL_ELF)
$(call colorecho, "\nLaunching readelf") $(call color_header, "Launching readelf")
@$(DOCKER_TOOLS) $(READELF_BINARY) --headers $(KERNEL_ELF) @$(DOCKER_TOOLS) $(READELF_BINARY) --headers $(KERNEL_ELF)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Run objdump ## Run objdump
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
objdump: $(KERNEL_ELF) objdump: $(KERNEL_ELF)
$(call colorecho, "\nLaunching objdump") $(call color_header, "Launching objdump")
@$(DOCKER_TOOLS) $(OBJDUMP_BINARY) --disassemble --demangle \ @$(DOCKER_TOOLS) $(OBJDUMP_BINARY) --disassemble --demangle \
--section .text \ --section .text \
--section .rodata \ --section .rodata \
@ -203,7 +222,7 @@ objdump: $(KERNEL_ELF)
## Run nm ## Run nm
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
nm: $(KERNEL_ELF) nm: $(KERNEL_ELF)
$(call colorecho, "\nLaunching nm") $(call color_header, "Launching nm")
@$(DOCKER_TOOLS) $(NM_BINARY) --demangle --print-size $(KERNEL_ELF) | sort | rustfilt @$(DOCKER_TOOLS) $(NM_BINARY) --demangle --print-size $(KERNEL_ELF) | sort | rustfilt
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
@ -229,7 +248,7 @@ jtagboot:
## Start OpenOCD session ## Start OpenOCD session
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
openocd: openocd:
$(call colorecho, "\nLaunching OpenOCD") $(call color_header, "Launching OpenOCD")
@$(DOCKER_OPENOCD) openocd $(OPENOCD_ARG) @$(DOCKER_OPENOCD) openocd $(OPENOCD_ARG)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
@ -238,7 +257,7 @@ openocd:
gdb: RUSTC_MISC_ARGS += -C debuginfo=2 gdb: RUSTC_MISC_ARGS += -C debuginfo=2
gdb-opt0: RUSTC_MISC_ARGS += -C debuginfo=2 -C opt-level=0 gdb-opt0: RUSTC_MISC_ARGS += -C debuginfo=2 -C opt-level=0
gdb gdb-opt0: $(KERNEL_ELF) gdb gdb-opt0: $(KERNEL_ELF)
$(call colorecho, "\nLaunching GDB") $(call color_header, "Launching GDB")
@$(DOCKER_GDB) gdb-multiarch -q $(KERNEL_ELF) @$(DOCKER_GDB) gdb-multiarch -q $(KERNEL_ELF)
@ -250,8 +269,8 @@ gdb gdb-opt0: $(KERNEL_ELF)
ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board. ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board.
test_boot test : test_boot test:
$(call colorecho, "\n$(QEMU_MISSING_STRING)") $(call color_header, "$(QEMU_MISSING_STRING)")
else # QEMU is supported. else # QEMU is supported.
@ -259,7 +278,7 @@ else # QEMU is supported.
## Run boot test ## Run boot test
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
test_boot: $(KERNEL_BIN) test_boot: $(KERNEL_BIN)
$(call colorecho, "\nBoot test - $(BSP)") $(call color_header, "Boot test - $(BSP)")
@$(DOCKER_TEST) $(EXEC_TEST_DISPATCH) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN) @$(DOCKER_TEST) $(EXEC_TEST_DISPATCH) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN)
test: test_boot test: test_boot

@ -2,7 +2,7 @@
## ##
## Copyright (c) 2018-2022 Andre Richter <andre.o.richter@gmail.com> ## Copyright (c) 2018-2022 Andre Richter <andre.o.richter@gmail.com>
include ../common/color.mk include ../common/format.mk
include ../common/docker.mk include ../common/docker.mk
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
@ -56,10 +56,16 @@ export LD_SCRIPT_PATH
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
## Generic configuration values ## Targets and Prerequisites
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
KERNEL_LINKER_SCRIPT = link.ld KERNEL_LINKER_SCRIPT = link.ld
KERNEL_ELF = target/$(TARGET)/release/kernel
LAST_BUILD_CONFIG = target/$(BSP).build_config
KERNEL_ELF = target/$(TARGET)/release/kernel
# This parses cargo's dep-info file.
# https://doc.rust-lang.org/cargo/guide/build-cache.html#dep-info-files
KERNEL_ELF_DEPS = $(filter-out %: ,$(file < $(KERNEL_ELF_RAW).d)) $(LAST_BUILD_CONFIG)
@ -123,28 +129,41 @@ endif
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
## Targets ## Targets
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
.PHONY: all $(KERNEL_ELF) $(KERNEL_BIN) doc qemu chainboot clippy clean readelf objdump nm check .PHONY: all doc qemu chainboot clippy clean readelf objdump nm check
all: $(KERNEL_BIN) all: $(KERNEL_BIN)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the kernel ELF ## Save the configuration as a file, so make understands if it changed.
##------------------------------------------------------------------------------
$(LAST_BUILD_CONFIG):
@rm -f target/*.build_config
@mkdir -p target
@touch $(LAST_BUILD_CONFIG)
##------------------------------------------------------------------------------
## Compile the kernel ELF
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
$(KERNEL_ELF): $(KERNEL_ELF): $(KERNEL_ELF_DEPS)
$(call colorecho, "\nCompiling kernel - $(BSP)") $(call color_header, "Compiling kernel ELF - $(BSP)")
@RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD) @RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the stripped kernel binary ## Generate the stripped kernel binary
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
$(KERNEL_BIN): $(KERNEL_ELF) $(KERNEL_BIN): $(KERNEL_ELF)
$(call color_header, "Generating stripped binary")
@$(OBJCOPY_CMD) $(KERNEL_ELF) $(KERNEL_BIN) @$(OBJCOPY_CMD) $(KERNEL_ELF) $(KERNEL_BIN)
$(call color_progress_prefix, "Name")
@echo $(KERNEL_BIN)
$(call color_progress_prefix, "Size")
@printf '%s KiB\n' `du -k $(KERNEL_BIN) | cut -f1`
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the documentation ## Generate the documentation
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
doc: doc:
$(call colorecho, "\nGenerating docs") $(call color_header, "Generating docs")
@$(DOC_CMD) --document-private-items --open @$(DOC_CMD) --document-private-items --open
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
@ -153,12 +172,12 @@ doc:
ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board. ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board.
qemu: qemu:
$(call colorecho, "\n$(QEMU_MISSING_STRING)") $(call color_header, "$(QEMU_MISSING_STRING)")
else # QEMU is supported. else # QEMU is supported.
qemu: $(KERNEL_BIN) qemu: $(KERNEL_BIN)
$(call colorecho, "\nLaunching QEMU") $(call color_header, "Launching QEMU")
@$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN) @$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN)
endif endif
@ -185,14 +204,14 @@ clean:
## Run readelf ## Run readelf
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
readelf: $(KERNEL_ELF) readelf: $(KERNEL_ELF)
$(call colorecho, "\nLaunching readelf") $(call color_header, "Launching readelf")
@$(DOCKER_TOOLS) $(READELF_BINARY) --headers $(KERNEL_ELF) @$(DOCKER_TOOLS) $(READELF_BINARY) --headers $(KERNEL_ELF)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Run objdump ## Run objdump
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
objdump: $(KERNEL_ELF) objdump: $(KERNEL_ELF)
$(call colorecho, "\nLaunching objdump") $(call color_header, "Launching objdump")
@$(DOCKER_TOOLS) $(OBJDUMP_BINARY) --disassemble --demangle \ @$(DOCKER_TOOLS) $(OBJDUMP_BINARY) --disassemble --demangle \
--section .text \ --section .text \
--section .rodata \ --section .rodata \
@ -203,7 +222,7 @@ objdump: $(KERNEL_ELF)
## Run nm ## Run nm
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
nm: $(KERNEL_ELF) nm: $(KERNEL_ELF)
$(call colorecho, "\nLaunching nm") $(call color_header, "Launching nm")
@$(DOCKER_TOOLS) $(NM_BINARY) --demangle --print-size $(KERNEL_ELF) | sort | rustfilt @$(DOCKER_TOOLS) $(NM_BINARY) --demangle --print-size $(KERNEL_ELF) | sort | rustfilt
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
@ -229,7 +248,7 @@ jtagboot:
## Start OpenOCD session ## Start OpenOCD session
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
openocd: openocd:
$(call colorecho, "\nLaunching OpenOCD") $(call color_header, "Launching OpenOCD")
@$(DOCKER_OPENOCD) openocd $(OPENOCD_ARG) @$(DOCKER_OPENOCD) openocd $(OPENOCD_ARG)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
@ -238,7 +257,7 @@ openocd:
gdb: RUSTC_MISC_ARGS += -C debuginfo=2 gdb: RUSTC_MISC_ARGS += -C debuginfo=2
gdb-opt0: RUSTC_MISC_ARGS += -C debuginfo=2 -C opt-level=0 gdb-opt0: RUSTC_MISC_ARGS += -C debuginfo=2 -C opt-level=0
gdb gdb-opt0: $(KERNEL_ELF) gdb gdb-opt0: $(KERNEL_ELF)
$(call colorecho, "\nLaunching GDB") $(call color_header, "Launching GDB")
@$(DOCKER_GDB) gdb-multiarch -q $(KERNEL_ELF) @$(DOCKER_GDB) gdb-multiarch -q $(KERNEL_ELF)
@ -250,8 +269,8 @@ gdb gdb-opt0: $(KERNEL_ELF)
ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board. ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board.
test_boot test : test_boot test:
$(call colorecho, "\n$(QEMU_MISSING_STRING)") $(call color_header, "$(QEMU_MISSING_STRING)")
else # QEMU is supported. else # QEMU is supported.
@ -259,7 +278,7 @@ else # QEMU is supported.
## Run boot test ## Run boot test
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
test_boot: $(KERNEL_BIN) test_boot: $(KERNEL_BIN)
$(call colorecho, "\nBoot test - $(BSP)") $(call color_header, "Boot test - $(BSP)")
@$(DOCKER_TEST) $(EXEC_TEST_DISPATCH) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN) @$(DOCKER_TEST) $(EXEC_TEST_DISPATCH) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN)
test: test_boot test: test_boot

@ -2,7 +2,7 @@
## ##
## Copyright (c) 2018-2022 Andre Richter <andre.o.richter@gmail.com> ## Copyright (c) 2018-2022 Andre Richter <andre.o.richter@gmail.com>
include ../common/color.mk include ../common/format.mk
include ../common/docker.mk include ../common/docker.mk
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
@ -56,10 +56,16 @@ export LD_SCRIPT_PATH
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
## Generic configuration values ## Targets and Prerequisites
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
KERNEL_LINKER_SCRIPT = link.ld KERNEL_LINKER_SCRIPT = link.ld
KERNEL_ELF = target/$(TARGET)/release/kernel
LAST_BUILD_CONFIG = target/$(BSP).build_config
KERNEL_ELF = target/$(TARGET)/release/kernel
# This parses cargo's dep-info file.
# https://doc.rust-lang.org/cargo/guide/build-cache.html#dep-info-files
KERNEL_ELF_DEPS = $(filter-out %: ,$(file < $(KERNEL_ELF_RAW).d)) $(LAST_BUILD_CONFIG)
@ -123,28 +129,41 @@ endif
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
## Targets ## Targets
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
.PHONY: all $(KERNEL_ELF) $(KERNEL_BIN) doc qemu chainboot clippy clean readelf objdump nm check .PHONY: all doc qemu chainboot clippy clean readelf objdump nm check
all: $(KERNEL_BIN) all: $(KERNEL_BIN)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the kernel ELF ## Save the configuration as a file, so make understands if it changed.
##------------------------------------------------------------------------------
$(LAST_BUILD_CONFIG):
@rm -f target/*.build_config
@mkdir -p target
@touch $(LAST_BUILD_CONFIG)
##------------------------------------------------------------------------------
## Compile the kernel ELF
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
$(KERNEL_ELF): $(KERNEL_ELF): $(KERNEL_ELF_DEPS)
$(call colorecho, "\nCompiling kernel - $(BSP)") $(call color_header, "Compiling kernel ELF - $(BSP)")
@RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD) @RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the stripped kernel binary ## Generate the stripped kernel binary
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
$(KERNEL_BIN): $(KERNEL_ELF) $(KERNEL_BIN): $(KERNEL_ELF)
$(call color_header, "Generating stripped binary")
@$(OBJCOPY_CMD) $(KERNEL_ELF) $(KERNEL_BIN) @$(OBJCOPY_CMD) $(KERNEL_ELF) $(KERNEL_BIN)
$(call color_progress_prefix, "Name")
@echo $(KERNEL_BIN)
$(call color_progress_prefix, "Size")
@printf '%s KiB\n' `du -k $(KERNEL_BIN) | cut -f1`
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the documentation ## Generate the documentation
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
doc: doc:
$(call colorecho, "\nGenerating docs") $(call color_header, "Generating docs")
@$(DOC_CMD) --document-private-items --open @$(DOC_CMD) --document-private-items --open
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
@ -153,12 +172,12 @@ doc:
ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board. ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board.
qemu: qemu:
$(call colorecho, "\n$(QEMU_MISSING_STRING)") $(call color_header, "$(QEMU_MISSING_STRING)")
else # QEMU is supported. else # QEMU is supported.
qemu: $(KERNEL_BIN) qemu: $(KERNEL_BIN)
$(call colorecho, "\nLaunching QEMU") $(call color_header, "Launching QEMU")
@$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN) @$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN)
endif endif
@ -185,14 +204,14 @@ clean:
## Run readelf ## Run readelf
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
readelf: $(KERNEL_ELF) readelf: $(KERNEL_ELF)
$(call colorecho, "\nLaunching readelf") $(call color_header, "Launching readelf")
@$(DOCKER_TOOLS) $(READELF_BINARY) --headers $(KERNEL_ELF) @$(DOCKER_TOOLS) $(READELF_BINARY) --headers $(KERNEL_ELF)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Run objdump ## Run objdump
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
objdump: $(KERNEL_ELF) objdump: $(KERNEL_ELF)
$(call colorecho, "\nLaunching objdump") $(call color_header, "Launching objdump")
@$(DOCKER_TOOLS) $(OBJDUMP_BINARY) --disassemble --demangle \ @$(DOCKER_TOOLS) $(OBJDUMP_BINARY) --disassemble --demangle \
--section .text \ --section .text \
--section .rodata \ --section .rodata \
@ -203,7 +222,7 @@ objdump: $(KERNEL_ELF)
## Run nm ## Run nm
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
nm: $(KERNEL_ELF) nm: $(KERNEL_ELF)
$(call colorecho, "\nLaunching nm") $(call color_header, "Launching nm")
@$(DOCKER_TOOLS) $(NM_BINARY) --demangle --print-size $(KERNEL_ELF) | sort | rustfilt @$(DOCKER_TOOLS) $(NM_BINARY) --demangle --print-size $(KERNEL_ELF) | sort | rustfilt
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
@ -229,7 +248,7 @@ jtagboot:
## Start OpenOCD session ## Start OpenOCD session
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
openocd: openocd:
$(call colorecho, "\nLaunching OpenOCD") $(call color_header, "Launching OpenOCD")
@$(DOCKER_OPENOCD) openocd $(OPENOCD_ARG) @$(DOCKER_OPENOCD) openocd $(OPENOCD_ARG)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
@ -238,7 +257,7 @@ openocd:
gdb: RUSTC_MISC_ARGS += -C debuginfo=2 gdb: RUSTC_MISC_ARGS += -C debuginfo=2
gdb-opt0: RUSTC_MISC_ARGS += -C debuginfo=2 -C opt-level=0 gdb-opt0: RUSTC_MISC_ARGS += -C debuginfo=2 -C opt-level=0
gdb gdb-opt0: $(KERNEL_ELF) gdb gdb-opt0: $(KERNEL_ELF)
$(call colorecho, "\nLaunching GDB") $(call color_header, "Launching GDB")
@$(DOCKER_GDB) gdb-multiarch -q $(KERNEL_ELF) @$(DOCKER_GDB) gdb-multiarch -q $(KERNEL_ELF)
@ -250,8 +269,8 @@ gdb gdb-opt0: $(KERNEL_ELF)
ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board. ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board.
test_boot test : test_boot test:
$(call colorecho, "\n$(QEMU_MISSING_STRING)") $(call color_header, "$(QEMU_MISSING_STRING)")
else # QEMU is supported. else # QEMU is supported.
@ -259,7 +278,7 @@ else # QEMU is supported.
## Run boot test ## Run boot test
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
test_boot: $(KERNEL_BIN) test_boot: $(KERNEL_BIN)
$(call colorecho, "\nBoot test - $(BSP)") $(call color_header, "Boot test - $(BSP)")
@$(DOCKER_TEST) $(EXEC_TEST_DISPATCH) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN) @$(DOCKER_TEST) $(EXEC_TEST_DISPATCH) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN)
test: test_boot test: test_boot

@ -2,7 +2,7 @@
## ##
## Copyright (c) 2018-2022 Andre Richter <andre.o.richter@gmail.com> ## Copyright (c) 2018-2022 Andre Richter <andre.o.richter@gmail.com>
include ../common/color.mk include ../common/format.mk
include ../common/docker.mk include ../common/docker.mk
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
@ -65,10 +65,16 @@ export LD_SCRIPT_PATH
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
## Generic configuration values ## Targets and Prerequisites
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
KERNEL_LINKER_SCRIPT = link.ld KERNEL_LINKER_SCRIPT = link.ld
KERNEL_ELF = target/$(TARGET)/release/kernel
LAST_BUILD_CONFIG = target/$(BSP).build_config
KERNEL_ELF = target/$(TARGET)/release/kernel
# This parses cargo's dep-info file.
# https://doc.rust-lang.org/cargo/guide/build-cache.html#dep-info-files
KERNEL_ELF_DEPS = $(filter-out %: ,$(file < $(KERNEL_ELF_RAW).d)) $(LAST_BUILD_CONFIG)
@ -133,28 +139,41 @@ endif
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
## Targets ## Targets
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
.PHONY: all $(KERNEL_ELF) $(KERNEL_BIN) doc qemu chainboot clippy clean readelf objdump nm check .PHONY: all doc qemu chainboot clippy clean readelf objdump nm check
all: $(KERNEL_BIN) all: $(KERNEL_BIN)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the kernel ELF ## Save the configuration as a file, so make understands if it changed.
##------------------------------------------------------------------------------
$(LAST_BUILD_CONFIG):
@rm -f target/*.build_config
@mkdir -p target
@touch $(LAST_BUILD_CONFIG)
##------------------------------------------------------------------------------
## Compile the kernel ELF
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
$(KERNEL_ELF): $(KERNEL_ELF): $(KERNEL_ELF_DEPS)
$(call colorecho, "\nCompiling kernel - $(BSP)") $(call color_header, "Compiling kernel ELF - $(BSP)")
@RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD) @RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the stripped kernel binary ## Generate the stripped kernel binary
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
$(KERNEL_BIN): $(KERNEL_ELF) $(KERNEL_BIN): $(KERNEL_ELF)
$(call color_header, "Generating stripped binary")
@$(OBJCOPY_CMD) $(KERNEL_ELF) $(KERNEL_BIN) @$(OBJCOPY_CMD) $(KERNEL_ELF) $(KERNEL_BIN)
$(call color_progress_prefix, "Name")
@echo $(KERNEL_BIN)
$(call color_progress_prefix, "Size")
@printf '%s KiB\n' `du -k $(KERNEL_BIN) | cut -f1`
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the documentation ## Generate the documentation
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
doc: doc:
$(call colorecho, "\nGenerating docs") $(call color_header, "Generating docs")
@$(DOC_CMD) --document-private-items --open @$(DOC_CMD) --document-private-items --open
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
@ -163,12 +182,12 @@ doc:
ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board. ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board.
qemu: qemu:
$(call colorecho, "\n$(QEMU_MISSING_STRING)") $(call color_header, "$(QEMU_MISSING_STRING)")
else # QEMU is supported. else # QEMU is supported.
qemu: $(KERNEL_BIN) qemu: $(KERNEL_BIN)
$(call colorecho, "\nLaunching QEMU") $(call color_header, "Launching QEMU")
@$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN) @$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN)
endif endif
@ -195,14 +214,14 @@ clean:
## Run readelf ## Run readelf
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
readelf: $(KERNEL_ELF) readelf: $(KERNEL_ELF)
$(call colorecho, "\nLaunching readelf") $(call color_header, "Launching readelf")
@$(DOCKER_TOOLS) $(READELF_BINARY) --headers $(KERNEL_ELF) @$(DOCKER_TOOLS) $(READELF_BINARY) --headers $(KERNEL_ELF)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Run objdump ## Run objdump
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
objdump: $(KERNEL_ELF) objdump: $(KERNEL_ELF)
$(call colorecho, "\nLaunching objdump") $(call color_header, "Launching objdump")
@$(DOCKER_TOOLS) $(OBJDUMP_BINARY) --disassemble --demangle \ @$(DOCKER_TOOLS) $(OBJDUMP_BINARY) --disassemble --demangle \
--section .text \ --section .text \
--section .rodata \ --section .rodata \
@ -213,7 +232,7 @@ objdump: $(KERNEL_ELF)
## Run nm ## Run nm
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
nm: $(KERNEL_ELF) nm: $(KERNEL_ELF)
$(call colorecho, "\nLaunching nm") $(call color_header, "Launching nm")
@$(DOCKER_TOOLS) $(NM_BINARY) --demangle --print-size $(KERNEL_ELF) | sort | rustfilt @$(DOCKER_TOOLS) $(NM_BINARY) --demangle --print-size $(KERNEL_ELF) | sort | rustfilt
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
@ -239,7 +258,7 @@ jtagboot:
## Start OpenOCD session ## Start OpenOCD session
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
openocd: openocd:
$(call colorecho, "\nLaunching OpenOCD") $(call color_header, "Launching OpenOCD")
@$(DOCKER_OPENOCD) openocd $(OPENOCD_ARG) @$(DOCKER_OPENOCD) openocd $(OPENOCD_ARG)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
@ -248,7 +267,7 @@ openocd:
gdb: RUSTC_MISC_ARGS += -C debuginfo=2 gdb: RUSTC_MISC_ARGS += -C debuginfo=2
gdb-opt0: RUSTC_MISC_ARGS += -C debuginfo=2 -C opt-level=0 gdb-opt0: RUSTC_MISC_ARGS += -C debuginfo=2 -C opt-level=0
gdb gdb-opt0: $(KERNEL_ELF) gdb gdb-opt0: $(KERNEL_ELF)
$(call colorecho, "\nLaunching GDB") $(call color_header, "Launching GDB")
@$(DOCKER_GDB) gdb-multiarch -q $(KERNEL_ELF) @$(DOCKER_GDB) gdb-multiarch -q $(KERNEL_ELF)
@ -261,7 +280,7 @@ gdb gdb-opt0: $(KERNEL_ELF)
ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board. ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board.
test_boot test_unit test_integration test: test_boot test_unit test_integration test:
$(call colorecho, "\n$(QEMU_MISSING_STRING)") $(call color_header, "$(QEMU_MISSING_STRING)")
else # QEMU is supported. else # QEMU is supported.
@ -269,7 +288,7 @@ else # QEMU is supported.
## Run boot test ## Run boot test
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
test_boot: $(KERNEL_BIN) test_boot: $(KERNEL_BIN)
$(call colorecho, "\nBoot test - $(BSP)") $(call color_header, "Boot test - $(BSP)")
@$(DOCKER_TEST) $(EXEC_TEST_DISPATCH) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN) @$(DOCKER_TEST) $(EXEC_TEST_DISPATCH) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
@ -297,7 +316,7 @@ endef
## Run unit test(s) ## Run unit test(s)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
test_unit: test_unit:
$(call colorecho, "\nCompiling unit test(s) - $(BSP)") $(call color_header, "Compiling unit test(s) - $(BSP)")
$(call test_prepare) $(call test_prepare)
@RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(TEST_CMD) --lib @RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(TEST_CMD) --lib
@ -305,7 +324,7 @@ test_unit:
## Run integration test(s) ## Run integration test(s)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
test_integration: test_integration:
$(call colorecho, "\nCompiling integration test(s) - $(BSP)") $(call color_header, "Compiling integration test(s) - $(BSP)")
$(call test_prepare) $(call test_prepare)
@RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(TEST_CMD) $(TEST_ARG) @RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(TEST_CMD) $(TEST_ARG)

@ -415,7 +415,7 @@ endef
## Run unit test(s) ## Run unit test(s)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
test_unit: test_unit:
$(call colorecho, "\nCompiling unit test(s) - $(BSP)") $(call color_header, "Compiling unit test(s) - $(BSP)")
$(call test_prepare) $(call test_prepare)
@RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(TEST_CMD) --lib @RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(TEST_CMD) --lib
``` ```
@ -1006,7 +1006,7 @@ diff -uNr 11_exceptions_part1_groundwork/Makefile 12_integrated_testing/Makefile
OBJDUMP_BINARY = aarch64-none-elf-objdump OBJDUMP_BINARY = aarch64-none-elf-objdump
NM_BINARY = aarch64-none-elf-nm NM_BINARY = aarch64-none-elf-nm
READELF_BINARY = aarch64-none-elf-readelf READELF_BINARY = aarch64-none-elf-readelf
@@ -83,6 +92,7 @@ @@ -89,6 +98,7 @@
DOC_CMD = cargo doc $(COMPILER_ARGS) DOC_CMD = cargo doc $(COMPILER_ARGS)
CLIPPY_CMD = cargo clippy $(COMPILER_ARGS) CLIPPY_CMD = cargo clippy $(COMPILER_ARGS)
CHECK_CMD = cargo check $(COMPILER_ARGS) CHECK_CMD = cargo check $(COMPILER_ARGS)
@ -1014,7 +1014,7 @@ diff -uNr 11_exceptions_part1_groundwork/Makefile 12_integrated_testing/Makefile
OBJCOPY_CMD = rust-objcopy \ OBJCOPY_CMD = rust-objcopy \
--strip-all \ --strip-all \
-O binary -O binary
@@ -246,11 +256,11 @@ @@ -265,11 +275,11 @@
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
## Testing targets ## Testing targets
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
@ -1023,13 +1023,13 @@ diff -uNr 11_exceptions_part1_groundwork/Makefile 12_integrated_testing/Makefile
ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board. ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board.
-test_boot test : -test_boot test:
+test_boot test_unit test_integration test: +test_boot test_unit test_integration test:
$(call colorecho, "\n$(QEMU_MISSING_STRING)") $(call color_header, "$(QEMU_MISSING_STRING)")
else # QEMU is supported. else # QEMU is supported.
@@ -262,6 +272,43 @@ @@ -281,6 +291,43 @@
$(call colorecho, "\nBoot test - $(BSP)") $(call color_header, "Boot test - $(BSP)")
@$(DOCKER_TEST) $(EXEC_TEST_DISPATCH) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN) @$(DOCKER_TEST) $(EXEC_TEST_DISPATCH) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN)
-test: test_boot -test: test_boot
@ -1058,7 +1058,7 @@ diff -uNr 11_exceptions_part1_groundwork/Makefile 12_integrated_testing/Makefile
+## Run unit test(s) +## Run unit test(s)
+##------------------------------------------------------------------------------ +##------------------------------------------------------------------------------
+test_unit: +test_unit:
+ $(call colorecho, "\nCompiling unit test(s) - $(BSP)") + $(call color_header, "Compiling unit test(s) - $(BSP)")
+ $(call test_prepare) + $(call test_prepare)
+ @RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(TEST_CMD) --lib + @RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(TEST_CMD) --lib
+ +
@ -1066,7 +1066,7 @@ diff -uNr 11_exceptions_part1_groundwork/Makefile 12_integrated_testing/Makefile
+## Run integration test(s) +## Run integration test(s)
+##------------------------------------------------------------------------------ +##------------------------------------------------------------------------------
+test_integration: +test_integration:
+ $(call colorecho, "\nCompiling integration test(s) - $(BSP)") + $(call color_header, "Compiling integration test(s) - $(BSP)")
+ $(call test_prepare) + $(call test_prepare)
+ @RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(TEST_CMD) $(TEST_ARG) + @RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(TEST_CMD) $(TEST_ARG)
+ +

@ -2,7 +2,7 @@
## ##
## Copyright (c) 2018-2022 Andre Richter <andre.o.richter@gmail.com> ## Copyright (c) 2018-2022 Andre Richter <andre.o.richter@gmail.com>
include ../common/color.mk include ../common/format.mk
include ../common/docker.mk include ../common/docker.mk
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
@ -65,10 +65,16 @@ export LD_SCRIPT_PATH
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
## Generic configuration values ## Targets and Prerequisites
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
KERNEL_LINKER_SCRIPT = link.ld KERNEL_LINKER_SCRIPT = link.ld
KERNEL_ELF = target/$(TARGET)/release/kernel
LAST_BUILD_CONFIG = target/$(BSP).build_config
KERNEL_ELF = target/$(TARGET)/release/kernel
# This parses cargo's dep-info file.
# https://doc.rust-lang.org/cargo/guide/build-cache.html#dep-info-files
KERNEL_ELF_DEPS = $(filter-out %: ,$(file < $(KERNEL_ELF_RAW).d)) $(LAST_BUILD_CONFIG)
@ -133,28 +139,41 @@ endif
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
## Targets ## Targets
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
.PHONY: all $(KERNEL_ELF) $(KERNEL_BIN) doc qemu chainboot clippy clean readelf objdump nm check .PHONY: all doc qemu chainboot clippy clean readelf objdump nm check
all: $(KERNEL_BIN) all: $(KERNEL_BIN)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the kernel ELF ## Save the configuration as a file, so make understands if it changed.
##------------------------------------------------------------------------------
$(LAST_BUILD_CONFIG):
@rm -f target/*.build_config
@mkdir -p target
@touch $(LAST_BUILD_CONFIG)
##------------------------------------------------------------------------------
## Compile the kernel ELF
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
$(KERNEL_ELF): $(KERNEL_ELF): $(KERNEL_ELF_DEPS)
$(call colorecho, "\nCompiling kernel - $(BSP)") $(call color_header, "Compiling kernel ELF - $(BSP)")
@RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD) @RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the stripped kernel binary ## Generate the stripped kernel binary
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
$(KERNEL_BIN): $(KERNEL_ELF) $(KERNEL_BIN): $(KERNEL_ELF)
$(call color_header, "Generating stripped binary")
@$(OBJCOPY_CMD) $(KERNEL_ELF) $(KERNEL_BIN) @$(OBJCOPY_CMD) $(KERNEL_ELF) $(KERNEL_BIN)
$(call color_progress_prefix, "Name")
@echo $(KERNEL_BIN)
$(call color_progress_prefix, "Size")
@printf '%s KiB\n' `du -k $(KERNEL_BIN) | cut -f1`
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the documentation ## Generate the documentation
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
doc: doc:
$(call colorecho, "\nGenerating docs") $(call color_header, "Generating docs")
@$(DOC_CMD) --document-private-items --open @$(DOC_CMD) --document-private-items --open
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
@ -163,12 +182,12 @@ doc:
ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board. ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board.
qemu: qemu:
$(call colorecho, "\n$(QEMU_MISSING_STRING)") $(call color_header, "$(QEMU_MISSING_STRING)")
else # QEMU is supported. else # QEMU is supported.
qemu: $(KERNEL_BIN) qemu: $(KERNEL_BIN)
$(call colorecho, "\nLaunching QEMU") $(call color_header, "Launching QEMU")
@$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN) @$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN)
endif endif
@ -195,14 +214,14 @@ clean:
## Run readelf ## Run readelf
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
readelf: $(KERNEL_ELF) readelf: $(KERNEL_ELF)
$(call colorecho, "\nLaunching readelf") $(call color_header, "Launching readelf")
@$(DOCKER_TOOLS) $(READELF_BINARY) --headers $(KERNEL_ELF) @$(DOCKER_TOOLS) $(READELF_BINARY) --headers $(KERNEL_ELF)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Run objdump ## Run objdump
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
objdump: $(KERNEL_ELF) objdump: $(KERNEL_ELF)
$(call colorecho, "\nLaunching objdump") $(call color_header, "Launching objdump")
@$(DOCKER_TOOLS) $(OBJDUMP_BINARY) --disassemble --demangle \ @$(DOCKER_TOOLS) $(OBJDUMP_BINARY) --disassemble --demangle \
--section .text \ --section .text \
--section .rodata \ --section .rodata \
@ -213,7 +232,7 @@ objdump: $(KERNEL_ELF)
## Run nm ## Run nm
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
nm: $(KERNEL_ELF) nm: $(KERNEL_ELF)
$(call colorecho, "\nLaunching nm") $(call color_header, "Launching nm")
@$(DOCKER_TOOLS) $(NM_BINARY) --demangle --print-size $(KERNEL_ELF) | sort | rustfilt @$(DOCKER_TOOLS) $(NM_BINARY) --demangle --print-size $(KERNEL_ELF) | sort | rustfilt
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
@ -239,7 +258,7 @@ jtagboot:
## Start OpenOCD session ## Start OpenOCD session
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
openocd: openocd:
$(call colorecho, "\nLaunching OpenOCD") $(call color_header, "Launching OpenOCD")
@$(DOCKER_OPENOCD) openocd $(OPENOCD_ARG) @$(DOCKER_OPENOCD) openocd $(OPENOCD_ARG)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
@ -248,7 +267,7 @@ openocd:
gdb: RUSTC_MISC_ARGS += -C debuginfo=2 gdb: RUSTC_MISC_ARGS += -C debuginfo=2
gdb-opt0: RUSTC_MISC_ARGS += -C debuginfo=2 -C opt-level=0 gdb-opt0: RUSTC_MISC_ARGS += -C debuginfo=2 -C opt-level=0
gdb gdb-opt0: $(KERNEL_ELF) gdb gdb-opt0: $(KERNEL_ELF)
$(call colorecho, "\nLaunching GDB") $(call color_header, "Launching GDB")
@$(DOCKER_GDB) gdb-multiarch -q $(KERNEL_ELF) @$(DOCKER_GDB) gdb-multiarch -q $(KERNEL_ELF)
@ -261,7 +280,7 @@ gdb gdb-opt0: $(KERNEL_ELF)
ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board. ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board.
test_boot test_unit test_integration test: test_boot test_unit test_integration test:
$(call colorecho, "\n$(QEMU_MISSING_STRING)") $(call color_header, "$(QEMU_MISSING_STRING)")
else # QEMU is supported. else # QEMU is supported.
@ -269,7 +288,7 @@ else # QEMU is supported.
## Run boot test ## Run boot test
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
test_boot: $(KERNEL_BIN) test_boot: $(KERNEL_BIN)
$(call colorecho, "\nBoot test - $(BSP)") $(call color_header, "Boot test - $(BSP)")
@$(DOCKER_TEST) $(EXEC_TEST_DISPATCH) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN) @$(DOCKER_TEST) $(EXEC_TEST_DISPATCH) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
@ -297,7 +316,7 @@ endef
## Run unit test(s) ## Run unit test(s)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
test_unit: test_unit:
$(call colorecho, "\nCompiling unit test(s) - $(BSP)") $(call color_header, "Compiling unit test(s) - $(BSP)")
$(call test_prepare) $(call test_prepare)
@RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(TEST_CMD) --lib @RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(TEST_CMD) --lib
@ -305,7 +324,7 @@ test_unit:
## Run integration test(s) ## Run integration test(s)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
test_integration: test_integration:
$(call colorecho, "\nCompiling integration test(s) - $(BSP)") $(call color_header, "Compiling integration test(s) - $(BSP)")
$(call test_prepare) $(call test_prepare)
@RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(TEST_CMD) $(TEST_ARG) @RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(TEST_CMD) $(TEST_ARG)

@ -2,7 +2,7 @@
## ##
## Copyright (c) 2018-2022 Andre Richter <andre.o.richter@gmail.com> ## Copyright (c) 2018-2022 Andre Richter <andre.o.richter@gmail.com>
include ../common/color.mk include ../common/format.mk
include ../common/docker.mk include ../common/docker.mk
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
@ -65,10 +65,16 @@ export LD_SCRIPT_PATH
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
## Generic configuration values ## Targets and Prerequisites
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
KERNEL_LINKER_SCRIPT = link.ld KERNEL_LINKER_SCRIPT = link.ld
KERNEL_ELF = target/$(TARGET)/release/kernel
LAST_BUILD_CONFIG = target/$(BSP).build_config
KERNEL_ELF = target/$(TARGET)/release/kernel
# This parses cargo's dep-info file.
# https://doc.rust-lang.org/cargo/guide/build-cache.html#dep-info-files
KERNEL_ELF_DEPS = $(filter-out %: ,$(file < $(KERNEL_ELF_RAW).d)) $(LAST_BUILD_CONFIG)
@ -133,28 +139,41 @@ endif
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
## Targets ## Targets
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
.PHONY: all $(KERNEL_ELF) $(KERNEL_BIN) doc qemu chainboot clippy clean readelf objdump nm check .PHONY: all doc qemu chainboot clippy clean readelf objdump nm check
all: $(KERNEL_BIN) all: $(KERNEL_BIN)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the kernel ELF ## Save the configuration as a file, so make understands if it changed.
##------------------------------------------------------------------------------
$(LAST_BUILD_CONFIG):
@rm -f target/*.build_config
@mkdir -p target
@touch $(LAST_BUILD_CONFIG)
##------------------------------------------------------------------------------
## Compile the kernel ELF
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
$(KERNEL_ELF): $(KERNEL_ELF): $(KERNEL_ELF_DEPS)
$(call colorecho, "\nCompiling kernel - $(BSP)") $(call color_header, "Compiling kernel ELF - $(BSP)")
@RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD) @RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the stripped kernel binary ## Generate the stripped kernel binary
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
$(KERNEL_BIN): $(KERNEL_ELF) $(KERNEL_BIN): $(KERNEL_ELF)
$(call color_header, "Generating stripped binary")
@$(OBJCOPY_CMD) $(KERNEL_ELF) $(KERNEL_BIN) @$(OBJCOPY_CMD) $(KERNEL_ELF) $(KERNEL_BIN)
$(call color_progress_prefix, "Name")
@echo $(KERNEL_BIN)
$(call color_progress_prefix, "Size")
@printf '%s KiB\n' `du -k $(KERNEL_BIN) | cut -f1`
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the documentation ## Generate the documentation
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
doc: doc:
$(call colorecho, "\nGenerating docs") $(call color_header, "Generating docs")
@$(DOC_CMD) --document-private-items --open @$(DOC_CMD) --document-private-items --open
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
@ -163,12 +182,12 @@ doc:
ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board. ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board.
qemu: qemu:
$(call colorecho, "\n$(QEMU_MISSING_STRING)") $(call color_header, "$(QEMU_MISSING_STRING)")
else # QEMU is supported. else # QEMU is supported.
qemu: $(KERNEL_BIN) qemu: $(KERNEL_BIN)
$(call colorecho, "\nLaunching QEMU") $(call color_header, "Launching QEMU")
@$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN) @$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN)
endif endif
@ -195,14 +214,14 @@ clean:
## Run readelf ## Run readelf
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
readelf: $(KERNEL_ELF) readelf: $(KERNEL_ELF)
$(call colorecho, "\nLaunching readelf") $(call color_header, "Launching readelf")
@$(DOCKER_TOOLS) $(READELF_BINARY) --headers $(KERNEL_ELF) @$(DOCKER_TOOLS) $(READELF_BINARY) --headers $(KERNEL_ELF)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Run objdump ## Run objdump
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
objdump: $(KERNEL_ELF) objdump: $(KERNEL_ELF)
$(call colorecho, "\nLaunching objdump") $(call color_header, "Launching objdump")
@$(DOCKER_TOOLS) $(OBJDUMP_BINARY) --disassemble --demangle \ @$(DOCKER_TOOLS) $(OBJDUMP_BINARY) --disassemble --demangle \
--section .text \ --section .text \
--section .rodata \ --section .rodata \
@ -213,7 +232,7 @@ objdump: $(KERNEL_ELF)
## Run nm ## Run nm
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
nm: $(KERNEL_ELF) nm: $(KERNEL_ELF)
$(call colorecho, "\nLaunching nm") $(call color_header, "Launching nm")
@$(DOCKER_TOOLS) $(NM_BINARY) --demangle --print-size $(KERNEL_ELF) | sort | rustfilt @$(DOCKER_TOOLS) $(NM_BINARY) --demangle --print-size $(KERNEL_ELF) | sort | rustfilt
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
@ -239,7 +258,7 @@ jtagboot:
## Start OpenOCD session ## Start OpenOCD session
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
openocd: openocd:
$(call colorecho, "\nLaunching OpenOCD") $(call color_header, "Launching OpenOCD")
@$(DOCKER_OPENOCD) openocd $(OPENOCD_ARG) @$(DOCKER_OPENOCD) openocd $(OPENOCD_ARG)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
@ -248,7 +267,7 @@ openocd:
gdb: RUSTC_MISC_ARGS += -C debuginfo=2 gdb: RUSTC_MISC_ARGS += -C debuginfo=2
gdb-opt0: RUSTC_MISC_ARGS += -C debuginfo=2 -C opt-level=0 gdb-opt0: RUSTC_MISC_ARGS += -C debuginfo=2 -C opt-level=0
gdb gdb-opt0: $(KERNEL_ELF) gdb gdb-opt0: $(KERNEL_ELF)
$(call colorecho, "\nLaunching GDB") $(call color_header, "Launching GDB")
@$(DOCKER_GDB) gdb-multiarch -q $(KERNEL_ELF) @$(DOCKER_GDB) gdb-multiarch -q $(KERNEL_ELF)
@ -261,7 +280,7 @@ gdb gdb-opt0: $(KERNEL_ELF)
ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board. ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board.
test_boot test_unit test_integration test: test_boot test_unit test_integration test:
$(call colorecho, "\n$(QEMU_MISSING_STRING)") $(call color_header, "$(QEMU_MISSING_STRING)")
else # QEMU is supported. else # QEMU is supported.
@ -269,7 +288,7 @@ else # QEMU is supported.
## Run boot test ## Run boot test
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
test_boot: $(KERNEL_BIN) test_boot: $(KERNEL_BIN)
$(call colorecho, "\nBoot test - $(BSP)") $(call color_header, "Boot test - $(BSP)")
@$(DOCKER_TEST) $(EXEC_TEST_DISPATCH) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN) @$(DOCKER_TEST) $(EXEC_TEST_DISPATCH) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
@ -297,7 +316,7 @@ endef
## Run unit test(s) ## Run unit test(s)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
test_unit: test_unit:
$(call colorecho, "\nCompiling unit test(s) - $(BSP)") $(call color_header, "Compiling unit test(s) - $(BSP)")
$(call test_prepare) $(call test_prepare)
@RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(TEST_CMD) --lib @RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(TEST_CMD) --lib
@ -305,7 +324,7 @@ test_unit:
## Run integration test(s) ## Run integration test(s)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
test_integration: test_integration:
$(call colorecho, "\nCompiling integration test(s) - $(BSP)") $(call color_header, "Compiling integration test(s) - $(BSP)")
$(call test_prepare) $(call test_prepare)
@RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(TEST_CMD) $(TEST_ARG) @RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(TEST_CMD) $(TEST_ARG)

@ -2,7 +2,7 @@
## ##
## Copyright (c) 2018-2022 Andre Richter <andre.o.richter@gmail.com> ## Copyright (c) 2018-2022 Andre Richter <andre.o.richter@gmail.com>
include ../common/color.mk include ../common/format.mk
include ../common/docker.mk include ../common/docker.mk
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
@ -65,10 +65,23 @@ export LD_SCRIPT_PATH
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
## Generic configuration values ## Targets and Prerequisites
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
KERNEL_LINKER_SCRIPT = link.ld KERNEL_LINKER_SCRIPT = link.ld
KERNEL_ELF = target/$(TARGET)/release/kernel
TT_TOOL_PATH = translation_table_tool
LAST_BUILD_CONFIG = target/$(BSP).build_config
KERNEL_ELF_RAW = target/$(TARGET)/release/kernel
# This parses cargo's dep-info file.
# https://doc.rust-lang.org/cargo/guide/build-cache.html#dep-info-files
KERNEL_ELF_RAW_DEPS = $(filter-out %: ,$(file < $(KERNEL_ELF_RAW).d)) $(LAST_BUILD_CONFIG)
KERNEL_ELF_TTABLES = target/$(TARGET)/release/kernel+ttables
KERNEL_ELF_TTABLES_DEPS = $(KERNEL_ELF_RAW) $(wildcard $(TT_TOOL_PATH)/*)
KERNEL_ELF = $(KERNEL_ELF_TTABLES)
@ -98,7 +111,7 @@ OBJCOPY_CMD = rust-objcopy \
-O binary -O binary
EXEC_QEMU = $(QEMU_BINARY) -M $(QEMU_MACHINE_TYPE) EXEC_QEMU = $(QEMU_BINARY) -M $(QEMU_MACHINE_TYPE)
EXEC_TT_TOOL = ruby translation_table_tool/main.rb EXEC_TT_TOOL = ruby $(TT_TOOL_PATH)/main.rb
EXEC_TEST_DISPATCH = ruby ../common/tests/dispatch.rb EXEC_TEST_DISPATCH = ruby ../common/tests/dispatch.rb
EXEC_MINIPUSH = ruby ../common/serial/minipush.rb EXEC_MINIPUSH = ruby ../common/serial/minipush.rb
@ -134,29 +147,49 @@ endif
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
## Targets ## Targets
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
.PHONY: all $(KERNEL_ELF) $(KERNEL_BIN) doc qemu chainboot clippy clean readelf objdump nm check .PHONY: all doc qemu chainboot clippy clean readelf objdump nm check
all: $(KERNEL_BIN) all: $(KERNEL_BIN)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the kernel ELF ## Save the configuration as a file, so make understands if it changed.
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
$(KERNEL_ELF): $(LAST_BUILD_CONFIG):
$(call colorecho, "\nCompiling kernel - $(BSP)") @rm -f target/*.build_config
@mkdir -p target
@touch $(LAST_BUILD_CONFIG)
##------------------------------------------------------------------------------
## Compile the kernel ELF
##------------------------------------------------------------------------------
$(KERNEL_ELF_RAW): $(KERNEL_ELF_RAW_DEPS)
$(call color_header, "Compiling kernel ELF - $(BSP)")
@RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD) @RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD)
@$(DOCKER_TOOLS) $(EXEC_TT_TOOL) $(TARGET) $(BSP) $(KERNEL_ELF)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the stripped kernel binary ## Precompute the kernel translation tables and patch them into the kernel ELF
##------------------------------------------------------------------------------
$(KERNEL_ELF_TTABLES): $(KERNEL_ELF_TTABLES_DEPS)
$(call color_header, "Precomputing kernel translation tables and patching kernel ELF")
@cp $(KERNEL_ELF_RAW) $(KERNEL_ELF_TTABLES)
@$(DOCKER_TOOLS) $(EXEC_TT_TOOL) $(TARGET) $(BSP) $(KERNEL_ELF_TTABLES)
##------------------------------------------------------------------------------
## Generate the stripped kernel binary
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
$(KERNEL_BIN): $(KERNEL_ELF) $(KERNEL_BIN): $(KERNEL_ELF_TTABLES)
@$(OBJCOPY_CMD) $(KERNEL_ELF) $(KERNEL_BIN) $(call color_header, "Generating stripped binary")
@$(OBJCOPY_CMD) $(KERNEL_ELF_TTABLES) $(KERNEL_BIN)
$(call color_progress_prefix, "Name")
@echo $(KERNEL_BIN)
$(call color_progress_prefix, "Size")
@printf '%s KiB\n' `du -k $(KERNEL_BIN) | cut -f1`
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the documentation ## Generate the documentation
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
doc: doc:
$(call colorecho, "\nGenerating docs") $(call color_header, "Generating docs")
@$(DOC_CMD) --document-private-items --open @$(DOC_CMD) --document-private-items --open
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
@ -165,12 +198,12 @@ doc:
ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board. ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board.
qemu: qemu:
$(call colorecho, "\n$(QEMU_MISSING_STRING)") $(call color_header, "$(QEMU_MISSING_STRING)")
else # QEMU is supported. else # QEMU is supported.
qemu: $(KERNEL_BIN) qemu: $(KERNEL_BIN)
$(call colorecho, "\nLaunching QEMU") $(call color_header, "Launching QEMU")
@$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN) @$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN)
endif endif
@ -197,14 +230,14 @@ clean:
## Run readelf ## Run readelf
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
readelf: $(KERNEL_ELF) readelf: $(KERNEL_ELF)
$(call colorecho, "\nLaunching readelf") $(call color_header, "Launching readelf")
@$(DOCKER_TOOLS) $(READELF_BINARY) --headers $(KERNEL_ELF) @$(DOCKER_TOOLS) $(READELF_BINARY) --headers $(KERNEL_ELF)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Run objdump ## Run objdump
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
objdump: $(KERNEL_ELF) objdump: $(KERNEL_ELF)
$(call colorecho, "\nLaunching objdump") $(call color_header, "Launching objdump")
@$(DOCKER_TOOLS) $(OBJDUMP_BINARY) --disassemble --demangle \ @$(DOCKER_TOOLS) $(OBJDUMP_BINARY) --disassemble --demangle \
--section .text \ --section .text \
--section .rodata \ --section .rodata \
@ -215,7 +248,7 @@ objdump: $(KERNEL_ELF)
## Run nm ## Run nm
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
nm: $(KERNEL_ELF) nm: $(KERNEL_ELF)
$(call colorecho, "\nLaunching nm") $(call color_header, "Launching nm")
@$(DOCKER_TOOLS) $(NM_BINARY) --demangle --print-size $(KERNEL_ELF) | sort | rustfilt @$(DOCKER_TOOLS) $(NM_BINARY) --demangle --print-size $(KERNEL_ELF) | sort | rustfilt
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
@ -241,7 +274,7 @@ jtagboot:
## Start OpenOCD session ## Start OpenOCD session
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
openocd: openocd:
$(call colorecho, "\nLaunching OpenOCD") $(call color_header, "Launching OpenOCD")
@$(DOCKER_OPENOCD) openocd $(OPENOCD_ARG) @$(DOCKER_OPENOCD) openocd $(OPENOCD_ARG)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
@ -250,7 +283,7 @@ openocd:
gdb: RUSTC_MISC_ARGS += -C debuginfo=2 gdb: RUSTC_MISC_ARGS += -C debuginfo=2
gdb-opt0: RUSTC_MISC_ARGS += -C debuginfo=2 -C opt-level=0 gdb-opt0: RUSTC_MISC_ARGS += -C debuginfo=2 -C opt-level=0
gdb gdb-opt0: $(KERNEL_ELF) gdb gdb-opt0: $(KERNEL_ELF)
$(call colorecho, "\nLaunching GDB") $(call color_header, "Launching GDB")
@$(DOCKER_GDB) gdb-multiarch -q $(KERNEL_ELF) @$(DOCKER_GDB) gdb-multiarch -q $(KERNEL_ELF)
@ -263,7 +296,7 @@ gdb gdb-opt0: $(KERNEL_ELF)
ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board. ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board.
test_boot test_unit test_integration test: test_boot test_unit test_integration test:
$(call colorecho, "\n$(QEMU_MISSING_STRING)") $(call color_header, "$(QEMU_MISSING_STRING)")
else # QEMU is supported. else # QEMU is supported.
@ -271,7 +304,7 @@ else # QEMU is supported.
## Run boot test ## Run boot test
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
test_boot: $(KERNEL_BIN) test_boot: $(KERNEL_BIN)
$(call colorecho, "\nBoot test - $(BSP)") $(call color_header, "Boot test - $(BSP)")
@$(DOCKER_TEST) $(EXEC_TEST_DISPATCH) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN) @$(DOCKER_TEST) $(EXEC_TEST_DISPATCH) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
@ -300,7 +333,7 @@ endef
## Run unit test(s) ## Run unit test(s)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
test_unit: test_unit:
$(call colorecho, "\nCompiling unit test(s) - $(BSP)") $(call color_header, "Compiling unit test(s) - $(BSP)")
$(call test_prepare) $(call test_prepare)
@RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(TEST_CMD) --lib @RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(TEST_CMD) --lib
@ -308,7 +341,7 @@ test_unit:
## Run integration test(s) ## Run integration test(s)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
test_integration: test_integration:
$(call colorecho, "\nCompiling integration test(s) - $(BSP)") $(call color_header, "Compiling integration test(s) - $(BSP)")
$(call test_prepare) $(call test_prepare)
@RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(TEST_CMD) $(TEST_ARG) @RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(TEST_CMD) $(TEST_ARG)

@ -564,19 +564,42 @@ might have been possible to write this tool in Rust as well, and borrow/share th
with the kernel. But in the end, I found it not worth the effort for the few lines of code. with the kernel. But in the end, I found it not worth the effort for the few lines of code.
In the `Makefile`, the tool is invoked after compiling and linking the kernel, and before the In the `Makefile`, the tool is invoked after compiling and linking the kernel, and before the
`objcopy`. It's command line arguments are the target `BSP` type and the path to the kernel's `ELF` `stripped binary` is generated. It's command line arguments are the target `BSP` type and the path
file: to the kernel's `ELF` file:
```Makefile ```Makefile
all: $(KERNEL_BIN) TT_TOOL_PATH = translation_table_tool
$(KERNEL_ELF): KERNEL_ELF_RAW = target/$(TARGET)/release/kernel
$(call colorecho, "\nCompiling kernel - $(BSP)") # [...]
KERNEL_ELF_TTABLES = target/$(TARGET)/release/kernel+ttables
# [...]
EXEC_TT_TOOL = ruby $(TT_TOOL_PATH)/main.rb
# [...]
##------------------------------------------------------------------------------
## Compile the kernel ELF
##------------------------------------------------------------------------------
$(KERNEL_ELF_RAW): $(KERNEL_ELF_RAW_DEPS)
$(call color_header, "Compiling kernel ELF - $(BSP)")
@RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD) @RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD)
@$(DOCKER_TOOLS) ruby translation_table_tool/main.rb $(TARGET) $(BSP) $(KERNEL_ELF)
$(KERNEL_BIN): $(KERNEL_ELF) ##------------------------------------------------------------------------------
@$(OBJCOPY_CMD) $(KERNEL_ELF) $(KERNEL_BIN) ## Precompute the kernel translation tables and patch them into the kernel ELF
##------------------------------------------------------------------------------
$(KERNEL_ELF_TTABLES): $(KERNEL_ELF_TTABLES_DEPS)
$(call color_header, "Precomputing kernel translation tables and patching kernel ELF")
@cp $(KERNEL_ELF_RAW) $(KERNEL_ELF_TTABLES)
@$(DOCKER_TOOLS) $(EXEC_TT_TOOL) $(TARGET) $(BSP) $(KERNEL_ELF_TTABLES)
##------------------------------------------------------------------------------
## Generate the stripped kernel binary
##------------------------------------------------------------------------------
$(KERNEL_BIN): $(KERNEL_ELF_TTABLES)
$(call color_header, "Generating stripped binary")
@$(OBJCOPY_CMD) $(KERNEL_ELF_TTABLES) $(KERNEL_BIN)
``` ```
In `main.rb`, the `KERNEL_ELF` instance for handling the `ELF` file is created first, followed by In `main.rb`, the `KERNEL_ELF` instance for handling the `ELF` file is created first, followed by
@ -788,23 +811,65 @@ diff -uNr 14_virtual_mem_part2_mmio_remap/Cargo.toml 15_virtual_mem_part3_precom
diff -uNr 14_virtual_mem_part2_mmio_remap/Makefile 15_virtual_mem_part3_precomputed_tables/Makefile diff -uNr 14_virtual_mem_part2_mmio_remap/Makefile 15_virtual_mem_part3_precomputed_tables/Makefile
--- 14_virtual_mem_part2_mmio_remap/Makefile --- 14_virtual_mem_part2_mmio_remap/Makefile
+++ 15_virtual_mem_part3_precomputed_tables/Makefile +++ 15_virtual_mem_part3_precomputed_tables/Makefile
@@ -98,6 +98,7 @@ @@ -69,12 +69,19 @@
##--------------------------------------------------------------------------------------------------
KERNEL_LINKER_SCRIPT = link.ld
+TT_TOOL_PATH = translation_table_tool
+
LAST_BUILD_CONFIG = target/$(BSP).build_config
-KERNEL_ELF = target/$(TARGET)/release/kernel
+KERNEL_ELF_RAW = target/$(TARGET)/release/kernel
# This parses cargo's dep-info file.
# https://doc.rust-lang.org/cargo/guide/build-cache.html#dep-info-files
-KERNEL_ELF_DEPS = $(filter-out modulo: ,$(file < $(KERNEL_ELF_RAW).d)) $(LAST_BUILD_CONFIG)
+KERNEL_ELF_RAW_DEPS = $(filter-out modulo: ,$(file < $(KERNEL_ELF_RAW).d)) $(LAST_BUILD_CONFIG)
+
+KERNEL_ELF_TTABLES = target/$(TARGET)/release/kernel+ttables
+KERNEL_ELF_TTABLES_DEPS = $(KERNEL_ELF_RAW) $(wildcard $(TT_TOOL_PATH)/*)
+
+KERNEL_ELF = $(KERNEL_ELF_TTABLES)
@@ -104,6 +111,7 @@
-O binary -O binary
EXEC_QEMU = $(QEMU_BINARY) -M $(QEMU_MACHINE_TYPE) EXEC_QEMU = $(QEMU_BINARY) -M $(QEMU_MACHINE_TYPE)
+EXEC_TT_TOOL = ruby translation_table_tool/main.rb +EXEC_TT_TOOL = ruby $(TT_TOOL_PATH)/main.rb
EXEC_TEST_DISPATCH = ruby ../common/tests/dispatch.rb EXEC_TEST_DISPATCH = ruby ../common/tests/dispatch.rb
EXEC_MINIPUSH = ruby ../common/serial/minipush.rb EXEC_MINIPUSH = ruby ../common/serial/minipush.rb
@@ -143,6 +144,7 @@ @@ -154,16 +162,24 @@
$(KERNEL_ELF): ##------------------------------------------------------------------------------
$(call colorecho, "\nCompiling kernel - $(BSP)") ## Compile the kernel ELF
##------------------------------------------------------------------------------
-$(KERNEL_ELF): $(KERNEL_ELF_DEPS)
+$(KERNEL_ELF_RAW): $(KERNEL_ELF_RAW_DEPS)
$(call color_header, "Compiling kernel ELF - $(BSP)")
@RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD) @RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD)
+ @$(DOCKER_TOOLS) $(EXEC_TT_TOOL) $(TARGET) $(BSP) $(KERNEL_ELF)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the stripped kernel binary +## Precompute the kernel translation tables and patch them into the kernel ELF
@@ -281,6 +283,7 @@ +##------------------------------------------------------------------------------
+$(KERNEL_ELF_TTABLES): $(KERNEL_ELF_TTABLES_DEPS)
+ $(call color_header, "Precomputing kernel translation tables and patching kernel ELF")
+ @cp $(KERNEL_ELF_RAW) $(KERNEL_ELF_TTABLES)
+ @$(DOCKER_TOOLS) $(EXEC_TT_TOOL) $(TARGET) $(BSP) $(KERNEL_ELF_TTABLES)
+
+##------------------------------------------------------------------------------
## Generate the stripped kernel binary
##------------------------------------------------------------------------------
-$(KERNEL_BIN): $(KERNEL_ELF)
+$(KERNEL_BIN): $(KERNEL_ELF_TTABLES)
$(call color_header, "Generating stripped binary")
- @$(OBJCOPY_CMD) $(KERNEL_ELF) $(KERNEL_BIN)
+ @$(OBJCOPY_CMD) $(KERNEL_ELF_TTABLES) $(KERNEL_BIN)
$(call color_progress_prefix, "Name")
@echo $(KERNEL_BIN)
$(call color_progress_prefix, "Size")
@@ -300,6 +316,7 @@
TEST_ELF=$$(echo $$1 | sed -e 's/.*target/target/g') TEST_ELF=$$(echo $$1 | sed -e 's/.*target/target/g')
TEST_BINARY=$$(echo $$1.img | sed -e 's/.*target/target/g') TEST_BINARY=$$(echo $$1.img | sed -e 's/.*target/target/g')
@ -2490,7 +2555,7 @@ diff -uNr 14_virtual_mem_part2_mmio_remap/translation_table_tool/kernel_elf.rb 1
diff -uNr 14_virtual_mem_part2_mmio_remap/translation_table_tool/main.rb 15_virtual_mem_part3_precomputed_tables/translation_table_tool/main.rb diff -uNr 14_virtual_mem_part2_mmio_remap/translation_table_tool/main.rb 15_virtual_mem_part3_precomputed_tables/translation_table_tool/main.rb
--- 14_virtual_mem_part2_mmio_remap/translation_table_tool/main.rb --- 14_virtual_mem_part2_mmio_remap/translation_table_tool/main.rb
+++ 15_virtual_mem_part3_precomputed_tables/translation_table_tool/main.rb +++ 15_virtual_mem_part3_precomputed_tables/translation_table_tool/main.rb
@@ -0,0 +1,50 @@ @@ -0,0 +1,47 @@
+#!/usr/bin/env ruby +#!/usr/bin/env ruby
+# frozen_string_literal: true +# frozen_string_literal: true
+ +
@ -2512,9 +2577,6 @@ diff -uNr 14_virtual_mem_part2_mmio_remap/translation_table_tool/main.rb 15_virt
+require_relative 'bsp' +require_relative 'bsp'
+require_relative 'arch' +require_relative 'arch'
+ +
+puts
+puts 'Precomputing kernel translation tables and patching kernel ELF'.cyan
+
+start = Time.now +start = Time.now
+ +
+KERNEL_ELF = KernelELF.new(kernel_elf_path) +KERNEL_ELF = KernelELF.new(kernel_elf_path)

@ -19,9 +19,6 @@ require_relative 'kernel_elf'
require_relative 'bsp' require_relative 'bsp'
require_relative 'arch' require_relative 'arch'
puts
puts 'Precomputing kernel translation tables and patching kernel ELF'.cyan
start = Time.now start = Time.now
KERNEL_ELF = KernelELF.new(kernel_elf_path) KERNEL_ELF = KernelELF.new(kernel_elf_path)

@ -2,7 +2,7 @@
## ##
## Copyright (c) 2018-2022 Andre Richter <andre.o.richter@gmail.com> ## Copyright (c) 2018-2022 Andre Richter <andre.o.richter@gmail.com>
include ../common/color.mk include ../common/format.mk
include ../common/docker.mk include ../common/docker.mk
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
@ -65,10 +65,23 @@ export LD_SCRIPT_PATH
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
## Generic configuration values ## Targets and Prerequisites
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
KERNEL_LINKER_SCRIPT = link.ld KERNEL_LINKER_SCRIPT = link.ld
KERNEL_ELF = target/$(TARGET)/release/kernel
TT_TOOL_PATH = translation_table_tool
LAST_BUILD_CONFIG = target/$(BSP).build_config
KERNEL_ELF_RAW = target/$(TARGET)/release/kernel
# This parses cargo's dep-info file.
# https://doc.rust-lang.org/cargo/guide/build-cache.html#dep-info-files
KERNEL_ELF_RAW_DEPS = $(filter-out %: ,$(file < $(KERNEL_ELF_RAW).d)) $(LAST_BUILD_CONFIG)
KERNEL_ELF_TTABLES = target/$(TARGET)/release/kernel+ttables
KERNEL_ELF_TTABLES_DEPS = $(KERNEL_ELF_RAW) $(wildcard $(TT_TOOL_PATH)/*)
KERNEL_ELF = $(KERNEL_ELF_TTABLES)
@ -98,7 +111,7 @@ OBJCOPY_CMD = rust-objcopy \
-O binary -O binary
EXEC_QEMU = $(QEMU_BINARY) -M $(QEMU_MACHINE_TYPE) EXEC_QEMU = $(QEMU_BINARY) -M $(QEMU_MACHINE_TYPE)
EXEC_TT_TOOL = ruby translation_table_tool/main.rb EXEC_TT_TOOL = ruby $(TT_TOOL_PATH)/main.rb
EXEC_TEST_DISPATCH = ruby ../common/tests/dispatch.rb EXEC_TEST_DISPATCH = ruby ../common/tests/dispatch.rb
EXEC_MINIPUSH = ruby ../common/serial/minipush.rb EXEC_MINIPUSH = ruby ../common/serial/minipush.rb
@ -134,29 +147,49 @@ endif
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
## Targets ## Targets
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
.PHONY: all $(KERNEL_ELF) $(KERNEL_BIN) doc qemu chainboot clippy clean readelf objdump nm check .PHONY: all doc qemu chainboot clippy clean readelf objdump nm check
all: $(KERNEL_BIN) all: $(KERNEL_BIN)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the kernel ELF ## Save the configuration as a file, so make understands if it changed.
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
$(KERNEL_ELF): $(LAST_BUILD_CONFIG):
$(call colorecho, "\nCompiling kernel - $(BSP)") @rm -f target/*.build_config
@mkdir -p target
@touch $(LAST_BUILD_CONFIG)
##------------------------------------------------------------------------------
## Compile the kernel ELF
##------------------------------------------------------------------------------
$(KERNEL_ELF_RAW): $(KERNEL_ELF_RAW_DEPS)
$(call color_header, "Compiling kernel ELF - $(BSP)")
@RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD) @RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD)
@$(DOCKER_TOOLS) $(EXEC_TT_TOOL) $(TARGET) $(BSP) $(KERNEL_ELF)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the stripped kernel binary ## Precompute the kernel translation tables and patch them into the kernel ELF
##------------------------------------------------------------------------------
$(KERNEL_ELF_TTABLES): $(KERNEL_ELF_TTABLES_DEPS)
$(call color_header, "Precomputing kernel translation tables and patching kernel ELF")
@cp $(KERNEL_ELF_RAW) $(KERNEL_ELF_TTABLES)
@$(DOCKER_TOOLS) $(EXEC_TT_TOOL) $(TARGET) $(BSP) $(KERNEL_ELF_TTABLES)
##------------------------------------------------------------------------------
## Generate the stripped kernel binary
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
$(KERNEL_BIN): $(KERNEL_ELF) $(KERNEL_BIN): $(KERNEL_ELF_TTABLES)
@$(OBJCOPY_CMD) $(KERNEL_ELF) $(KERNEL_BIN) $(call color_header, "Generating stripped binary")
@$(OBJCOPY_CMD) $(KERNEL_ELF_TTABLES) $(KERNEL_BIN)
$(call color_progress_prefix, "Name")
@echo $(KERNEL_BIN)
$(call color_progress_prefix, "Size")
@printf '%s KiB\n' `du -k $(KERNEL_BIN) | cut -f1`
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the documentation ## Generate the documentation
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
doc: doc:
$(call colorecho, "\nGenerating docs") $(call color_header, "Generating docs")
@$(DOC_CMD) --document-private-items --open @$(DOC_CMD) --document-private-items --open
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
@ -165,12 +198,12 @@ doc:
ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board. ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board.
qemu: qemu:
$(call colorecho, "\n$(QEMU_MISSING_STRING)") $(call color_header, "$(QEMU_MISSING_STRING)")
else # QEMU is supported. else # QEMU is supported.
qemu: $(KERNEL_BIN) qemu: $(KERNEL_BIN)
$(call colorecho, "\nLaunching QEMU") $(call color_header, "Launching QEMU")
@$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN) @$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN)
endif endif
@ -197,14 +230,14 @@ clean:
## Run readelf ## Run readelf
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
readelf: $(KERNEL_ELF) readelf: $(KERNEL_ELF)
$(call colorecho, "\nLaunching readelf") $(call color_header, "Launching readelf")
@$(DOCKER_TOOLS) $(READELF_BINARY) --headers $(KERNEL_ELF) @$(DOCKER_TOOLS) $(READELF_BINARY) --headers $(KERNEL_ELF)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Run objdump ## Run objdump
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
objdump: $(KERNEL_ELF) objdump: $(KERNEL_ELF)
$(call colorecho, "\nLaunching objdump") $(call color_header, "Launching objdump")
@$(DOCKER_TOOLS) $(OBJDUMP_BINARY) --disassemble --demangle \ @$(DOCKER_TOOLS) $(OBJDUMP_BINARY) --disassemble --demangle \
--section .text \ --section .text \
--section .rodata \ --section .rodata \
@ -215,7 +248,7 @@ objdump: $(KERNEL_ELF)
## Run nm ## Run nm
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
nm: $(KERNEL_ELF) nm: $(KERNEL_ELF)
$(call colorecho, "\nLaunching nm") $(call color_header, "Launching nm")
@$(DOCKER_TOOLS) $(NM_BINARY) --demangle --print-size $(KERNEL_ELF) | sort | rustfilt @$(DOCKER_TOOLS) $(NM_BINARY) --demangle --print-size $(KERNEL_ELF) | sort | rustfilt
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
@ -241,7 +274,7 @@ jtagboot:
## Start OpenOCD session ## Start OpenOCD session
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
openocd: openocd:
$(call colorecho, "\nLaunching OpenOCD") $(call color_header, "Launching OpenOCD")
@$(DOCKER_OPENOCD) openocd $(OPENOCD_ARG) @$(DOCKER_OPENOCD) openocd $(OPENOCD_ARG)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
@ -250,7 +283,7 @@ openocd:
gdb: RUSTC_MISC_ARGS += -C debuginfo=2 gdb: RUSTC_MISC_ARGS += -C debuginfo=2
gdb-opt0: RUSTC_MISC_ARGS += -C debuginfo=2 -C opt-level=0 gdb-opt0: RUSTC_MISC_ARGS += -C debuginfo=2 -C opt-level=0
gdb gdb-opt0: $(KERNEL_ELF) gdb gdb-opt0: $(KERNEL_ELF)
$(call colorecho, "\nLaunching GDB") $(call color_header, "Launching GDB")
@$(DOCKER_GDB) gdb-multiarch -q $(KERNEL_ELF) @$(DOCKER_GDB) gdb-multiarch -q $(KERNEL_ELF)
@ -263,7 +296,7 @@ gdb gdb-opt0: $(KERNEL_ELF)
ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board. ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board.
test_boot test_unit test_integration test: test_boot test_unit test_integration test:
$(call colorecho, "\n$(QEMU_MISSING_STRING)") $(call color_header, "$(QEMU_MISSING_STRING)")
else # QEMU is supported. else # QEMU is supported.
@ -271,7 +304,7 @@ else # QEMU is supported.
## Run boot test ## Run boot test
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
test_boot: $(KERNEL_BIN) test_boot: $(KERNEL_BIN)
$(call colorecho, "\nBoot test - $(BSP)") $(call color_header, "Boot test - $(BSP)")
@$(DOCKER_TEST) $(EXEC_TEST_DISPATCH) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN) @$(DOCKER_TEST) $(EXEC_TEST_DISPATCH) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
@ -300,7 +333,7 @@ endef
## Run unit test(s) ## Run unit test(s)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
test_unit: test_unit:
$(call colorecho, "\nCompiling unit test(s) - $(BSP)") $(call color_header, "Compiling unit test(s) - $(BSP)")
$(call test_prepare) $(call test_prepare)
@RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(TEST_CMD) --lib @RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(TEST_CMD) --lib
@ -308,7 +341,7 @@ test_unit:
## Run integration test(s) ## Run integration test(s)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
test_integration: test_integration:
$(call colorecho, "\nCompiling integration test(s) - $(BSP)") $(call color_header, "Compiling integration test(s) - $(BSP)")
$(call test_prepare) $(call test_prepare)
@RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(TEST_CMD) $(TEST_ARG) @RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(TEST_CMD) $(TEST_ARG)

@ -19,9 +19,6 @@ require_relative 'kernel_elf'
require_relative 'bsp' require_relative 'bsp'
require_relative 'arch' require_relative 'arch'
puts
puts 'Precomputing kernel translation tables and patching kernel ELF'.cyan
start = Time.now start = Time.now
KERNEL_ELF = KernelELF.new(kernel_elf_path) KERNEL_ELF = KernelELF.new(kernel_elf_path)

@ -2,7 +2,7 @@
## ##
## Copyright (c) 2018-2022 Andre Richter <andre.o.richter@gmail.com> ## Copyright (c) 2018-2022 Andre Richter <andre.o.richter@gmail.com>
include ../common/color.mk include ../common/format.mk
include ../common/docker.mk include ../common/docker.mk
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
@ -52,10 +52,16 @@ export LD_SCRIPT_PATH
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
## Generic configuration values ## Targets and Prerequisites
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
KERNEL_LINKER_SCRIPT = link.ld KERNEL_LINKER_SCRIPT = link.ld
KERNEL_ELF = target/$(TARGET)/release/kernel
LAST_BUILD_CONFIG = target/$(BSP).build_config
KERNEL_ELF = target/$(TARGET)/release/kernel
# This parses cargo's dep-info file.
# https://doc.rust-lang.org/cargo/guide/build-cache.html#dep-info-files
KERNEL_ELF_DEPS = $(filter-out %: ,$(file < $(KERNEL_ELF_RAW).d)) $(LAST_BUILD_CONFIG)
@ -112,28 +118,41 @@ endif
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
## Targets ## Targets
##-------------------------------------------------------------------------------------------------- ##--------------------------------------------------------------------------------------------------
.PHONY: all $(KERNEL_ELF) $(KERNEL_BIN) doc qemu chainboot clippy clean readelf objdump nm check .PHONY: all doc qemu chainboot clippy clean readelf objdump nm check
all: $(KERNEL_BIN) all: $(KERNEL_BIN)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the kernel ELF ## Save the configuration as a file, so make understands if it changed.
##------------------------------------------------------------------------------
$(LAST_BUILD_CONFIG):
@rm -f target/*.build_config
@mkdir -p target
@touch $(LAST_BUILD_CONFIG)
##------------------------------------------------------------------------------
## Compile the kernel ELF
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
$(KERNEL_ELF): $(KERNEL_ELF): $(KERNEL_ELF_DEPS)
$(call colorecho, "\nCompiling kernel - $(BSP)") $(call color_header, "Compiling kernel ELF - $(BSP)")
@RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD) @RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the stripped kernel binary ## Generate the stripped kernel binary
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
$(KERNEL_BIN): $(KERNEL_ELF) $(KERNEL_BIN): $(KERNEL_ELF)
$(call color_header, "Generating stripped binary")
@$(OBJCOPY_CMD) $(KERNEL_ELF) $(KERNEL_BIN) @$(OBJCOPY_CMD) $(KERNEL_ELF) $(KERNEL_BIN)
$(call color_progress_prefix, "Name")
@echo $(KERNEL_BIN)
$(call color_progress_prefix, "Size")
@printf '%s KiB\n' `du -k $(KERNEL_BIN) | cut -f1`
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Build the documentation ## Generate the documentation
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
doc: doc:
$(call colorecho, "\nGenerating docs") $(call color_header, "Generating docs")
@$(DOC_CMD) --document-private-items --open @$(DOC_CMD) --document-private-items --open
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
@ -142,12 +161,12 @@ doc:
ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board. ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board.
qemu: qemu:
$(call colorecho, "\n$(QEMU_MISSING_STRING)") $(call color_header, "$(QEMU_MISSING_STRING)")
else # QEMU is supported. else # QEMU is supported.
qemu: $(KERNEL_BIN) qemu: $(KERNEL_BIN)
$(call colorecho, "\nLaunching QEMU") $(call color_header, "Launching QEMU")
@$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN) @$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN)
endif endif
@ -174,14 +193,14 @@ clean:
## Run readelf ## Run readelf
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
readelf: $(KERNEL_ELF) readelf: $(KERNEL_ELF)
$(call colorecho, "\nLaunching readelf") $(call color_header, "Launching readelf")
@$(DOCKER_TOOLS) $(READELF_BINARY) --headers $(KERNEL_ELF) @$(DOCKER_TOOLS) $(READELF_BINARY) --headers $(KERNEL_ELF)
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## Run objdump ## Run objdump
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
objdump: $(KERNEL_ELF) objdump: $(KERNEL_ELF)
$(call colorecho, "\nLaunching objdump") $(call color_header, "Launching objdump")
@$(DOCKER_TOOLS) $(OBJDUMP_BINARY) --disassemble --demangle \ @$(DOCKER_TOOLS) $(OBJDUMP_BINARY) --disassemble --demangle \
--section .text \ --section .text \
--section .rodata \ --section .rodata \
@ -192,7 +211,7 @@ objdump: $(KERNEL_ELF)
## Run nm ## Run nm
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
nm: $(KERNEL_ELF) nm: $(KERNEL_ELF)
$(call colorecho, "\nLaunching nm") $(call color_header, "Launching nm")
@$(DOCKER_TOOLS) $(NM_BINARY) --demangle --print-size $(KERNEL_ELF) | sort | rustfilt @$(DOCKER_TOOLS) $(NM_BINARY) --demangle --print-size $(KERNEL_ELF) | sort | rustfilt
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
@ -210,8 +229,8 @@ check:
ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board. ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board.
test_boot test : test_boot test:
$(call colorecho, "\n$(QEMU_MISSING_STRING)") $(call color_header, "$(QEMU_MISSING_STRING)")
else # QEMU is supported. else # QEMU is supported.
@ -219,7 +238,7 @@ else # QEMU is supported.
## Run boot test ## Run boot test
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
test_boot: $(KERNEL_BIN) test_boot: $(KERNEL_BIN)
$(call colorecho, "\nBoot test - $(BSP)") $(call color_header, "Boot test - $(BSP)")
@$(DOCKER_TEST) $(EXEC_TEST_DISPATCH) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN) @$(DOCKER_TEST) $(EXEC_TEST_DISPATCH) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN)
test: test_boot test: test_boot

@ -1,5 +0,0 @@
define colorecho
@tput setaf 6 2> /dev/null || true
@echo $1
@tput sgr0 2> /dev/null || true
endef

@ -0,0 +1,12 @@
define color_header
@tput setaf 6 2> /dev/null || true
@printf '\n%s\n' $(1)
@tput sgr0 2> /dev/null || true
endef
define color_progress_prefix
@tput setaf 2 2> /dev/null || true
@tput bold 2 2> /dev/null || true
@printf '%12s ' $(1)
@tput sgr0 2> /dev/null || true
endef
Loading…
Cancel
Save