Skip to contentSkip to conversation

Update architecture detection

PATCH Applied Ben Hutchings 2 participants 14 messages Jul 26, 2018 – Aug 2, 2018 Kbuild

lore
Share & tools
lore
#0 lore raw

cover Update architecture detection

This series cleans up the set_debarch function in scripts/package/mkdebian and adds support for several additional Debian architectures.

Ben.

Ben Hutchings (12):
builddeb: Skip architecture detection when KBUILD_DEBARCH is set
builddeb: Change architecture detection fallback to use
dpkg-architecture
builddeb: Drop check for 32-bit s390
builddeb: Introduce functions to simplify kconfig tests in set_debarch
builddeb: Add automatic support for ppc64 and powerpcspe architectures
builddeb: Add automatic support for mips64el architecture
builddeb: Add automatic support for mips46{,64}{,el} architectures
builddeb: Add automatic support for sparc64 architecture
builddeb: Add automatic support for or1k architecture
builddeb: Add automatic support for m68k architecture
builddeb: Add automatic support for riscv* architectures
builddeb: Add automatic support for sh{3,4}{,eb} architectures

 scripts/package/mkdebian | 68 +++++++++++++++++++++++++++++-----------
 1 file changed, 50 insertions(+), 18 deletions(-)
#1 lore raw

PATCH 1/12 builddeb: Skip architecture detection when KBUILD_DEBARCH is set

If KBUILD_DEBARCH is set then we will not use the result of architecture detection, and we may also warn unnecessarily. Move the check for KBUILD_DEBARCH further up to avoid this.

---
 scripts/package/mkdebian | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
scripts/package/mkdebian +6 -3
index 985d72d1ab34..434f0b4d5231 100755
@@ -7,6 +7,11 @@
 set -e
 
 set_debarch() {
+	if [ -n "$KBUILD_DEBARCH" ] ; then
+		debarch="$KBUILD_DEBARCH"
+		return
+	fi
+
 	# Attempt to find the correct Debian architecture
 	case "$UTS_MACHINE" in
 	i386|ia64|alpha)
@@ -46,10 +51,8 @@ set_debarch() {
 		echo "Falling back to using your current userspace instead!" >&2
 		echo "Please add support for $UTS_MACHINE to ${0} ..." >&2
 		echo "" >&2
+		;;
 	esac
-	if [ -n "$KBUILD_DEBARCH" ] ; then
-		debarch="$KBUILD_DEBARCH"
-	fi
 }
 
 # Some variables and settings used throughout the script
#2 lore raw

PATCH 2/12 builddeb: Change architecture detection fallback to use dpkg-architecture

In reply to Ben Hutchings

We currently use dpkg --print-architecture, which reports the architecture of the build machine. We can make a better guess than this by asking dpkg-architecture what the host architecture, i.e. the default architecture for building packages, is. This is sensitive to environment variables such as CC and DEB_HOST_ARCH, which should already be set in a cross-build environment.

---
 scripts/package/mkdebian | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
scripts/package/mkdebian +2 -2
index 434f0b4d5231..389bf983879d 100755
@@ -42,13 +42,13 @@ set_debarch() {
 		fi
 		;;
 	*)
-		debarch=$(dpkg --print-architecture)
+		debarch=$(dpkg-architecture -qDEB_HOST_ARCH)
 		echo "" >&2
 		echo "** ** **  WARNING  ** ** **" >&2
 		echo "" >&2
 		echo "Your architecture doesn't have its equivalent" >&2
 		echo "Debian userspace architecture defined!" >&2
-		echo "Falling back to using your current userspace instead!" >&2
+		echo "Falling back to the current host architecture ($debarch)." >&2
 		echo "Please add support for $UTS_MACHINE to ${0} ..." >&2
 		echo "" >&2
 		;;
#3 lore raw

PATCH 3/12 builddeb: Drop check for 32-bit s390

In reply to Ben Hutchings

s390 now only supports 64-bit configurations.

---
 scripts/package/mkdebian | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/package/mkdebian +1 -1
index 389bf983879d..f4449b575379 100755
@@ -21,7 +21,7 @@ set_debarch() {
 	sparc*)
 		debarch=sparc ;;
 	s390*)
-		debarch=s390$(grep -q CONFIG_64BIT=y $KCONFIG_CONFIG && echo x || true) ;;
+		debarch=s390x ;;
 	ppc*)
 		debarch=$(grep -q CPU_LITTLE_ENDIAN=y $KCONFIG_CONFIG && echo ppc64el || echo powerpc) ;;
 	parisc*)
#4 lore raw

PATCH 4/12 builddeb: Introduce functions to simplify kconfig tests in set_debarch

In reply to Ben Hutchings

We now have many repetitive greps over the kernel config. Refactor them into functions.

---
 scripts/package/mkdebian | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)
scripts/package/mkdebian +17 -9
index f4449b575379..ada3c73d1493 100755
@@ -6,6 +6,18 @@
 
 set -e
 
