2019-11-25 18:54:05 +00:00
|
|
|
## SPDX-License-Identifier: MIT OR Apache-2.0
|
2019-11-01 22:03:29 +00:00
|
|
|
##
|
2021-01-01 10:28:32 +00:00
|
|
|
## Copyright (c) 2018-2021 Andre Richter <andre.o.richter@gmail.com>
|
2019-11-01 22:03:29 +00:00
|
|
|
|
|
|
|
# Default to the RPi3
|
2020-04-12 20:22:29 +00:00
|
|
|
BSP ?= rpi3
|
2019-11-01 22:03:29 +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
|
|
|
|
2020-04-11 10:22:52 +00:00
|
|
|
# Query the host system's kernel name
|
2020-04-12 20:22:29 +00:00
|
|
|
UNAME_S = $(shell uname -s)
|
2020-04-11 10:22:52 +00:00
|
|
|
|
2019-11-01 22:03:29 +00:00
|
|
|
# BSP-specific arguments
|
|
|
|
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
|
2020-11-01 14:54:11 +00:00
|
|
|
OBJDUMP_BINARY = aarch64-none-elf-objdump
|
|
|
|
NM_BINARY = aarch64-none-elf-nm
|
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
|
|
|
|
LINKER_FILE = src/bsp/raspberrypi/link.ld
|
|
|
|
RUSTC_MISC_ARGS = -C target-cpu=cortex-a53
|
2019-11-01 22:03:29 +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
|
2020-11-01 14:54:11 +00:00
|
|
|
OBJDUMP_BINARY = aarch64-none-elf-objdump
|
|
|
|
NM_BINARY = aarch64-none-elf-nm
|
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
|
|
|
|
LINKER_FILE = src/bsp/raspberrypi/link.ld
|
|
|
|
RUSTC_MISC_ARGS = -C target-cpu=cortex-a72
|
2019-11-01 22:03:29 +00:00
|
|
|
endif
|
|
|
|
|
2020-04-14 21:16:35 +00:00
|
|
|
# Export for build.rs
|
|
|
|
export LINKER_FILE
|
2020-04-07 21:17:48 +00:00
|
|
|
|
2020-01-14 19:45:41 +00:00
|
|
|
RUSTFLAGS = -C link-arg=-T$(LINKER_FILE) $(RUSTC_MISC_ARGS)
|
2019-11-13 07:40:23 +00:00
|
|
|
RUSTFLAGS_PEDANTIC = $(RUSTFLAGS) -D warnings -D missing_docs
|
|
|
|
|
2021-01-23 21:43:59 +00:00
|
|
|
FEATURES = bsp_$(BSP)
|
2020-04-07 21:17:48 +00:00
|
|
|
COMPILER_ARGS = --target=$(TARGET) \
|
2021-01-23 21:43:59 +00:00
|
|
|
--features $(FEATURES) \
|
2020-04-12 20:22:29 +00:00
|
|
|
--release
|
2019-11-01 22:03:29 +00:00
|
|
|
|
2020-04-11 10:22:52 +00:00
|
|
|
RUSTC_CMD = cargo rustc $(COMPILER_ARGS)
|
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)
|
2020-04-15 21:00:21 +00:00
|
|
|
CHECK_CMD = cargo check $(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-01-14 19:45:41 +00:00
|
|
|
|
2020-04-11 10:22:52 +00:00
|
|
|
KERNEL_ELF = target/$(TARGET)/release/kernel
|
|
|
|
|
2020-01-14 19:45:41 +00:00
|
|
|
DOCKER_IMAGE = rustembedded/osdev-utils
|
2020-11-01 14:54:11 +00:00
|
|
|
DOCKER_CMD = docker run --rm -v $(shell pwd):/work/tutorial -w /work/tutorial
|
|
|
|
DOCKER_CMD_INTERACT = $(DOCKER_CMD) -i -t
|
2020-04-11 10:22:52 +00:00
|
|
|
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-01-14 19:45:41 +00:00
|
|
|
DOCKER_ARG_NET = --network host
|
2020-04-11 10:22:52 +00:00
|
|
|
|
2020-11-01 14:54:11 +00:00
|
|
|
DOCKER_QEMU = $(DOCKER_CMD_INTERACT) $(DOCKER_IMAGE)
|
|
|
|
DOCKER_GDB = $(DOCKER_CMD_INTERACT) $(DOCKER_ARG_NET) $(DOCKER_IMAGE)
|
|
|
|
DOCKER_ELFTOOLS = $(DOCKER_CMD) $(DOCKER_IMAGE)
|
2020-04-11 10:22:52 +00:00
|
|
|
|
|
|
|
# Dockerize commands that require USB device passthrough only on Linux
|
|
|
|
ifeq ($(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
|
|
|
|
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)
|
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
|
|
|
|
|
|
|
|
EXEC_QEMU = $(QEMU_BINARY) -M $(QEMU_MACHINE_TYPE)
|
|
|
|
EXEC_MINIPUSH = ruby ../utils/minipush.rb
|
2019-11-01 22:03:29 +00:00
|
|
|
|
2020-04-16 20:46:11 +00:00
|
|
|
.PHONY: all $(KERNEL_ELF) $(KERNEL_BIN) doc qemu chainboot jtagboot openocd gdb gdb-opt0 clippy \
|
|
|
|
clean readelf objdump nm check
|
2019-11-01 22:03:29 +00:00
|
|
|
|
2020-04-16 20:46:11 +00:00
|
|
|
all: $(KERNEL_BIN)
|
|
|
|
|
|
|
|
$(KERNEL_ELF):
|
2020-04-07 21:17:48 +00:00
|
|
|
RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD)
|
2020-04-16 20:46:11 +00:00
|
|
|
|
|
|
|
$(KERNEL_BIN): $(KERNEL_ELF)
|
|
|
|
@$(OBJCOPY_CMD) $(KERNEL_ELF) $(KERNEL_BIN)
|
2019-11-01 22:03:29 +00:00
|
|
|
|
|
|
|
doc:
|
2020-04-09 19:25:56 +00:00
|
|
|
$(DOC_CMD) --document-private-items --open
|
2019-11-01 22:03:29 +00:00
|
|
|
|
|
|
|
ifeq ($(QEMU_MACHINE_TYPE),)
|
|
|
|
qemu:
|
|
|
|
@echo "This board is not yet supported for QEMU."
|
|
|
|
else
|
2020-04-16 20:46:11 +00:00
|
|
|
qemu: $(KERNEL_BIN)
|
|
|
|
@$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN)
|
2019-11-01 22:03:29 +00:00
|
|
|
endif
|
|
|
|
|
2020-04-16 20:46:11 +00:00
|
|
|
chainboot: $(KERNEL_BIN)
|
|
|
|
@$(DOCKER_CHAINBOOT) $(EXEC_MINIPUSH) $(DEV_SERIAL) $(KERNEL_BIN)
|
2019-11-01 22:03:29 +00:00
|
|
|
|
|
|
|
jtagboot:
|
2020-04-11 10:22:52 +00:00
|
|
|
@$(DOCKER_JTAGBOOT) $(EXEC_MINIPUSH) $(DEV_SERIAL) $(JTAG_BOOT_IMAGE)
|
2019-11-01 22:03:29 +00:00
|
|
|
|
|
|
|
openocd:
|
2020-04-11 10:22:52 +00:00
|
|
|
@$(DOCKER_OPENOCD) openocd $(OPENOCD_ARG)
|
2019-11-01 22:03:29 +00:00
|
|
|
|
|
|
|
define gen_gdb
|
2020-04-16 20:46:11 +00:00
|
|
|
RUSTFLAGS="$(RUSTFLAGS_PEDANTIC) $1" $(RUSTC_CMD)
|
|
|
|
@$(DOCKER_GDB) gdb-multiarch -q $(KERNEL_ELF)
|
2019-11-01 22:03:29 +00:00
|
|
|
endef
|
|
|
|
|
2020-04-14 21:16:35 +00:00
|
|
|
gdb:
|
2019-11-01 22:03:29 +00:00
|
|
|
$(call gen_gdb,-C debuginfo=2)
|
|
|
|
|
2020-04-14 21:16:35 +00:00
|
|
|
gdb-opt0:
|
2019-11-01 22:03:29 +00:00
|
|
|
$(call gen_gdb,-C debuginfo=2 -C opt-level=0)
|
|
|
|
|
|
|
|
clippy:
|
2020-04-07 21:17:48 +00:00
|
|
|
RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(CLIPPY_CMD)
|
2019-11-01 22:03:29 +00:00
|
|
|
|
|
|
|
clean:
|
2020-04-16 20:46:11 +00:00
|
|
|
rm -rf target $(KERNEL_BIN)
|
2019-11-01 22:03:29 +00:00
|
|
|
|
2020-04-16 20:46:11 +00:00
|
|
|
readelf: $(KERNEL_ELF)
|
2020-07-21 15:47:43 +00:00
|
|
|
readelf --headers $(KERNEL_ELF)
|
2019-11-01 22:03:29 +00:00
|
|
|
|
2020-04-16 20:46:11 +00:00
|
|
|
objdump: $(KERNEL_ELF)
|
2020-11-20 21:26:29 +00:00
|
|
|
@$(DOCKER_ELFTOOLS) $(OBJDUMP_BINARY) --disassemble --demangle $(KERNEL_ELF) | rustfilt
|
2019-11-01 22:03:29 +00:00
|
|
|
|
2020-04-16 20:46:11 +00:00
|
|
|
nm: $(KERNEL_ELF)
|
2020-11-20 21:26:29 +00:00
|
|
|
@$(DOCKER_ELFTOOLS) $(NM_BINARY) --demangle --print-size $(KERNEL_ELF) | sort | rustfilt
|
2020-04-15 21:00:21 +00:00
|
|
|
|
|
|
|
# For rust-analyzer
|
|
|
|
check:
|
|
|
|
@RUSTFLAGS="$(RUSTFLAGS)" $(CHECK_CMD) --message-format=json
|