commit e430bc153c8386df4ddd2173da5f62f5b7215c22 from: Benjamin Stürz date: Mon Oct 14 23:24:46 2024 UTC import commit - /dev/null commit + e430bc153c8386df4ddd2173da5f62f5b7215c22 blob - /dev/null blob + 131b767761cc4dc9a2a43d3c15f5d90aa53b6ed7 (mode 644) --- /dev/null +++ .gitignore @@ -0,0 +1,5 @@ +src +build +tools +data/*.old +floppy.img blob - /dev/null blob + b566c86f054068bfd47a24c85b5b754d6314eb59 (mode 644) --- /dev/null +++ Makefile @@ -0,0 +1,259 @@ +.POSIX: + +include config.mk + +TOP != pwd +TOOLS = ${TOP}/tools +ROOTFS = ${TOP}/build/rootfs +CROSS = ${TOOLS}/bin/${TARGET}- +T = build/.stamps +U = ${TOP}/data/bin + +GMAKE = $U/gmake + +all: floppy.img + +toolchain: $T/toolchain + +$T/toolchain: $T/i-libgcc $T/kheaders + touch $@ + +clean: + rm -rf build tools + rm -f floppy.img + +distclean: clean + rm -rf src + rm -f data/*.old + +floppy.img: build/kernel build/initrd data/syslinux.cfg + $U/mkfloppy "${TOP}" floppy.img + +build/initrd: + +# DOWNLOAD +download: src/binutils.tgz src/gmp.tgz src/mpfr.tgz src/mpc.tgz src/gcc.tgz src/linux.tgz src/musl.tgz src/busybox.tar.bz2 + +src/binutils.tgz: + @mkdir -p src + $U/download src/binutils.tgz ${GNUFTP}/binutils/binutils-${BINUTILS_VER}.tar.gz + +src/gmp.tgz: + @mkdir -p src + $U/download src/gmp.tgz ${GNUFTP}/gmp/gmp-${GMP_VER}.tar.gz + +src/mpfr.tgz: + @mkdir -p src + $U/download src/mpfr.tgz ${GNUFTP}/mpfr/mpfr-${MPFR_VER}.tar.gz + +src/mpc.tgz: + @mkdir -p src + $U/download src/mpc.tgz ${GNUFTP}/mpc/mpc-${MPC_VER}.tar.gz + +src/gcc.tgz: + @mkdir -p src + $U/download src/gcc.tgz ${GNUFTP}/gcc/gcc-${GCC_VER}/gcc-${GCC_VER}.tar.gz + +src/linux.tgz: + @mkdir -p src + $U/download src/linux.tgz https://mirrors.edge.kernel.org/pub/linux/kernel/v${LINUX_MAJOR}.x/linux-${LINUX_VER}.tar.gz + +src/musl.tgz: + @mkdir -p src + $U/download src/musl.tgz https://musl.libc.org/releases/musl-${MUSL_VER}.tar.gz + +src/busybox.tar.bz2: + @mkdir -p src + $U/download src/busybox.tar.bz2 https://busybox.net/downloads/busybox-${BUSYBOX_VER}.tar.bz2 + +# EXTRACT +extract: $T/x-binutils $T/x-gmp $T/x-mpfr $T/x-mpc $T/x-gcc $T/x-linux $T/x-busybox + +$T/x-binutils: src/binutils.tgz + $U/extract -z binutils tgz + +$T/x-gmp: src/gmp.tgz + $U/extract -z gmp tgz + +$T/x-mpfr: src/mpfr.tgz + $U/extract -z mpfr tgz + +$T/x-mpc: src/mpc.tgz + $U/extract -z mpc tgz + +$T/x-gcc: src/gcc.tgz + $U/extract -z gcc tgz + ln -sf ../gmp ../mpfr ../mpc build/gcc/ + +$T/x-linux: src/linux.tgz + $U/extract -z linux tgz + +$T/x-musl: src/musl.tgz + $U/extract -z musl tgz + +$T/x-busybox: src/busybox.tar.bz2 + $U/extract -j busybox tar.bz2 + sed -i 's/main() {}/int main() {}/' build/busybox/scripts/kconfig/lxdialog/check-lxdialog.sh + +# KERNEL HEADERS + +$T/kheaders: $T/x-linux + (cd build/linux && ${GMAKE} ARCH=${ARCH} INSTALL_HDR_PATH=${TOOLS}/${TARGET} headers_install) + touch $@ + +# BINUTILS + +$T/c-binutils: $T/x-binutils + rm -rf build/binutils/build + mkdir -p build/binutils/build + (cd build/binutils/build && \ + ../configure \ + --prefix=${TOOLS} \ + --target=${TARGET} \ + --with-arch=${CPU} \ + --with-tune=${CPU} \ + --with-system-zlib \ + --disable-nls \ + --disable-multilib \ + --disable-gold \ + --disable-gprofng) + touch $@ + +$T/b-binutils: $T/c-binutils + (cd build/binutils/build && ${GMAKE}) + touch $@ + +$T/i-binutils: $T/b-binutils + (cd build/binutils/build && ${GMAKE} install) + touch $@ + +# GCC + +$T/c-gcc: $T/i-binutils $T/x-gcc $T/x-gmp $T/x-mpfr $T/x-mpc + rm -rf build/gcc/build + mkdir -p build/gcc/build + (cd build/gcc/build && \ + ../configure \ + --prefix=${TOOLS} \ + --target=${TARGET} \ + --with-arch=${CPU} \ + --with-tune=${CPU} \ + --with-system-zlib \ + --with-newlib \ + --without-headers \ + --enable-languages=c \ + --disable-nls \ + --disable-multilib \ + --disable-libssp \ + --disable-libsanitizer \ + --disable-libstdcxx \ + --disable-libgomp \ + --disable-libquadmath \ + --disable-libvtv \ + --disable-threads \ + --disable-shared \ + --enable-static) + touch $@ + +$T/b-gcc: $T/c-gcc + (cd build/gcc/build && ${GMAKE} all-gcc) + touch $@ + +$T/i-gcc: $T/b-gcc + (cd build/gcc/build && ${GMAKE} install-gcc) + touch $@ + +# MUSL + +$T/c-musl: $T/i-gcc $T/x-musl + rm -rf build/musl/build + mkdir -p build/musl/build + (cd build/musl/build && \ + ../configure \ + CROSS_COMPILE=${CROSS} \ + --prefix=${TOOLS}/${TARGET} \ + --target=${TARGET} \ + --enable-static \ + --disable-shared \ + --disable-wrapper) + touch $@ + +$T/b-musl: $T/c-musl + (cd build/musl/build && ${GMAKE}) + touch $@ + +$T/i-musl: $T/b-musl + (cd build/musl/build && ${GMAKE} install) + touch $@ + +# LIBGCC + +$T/b-libgcc: $T/i-gcc $T/i-musl + (cd build/gcc/build && ${GMAKE} all-target-libgcc) + touch $@ + +$T/i-libgcc: $T/b-libgcc + (cd build/gcc/build && ${GMAKE} install-target-libgcc) + touch $@ + +# BUSYBOX +BBFLAGS = ARCH=${ARCH} CROSS_COMPILE=${CROSS} CONFIG_PREFIX=${ROOTFS} + +busybox: $T/i-busybox + @du -sh ${ROOTFS}/bin/busybox + +busybox-defconfig: $T/x-busybox + (cd build/busybox && ${GMAKE} ${BBFLAGS} defconfig) + -cp -f data/bbconfig data/bbconfig.old + cp -f build/busybox/.config data/bbconfig + +busybox-menuconfig: $T/x-busybox + -cp -f data/bbconfig build/busybox/.config + (cd build/busybox && ${GMAKE} ${BBFLAGS} menuconfig) + -cp -f data/bbconfig data/bbconfig.old + cp -f build/busybox/.config data/bbconfig + +$T/b-busybox: $T/x-busybox $T/toolchain data/bbconfig + @cp -f data/bbconfig build/busybox/.config + (cd build/busybox && ${GMAKE} ${BBFLAGS}) + touch $@ + +$T/i-busybox: $T/b-busybox + @mkdir -p ${ROOTFS} + (cd build/busybox && ${GMAKE} ${BBFLAGS} install) + touch $@ + +# KERNEL +KFLAGS = ARCH=${ARCH} CROSS_COMPILE=${CROSS} + +kernel: build/kernel + @du -sh build/kernel + +linux-defconfig: $T/x-linux + (cd build/linux && ${GMAKE} ${KFLAGS} defconfig) + -cp -f data/kconfig data/kconfig.old + cp -f build/linux/.config data/kconfig + +linux-menuconfig: $T/x-linux + -cp -f data/kconfig build/linux/.config + (cd build/linux && ${GMAKE} ${KFLAGS} menuconfig) + -cp -f data/kconfig data/kconfig.old + cp -f build/linux/.config data/kconfig + +$T/b-linux: $T/x-linux $T/toolchain data/kconfig + (cd build/linux && ${GMAKE} ${KFLAGS}) + touch $@ + +build/kernel: $T/b-linux + cp -f build/linux/arch/x86/boot/bzImage build/kernel + +# INITRD + +$T/rootfs: + @mkdir -p ${ROOTFS} + ${SUDO} cp -av data/initrd/* ${ROOTFS}/ + touch $@ + + +build/initrd: $T/rootfs $T/i-busybox + (cd ${ROOTFS} && find . | cpio --owner=0:0 -H newc -o | xz --check=crc32 -e) > $@ blob - /dev/null blob + 42c2eef48564e149b00f2b72deac333473fd22fe (mode 644) --- /dev/null +++ config.mk @@ -0,0 +1,18 @@ +ARCH = i386 +CPU = i486 +TARGET = i486-unknown-linux-musl + +SUDO = sudo + +BINUTILS_VER = 2.43 +GMP_VER = 6.3.0 +MPFR_VER = 4.2.1 +MPC_VER = 1.3.1 +GCC_VER = 14.2.0 +LINUX_VER = 4.19.322 +MUSL_VER = 1.2.5 +BUSYBOX_VER = 1.36.0 + +GNUFTP = https://ftp.gnu.org/gnu + +LINUX_MAJOR != echo ${LINUX_VER} | cut -d. -f1 blob - /dev/null blob + 8c7f93fd0ba274a8b6271a84ac884df0547c8638 (mode 755) --- /dev/null +++ data/bin/download @@ -0,0 +1,26 @@ +#!/bin/sh + +has() { + command -v "$1" >/dev/null 2>&1 +} + + +case "$(uname)" in +OpenBSD|NetBSD) + ftp -o "$1" "$2" + ;; + +FreeBSD) + fetch -o "$1" "$2" + ;; +*) + if has 'wget'; then + wget -qO "$1" "$2" + elif has 'curl'; then + curl -sLo "$1" "$2" + else + echo "No download program found for $(uname)" >&2 + exit 1 + fi + ;; +esac blob - /dev/null blob + e7fd132dce0f8e4782b9e9dc2cb170b03256ca67 (mode 755) --- /dev/null +++ data/bin/extract @@ -0,0 +1,12 @@ +#!/bin/sh + +T=build/.stamps +flag=$1 +name=$2 +ext=$3 + +mkdir -p build "$T" +rm -rf "build/$name" +tar -C build -x $flag -f "src/$name.$ext" +mv build/$name-* "build/$name" +touch "$T/x-$name" blob - /dev/null blob + 395c586de79710fb751542bc5171659531f991e9 (mode 755) --- /dev/null +++ data/bin/gmake @@ -0,0 +1,18 @@ +#!/bin/sh + +case "$(uname)" in +Linux) + exec make "$@" + ;; +*BSD) + ncpu=$(echo "$MAKEFLAGS" | grep -oE -- '-j [0-9]+') + keep=$(echo "$MAKEFLAGS" | grep -o -- '-k') + unset MAKEFLAGS + exec gmake $ncpu $keep "$@" + ;; +*) + echo "Unsupported OS: $(uname)" >&2 + exit 1 + ;; +esac + blob - /dev/null blob + 7c186edfd8d784bdb340dc973d2228e40cbbfe65 (mode 755) --- /dev/null +++ data/bin/mkfloppy @@ -0,0 +1,24 @@ +#!/bin/sh -e + +SUDO=sudo +SIZE=1440 + +cleanup() { + "$SUDO" umount "$mp" || true + rmdir "$mp" || true + rm -f "$tmp" +} + +tmp=$(mktemp) +mp=$(mktemp -d) + +trap cleanup ERR INT + +dd if=/dev/zero of="$tmp" bs=1K count=${SIZE} +mkdosfs "$tmp" +syslinux --install "$tmp" +${SUDO} mount -o loop "$tmp" "$mp" +${SUDO} cp "$1/build/kernel" "$1/build/initrd" "$1/data/syslinux.cfg" "$mp/" +df -h 2>/dev/null | grep -Fx "$mp" +cp -f "$tmp" "$2" +cleanup blob - /dev/null blob + 75721cd5afd69ad22111ed437cd4fe7ecfd6393c (mode 644) --- /dev/null +++ data/initrd/etc/hosts @@ -0,0 +1 @@ +127.0.0.1 localhost blob - /dev/null blob + b98b9e9741c6b21a2c3e22be0e3d9a3e9e6e209a (mode 644) --- /dev/null +++ data/initrd/etc/inittab @@ -0,0 +1,4 @@ +::sysinit:/etc/rc +::askfirst:/bin/sh +::restart:/sbin/init +::ctrlaltdel:/sbin/reboot blob - /dev/null blob + 2bd8a0f67dc07b060fe984f72f16ee5dd87a8bff (mode 755) --- /dev/null +++ data/initrd/etc/rc @@ -0,0 +1,7 @@ +#!/bin/sh +mount -t proc none /proc +mount -t sysfs none /sys + +while true; do + /bin/sh +done blob - /dev/null blob + 8dda3fc099d08cf36e1f53df28598d1ee7662990 (mode 644) --- /dev/null +++ data/initrd/etc/resolv.conf @@ -0,0 +1 @@ +nameserver 1.1.1.1 blob - /dev/null blob + b8213d8d9558e25214a333bd80aa6eae738857de (mode 755) --- /dev/null +++ data/syslinux.cfg @@ -0,0 +1,6 @@ +DEFAULT linux +LABEL linux + SAY [ 486 Linux ] + KERNEL kernel + INITRD initrd +EOF