From 350748137b62e2aa15c62c53ebf4d30816e441f4 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Fri, 30 Apr 2021 15:03:27 +0200 Subject: Added MBR driver and better disk creation --- run | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'run') diff --git a/run b/run index 6e9ea7e..5504cb5 100755 --- a/run +++ b/run @@ -86,7 +86,7 @@ make_cross() { } make_disk() { - rm -rf disk && mkdir -p disk/font/ && mkdir -p disk/icons/ && mkdir -p disk/conf/ + rm -rf disk && mkdir -p disk/font/ && mkdir -p disk/icons/ && mkdir -p disk/conf/ && mkdir -p disk/boot/ echo "Hallo" >disk/conf/test cp -r res/ disk/ @@ -145,8 +145,16 @@ make_build() { $MAKE -j $($NPROC) DEBUG=0 fi - # Create disk image + # Prepare Grub + mkdir -p disk/boot/grub/ + cp build/apps/kernel/exec disk/boot/melvix + cp boot/grub.cfg disk/boot/grub/ + + # Create disk image # TODO: Fix build for OpenBSD dd if=/dev/zero of=build/disk.img bs=1k count=32k status=none + DEV=$($SUDO losetup --find --partscan --show build/disk.img) + PART="p1" + $SUDO parted -s "$DEV" mklabel msdos mkpart primary ext2 32k 100% -a minimal set 1 boot on if [ "$(uname -s)" = "OpenBSD" ]; then VND=$($SUDO vnconfig build/disk.img) ( @@ -159,7 +167,7 @@ make_build() { ) | $SUDO fdisk -e $VND >/dev/null $SUDO mkfs.ext2 -F /dev/${VND}i >/dev/null else - $SUDO mke2fs -b 1024 -q build/disk.img + $SUDO mke2fs -b 1024 -q "$DEV$PART" fi # Set test app as init @@ -171,21 +179,19 @@ make_build() { if [ "$(uname -s)" = "OpenBSD" ]; then $SUDO mount -t ext2fs /dev/${VND}i mnt/ else - $SUDO mount build/disk.img mnt/ + $SUDO mount "$DEV$PART" mnt/ fi $SUDO cp -r disk/* mnt/ $SUDO chmod -R 0 mnt/conf/ $SUDO cp -r build/apps/ mnt/apps/ - $SUDO umount mnt/ - rm -rf mnt/ - - mkdir -p iso/boot/grub/ - cp build/apps/kernel/exec iso/boot/melvix - cp boot/grub.cfg iso/boot/grub/ - grub-mkrescue -o build/melvix.iso iso/ + $SUDO grub-install --boot-directory=mnt/boot --target=i386-pc --modules="ext2" "$DEV" + $SUDO umount mnt/ || (sleep 1 && sync && sudo umount mnt) + $SUDO rm -rf mnt/ if [ "$(uname -s)" = "OpenBSD" ]; then $SUDO vnconfig -u $VND + else + $SUDO losetup -d "$DEV" fi printf "Build finshed successfully!\n\n" @@ -193,17 +199,17 @@ make_build() { make_test() { if [ "$mode" = "test" ]; then - qemu_with_flags -serial file:test.log -nographic -cdrom build/melvix.iso -drive file=build/disk.img,format=raw,index=1,media=disk + qemu_with_flags -serial file:test.log -nographic -drive file=build/disk.img,format=raw,index=1,media=disk echo grep -E 'PASS|FAIL' test.log if grep -q "All tests passed" test.log; then exit 0; else exit 1; fi else - qemu_with_flags -serial stdio -cdrom build/melvix.iso -drive file=build/disk.img,format=raw,index=1,media=disk + qemu_with_flags -serial stdio -drive file=build/disk.img,format=raw,index=1,media=disk fi } make_debug() { - qemu_with_flags -serial stdio -cdrom build/melvix.iso -drive file=build/disk.img,format=raw,index=1,media=disk -s -S + qemu_with_flags -serial stdio -drive file=build/disk.img,format=raw,index=1,media=disk -s -S } make_disasm() { -- cgit v1.2.3