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.master
parent
8e556ca5a9
commit
4900085a1c
94
Makefile
94
Makefile
|
@ -1,6 +1,9 @@
|
||||||
update.tar: output/update.tar.zstd
|
O ?= .
|
||||||
|
IMAGESDIR ?= $(O)/images
|
||||||
|
|
||||||
.prepared: \
|
update.tar: $(IMAGESDIR)/update.tar.zstd
|
||||||
|
|
||||||
|
$(O)/.prepared: \
|
||||||
prepare.sh \
|
prepare.sh \
|
||||||
config-portage.sh \
|
config-portage.sh \
|
||||||
setup-local-repo.sh \
|
setup-local-repo.sh \
|
||||||
|
@ -9,86 +12,87 @@ update.tar: output/update.tar.zstd
|
||||||
./prepare.sh
|
./prepare.sh
|
||||||
./config-portage.sh
|
./config-portage.sh
|
||||||
./setup-local-repo.sh
|
./setup-local-repo.sh
|
||||||
touch .prepared
|
mkdir -p $(O)
|
||||||
|
touch $(O)/.prepared
|
||||||
|
|
||||||
prepare: .prepared
|
prepare: $(O)/.prepared
|
||||||
|
|
||||||
.host-tools: \
|
$(O)/.host-tools: \
|
||||||
build-host-tools.sh \
|
build-host-tools.sh \
|
||||||
.prepared
|
$(O)/.prepared
|
||||||
./build-host-tools.sh
|
./build-host-tools.sh
|
||||||
touch .host-tools
|
touch $(O)/.host-tools
|
||||||
|
|
||||||
host-tools: .host-tools
|
host-tools: $(O)/.host-tools
|
||||||
|
|
||||||
.built: \
|
$(O)/.built: \
|
||||||
build.sh \
|
build.sh \
|
||||||
build-rootfs.sh \
|
build-rootfs.sh \
|
||||||
linux/arch/arm64/boot/Image.gz \
|
$(O)/linux/arch/arm64/boot/Image.gz \
|
||||||
.host-tools \
|
$(O)/.host-tools \
|
||||||
.prepared
|
$(O)/.prepared
|
||||||
./build.sh
|
./build.sh
|
||||||
./build-rootfs.sh
|
./build-rootfs.sh
|
||||||
touch .built
|
touch $(O)/.built
|
||||||
|
|
||||||
images/rootfs.squashfs: \
|
$(IMAGESDIR)/rootfs.squashfs: \
|
||||||
build-squashfs.sh \
|
build-squashfs.sh \
|
||||||
squashfs.exclude \
|
squashfs.exclude \
|
||||||
.built
|
$(O)/.built
|
||||||
./build-squashfs.sh
|
./build-squashfs.sh "$(IMAGESDIR)"
|
||||||
|
|
||||||
squashfs: images/rootfs.squashfs
|
squashfs: $(IMAGESDIR)/rootfs.squashfs
|
||||||
|
|
||||||
linux/arch/arm64/boot/Image.gz: \
|
$(O)/linux/arch/arm64/boot/Image.gz: \
|
||||||
build-kernel.sh \
|
build-kernel.sh \
|
||||||
linux.config \
|
linux.config \
|
||||||
.host-tools \
|
$(O)/.host-tools \
|
||||||
.prepared
|
$(O)/.prepared
|
||||||
./build-kernel.sh
|
./build-kernel.sh "$(O)"
|
||||||
|
|
||||||
kernel: linux/arch/arm64/boot/Image.gz
|
kernel: $(O)/linux/arch/arm64/boot/Image.gz
|
||||||
|
|
||||||
output/efi-part/EFI/BOOT/BOOTAA64.efi: \
|
$(O)/efi-part/EFI/BOOT/BOOTAA64.efi: \
|
||||||
build-grub.sh \
|
build-grub.sh \
|
||||||
grub.cfg \
|
grub.cfg \
|
||||||
.host-tools \
|
$(O)/.host-tools \
|
||||||
.prepared
|
$(O)/.prepared
|
||||||
./build-grub.sh
|
./build-grub.sh "$(O)"
|
||||||
|
|
||||||
grub: output/efi-part/EFI/BOOT/BOOTAA64.efi
|
grub: $(O)/efi-part/EFI/BOOT/BOOTAA64.efi
|
||||||
|
|
||||||
output/efi-part/u-boot.bin: \
|
$(O)/efi-part/u-boot.bin: \
|
||||||
build-uboot.sh \
|
build-uboot.sh \
|
||||||
u-boot.config
|
u-boot.config
|
||||||
./build-uboot.sh
|
./build-uboot.sh "$(O)"
|
||||||
|
|
||||||
uboot: output/efi-part/u-boot.bin
|
uboot: $(O)/efi-part/u-boot.bin
|
||||||
|
|
||||||
images/sdcard.img: \
|
$(IMAGESDIR)/sdcard.img: \
|
||||||
genimage.cfg \
|
genimage.cfg \
|
||||||
genimage.sh \
|
genimage.sh \
|
||||||
post-build.sh \
|
post-build.sh \
|
||||||
output/efi-part/u-boot.bin \
|
$(O)/efi-part/u-boot.bin \
|
||||||
output/efi-part/EFI/BOOT/BOOTAA64.efi
|
$(O)/efi-part/EFI/BOOT/BOOTAA64.efi
|
||||||
./post-build.sh
|
./post-build.sh "$(O)"
|
||||||
./genimage.sh
|
./genimage.sh "$(O)" "$(IMAGESDIR)"
|
||||||
|
|
||||||
sdcard.img: images/sdcard.img
|
sdcard.img: $(IMAGESDIR)/sdcard.img
|
||||||
|
|
||||||
images/firmware.img: images/sdcard.img
|
$(IMAGESDIR)/firmware.img: $(IMAGESDIR)/sdcard.img
|
||||||
|
|
||||||
output/update.tar.zstd: \
|
$(IMAGESDIR)/update.tar.zstd: \
|
||||||
images/rootfs.squashfs \
|
$(IMAGESDIR)/rootfs.squashfs \
|
||||||
images/firmware.img \
|
$(IMAGESDIR)/firmware.img \
|
||||||
install-update.sh \
|
install-update.sh \
|
||||||
.host-tools \
|
$(O)/.host-tools \
|
||||||
.prepared
|
$(O)/.prepared
|
||||||
./build-update.sh
|
./build-update.sh "$(IMAGESDIR)"
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
git -C u-boot clean -fdx && git -C u-boot checkout -- .
|
git -C u-boot clean -fdx && git -C u-boot checkout -- .
|
||||||
rm -rf linux output images tmp
|
rm -rf $(O)/linux $(O)/output $(IMAGESDIR) $(O)/tmp
|
||||||
rm -f .prepared .host-tools
|
rm -f $(O)/.prepared $(O)/.host-tools
|
||||||
|
|
||||||
.PHONY: \
|
.PHONY: \
|
||||||
grub \
|
grub \
|
||||||
|
|
|
@ -5,6 +5,8 @@ set -e
|
||||||
|
|
||||||
. ./config
|
. ./config
|
||||||
|
|
||||||
|
O="${1}"
|
||||||
|
|
||||||
GRUB_MODULES='
|
GRUB_MODULES='
|
||||||
boot
|
boot
|
||||||
echo
|
echo
|
||||||
|
@ -26,17 +28,17 @@ zstd
|
||||||
'
|
'
|
||||||
|
|
||||||
echo 'Creating GRUB image ...'
|
echo 'Creating GRUB image ...'
|
||||||
mkdir -p output/efi-part/EFI/BOOT
|
mkdir -p "${O}"/efi-part/EFI/BOOT
|
||||||
grub-mkimage \
|
grub-mkimage \
|
||||||
-O arm64-efi \
|
-O arm64-efi \
|
||||||
-o output/efi-part/EFI/BOOT/BOOTAA64.efi \
|
-o "${O}"/efi-part/EFI/BOOT/BOOTAA64.efi \
|
||||||
-d /usr/${target}/usr/lib/grub/arm64-efi \
|
-d /usr/${target}/usr/lib/grub/arm64-efi \
|
||||||
-p /EFI/gentoo \
|
-p /EFI/gentoo \
|
||||||
${GRUB_MODULES}
|
${GRUB_MODULES}
|
||||||
|
|
||||||
echo 'Generating GRUB configuration file ...'
|
echo 'Generating GRUB configuration file ...'
|
||||||
mkdir -p output/efi-part/EFI/gentoo
|
mkdir -p "${O}"/efi-part/EFI/gentoo
|
||||||
cp -uv grub.cfg output/efi-part/EFI/gentoo
|
cp -uv grub.cfg "${O}"/efi-part/EFI/gentoo
|
||||||
grub-editenv output/efi-part/EFI/gentoo/grubenv set rootflags='ro'
|
grub-editenv "${O}"/efi-part/EFI/gentoo/grubenv set rootflags='ro'
|
||||||
grub-editenv output/efi-part/EFI/gentoo/grubenv set default=0
|
grub-editenv "${O}"/efi-part/EFI/gentoo/grubenv set default=0
|
||||||
grub-editenv output/efi-part/EFI/gentoo/grubenv set timeout=5
|
grub-editenv "${O}"/efi-part/EFI/gentoo/grubenv set timeout=5
|
||||||
|
|
|
@ -3,16 +3,20 @@
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
O="${1}"
|
||||||
|
|
||||||
. ./config
|
. ./config
|
||||||
|
|
||||||
emerge -vnj ${kernel_pkg}
|
emerge -vnj ${kernel_pkg}
|
||||||
|
|
||||||
export ARCH=arm64 CROSS_COMPILE=${target}-
|
export ARCH=arm64 CROSS_COMPILE=${target}-
|
||||||
mkdir -p linux
|
unset MAKEFLAGS MAKEOVERRIDES MAKELEVEL
|
||||||
cd linux
|
mkdir -p "${O}"/linux
|
||||||
/usr/src/linux/scripts/kconfig/merge_config.sh -m \
|
/usr/src/linux/scripts/kconfig/merge_config.sh -m \
|
||||||
|
-O "${O}"/linux \
|
||||||
/usr/src/linux/arch/*/configs/${kernel_defconfig}_defconfig \
|
/usr/src/linux/arch/*/configs/${kernel_defconfig}_defconfig \
|
||||||
../linux.config
|
linux.config
|
||||||
|
cd "${O}"/linux
|
||||||
make -C /usr/src/linux O=${PWD} olddefconfig
|
make -C /usr/src/linux O=${PWD} olddefconfig
|
||||||
make -j$(nproc)
|
make -j$(nproc)
|
||||||
touch arch/arm64/boot/Image.gz
|
touch arch/arm64/boot/Image.gz
|
||||||
|
@ -22,14 +26,14 @@ cd -
|
||||||
|
|
||||||
printf 'Installing Kernel %s ...\n' "${kver}"
|
printf 'Installing Kernel %s ...\n' "${kver}"
|
||||||
mkdir -p /mnt/gentoo/boot
|
mkdir -p /mnt/gentoo/boot
|
||||||
cp -au linux/arch/arm64/boot/Image.gz /mnt/gentoo/boot/vmlinuz-${kver}
|
cp -au "${O}"/linux/arch/arm64/boot/Image.gz /mnt/gentoo/boot/vmlinuz-${kver}
|
||||||
cp -au linux/.config /mnt/gentoo/boot/config-${kver}
|
cp -au "${O}"/linux/.config /mnt/gentoo/boot/config-${kver}
|
||||||
cp -au linux/System.map /mnt/gentoo/boot/System.map-${kver}
|
cp -au "${O}"/linux/System.map /mnt/gentoo/boot/System.map-${kver}
|
||||||
|
|
||||||
printf 'Installing device tree binaries ...\n'
|
printf 'Installing device tree binaries ...\n'
|
||||||
mkdir -p output/efi-part/overlays
|
mkdir -p "${O}"/efi-part/overlays
|
||||||
cp -au linux/arch/arm64/boot/dts/${device_tree} output/efi-part/
|
cp -u "${O}"/linux/arch/arm64/boot/dts/${device_tree} "${O}"/efi-part/
|
||||||
cp -au \
|
cp -u \
|
||||||
linux/arch/arm64/boot/dts/overlays/*.dtb \
|
"${O}"/linux/arch/arm64/boot/dts/overlays/*.dtb \
|
||||||
linux/arch/arm64/boot/dts/overlays/*.dtbo \
|
"${O}"/linux/arch/arm64/boot/dts/overlays/*.dtbo \
|
||||||
output/efi-part/overlays/
|
"${O}"/efi-part/overlays/
|
||||||
|
|
|
@ -5,10 +5,12 @@ set -e
|
||||||
|
|
||||||
. ./config
|
. ./config
|
||||||
|
|
||||||
mkdir -p images
|
IMAGESDIR="${1}"
|
||||||
|
|
||||||
|
mkdir -p "${IMAGESDIR}"
|
||||||
mksquashfs \
|
mksquashfs \
|
||||||
/mnt/gentoo \
|
/mnt/gentoo \
|
||||||
images/rootfs.squashfs \
|
"${IMAGESDIR}"/rootfs.squashfs \
|
||||||
-comp gzip \
|
-comp gzip \
|
||||||
-ef squashfs.exclude \
|
-ef squashfs.exclude \
|
||||||
-no-exports \
|
-no-exports \
|
||||||
|
|
|
@ -5,12 +5,14 @@ set -e
|
||||||
|
|
||||||
. ./config
|
. ./config
|
||||||
|
|
||||||
|
O="${1}"
|
||||||
|
|
||||||
./patch-uboot.sh
|
./patch-uboot.sh
|
||||||
cd u-boot
|
cd u-boot
|
||||||
cat configs/rpi_4_defconfig ../u-boot.config > configs/yellow_defconfig
|
cat configs/rpi_4_defconfig ../u-boot.config > configs/yellow_defconfig
|
||||||
make yellow_defconfig
|
make O="${O}"/u-boot yellow_defconfig
|
||||||
CROSS_COMPILE=${target}- make
|
CROSS_COMPILE=${target}- make O="${O}"/u-boot -j$(nproc)
|
||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
mkdir -p output/efi-part
|
mkdir -p "${O}"/efi-part
|
||||||
cp -au u-boot/u-boot.bin output/efi-part
|
cp -u "${O}"/u-boot/u-boot.bin "${O}"/efi-part
|
||||||
|
|
|
@ -5,11 +5,13 @@ set -e
|
||||||
|
|
||||||
. ./config
|
. ./config
|
||||||
|
|
||||||
cd images
|
IMAGESDIR="$1"
|
||||||
|
|
||||||
|
cd "${IMAGESDIR}"
|
||||||
sha256sum firmware.img > digests
|
sha256sum firmware.img > digests
|
||||||
sha256sum rootfs.squashfs >> digests
|
sha256sum rootfs.squashfs >> digests
|
||||||
ln ../install-update.sh install
|
cp -u "${OLDPWD}"/install-update.sh install
|
||||||
tar -c --zstd -f ../output/update.tar.zstd \
|
tar -c --zstd -f update.tar.zstd \
|
||||||
digests \
|
digests \
|
||||||
firmware.img \
|
firmware.img \
|
||||||
rootfs.squashfs \
|
rootfs.squashfs \
|
||||||
|
|
2
build.sh
2
build.sh
|
@ -5,6 +5,8 @@ set -e
|
||||||
|
|
||||||
. ./config
|
. ./config
|
||||||
|
|
||||||
|
unset MAKEFLAGS MAKEOVERRIDES MAKELEVEL
|
||||||
|
|
||||||
${target}-emerge -vuUDj sys-apps/util-linux
|
${target}-emerge -vuUDj sys-apps/util-linux
|
||||||
|
|
||||||
${target}-emerge -vnuUDj \
|
${target}-emerge -vnuUDj \
|
||||||
|
|
|
@ -4,7 +4,7 @@ image firmware.img {
|
||||||
vfat {
|
vfat {
|
||||||
}
|
}
|
||||||
|
|
||||||
srcpath = "output/efi-part"
|
srcpath = "efi-part"
|
||||||
size = 32M
|
size = 32M
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
10
genimage.sh
10
genimage.sh
|
@ -14,14 +14,18 @@ cleanup() {
|
||||||
|
|
||||||
. ./config
|
. ./config
|
||||||
|
|
||||||
|
O="${1}"
|
||||||
|
IMAGESDIR="${2}"
|
||||||
|
|
||||||
trap cleanup INT TERM QUIT EXIT
|
trap cleanup INT TERM QUIT EXIT
|
||||||
tmproot=$(mktemp -d)
|
tmproot=$(mktemp -d)
|
||||||
tmppath=$(mktemp -d)
|
tmppath=$(mktemp -d)
|
||||||
|
|
||||||
|
cd "${O}"
|
||||||
genimage \
|
genimage \
|
||||||
--rootpath "${tmproot}" \
|
--rootpath "${tmproot}" \
|
||||||
--tmppath "${tmppath}" \
|
--tmppath "${tmppath}" \
|
||||||
--inputpath images/ \
|
--inputpath "${IMAGESDIR}" \
|
||||||
--outputpath images/ \
|
--outputpath "${IMAGESDIR}" \
|
||||||
--mkdosfs mkfs.vfat \
|
--mkdosfs mkfs.vfat \
|
||||||
--config genimage.cfg
|
--config "${OLDPWD}"/genimage.cfg
|
||||||
|
|
|
@ -5,9 +5,9 @@ set -e
|
||||||
|
|
||||||
. ./config
|
. ./config
|
||||||
|
|
||||||
cp -auv \
|
cp -uv \
|
||||||
/usr/${target}/boot/*.bin \
|
/usr/${target}/boot/*.bin \
|
||||||
/usr/${target}/boot/*.dat \
|
/usr/${target}/boot/*.dat \
|
||||||
/usr/${target}/boot/*.elf \
|
/usr/${target}/boot/*.elf \
|
||||||
config.txt \
|
config.txt \
|
||||||
output/efi-part/
|
"$1"/efi-part/
|
||||||
|
|
Loading…
Reference in New Issue