Compare commits
5 Commits
a312d75bb2
...
f2397b775c
Author | SHA1 | Date |
---|---|---|
Bananymous | f2397b775c | |
Bananymous | 8b81406b81 | |
Bananymous | e2515c1109 | |
Bananymous | 5293ae070d | |
Bananymous | 6e2443ca72 |
|
@ -1,3 +0,0 @@
|
||||||
test.img
|
|
||||||
build/
|
|
||||||
installer/build/
|
|
|
@ -1,18 +1,3 @@
|
||||||
cmake_minimum_required(VERSION 3.26)
|
cmake_minimum_required(VERSION 3.26)
|
||||||
|
|
||||||
project(bootloader ASM)
|
add_subdirectory(bios)
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
|
@ -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)
|
|
@ -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
|
|
|
@ -0,0 +1 @@
|
||||||
|
build/
|
|
@ -13,6 +13,9 @@ namespace Kernel
|
||||||
static BAN::ErrorOr<BAN::RefPtr<ProcPidInode>> create_new(Process&, TmpFileSystem&, mode_t, uid_t, gid_t);
|
static BAN::ErrorOr<BAN::RefPtr<ProcPidInode>> create_new(Process&, TmpFileSystem&, mode_t, uid_t, gid_t);
|
||||||
~ProcPidInode() = default;
|
~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();
|
void cleanup();
|
||||||
|
|
||||||
protected:
|
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);
|
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;
|
~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:
|
protected:
|
||||||
virtual BAN::ErrorOr<size_t> read_impl(off_t, BAN::ByteSpan) override;
|
virtual BAN::ErrorOr<size_t> read_impl(off_t, BAN::ByteSpan) override;
|
||||||
|
|
||||||
|
|
|
@ -27,8 +27,8 @@ namespace Kernel
|
||||||
virtual ino_t ino() const override final { return m_ino; }
|
virtual ino_t ino() const override final { return m_ino; }
|
||||||
virtual Mode mode() const override final { return Mode(m_inode_info.mode); }
|
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 nlink_t nlink() const override final { return m_inode_info.nlink; }
|
||||||
virtual uid_t uid() const override final { return m_inode_info.uid; }
|
virtual uid_t uid() const override { return m_inode_info.uid; }
|
||||||
virtual gid_t gid() const override final { return m_inode_info.gid; }
|
virtual gid_t gid() const override { return m_inode_info.gid; }
|
||||||
virtual off_t size() const override final { return m_inode_info.size; }
|
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 atime() const override final { return m_inode_info.atime; }
|
||||||
virtual timespec mtime() const override final { return m_inode_info.mtime; }
|
virtual timespec mtime() const override final { return m_inode_info.mtime; }
|
||||||
|
|
|
@ -39,11 +39,10 @@ build_toolchain () {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
$BANAN_TOOLCHAIN_DIR/build.sh
|
$BANAN_TOOLCHAIN_DIR/build.sh
|
||||||
build_target libc-install
|
|
||||||
$BANAN_TOOLCHAIN_DIR/build.sh libstdc++
|
|
||||||
}
|
}
|
||||||
|
|
||||||
create_image () {
|
create_image () {
|
||||||
|
build_target bootloader
|
||||||
build_target install-sysroot
|
build_target install-sysroot
|
||||||
$BANAN_SCRIPT_DIR/image.sh "$1"
|
$BANAN_SCRIPT_DIR/image.sh "$1"
|
||||||
}
|
}
|
||||||
|
@ -97,12 +96,6 @@ case $1 in
|
||||||
rm -f $FAKEROOT_FILE
|
rm -f $FAKEROOT_FILE
|
||||||
rm -rf $BANAN_SYSROOT
|
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
|
build_target $1
|
||||||
;;
|
;;
|
||||||
|
|
|
@ -25,3 +25,7 @@ export BANAN_DISK_IMAGE_PATH=$BANAN_BUILD_DIR/banan-os.img
|
||||||
if [[ -z $BANAN_UEFI_BOOT ]]; then
|
if [[ -z $BANAN_UEFI_BOOT ]]; then
|
||||||
export BANAN_UEFI_BOOT=0
|
export BANAN_UEFI_BOOT=0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ -z $BANAN_BOOTLOADER ]]; then
|
||||||
|
export BANAN_BOOTLOADER="BANAN"
|
||||||
|
fi
|
||||||
|
|
|
@ -15,6 +15,11 @@ if [[ -z $BANAN_TOOLCHAIN_PREFIX ]]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ -z $BANAN_BOOTLOADER ]]; then
|
||||||
|
echo "You must set the BANAN_BOOTLOADER environment variable" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ -z $BANAN_ARCH ]]; then
|
if [[ -z $BANAN_ARCH ]]; then
|
||||||
echo "You must set the BANAN_ARCH environment variable" >&2
|
echo "You must set the BANAN_ARCH environment variable" >&2
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -74,23 +79,39 @@ PARTITION2=${LOOP_DEV}p2
|
||||||
|
|
||||||
sudo mkfs.ext2 -b 1024 -q $PARTITION2
|
sudo mkfs.ext2 -b 1024 -q $PARTITION2
|
||||||
|
|
||||||
if [[ "$BANAN_UEFI_BOOT" == "1" ]]; then
|
if [[ "$BANAN_BOOTLOADER" == "GRUB" ]]; then
|
||||||
sudo mkfs.fat $PARTITION1 > /dev/null
|
if [[ "$BANAN_UEFI_BOOT" == "1" ]]; then
|
||||||
sudo mount $PARTITION1 "$MOUNT_DIR"
|
sudo mkfs.fat $PARTITION1 > /dev/null
|
||||||
sudo mkdir -p "$MOUNT_DIR/EFI/BOOT"
|
sudo mount $PARTITION1 "$MOUNT_DIR"
|
||||||
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 mkdir -p "$MOUNT_DIR/EFI/BOOT"
|
||||||
sudo umount "$MOUNT_DIR"
|
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 mount $PARTITION2 "$MOUNT_DIR"
|
||||||
sudo mkdir -p "$MOUNT_DIR/boot/grub"
|
sudo mkdir -p "$MOUNT_DIR/boot/grub"
|
||||||
sudo cp "$BANAN_TOOLCHAIN_DIR/grub-uefi.cfg" "$MOUNT_DIR/boot/grub/grub.cfg"
|
sudo cp "$BANAN_TOOLCHAIN_DIR/grub-uefi.cfg" "$MOUNT_DIR/boot/grub/grub.cfg"
|
||||||
sudo umount "$MOUNT_DIR"
|
sudo umount "$MOUNT_DIR"
|
||||||
else
|
else
|
||||||
sudo mount $PARTITION2 "$MOUNT_DIR"
|
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 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 mkdir -p "$MOUNT_DIR/boot/grub"
|
||||||
sudo cp "$BANAN_TOOLCHAIN_DIR/grub-legacy-boot.cfg" "$MOUNT_DIR/boot/grub/grub.cfg"
|
sudo cp "$BANAN_TOOLCHAIN_DIR/grub-legacy-boot.cfg" "$MOUNT_DIR/boot/grub/grub.cfg"
|
||||||
sudo umount "$MOUNT_DIR"
|
sudo umount "$MOUNT_DIR"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
sudo losetup -d $LOOP_DEV
|
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
|
||||||
|
|
||||||
|
|
|
@ -12,14 +12,6 @@ fi
|
||||||
|
|
||||||
if [[ "$1" == "full" ]] || [[ ! -f $BANAN_DISK_IMAGE_PATH ]]; then
|
if [[ "$1" == "full" ]] || [[ ! -f $BANAN_DISK_IMAGE_PATH ]]; then
|
||||||
$BANAN_SCRIPT_DIR/image-create.sh
|
$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
|
fi
|
||||||
|
|
||||||
LOOP_DEV=$(sudo losetup --show -f "$BANAN_DISK_IMAGE_PATH")
|
LOOP_DEV=$(sudo losetup --show -f "$BANAN_DISK_IMAGE_PATH")
|
||||||
|
|
|
@ -26,6 +26,11 @@ if [[ -z $BANAN_BUILD_DIR ]]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
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
|
if [[ -z $BANAN_TOOLCHAIN_DIR ]]; then
|
||||||
echo "You must set the BANAN_TOOLCHAIN_DIR environment variable" >&2
|
echo "You must set the BANAN_TOOLCHAIN_DIR environment variable" >&2
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -46,6 +51,10 @@ if [[ -z $BANAN_ARCH ]]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ -z ${MAKE_JOBS:x} ]]; then
|
||||||
|
MAKE_JOBS="-j$(nproc)"
|
||||||
|
fi
|
||||||
|
|
||||||
enter_clean_build () {
|
enter_clean_build () {
|
||||||
rm -rf build
|
rm -rf build
|
||||||
mkdir build
|
mkdir build
|
||||||
|
@ -74,7 +83,7 @@ build_binutils () {
|
||||||
--disable-nls \
|
--disable-nls \
|
||||||
--disable-werror
|
--disable-werror
|
||||||
|
|
||||||
make
|
make $MAKE_JOBS
|
||||||
make install
|
make install
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,9 +109,10 @@ build_gcc () {
|
||||||
--disable-nls \
|
--disable-nls \
|
||||||
--enable-languages=c,c++
|
--enable-languages=c,c++
|
||||||
|
|
||||||
make all-gcc
|
make $MAKE_JOBS all-gcc
|
||||||
make all-target-libgcc CFLAGS_FOR_TARGET='-g -O2 -mcmodel=large -mno-red-zone'
|
make $MAKE_JOBS all-target-libgcc CFLAGS_FOR_TARGET='-g -O2 -mcmodel=large -mno-red-zone'
|
||||||
make install-gcc install-target-libgcc
|
make install-gcc
|
||||||
|
make install-target-libgcc
|
||||||
}
|
}
|
||||||
|
|
||||||
build_grub () {
|
build_grub () {
|
||||||
|
@ -127,7 +137,7 @@ build_grub () {
|
||||||
--with-platform="efi" \
|
--with-platform="efi" \
|
||||||
--disable-werror
|
--disable-werror
|
||||||
|
|
||||||
make
|
make $MAKE_JOBS
|
||||||
make install
|
make install
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,38 +148,29 @@ build_libstdcpp () {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cd $BANAN_BUILD_DIR/toolchain/$GCC_VERSION/build
|
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
|
make install-target-libstdc++-v3
|
||||||
}
|
}
|
||||||
|
|
||||||
if [[ $# -ge 1 ]]; then
|
# delete everything but toolchain
|
||||||
if [[ "$1" == "libstdc++" ]]; then
|
find $BANAN_BUILD_DIR -mindepth 1 -maxdepth 1 ! -name toolchain -exec rm -r {} +
|
||||||
build_libstdcpp
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "unrecognized arguments $@"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# NOTE: we have to manually create initial sysroot with libc headers
|
# NOTE: we have to manually create initial sysroot with libc headers
|
||||||
# since cmake cannot be invoked yet
|
# since cmake cannot be invoked yet
|
||||||
echo "Creating dummy sysroot"
|
echo "Creating dummy sysroot"
|
||||||
rm -rf $BANAN_SYSROOT
|
|
||||||
mkdir -p $BANAN_SYSROOT/usr
|
mkdir -p $BANAN_SYSROOT/usr
|
||||||
cp -r $BANAN_ROOT_DIR/libc/include $BANAN_SYSROOT/usr/include
|
cp -r $BANAN_ROOT_DIR/libc/include $BANAN_SYSROOT/usr/include
|
||||||
|
|
||||||
|
|
||||||
# Cleanup all old files from toolchain prefix
|
# Cleanup all old files from toolchain prefix
|
||||||
rm -rf $BANAN_TOOLCHAIN_PREFIX
|
rm -rf $BANAN_TOOLCHAIN_PREFIX
|
||||||
|
|
||||||
if [[ -z ${MAKEFLAGS:x} ]]; then
|
|
||||||
export MAKEFLAGS="-j$(nproc)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
mkdir -p $BANAN_BUILD_DIR/toolchain
|
mkdir -p $BANAN_BUILD_DIR/toolchain
|
||||||
build_binutils
|
build_binutils
|
||||||
build_gcc
|
build_gcc
|
||||||
build_grub
|
build_grub
|
||||||
|
|
||||||
rm -rf $BANAN_SYSROOT
|
# delete sysroot and install libc
|
||||||
|
rm -r $BANAN_SYSROOT
|
||||||
|
$BANAN_SCRIPT_DIR/build.sh libc-install
|
||||||
|
|
||||||
|
build_libstdcpp
|
||||||
|
|
Loading…
Reference in New Issue