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 \
|
||||
config-portage.sh \
|
||||
setup-local-repo.sh \
|
||||
|
@ -9,86 +12,87 @@ update.tar: output/update.tar.zstd
|
|||
./prepare.sh
|
||||
./config-portage.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 \
|
||||
.prepared
|
||||
$(O)/.prepared
|
||||
./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-rootfs.sh \
|
||||
linux/arch/arm64/boot/Image.gz \
|
||||
.host-tools \
|
||||
.prepared
|
||||
$(O)/linux/arch/arm64/boot/Image.gz \
|
||||
$(O)/.host-tools \
|
||||
$(O)/.prepared
|
||||
./build.sh
|
||||
./build-rootfs.sh
|
||||
touch .built
|
||||
touch $(O)/.built
|
||||
|
||||
images/rootfs.squashfs: \
|
||||
$(IMAGESDIR)/rootfs.squashfs: \
|
||||
build-squashfs.sh \
|
||||
squashfs.exclude \
|
||||
.built
|
||||
./build-squashfs.sh
|
||||
$(O)/.built
|
||||
./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 \
|
||||
linux.config \
|
||||
.host-tools \
|
||||
.prepared
|
||||
./build-kernel.sh
|
||||
$(O)/.host-tools \
|
||||
$(O)/.prepared
|
||||
./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 \
|
||||
grub.cfg \
|
||||
.host-tools \
|
||||
.prepared
|
||||
./build-grub.sh
|
||||
$(O)/.host-tools \
|
||||
$(O)/.prepared
|
||||
./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 \
|
||||
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.sh \
|
||||
post-build.sh \
|
||||
output/efi-part/u-boot.bin \
|
||||
output/efi-part/EFI/BOOT/BOOTAA64.efi
|
||||
./post-build.sh
|
||||
./genimage.sh
|
||||
$(O)/efi-part/u-boot.bin \
|
||||
$(O)/efi-part/EFI/BOOT/BOOTAA64.efi
|
||||
./post-build.sh "$(O)"
|
||||
./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: \
|
||||
images/rootfs.squashfs \
|
||||
images/firmware.img \
|
||||
$(IMAGESDIR)/update.tar.zstd: \
|
||||
$(IMAGESDIR)/rootfs.squashfs \
|
||||
$(IMAGESDIR)/firmware.img \
|
||||
install-update.sh \
|
||||
.host-tools \
|
||||
.prepared
|
||||
./build-update.sh
|
||||
$(O)/.host-tools \
|
||||
$(O)/.prepared
|
||||
./build-update.sh "$(IMAGESDIR)"
|
||||
|
||||
clean:
|
||||
git -C u-boot clean -fdx && git -C u-boot checkout -- .
|
||||
rm -rf linux output images tmp
|
||||
rm -f .prepared .host-tools
|
||||
rm -rf $(O)/linux $(O)/output $(IMAGESDIR) $(O)/tmp
|
||||
rm -f $(O)/.prepared $(O)/.host-tools
|
||||
|
||||
.PHONY: \
|
||||
grub \
|
||||
|
|
|
@ -5,6 +5,8 @@ set -e
|
|||
|
||||
. ./config
|
||||
|
||||
O="${1}"
|
||||
|
||||
GRUB_MODULES='
|
||||
boot
|
||||
echo
|
||||
|
@ -26,17 +28,17 @@ zstd
|
|||
'
|
||||
|
||||
echo 'Creating GRUB image ...'
|
||||
mkdir -p output/efi-part/EFI/BOOT
|
||||
mkdir -p "${O}"/efi-part/EFI/BOOT
|
||||
grub-mkimage \
|
||||
-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 \
|
||||
-p /EFI/gentoo \
|
||||
${GRUB_MODULES}
|
||||
|
||||
echo 'Generating GRUB configuration file ...'
|
||||
mkdir -p output/efi-part/EFI/gentoo
|
||||
cp -uv grub.cfg output/efi-part/EFI/gentoo
|
||||
grub-editenv output/efi-part/EFI/gentoo/grubenv set rootflags='ro'
|
||||
grub-editenv output/efi-part/EFI/gentoo/grubenv set default=0
|
||||
grub-editenv output/efi-part/EFI/gentoo/grubenv set timeout=5
|
||||
mkdir -p "${O}"/efi-part/EFI/gentoo
|
||||
cp -uv grub.cfg "${O}"/efi-part/EFI/gentoo
|
||||
grub-editenv "${O}"/efi-part/EFI/gentoo/grubenv set rootflags='ro'
|
||||
grub-editenv "${O}"/efi-part/EFI/gentoo/grubenv set default=0
|
||||
grub-editenv "${O}"/efi-part/EFI/gentoo/grubenv set timeout=5
|
||||
|
|
|
@ -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/
|
||||
|
|
|
@ -5,10 +5,12 @@ set -e
|
|||
|
||||
. ./config
|
||||
|
||||
mkdir -p images
|
||||
IMAGESDIR="${1}"
|
||||
|
||||
mkdir -p "${IMAGESDIR}"
|
||||
mksquashfs \
|
||||
/mnt/gentoo \
|
||||
images/rootfs.squashfs \
|
||||
"${IMAGESDIR}"/rootfs.squashfs \
|
||||
-comp gzip \
|
||||
-ef squashfs.exclude \
|
||||
-no-exports \
|
||||
|
|
|
@ -5,12 +5,14 @@ set -e
|
|||
|
||||
. ./config
|
||||
|
||||
O="${1}"
|
||||
|
||||
./patch-uboot.sh
|
||||
cd u-boot
|
||||
cat configs/rpi_4_defconfig ../u-boot.config > configs/yellow_defconfig
|
||||
make yellow_defconfig
|
||||
CROSS_COMPILE=${target}- make
|
||||
make O="${O}"/u-boot yellow_defconfig
|
||||
CROSS_COMPILE=${target}- make O="${O}"/u-boot -j$(nproc)
|
||||
cd ..
|
||||
|
||||
mkdir -p output/efi-part
|
||||
cp -au u-boot/u-boot.bin output/efi-part
|
||||
mkdir -p "${O}"/efi-part
|
||||
cp -u "${O}"/u-boot/u-boot.bin "${O}"/efi-part
|
||||
|
|
|
@ -5,11 +5,13 @@ set -e
|
|||
|
||||
. ./config
|
||||
|
||||
cd images
|
||||
IMAGESDIR="$1"
|
||||
|
||||
cd "${IMAGESDIR}"
|
||||
sha256sum firmware.img > digests
|
||||
sha256sum rootfs.squashfs >> digests
|
||||
ln ../install-update.sh install
|
||||
tar -c --zstd -f ../output/update.tar.zstd \
|
||||
cp -u "${OLDPWD}"/install-update.sh install
|
||||
tar -c --zstd -f update.tar.zstd \
|
||||
digests \
|
||||
firmware.img \
|
||||
rootfs.squashfs \
|
||||
|
|
2
build.sh
2
build.sh
|
@ -5,6 +5,8 @@ set -e
|
|||
|
||||
. ./config
|
||||
|
||||
unset MAKEFLAGS MAKEOVERRIDES MAKELEVEL
|
||||
|
||||
${target}-emerge -vuUDj sys-apps/util-linux
|
||||
|
||||
${target}-emerge -vnuUDj \
|
||||
|
|
|
@ -4,7 +4,7 @@ image firmware.img {
|
|||
vfat {
|
||||
}
|
||||
|
||||
srcpath = "output/efi-part"
|
||||
srcpath = "efi-part"
|
||||
size = 32M
|
||||
}
|
||||
|
||||
|
|
10
genimage.sh
10
genimage.sh
|
@ -14,14 +14,18 @@ cleanup() {
|
|||
|
||||
. ./config
|
||||
|
||||
O="${1}"
|
||||
IMAGESDIR="${2}"
|
||||
|
||||
trap cleanup INT TERM QUIT EXIT
|
||||
tmproot=$(mktemp -d)
|
||||
tmppath=$(mktemp -d)
|
||||
|
||||
cd "${O}"
|
||||
genimage \
|
||||
--rootpath "${tmproot}" \
|
||||
--tmppath "${tmppath}" \
|
||||
--inputpath images/ \
|
||||
--outputpath images/ \
|
||||
--inputpath "${IMAGESDIR}" \
|
||||
--outputpath "${IMAGESDIR}" \
|
||||
--mkdosfs mkfs.vfat \
|
||||
--config genimage.cfg
|
||||
--config "${OLDPWD}"/genimage.cfg
|
||||
|
|
|
@ -5,9 +5,9 @@ set -e
|
|||
|
||||
. ./config
|
||||
|
||||
cp -auv \
|
||||
cp -uv \
|
||||
/usr/${target}/boot/*.bin \
|
||||
/usr/${target}/boot/*.dat \
|
||||
/usr/${target}/boot/*.elf \
|
||||
config.txt \
|
||||
output/efi-part/
|
||||
"$1"/efi-part/
|
||||
|
|
Loading…
Reference in New Issue