rust-raspberrypi-OS-tutorials/03_hacky_hello_world/Makefile

116 lines
3.4 KiB
Makefile
Raw Normal View History

2019-11-25 18:54:05 +00:00
## SPDX-License-Identifier: MIT OR Apache-2.0
2019-09-24 20:55:23 +00:00
##
2021-01-01 10:28:32 +00:00
## Copyright (c) 2018-2021 Andre Richter <andre.o.richter@gmail.com>
2019-09-24 20:55:23 +00:00
2021-03-12 22:44:10 +00:00
include ../utils/color.mk.in
2019-09-24 20:55:23 +00:00
# Default to the RPi3
2020-04-12 20:22:29 +00:00
BSP ?= rpi3
2019-09-24 20:55:23 +00:00
# BSP-specific arguments
2019-10-21 19:19:11 +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
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
LINKER_FILE = src/bsp/raspberrypi/link.ld
RUSTC_MISC_ARGS = -C target-cpu=cortex-a53
2019-10-29 21:32:49 +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
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
LINKER_FILE = src/bsp/raspberrypi/link.ld
RUSTC_MISC_ARGS = -C target-cpu=cortex-a72
2019-09-24 20:55:23 +00:00
endif
# Export for build.rs
export LINKER_FILE
2021-03-12 22:44:10 +00:00
QEMU_MISSING_STRING = "This board is not yet supported for QEMU."
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-03-12 22:44:10 +00:00
FEATURES = --features bsp_$(BSP)
COMPILER_ARGS = --target=$(TARGET) \
2021-03-12 22:44:10 +00:00
$(FEATURES) \
2020-04-12 20:22:29 +00:00
--release
2019-09-24 20:55:23 +00:00
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)
2020-04-12 09:54:13 +00:00
OBJCOPY_CMD = rust-objcopy \
2020-04-12 20:22:29 +00:00
--strip-all \
-O binary
2019-09-24 20:55:23 +00:00
KERNEL_ELF = target/$(TARGET)/release/kernel
DOCKER_IMAGE = rustembedded/osdev-utils
DOCKER_CMD = docker run --rm -v $(shell pwd):/work/tutorial -w /work/tutorial
DOCKER_CMD_INTERACT = $(DOCKER_CMD) -i -t
2021-03-12 22:44:10 +00:00
DOCKER_QEMU = $(DOCKER_CMD_INTERACT) $(DOCKER_IMAGE)
DOCKER_TOOLS = $(DOCKER_CMD) $(DOCKER_IMAGE)
2020-04-12 20:22:29 +00:00
EXEC_QEMU = $(QEMU_BINARY) -M $(QEMU_MACHINE_TYPE)
2019-09-24 20:55:23 +00:00
2020-04-16 20:46:11 +00:00
.PHONY: all $(KERNEL_ELF) $(KERNEL_BIN) doc qemu clippy clean readelf objdump nm check
2019-09-24 20:55:23 +00:00
2020-04-16 20:46:11 +00:00
all: $(KERNEL_BIN)
$(KERNEL_ELF):
2021-03-12 22:44:10 +00:00
$(call colorecho, "\nCompiling kernel - $(BSP)")
@RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD)
2020-04-16 20:46:11 +00:00
$(KERNEL_BIN): $(KERNEL_ELF)
@$(OBJCOPY_CMD) $(KERNEL_ELF) $(KERNEL_BIN)
2019-09-24 20:55:23 +00:00
doc:
2021-03-12 22:44:10 +00:00
$(call colorecho, "\nGenerating docs")
@$(DOC_CMD) --document-private-items --open
2019-09-24 20:55:23 +00:00
2019-10-29 21:32:49 +00:00
ifeq ($(QEMU_MACHINE_TYPE),)
qemu:
2021-03-12 22:44:10 +00:00
$(call colorecho, "\n$(QEMU_MISSING_STRING)")
2019-10-29 21:32:49 +00:00
else
2020-04-16 20:46:11 +00:00
qemu: $(KERNEL_BIN)
2021-03-12 22:44:10 +00:00
$(call colorecho, "\nLaunching QEMU")
2020-04-16 20:46:11 +00:00
@$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN)
2019-10-29 21:32:49 +00:00
endif
2019-09-24 20:55:23 +00:00
clippy:
2021-03-12 22:44:10 +00:00
@RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(CLIPPY_CMD)
2019-09-24 20:55:23 +00:00
clean:
2020-04-16 20:46:11 +00:00
rm -rf target $(KERNEL_BIN)
2019-09-24 20:55:23 +00:00
2020-04-16 20:46:11 +00:00
readelf: $(KERNEL_ELF)
2021-03-12 22:44:10 +00:00
$(call colorecho, "\nLaunching readelf")
@$(DOCKER_TOOLS) $(READELF_BINARY) --headers $(KERNEL_ELF)
2019-09-24 20:55:23 +00:00
2020-04-16 20:46:11 +00:00
objdump: $(KERNEL_ELF)
2021-03-12 22:44:10 +00:00
$(call colorecho, "\nLaunching objdump")
@$(DOCKER_TOOLS) $(OBJDUMP_BINARY) --disassemble --demangle \
--section .text \
--section .rodata \
2021-03-16 21:36:06 +00:00
--section .got \
2021-03-12 22:44:10 +00:00
$(KERNEL_ELF) | rustfilt
2019-09-24 20:55:23 +00:00
2020-04-16 20:46:11 +00:00
nm: $(KERNEL_ELF)
2021-03-12 22:44:10 +00:00
$(call colorecho, "\nLaunching nm")
@$(DOCKER_TOOLS) $(NM_BINARY) --demangle --print-size $(KERNEL_ELF) | sort | rustfilt
# For rust-analyzer
check:
@RUSTFLAGS="$(RUSTFLAGS)" $(CHECK_CMD) --message-format=json