Compare commits

...

5 Commits

Author SHA1 Message Date
Bananymous f2397b775c BuildSystem: Remove old bootloader target
And creating image now builds the bootloader
2023-11-20 00:56:06 +02:00
Bananymous 8b81406b81 Toolchain: Build full toolchain with one call to toolchain/build.sh 2023-11-20 00:56:06 +02:00
Bananymous e2515c1109 Buildsystem: default bootloader is not my custom one
You can set BANAN_BOOTLOADER=GRUB to use grub instead. Image creation
does not convert disk image now automatically between bootloaders and
calling ./bos image-full is now required.
2023-11-18 17:18:03 +02:00
Bananymous 5293ae070d Kernel: ProcFS inodes reflect processes ruid/rgid
setgid/setuid did not change the permissions of procfs inodes. This
made Shell launched by init not appear in meminfo.
2023-11-18 14:26:44 +02:00
Bananymous 6e2443ca72 Bootloader do some directory restructuring 2023-11-18 13:59:45 +02:00
21 changed files with 93 additions and 112 deletions

View File

@ -1,3 +0,0 @@
test.img
build/
installer/build/

View File

@ -1,18 +1,3 @@
cmake_minimum_required(VERSION 3.26)
project(bootloader ASM)
set(BOOTLOADER_SOURCES
boot.S
command_line.S
disk.S
elf.S
ext2.S
framebuffer.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)
add_subdirectory(bios)

View File

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

View File

@ -1,37 +0,0 @@
#!/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
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)
INSTALLER_BUILD_DIR=$(dirname $(realpath $0))/installer/build
BOOTLOADER_ELF=$BANAN_BUILD_DIR/bootloader/bootloader
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
cd $INSTALLER_BUILD_DIR
cmake ..
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

1
bootloader/installer/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
build/

View File

@ -13,6 +13,9 @@ namespace Kernel
static BAN::ErrorOr<BAN::RefPtr<ProcPidInode>> create_new(Process&, TmpFileSystem&, mode_t, uid_t, gid_t);
~ProcPidInode() = default;
virtual uid_t uid() const override { return m_process.credentials().ruid(); }
virtual gid_t gid() const override { return m_process.credentials().rgid(); }
void cleanup();
protected:
@ -31,6 +34,9 @@ namespace Kernel
static BAN::ErrorOr<BAN::RefPtr<ProcROInode>> create_new(Process&, size_t (Process::*callback)(off_t, BAN::ByteSpan) const, TmpFileSystem&, mode_t, uid_t, gid_t);
~ProcROInode() = default;
virtual uid_t uid() const override { return m_process.credentials().ruid(); }
virtual gid_t gid() const override { return m_process.credentials().rgid(); }
protected:
virtual BAN::ErrorOr<size_t> read_impl(off_t, BAN::ByteSpan) override;

View File

@ -27,8 +27,8 @@ namespace Kernel
virtual ino_t ino() const override final { return m_ino; }
virtual Mode mode() const override final { return Mode(m_inode_info.mode); }
virtual nlink_t nlink() const override final { return m_inode_info.nlink; }
virtual uid_t uid() const override final { return m_inode_info.uid; }
virtual gid_t gid() const override final { return m_inode_info.gid; }
virtual uid_t uid() const override { return m_inode_info.uid; }
virtual gid_t gid() const override { return m_inode_info.gid; }
virtual off_t size() const override final { return m_inode_info.size; }
virtual timespec atime() const override final { return m_inode_info.atime; }
virtual timespec mtime() const override final { return m_inode_info.mtime; }

View File

@ -39,11 +39,10 @@ build_toolchain () {
fi
$BANAN_TOOLCHAIN_DIR/build.sh
build_target libc-install
$BANAN_TOOLCHAIN_DIR/build.sh libstdc++
}
create_image () {
build_target bootloader
build_target install-sysroot
$BANAN_SCRIPT_DIR/image.sh "$1"
}
@ -97,12 +96,6 @@ case $1 in
rm -f $FAKEROOT_FILE
rm -rf $BANAN_SYSROOT
;;
bootloader)
create_image
build_target bootloader
$BANAN_ROOT_DIR/bootloader/install.sh
$BANAN_SCRIPT_DIR/qemu.sh -serial stdio $QEMU_ACCEL
;;
*)
build_target $1
;;

