2019-12-30 23:04:13 +00:00
|
|
|
## SPDX-License-Identifier: MIT OR Apache-2.0
|
|
|
|
##
|
2023-09-15 12:22:15 +00:00
|
|
|
## Copyright (c) 2018-2023 Andre Richter <andre.o.richter@gmail.com>
|
2019-12-30 23:04:13 +00:00
|
|
|
|
2021-11-13 12:12:10 +00:00
|
|
|
include ../common/docker.mk
|
2022-10-24 20:15:48 +00:00
|
|
|
include ../common/format.mk
|
|
|
|
include ../common/operating_system.mk
|
2021-03-12 22:44:10 +00:00
|
|
|
|
2021-07-12 20:08:22 +00:00
|
|
|
##--------------------------------------------------------------------------------------------------
|
|
|
|
## Optional, user-provided configuration values
|
|
|
|
##--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
# Default to the RPi3.
|
2020-04-12 20:22:29 +00:00
|
|
|
BSP ?= rpi3
|
2019-12-30 23:04:13 +00:00
|
|
|
|
2020-04-11 10:22:52 +00:00
|
|
|
# Default to a serial device name that is common in Linux.
|
2020-04-12 20:22:29 +00:00
|
|
|
DEV_SERIAL ?= /dev/ttyUSB0
|
2020-01-14 19:45:41 +00:00
|
|
|
|
2021-07-12 20:08:22 +00:00
|
|
|
# Optional integration test name.
|
|
|
|
ifdef TEST
|
|
|
|
TEST_ARG = --test $(TEST)
|
|
|
|
else
|
|
|
|
TEST_ARG = --test '*'
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
2020-04-11 10:22:52 +00:00
|
|
|
|
2021-07-12 20:08:22 +00:00
|
|
|
##--------------------------------------------------------------------------------------------------
|
2022-04-11 20:24:18 +00:00
|
|
|
## BSP-specific configuration values
|
2021-07-12 20:08:22 +00:00
|
|
|
##--------------------------------------------------------------------------------------------------
|
2022-04-11 20:24:18 +00:00
|
|
|
QEMU_MISSING_STRING = "This board is not yet supported for QEMU."
|
2021-07-12 20:08:22 +00:00
|
|
|
|
2019-12-30 23:04:13 +00:00
|
|
|
ifeq ($(BSP),rpi3)
|
2020-04-12 20:22:29 +00:00
|
|
|
TARGET = aarch64-unknown-none-softfloat
|
2020-04-16 20:46:11 +00:00
|
|
|
KERNEL_BIN = kernel8.img
|
2020-04-12 20:22:29 +00:00
|
|
|
QEMU_BINARY = qemu-system-aarch64
|
|
|
|
QEMU_MACHINE_TYPE = raspi3
|
|
|
|
QEMU_RELEASE_ARGS = -serial stdio -display none
|
|
|
|
QEMU_TEST_ARGS = $(QEMU_RELEASE_ARGS) -semihosting
|
2020-11-01 14:54:11 +00:00
|
|
|
OBJDUMP_BINARY = aarch64-none-elf-objdump
|
|
|
|
NM_BINARY = aarch64-none-elf-nm
|
2021-03-12 22:44:10 +00:00
|
|
|
READELF_BINARY = aarch64-none-elf-readelf
|
2020-04-12 20:22:29 +00:00
|
|
|
OPENOCD_ARG = -f /openocd/tcl/interface/ftdi/olimex-arm-usb-tiny-h.cfg -f /openocd/rpi3.cfg
|
|
|
|
JTAG_BOOT_IMAGE = ../X1_JTAG_boot/jtag_boot_rpi3.img
|
2022-04-19 20:44:01 +00:00
|
|
|
LD_SCRIPT_PATH = $(shell pwd)/kernel/src/bsp/raspberrypi
|
2020-04-12 20:22:29 +00:00
|
|
|
RUSTC_MISC_ARGS = -C target-cpu=cortex-a53
|
2019-12-30 23:04:13 +00:00
|
|
|
else ifeq ($(BSP),rpi4)
|
2020-04-12 20:22:29 +00:00
|
|
|
TARGET = aarch64-unknown-none-softfloat
|
2020-04-16 20:46:11 +00:00
|
|
|
KERNEL_BIN = kernel8.img
|
2020-04-12 20:22:29 +00:00
|
|
|
QEMU_BINARY = qemu-system-aarch64
|
|
|
|
QEMU_MACHINE_TYPE =
|
|
|
|
QEMU_RELEASE_ARGS = -serial stdio -display none
|
|
|
|
QEMU_TEST_ARGS = $(QEMU_RELEASE_ARGS) -semihosting
|
2020-11-01 14:54:11 +00:00
|
|
|
OBJDUMP_BINARY = aarch64-none-elf-objdump
|
|
|
|
NM_BINARY = aarch64-none-elf-nm
|
2021-03-12 22:44:10 +00:00
|
|
|
READELF_BINARY = aarch64-none-elf-readelf
|
2020-04-12 20:22:29 +00:00
|
|
|
OPENOCD_ARG = -f /openocd/tcl/interface/ftdi/olimex-arm-usb-tiny-h.cfg -f /openocd/rpi4.cfg
|
|
|
|
JTAG_BOOT_IMAGE = ../X1_JTAG_boot/jtag_boot_rpi4.img
|
2022-04-19 20:44:01 +00:00
|
|
|
LD_SCRIPT_PATH = $(shell pwd)/kernel/src/bsp/raspberrypi
|
2020-04-12 20:22:29 +00:00
|
|
|
RUSTC_MISC_ARGS = -C target-cpu=cortex-a72
|
2019-12-30 23:04:13 +00:00
|
|
|
endif
|
|
|
|
|
2021-07-12 20:08:22 +00:00
|
|
|
# Export for build.rs.
|
2022-04-11 20:24:18 +00:00
|
|
|
export LD_SCRIPT_PATH
|
|
|
|
|
2020-04-14 21:16:35 +00:00
|
|
|
|
2022-04-11 20:24:18 +00:00
|
|
|
|
|
|
|
##--------------------------------------------------------------------------------------------------
|
2022-04-12 19:54:53 +00:00
|
|
|
## Targets and Prerequisites
|
2022-04-11 20:24:18 +00:00
|
|
|
##--------------------------------------------------------------------------------------------------
|
2022-04-19 20:44:01 +00:00
|
|
|
KERNEL_MANIFEST = kernel/Cargo.toml
|
2022-04-19 07:09:09 +00:00
|
|
|
KERNEL_LINKER_SCRIPT = kernel.ld
|
2022-04-19 20:44:01 +00:00
|
|
|
LAST_BUILD_CONFIG = target/$(BSP).build_config
|
2022-04-12 19:54:53 +00:00
|
|
|
|
|
|
|
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
|
2022-06-27 09:06:06 +00:00
|
|
|
KERNEL_ELF_DEPS = $(filter-out %: ,$(file < $(KERNEL_ELF).d)) $(KERNEL_MANIFEST) $(LAST_BUILD_CONFIG)
|
2021-07-12 20:08:22 +00:00
|
|
|
|
2019-12-30 23:04:13 +00:00
|
|
|
|
|
|
|
|
2021-07-12 20:08:22 +00:00
|
|
|
##--------------------------------------------------------------------------------------------------
|
|
|
|
## Command building blocks
|
|
|
|
##--------------------------------------------------------------------------------------------------
|
2022-04-11 20:24:18 +00:00
|
|
|
RUSTFLAGS = $(RUSTC_MISC_ARGS) \
|
|
|
|
-C link-arg=--library-path=$(LD_SCRIPT_PATH) \
|
|
|
|
-C link-arg=--script=$(KERNEL_LINKER_SCRIPT)
|
|
|
|
|
|
|
|
RUSTFLAGS_PEDANTIC = $(RUSTFLAGS) \
|
|
|
|
-D warnings \
|
|
|
|
-D missing_docs
|
2019-12-30 23:04:13 +00:00
|
|
|
|
2021-03-11 22:14:08 +00:00
|
|
|
FEATURES = --features bsp_$(BSP)
|
2020-04-07 21:17:48 +00:00
|
|
|
COMPILER_ARGS = --target=$(TARGET) \
|
2021-03-11 22:14:08 +00:00
|
|
|
$(FEATURES) \
|
2020-04-12 20:22:29 +00:00
|
|
|
--release
|
2020-04-07 21:17:48 +00:00
|
|
|
|
2022-04-19 20:44:01 +00:00
|
|
|
RUSTC_CMD = cargo rustc $(COMPILER_ARGS) --manifest-path $(KERNEL_MANIFEST)
|
2020-04-09 19:25:56 +00:00
|
|
|
DOC_CMD = cargo doc $(COMPILER_ARGS)
|
2020-04-11 10:22:52 +00:00
|
|
|
CLIPPY_CMD = cargo clippy $(COMPILER_ARGS)
|
2022-04-19 20:44:01 +00:00
|
|
|
TEST_CMD = cargo test $(COMPILER_ARGS) --manifest-path $(KERNEL_MANIFEST)
|
2020-04-12 09:54:13 +00:00
|
|
|
OBJCOPY_CMD = rust-objcopy \
|
2020-04-12 20:22:29 +00:00
|
|
|
--strip-all \
|
|
|
|
-O binary
|
2020-01-14 19:45:41 +00:00
|
|
|
|
2021-07-12 20:08:22 +00:00
|
|
|
EXEC_QEMU = $(QEMU_BINARY) -M $(QEMU_MACHINE_TYPE)
|
|
|
|
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
|
|
|
|
DOCKER_ARG_DIR_JTAG = -v $(shell pwd)/../X1_JTAG_boot:/work/X1_JTAG_boot
|
|
|
|
DOCKER_ARG_DEV = --privileged -v /dev:/dev
|
|
|
|
DOCKER_ARG_NET = --network host
|
2020-04-11 10:22:52 +00:00
|
|
|
|
2021-11-13 12:12:10 +00:00
|
|
|
# DOCKER_IMAGE defined in include file (see top of this file).
|
2021-03-12 22:44:10 +00:00
|
|
|
DOCKER_QEMU = $(DOCKER_CMD_INTERACT) $(DOCKER_IMAGE)
|
|
|
|
DOCKER_TOOLS = $(DOCKER_CMD) $(DOCKER_IMAGE)
|
2021-07-12 20:08:22 +00:00
|
|
|
DOCKER_TEST = $(DOCKER_CMD) $(DOCKER_ARG_DIR_COMMON) $(DOCKER_IMAGE)
|
|
|
|
DOCKER_GDB = $(DOCKER_CMD_INTERACT) $(DOCKER_ARG_NET) $(DOCKER_IMAGE)
|
2020-04-11 10:22:52 +00:00
|
|
|
|
2021-07-12 20:08:22 +00:00
|
|
|
# Dockerize commands, which require USB device passthrough, only on Linux.
|
|
|
|
ifeq ($(shell uname -s),Linux)
|
2020-11-01 14:54:11 +00:00
|
|
|
DOCKER_CMD_DEV = $(DOCKER_CMD_INTERACT) $(DOCKER_ARG_DEV)
|
2020-04-11 10:22:52 +00:00
|
|
|
|
2021-07-12 20:08:22 +00:00
|
|
|
DOCKER_CHAINBOOT = $(DOCKER_CMD_DEV) $(DOCKER_ARG_DIR_COMMON) $(DOCKER_IMAGE)
|
|
|
|
DOCKER_JTAGBOOT = $(DOCKER_CMD_DEV) $(DOCKER_ARG_DIR_COMMON) $(DOCKER_ARG_DIR_JTAG) $(DOCKER_IMAGE)
|
2020-04-12 20:22:29 +00:00
|
|
|
DOCKER_OPENOCD = $(DOCKER_CMD_DEV) $(DOCKER_ARG_NET) $(DOCKER_IMAGE)
|
2020-04-11 10:22:52 +00:00
|
|
|
else
|
2020-04-12 20:22:29 +00:00
|
|
|
DOCKER_OPENOCD = echo "Not yet supported on non-Linux systems."; \#
|
2020-04-11 10:22:52 +00:00
|
|
|
endif
|
|
|
|
|
2019-12-30 23:04:13 +00:00
|
|
|
|
2021-07-12 20:08:22 +00:00
|
|
|
|
|
|
|
##--------------------------------------------------------------------------------------------------
|
|
|
|
## Targets
|
|
|
|
##--------------------------------------------------------------------------------------------------
|
2022-04-12 19:54:53 +00:00
|
|
|
.PHONY: all doc qemu chainboot clippy clean readelf objdump nm check
|
2019-12-30 23:04:13 +00:00
|
|
|
|
2020-04-16 20:46:11 +00:00
|
|
|
all: $(KERNEL_BIN)
|
|
|
|
|
2021-07-12 20:08:22 +00:00
|
|
|
##------------------------------------------------------------------------------
|
2022-04-12 19:54:53 +00:00
|
|
|
## 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
|
2021-07-12 20:08:22 +00:00
|
|
|
##------------------------------------------------------------------------------
|
2022-04-12 19:54:53 +00:00
|
|
|
$(KERNEL_ELF): $(KERNEL_ELF_DEPS)
|
|
|
|
$(call color_header, "Compiling kernel ELF - $(BSP)")
|
2021-03-12 22:44:10 +00:00
|
|
|
@RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD)
|
2020-04-16 20:46:11 +00:00
|
|
|
|
2021-07-12 20:08:22 +00:00
|
|
|
##------------------------------------------------------------------------------
|
2022-04-12 19:54:53 +00:00
|
|
|
## Generate the stripped kernel binary
|
2021-07-12 20:08:22 +00:00
|
|
|
##------------------------------------------------------------------------------
|
2020-04-16 20:46:11 +00:00
|
|
|
$(KERNEL_BIN): $(KERNEL_ELF)
|
2022-04-12 19:54:53 +00:00
|
|
|
$(call color_header, "Generating stripped binary")
|
2020-04-16 20:46:11 +00:00
|
|
|
@$(OBJCOPY_CMD) $(KERNEL_ELF) $(KERNEL_BIN)
|
2022-04-12 19:54:53 +00:00
|
|
|
$(call color_progress_prefix, "Name")
|
|
|
|
@echo $(KERNEL_BIN)
|
|
|
|
$(call color_progress_prefix, "Size")
|
2022-10-24 20:15:48 +00:00
|
|
|
$(call disk_usage_KiB, $(KERNEL_BIN))
|
2019-12-30 23:04:13 +00:00
|
|
|
|
2021-07-12 20:08:22 +00:00
|
|
|
##------------------------------------------------------------------------------
|
2022-04-12 19:54:53 +00:00
|
|
|
## Generate the documentation
|
2021-07-12 20:08:22 +00:00
|
|
|
##------------------------------------------------------------------------------
|
2019-12-30 23:04:13 +00:00
|
|
|
doc:
|
2022-04-12 19:54:53 +00:00
|
|
|
$(call color_header, "Generating docs")
|
2021-03-12 22:44:10 +00:00
|
|
|
@$(DOC_CMD) --document-private-items --open
|
2019-12-30 23:04:13 +00:00
|
|
|
|
2021-07-12 20:08:22 +00:00
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
## Run the kernel in QEMU
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board.
|
|
|
|
|
|
|
|
qemu:
|
2022-04-12 19:54:53 +00:00
|
|
|
$(call color_header, "$(QEMU_MISSING_STRING)")
|
2021-07-12 20:08:22 +00:00
|
|
|
|
|
|
|
else # QEMU is supported.
|
|
|
|
|
2020-04-16 20:46:11 +00:00
|
|
|
qemu: $(KERNEL_BIN)
|
2022-04-12 19:54:53 +00:00
|
|
|
$(call color_header, "Launching QEMU")
|
2020-04-16 20:46:11 +00:00
|
|
|
@$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN)
|
2019-12-30 23:04:13 +00:00
|
|
|
|
|
|
|
endif
|
|
|
|
|
2021-07-12 20:08:22 +00:00
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
## Push the kernel to the real HW target
|
|
|
|
##------------------------------------------------------------------------------
|
2020-04-16 20:46:11 +00:00
|
|
|
chainboot: $(KERNEL_BIN)
|
|
|
|
@$(DOCKER_CHAINBOOT) $(EXEC_MINIPUSH) $(DEV_SERIAL) $(KERNEL_BIN)
|
2019-12-30 23:04:13 +00:00
|
|
|
|
2021-07-12 20:08:22 +00:00
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
## Run clippy
|
|
|
|
##------------------------------------------------------------------------------
|
2019-12-30 23:04:13 +00:00
|
|
|
clippy:
|
2021-03-12 22:44:10 +00:00
|
|
|
@RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(CLIPPY_CMD)
|
2022-04-19 20:44:01 +00:00
|
|
|
@RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(CLIPPY_CMD) --features test_build --tests \
|
|
|
|
--manifest-path $(KERNEL_MANIFEST)
|
2019-12-30 23:04:13 +00:00
|
|
|
|
2021-07-12 20:08:22 +00:00
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
## Clean
|
|
|
|
##------------------------------------------------------------------------------
|
2019-12-30 23:04:13 +00:00
|
|
|
clean:
|
2020-04-16 20:46:11 +00:00
|
|
|
rm -rf target $(KERNEL_BIN)
|
2019-12-30 23:04:13 +00:00
|
|
|
|
2021-07-12 20:08:22 +00:00
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
## Run readelf
|
|
|
|
##------------------------------------------------------------------------------
|
2020-04-16 20:46:11 +00:00
|
|
|
readelf: $(KERNEL_ELF)
|
2022-04-12 19:54:53 +00:00
|
|
|
$(call color_header, "Launching readelf")
|
2021-03-12 22:44:10 +00:00
|
|
|
@$(DOCKER_TOOLS) $(READELF_BINARY) --headers $(KERNEL_ELF)
|
2019-12-30 23:04:13 +00:00
|
|
|
|
2021-07-12 20:08:22 +00:00
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
## Run objdump
|
|
|
|
##------------------------------------------------------------------------------
|
2020-04-16 20:46:11 +00:00
|
|
|
objdump: $(KERNEL_ELF)
|
2022-04-12 19:54:53 +00:00
|
|
|
$(call color_header, "Launching objdump")
|
2021-03-12 22:44:10 +00:00
|
|
|
@$(DOCKER_TOOLS) $(OBJDUMP_BINARY) --disassemble --demangle \
|
|
|
|
--section .text \
|
|
|
|
--section .rodata \
|
|
|
|
$(KERNEL_ELF) | rustfilt
|
2019-12-30 23:04:13 +00:00
|
|
|
|
2021-07-12 20:08:22 +00:00
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
## Run nm
|
|
|
|
##------------------------------------------------------------------------------
|
2020-04-16 20:46:11 +00:00
|
|
|
nm: $(KERNEL_ELF)
|
2022-04-12 19:54:53 +00:00
|
|
|
$(call color_header, "Launching nm")
|
2021-03-12 22:44:10 +00:00
|
|
|
@$(DOCKER_TOOLS) $(NM_BINARY) --demangle --print-size $(KERNEL_ELF) | sort | rustfilt
|
2020-04-15 21:00:21 +00:00
|
|
|
|
2021-07-12 20:08:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
##--------------------------------------------------------------------------------------------------
|
|
|
|
## 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:
|
2022-04-12 19:54:53 +00:00
|
|
|
$(call color_header, "Launching OpenOCD")
|
2021-07-12 20:08:22 +00:00
|
|
|
@$(DOCKER_OPENOCD) openocd $(OPENOCD_ARG)
|
|
|
|
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
## Start GDB session
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
gdb: RUSTC_MISC_ARGS += -C debuginfo=2
|
|
|
|
gdb-opt0: RUSTC_MISC_ARGS += -C debuginfo=2 -C opt-level=0
|
|
|
|
gdb gdb-opt0: $(KERNEL_ELF)
|
2022-04-12 19:54:53 +00:00
|
|
|
$(call color_header, "Launching GDB")
|
2021-07-12 20:08:22 +00:00
|
|
|
@$(DOCKER_GDB) gdb-multiarch -q $(KERNEL_ELF)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
##--------------------------------------------------------------------------------------------------
|
|
|
|
## Testing targets
|
|
|
|
##--------------------------------------------------------------------------------------------------
|
|
|
|
.PHONY: test test_boot test_unit test_integration
|
|
|
|
|
2022-04-19 07:10:06 +00:00
|
|
|
test_unit test_integration: FEATURES += --features test_build
|
|
|
|
|
2021-07-12 20:08:22 +00:00
|
|
|
ifeq ($(QEMU_MACHINE_TYPE),) # QEMU is not supported for the board.
|
|
|
|
|
|
|
|
test_boot test_unit test_integration test:
|
2022-04-12 19:54:53 +00:00
|
|
|
$(call color_header, "$(QEMU_MISSING_STRING)")
|
2021-07-12 20:08:22 +00:00
|
|
|
|
|
|
|
else # QEMU is supported.
|
|
|
|
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
## Run boot test
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
test_boot: $(KERNEL_BIN)
|
2022-04-12 19:54:53 +00:00
|
|
|
$(call color_header, "Boot test - $(BSP)")
|
2021-07-12 20:08:22 +00:00
|
|
|
@$(DOCKER_TEST) $(EXEC_TEST_DISPATCH) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN)
|
|
|
|
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
## Helpers for unit and integration test targets
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
define KERNEL_TEST_RUNNER
|
2022-10-23 15:34:28 +00:00
|
|
|
#!/usr/bin/env bash
|
2021-07-12 20:08:22 +00:00
|
|
|
|
2022-04-19 20:44:01 +00:00
|
|
|
# The cargo test runner seems to change into the crate under test's directory. Therefore, ensure
|
|
|
|
# this script executes from the root.
|
|
|
|
cd $(shell pwd)
|
|
|
|
|
2021-07-12 20:08:22 +00:00
|
|
|
TEST_ELF=$$(echo $$1 | sed -e 's/.*target/target/g')
|
|
|
|
TEST_BINARY=$$(echo $$1.img | sed -e 's/.*target/target/g')
|
|
|
|
|
|
|
|
$(OBJCOPY_CMD) $$TEST_ELF $$TEST_BINARY
|
|
|
|
$(DOCKER_TEST) $(EXEC_TEST_DISPATCH) $(EXEC_QEMU) $(QEMU_TEST_ARGS) -kernel $$TEST_BINARY
|
|
|
|
endef
|
|
|
|
|
|
|
|
export KERNEL_TEST_RUNNER
|
|
|
|
|
|
|
|
define test_prepare
|
|
|
|
@mkdir -p target
|
|
|
|
@echo "$$KERNEL_TEST_RUNNER" > target/kernel_test_runner.sh
|
|
|
|
@chmod +x target/kernel_test_runner.sh
|
|
|
|
endef
|
|
|
|
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
## Run unit test(s)
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
test_unit:
|
2022-04-12 19:54:53 +00:00
|
|
|
$(call color_header, "Compiling unit test(s) - $(BSP)")
|
2021-07-12 20:08:22 +00:00
|
|
|
$(call test_prepare)
|
2022-04-10 20:08:43 +00:00
|
|
|
@RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(TEST_CMD) --lib
|
2021-07-12 20:08:22 +00:00
|
|
|
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
## Run integration test(s)
|
|
|
|
##------------------------------------------------------------------------------
|
|
|
|
test_integration:
|
2022-04-12 19:54:53 +00:00
|
|
|
$(call color_header, "Compiling integration test(s) - $(BSP)")
|
2021-07-12 20:08:22 +00:00
|
|
|
$(call test_prepare)
|
|
|
|
@RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(TEST_CMD) $(TEST_ARG)
|
|
|
|
|
|
|
|
test: test_boot test_unit test_integration
|
|
|
|
|
|
|
|
endif
|