-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
145 lines (123 loc) · 4.61 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
CARGO_DEBUG_TARGET ?= release
CARGO_ARCH_TARGET = x86_64-unknown-uefi
OUT_ROOT_DIR=./images
BOOT_ISO=$(OUT_ROOT_DIR)/efiboot.iso
EFI_BOOT_IMG=$(OUT_ROOT_DIR)/efiboot.img
OVMF_DIR = $(OUT_ROOT_DIR)/ovmf-no-nvme
OVMF_FILES = \
$(OVMF_DIR)/OVMF_CODE_no_nvme.fd \
$(OVMF_DIR)/OVMF_VARS_no_nvme.fd \
$(OVMF_DIR)/OVMF_no_nvme.fd \
$(OVMF_DIR)/NvmExpressDxe.efi \
$(OVMF_DIR)/shellx64.efi
ESP_DIR = $(OUT_ROOT_DIR)/esp
NVME_DIR = $(OUT_ROOT_DIR)/nvme
BOOT_FILES = \
$(ESP_DIR)/EFI/BOOT/BOOTX64.efi \
$(ESP_DIR)/EFI/BOOT/JS/DRIVERS/NvmExpressDxe.efi \
$(if $(filter debug,$(CARGO_DEBUG_TARGET)),$(ESP_DIR)/EFI/BOOT/shellx64.efi)
BOOTLOADER = ./target/$(CARGO_ARCH_TARGET)/$(CARGO_DEBUG_TARGET)/jumpstart.efi
.PHONY: all
all: run-iso
.PHONY: ovmf
ovmf: $(OVMF_FILES)
$(OVMF_FILES): Dockerfile
docker buildx build -o type=local,dest=$(OVMF_DIR) .
# files created by the docker build may be very old
# so we need to touch them to update the timestamp
touch -r Dockerfile $(OVMF_FILES)
$(BOOT_FILES): $(BOOTLOADER) $(OVMF_FILES)
@echo "Populating ESP directory"
mkdir -p $(ESP_DIR)/EFI/BOOT/JS/DRIVERS
mkdir -p $(NVME_DIR)
# touch $(NVME_DIR)/nvme-dummy.efi
cp $(OVMF_DIR)/NvmExpressDxe.efi $(ESP_DIR)/EFI/BOOT/JS/DRIVERS
# if we are building for i686-unknown-uefi copy to BOOTAI32.efi
ifeq ($(CARGO_ARCH_TARGET),i686-unknown-uefi)
cp $(BOOTLOADER) $(ESP_DIR)/EFI/BOOT/BOOTIA32.efi
else
cp $(BOOTLOADER) $(ESP_DIR)/EFI/BOOT/BOOTX64.efi
endif
# copy UEFI Shell to the ESP only for debug target
ifeq ($(TARGET),debug)
cp $(OVMF_DIR)/shellx64.efi $(ESP_DIR)/EFI/BOOT
endif
#
# Gebnerate an ISO image that can be booted from UEFI only
#
# FIXME: should I add USB boot support?
# For more information see:
# https://www.0xf8.org/2020/03/recreating-isos-that-boot-from-both-dvd-and-mass-storage-such-as-usb-sticks-and-in-both-legacy-bios-and-uefi-environments/
# https://wiki.debian.org/RepackBootableISO#What_to_do_if_no_file_.2F.disk.2Fmkisofs_exists
# https://dev.lovelyhq.com/libburnia/libisofs/raw/branch/master/doc/boot_sectors.txt
# https://fedoraproject.org/wiki/User:Pjones/BootableCDsForBIOSAndUEFI#New_UEFI.2FBIOS_hybrid_method
.PHONY: iso
iso: $(BOOT_ISO)
$(BOOT_ISO): $(EFI_BOOT_IMG)
# create a temorray directory
$(eval iso_tmp_dir:=$(shell mktemp -d))
cp -r $(ESP_DIR)/* $(iso_tmp_dir)
cp $^ $(iso_tmp_dir)/EFI/BOOT/efiboot.img
@mkisofs \
-o $@ \
-R -J -v -d -N \
-x $@ \
-hide-rr-moved \
-no-emul-boot \
-eltorito-platform efi \
-eltorito-boot EFI/BOOT/efiboot.img \
-V "EFIBOOTISO" \
-A "EFI Boot ISO Test" \
$(iso_tmp_dir)
# cleanup
rm -rf $(iso_tmp_dir)
$(EFI_BOOT_IMG): $(BOOT_FILES)
# Create a FAT32 image for the UEFI boot files
# remove image file if it already exists so we do not calculate its size
rm -f $@
# calculate the size of the image in megabytes
# $(eval image_size:=$(shell du -sm $(ESP_DIR) | cut -f1))
@echo "Creating FAT32 image with size $(image_size)"
dd if=/dev/zero of=$@ bs=1M count=$(image_size)
mkfs.vfat -n 'JSEFIBOOT' $@
mmd -i $@ ::EFI
mmd -i $@ ::EFI/BOOT
mmd -i $@ ::EFI/BOOT/JS
mmd -i $@ ::EFI/BOOT/JS/DRIVERS
mcopy -i $@ $(ESP_DIR)/EFI/BOOT/BOOTX64.efi ::EFI/BOOT/BOOTX64.EFI
mcopy -i $@ $(ESP_DIR)/EFI/BOOT/JS/DRIVERS/NvmExpressDxe.efi ::EFI/BOOT/JS/DRIVERS/NvmExpressDxe.efi
ifeq ($(CARGO_DEBUG_TARGET),debug)
mcopy -i $@ $(ESP_DIR)/EFI/BOOT/shellx64.efi ::EFI/BOOT/SHELLX64.EFI
endif
RUST_SRC_FILES := $(shell find ./src -type f -name '*.rs')
RUST_SRC_FILES += Cargo.toml Cargo.lock rust-toolchain.toml
$(BOOTLOADER): $(RUST_SRC_FILES)
cargo build --target=$(CARGO_ARCH_TARGET) $(if $(filter release,$(CARGO_DEBUG_TARGET)),--release)
$(OUT_ROOT_DIR)/nvme-1.img:
dd if=/dev/zero of=$@ bs=1M count=1024
.PHONY: run-iso
run-iso: ovmf $(BOOT_ISO)
qemu-system-x86_64 -enable-kvm -serial stdio \
-debugcon file:debug.log -global isa-debugcon.iobase=0x402 \
-bios $(OVMF_DIR)/OVMF_no_nvme.fd \
-cdrom $(BOOT_ISO) -boot d -m 512
.PHONY: check-iso
check-iso: $(BOOT_ISO)
xorriso -indev $^ -report_system_area plain -report_el_torito plain
.PHONY: run
run: $(OUT_ROOT_DIR)/nvme-1.img $(BOOT_FILES)
qemu-system-x86_64 -enable-kvm -serial stdio \
-debugcon file:debug.log -global isa-debugcon.iobase=0x402 \
-drive if=pflash,format=raw,unit=0,file=$(OVMF_DIR)/OVMF_CODE_no_nvme.fd,readonly=on \
-drive if=pflash,format=raw,unit=1,file=$(OVMF_DIR)/OVMF_VARS_no_nvme.fd \
-drive format=raw,file=fat:rw:$(NVME_DIR),if=none,id=nvm \
-device nvme,serial=deadbeef,drive=nvm \
-drive format=raw,file=$<,if=none,id=nvm-1 \
-device nvme,serial=beefdead,drive=nvm-1 \
-drive format=raw,file=fat:rw:$(ESP_DIR)
.PHONY: clean
clean:
cargo clean
rm -rf $(OUT_ROOT_DIR)
rm -f debug.log
rm -f efiboot.iso