rust-raspberrypi-OS-tutorials/14_exceptions_part2_peripheral_IRQs/Makefile

174 lines
5.3 KiB
Makefile
Raw Normal View History

2020-04-06 21:17:09 +00:00
## SPDX-License-Identifier: MIT OR Apache-2.0
##
## Copyright (c) 2018-2020 Andre Richter <andre.o.richter@gmail.com>
# Default to the RPi3
2020-04-12 20:22:29 +00:00
BSP ?= rpi3
2020-04-06 21:17:09 +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-04-06 21:17:09 +00:00
# Query the host system's kernel name
2020-04-12 20:22:29 +00:00
UNAME_S = $(shell uname -s)
2020-04-06 21:17:09 +00:00
# BSP-specific arguments
ifeq ($(BSP),rpi3)
2020-04-12 20:22:29 +00:00
TARGET = aarch64-unknown-none-softfloat
OUTPUT = kernel8.img
QEMU_BINARY = qemu-system-aarch64
QEMU_MACHINE_TYPE = raspi3
QEMU_RELEASE_ARGS = -serial stdio -display none
QEMU_TEST_ARGS = $(QEMU_RELEASE_ARGS) -semihosting
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
LINKER_FILE = src/bsp/raspberrypi/link.ld
RUSTC_MISC_ARGS = -C target-cpu=cortex-a53
2020-04-06 21:17:09 +00:00
else ifeq ($(BSP),rpi4)
2020-04-12 20:22:29 +00:00
TARGET = aarch64-unknown-none-softfloat
OUTPUT = kernel8.img
QEMU_BINARY = qemu-system-aarch64
QEMU_MACHINE_TYPE =
QEMU_RELEASE_ARGS = -serial stdio -display none
QEMU_TEST_ARGS = $(QEMU_RELEASE_ARGS) -semihosting
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
LINKER_FILE = src/bsp/raspberrypi/link.ld
RUSTC_MISC_ARGS = -C target-cpu=cortex-a72
2020-04-06 21:17:09 +00:00
endif
# Export for build.rs
export LINKER_FILE
2020-04-06 21:17:09 +00:00
# Testing-specific arguments
ifdef TEST
2020-04-12 20:22:29 +00:00
ifeq ($(TEST),unit)
TEST_ARG = --lib
else
TEST_ARG = --test $(TEST)
endif
2020-04-06 21:17:09 +00:00
endif
QEMU_MISSING_STRING = "This board is not yet supported for QEMU."
RUSTFLAGS = -C link-arg=-T$(LINKER_FILE) $(RUSTC_MISC_ARGS)
RUSTFLAGS_PEDANTIC = $(RUSTFLAGS) -D warnings -D missing_docs
FEATURES = bsp_$(BSP)
COMPILER_ARGS = --target=$(TARGET) \
2020-04-12 20:22:29 +00:00
--features $(FEATURES) \
--release
RUSTC_CMD = cargo rustc $(COMPILER_ARGS)
2020-04-09 19:25:56 +00:00
DOC_CMD = cargo doc $(COMPILER_ARGS)
CLIPPY_CMD = cargo clippy $(COMPILER_ARGS)
CHECK_CMD = cargo check $(COMPILER_ARGS)
TEST_CMD = cargo test $(COMPILER_ARGS)
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-04-06 21:17:09 +00:00
KERNEL_ELF = target/$(TARGET)/release/kernel
2020-04-06 21:17:09 +00:00
DOCKER_IMAGE = rustembedded/osdev-utils
DOCKER_CMD_TEST = docker run -i --rm -v $(shell pwd):/work/tutorial -w /work/tutorial
2020-04-06 21:17:09 +00:00
DOCKER_CMD_USER = $(DOCKER_CMD_TEST) -t
DOCKER_ARG_DIR_UTILS = -v $(shell pwd)/../utils:/work/utils
DOCKER_ARG_DIR_JTAG = -v $(shell pwd)/../X1_JTAG_boot:/work/X1_JTAG_boot
DOCKER_ARG_DEV = --privileged -v /dev:/dev
2020-04-06 21:17:09 +00:00
DOCKER_ARG_NET = --network host
DOCKER_QEMU = $(DOCKER_CMD_USER) $(DOCKER_IMAGE)
DOCKER_GDB = $(DOCKER_CMD_USER) $(DOCKER_ARG_NET) $(DOCKER_IMAGE)
DOCKER_TEST = $(DOCKER_CMD_TEST) $(DOCKER_IMAGE)
# Dockerize commands that require USB device passthrough only on Linux
ifeq ($(UNAME_S),Linux)
2020-04-12 20:22:29 +00:00
DOCKER_CMD_DEV = $(DOCKER_CMD_USER) $(DOCKER_ARG_DEV)
2020-04-12 20:22:29 +00:00
DOCKER_CHAINBOOT = $(DOCKER_CMD_DEV) $(DOCKER_ARG_DIR_UTILS) $(DOCKER_IMAGE)
DOCKER_JTAGBOOT = $(DOCKER_CMD_DEV) $(DOCKER_ARG_DIR_UTILS) $(DOCKER_ARG_DIR_JTAG) $(DOCKER_IMAGE)
DOCKER_OPENOCD = $(DOCKER_CMD_DEV) $(DOCKER_ARG_NET) $(DOCKER_IMAGE)
else
2020-04-12 20:22:29 +00:00
DOCKER_OPENOCD = echo "Not yet supported on non-Linux systems."; \#
endif
2020-04-12 20:22:29 +00:00
EXEC_QEMU = $(QEMU_BINARY) -M $(QEMU_MACHINE_TYPE)
EXEC_MINIPUSH = ruby ../utils/minipush.rb
2020-04-06 21:17:09 +00:00
.PHONY: all doc qemu test chainboot jtagboot openocd gdb gdb-opt0 clippy clean readelf objdump nm check
2020-04-06 21:17:09 +00:00
all:
RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD)
@if [ ! -f kernel ] || [ $(KERNEL_ELF) -nt kernel ]; then \
cp $(KERNEL_ELF) .; \
$(OBJCOPY_CMD) kernel $(OUTPUT); \
fi
2020-04-06 21:17:09 +00:00
doc:
2020-04-09 19:25:56 +00:00
$(DOC_CMD) --document-private-items --open
2020-04-06 21:17:09 +00:00
qemu: FEATURES += --features qemu-quirks
ifeq ($(QEMU_MACHINE_TYPE),)
2020-04-12 20:22:29 +00:00
qemu test:
2020-04-06 21:17:09 +00:00
@echo $(QEMU_MISSING_STRING)
else
qemu: all
@$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(OUTPUT)
2020-04-06 21:17:09 +00:00
define KERNEL_TEST_RUNNER
2020-04-12 20:22:29 +00:00
#!/usr/bin/env bash
2020-04-06 21:17:09 +00:00
2020-04-12 20:22:29 +00:00
$(OBJCOPY_CMD) $$1 $$1.img
TEST_BINARY=$$(echo $$1.img | sed -e 's/.*target/target/g')
$(DOCKER_TEST) ruby tests/runner.rb $(EXEC_QEMU) $(QEMU_TEST_ARGS) -kernel $$TEST_BINARY
2020-04-06 21:17:09 +00:00
endef
export KERNEL_TEST_RUNNER
test: FEATURES += --features qemu-quirks
test:
2020-04-06 21:17:09 +00:00
@mkdir -p target
@echo "$$KERNEL_TEST_RUNNER" > target/kernel_test_runner.sh
@chmod +x target/kernel_test_runner.sh
RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(TEST_CMD) $(TEST_ARG)
2020-04-06 21:17:09 +00:00
endif
chainboot: all
@$(DOCKER_CHAINBOOT) $(EXEC_MINIPUSH) $(DEV_SERIAL) $(OUTPUT)
2020-04-06 21:17:09 +00:00
jtagboot:
@$(DOCKER_JTAGBOOT) $(EXEC_MINIPUSH) $(DEV_SERIAL) $(JTAG_BOOT_IMAGE)
2020-04-06 21:17:09 +00:00
openocd:
@$(DOCKER_OPENOCD) openocd $(OPENOCD_ARG)
2020-04-06 21:17:09 +00:00
define gen_gdb
2020-04-12 20:22:29 +00:00
RUSTFLAGS="$(RUSTFLAGS_PEDANTIC) $1" $(RUSTC_CMD)
cp $(KERNEL_ELF) kernel_for_jtag
@$(DOCKER_GDB) gdb-multiarch -q kernel_for_jtag
2020-04-06 21:17:09 +00:00
endef
gdb:
2020-04-06 21:17:09 +00:00
$(call gen_gdb,-C debuginfo=2)
gdb-opt0:
2020-04-06 21:17:09 +00:00
$(call gen_gdb,-C debuginfo=2 -C opt-level=0)
clippy:
RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(CLIPPY_CMD)
2020-04-06 21:17:09 +00:00
clean:
rm -rf target
readelf: all
2020-04-12 20:22:29 +00:00
readelf -a $(KERNEL_ELF)
2020-04-06 21:17:09 +00:00
objdump: all
2020-04-12 20:22:29 +00:00
rust-objdump --arch-name aarch64 -disassemble -no-show-raw-insn -print-imm-hex $(KERNEL_ELF)
2020-04-06 21:17:09 +00:00
nm: all
2020-04-12 20:22:29 +00:00
rust-nm --demangle --print-size $(KERNEL_ELF) | sort
# For rust-analyzer
check:
@RUSTFLAGS="$(RUSTFLAGS)" $(CHECK_CMD) --message-format=json