2022-09-13 17:55:17 +00:00
|
|
|
# Copyright 2020 The ChromiumOS Authors
|
2020-11-10 17:34:56 +00:00
|
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
|
|
# found in the LICENSE file.
|
|
|
|
|
|
|
|
# Builds the kernel and rootfs for the guest used in integration testing.
|
|
|
|
#
|
|
|
|
# The main artifacts are:
|
|
|
|
# target/guest_under_test/bzImage
|
|
|
|
# target/guest_under_test/rootfs
|
|
|
|
|
2021-02-04 23:38:15 +00:00
|
|
|
ARCH ?= $(shell arch)
|
|
|
|
ifeq ($(ARCH), x86_64)
|
|
|
|
KERNEL_ARCH=x86
|
|
|
|
KERNEL_BINARY=bzImage
|
|
|
|
DOCKER_ARCH=amd64
|
|
|
|
CROSS_COMPILE=
|
|
|
|
RUSTFLAGS=
|
|
|
|
else ifeq ($(ARCH), aarch64)
|
|
|
|
KERNEL_ARCH=arm64
|
|
|
|
KERNEL_BINARY=Image
|
|
|
|
DOCKER_ARCH=arm64v8
|
|
|
|
CROSS_COMPILE=aarch64-linux-gnu-
|
|
|
|
RUSTFLAGS="-Clinker=aarch64-linux-gnu-ld"
|
|
|
|
else
|
|
|
|
$(error Only x86_64 or aarch64 are supported)
|
|
|
|
endif
|
|
|
|
|
|
|
|
# Build against the musl toolchain, which will produce a statically linked,
|
|
|
|
# portable binary that we can run on the alpine linux guest without needing
|
|
|
|
# libc at runtime
|
|
|
|
RUST_TARGET ?= $(ARCH)-unknown-linux-musl
|
|
|
|
|
2020-11-10 17:34:56 +00:00
|
|
|
# We are building everything in target/guest_under_test
|
|
|
|
CARGO_TARGET ?= $(shell cargo metadata --no-deps --format-version 1 | \
|
|
|
|
jq -r ".target_directory")
|
2021-02-04 23:38:15 +00:00
|
|
|
TARGET ?= $(CARGO_TARGET)/guest_under_test/$(ARCH)
|
2020-11-10 17:34:56 +00:00
|
|
|
$(shell mkdir -p $(TARGET))
|
|
|
|
|
|
|
|
# Parameteters for building the kernel locally
|
2023-03-09 19:28:52 +00:00
|
|
|
KERNEL_REPO ?= https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
|
|
|
|
KERNEL_BRANCH ?= linux-6.1.y
|
2020-11-10 17:34:56 +00:00
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Main targets
|
|
|
|
|
|
|
|
all: $(TARGET)/rootfs $(TARGET)/bzImage
|
|
|
|
|
2023-03-09 19:28:52 +00:00
|
|
|
# Clean all local build artifacts, but not downloaded sources.
|
2020-11-10 17:34:56 +00:00
|
|
|
clean:
|
2023-07-25 20:47:58 +00:00
|
|
|
rm -rf $(TARGET)/kernel-build $(TARGET)/rootfs-build $(TARGET)/initramfs-build $(TARGET)/rootfs $(TARGET)/bzImage $(TARGET)/initramfs.cpio.gz
|
2023-03-09 19:28:52 +00:00
|
|
|
|
|
|
|
clean-all:
|
2020-11-10 17:34:56 +00:00
|
|
|
rm -rf $(TARGET)
|
|
|
|
|
2023-07-25 20:47:58 +00:00
|
|
|
x86_64_initramfs: $(TARGET)/initramfs
|
|
|
|
|
2023-08-17 00:30:51 +00:00
|
|
|
delegate: $(TARGET)/rootfs-build/delegate
|
|
|
|
|
2020-11-10 17:34:56 +00:00
|
|
|
################################################################################
|
|
|
|
# Build rootfs
|
|
|
|
|
|
|
|
# Build rootfs from Dockerfile and export into squashfs
|
2023-03-09 19:28:52 +00:00
|
|
|
$(TARGET)/rootfs: $(TARGET)/rootfs-build/delegate rootfs/Dockerfile
|
2020-11-10 17:34:56 +00:00
|
|
|
# Build image from Dockerfile
|
2023-03-09 19:28:52 +00:00
|
|
|
DOCKER_BUILDKIT=1 docker build -t crosvm_e2e_test_guest $(TARGET)/rootfs-build \
|
|
|
|
-f rootfs/Dockerfile --build-arg ARCH=$(DOCKER_ARCH)
|
2020-11-10 17:34:56 +00:00
|
|
|
|
|
|
|
# Create container and export into squashfs, and don't forget to clean up
|
|
|
|
# the container afterwards.
|
|
|
|
set -x; \
|
2023-03-09 19:28:52 +00:00
|
|
|
CONTAINER=$$(docker create crosvm_e2e_test_guest); \
|
2020-11-10 17:34:56 +00:00
|
|
|
docker export $$CONTAINER | tar2sqfs -c gzip -f $@; \
|
|
|
|
docker rm $$CONTAINER
|
|
|
|
|
|
|
|
# Build and copy delegate binary into rootfs build directory
|
2023-08-17 00:30:51 +00:00
|
|
|
$(TARGET)/rootfs-build/delegate: rootfs/delegate/Cargo.toml rootfs/delegate/src/main.rs rootfs/delegate/src/wire_format.rs
|
2020-11-10 17:34:56 +00:00
|
|
|
rustup target add $(RUST_TARGET)
|
2023-08-17 00:30:51 +00:00
|
|
|
CARGO_TARGET_DIR=$(TARGET) RUSTFLAGS=$(RUSTFLAGS) cargo build --target $(RUST_TARGET) --release --manifest-path=rootfs/delegate/Cargo.toml
|
|
|
|
cp $(TARGET)/$(RUST_TARGET)/release/delegate $(TARGET)/rootfs-build/delegate
|
2020-11-10 17:34:56 +00:00
|
|
|
|
2023-07-25 20:47:58 +00:00
|
|
|
################################################################################
|
|
|
|
# Build initramfs
|
|
|
|
|
|
|
|
# Build initramfs from Containerfile and package as cpio archive
|
|
|
|
$(TARGET)/initramfs: $(TARGET)/rootfs-build/delegate initramfs/Containerfile initramfs/init.sh
|
|
|
|
-mkdir -p $(TARGET)/initramfs-build
|
|
|
|
cp initramfs/init.sh $(TARGET)/initramfs-build/init.sh
|
|
|
|
cp $(TARGET)/rootfs-build/delegate $(TARGET)/initramfs-build/delegate
|
|
|
|
podman build -t crosvm_e2e_test_guest_initramfs $(TARGET)/initramfs-build -f initramfs/Containerfile
|
|
|
|
-mkdir -p $(TARGET)/initramfs-build/cpio-base
|
|
|
|
# Create container and export into squashfs, and don't forget to clean up
|
|
|
|
# the container afterwards.
|
|
|
|
set -x; \
|
|
|
|
CONTAINER=$$(podman create crosvm_e2e_test_guest_initramfs); \
|
|
|
|
podman export $$CONTAINER | tar -xf - -C $(TARGET)/initramfs-build/cpio-base; \
|
|
|
|
podman rm $$CONTAINER; \
|
|
|
|
cd $(TARGET)/initramfs-build/cpio-base; \
|
|
|
|
find . -print0 | cpio --null --create --verbose --format=newc | gzip --best > $(TARGET)/initramfs.cpio.gz
|
|
|
|
|
2020-11-10 17:34:56 +00:00
|
|
|
################################################################################
|
|
|
|
# Build kernel
|
|
|
|
|
|
|
|
$(TARGET)/bzImage: $(TARGET)/kernel-source $(TARGET)/kernel-build
|
2023-03-09 19:28:52 +00:00
|
|
|
cd $(TARGET)/kernel-source \
|
|
|
|
&& make O=$(TARGET)/kernel-build \
|
|
|
|
ARCH=$(KERNEL_ARCH) \
|
|
|
|
CROSS_COMPILE=$(CROSS_COMPILE) \
|
|
|
|
-j$(shell nproc)\
|
|
|
|
olddefconfig \
|
|
|
|
$(KERNEL_BINARY)
|
|
|
|
|
2021-02-04 23:38:15 +00:00
|
|
|
cp $(TARGET)/kernel-build/arch/${KERNEL_ARCH}/boot/$(KERNEL_BINARY) $@
|
2020-11-10 17:34:56 +00:00
|
|
|
|
2023-03-09 19:28:52 +00:00
|
|
|
$(TARGET)/kernel-build: $(TARGET)/kernel-source kernel/$(KERNEL_ARCH).config kernel/common.config
|
2020-11-10 17:34:56 +00:00
|
|
|
mkdir -p $@
|
2023-03-09 19:28:52 +00:00
|
|
|
cat kernel/common.config kernel/$(KERNEL_ARCH).config > $@/.config
|
|
|
|
touch $@
|
2020-11-10 17:34:56 +00:00
|
|
|
|
|
|
|
$(TARGET)/kernel-source:
|
|
|
|
rm -rf $@
|
|
|
|
git clone --depth 1 --branch $(KERNEL_BRANCH) $(KERNEL_REPO) $@
|
|
|
|
|
|
|
|
|
|
|
|
.PHONY: clean all update-prebuilts
|