From b35cad0c2e4afde4bfae50d21551837c6185b301 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Tue, 2 Apr 2024 12:48:35 +0300 Subject: [PATCH] Bootloader allow installation when BANAN_ARCH=i686 --- bootloader/installer/CMakeLists.txt | 17 +++++++++++------ bootloader/installer/ELF.cpp | 2 +- script/install-bootloader.sh | 11 ++++++++--- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/bootloader/installer/CMakeLists.txt b/bootloader/installer/CMakeLists.txt index f2abc69a..d5efc80f 100644 --- a/bootloader/installer/CMakeLists.txt +++ b/bootloader/installer/CMakeLists.txt @@ -1,6 +1,11 @@ cmake_minimum_required(VERSION 3.26) -project(x86_64-banan_os-bootloader-installer CXX) +if (NOT DEFINED ENV{BANAN_ARCH}) + message(FATAL_ERROR "environment variable BANAN_ARCH not defined") +endif () +set(BANAN_ARCH $ENV{BANAN_ARCH}) + +project(banan_os-bootloader-installer CXX) set(SOURCES crc32.cpp @@ -10,8 +15,8 @@ set(SOURCES main.cpp ) -add_executable(x86_64-banan_os-bootloader-installer ${SOURCES}) -target_compile_options(x86_64-banan_os-bootloader-installer PRIVATE -O2 -std=c++20) -target_compile_definitions(x86_64-banan_os-bootloader-installer PRIVATE __arch=x86_64) -target_include_directories(x86_64-banan_os-bootloader-installer PRIVATE ${CMAKE_SOURCE_DIR}/../../LibELF/include) -target_include_directories(x86_64-banan_os-bootloader-installer PRIVATE ${CMAKE_SOURCE_DIR}/../../kernel/include) +add_executable(banan_os-bootloader-installer ${SOURCES}) +target_compile_options(banan_os-bootloader-installer PRIVATE -O2 -std=c++20) +target_compile_definitions(banan_os-bootloader-installer PRIVATE __arch=${BANAN_ARCH}) +target_include_directories(banan_os-bootloader-installer PRIVATE ${CMAKE_SOURCE_DIR}/../../LibELF/include) +target_include_directories(banan_os-bootloader-installer PRIVATE ${CMAKE_SOURCE_DIR}/../../kernel/include) diff --git a/bootloader/installer/ELF.cpp b/bootloader/installer/ELF.cpp index bc2d0845..99c5b4d5 100644 --- a/bootloader/installer/ELF.cpp +++ b/bootloader/installer/ELF.cpp @@ -81,7 +81,7 @@ bool ELFFile::validate_elf_header() const #if ARCH(x86_64) if (elf_header.e_ident[EI_CLASS] != ELFCLASS64) -#elif ARCH(i386) +#elif ARCH(i686) if (elf_header.e_ident[EI_CLASS] != ELFCLASS32) #endif { diff --git a/script/install-bootloader.sh b/script/install-bootloader.sh index 204190c4..410c8c62 100755 --- a/script/install-bootloader.sh +++ b/script/install-bootloader.sh @@ -2,6 +2,11 @@ set -e +if [[ -z $BANAN_ARCH ]]; then + echo "You must set the BANAN_ARCH environment variable" >&2 + exit 1 +fi + if [[ -z $BANAN_DISK_IMAGE_PATH ]]; then echo "You must set the BANAN_DISK_IMAGE_PATH environment variable" >&2 exit 1 @@ -26,7 +31,7 @@ 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) -INSTALLER_BUILD_DIR=$BANAN_ROOT_DIR/bootloader/installer/build +INSTALLER_BUILD_DIR=$BANAN_ROOT_DIR/bootloader/installer/build/$BANAN_ARCH BOOTLOADER_ELF=$BANAN_BUILD_DIR/bootloader/bios/bootloader if ! [ -f $BOOTLOADER_ELF ]; then @@ -37,11 +42,11 @@ fi if ! [ -d $INSTALLER_BUILD_DIR ]; then mkdir -p $INSTALLER_BUILD_DIR cd $INSTALLER_BUILD_DIR - $CMAKE_COMMAND .. + $CMAKE_COMMAND ../.. fi cd $INSTALLER_BUILD_DIR make echo installing bootloader -$INSTALLER_BUILD_DIR/x86_64-banan_os-bootloader-installer $BOOTLOADER_ELF $BANAN_DISK_IMAGE_PATH $ROOT_PARTITION_GUID +$INSTALLER_BUILD_DIR/banan_os-bootloader-installer $BOOTLOADER_ELF $BANAN_DISK_IMAGE_PATH $ROOT_PARTITION_GUID