Skip to contentSkip to conversation

prepare-kernel.sh: Emit architecture agnostic changes

RFC PATCH In review Richard Weinberger 2 participants 4 messages May 17, 2024 – May 21, 2024

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 prepare-kernel.sh: Emit architecture agnostic changes

If --arch= is not passed, emit changes that work on all architectures supported by Xenomai, currently arm, arm64 and x86.
This is especially useful with --outpatch=, the resulting patch can be used for any architecture later and makes maintaining and building a Xenomai enabled kernel easier.

---
 scripts/Kconfig.frag      |  2 +-
 scripts/prepare-kernel.sh | 56 +++++++++++++++++----------------------
 2 files changed, 25 insertions(+), 33 deletions(-)
scripts/Kconfig.frag +1 -1
index b76d25e53..3c9ad2b9f 100644
@@ -16,7 +16,7 @@ menuconfig XENOMAI
 	  Please visit http://xenomai.org for more information.
 
 if XENOMAI
-source "arch/@SRCARCH@/xenomai/Kconfig"
+source "arch/$(SRCARCH)/xenomai/Kconfig"
 endif
 
 if MIGRATION
scripts/prepare-kernel.sh +24 -32

98 lines not on this page · raw message

Signature · 1 line
2.35.3
#1 lore raw
Quoted 17 lines · Richard Weinberger

If --arch= is not passed, emit changes that work on all architectures supported by Xenomai, currently arm, arm64 and x86.
This is especially useful with --outpatch=, the resulting patch can be used for any architecture later and makes maintaining and building a Xenomai enabled kernel easier.

---
 scripts/Kconfig.frag      |  2 +-
 scripts/prepare-kernel.sh | 56 +++++++++++++++++----------------------
 2 files changed, 25 insertions(+), 33 deletions(-)
scripts/Kconfig.frag +0 -0
index b76d25e53..3c9ad2b9f 100644

scripts/Kconfig.frag menuconfig XENOMAI · line 19

Quoted 5 lines
scripts/Kconfig.frag +1 -1
@@ -16,7 +16,7 @@ menuconfig XENOMAI
 	  Please visit http://xenomai.org for more information.
 
 if XENOMAI
-source "arch/@SRCARCH@/xenomai/Kconfig"
+source "arch/$(SRCARCH)/xenomai/Kconfig"

That was likely there for historical reasons. Removing it makes things only simpler.

Quoted 18 lines
scripts/Kconfig.frag +0 -0
 endif
 
 if MIGRATION
scripts/prepare-kernel.sh +0 -7
index c9aeeb4fa..25f3b4a7c 100755
@@ -249,37 +249,24 @@ if test "x$output_patch" != "x"; then
 
 fi
 
-# Infer the default architecture if unspecified.
-
-if test x$linux_arch = x; then
-   build_arch=`$xenomai_root/config/config.guess`
-   default_linux_arch=`echo $build_arch|cut -f1 -d-`
-fi
-

scripts/prepare-kernel.sh if test "x$output_patch" != "x"; then · line 254

Quoted 10 lines
scripts/prepare-kernel.sh +1 -7
 while : ; do
    if test x$linux_arch = x; then
-      if test x$usedefault = x; then
-         echo -n "Target architecture [default $default_linux_arch]: "
-         read linux_arch
-      fi
-      if test "x$linux_arch" = x; then
-         linux_arch=$default_linux_arch
-      fi
+      target_linux_archs=(x86 arm arm64)

Is there a particular advantage to use a bash array for that, rather than just a plain space-separated list?

Quoted 71 lines
scripts/prepare-kernel.sh +19 -16
+      break
    fi
    case "$linux_arch" in
    x86*|i*86|amd*)
-      linux_arch=x86
+      target_linux_archs=(x86)
       ;;
    arm)
-      linux_arch=arm
+      target_linux_archs=(arm)
       ;;
    arm64|aarch64)
-      linux_arch=arm64
+      target_linux_archs=(arm64)
       ;;
    *)
       echo "$me: unsupported architecture: $linux_arch" >&2
-      linux_arch=
-      usedefault=
+      exit 1
       ;;
    esac
    if test \! x$linux_arch = x; then
@@ -333,10 +320,12 @@ else
    cd $curdir
 fi
 
-if test \! -r $linux_tree/arch/$linux_arch/$arch_probe_header; then
-   echo "$me: $linux_tree has no IRQ pipeline support for $linux_arch" >&2
-   exit 2
-fi
+for a in ${target_linux_archs[@]}; do
+   if test \! -r $linux_tree/arch/$a/$arch_probe_header; then
+      echo "$me: $linux_tree has no IRQ pipeline support for $a" >&2
+      exit 2
+   fi
+done
 
 if test x$verbose = x1; then
    echo "IRQ pipeline installed."
@@ -369,19 +358,20 @@ case $linux_VERSION.$linux_PATCHLEVEL in
 	    -e "s,@VERSION_MINOR@,$version_minor,g" \
 	    -e "s,@REVISION_LEVEL@,$revision_level,g" \
 	    -e "s,@VERSION_STRING@,$version_string,g" \
-	    -e "s,@SRCARCH@,$linux_arch,g" \
 	    $xenomai_root/scripts/Kconfig.frag |
             patch_append init/Kconfig
     fi
 
 test "x$CONFIG_XENO_REVISION_LEVEL" = "x" && CONFIG_XENO_REVISION_LEVEL=0
 