View File

@ -25,3 +25,7 @@ export BANAN_DISK_IMAGE_PATH=$BANAN_BUILD_DIR/banan-os.img
if [[ -z $BANAN_UEFI_BOOT ]]; then
export BANAN_UEFI_BOOT=0
fi
if [[ -z $BANAN_BOOTLOADER ]]; then
export BANAN_BOOTLOADER="BANAN"
fi

View File

@ -15,6 +15,11 @@ if [[ -z $BANAN_TOOLCHAIN_PREFIX ]]; then
exit 1
fi
if [[ -z $BANAN_BOOTLOADER ]]; then
echo "You must set the BANAN_BOOTLOADER environment variable" >&2
exit 1
fi
if [[ -z $BANAN_ARCH ]]; then
echo "You must set the BANAN_ARCH environment variable" >&2
exit 1
@ -74,23 +79,39 @@ PARTITION2=${LOOP_DEV}p2
sudo mkfs.ext2 -b 1024 -q $PARTITION2
if [[ "$BANAN_UEFI_BOOT" == "1" ]]; then
sudo mkfs.fat $PARTITION1 > /dev/null
sudo mount $PARTITION1 "$MOUNT_DIR"
sudo mkdir -p "$MOUNT_DIR/EFI/BOOT"
sudo "$BANAN_TOOLCHAIN_PREFIX/bin/grub-mkstandalone" -O "$BANAN_ARCH-efi" -o "$MOUNT_DIR/EFI/BOOT/BOOTX64.EFI" "boot/grub/grub.cfg=$BANAN_TOOLCHAIN_DIR/grub-memdisk.cfg"
sudo umount "$MOUNT_DIR"
if [[ "$BANAN_BOOTLOADER" == "GRUB" ]]; then
if [[ "$BANAN_UEFI_BOOT" == "1" ]]; then
sudo mkfs.fat $PARTITION1 > /dev/null
sudo mount $PARTITION1 "$MOUNT_DIR"
sudo mkdir -p "$MOUNT_DIR/EFI/BOOT"
sudo "$BANAN_TOOLCHAIN_PREFIX/bin/grub-mkstandalone" -O "$BANAN_ARCH-efi" -o "$MOUNT_DIR/EFI/BOOT/BOOTX64.EFI" "boot/grub/grub.cfg=$BANAN_TOOLCHAIN_DIR/grub-memdisk.cfg"
sudo umount "$MOUNT_DIR"
sudo mount $PARTITION2 "$MOUNT_DIR"
sudo mkdir -p "$MOUNT_DIR/boot/grub"
sudo cp "$BANAN_TOOLCHAIN_DIR/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 "$BANAN_TOOLCHAIN_DIR/grub-legacy-boot.cfg" "$MOUNT_DIR/boot/grub/grub.cfg"
sudo umount "$MOUNT_DIR"
sudo mount $PARTITION2 "$MOUNT_DIR"
sudo mkdir -p "$MOUNT_DIR/boot/grub"
sudo cp "$BANAN_TOOLCHAIN_DIR/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 "$BANAN_TOOLCHAIN_DIR/grub-legacy-boot.cfg" "$MOUNT_DIR/boot/grub/grub.cfg"
sudo umount "$MOUNT_DIR"
fi
fi
sudo losetup -d $LOOP_DEV
if [[ "$BANAN_BOOTLOADER" == "GRUB" ]]; then
echo > /dev/null
elif [[ "$BANAN_BOOTLOADER" == "BANAN" ]]; then
if [[ "$BANAN_UEFI_BOOT" == "1" ]]; then
echo "banan bootloader does not support UEFI" >&2
exit 1
fi
$BANAN_SCRIPT_DIR/install-bootloader.sh
else
echo "unrecognized bootloader $BANAN_BOOTLOADER" >&2
exit 1
fi

