Add Makefile for creating images and launching qemu.

This commit is contained in:
Andrius Štikonas 2022-08-07 11:30:42 +01:00
parent 129bfcbd16
commit f552c166df
24 changed files with 112 additions and 6 deletions

3
.gitignore vendored
View File

@ -1,7 +1,8 @@
# SPDX-FileCopyrightText: 2022 Andrius Štikonas <andrius@stikonas.eu>
# SPDX-License-Identifier: MIT
*~
*/build/
build/
*.d
*.lib
*.efi

3
.gitmodules vendored
View File

@ -1,3 +1,6 @@
# SPDX-FileCopyrightText: 2022 Andrius Štikonas <andrius@stikonas.eu>
# SPDX-License-Identifier: MIT
[submodule "bootstrap-seeds"]
path = bootstrap-seeds
url = https://github.com/oriansj/bootstrap-seeds/

View File

@ -1,3 +1,4 @@
/* SPDX-FileCopyrightText: Mike Krinkin */
/* SPDX-License-Identifier: Unlicense */
#ifndef __EFI_BOOT_TABLE_H__

View File

@ -1,3 +1,4 @@
/* SPDX-FileCopyrightText: Mike Krinkin */
/* SPDX-License-Identifier: Unlicense */
#ifndef __EFI_DEVICE_PATH_PROTOCOL_H__

View File

@ -1,3 +1,4 @@
/* SPDX-FileCopyrightText: Mike Krinkin */
/* SPDX-License-Identifier: Unlicense */
#ifndef __EFI_H__

View File

@ -1,3 +1,4 @@
/* SPDX-FileCopyrightText: Mike Krinkin */
/* SPDX-License-Identifier: Unlicense */
#ifndef __EFI_FILE_PROTOCOL_H__

View File

@ -1,3 +1,4 @@
/* SPDX-FileCopyrightText: Mike Krinkin */
/* SPDX-License-Identifier: Unlicense */
#ifndef __EFI_LOADED_IMAGE_PROTOCOL_H__

View File

@ -1,3 +1,4 @@
/* SPDX-FileCopyrightText: Mike Krinkin */
/* SPDX-License-Identifier: Unlicense */
#ifndef __EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_H__

View File

@ -1,3 +1,4 @@
/* SPDX-FileCopyrightText: Mike Krinkin */
/* SPDX-License-Identifier: Unlicense */
#ifndef __EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL_H__

View File

@ -1,3 +1,4 @@
/* SPDX-FileCopyrightText: Mike Krinkin */
/* SPDX-License-Identifier: Unlicense */
#ifndef __EFI_SYSTEM_TABLE_H__

View File

@ -1,3 +1,4 @@
/* SPDX-FileCopyrightText: Mike Krinkin */
/* SPDX-License-Identifier: Unlicense */
#ifndef __EFI_TYPES_H__

View File

@ -1,4 +1,6 @@
# kaem
# SPDX-FileCopyrightText: 2022 Andrius Štikonas <andrius@stikonas.eu>
#
# SPDX-License-Identifier: GPL-3.0-or-later
# Rebuild hex0
EFI\BOOT\hex0.efi hex0_amd64.hex0 hex0.efi

View File

@ -1,3 +0,0 @@
# SPDX-License-Identifier: Unlicense
BOOTX64

53
Makefile Normal file
View File