-    if ! grep -q CONFIG_XENOMAI $linux_tree/arch/$linux_arch/Makefile; then
-	p="KBUILD_CFLAGS += -I\$(srctree)/arch/\$(SRCARCH)/xenomai/include -I\$(srctree)/include/xenomai"
-	(echo; echo $p) | patch_append arch/$linux_arch/Makefile
-	p="core-\$(CONFIG_XENOMAI)	+= arch/$linux_arch/xenomai/"
-	echo $p | patch_append arch/$linux_arch/Makefile
-    fi
+    for a in ${target_linux_archs[@]}; do
+        if ! grep -q CONFIG_XENOMAI $linux_tree/arch/$a/Makefile; then
+	    p="KBUILD_CFLAGS += -I\$(srctree)/arch/\$(SRCARCH)/xenomai/include -I\$(srctree)/include/xenomai"
+	    (echo; echo $p) | patch_append arch/$a/Makefile
+	    p="core-\$(CONFIG_XENOMAI)	+= arch/\$(SRCARCH)/xenomai/"
+	    echo $p | patch_append arch/$a/Makefile
+        fi
+    done
 
     patch_architecture_specific="n"
 
@@ -404,8 +394,10 @@ esac
 
 patch_kernelversion_specific="n"

scripts/prepare-kernel.sh esac · line 403

Quoted 10 lines
scripts/prepare-kernel.sh +4 -2
 patch_architecture_specific="y"
-patch_link r m kernel/cobalt/arch/$linux_arch arch/$linux_arch/xenomai
-patch_link n n kernel/cobalt/include/dovetail arch/$linux_arch/include/dovetail
+for a in ${target_linux_archs[@]}; do
+    patch_link r m kernel/cobalt/arch/$a arch/$a/xenomai
+    patch_link n n kernel/cobalt/include/dovetail arch/$a/include/dovetail
+done
 patch_architecture_specific="n"
 patch_link n m kernel/cobalt kernel/xenomai
 patch_link n cobalt-core.h kernel/cobalt/trace include/trace/events

This indeed looks like a valuable enhancement.

Jan

Signature · 2 lines
Siemens AG, Technology
Linux Expert Center
#2 lore raw

----- Ursprüngliche Mail -----

Quoted 6 lines

scripts/Kconfig.frag menuconfig XENOMAI · line 19

Quoted 3 lines

if XENOMAI

scripts/Kconfig.frag +1 -1
-source "arch/@SRCARCH@/xenomai/Kconfig"
+source "arch/$(SRCARCH)/xenomai/Kconfig"

That was likely there for historical reasons. Removing it makes things only simpler.

You mean removing the whole line or just @SRCARCH@?

Quoted 23 lines
Quoted 23 lines

endif

if MIGRATION

scripts/prepare-kernel.sh +0 -10
index c9aeeb4fa..25f3b4a7c 100755
@@ -249,37 +249,24 @@ if test "x$output_patch" != "x"; then
 
 fi
 
-# Infer the default architecture if unspecified.
-
-if test x$linux_arch = x; then
-   build_arch=`$xenomai_root/config/config.guess`
-   default_linux_arch=`echo $build_arch|cut -f1 -d-`
-fi
-
 while : ; do
    if test x$linux_arch = x; then
-      if test x$usedefault = x; then
-         echo -n "Target architecture [default $default_linux_arch]: "
-         read linux_arch
Quoted 8 lines

scripts/prepare-kernel.sh if test "x$output_patch" != "x"; then · line 254

Quoted 5 lines
scripts/prepare-kernel.sh +1 -4
-      fi
-      if test "x$linux_arch" = x; then
-         linux_arch=$default_linux_arch
-      fi
+      target_linux_archs=(x86 arm arm64)

Is there a particular advantage to use a bash array for that, rather than just a plain space-separated list?

Hmm. In this case not really. Since the architecture names will never contain spaces nor special characters.

Thanks,
//richard

#3 lore raw
Quoted 10 lines · Richard Weinberger

----- Ursprüngliche Mail -----

Quoted 6 lines

scripts/Kconfig.frag menuconfig XENOMAI · line 19

Quoted 3 lines

if XENOMAI

scripts/Kconfig.frag +1 -1
-source "arch/@SRCARCH@/xenomai/Kconfig"
+source "arch/$(SRCARCH)/xenomai/Kconfig"

That was likely there for historical reasons. Removing it makes things only simpler.

You mean removing the whole line or just @SRCARCH@?

No, that was no call for action, just a statement.

Quoted 32 lines
Quoted 23 lines
Quoted 23 lines

endif

if MIGRATION

scripts/prepare-kernel.sh +0 -10
index c9aeeb4fa..25f3b4a7c 100755
@@ -249,37 +249,24 @@ if test "x$output_patch" != "x"; then
 
 fi
 
-# Infer the default architecture if unspecified.
-
-if test x$linux_arch = x; then
-   build_arch=`$xenomai_root/config/config.guess`
-   default_linux_arch=`echo $build_arch|cut -f1 -d-`
-fi
-
 while : ; do
    if test x$linux_arch = x; then
-      if test x$usedefault = x; then
-         echo -n "Target architecture [default $default_linux_arch]: "
-         read linux_arch
Quoted 8 lines

scripts/prepare-kernel.sh if test "x$output_patch" != "x"; then · line 254

Quoted 5 lines
scripts/prepare-kernel.sh +1 -4
-      fi
-      if test "x$linux_arch" = x; then
-         linux_arch=$default_linux_arch
-      fi
+      target_linux_archs=(x86 arm arm64)

Is there a particular advantage to use a bash array for that, rather than just a plain space-separated list?

Quoted 2 lines

Hmm. In this case not really. Since the architecture names will never contain spaces nor special characters.

I'm not sure if we have other bashism in the script (the shellcheck list is long...) but with this, we would for sure. So I would avoid it here.

Jan

Signature · 2 lines
Siemens AG, Technology
Linux Expert Center