Iso added
This commit is contained in:
54
Makefile
54
Makefile
@@ -78,11 +78,51 @@ QEMU_FLAGS = -machine q35 \
|
|||||||
-net none \
|
-net none \
|
||||||
-no-reboot
|
-no-reboot
|
||||||
|
|
||||||
# Phony targets
|
# Phony targets
|
||||||
.PHONY: all clean run setup install-deps
|
.PHONY: all clean run setup install-deps iso runiso
|
||||||
|
|
||||||
# Default target
|
# Default target
|
||||||
all: setup $(EFI_DIR)/$(TARGET) $(BUILD_DIR)/$(KERNEL_TARGET)
|
all: setup $(EFI_DIR)/$(TARGET) $(BUILD_DIR)/$(KERNEL_TARGET)
|
||||||
|
# ISO target
|
||||||
|
ISO_FILE = $(IMAGE_DIR)/os.iso
|
||||||
|
|
||||||
|
ESP_IMG = $(IMAGE_DIR)/staging/esp.img
|
||||||
|
|
||||||
|
iso: all
|
||||||
|
@echo "Creating FAT ESP image for UEFI boot..."
|
||||||
|
@mkdir -p $(IMAGE_DIR)/staging
|
||||||
|
@# Calculate size: EFI binary + kernel + overhead, rounded up to MiB
|
||||||
|
@SIZE_KB=$$(( ($$(stat -c%s $(EFI_DIR)/$(TARGET)) + $$(stat -c%s $(BUILD_DIR)/$(KERNEL_TARGET)) + 1048576) / 1024 )); \
|
||||||
|
dd if=/dev/zero of=$(ESP_IMG) bs=1K count=$$SIZE_KB 2>/dev/null
|
||||||
|
mkfs.fat -F 12 $(ESP_IMG) >/dev/null
|
||||||
|
mmd -i $(ESP_IMG) ::EFI
|
||||||
|
mmd -i $(ESP_IMG) ::EFI/BOOT
|
||||||
|
mcopy -i $(ESP_IMG) $(EFI_DIR)/$(TARGET) ::EFI/BOOT/BOOTX64.EFI
|
||||||
|
mcopy -i $(ESP_IMG) $(BUILD_DIR)/$(KERNEL_TARGET) ::kernel.elf
|
||||||
|
@echo "Creating ISO image..."
|
||||||
|
xorriso -as mkisofs \
|
||||||
|
-o $(ISO_FILE) \
|
||||||
|
-e esp.img \
|
||||||
|
-no-emul-boot \
|
||||||
|
$(IMAGE_DIR)/staging
|
||||||
|
@echo "ISO image created: $(ISO_FILE)"
|
||||||
|
|
||||||
|
# Run from ISO with QEMU
|
||||||
|
runiso: iso
|
||||||
|
@echo "Starting QEMU from ISO..."
|
||||||
|
@echo "Using OVMF firmware: $(OVMF_CODE)"
|
||||||
|
@if [ ! -f $(BUILD_DIR)/OVMF_VARS.fd ]; then \
|
||||||
|
echo "Creating OVMF_VARS.fd from template..."; \
|
||||||
|
cp $(OVMF_VARS_TEMPLATE) $(BUILD_DIR)/OVMF_VARS.fd 2>/dev/null || \
|
||||||
|
dd if=/dev/zero of=$(BUILD_DIR)/OVMF_VARS.fd bs=1M count=64 2>/dev/null; \
|
||||||
|
fi
|
||||||
|
$(QEMU) -machine q35 \
|
||||||
|
-drive if=pflash,format=raw,readonly=on,file=$(OVMF_CODE) \
|
||||||
|
-drive if=pflash,format=raw,file=$(BUILD_DIR)/OVMF_VARS.fd \
|
||||||
|
-cdrom $(ISO_FILE) \
|
||||||
|
-net none \
|
||||||
|
-nographic \
|
||||||
|
-no-reboot
|
||||||
|
|
||||||
# Create necessary directories
|
# Create necessary directories
|
||||||
setup:
|
setup:
|
||||||
@@ -170,16 +210,18 @@ clean:
|
|||||||
install-deps:
|
install-deps:
|
||||||
@echo "Installing dependencies..."
|
@echo "Installing dependencies..."
|
||||||
sudo apt-get update
|
sudo apt-get update
|
||||||
sudo apt-get install -y gnu-efi qemu-system-x86 ovmf gcc binutils make
|
sudo apt-get install -y gnu-efi qemu-system-x86 ovmf gcc binutils make xorriso mtools
|
||||||
@echo "Dependencies installed."
|
@echo "Dependencies installed."
|
||||||
|
|
||||||
# Help target
|
# Help target
|
||||||
help:
|
help:
|
||||||
@echo "UEFI Operating System Makefile"
|
@echo "UEFI Operating System Makefile"
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "Targets:"
|
@echo "Targets:"
|
||||||
@echo " all - Build the UEFI application (default)"
|
@echo " all - Build the UEFI application (default)"
|
||||||
@echo " run - Build and run with QEMU"
|
@echo " run - Build and run with QEMU"
|
||||||
|
@echo " iso - Create a bootable ISO image"
|
||||||
|
@echo " runiso - Build, create ISO, and run in QEMU from ISO"
|
||||||
@echo " clean - Remove build artifacts"
|
@echo " clean - Remove build artifacts"
|
||||||
@echo " install-deps - Install required dependencies (Debian/Ubuntu)"
|
@echo " install-deps - Install required dependencies (Debian/Ubuntu)"
|
||||||
@echo " help - Display this help message"
|
@echo " help - Display this help message"
|
||||||
@@ -187,5 +229,7 @@ help:
|
|||||||
@echo "Usage:"
|
@echo "Usage:"
|
||||||
@echo " make # Build the OS"
|
@echo " make # Build the OS"
|
||||||
@echo " make run # Build and run in QEMU"
|
@echo " make run # Build and run in QEMU"
|
||||||
|
@echo " make iso # Create ISO image"
|
||||||
|
@echo " make runiso # Build, create ISO, and run in QEMU from ISO"
|
||||||
@echo " make clean # Clean build files"
|
@echo " make clean # Clean build files"
|
||||||
@echo " make install-deps # Install dependencies"
|
@echo " make install-deps # Install dependencies"
|
||||||
|
|||||||
Reference in New Issue
Block a user