+is_enabled() {
+	grep -q "^CONFIG_$1=y" $KCONFIG_CONFIG
+}
+
+if_enabled_echo() {
+	if is_enabled "$1"; then
+		echo -n "$2"
+	elif [ $# -ge 3 ]; then
+		echo -n "$3"
+	fi
+}
+
 set_debarch() {
 	if [ -n "$KBUILD_DEBARCH" ] ; then
 		debarch="$KBUILD_DEBARCH"
@@ -23,22 +35,18 @@ set_debarch() {
 	s390*)
 		debarch=s390x ;;
 	ppc*)
-		debarch=$(grep -q CPU_LITTLE_ENDIAN=y $KCONFIG_CONFIG && echo ppc64el || echo powerpc) ;;
+		debarch=$(if_enabled_echo CPU_LITTLE_ENDIAN ppc64el powerpc) ;;
 	parisc*)
 		debarch=hppa ;;
 	mips*)
-		debarch=mips$(grep -q CPU_LITTLE_ENDIAN=y $KCONFIG_CONFIG && echo el || true) ;;
+		debarch=mips$(if_enabled_echo CPU_LITTLE_ENDIAN el) ;;
 	aarch64|arm64)
 		debarch=arm64 ;;
 	arm*)
-		if grep -q CONFIG_AEABI=y $KCONFIG_CONFIG; then
-		    if grep -q CONFIG_VFP=y $KCONFIG_CONFIG; then
-			debarch=armhf
-		    else
-			debarch=armel
-		    fi
+		if is_enabled AEABI; then
+			debarch=arm$(if_enabled_echo VFP hf el)
 		else
-		    debarch=arm
+			debarch=arm
 		fi
 		;;
 	*)
#5 lore raw

PATCH 5/12 builddeb: Add automatic support for ppc64 and powerpcspe architectures

In reply to Ben Hutchings

We currently label 64-bit big-endian kernel packages as powerpc (32-bit), mostly because it was officially supported while ppc64 (64-bit big-endian) was not. Now neither is officially supported, so label these packages as ppc64.

Debian also has a powerpcspe (32-bit with SPE) architecture. Label packages with a suitable configuration as powerpcspe.

---
 scripts/package/mkdebian | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
scripts/package/mkdebian +6 -1
index ada3c73d1493..0891974f499b 100755
@@ -35,7 +35,12 @@ set_debarch() {
 	s390*)
 		debarch=s390x ;;
 	ppc*)
-		debarch=$(if_enabled_echo CPU_LITTLE_ENDIAN ppc64el powerpc) ;;
+		if is_enabled 64BIT; then
+			debarch=ppc64$(if_enabled_echo CPU_LITTLE_ENDIAN el)
+		else
+			debarch=powerpc$(if_enabled_echo SPE spe)
+		fi
+		;;
 	parisc*)
 		debarch=hppa ;;
 	mips*)
#6 lore raw

PATCH 6/12 builddeb: Add automatic support for mips64el architecture

In reply to Ben Hutchings

We currently label 64-bit little-endian kernel packages as mipsel (32-bit little-endian), mostly it was officially supported while mips64el (64-bit little-endian) was not. Now both are officially supported, so label these packages as mips64el.

---
 scripts/package/mkdebian | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
scripts/package/mkdebian +6 -1
index 0891974f499b..350724cdc5af 100755
@@ -44,7 +44,12 @@ set_debarch() {
 	parisc*)
 		debarch=hppa ;;
 	mips*)
-		debarch=mips$(if_enabled_echo CPU_LITTLE_ENDIAN el) ;;
+		if is_enabled CPU_LITTLE_ENDIAN; then
+			debarch=mips$(if_enabled_echo 64BIT 64)el
+		else
+			debarch=mips
+		fi
+		;;
 	aarch64|arm64)
 		debarch=arm64 ;;
 	arm*)
#7 lore raw

PATCH 7/12 builddeb: Add automatic support for mips{,64}r6{,el} architectures

In reply to Ben Hutchings

MIPS R6 is not fully backward-compatible, so Debian has separate architecture names for userland built for R6. Label kernel packages accordingly.

---
 scripts/package/mkdebian | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
scripts/package/mkdebian +3 -1
index 350724cdc5af..595482923844 100755
@@ -45,7 +45,9 @@ set_debarch() {
 		debarch=hppa ;;
 	mips*)
 		if is_enabled CPU_LITTLE_ENDIAN; then
-			debarch=mips$(if_enabled_echo 64BIT 64)el
+			debarch=mips$(if_enabled_echo 64BIT 64)$(if_enabled_echo CPU_MIPSR6 r6)el
+		elif is_enabled CPU_MIPSR6; then
+			debarch=mips$(if_enabled_echo 64BIT 64)r6
 		else
 			debarch=mips
 		fi
#8 lore raw

PATCH 8/12 builddeb: Add automatic support for sparc64 architecture

In reply to Ben Hutchings

We currently label 64-bit kernel packages as sparc (32-bit), mostly because it was officially supported while sparc64 was not. Now neither is officially supported, so label these packages as sparc64.

---
 scripts/package/mkdebian | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/package/mkdebian +1 -1
