|
| 1 | +# |
| 2 | +# MIT License |
| 3 | +# |
| 4 | +# Copyright (c) 2018-2019 Andre Richter <andre.o.richter@gmail.com> |
| 5 | +# |
| 6 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | +# of this software and associated documentation files (the "Software"), to deal |
| 8 | +# in the Software without restriction, including without limitation the rights |
| 9 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | +# copies of the Software, and to permit persons to whom the Software is |
| 11 | +# furnished to do so, subject to the following conditions: |
| 12 | +# |
| 13 | +# The above copyright notice and this permission notice shall be included in all |
| 14 | +# copies or substantial portions of the Software. |
| 15 | +# |
| 16 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | +# SOFTWARE. |
| 23 | +# |
| 24 | + |
| 25 | +TARGET = aarch64-unknown-none |
| 26 | + |
| 27 | +SOURCES = $(wildcard **/*.rs) $(wildcard **/*.S) link.ld |
| 28 | + |
| 29 | + |
| 30 | +XRUSTC_CMD = cargo xrustc --target=$(TARGET) --release |
| 31 | +CARGO_OUTPUT = target/$(TARGET)/release/kernel8 |
| 32 | + |
| 33 | +OBJCOPY = cargo objcopy -- |
| 34 | +OBJCOPY_PARAMS = --strip-all -O binary |
| 35 | + |
| 36 | +CONTAINER_UTILS = andrerichter/raspi3-utils |
| 37 | +CONTAINER_OPENOCD = andrerichter/raspi3-openocd |
| 38 | +CONTAINER_GDB = andrerichter/raspi3-gdb |
| 39 | + |
| 40 | +DOCKER_CMD = docker run -it --rm |
| 41 | +DOCKER_ARG_CURDIR = -v $(shell pwd):/work -w /work |
| 42 | +DOCKER_ARG_TTY = --privileged -v /dev:/dev |
| 43 | +DOCKER_ARG_JTAG = -v $(shell pwd)/../X1_JTAG_boot:/jtag |
| 44 | +DOCKER_ARG_NET = --network host |
| 45 | + |
| 46 | +DOCKER_EXEC_QEMU = qemu-system-aarch64 -M raspi3 -kernel kernel8.img |
| 47 | +DOCKER_EXEC_RASPBOOT = raspbootcom /dev/ttyUSB0 |
| 48 | + |
| 49 | +.PHONY: all qemu raspboot clippy clean objdump nm jtag |
| 50 | + |
| 51 | +all: clean kernel8.img |
| 52 | + |
| 53 | +$(CARGO_OUTPUT): $(SOURCES) |
| 54 | + $(XRUSTC_CMD) |
| 55 | + |
| 56 | +kernel8.img: $(CARGO_OUTPUT) |
| 57 | + cp $< . |
| 58 | + $(OBJCOPY) $(OBJCOPY_PARAMS) $< kernel8.img |
| 59 | + |
| 60 | +qemu: all |
| 61 | + $(DOCKER_CMD) $(DOCKER_ARG_CURDIR) $(CONTAINER_UTILS) \ |
| 62 | + $(DOCKER_EXEC_QEMU) -serial stdio |
| 63 | + |
| 64 | +raspboot: all |
| 65 | + $(DOCKER_CMD) $(DOCKER_ARG_CURDIR) $(DOCKER_ARG_TTY) \ |
| 66 | + $(CONTAINER_UTILS) $(DOCKER_EXEC_RASPBOOT) kernel8.img |
| 67 | + |
| 68 | +clippy: |
| 69 | + cargo xclippy --target=$(TARGET) |
| 70 | + |
| 71 | +clean: |
| 72 | + cargo clean |
| 73 | + |
| 74 | +objdump: |
| 75 | + cargo objdump --target $(TARGET) -- -disassemble -print-imm-hex kernel8 |
| 76 | + |
| 77 | +nm: |
| 78 | + cargo nm --target $(TARGET) -- kernel8 | sort |
| 79 | + |
| 80 | +jtagboot: |
| 81 | + $(DOCKER_CMD) $(DOCKER_ARG_TTY) $(DOCKER_ARG_JTAG) $(CONTAINER_UTILS) \ |
| 82 | + $(DOCKER_EXEC_RASPBOOT) /jtag/jtag_boot.img |
| 83 | + |
| 84 | +openocd: |
| 85 | + $(DOCKER_CMD) $(DOCKER_ARG_TTY) $(DOCKER_ARG_NET) $(CONTAINER_OPENOCD) |
| 86 | + |
| 87 | +define gen_gdb |
| 88 | + $(XRUSTC_CMD) -- $1 |
| 89 | + cp $(CARGO_OUTPUT) kernel8_for_jtag |
| 90 | + $(DOCKER_CMD) $(DOCKER_ARG_CURDIR) $(DOCKER_ARG_NET) $(CONTAINER_GDB) \ |
| 91 | + gdb-multiarch -q kernel8_for_jtag |
| 92 | +endef |
| 93 | + |
| 94 | +gdb: clean $(SOURCES) |
| 95 | + $(call gen_gdb,-C debuginfo=2) |
| 96 | + |
| 97 | +gdb-opt0: clean $(SOURCES) |
| 98 | + $(call gen_gdb,-C debuginfo=2 -C opt-level=0) |
0 commit comments