Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build_image
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions build_packages
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down