index 595482923844..83179a4c6fda 100755
@@ -31,7 +31,7 @@ set_debarch() {
 	x86_64)
 		debarch=amd64 ;;
 	sparc*)
-		debarch=sparc ;;
+		debarch=sparc$(if_enabled_echo 64BIT 64) ;;
 	s390*)
 		debarch=s390x ;;
 	ppc*)
#9 lore raw

PATCH 9/12 builddeb: Add automatic support for or1k architecture

In reply to Ben Hutchings
---
 scripts/package/mkdebian | 2 ++
 1 file changed, 2 insertions(+)
scripts/package/mkdebian +2 -0
index 83179a4c6fda..fb0d3056f3e2 100755
@@ -61,6 +61,8 @@ set_debarch() {
 			debarch=arm
 		fi
 		;;
+	openrisc)
+		debarch=or1k ;;
 	*)
 		debarch=$(dpkg-architecture -qDEB_HOST_ARCH)
 		echo "" >&2
#10 lore raw

PATCH 10/12 builddeb: Add automatic support for m68k architecture

In reply to Ben Hutchings
---
 scripts/package/mkdebian | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/package/mkdebian +1 -1
index fb0d3056f3e2..470899fa3a8c 100755
@@ -26,7 +26,7 @@ set_debarch() {
 
 	# Attempt to find the correct Debian architecture
 	case "$UTS_MACHINE" in
-	i386|ia64|alpha)
+	i386|ia64|alpha|m68k)
 		debarch="$UTS_MACHINE" ;;
 	x86_64)
 		debarch=amd64 ;;
#11 lore raw

PATCH 11/12 builddeb: Add automatic support for riscv* architectures

In reply to Ben Hutchings

Debian currently only defines "riscv64", but it seems safe to assume that any 32-bit port will now be called "riscv32", also matching $UTS_MACHINE.

---
 scripts/package/mkdebian | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/package/mkdebian +1 -1
index 470899fa3a8c..3ef2fd0c5086 100755
@@ -26,7 +26,7 @@ set_debarch() {
 
 	# Attempt to find the correct Debian architecture
 	case "$UTS_MACHINE" in
-	i386|ia64|alpha|m68k)
+	i386|ia64|alpha|m68k|riscv*)
 		debarch="$UTS_MACHINE" ;;
 	x86_64)
 		debarch=amd64 ;;
#12 lore raw

PATCH 12/12 builddeb: Add automatic support for sh{3,4}{,eb} architectures

In reply to Ben Hutchings

Different generations of the SH architecture are not very compatible, so there are/were separate Debian ports for SH3 and SH4.

Move the fallback out of the "case" statement, so that it will also be used in case we find some SH architecture version without a known mapping.

---
 scripts/package/mkdebian | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
scripts/package/mkdebian +10 -3
index 3ef2fd0c5086..663a7f343b42 100755
@@ -63,7 +63,15 @@ set_debarch() {
 		;;
 	openrisc)
 		debarch=or1k ;;
-	*)
+	sh)
+		if is_enabled CPU_SH3; then
+			debarch=sh3$(if_enabled_echo CPU_BIG_ENDIAN eb)
+		elif is_enabled CPU_SH4; then
+			debarch=sh4$(if_enabled_echo CPU_BIG_ENDIAN eb)
+		fi
+		;;
+	esac
+	if [ -z "$debarch" ]; then
 		debarch=$(dpkg-architecture -qDEB_HOST_ARCH)
 		echo "" >&2
 		echo "** ** **  WARNING  ** ** **" >&2
@@ -73,8 +81,7 @@ set_debarch() {
 		echo "Falling back to the current host architecture ($debarch)." >&2
 		echo "Please add support for $UTS_MACHINE to ${0} ..." >&2
 		echo "" >&2
-		;;
-	esac
+	fi
 }
 
 # Some variables and settings used throughout the script
#13 lore raw
In reply to Ben Hutchings

2018-07-26 19:19 GMT+09:00 Ben Hutchings <[email protected]>:

Quoted 21 lines

This series cleans up the set_debarch function in scripts/package/mkdebian and adds support for several additional Debian architectures.

Ben.

Ben Hutchings (12):
builddeb: Skip architecture detection when KBUILD_DEBARCH is set
builddeb: Change architecture detection fallback to use
dpkg-architecture
builddeb: Drop check for 32-bit s390
builddeb: Introduce functions to simplify kconfig tests in set_debarch
builddeb: Add automatic support for ppc64 and powerpcspe architectures
builddeb: Add automatic support for mips64el architecture
builddeb: Add automatic support for mips46{,64}{,el} architectures
builddeb: Add automatic support for sparc64 architecture
builddeb: Add automatic support for or1k architecture
builddeb: Add automatic support for m68k architecture
builddeb: Add automatic support for riscv* architectures
builddeb: Add automatic support for sh{3,4}{,eb} architectures

Quoted 3 lines
 scripts/package/mkdebian | 68 +++++++++++++++++++++++++++++-----------
 1 file changed, 50 insertions(+), 18 deletions(-)

Applied. Thanks!

Signature · 2 lines
Best Regards
Masahiro Yamada