]> glassweightruler.freedombox.rocks Git - waydroid.git/commitdiff
arch: Separately identify arm64_only CPUs without AArch32 support
authorJami Kettunen <jami.kettunen@protonmail.com>
Fri, 23 May 2025 13:53:21 +0000 (16:53 +0300)
committerAlessandro Astone <ales.astone@gmail.com>
Fri, 23 May 2025 17:07:58 +0000 (19:07 +0200)
More and more modern AArch64 SoCs present both in computers and phones
can no longer run normal arm64 image builds which (currently anyway)
also ship various amounts of 32-bit executables that cannot be natively
executed; thus let's target an upcoming arm64_only OTA channel instead.

tools/helpers/arch.py

index c74ef906574fbc1533e316ecd6e9e7b0c450a9fd..8f4543a582dbd47f9a7e6eaabd12282fbecf54c6 100644 (file)
@@ -2,6 +2,21 @@
 # SPDX-License-Identifier: GPL-3.0-or-later
 import platform
 import logging
 # SPDX-License-Identifier: GPL-3.0-or-later
 import platform
 import logging
+import ctypes
+
+def is_32bit_capable():
+    # man 2 personality
+    personality = ctypes.CDLL(None).personality
+    personality.restype = ctypes.c_int
+    personality.argtypes = [ctypes.c_ulong]
+    # linux/include/uapi/linux/personality.h
+    PER_LINUX32 = 0x0008
+    # mirror e.g. https://github.com/util-linux/util-linux/blob/v2.41/sys-utils/lscpu-cputype.c#L745-L756
+    pers = personality(PER_LINUX32)
+    if pers != -1: # success, revert back to previous persona (typically just PER_LINUX, 0x0000)
+        personality(pers)
+        return True
+    return False # unable to "impersonate" 32-bit host, nothing done
 
 def host():
     machine = platform.machine()
 
 def host():
     machine = platform.machine()
@@ -29,5 +44,8 @@ def maybe_remap(target):
             return "x86"
     elif target == "arm64" and platform.architecture()[0] == "32bit":
         return "arm"
             return "x86"
     elif target == "arm64" and platform.architecture()[0] == "32bit":
         return "arm"
+    elif target == "arm64" and not is_32bit_capable():
+        logging.info("AArch64 CPU does not appear to support AArch32, assuming arm64_only...")
+        return "arm64_only"
 
     return target
 
     return target