From 1a75262b048b824d70d2f440c8d0fe518dd57f93 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Sun, 12 Nov 2023 01:17:30 +0200 Subject: [PATCH] BuildSystem: add bootloader target Use this target to run banan-os with custom bootloader --- bootloader/build-and-run.sh | 45 ------------------------------------- bootloader/install.sh | 35 +++++++++++++++++++++++++++++ script/build.sh | 6 ++++- 3 files changed, 40 insertions(+), 46 deletions(-) delete mode 100755 bootloader/build-and-run.sh create mode 100755 bootloader/install.sh diff --git a/bootloader/build-and-run.sh b/bootloader/build-and-run.sh deleted file mode 100755 index f21857aa..00000000 --- a/bootloader/build-and-run.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/sh - -set -e - -CURRENT_DIR=$(dirname $(realpath $0)) - -INSTALLER_DIR=$CURRENT_DIR/installer -INSTALLER_BUILD_DIR=$INSTALLER_DIR/build - -BUILD_DIR=$CURRENT_DIR/build -DISK_IMAGE_PATH=$CURRENT_DIR/test.img - -if ! [ -d $INSTALLER_BUILD_DIR ]; then - mkdir -p $INSTALLER_BUILD_DIR - cd $INSTALLER_BUILD_DIR - cmake .. -fi - -cd $INSTALLER_BUILD_DIR -make - -cd $CURRENT_DIR - -echo creating clean disk image -truncate --size 0 $DISK_IMAGE_PATH -truncate --size 50M $DISK_IMAGE_PATH -echo -ne 'g\nn\n\n\n+1M\nt 1\n4\nw\n' | fdisk $DISK_IMAGE_PATH > /dev/null - -mkdir -p $BUILD_DIR - -echo compiling bootloader -x86_64-banan_os-as arch/x86_64/boot.S -o $BUILD_DIR/bootloader.o - -echo linking bootloader -x86_64-banan_os-ld -nostdlib -T arch/x86_64/linker.ld $BUILD_DIR/bootloader.o -o $BUILD_DIR/bootloader - -echo installing bootloader -$INSTALLER_BUILD_DIR/x86_64-banan_os-bootloader-installer $BUILD_DIR/bootloader $DISK_IMAGE_PATH - -if [ "$1" == "debug" ] ; then - QEMU_FLAGS="-s -S" -fi - -echo running qemu -env BANAN_DISK_IMAGE_PATH=${DISK_IMAGE_PATH} BANAN_ARCH=x86_64 ../script/qemu.sh $QEMU_FLAGS diff --git a/bootloader/install.sh b/bootloader/install.sh new file mode 100755 index 00000000..037d4aa2 --- /dev/null +++ b/bootloader/install.sh @@ -0,0 +1,35 @@ +#!/bin/sh + +set -e + +if [[ -z $BANAN_DISK_IMAGE_PATH ]]; then + echo "You must set the BANAN_DISK_IMAGE_PATH environment variable" >&2 + exit 1 +fi + +CURRENT_DIR=$(dirname $(realpath $0)) + +INSTALLER_DIR=$CURRENT_DIR/installer +INSTALLER_BUILD_DIR=$INSTALLER_DIR/build + +BUILD_DIR=$CURRENT_DIR/build + +if ! [ -d $INSTALLER_BUILD_DIR ]; then + mkdir -p $INSTALLER_BUILD_DIR + cd $INSTALLER_BUILD_DIR + cmake .. +fi + +cd $INSTALLER_BUILD_DIR +make + +mkdir -p $BUILD_DIR + +echo compiling bootloader +x86_64-banan_os-as $CURRENT_DIR/arch/x86_64/boot.S -o $BUILD_DIR/bootloader.o + +echo linking bootloader +x86_64-banan_os-ld -nostdlib -T $CURRENT_DIR/arch/x86_64/linker.ld $BUILD_DIR/bootloader.o -o $BUILD_DIR/bootloader + +echo installing bootloader +$INSTALLER_BUILD_DIR/x86_64-banan_os-bootloader-installer $BUILD_DIR/bootloader $BANAN_DISK_IMAGE_PATH diff --git a/script/build.sh b/script/build.sh index 52642add..d51bc084 100755 --- a/script/build.sh +++ b/script/build.sh @@ -97,8 +97,12 @@ case $1 in rm -f $FAKEROOT_FILE rm -rf $BANAN_SYSROOT ;; + bootloader) + create_image + $BANAN_ROOT_DIR/bootloader/install.sh + $BANAN_SCRIPT_DIR/qemu.sh -serial stdio $QEMU_ACCEL + ;; *) build_target $1 ;; esac -