Bootloader: Build with cmake instead of custom script

This commit is contained in:
Bananymous 2023-11-14 03:44:47 +02:00
parent b0b39c56ba
commit 8aab3a62cc
4 changed files with 30 additions and 19 deletions

View File

@ -16,6 +16,7 @@ set(BANAN_BIN ${BANAN_SYSROOT}/usr/bin)
set(BANAN_BOOT ${BANAN_SYSROOT}/boot)
add_subdirectory(kernel)
add_subdirectory(bootloader)
add_subdirectory(BAN)
add_subdirectory(libc)
add_subdirectory(LibELF)

15
bootloader/CMakeLists.txt Normal file
View File

@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.26)
project(bootloader ASM)
set(BOOTLOADER_SOURCES
boot.S
command_line.S
disk.S
memory_map.S
utils.S
)
add_executable(bootloader ${BOOTLOADER_SOURCES})
target_link_options(bootloader PUBLIC LINKER:-T,${CMAKE_CURRENT_SOURCE_DIR}/linker.ld)
target_link_options(bootloader PUBLIC -nostdlib)

View File

@ -7,16 +7,22 @@ if [[ -z $BANAN_DISK_IMAGE_PATH ]]; then
exit 1
fi
if [[ -z $BANAN_BUILD_DIR ]]; then
echo "You must set the BANAN_BUILD_DIR environment variable" >&2
exit 1
fi
ROOT_PARTITION_INDEX=2
ROOT_PARTITION_INFO=$(fdisk -x $BANAN_DISK_IMAGE_PATH | grep "^$BANAN_DISK_IMAGE_PATH" | head -$ROOT_PARTITION_INDEX | tail -1)
ROOT_PARTITION_GUID=$(echo $ROOT_PARTITION_INFO | cut -d' ' -f6)
CURRENT_DIR=$(dirname $(realpath $0))
INSTALLER_BUILD_DIR=$(dirname $(realpath $0))/installer/build
BOOTLOADER_ELF=$BANAN_BUILD_DIR/bootloader/bootloader
INSTALLER_DIR=$CURRENT_DIR/installer
INSTALLER_BUILD_DIR=$INSTALLER_DIR/build
BUILD_DIR=$CURRENT_DIR/build
if ! [ -f $BOOTLOADER_ELF ]; then
echo "You must build the bootloader first" >&2
exit 1
fi
if ! [ -d $INSTALLER_BUILD_DIR ]; then
mkdir -p $INSTALLER_BUILD_DIR
@ -27,17 +33,5 @@ fi
cd $INSTALLER_BUILD_DIR
make
mkdir -p $BUILD_DIR
echo compiling bootloader
x86_64-banan_os-as $CURRENT_DIR/boot.S -o $BUILD_DIR/boot.o
x86_64-banan_os-as $CURRENT_DIR/command_line.S -o $BUILD_DIR/command_line.o
x86_64-banan_os-as $CURRENT_DIR/disk.S -o $BUILD_DIR/disk.o
x86_64-banan_os-as $CURRENT_DIR/memory_map.S -o $BUILD_DIR/memory_map.o
x86_64-banan_os-as $CURRENT_DIR/utils.S -o $BUILD_DIR/utils.o
echo linking bootloader
x86_64-banan_os-ld -nostdlib -T $CURRENT_DIR/linker.ld $BUILD_DIR/boot.o $BUILD_DIR/command_line.o $BUILD_DIR/disk.o $BUILD_DIR/memory_map.o $BUILD_DIR/utils.o -o $BUILD_DIR/bootloader
echo installing bootloader to
$INSTALLER_BUILD_DIR/x86_64-banan_os-bootloader-installer $BUILD_DIR/bootloader $BANAN_DISK_IMAGE_PATH $ROOT_PARTITION_GUID
echo installing bootloader
$INSTALLER_BUILD_DIR/x86_64-banan_os-bootloader-installer $BOOTLOADER_ELF $BANAN_DISK_IMAGE_PATH $ROOT_PARTITION_GUID

View File

@ -99,6 +99,7 @@ case $1 in
;;
bootloader)
create_image
build_target bootloader
$BANAN_ROOT_DIR/bootloader/install.sh
$BANAN_SCRIPT_DIR/qemu.sh -serial stdio $QEMU_ACCEL
;;