Fixed check script; added --check flag to build script; added argument parsing to check and build script; added documentation to NoneTextDisplay; renamed multiboot2 section to bootheader

This commit is contained in:
Arthur Beck 2025-02-13 15:53:12 -06:00
parent 296135901b
commit bf9c3f10a7
6 changed files with 144 additions and 25 deletions

View file

@ -1,7 +1,50 @@
#!/bin/bash #!/bin/bash
( (
set -e set -o errexit -o pipefail -o noclobber
HAVE_GETOPT=true
getopt --test > /dev/null && true
if [[ $? -ne 4 ]]; then
if [[ -n "EXIT_WITHOUT_GETOPT" ]]; then
echo '`getopt --test` failed. Exiting.'
exit 1
else
echo '`getopt --test` failed. Continuing and ignoring command line flags. (note that $1 will still be used for the target)'
echo '(to exit instead of ignoring, set the environment variable `EXIT_WITHOUT_GETOPT` to a non-null value)'
HAVE_GETOPT=false
fi
fi
check=false
if [[ "$HAVE_GETOPT" = "true" ]]; then
LONGOPTS=check
OPTIONS=c
PARSED=$(getopt --options=$OPTIONS --longoptions=$LONGOPTS --name "$0" -- "$@") || (
echo '`getopt` failed to parse command line arguments. Check the arguments passed.'
exit 1
)
eval set -- "$PARSED"
while true; do
case "$1" in
-c|--check)
check=true
shift
;;
--)
shift
break
;;
*)
echo "Unknown argument"
exit 1
;;
esac
done
fi
export KERNEL_DIR=$(readlink -e .) export KERNEL_DIR=$(readlink -e .)
@ -38,20 +81,24 @@
real_target=${!target} real_target=${!target}
real_target=$(basename $real_target) real_target=$(basename $real_target)
echo "Compiling target $target(with rust target of $real_target)" echo "Compiling target $target(with rust target of $real_target)"
cargo build --target "$real_target" --release -Zbuild-std=core,alloc --bin entrypoint_$target if [[ $check = "true" ]]; then
cp "target/$(echo $real_target | sed 's/\.json//')/release/entrypoint_$target" kernel-$target cargo check --target "$real_target" --release -Zbuild-std=core,alloc --bin entrypoint_$target
else
cargo build --target "$real_target" --release -Zbuild-std=core,alloc --bin entrypoint_$target
cp "target/$(echo $real_target | sed 's/\.json//')/release/entrypoint_$target" kernel-$target
if [[ "$CONFIG_BUILD_GRUB" = "true" ]]; then if [[ "$CONFIG_BUILD_GRUB" = "true" ]]; then
if [[ "$target" = "x86" || "$target" = "mips64" || "$target" = "mipsel" || "$target" = "mipsle" ]]; then if [[ "$target" = "x86" || "$target" = "mips64" || "$target" = "mipsel" || "$target" = "mipsle" ]]; then
rm -rf grub aphrodite-grub-$target.iso rm -rf grub aphrodite-grub-$target.iso
cp -r ./grub_template ./grub cp -r ./grub_template ./grub
cp kernel-$target ./grub/boot/aphrodite.kernel cp kernel-$target ./grub/boot/aphrodite.kernel
sed -i "s@%{VERSION}@$VERSION@g" ./grub/boot/grub/grub.cfg sed -i "s@%{VERSION}@$VERSION@g" ./grub/boot/grub/grub.cfg
grub-mkrescue -o aphrodite-grub-$target.iso grub grub-mkrescue -o aphrodite-grub-$target.iso grub
cp aphrodite-grub-$target.iso aphrodite-$target.iso cp aphrodite-grub-$target.iso aphrodite-$target.iso
fi
fi fi
fi fi
} }

View file

