|
|
|
@ -77,17 +77,17 @@ KERNEL_ELF_RAW = target/$(TARGET)/release/kernel
|
|
|
|
|
# https://doc.rust-lang.org/cargo/guide/build-cache.html#dep-info-files
|
|
|
|
|
KERNEL_ELF_RAW_DEPS = $(filter-out %: ,$(file < $(KERNEL_ELF_RAW).d)) $(KERNEL_MANIFEST) $(LAST_BUILD_CONFIG)
|
|
|
|
|
|
|
|
|
|
## ------------------------------------------------------------------------------
|
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
|
## Translation tables
|
|
|
|
|
## ------------------------------------------------------------------------------
|
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
|
TT_TOOL_PATH = tools/translation_table_tool
|
|
|
|
|
|
|
|
|
|
KERNEL_ELF_TTABLES = target/$(TARGET)/release/kernel+ttables
|
|
|
|
|
KERNEL_ELF_TTABLES_DEPS = $(KERNEL_ELF_RAW) $(wildcard $(TT_TOOL_PATH)/*)
|
|
|
|
|
|
|
|
|
|
## ------------------------------------------------------------------------------
|
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
|
## Kernel symbols
|
|
|
|
|
## ------------------------------------------------------------------------------
|
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
|
export KERNEL_SYMBOLS_TOOL_PATH = tools/kernel_symbols_tool
|
|
|
|
|
|
|
|
|
|
KERNEL_ELF_TTABLES_SYMS = target/$(TARGET)/release/kernel+ttables+symbols
|
|
|
|
@ -137,9 +137,9 @@ EXEC_TT_TOOL = ruby $(TT_TOOL_PATH)/main.rb
|
|
|
|
|
EXEC_TEST_DISPATCH = ruby ../common/tests/dispatch.rb
|
|
|
|
|
EXEC_MINIPUSH = ruby ../common/serial/minipush.rb
|
|
|
|
|
|
|
|
|
|
## ------------------------------------------------------------------------------
|
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
|
## Dockerization
|
|
|
|
|
## ------------------------------------------------------------------------------
|
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
|
DOCKER_CMD = docker run -t --rm -v $(shell pwd):/work/tutorial -w /work/tutorial
|
|
|
|
|
DOCKER_CMD_INTERACT = $(DOCKER_CMD) -i
|
|
|
|
|
DOCKER_ARG_DIR_COMMON = -v $(shell pwd)/../common:/work/common
|
|
|
|
@ -173,39 +173,39 @@ endif
|
|
|
|
|
|
|
|
|
|
all: $(KERNEL_BIN)
|
|
|
|
|
|
|
|
|
|
## ------------------------------------------------------------------------------
|
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
|
## 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_RAW): $(KERNEL_ELF_RAW_DEPS)
|
|
|
|
|
$(call color_header, "Compiling kernel ELF - $(BSP)")
|
|
|
|
|
@RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD)
|
|
|
|
|
|
|
|
|
|
## ------------------------------------------------------------------------------
|
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
|
## 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) $(BSP) $(KERNEL_ELF_TTABLES)
|
|
|
|
|
|
|
|
|
|
## ------------------------------------------------------------------------------
|
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
|
## Generate kernel symbols and patch them into the kernel ELF
|
|
|
|
|
## ------------------------------------------------------------------------------
|
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
|
$(KERNEL_ELF_TTABLES_SYMS): $(KERNEL_ELF_TTABLES_SYMS_DEPS)
|
|
|
|
|
$(call color_header, "Generating kernel symbols and patching kernel ELF")
|
|
|
|
|
@$(MAKE) --no-print-directory -f kernel_symbols.mk
|
|
|
|
|
|
|
|
|
|
## ------------------------------------------------------------------------------
|
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
|
## Generate the stripped kernel binary
|
|
|
|
|
## ------------------------------------------------------------------------------
|
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
|
$(KERNEL_BIN): $(KERNEL_ELF_TTABLES_SYMS)
|
|
|
|
|
$(call color_header, "Generating stripped binary")
|
|
|
|
|
@$(OBJCOPY_CMD) $(KERNEL_ELF_TTABLES_SYMS) $(KERNEL_BIN)
|
|
|
|
@ -214,16 +214,16 @@ $(KERNEL_BIN): $(KERNEL_ELF_TTABLES_SYMS)
|
|
|
|
|
$(call color_progress_prefix, "Size")
|
|
|
|
|
$(call disk_usage_KiB, $(KERNEL_BIN))
|
|
|
|
|
|
|
|
|
|
## ------------------------------------------------------------------------------
|
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
|
## Generate the documentation
|
|
|
|
|
## ------------------------------------------------------------------------------
|
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
|
doc: clean
|
|
|
|
|
$(call color_header, "Generating docs")
|
|
|
|
|
@$(DOC_CMD) --document-private-items --open
|
|
|
|
|
|
|
|
|
|
## ------------------------------------------------------------------------------
|
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
|
## Run the kernel in QEMU
|
|
|
|
|
## ------------------------------------------------------------------------------
|
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
|
ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board.
|
|
|
|
|
|
|
|
|
|
qemu:
|
|
|
|
@ -237,36 +237,36 @@ qemu: $(KERNEL_BIN)
|
|
|
|
|
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
## ------------------------------------------------------------------------------
|
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
|
## Push the kernel to the real HW target
|
|
|
|
|
## ------------------------------------------------------------------------------
|
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
|
chainboot: $(KERNEL_BIN)
|
|
|
|
|
@$(DOCKER_CHAINBOOT) $(EXEC_MINIPUSH) $(DEV_SERIAL) $(KERNEL_BIN)
|
|
|
|
|
|
|
|
|
|
## ------------------------------------------------------------------------------
|
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
|
## Run clippy
|
|
|
|
|
## ------------------------------------------------------------------------------
|
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
|
clippy:
|
|
|
|
|
@RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(CLIPPY_CMD)
|
|
|
|
|
@RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(CLIPPY_CMD) --features test_build --tests \
|
|
|
|
|
--manifest-path $(KERNEL_MANIFEST)
|
|
|
|
|
|
|
|
|
|
## ------------------------------------------------------------------------------
|
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
|
## Clean
|
|
|
|
|
## ------------------------------------------------------------------------------
|
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
|
clean:
|
|
|
|
|
rm -rf target $(KERNEL_BIN)
|
|
|
|
|
|
|
|
|
|
## ------------------------------------------------------------------------------
|
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
|
## Run readelf
|
|
|
|
|
## ------------------------------------------------------------------------------
|
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
|
readelf: $(KERNEL_ELF)
|
|
|
|
|
$(call color_header, "Launching readelf")
|
|
|
|
|
@$(DOCKER_TOOLS) $(READELF_BINARY) --headers $(KERNEL_ELF)
|
|
|
|
|
|
|
|
|
|
## ------------------------------------------------------------------------------
|
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
|
## Run objdump
|
|
|
|
|
## ------------------------------------------------------------------------------
|
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
|
objdump: $(KERNEL_ELF)
|
|
|
|
|
$(call color_header, "Launching objdump")
|
|
|
|
|
@$(DOCKER_TOOLS) $(OBJDUMP_BINARY) --disassemble --demangle \
|
|
|
|
@ -274,9 +274,9 @@ objdump: $(KERNEL_ELF)
|
|
|
|
|
--section .rodata \
|
|
|
|
|
$(KERNEL_ELF) | rustfilt
|
|
|
|
|
|
|
|
|
|
## ------------------------------------------------------------------------------
|
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
|
## Run nm
|
|
|
|
|
## ------------------------------------------------------------------------------
|
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
|
nm: $(KERNEL_ELF)
|
|
|
|
|
$(call color_header, "Launching nm")
|
|
|
|
|
@$(DOCKER_TOOLS) $(NM_BINARY) --demangle --print-size $(KERNEL_ELF) | sort | rustfilt
|
|
|
|
@ -288,22 +288,22 @@ nm: $(KERNEL_ELF)
|
|
|
|
|
##--------------------------------------------------------------------------------------------------
|
|
|
|
|
.PHONY: jtagboot openocd gdb gdb-opt0
|
|
|
|
|
|
|
|
|
|
## ------------------------------------------------------------------------------
|
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
|
## Push the JTAG boot image to the real HW target
|
|
|
|
|
## ------------------------------------------------------------------------------
|
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
|
jtagboot:
|
|
|
|
|
@$(DOCKER_JTAGBOOT) $(EXEC_MINIPUSH) $(DEV_SERIAL) $(JTAG_BOOT_IMAGE)
|
|
|
|
|
|
|
|
|
|
## ------------------------------------------------------------------------------
|
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
|
## Start OpenOCD session
|
|
|
|
|
## ------------------------------------------------------------------------------
|
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
|
openocd:
|
|
|
|
|
$(call color_header, "Launching OpenOCD")
|
|
|
|
|
@$(DOCKER_OPENOCD) openocd $(OPENOCD_ARG)
|
|
|
|
|
|
|
|
|
|
## ------------------------------------------------------------------------------
|
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
|
## Start GDB session
|
|
|
|
|
## ------------------------------------------------------------------------------
|
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
|
gdb-opt0: RUSTC_MISC_ARGS += -C opt-level=0
|
|
|
|
|
gdb gdb-opt0: $(KERNEL_ELF)
|
|
|
|
|
$(call color_header, "Launching GDB")
|
|
|
|
@ -325,16 +325,16 @@ test_boot test_unit test_integration test:
|
|
|
|
|
|
|
|
|
|
else # QEMU is supported.
|
|
|
|
|
|
|
|
|
|
## ------------------------------------------------------------------------------
|
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
|
## Run boot test
|
|
|
|
|
## ------------------------------------------------------------------------------
|
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
|
test_boot: $(KERNEL_BIN)
|
|
|
|
|
$(call color_header, "Boot test - $(BSP)")
|
|
|
|
|
@$(DOCKER_TEST) $(EXEC_TEST_DISPATCH) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN)
|
|
|
|
|
|
|
|
|
|
## ------------------------------------------------------------------------------
|
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
|
## Helpers for unit and integration test targets
|
|
|
|
|
## ------------------------------------------------------------------------------
|
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
|
define KERNEL_TEST_RUNNER
|
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
|
@ -367,17 +367,17 @@ define test_prepare
|
|
|
|
|
@chmod +x target/kernel_test_runner.sh
|
|
|
|
|
endef
|
|
|
|
|
|
|
|
|
|
## ------------------------------------------------------------------------------
|
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
|
## Run unit test(s)
|
|
|
|
|
## ------------------------------------------------------------------------------
|
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
|
test_unit:
|
|
|
|
|
$(call color_header, "Compiling unit test(s) - $(BSP)")
|
|
|
|
|
$(call test_prepare)
|
|
|
|
|
@RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(TEST_CMD) --lib
|
|
|
|
|
|
|
|
|
|
## ------------------------------------------------------------------------------
|
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
|
## Run integration test(s)
|
|
|
|
|
## ------------------------------------------------------------------------------
|
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
|
test_integration:
|
|
|
|
|
$(call color_header, "Compiling integration test(s) - $(BSP)")
|
|
|
|
|
$(call test_prepare)
|
|
|
|
|