diff --git a/.gitignore b/.gitignore index 9c177a55e..fe19aea93 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ base/ *.tar.* toolchain/*/ +!toolchain/local/ !base-sysroot.tar.gz diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c3056da4..5803ea0a0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,10 @@ if(DEFINED QEMU_ACCEL) set(QEMU_ACCEL -accel ${QEMU_ACCEL}) endif() +if(DEFINED UEFI_BOOT) + set(UEFI_BOOT 1) +endif() + add_compile_options(-mno-sse -mno-sse2) add_compile_definitions(__enable_sse=0) @@ -67,7 +71,7 @@ add_custom_target(libstdc++ ) add_custom_target(image - COMMAND ${CMAKE_COMMAND} -E env SYSROOT="${BANAN_SYSROOT}" DISK_IMAGE_PATH="${DISK_IMAGE_PATH}" ${CMAKE_SOURCE_DIR}/image.sh + COMMAND ${CMAKE_COMMAND} -E env BANAN_ARCH="${BANAN_ARCH}" SYSROOT="${BANAN_SYSROOT}" DISK_IMAGE_PATH="${DISK_IMAGE_PATH}" TOOLCHAIN="${TOOLCHAIN_PREFIX}" UEFI_BOOT="${UEFI_BOOT}" ${CMAKE_SOURCE_DIR}/image.sh DEPENDS kernel-install DEPENDS ban-install DEPENDS libc-install @@ -77,7 +81,7 @@ add_custom_target(image ) add_custom_target(image-full - COMMAND ${CMAKE_COMMAND} -E env SYSROOT="${BANAN_SYSROOT}" DISK_IMAGE_PATH="${DISK_IMAGE_PATH}" ${CMAKE_SOURCE_DIR}/image-full.sh + COMMAND ${CMAKE_COMMAND} -E env BANAN_ARCH="${BANAN_ARCH}" SYSROOT="${BANAN_SYSROOT}" DISK_IMAGE_PATH="${DISK_IMAGE_PATH}" TOOLCHAIN="${TOOLCHAIN_PREFIX}" UEFI_BOOT="${UEFI_BOOT}" ${CMAKE_SOURCE_DIR}/image-full.sh DEPENDS kernel-install DEPENDS ban-install DEPENDS libc-install @@ -92,19 +96,19 @@ add_custom_target(check-fs ) add_custom_target(qemu - COMMAND ${CMAKE_COMMAND} -E env BANAN_ARCH="${BANAN_ARCH}" DISK_IMAGE_PATH="${DISK_IMAGE_PATH}" ${CMAKE_SOURCE_DIR}/qemu.sh -serial stdio ${QEMU_ACCEL} + COMMAND ${CMAKE_COMMAND} -E env BANAN_ARCH="${BANAN_ARCH}" DISK_IMAGE_PATH="${DISK_IMAGE_PATH}" UEFI_BOOT="${UEFI_BOOT}" ${CMAKE_SOURCE_DIR}/qemu.sh -serial stdio ${QEMU_ACCEL} DEPENDS image USES_TERMINAL ) add_custom_target(qemu-nographic - COMMAND ${CMAKE_COMMAND} -E env BANAN_ARCH="${BANAN_ARCH}" DISK_IMAGE_PATH="${DISK_IMAGE_PATH}" ${CMAKE_SOURCE_DIR}/qemu.sh -nographic ${QEMU_ACCEL} + COMMAND ${CMAKE_COMMAND} -E env BANAN_ARCH="${BANAN_ARCH}" DISK_IMAGE_PATH="${DISK_IMAGE_PATH}" UEFI_BOOT="${UEFI_BOOT}" ${CMAKE_SOURCE_DIR}/qemu.sh -nographic ${QEMU_ACCEL} DEPENDS image USES_TERMINAL ) add_custom_target(qemu-debug - COMMAND ${CMAKE_COMMAND} -E env BANAN_ARCH="${BANAN_ARCH}" DISK_IMAGE_PATH="${DISK_IMAGE_PATH}" ${CMAKE_SOURCE_DIR}/qemu.sh -serial stdio -d int -no-reboot + COMMAND ${CMAKE_COMMAND} -E env BANAN_ARCH="${BANAN_ARCH}" DISK_IMAGE_PATH="${DISK_IMAGE_PATH}" UEFI_BOOT="${UEFI_BOOT}" ${CMAKE_SOURCE_DIR}/qemu.sh -serial stdio -d int -no-reboot DEPENDS image USES_TERMINAL ) diff --git a/base-sysroot.tar.gz b/base-sysroot.tar.gz index 310827bc1..f30cf5e6f 100644 Binary files a/base-sysroot.tar.gz and b/base-sysroot.tar.gz differ diff --git a/image-full.sh b/image-full.sh index 934f7556e..8ebc2ddc9 100755 --- a/image-full.sh +++ b/image-full.sh @@ -4,29 +4,50 @@ set -e DISK_SIZE=$[50 * 1024 * 1024] MOUNT_DIR=/mnt -truncate -s 0 $DISK_IMAGE_PATH -truncate -s $DISK_SIZE $DISK_IMAGE_PATH +truncate -s 0 "$DISK_IMAGE_PATH" +truncate -s $DISK_SIZE "$DISK_IMAGE_PATH" -sed -e 's/\s*\([-\+[:alnum:]]*\).*/\1/' << EOF | fdisk $DISK_IMAGE_PATH > /dev/null - g # gpt - n # new partition - 1 # partition number 1 - # default (from the beginning of the disk) - +1MiB # bios boot partiton size - n # new partition - 2 # partition number 2 - # default (right after bios boot partition) - # default (to the end of disk) - t # set type - 1 # ... of partition 1 - 4 # bios boot partition - t # set type - 2 # ... of partition 2 - 20 # Linux filesystem - w # write changes +if [ "$UEFI_BOOT" == "1" ]; then + sed -e 's/\s*\([-\+[:alnum:]]*\).*/\1/' << EOF | fdisk "$DISK_IMAGE_PATH" > /dev/null + g # gpt + n # new partition + 1 # partition number 1 + # default (from the beginning of the disk) + +16M # efi system size + n # new partition + 2 # partition number 2 + # default (right after efi system partition) + # default (to the end of disk) + t # set type + 1 # ... of partition 1 + 1 # efi system + t # set type + 2 # ... of partition 2 + 20 # Linux filesystem + w # write changes EOF +else + sed -e 's/\s*\([-\+[:alnum:]]*\).*/\1/' << EOF | fdisk "$DISK_IMAGE_PATH" > /dev/null + g # gpt + n # new partition + 1 # partition number 1 + # default (from the beginning of the disk) + +1M # bios boot partition size + n # new partition + 2 # partition number 2 + # default (right after bios partition) + # default (to the end of disk) + t # set type + 1 # ... of partition 1 + 4 # bios boot partition + t # set type + 2 # ... of partition 2 + 20 # Linux filesystem + w # write changes +EOF +fi -LOOP_DEV=$(sudo losetup -f --show $DISK_IMAGE_PATH) +LOOP_DEV=$(sudo losetup -f --show "$DISK_IMAGE_PATH") sudo partprobe $LOOP_DEV PARTITION1=${LOOP_DEV}p1 @@ -34,8 +55,23 @@ PARTITION2=${LOOP_DEV}p2 sudo mkfs.ext2 -d $SYSROOT -b 1024 -q $PARTITION2 -sudo mount $PARTITION2 $MOUNT_DIR -sudo grub-install --no-floppy --target=i386-pc --modules="normal ext2 multiboot" --boot-directory=${MOUNT_DIR}/boot $LOOP_DEV -sudo umount $MOUNT_DIR +if [[ "$UEFI_BOOT" == "1" ]]; then + sudo mkfs.fat $PARTITION1 > /dev/null + sudo mount $PARTITION1 "$MOUNT_DIR" + sudo mkdir -p "$MOUNT_DIR/EFI/BOOT" + sudo "$TOOLCHAIN/bin/grub-mkstandalone" -O "$BANAN_ARCH-efi" -o "$MOUNT_DIR/EFI/BOOT/BOOTX64.EFI" "boot/grub/grub.cfg=$TOOLCHAIN/grub-memdisk.cfg" + sudo umount "$MOUNT_DIR" + + sudo mount $PARTITION2 "$MOUNT_DIR" + sudo mkdir -p "$MOUNT_DIR/boot/grub" + sudo cp "$TOOLCHAIN/grub-uefi.cfg" "$MOUNT_DIR/boot/grub/grub.cfg" + sudo umount "$MOUNT_DIR" +else + sudo mount $PARTITION2 "$MOUNT_DIR" + sudo grub-install --no-floppy --target=i386-pc --modules="normal ext2 multiboot" --boot-directory="$MOUNT_DIR/boot" $LOOP_DEV + sudo mkdir -p "$MOUNT_DIR/boot/grub" + sudo cp "$TOOLCHAIN/grub-legacy-boot.cfg" "$MOUNT_DIR/boot/grub/grub.cfg" + sudo umount "$MOUNT_DIR" +fi sudo losetup -d $LOOP_DEV diff --git a/image.sh b/image.sh index 18c386562..c0662b8e2 100755 --- a/image.sh +++ b/image.sh @@ -1,11 +1,19 @@ #!/bin/bash -set -e if [ ! -f $DISK_IMAGE_PATH ]; then $(dirname "$0")/image-full.sh exit 0 fi +fdisk -l $DISK_IMAGE_PATH | grep -q 'EFI System'; IMAGE_IS_UEFI=$? +[[ $UEFI_BOOT == 1 ]]; CREATE_IS_UEFI=$? + +if [ $IMAGE_IS_UEFI -ne $CREATE_IS_UEFI ]; then + echo Converting disk image to/from UEFI + $(dirname "$0")/image-full.sh + exit 0 +fi + MOUNT_DIR=/mnt LOOP_DEV=$(sudo losetup -f --show $DISK_IMAGE_PATH) diff --git a/qemu.sh b/qemu.sh index f92acf2c7..4530527ae 100755 --- a/qemu.sh +++ b/qemu.sh @@ -1,9 +1,18 @@ #!/bin/bash set -e +if [ -z ${OVMF_PATH+x} ]; then + OVMF_PATH="/usr/share/ovmf/x64/OVMF.fd" +fi + +if [ "$UEFI_BOOT" == "1" ]; then + BIOS_ARGS="-bios $OVMF_PATH -net none" +fi + qemu-system-$BANAN_ARCH \ -m 128 \ -smp 2 \ + $BIOS_ARGS \ -drive format=raw,id=disk,file=${DISK_IMAGE_PATH},if=none \ -device ahci,id=ahci \ -device ide-hd,drive=disk,bus=ahci.0 \ diff --git a/toolchain/local/grub-legacy-boot.cfg b/toolchain/local/grub-legacy-boot.cfg new file mode 100644 index 000000000..1798a1e54 --- /dev/null +++ b/toolchain/local/grub-legacy-boot.cfg @@ -0,0 +1,23 @@ +menuentry "banan-os" { + multiboot /boot/banan-os.kernel root=/dev/sda2 +} + +menuentry "banan-os (no serial)" { + multiboot /boot/banan-os.kernel root=/dev/sda2 noserial +} + +menuentry "banan-os (only serial)" { + multiboot /boot/banan-os.kernel root=/dev/sda2 console=ttyS0 +} + +menuentry "banan-os (no apic)" { + multiboot /boot/banan-os.kernel root=/dev/sda2 noapic +} + +menuentry "banan-os (no apic, no serial)" { + multiboot /boot/banan-os.kernel root=/dev/sda2 noapic noserial +} + +menuentry "banan-os (no apic, only serial)" { + multiboot /boot/banan-os.kernel root=/dev/sda2 noapic console=ttyS0 +} diff --git a/toolchain/local/grub-memdisk.cfg b/toolchain/local/grub-memdisk.cfg new file mode 100644 index 000000000..149ca24d6 --- /dev/null +++ b/toolchain/local/grub-memdisk.cfg @@ -0,0 +1,2 @@ +insmod part_gpt +configfile (hd0,gpt2)/boot/grub/grub.cfg diff --git a/toolchain/local/grub-uefi.cfg b/toolchain/local/grub-uefi.cfg new file mode 100644 index 000000000..ca0ecb2c1 --- /dev/null +++ b/toolchain/local/grub-uefi.cfg @@ -0,0 +1,26 @@ +insmod part_gpt +set root=(hd0,gpt2) + +menuentry "banan-os" { + multiboot /boot/banan-os.kernel root=/dev/sda2 +} + +menuentry "banan-os (no serial)" { + multiboot /boot/banan-os.kernel root=/dev/sda2 noserial +} + +menuentry "banan-os (only serial)" { + multiboot /boot/banan-os.kernel root=/dev/sda2 console=ttyS0 +} + +menuentry "banan-os (no apic)" { + multiboot /boot/banan-os.kernel root=/dev/sda2 noapic +} + +menuentry "banan-os (no apic, no serial)" { + multiboot /boot/banan-os.kernel root=/dev/sda2 noapic noserial +} + +menuentry "banan-os (no apic, only serial)" { + multiboot /boot/banan-os.kernel root=/dev/sda2 noapic console=ttyS0 +}