BuildSystem: add cmake variable UEFI_BOOT
If this variable is defined in cmake, image will be build with esp and booted with uefi.
This commit is contained in:
parent
5bf0f9742a
commit
29db8d0d40
|
@ -5,4 +5,5 @@ base/
|
||||||
*.tar.*
|
*.tar.*
|
||||||
toolchain/*/
|
toolchain/*/
|
||||||
|
|
||||||
|
!toolchain/local/
|
||||||
!base-sysroot.tar.gz
|
!base-sysroot.tar.gz
|
||||||
|
|
|
@ -22,6 +22,10 @@ if(DEFINED QEMU_ACCEL)
|
||||||
set(QEMU_ACCEL -accel ${QEMU_ACCEL})
|
set(QEMU_ACCEL -accel ${QEMU_ACCEL})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(DEFINED UEFI_BOOT)
|
||||||
|
set(UEFI_BOOT 1)
|
||||||
|
endif()
|
||||||
|
|
||||||
add_compile_options(-mno-sse -mno-sse2)
|
add_compile_options(-mno-sse -mno-sse2)
|
||||||
add_compile_definitions(__enable_sse=0)
|
add_compile_definitions(__enable_sse=0)
|
||||||
|
|
||||||
|
@ -67,7 +71,7 @@ add_custom_target(libstdc++
|
||||||
)
|
)
|
||||||
|
|
||||||
add_custom_target(image
|
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 kernel-install
|
||||||
DEPENDS ban-install
|
DEPENDS ban-install
|
||||||
DEPENDS libc-install
|
DEPENDS libc-install
|
||||||
|
@ -77,7 +81,7 @@ add_custom_target(image
|
||||||
)
|
)
|
||||||
|
|
||||||
add_custom_target(image-full
|
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 kernel-install
|
||||||
DEPENDS ban-install
|
DEPENDS ban-install
|
||||||
DEPENDS libc-install
|
DEPENDS libc-install
|
||||||
|
@ -92,19 +96,19 @@ add_custom_target(check-fs
|
||||||
)
|
)
|
||||||
|
|
||||||
add_custom_target(qemu
|
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
|
DEPENDS image
|
||||||
USES_TERMINAL
|
USES_TERMINAL
|
||||||
)
|
)
|
||||||
|
|
||||||
add_custom_target(qemu-nographic
|
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
|
DEPENDS image
|
||||||
USES_TERMINAL
|
USES_TERMINAL
|
||||||
)
|
)
|
||||||
|
|
||||||
add_custom_target(qemu-debug
|
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
|
DEPENDS image
|
||||||
USES_TERMINAL
|
USES_TERMINAL
|
||||||
)
|
)
|
||||||
|
|
Binary file not shown.
|
@ -4,29 +4,50 @@ set -e
|
||||||
DISK_SIZE=$[50 * 1024 * 1024]
|
DISK_SIZE=$[50 * 1024 * 1024]
|
||||||
MOUNT_DIR=/mnt
|
MOUNT_DIR=/mnt
|
||||||
|
|
||||||
truncate -s 0 $DISK_IMAGE_PATH
|
truncate -s 0 "$DISK_IMAGE_PATH"
|
||||||
truncate -s $DISK_SIZE $DISK_IMAGE_PATH
|
truncate -s $DISK_SIZE "$DISK_IMAGE_PATH"
|
||||||
|
|
||||||
sed -e 's/\s*\([-\+[:alnum:]]*\).*/\1/' << EOF | fdisk $DISK_IMAGE_PATH > /dev/null
|
if [ "$UEFI_BOOT" == "1" ]; then
|
||||||
g # gpt
|
sed -e 's/\s*\([-\+[:alnum:]]*\).*/\1/' << EOF | fdisk "$DISK_IMAGE_PATH" > /dev/null
|
||||||
n # new partition
|
g # gpt
|
||||||
1 # partition number 1
|
n # new partition
|
||||||
# default (from the beginning of the disk)
|
1 # partition number 1
|
||||||
+1MiB # bios boot partiton size
|
# default (from the beginning of the disk)
|
||||||
n # new partition
|
+16M # efi system size
|
||||||
2 # partition number 2
|
n # new partition
|
||||||
# default (right after bios boot partition)
|
2 # partition number 2
|
||||||
# default (to the end of disk)
|
# default (right after efi system partition)
|
||||||
t # set type
|
# default (to the end of disk)
|
||||||
1 # ... of partition 1
|
t # set type
|
||||||
4 # bios boot partition
|
1 # ... of partition 1
|
||||||
t # set type
|
1 # efi system
|
||||||
2 # ... of partition 2
|
t # set type
|
||||||
20 # Linux filesystem
|
2 # ... of partition 2
|
||||||
w # write changes
|
20 # Linux filesystem
|
||||||
|
w # write changes
|
||||||
EOF
|
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
|
sudo partprobe $LOOP_DEV
|
||||||
|
|
||||||
PARTITION1=${LOOP_DEV}p1
|
PARTITION1=${LOOP_DEV}p1
|
||||||
|
@ -34,8 +55,23 @@ PARTITION2=${LOOP_DEV}p2
|
||||||
|
|
||||||
sudo mkfs.ext2 -d $SYSROOT -b 1024 -q $PARTITION2
|
sudo mkfs.ext2 -d $SYSROOT -b 1024 -q $PARTITION2
|
||||||
|
|
||||||
sudo mount $PARTITION2 $MOUNT_DIR
|
if [[ "$UEFI_BOOT" == "1" ]]; then
|
||||||
sudo grub-install --no-floppy --target=i386-pc --modules="normal ext2 multiboot" --boot-directory=${MOUNT_DIR}/boot $LOOP_DEV
|
sudo mkfs.fat $PARTITION1 > /dev/null
|
||||||
sudo umount $MOUNT_DIR
|
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
|
sudo losetup -d $LOOP_DEV
|
||||||
|
|
10
image.sh
10
image.sh
|
@ -1,11 +1,19 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
|
||||||
|
|
||||||
if [ ! -f $DISK_IMAGE_PATH ]; then
|
if [ ! -f $DISK_IMAGE_PATH ]; then
|
||||||
$(dirname "$0")/image-full.sh
|
$(dirname "$0")/image-full.sh
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
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
|
MOUNT_DIR=/mnt
|
||||||
|
|
||||||
LOOP_DEV=$(sudo losetup -f --show $DISK_IMAGE_PATH)
|
LOOP_DEV=$(sudo losetup -f --show $DISK_IMAGE_PATH)
|
||||||
|
|
9
qemu.sh
9
qemu.sh
|
@ -1,9 +1,18 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
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 \
|
qemu-system-$BANAN_ARCH \
|
||||||
-m 128 \
|
-m 128 \
|
||||||
-smp 2 \
|
-smp 2 \
|
||||||
|
$BIOS_ARGS \
|
||||||
-drive format=raw,id=disk,file=${DISK_IMAGE_PATH},if=none \
|
-drive format=raw,id=disk,file=${DISK_IMAGE_PATH},if=none \
|
||||||
-device ahci,id=ahci \
|
-device ahci,id=ahci \
|
||||||
-device ide-hd,drive=disk,bus=ahci.0 \
|
-device ide-hd,drive=disk,bus=ahci.0 \
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
|
@ -0,0 +1,2 @@
|
||||||
|
insmod part_gpt
|
||||||
|
configfile (hd0,gpt2)/boot/grub/grub.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
|
||||||
|
}
|
Loading…
Reference in New Issue