View File

@ -12,14 +12,6 @@ fi
if [[ "$1" == "full" ]] || [[ ! -f $BANAN_DISK_IMAGE_PATH ]]; then
$BANAN_SCRIPT_DIR/image-create.sh
else
fdisk -l $BANAN_DISK_IMAGE_PATH | grep -q 'EFI System'; IMAGE_IS_UEFI=$?
[[ $BANAN_UEFI_BOOT == 1 ]]; CREATE_IS_UEFI=$?
if [[ $IMAGE_IS_UEFI -ne $CREATE_IS_UEFI ]]; then
echo Converting disk image to/from UEFI
$BANAN_SCRIPT_DIR/image-create.sh
fi
fi
LOOP_DEV=$(sudo losetup --show -f "$BANAN_DISK_IMAGE_PATH")

View File

@ -26,6 +26,11 @@ if [[ -z $BANAN_BUILD_DIR ]]; then
exit 1
fi
if [[ -z $BANAN_SCRIPT_DIR ]]; then
echo "You must set the BANAN_SCRIPT_DIR environment variable" >&2
exit 1
fi
if [[ -z $BANAN_TOOLCHAIN_DIR ]]; then
echo "You must set the BANAN_TOOLCHAIN_DIR environment variable" >&2
exit 1
@ -46,6 +51,10 @@ if [[ -z $BANAN_ARCH ]]; then
exit 1
fi
if [[ -z ${MAKE_JOBS:x} ]]; then
MAKE_JOBS="-j$(nproc)"
fi
enter_clean_build () {
rm -rf build
mkdir build
@ -74,7 +83,7 @@ build_binutils () {
--disable-nls \
--disable-werror
make
make $MAKE_JOBS
make install
}
@ -100,9 +109,10 @@ build_gcc () {
--disable-nls \
--enable-languages=c,c++
make all-gcc
make all-target-libgcc CFLAGS_FOR_TARGET='-g -O2 -mcmodel=large -mno-red-zone'
make install-gcc install-target-libgcc
make $MAKE_JOBS all-gcc
make $MAKE_JOBS all-target-libgcc CFLAGS_FOR_TARGET='-g -O2 -mcmodel=large -mno-red-zone'
make install-gcc
make install-target-libgcc
}
build_grub () {
@ -127,7 +137,7 @@ build_grub () {
--with-platform="efi" \
--disable-werror
make
make $MAKE_JOBS
make install
}
@ -138,38 +148,29 @@ build_libstdcpp () {
fi
cd $BANAN_BUILD_DIR/toolchain/$GCC_VERSION/build
make all-target-libstdc++-v3
make $MAKE_JOBS all-target-libstdc++-v3 CFLAGS_FOR_TARGET='-g -O2 -mcmodel=large -mno-red-zone'
make install-target-libstdc++-v3
}
if [[ $# -ge 1 ]]; then
if [[ "$1" == "libstdc++" ]]; then
build_libstdcpp
exit 0
fi
echo "unrecognized arguments $@"
exit 1
fi
# delete everything but toolchain
find $BANAN_BUILD_DIR -mindepth 1 -maxdepth 1 ! -name toolchain -exec rm -r {} +
# NOTE: we have to manually create initial sysroot with libc headers
# since cmake cannot be invoked yet
echo "Creating dummy sysroot"
rm -rf $BANAN_SYSROOT
mkdir -p $BANAN_SYSROOT/usr
cp -r $BANAN_ROOT_DIR/libc/include $BANAN_SYSROOT/usr/include
# Cleanup all old files from toolchain prefix
rm -rf $BANAN_TOOLCHAIN_PREFIX
if [[ -z ${MAKEFLAGS:x} ]]; then
export MAKEFLAGS="-j$(nproc)"
fi
mkdir -p $BANAN_BUILD_DIR/toolchain
build_binutils
build_gcc
build_grub
rm -rf $BANAN_SYSROOT
# delete sysroot and install libc
rm -r $BANAN_SYSROOT
$BANAN_SCRIPT_DIR/build.sh libc-install
build_libstdcpp