@ -0,0 +1,53 @@
# SPDX-FileCopyrightText: 2022 Andrius Štikonas <andrius@stikonas.eu>
#
# SPDX-License-Identifier: GPL-3.0-or-later
targets = kaem-minimal hex0
ESP_SIZE_MIB = 50
QEMU = qemu-system-x86_64
QEMU_KVM = -enable-kvm
ifneq ($(wildcard /usr/share/OVMF/OVMF_CODE.fd),)
OVMF_IMG = /usr/share/OVMF/OVMF_CODE.fd
else
OVMF_IMG = /usr/share/edk2-ovmf/OVMF_CODE.fd
endif
ESP_SIZE_SECTORS = $$(($(ESP_SIZE_MIB) * 2048))
DISK_SIZE_SECTORS = $$(($(ESP_SIZE_SECTORS) + 2048 + 33))
build_dir = build
rootfs_dir = $(build_dir)/rootfs
boot_dir = $(rootfs_dir)/EFI/BOOT
.PHONY : clean rootfs qemu
qemu: $(build_dir)/disk.img $(OVMF_IMG)
$(QEMU) -cpu qemu64 -net none \
$(QEMU_KVM) \
-drive if=pflash,format=raw,unit=0,file=$(OVMF_IMG),readonly=on \
-drive if=ide,format=raw,file=$<
$(build_dir)/disk.img: $(build_dir)/esp.img
dd if=/dev/zero of=$@ bs=512 count=$(DISK_SIZE_SECTORS)
parted $@ -s -a minimal mklabel gpt
parted $@ -s -a minimal mkpart EFI FAT32 2048s $(ESP_SIZE_SECTORS)s
parted $@ -s -a minimal toggle 1 boot
dd if=$< of=$@ bs=512 seek=2048 conv=notrunc
$(build_dir)/esp.img: rootfs
dd if=/dev/zero of=$@ bs=512 count=$(ESP_SIZE_SECTORS)
mformat -i $@ -h 32 -t 32 -n 64 -c 1
mcopy -s -i $@ $(rootfs_dir)/* ::
rootfs:
rm -rf $(rootfs_dir)
mkdir -p $(boot_dir)
rsync -av . $(rootfs_dir) --exclude $(build_dir) --exclude ".*" --exclude "Development/" --exclude "*/Development/" --exclude "bootstrap-seeds/"
mkdir -p $(rootfs_dir)/bootstrap-seeds/UEFI/
rsync -av bootstrap-seeds/UEFI/ $(rootfs_dir)/bootstrap-seeds/UEFI/
mv $(rootfs_dir)/bootstrap-seeds/UEFI/amd64/kaem-optional-seed.efi $(boot_dir)/BOOTX64.efi
clean:
rm -rf $(build_dir)

View File

@ -1,3 +1,7 @@
# SPDX-FileCopyrightText: 2022 Jeremiah Orians
#
# SPDX-License-Identifier: GPL-3.0-or-later
# DOS MZ header
4D 5A # Signature
00 00 # Number of bytes in the last page.

4
amd64/artifact/README Normal file
View File

@ -0,0 +1,4 @@
# SPDX-FileCopyrightText: 2022 Andrius Štikonas <andrius@stikonas.eu>
# SPDX-License-Identifier: MIT
This is a placeholder directory that will contain AMD64 bootstrap artifacts.

View File

@ -0,0 +1,7 @@
# SPDX-FileCopyrightText: 2022 Andrius Štikonas <andrius@stikonas.eu>
#
# SPDX-License-Identifier: GPL-3.0-or-later
#################################
# Phase-1 Build hex1 from hex0 #
#################################

View File

@ -0,0 +1,16 @@
# SPDX-FileCopyrightText: 2022 Andrius Štikonas <andrius@stikonas.eu>
#
# SPDX-License-Identifier: GPL-3.0-or-later
###############################################
# Phase-0 Build hex0 from bootstrapped binary #
###############################################
bootstrap-seeds\UEFI\amd64\hex0-seed.efi amd64\hex0.hex0 amd64\artifact\hex0.efi
# hex0 should have the exact same checksum as hex0-seed as they are both supposed
# to be built from hex0_amd64.hex0 and by definition must be identical
#########################################
# Phase-0b Build minimal kaem from hex0 #
#########################################
amd64\artifact\hex0.efi amd64\kaem-minimal.hex0 amd64\artifact\kaem-0.efi
# for checksum validation reasons

@ -1 +1 @@
Subproject commit c72070654660727b28334026cbb365dcd02e8f6b
Subproject commit c422e3cf55485b8ecd21cb7afeeccf0cc6616d36

10
kaem.amd64 Normal file
View File

@ -0,0 +1,10 @@
# SPDX-FileCopyrightText: 2022 Andrius Štikonas <andrius@stikonas.eu>
#
# SPDX-License-Identifier: GPL-3.0-or-later
##################################################
# Phase 0-11 Build hex0 from bootstrapped binary #
##################################################
EFI\BOOT\BOOTX64.efi amd64\mescc-tools-seed-kaem.kaem
amd64\artifact\kaem-0.efi amd64\mescc-tools-mini-kaem.kaem