From e4c2b8a014d9bec2ecf12ae17182430086ad0328 Mon Sep 17 00:00:00 2001 From: Jeremi Piotrowski Date: Tue, 9 Jul 2024 12:28:45 +0200 Subject: [PATCH] TMP #2 --- common.sh | 38 ++++++++++++++++++++++++++++++++++++++ setup_board | 6 ++++++ 2 files changed, 44 insertions(+) diff --git a/common.sh b/common.sh index 0cff99ed56..3dbb8040dc 100644 --- a/common.sh +++ b/common.sh @@ -51,6 +51,9 @@ fi # Turn on bash debug support if available for backtraces. shopt -s extdebug 2>/dev/null +# Source qemu library path +. /etc/profile.d/qemu-aarch64.sh 2> /dev/null || true + # Output a backtrace all the way back to the raw invocation, suppressing # only the _dump_trace frame itself. _dump_trace() { @@ -989,3 +992,38 @@ BOAT echo -e "${V_VIDOFF}" die "$* failed" } + +# The binfmt_misc support in the kernel is required. +# The aarch64 binaries should be executed through +# "/usr/bin/qemu-aarch64-static" +setup_qemu_static() { + local root_fs_dir="$1" + case "${BOARD}" in + amd64-usr) return 0;; + arm64-usr) + if [[ -f "${root_fs_dir}/sbin/ldconfig" ]]; then + sudo cp /usr/bin/qemu-aarch64 "${root_fs_dir}"/usr/bin/qemu-aarch64-static + echo export QEMU_LD_PREFIX=\"/build/arm64-usr/\" | sudo tee /etc/profile.d/qemu-aarch64.sh + . /etc/profile.d/qemu-aarch64.sh + else + die "Missing basic layout in target rootfs" + fi + ;; + *) die "Unsupported arch" ;; + esac +} + +clean_qemu_static() { + local root_fs_dir="$1" + case "${BOARD}" in + amd64-usr) return 0;; + arm64-usr) + if [[ -f "${root_fs_dir}/usr/bin/qemu-aarch64-static" ]]; then + sudo rm "${root_fs_dir}"/usr/bin/qemu-aarch64-static + else + die "File not found" + fi + ;; + *) die "Unsupported arch" ;; + esac +} diff --git a/setup_board b/setup_board index 70080ce1bd..6294fd8d68 100755 --- a/setup_board +++ b/setup_board @@ -367,6 +367,12 @@ if [[ ${FLAGS_regen_configs} -eq ${FLAGS_FALSE} ]]; then "${EMERGE_TOOLCHAIN_FLAGS[@]}" "${TOOLCHAIN_PKGS[@]}" fi +if [[ ${FLAGS_regen_configs_only} -eq ${FLAGS_FALSE} ]]; then + : +fi +# Setup BOARD_ROOT for QEMU user emulation. +setup_qemu_static "${BOARD_ROOT}" + if [ $FLAGS_default -eq $FLAGS_TRUE ] ; then echo $BOARD_VARIANT > "$GCLIENT_ROOT/src/scripts/.default_board" fi