From 51f84ca4e0fcc9d8e3b0050997544c63075349a5 Mon Sep 17 00:00:00 2001 From: Li Zhijian Date: Wed, 22 Apr 2026 17:13:44 +0800 Subject: [PATCH] common: check binfmt_misc for cross builds Fail early when cross builds lack the required binfmt_misc entry in build_packages and build_image, matching SDK guidance. Ref: https://www.flatcar.org/docs/latest/reference/developer-guides/sdk-modifying-flatcar/#select-the-target-architecture Signed-off-by: Li Zhijian --- build_image | 2 ++ build_packages | 2 ++ common.sh | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/build_image b/build_image index aa0e57f1580..5bcb59293d1 100755 --- a/build_image +++ b/build_image @@ -107,6 +107,8 @@ fi . "${BUILD_LIBRARY_DIR}/extra_sysexts.sh" || exit 1 . "${BUILD_LIBRARY_DIR}/oem_sysexts.sh" || exit 1 +check_binfmt_for_cross_build + PROD_IMAGE=0 PROD_TAR=0 CONTAINER=0 diff --git a/build_packages b/build_packages index 6f69b75d300..dd446dd509c 100755 --- a/build_packages +++ b/build_packages @@ -111,6 +111,8 @@ if [ "${FLAGS_skip_chroot_upgrade}" -eq "${FLAGS_TRUE}" ]; then UPDATE_ARGS+=( --skip_chroot_upgrade ) fi +check_binfmt_for_cross_build + "${SCRIPTS_DIR}"/setup_board --quiet --board=${FLAGS_board} "${UPDATE_ARGS[@]}" # set BOARD and BOARD_ROOT diff --git a/common.sh b/common.sh index 3dbb8040dc3..4fbc14363c3 100644 --- a/common.sh +++ b/common.sh @@ -993,6 +993,38 @@ BOAT die "$* failed" } +require_binfmt_entry() { + local entry="/proc/sys/fs/binfmt_misc/qemu-$1" + + if [[ ! -d /proc/sys/fs/binfmt_misc ]]; then + sudo mount -t binfmt_misc binfmt_misc /proc/sys/fs/binfmt_misc || true + fi + + if [[ ! -f "${entry}" ]] || ! grep -q '^enabled$' "${entry}"; then + die "Cross build requires binfmt_misc entry (missing or disabled): ${entry} +Please install qemu-user-static package on the host" + fi +} + +check_binfmt_for_cross_build() { + local host_arch + + host_arch=$(uname -m) + case "${FLAGS_board}" in + amd64-usr) + if [[ "${host_arch}" != "x86_64" ]]; then + require_binfmt_entry "x86_64" + fi + ;; + arm64-usr) + if [[ "${host_arch}" != "aarch64" ]]; then + require_binfmt_entry "aarch64" + fi + ;; + *) die "Unsupported arch" ;; + esac +} + # The binfmt_misc support in the kernel is required. # The aarch64 binaries should be executed through # "/usr/bin/qemu-aarch64-static"