|
|
|
@ -6,9 +6,9 @@ include ../common/docker.mk
|
|
|
|
|
include ../common/format.mk
|
|
|
|
|
include ../common/operating_system.mk
|
|
|
|
|
|
|
|
|
|
##--------------------------------------------------------------------------------------------------
|
|
|
|
|
## --------------------------------------------------------------------------------------------------
|
|
|
|
|
## Optional, user-provided configuration values
|
|
|
|
|
##--------------------------------------------------------------------------------------------------
|
|
|
|
|
## --------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
# Default to the RPi3.
|
|
|
|
|
BSP ?= rpi3
|
|
|
|
@ -30,9 +30,9 @@ endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
##--------------------------------------------------------------------------------------------------
|
|
|
|
|
## --------------------------------------------------------------------------------------------------
|
|
|
|
|
## BSP-specific configuration values
|
|
|
|
|
##--------------------------------------------------------------------------------------------------
|
|
|
|
|
## --------------------------------------------------------------------------------------------------
|
|
|
|
|
QEMU_MISSING_STRING = "This board is not yet supported for QEMU."
|
|
|
|
|
|
|
|
|
|
ifeq ($(BSP),rpi3)
|
|
|
|
@ -70,9 +70,9 @@ export LD_SCRIPT_PATH
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
##--------------------------------------------------------------------------------------------------
|
|
|
|
|
## --------------------------------------------------------------------------------------------------
|
|
|
|
|
## Targets and Prerequisites
|
|
|
|
|
##--------------------------------------------------------------------------------------------------
|
|
|
|
|
## --------------------------------------------------------------------------------------------------
|
|
|
|
|
KERNEL_MANIFEST = kernel/Cargo.toml
|
|
|
|
|
KERNEL_LINKER_SCRIPT = kernel.ld
|
|
|
|
|
LAST_BUILD_CONFIG = target/$(BSP)_$(DEBUG_PRINTS).build_config
|
|
|
|
@ -82,17 +82,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
|
|
|
|
@ -111,9 +111,9 @@ KERNEL_ELF = $(KERNEL_ELF_TTABLES_SYMS)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
##--------------------------------------------------------------------------------------------------
|
|
|
|
|
## --------------------------------------------------------------------------------------------------
|
|
|
|
|
## Command building blocks
|
|
|
|
|
##--------------------------------------------------------------------------------------------------
|
|
|
|
|
## --------------------------------------------------------------------------------------------------
|
|
|
|
|
RUSTFLAGS = $(RUSTC_MISC_ARGS) \
|
|
|
|
|
-C link-arg=--library-path=$(LD_SCRIPT_PATH) \
|
|
|
|
|
-C link-arg=--script=$(KERNEL_LINKER_SCRIPT)
|
|
|
|
@ -142,9 +142,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
|
|
|
|
@ -171,46 +171,46 @@ endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
##--------------------------------------------------------------------------------------------------
|
|
|
|
|
## --------------------------------------------------------------------------------------------------
|
|
|
|
|
## Targets
|
|
|
|
|
##--------------------------------------------------------------------------------------------------
|
|
|
|
|
## --------------------------------------------------------------------------------------------------
|
|
|
|
|
.PHONY: all doc qemu chainboot clippy clean readelf objdump nm check
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
@ -219,16 +219,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:
|
|
|
|
@ -242,36 +242,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 \
|
|
|
|
@ -279,36 +279,36 @@ 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
##--------------------------------------------------------------------------------------------------
|
|
|
|
|
## --------------------------------------------------------------------------------------------------
|
|
|
|
|
## Debugging targets
|
|
|
|
|
##--------------------------------------------------------------------------------------------------
|
|
|
|
|
## --------------------------------------------------------------------------------------------------
|
|
|
|
|
.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")
|
|
|
|
@ -316,9 +316,9 @@ gdb gdb-opt0: $(KERNEL_ELF)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
##--------------------------------------------------------------------------------------------------
|
|
|
|
|
## --------------------------------------------------------------------------------------------------
|
|
|
|
|
## Testing targets
|
|
|
|
|
##--------------------------------------------------------------------------------------------------
|
|
|
|
|
## --------------------------------------------------------------------------------------------------
|
|
|
|
|
.PHONY: test test_boot test_unit test_integration
|
|
|
|
|
|
|
|
|
|
test_unit test_integration: FEATURES += --features test_build
|
|
|
|
@ -330,16 +330,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
|
|
|
|
|
|
|
|
|
@ -372,17 +372,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)
|
|
|
|
|