diff --git a/boot-qemu.sh b/boot-qemu.sh index 66bfe3c..980abb3 100755 --- a/boot-qemu.sh +++ b/boot-qemu.sh @@ -3,29 +3,7 @@ # Root of the repo BASE=$(cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" && pwd) -function pretty_print() { - printf "%b%s\033[0m" "${1}" "${2}" - shift 2 - while ((${#})); do - printf "%b" "${1}" - shift - done - printf '\n' -} - -function green() { - pretty_print "\033[01;32m" "${@}" -} - -function red() { - pretty_print "\033[01;31m" "${@}" -} - -# Prints an error message in bold red then exits -function die() { - red "${@}" - exit 1 -} +source "${BASE}"/utils.sh # Check that a binary is found function checkbin() { @@ -155,21 +133,6 @@ function get_default_smp_value() { fi } -# Expands '-k' to an absolute path to a kernel image if necessary -function get_full_kernel_path() { - # If '-k' is an path that ends in the kernel image, we can just use it directly - if [[ ${KERNEL_LOCATION##*/} = "${KIMAGE:=zImage}" ]]; then - KERNEL=${KERNEL_LOCATION} - # If not though, we need to find it based on the kernel build directory - else - # If the image is an uncompressed vmlinux, it is in the root of the build folder - # Otherwise, it is in the architecture's boot directory - [[ ${KIMAGE} == "vmlinux" ]] || BOOT_DIR=arch/${ARCH}/boot/ - KERNEL=${KERNEL_LOCATION}/${BOOT_DIR}${KIMAGE} - fi - [[ -f ${KERNEL} ]] || die "${KERNEL} does not exist!" -} - # Takes a version (x.y.z) and prints a six or seven digit number # For example, QEMU 6.2.50 would become 602050 and Linux 5.10.100 # would become 510100 diff --git a/boot-uml.sh b/boot-uml.sh new file mode 100755 index 0000000..bebe96d --- /dev/null +++ b/boot-uml.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash + +BASE=$(dirname "$(readlink -f "$0")") +source "$BASE"/utils.sh + +function parse_parameters() { + while (($#)); do + case $1 in + -i | --interactive | --shell) + kernel_args=(init=/bin/sh) + ;; + -k | --kernel-location) + shift + KERNEL_LOCATION=$1 + ;; + esac + shift + done +} + +function reality_check() { + [[ -z $KERNEL_LOCATION ]] && die "Kernel image or kernel build folder ('-k') is required but not specified!" + KIMAGE=linux get_full_kernel_path +} + +function decomp_rootfs() { + rootfs=$BASE/images/x86_64/rootfs.ext4 + rm -rf "$rootfs" + zstd -q -d "$rootfs".zst -o "$rootfs" +} + +function execute_kernel() { + # exec is needed to avoid a "Killed" message when the kernel shuts down: + # https://github.com/ClangBuiltLinux/boot-utils/issues/60 + # Nothing runs after this command so it is okay for it to replace this process. + exec "$KERNEL" ubd0="$rootfs" "${kernel_args[@]}" +} + +parse_parameters "$@" +reality_check +decomp_rootfs +execute_kernel diff --git a/buildroot/buildroot-2020.11.2.tar.gz.sha256 b/buildroot/buildroot-2020.11.2.tar.gz.sha256 deleted file mode 100644 index 2837d71..0000000 --- a/buildroot/buildroot-2020.11.2.tar.gz.sha256 +++ /dev/null @@ -1 +0,0 @@ -ab42111f4855483f1769f83f4e7c60e0a8724ba2b3579041c02e2678db50bd21 buildroot-2020.11.2.tar.gz diff --git a/buildroot/buildroot-2022.02.tar.gz.sha256 b/buildroot/buildroot-2022.02.tar.gz.sha256 new file mode 100644 index 0000000..c82e887 --- /dev/null +++ b/buildroot/buildroot-2022.02.tar.gz.sha256 @@ -0,0 +1 @@ +9aaaa1317ca1082ccdabe3f2566bba06975080a80256adf87f860bc4c3f45a9b buildroot-2022.02.tar.gz diff --git a/buildroot/rebuild.sh b/buildroot/rebuild.sh index 9cc6be1..b85b92d 100755 --- a/buildroot/rebuild.sh +++ b/buildroot/rebuild.sh @@ -39,7 +39,7 @@ while ((${#})); do done # Download latest LTS buildroot release -BUILDROOT_VERSION=2020.11.2 +BUILDROOT_VERSION=2022.02 if [[ -d src ]]; then # Make support/scripts/setlocalversion do nothing because we are in a git # repository so it will return information about this repo, not Buildroot @@ -53,9 +53,6 @@ if [[ -d src ]]; then else download_br fi -# Patch buildroot with fakeroot fixes for newer glibc versions -[[ ! -f src/package/fakeroot/0002-libfakeroot.c-define-_STAT_VER-if-not-already-define.patch ]] && - curl -LSs https://github.com/buildroot/buildroot/commit/f45925a951318e9e53bead80b363e004301adc6f.patch | patch -d src -p1 cd src || exit 1 # Build the images for the architectures requested @@ -84,6 +81,8 @@ for CONFIG in "${CONFIGS[@]}"; do # Copy new images # Make sure images exist before moving them IMAGES=("output/images/rootfs.cpio") + # For x86_64, we also build an ext4 image for UML + [[ ${ARCH} == "x86_64" ]] && IMAGES+=("output/images/rootfs.ext4") for IMAGE in "${IMAGES[@]}"; do [[ -f ${IMAGE} ]] || die "${IMAGE} could not be found! Did the build error?" zstd -f -19 "${IMAGE}" -o "${IMAGES_FOLDER}/${IMAGE##*/}.zst" || die "Compressing ${IMAGE##*/} failed!" diff --git a/buildroot/riscv.config b/buildroot/riscv.config index 5ceac1f..7d8894c 100644 --- a/buildroot/riscv.config +++ b/buildroot/riscv.config @@ -1,6 +1,6 @@ BR2_riscv=y -BR2_RISCV_ABI_LP64=y BR2_TOOLCHAIN_EXTERNAL=y +BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_RISCV64_LP64D_GLIBC_STABLE=y BR2_TARGET_GENERIC_ROOT_PASSWD="root" BR2_TARGET_GENERIC_GETTY_PORT="ttyS0" BR2_ROOTFS_OVERLAY="../overlay-poweroff" diff --git a/buildroot/x86_64.config b/buildroot/x86_64.config index 53d4fa9..4801f5e 100644 --- a/buildroot/x86_64.config +++ b/buildroot/x86_64.config @@ -6,4 +6,7 @@ BR2_TARGET_GENERIC_ROOT_PASSWD="root" BR2_TARGET_GENERIC_GETTY_PORT="ttyS0" BR2_ROOTFS_OVERLAY="../overlay-poweroff" BR2_TARGET_ROOTFS_CPIO=y +BR2_TARGET_ROOTFS_EXT2=y +BR2_TARGET_ROOTFS_EXT2_4=y +BR2_TARGET_ROOTFS_EXT2_SIZE="10M" # BR2_TARGET_ROOTFS_TAR is not set diff --git a/images/.gitignore b/images/.gitignore index 446d49c..9611075 100644 --- a/images/.gitignore +++ b/images/.gitignore @@ -1,2 +1,3 @@ debian.img rootfs.cpio +rootfs.ext4 diff --git a/images/arm/rootfs.cpio.zst b/images/arm/rootfs.cpio.zst index 0ff832c..464f021 100644 Binary files a/images/arm/rootfs.cpio.zst and b/images/arm/rootfs.cpio.zst differ diff --git a/images/arm64/rootfs.cpio.zst b/images/arm64/rootfs.cpio.zst index 4ea661f..e44ccf6 100644 Binary files a/images/arm64/rootfs.cpio.zst and b/images/arm64/rootfs.cpio.zst differ diff --git a/images/arm64be/rootfs.cpio.zst b/images/arm64be/rootfs.cpio.zst index 548242b..2df8def 100644 Binary files a/images/arm64be/rootfs.cpio.zst and b/images/arm64be/rootfs.cpio.zst differ diff --git a/images/m68k/rootfs.cpio.zst b/images/m68k/rootfs.cpio.zst index 81db9f5..419a4bb 100644 Binary files a/images/m68k/rootfs.cpio.zst and b/images/m68k/rootfs.cpio.zst differ diff --git a/images/mips/rootfs.cpio.zst b/images/mips/rootfs.cpio.zst index b89552f..80f1094 100644 Binary files a/images/mips/rootfs.cpio.zst and b/images/mips/rootfs.cpio.zst differ diff --git a/images/mipsel/rootfs.cpio.zst b/images/mipsel/rootfs.cpio.zst index a602fac..8a5af3e 100644 Binary files a/images/mipsel/rootfs.cpio.zst and b/images/mipsel/rootfs.cpio.zst differ diff --git a/images/ppc32/rootfs.cpio.zst b/images/ppc32/rootfs.cpio.zst index c787721..a4b2d2e 100644 Binary files a/images/ppc32/rootfs.cpio.zst and b/images/ppc32/rootfs.cpio.zst differ diff --git a/images/ppc64/rootfs.cpio.zst b/images/ppc64/rootfs.cpio.zst index 252b39b..c05efe3 100644 Binary files a/images/ppc64/rootfs.cpio.zst and b/images/ppc64/rootfs.cpio.zst differ diff --git a/images/ppc64le/rootfs.cpio.zst b/images/ppc64le/rootfs.cpio.zst index 63ecc28..e833fef 100644 Binary files a/images/ppc64le/rootfs.cpio.zst and b/images/ppc64le/rootfs.cpio.zst differ diff --git a/images/riscv/rootfs.cpio.zst b/images/riscv/rootfs.cpio.zst index 75d6cf3..d3cbcd7 100644 Binary files a/images/riscv/rootfs.cpio.zst and b/images/riscv/rootfs.cpio.zst differ diff --git a/images/s390/rootfs.cpio.zst b/images/s390/rootfs.cpio.zst index d5d003c..9332e83 100644 Binary files a/images/s390/rootfs.cpio.zst and b/images/s390/rootfs.cpio.zst differ diff --git a/images/x86/rootfs.cpio.zst b/images/x86/rootfs.cpio.zst index 8e1c51e..d1f867a 100644 Binary files a/images/x86/rootfs.cpio.zst and b/images/x86/rootfs.cpio.zst differ diff --git a/images/x86_64/rootfs.cpio.zst b/images/x86_64/rootfs.cpio.zst index 96c62eb..cf1a2f1 100644 Binary files a/images/x86_64/rootfs.cpio.zst and b/images/x86_64/rootfs.cpio.zst differ diff --git a/images/x86_64/rootfs.ext4.zst b/images/x86_64/rootfs.ext4.zst new file mode 100644 index 0000000..8bf56de Binary files /dev/null and b/images/x86_64/rootfs.ext4.zst differ diff --git a/utils.sh b/utils.sh new file mode 100755 index 0000000..922b050 --- /dev/null +++ b/utils.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash + +function pretty_print() { + printf "%b%s\033[0m" "${1}" "${2}" + shift 2 + while ((${#})); do + printf "%b" "${1}" + shift + done + printf '\n' +} + +function green() { + pretty_print "\033[01;32m" "${@}" +} + +function red() { + pretty_print "\033[01;31m" "${@}" +} + +# Prints an error message in bold red then exits +function die() { + red "${@}" + exit 1 +} + +# Expands '-k' to an absolute path to a kernel image if necessary +function get_full_kernel_path() { + # If '-k' is a file, we can just use it directly + if [[ -f ${KERNEL_LOCATION} ]]; then + KERNEL=${KERNEL_LOCATION} + # If not, we need to find it based on the kernel build directory + else + # If the image is an uncompressed vmlinux or a UML image, it is in the + # root of the build folder + # Otherwise, it is in the architecture's boot directory + [[ -z ${KIMAGE} ]] && KIMAGE=zImage + [[ ${KIMAGE} == "vmlinux" || ${KIMAGE} == "linux" ]] || BOOT_DIR=arch/${ARCH}/boot/ + KERNEL=${KERNEL_LOCATION}/${BOOT_DIR}${KIMAGE} + fi + [[ -f ${KERNEL} ]] || die "${KERNEL} does not exist!" +}