@@ -593,3 +593,69 @@ function load_module_config() {
593593 echo " ================================================================"
594594 done
595595}
596+
597+ function chroot_correct_qemu() {
598+ local host_arch=" $1 "
599+ local target_arch=" $2 "
600+
601+ # Validate inputs
602+ if [[ -z " $host_arch " ]] || [[ -z " $target_arch " ]]; then
603+ echo " Error: Missing required arguments"
604+ echo " Usage: setup_qemu_chroot host_arch target_arch chroot_script custom_pi_os_path"
605+ return 1
606+ fi
607+
608+ # Copy required scripts
609+ cp " $chroot_script " chroot_script
610+ chmod 755 chroot_script
611+ cp " ${custom_pi_os_path} /common.sh" common.sh
612+ chmod 755 common.sh
613+
614+ # Set up QEMU if needed
615+ if [[ " $host_arch " != " armv7l" ]] || [[ " $host_arch " != " aarch64" ]]; then
616+ if [[ " $target_arch " == " armv7l" ]] || [[ " $target_arch " == " armhf" ]]; then
617+ if grep -q gentoo /etc/os-release; then
618+ ROOT=" $( realpath .) " emerge --usepkgonly --oneshot --nodeps qemu
619+ else
620+ cp " $( which qemu-arm-static) " usr/bin/qemu-arm-static
621+ fi
622+ elif [[ " $target_arch " == " aarch64" ]] || [[ " $target_arch " == " arm64" ]]; then
623+ if grep -q gentoo /etc/os-release; then
624+ ROOT=" $( realpath .) " emerge --usepkgonly --oneshot --nodeps qemu
625+ else
626+ cp " $( which qemu-aarch64-static) " usr/bin/qemu-aarch64-static
627+ fi
628+ fi
629+ fi
630+
631+ # Execute chroot with appropriate QEMU setup
632+ if [[ " $host_arch " != " armv7l" ]] && [[ " $host_arch " != " aarch64" ]] && [[ " $host_arch " != " arm64" ]]; then
633+ echo " Detected we are on a non-arm device"
634+ if [[ " $target_arch " == " armv7l" ]] || [[ " $target_arch " == " armhf" ]]; then
635+ echo " Building on non-ARM device a armv7l system, using qemu-arm-static"
636+ if grep -q gentoo /etc/os-release; then
637+ echo " Building on gentoo non-ARM device a armv7l system, using qemu-arm"
638+ chroot . usr/bin/qemu-arm /bin/bash /chroot_script
639+ else
640+ echo " Using normal non-arm qemu for armv7l"
641+ chroot . usr/bin/qemu-arm-static /bin/bash /chroot_script
642+ fi
643+ elif [[ " $target_arch " == " aarch64" ]] || [[ " $target_arch " == " arm64" ]]; then
644+ echo " Building on non-ARM device a aarch64/arm64 system, using qemu-aarch64-static"
645+ if grep -q gentoo /etc/os-release; then
646+ chroot . usr/bin/qemu-aarch64 /bin/bash /chroot_script
647+ else
648+ chroot . usr/bin/qemu-aarch64-static /bin/bash /chroot_script
649+ fi
650+ else
651+ echo " Unknown arch, building on: $host_arch image: $target_arch "
652+ return 1
653+ fi
654+ elif { [[ " $target_arch " == " armv7l" ]] || [[ " $target_arch " == " armhf" ]]; } && [[ " $host_arch " != " armv7l" ]]; then
655+ echo " Building on aarch64/arm64 device a armv7l system, using qemu-arm-static"
656+ chroot . usr/bin/qemu-arm-static /bin/bash /chroot_script
657+ else
658+ echo " Building on ARM device a armv7l/aarch64/arm64 system, not using qemu"
659+ chroot . /bin/bash /chroot_script
660+ fi
661+ }
0 commit comments