rust-raspberrypi-OS-tutorials/01_wait_forever/Makefile

90 lines
2.3 KiB
Makefile
Raw Normal View History

2019-11-25 18:54:05 +00:00
## SPDX-License-Identifier: MIT OR Apache-2.0
2019-09-21 22:32:54 +00:00
##
2020-01-01 23:41:03 +00:00
## Copyright (c) 2018-2020 Andre Richter <andre.o.richter@gmail.com>
2019-09-21 22:32:54 +00:00
# Default to the RPi3
ifndef BSP
2019-10-21 19:19:11 +00:00
BSP = rpi3
2019-09-21 22:32:54 +00:00
endif
# BSP-specific arguments
2019-10-21 19:19:11 +00:00
ifeq ($(BSP),rpi3)
TARGET = aarch64-unknown-none-softfloat
OUTPUT = kernel8.img
QEMU_BINARY = qemu-system-aarch64
2019-09-21 22:32:54 +00:00
QEMU_MACHINE_TYPE = raspi3
QEMU_RELEASE_ARGS = -serial stdio -display none
LINKER_FILE = src/bsp/rpi/link.ld
RUSTC_MISC_ARGS = -C target-cpu=cortex-a53
2019-10-29 21:32:49 +00:00
else ifeq ($(BSP),rpi4)
TARGET = aarch64-unknown-none-softfloat
OUTPUT = kernel8.img
# QEMU_BINARY = qemu-system-aarch64
# QEMU_MACHINE_TYPE =
# QEMU_RELEASE_ARGS = -serial stdio -display none
LINKER_FILE = src/bsp/rpi/link.ld
RUSTC_MISC_ARGS = -C target-cpu=cortex-a72
2019-09-21 22:32:54 +00:00
endif
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
2019-09-21 22:32:54 +00:00
SOURCES = $(wildcard **/*.rs) $(wildcard **/*.S) $(wildcard **/*.ld)
XRUSTC_CMD = cargo xrustc \
--target=$(TARGET) \
--features bsp_$(BSP) \
--release
2019-09-21 22:32:54 +00:00
CARGO_OUTPUT = target/$(TARGET)/release/kernel
OBJCOPY_CMD = cargo objcopy \
-- \
--strip-all \
-O binary
2019-09-21 22:32:54 +00:00
DOCKER_IMAGE = rustembedded/osdev-utils
DOCKER_CMD = docker run -it --rm
DOCKER_ARG_DIR_TUT = -v $(shell pwd):/work -w /work
DOCKER_EXEC_QEMU = $(QEMU_BINARY) -M $(QEMU_MACHINE_TYPE)
2019-09-21 22:32:54 +00:00
2019-10-17 07:38:24 +00:00
.PHONY: all doc qemu clippy clean readelf objdump nm
2019-09-21 22:32:54 +00:00
all: clean $(OUTPUT)
$(CARGO_OUTPUT): $(SOURCES)
2019-11-13 07:40:23 +00:00
RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(XRUSTC_CMD)
2019-09-21 22:32:54 +00:00
$(OUTPUT): $(CARGO_OUTPUT)
cp $< .
$(OBJCOPY_CMD) $< $(OUTPUT)
doc:
2019-10-21 19:19:11 +00:00
cargo xdoc --target=$(TARGET) --features bsp_$(BSP) --document-private-items
2019-09-21 22:32:54 +00:00
xdg-open target/$(TARGET)/doc/kernel/index.html
2019-10-29 21:32:49 +00:00
ifeq ($(QEMU_MACHINE_TYPE),)
qemu:
@echo "This board is not yet supported for QEMU."
else
2019-09-21 22:32:54 +00:00
qemu: all
@$(DOCKER_CMD) $(DOCKER_ARG_DIR_TUT) $(DOCKER_IMAGE) \
$(DOCKER_EXEC_QEMU) $(QEMU_RELEASE_ARGS) \
-kernel $(OUTPUT)
2019-10-29 21:32:49 +00:00
endif
2019-09-21 22:32:54 +00:00
clippy:
2020-01-09 21:11:39 +00:00
RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" cargo xclippy --target=$(TARGET) --features bsp_$(BSP)
2019-09-21 22:32:54 +00:00
clean:
2019-11-13 07:40:23 +00:00
rm -rf target
2019-09-21 22:32:54 +00:00
readelf:
readelf -a kernel
objdump:
2019-12-01 21:19:29 +00:00
cargo objdump --target $(TARGET) -- -disassemble -no-show-raw-insn -print-imm-hex kernel
2019-09-21 22:32:54 +00:00
nm:
2019-12-01 21:19:29 +00:00
cargo nm --target $(TARGET) -- -print-size kernel | sort