]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core.git/commitdiff
kernel-arch: Move kernel and uboot arch functions to lib/oe/kernel.py
authorRichard Purdie <richard.purdie@linuxfoundation.org>
Wed, 29 Jul 2026 22:32:52 +0000 (23:32 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Mon, 3 Aug 2026 17:04:08 +0000 (18:04 +0100)
Move the ARCH and UBOOT_ARCH python functions to the python library code.

The ability to alter valid_archs is removed as:
 - the values should be long since established by now
 - non-linux targets have an escape in the code
 - the lower case variable name is not normal convention and should be
   replaced if we were to retain it

By removing it we'll find out if anyone does actually need that (and we
can probably fix the entries in the file if there is anything missing).

The code itself is full of redundant codepaths but that is for another
patch if we try and improve it.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/classes-recipe/kernel-arch.bbclass
meta/lib/oe/kernel.py

index 5f8dbacc0c0460fa974ef8d5a3ed8b68419f6018..b00341c21806825f750501658712b3ca3243d21e 100644 (file)
@@ -4,61 +4,11 @@
 # SPDX-License-Identifier: MIT
 #
 
-#
 # set the ARCH environment variable for kernel compilation (including
 # modules). return value must match one of the architecture directories
 # in the kernel source "arch" directory
-#
-
-valid_archs = "alpha cris ia64 \
-               i386 x86 \
-               m68knommu m68k ppc powerpc powerpc64 ppc64  \
-               sparc sparc64 \
-               arm aarch64 \
-               m32r mips \
-               sh sh64 um h8300   \
-               parisc s390  v850 \
-               avr32 blackfin \
-               loongarch64 \
-               microblaze \
-               nios2 arc riscv xtensa"
-
-def map_kernel_arch(a, d):
-    import re
-
-    valid_archs = d.getVar('valid_archs').split()
-
-    if   re.match('(i.86|athlon|x86.64)$', a):  return 'x86'
-    elif re.match('arceb$', a):                 return 'arc'
-    elif re.match('armeb$', a):                 return 'arm'
-    elif re.match('aarch64$', a):               return 'arm64'
-    elif re.match('aarch64_be$', a):            return 'arm64'
-    elif re.match('aarch64_ilp32$', a):         return 'arm64'
-    elif re.match('aarch64_be_ilp32$', a):      return 'arm64'
-    elif re.match('loongarch(32|64|)$', a):     return 'loongarch'
-    elif re.match('mips(isa|)(32|64|)(r6|)(el|)$', a):      return 'mips'
-    elif re.match('mcf', a):                    return 'm68k'
-    elif re.match('riscv(32|64|)(eb|)$', a):    return 'riscv'
-    elif re.match('p(pc|owerpc)(|64)', a):      return 'powerpc'
-    elif re.match('sh(3|4)$', a):               return 'sh'
-    elif re.match('bfin', a):                   return 'blackfin'
-    elif re.match('microblazee[bl]', a):        return 'microblaze'
-    elif a in valid_archs:                      return a
-    else:
-        if not d.getVar("TARGET_OS").startswith("linux"):
-            return a
-        bb.error("cannot map '%s' to a linux kernel architecture" % a)
-
-export ARCH = "${@map_kernel_arch(d.getVar('TARGET_ARCH'), d)}"
-
-def map_uboot_arch(a, d):
-    import re
-
-    if   re.match('p(pc|owerpc)(|64)', a): return 'ppc'
-    elif re.match('i.86$', a): return 'x86'
-    return a
-
-export UBOOT_ARCH = "${@map_uboot_arch(d.getVar('ARCH'), d)}"
+export ARCH = "${@oe.kernel.map_kernel_arch(d)}"
+export UBOOT_ARCH = "${@oe.kernel.map_uboot_arch(d)}"
 
 # Set TARGET_??_KERNEL_ARCH in the machine .conf to set architecture
 # specific options necessary for building the kernel and modules.
index 421debed9af0705f4ada7e31a5ccb0895928f4d7..bab375c37aea1041d36bc50a0e477317b2bc806e 100644 (file)
@@ -6,6 +6,45 @@
 
 import re
 
+# Return a value for the ARCH environment variable for kernel compilation (including
+# modules). return value must match one of the architecture directories
+# in the kernel source "arch" directory
+def map_kernel_arch(d):
+    a = d.getVar('TARGET_ARCH')
+
+    valid_archs = ["alpha", "cris", "ia64", "i386", "x86", "m68knommu", "m68k", "ppc", "powerpc",
+                   "powerpc64", "ppc64", "sparc", "sparc64", "arm", "aarch64", "m32r", "mips",
+                   "sh", "sh64", "um", "h8300", "parisc", "s390", "v850", "avr32", "blackfin",
+                   "loongarch64", "microblaze", "nios2", "arc", "riscv", "xtensa"]
+
+    if   re.match('(i.86|athlon|x86.64)$', a):  return 'x86'
+    elif re.match('arceb$', a):                 return 'arc'
+    elif re.match('armeb$', a):                 return 'arm'
+    elif re.match('aarch64$', a):               return 'arm64'
+    elif re.match('aarch64_be$', a):            return 'arm64'
+    elif re.match('aarch64_ilp32$', a):         return 'arm64'
+    elif re.match('aarch64_be_ilp32$', a):      return 'arm64'
+    elif re.match('loongarch(32|64|)$', a):     return 'loongarch'
+    elif re.match('mips(isa|)(32|64|)(r6|)(el|)$', a):      return 'mips'
+    elif re.match('mcf', a):                    return 'm68k'
+    elif re.match('riscv(32|64|)(eb|)$', a):    return 'riscv'
+    elif re.match('p(pc|owerpc)(|64)', a):      return 'powerpc'
+    elif re.match('sh(3|4)$', a):               return 'sh'
+    elif re.match('bfin', a):                   return 'blackfin'
+    elif re.match('microblazee[bl]', a):        return 'microblaze'
+    elif a in valid_archs:                      return a
+    else:
+        if not d.getVar("TARGET_OS").startswith("linux"):
+            return a
+        bb.error("cannot map '%s' to a linux kernel architecture" % a)
+
+def map_uboot_arch(d):
+    a = map_kernel_arch(d)
+
+    if   re.match('p(pc|owerpc)(|64)', a): return 'ppc'
+    elif re.match('i.86$', a): return 'x86'
+    return a
+
 # parse kernel ABI version out of <linux/version.h>
 def get_version_headers(p):
     fn = p + '/include/linux/utsrelease.h'