Files
Limine/bootstrap
Kamila Szewczyk 9c3ead9386 decompressor: gzip/tinf -> limlz
removes external dependency on tinf by replacing the compression algorithm with a simpler, faster, smaller and more auditable fixed-width LZ77 encoding purpose-tailored to x86 code mixed with data.

before: decompressor.bin 2,492 bytes (tinf dependency) with .text 0x875 and .rodata 0x13c bytes each.
after: decompressor.bin consists only of .text, 0xe6-byte decompressor; 90.8% reduction in decompressor volume.

the dependency on gzip during compile-time is replaced by host/limlzpack.c, a Lempel-Ziv encoder in 275 SLoC that uses a suffix array matchfinder (prefix-doubling in mathcal O(n log^2 n) and Storer-Szymanski backwards parse. the fixed-width formats packets as [F][LLLL][MMM], favouring a literal-skewed distribution with F switching between one-byte and two-byte offsets (favouring recent statistics).

integrity checking is done via crc32 with the polynomial 0xEDB88320, reflected.

the effective loss in compression ratio by using a tremendously simpler and less packed with edge cases algorithm causes a compression ratio hit well below 1KB, factoring in the stub sizes.

also adds new machinery for host cc detection per review.
2026-04-19 00:29:09 +02:00

162 lines
4.6 KiB
Bash
Executable File

#! /bin/sh
set -ex
srcdir="$(dirname "$0")"
test -z "$srcdir" && srcdir=.
: "${AUTORECONF:=autoreconf}"
: "${AUTOMAKE:=automake}"
cd "$srcdir"
AUXFILES="config.guess config.sub install-sh"
clone_repo_commit() {
if test -d "$2/.git"; then
git -C "$2" reset --hard
git -C "$2" clean -fd
if ! git -C "$2" -c advice.detachedHead=false checkout $3; then
rm -rf "$2"
fi
else
if test -d "$2"; then
set +x
echo "error: '$2' is not a Git repository" 1>&2
exit 1
fi
fi
if ! test -d "$2"; then
git clone $1 "$2"
if ! git -C "$2" -c advice.detachedHead=false checkout $3; then
rm -rf "$2"
exit 1
fi
fi
}
download_by_hash() {
DOWNLOAD_COMMAND="curl -Lo"
if ! command -v "${DOWNLOAD_COMMAND%% *}" >/dev/null 2>&1; then
DOWNLOAD_COMMAND="wget -O"
if ! command -v "${DOWNLOAD_COMMAND%% *}" >/dev/null 2>&1; then
set +x
echo "error: Neither curl nor wget found" 1>&2
exit 1
fi
fi
SHA256_COMMAND="sha256sum"
if ! command -v "${SHA256_COMMAND%% *}" >/dev/null 2>&1; then
SHA256_COMMAND="sha256"
if ! command -v "${SHA256_COMMAND%% *}" >/dev/null 2>&1; then
set +x
echo "error: Cannot find sha256(sum) command" 1>&2
exit 1
fi
fi
if ! test -f "$2" || ! $SHA256_COMMAND "$2" | grep $3 >/dev/null 2>&1; then
rm -f "$2"
mkdir -p "$2" && rm -rf "$2"
$DOWNLOAD_COMMAND "$2" $1
if ! $SHA256_COMMAND "$2" | grep $3 >/dev/null 2>&1; then
set +x
echo "error: Cannot download file '$2' by hash" 1>&2
echo "incorrect hash:" 1>&2
$SHA256_COMMAND "$2" 1>&2
rm -f "$2"
exit 1
fi
fi
}
if ! test -f version; then
clone_repo_commit \
https://github.com/osdev0/freestnd-c-hdrs-0bsd.git \
freestnd-c-hdrs \
097259a899d30f0a4b7a694de2de5fdda942e923
clone_repo_commit \
https://github.com/osdev0/cc-runtime.git \
cc-runtime \
dae79833b57a01b9fd3e359ee31def69f5ae899b
cp cc-runtime/src/cc-runtime.c common/cc-runtime.s2.c
cp cc-runtime/src/cc-runtime.c decompressor/cc-runtime.c
clone_repo_commit \
https://github.com/Limine-Bootloader/limine-protocol.git \
limine-protocol \
6f3fafe337c30f94e7c2f5c4a21498346c5604bf
clone_repo_commit \
https://github.com/PicoEFI/PicoEFI.git \
picoefi \
9c99f66e4c15aebfd72e7becb72358473b484fcf
clone_repo_commit \
https://github.com/Mintsuki/Flanterm.git \
flanterm \
112434532822dde252c84b25a6798a9c00515d66
download_by_hash \
https://github.com/nothings/stb/raw/5c205738c191bcb0abc65c4febfa9bd25ff35234/stb_image.h \
common/lib/stb_image.h.nopatch \
594c2fe35d49488b4382dbfaec8f98366defca819d916ac95becf3e75f4200b3
cp common/lib/stb_image.h.nopatch common/lib/stb_image.h
patch -p0 < common/stb_image.patch
rm -f common/lib/stb_image.h.orig
clone_repo_commit \
https://github.com/osdev0/libfdt.git \
libfdt \
7bf94e6347129d17eca263112296ad170dec28a9
fi
# Create timestamps file
if test -d .git && git log -1 >/dev/null 2>&1; then
cat >timestamps <<EOF
REGEN_DATE="$(git log -1 --pretty=%cd --date='format:%B %Y')"
SOURCE_DATE_EPOCH="$(git log -1 --pretty=%ct)"
SOURCE_DATE_EPOCH_TOUCH="$(git log -1 --pretty=%cI | head -c 16 | sed 's/-//g;s/T//g;s/://g')"
EOF
else
if ! test -f timestamps; then
cat >timestamps <<EOF
REGEN_DATE="UNVERSIONED"
SOURCE_DATE_EPOCH="1546297200"
SOURCE_DATE_EPOCH_TOUCH="201901010000"
EOF
fi
fi
for auxfile in $AUXFILES; do
rm -f build-aux/$auxfile
done
$AUTORECONF -fvi -Wall
# Older versions of autoreconf have a bug where they do not
# install auxiliary files, sometimes... Check if that is the
# case and work around...
for auxfile in $AUXFILES; do
if ! test -f build-aux/$auxfile; then
if ! $AUTOMAKE --print-libdir >/dev/null 2>&1; then
set +x
echo "error: Broken autoreconf detected, but missing or broken automake." 1>&2
echo " Please make sure automake is installed and working." 1>&2
exit 1
fi
AUTOMAKE_LIBDIR="$($AUTOMAKE --print-libdir)"
if test -z "$AUTOMAKE_LIBDIR"; then
# Assume `true` was passed as $AUTOMAKE
continue
fi
mkdir -p build-aux
cp -v "$AUTOMAKE_LIBDIR/$auxfile" build-aux/
chmod +x build-aux/$auxfile
fi
done
set +x
printf "\nSource tree bootstrapped successfully!\n"