Support external build directory

When running inside a QEMU microvm with the source directory shared
via 9pfs, the kernel build process fails

> Error: Could not mmap file: vmlinux

Thus, we need to run the build in a path on a local filesystem.  To
support this, the Makefile now supports an `O` option, and all the build
scripts have been adjusted to make use of it as needed.

Since building in a local filesystem would ultimately discard the final
artifacts when the VM terminates, we need yet a different location for
the files we want to keep.  The `IMAGESDIR` option can be used to
specify this path.  This path can be on a shared filesystem, thus
saving the artifacts outside the microvm.
This commit is contained in:
2023-03-03 12:22:20 -06:00
parent 8e556ca5a9
commit 4900085a1c
10 changed files with 101 additions and 79 deletions

View File

@@ -3,16 +3,20 @@
set -e
O="${1}"
. ./config
emerge -vnj ${kernel_pkg}
export ARCH=arm64 CROSS_COMPILE=${target}-
mkdir -p linux
cd linux
unset MAKEFLAGS MAKEOVERRIDES MAKELEVEL
mkdir -p "${O}"/linux
/usr/src/linux/scripts/kconfig/merge_config.sh -m \
-O "${O}"/linux \
/usr/src/linux/arch/*/configs/${kernel_defconfig}_defconfig \
../linux.config
linux.config
cd "${O}"/linux
make -C /usr/src/linux O=${PWD} olddefconfig
make -j$(nproc)
touch arch/arm64/boot/Image.gz
@@ -22,14 +26,14 @@ cd -
printf 'Installing Kernel %s ...\n' "${kver}"
mkdir -p /mnt/gentoo/boot
cp -au linux/arch/arm64/boot/Image.gz /mnt/gentoo/boot/vmlinuz-${kver}
cp -au linux/.config /mnt/gentoo/boot/config-${kver}
cp -au linux/System.map /mnt/gentoo/boot/System.map-${kver}
cp -au "${O}"/linux/arch/arm64/boot/Image.gz /mnt/gentoo/boot/vmlinuz-${kver}
cp -au "${O}"/linux/.config /mnt/gentoo/boot/config-${kver}
cp -au "${O}"/linux/System.map /mnt/gentoo/boot/System.map-${kver}
printf 'Installing device tree binaries ...\n'
mkdir -p output/efi-part/overlays
cp -au linux/arch/arm64/boot/dts/${device_tree} output/efi-part/
cp -au \
linux/arch/arm64/boot/dts/overlays/*.dtb \
linux/arch/arm64/boot/dts/overlays/*.dtbo \
output/efi-part/overlays/
mkdir -p "${O}"/efi-part/overlays
cp -u "${O}"/linux/arch/arm64/boot/dts/${device_tree} "${O}"/efi-part/
cp -u \
"${O}"/linux/arch/arm64/boot/dts/overlays/*.dtb \
"${O}"/linux/arch/arm64/boot/dts/overlays/*.dtbo \
"${O}"/efi-part/overlays/