@ -1,14 +1,88 @@
#!/bin/bash #!/bin/bash
# Build the file (
./build set -o errexit -o pipefail -o noclobber
if grub-file --is-x86-multiboot2 kernel.flat; then HAVE_GETOPT=true
echo "Multiboot2 header valid" > ./check_results getopt --test > /dev/null && true
else if [[ $? -ne 4 ]]; then
echo "Multiboot2 header INVALID!" > ./check_results if [[ -n "EXIT_WITHOUT_GETOPT" ]]; then
fi echo '`getopt --test` failed. Exiting.'
exit 1
else
echo '`getopt --test` failed. Continuing and ignoring command line flags. (note that $1 will still be used for the target)'
echo '(to exit instead of ignoring, set the environment variable `EXIT_WITHOUT_GETOPT` to a non-null value)'
HAVE_GETOPT=false
fi
fi
echo real_check=false
cat check_results if [[ "$HAVE_GETOPT" = "true" ]]; then
LONGOPTS=real_check
OPTIONS=c
PARSED=$(getopt --options=$OPTIONS --longoptions=$LONGOPTS --name "$0" -- "$@") || (
echo '`getopt` failed to parse command line arguments. Check the arguments passed.'
exit 1
)
eval set -- "$PARSED"
while true; do
case "$1" in
-c|--real_check)
real_check=true
shift
;;
--)
shift
break
;;
*)
echo "Unknown argument"
exit 1
;;
esac
done
fi
if [[ $real_check = "true" ]]; then
./build --check $!
else
./build $!
fi
rm ./check_results
target="$1"
if [[ -z "$target" || "$target" = "x86" || "$target" = "mips64" || "$target" = "mipsel" || "$target" = "mipsle" ]]; then
if [[ -z "$target" ]]; then
# -f makes it so it won't error out if the file doesn't exist
rm -f targets.tmp
envsubst < "targets" > "targets.tmp"
export $(grep -Ev '^#' targets.tmp | xargs)
for target in $TARGETS; do
if grub-file --is-x86-multiboot2 kernel-$target; then
echo "Multiboot2 header valid" > ./check_results
else
echo "Multiboot2 header INVALID!" > ./check_results
fi
done
else
if grub-file --is-x86-multiboot2 kernel-$target; then
echo "Multiboot2 header valid" > ./check_results
else
echo "Multiboot2 header INVALID!" > ./check_results
fi
fi
else
echo "Multiboot2 header not checked as neither x86 nor mips is being built" > ./check_results
fi
echo
cat check_results
)

View file

@ -4,7 +4,7 @@ OUTPUT_FORMAT(elf32-i386)
SECTIONS { SECTIONS {
.text : { .text : {
. = ALIGN(8); . = ALIGN(8);
KEEP(*(.multiboot2)) KEEP(*(.bootheader))
KEEP(*(.start)) KEEP(*(.start))
KEEP(*(.text)) KEEP(*(.text))
KEEP(*(.panic)) KEEP(*(.panic))

View file

@ -20,7 +20,7 @@ use aphrodite::output::*;
use aphrodite::display::COLOR_DEFAULT; use aphrodite::display::COLOR_DEFAULT;
#[cfg(not(CONFIG_DISABLE_MULTIBOOT2_SUPPORT))] #[cfg(not(CONFIG_DISABLE_MULTIBOOT2_SUPPORT))]
#[unsafe(link_section = ".multiboot2")] #[unsafe(link_section = ".bootheader")]
#[unsafe(no_mangle)] #[unsafe(no_mangle)]
static MULTIBOOT2_HEADER: [u8; 24] = [ static MULTIBOOT2_HEADER: [u8; 24] = [
0xd6, 0x50, 0x52, 0xe8, // Magic number 0xd6, 0x50, 0x52, 0xe8, // Magic number

View file

@ -71,6 +71,7 @@ impl dyn TextDisplay + '_ {
} }
} }
/// An implementation of [TextDisplay]. Returns (1,1) for the size and always returns Ok(()) for all functions.
pub struct NoneTextDisplay {} pub struct NoneTextDisplay {}
impl TextDisplay for NoneTextDisplay { impl TextDisplay for NoneTextDisplay {

View file

@ -1,3 +0,0 @@
#!/bin/bash
set -e