Skip to contentSkip to conversation

riscv: Run with other QEMU models

PATCH In review Andrew Jones 1 participant 5 messages Feb 21, 2025 – Mar 4, 2025

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover riscv: Run with other QEMU models

Provide a couple patches allowing a QEMU machine model other than 'virt' to be used. We just need to be able to override 'virt' in the command line and it's also nice to be able to specify a different UART address for any early (pre DT parsing) outputs.

Andrew Jones (2):
configure: Allow earlycon for all architectures
riscv: Introduce MACHINE_OVERRIDE

 configure | 88 +++++++++++++++++++++++++++----------------------------
 riscv/run |  6 ++--
 2 files changed, 47 insertions(+), 47 deletions(-)
Signature · 1 line
2.48.1
#1 lore raw

PATCH 1/2 configure: Allow earlycon for all architectures

From: Andrew Jones <[email protected]>

earlycon could be used by any architecture so check it outside the arm block and apply it to riscv right away.

---
 configure | 88 +++++++++++++++++++++++++++----------------------------
 1 file changed, 43 insertions(+), 45 deletions(-)
configure +43 -45
index 86cf1da36467..7e462aaf1190 100755
@@ -78,10 +78,9 @@ usage() {
 	                           4k [default], 16k, 64k for arm64.
 	                           4k [default], 64k for ppc64.
 	    --earlycon=EARLYCON
-	                           Specify the UART name, type and address (optional, arm and
-	                           arm64 only). The specified address will overwrite the UART
-	                           address set by the --target option. EARLYCON can be one of
-	                           (case sensitive):
+				   Specify the UART name, type and address (optional).
+	                           The specified address will overwrite the UART address set by
+	                           the --target option. EARLYCON can be one of (case sensitive):
 	               uart[8250],mmio,ADDR
 	                           Specify an 8250 compatible UART at address ADDR. Supported
 	                           register stride is 8 bit only.
@@ -283,6 +282,41 @@ else
     fi
 fi
 
+if [ "$earlycon" ]; then
+    IFS=, read -r name type_addr addr <<<"$earlycon"
+    if [ "$name" != "uart" ] && [ "$name" != "uart8250" ] && [ "$name" != "pl011" ]; then
+        echo "unknown earlycon name: $name"
+        usage
+    fi
+
+    if [ "$name" = "pl011" ]; then
+        if [ -z "$addr" ]; then
+            addr=$type_addr
+        else
+            if [ "$type_addr" != "mmio32" ]; then
+                echo "unknown $name earlycon type: $type_addr"
+                usage
+            fi
+        fi
+    else
+        if [ "$type_addr" != "mmio" ]; then
+            echo "unknown $name earlycon type: $type_addr"
+            usage
+        fi
+    fi
+
+    if [ -z "$addr" ]; then
+        echo "missing $name earlycon address"
+        usage
+    fi
+    if [[ $addr =~ ^0(x|X)[0-9a-fA-F]+$ ]] || [[ $addr =~ ^[0-9]+$ ]]; then
+        uart_early_addr=$addr
+    else
+        echo "invalid $name earlycon address: $addr"
+        usage
+    fi
+fi
+
 [ -z "$processor" ] && processor="$arch"
 
 if [ "$processor" = "arm64" ]; then
@@ -296,51 +330,14 @@ if [ "$arch" = "i386" ] || [ "$arch" = "x86_64" ]; then
 elif [ "$arch" = "arm" ] || [ "$arch" = "arm64" ]; then
     testdir=arm
     if [ "$target" = "qemu" ]; then
-        arm_uart_early_addr=0x09000000
+        : "${uart_early_addr:=0x9000000}"
     elif [ "$target" = "kvmtool" ]; then
-        arm_uart_early_addr=0x1000000
+        : "${uart_early_addr:=0x1000000}"
         errata_force=1
     else
         echo "--target must be one of 'qemu' or 'kvmtool'!"
         usage
     fi
-
-    if [ "$earlycon" ]; then
-        IFS=, read -r name type_addr addr <<<"$earlycon"
-        if [ "$name" != "uart" ] && [ "$name" != "uart8250" ] &&
-                [ "$name" != "pl011" ]; then
-            echo "unknown earlycon name: $name"
-            usage
-        fi
-
-        if [ "$name" = "pl011" ]; then
-            if [ -z "$addr" ]; then
-                addr=$type_addr
-            else
-                if [ "$type_addr" != "mmio32" ]; then
-                    echo "unknown $name earlycon type: $type_addr"
-                    usage
-                fi
-            fi
-        else
-            if [ "$type_addr" != "mmio" ]; then
-                echo "unknown $name earlycon type: $type_addr"
-                usage
-            fi
-        fi
-
-        if [ -z "$addr" ]; then
-            echo "missing $name earlycon address"
-            usage
-        fi
-        if [[ $addr =~ ^0(x|X)[0-9a-fA-F]+$ ]] ||
-                [[ $addr =~ ^[0-9]+$ ]]; then
-            arm_uart_early_addr=$addr
-        else
-            echo "invalid $name earlycon address: $addr"
-            usage
-        fi
-    fi
 elif [ "$arch" = "ppc64" ]; then
     testdir=powerpc
     firmware="$testdir/boot_rom.bin"
@@ -351,6 +348,7 @@ elif [ "$arch" = "ppc64" ]; then
 elif [ "$arch" = "riscv32" ] || [ "$arch" = "riscv64" ]; then
     testdir=riscv
     arch_libdir=riscv
+    : "${uart_early_addr:=0x10000000}"
 elif [ "$arch" = "s390x" ]; then
     testdir=s390x
 else
@@ -491,7 +489,7 @@ EOF
 if [ "$arch" = "arm" ] || [ "$arch" = "arm64" ]; then
 cat <<EOF >> lib/config.h
 
-#define CONFIG_UART_EARLY_BASE ${arm_uart_early_addr}
+#define CONFIG_UART_EARLY_BASE ${uart_early_addr}
 #define CONFIG_ERRATA_FORCE ${errata_force}
 
 EOF
@@ -506,7 +504,7 @@ EOF
 elif [ "$arch" = "riscv32" ] || [ "$arch" = "riscv64" ]; then
 cat <<EOF >> lib/config.h
 
-#define CONFIG_UART_EARLY_BASE 0x10000000
+#define CONFIG_UART_EARLY_BASE ${uart_early_addr}
 
 EOF
 fi
Signature · 1 line
2.48.1
#2 lore raw

Re: [kvm-unit-tests PATCH 1/2] configure: Allow earlycon for all architectures

Quoted 15 lines · Andrew Jones

From: Andrew Jones <[email protected]>

earlycon could be used by any architecture so check it outside the arm block and apply it to riscv right away.

---
 configure | 88 +++++++++++++++++++++++++++----------------------------
 1 file changed, 43 insertions(+), 45 deletions(-)
configure +0 -0
index 86cf1da36467..7e462aaf1190 100755

configure usage() { · line 83

Quoted 10 lines
configure +3 -4
@@ -78,10 +78,9 @@ usage() {
 	                           4k [default], 16k, 64k for arm64.
 	                           4k [default], 64k for ppc64.
 	    --earlycon=EARLYCON
-	                           Specify the UART name, type and address (optional, arm and
-	                           arm64 only). The specified address will overwrite the UART
-	                           address set by the --target option. EARLYCON can be one of
-	                           (case sensitive):
+				   Specify the UART name, type and address (optional).
+	                           The specified address will overwrite the UART address set by
+	                           the --target option. EARLYCON can be one of (case sensitive):

I'll add

                                   (arm/arm64 and riscv32/riscv64 only)

since no other architecture is paying attention to the parameter at this time.

Thanks,
drew

Quoted 128 lines
configure +40 -41
 	               uart[8250],mmio,ADDR
 	                           Specify an 8250 compatible UART at address ADDR. Supported
 	                           register stride is 8 bit only.
@@ -283,6 +282,41 @@ else
     fi
 fi
 
+if [ "$earlycon" ]; then
+    IFS=, read -r name type_addr addr <<<"$earlycon"
+    if [ "$name" != "uart" ] && [ "$name" != "uart8250" ] && [ "$name" != "pl011" ]; then
+        echo "unknown earlycon name: $name"
+        usage
+    fi
+
+    if [ "$name" = "pl011" ]; then
+        if [ -z "$addr" ]; then
+            addr=$type_addr
+        else
+            if [ "$type_addr" != "mmio32" ]; then
+                echo "unknown $name earlycon type: $type_addr"
+                usage
+            fi
+        fi
+    else
+        if [ "$type_addr" != "mmio" ]; then
+            echo "unknown $name earlycon type: $type_addr"
+            usage
+        fi
+    fi
+
+    if [ -z "$addr" ]; then
+        echo "missing $name earlycon address"
+        usage
+    fi
+    if [[ $addr =~ ^0(x|X)[0-9a-fA-F]+$ ]] || [[ $addr =~ ^[0-9]+$ ]]; then
+        uart_early_addr=$addr
+    else
+        echo "invalid $name earlycon address: $addr"
+        usage
+    fi
+fi
+
 [ -z "$processor" ] && processor="$arch"
 
 if [ "$processor" = "arm64" ]; then
@@ -296,51 +330,14 @@ if [ "$arch" = "i386" ] || [ "$arch" = "x86_64" ]; then
 elif [ "$arch" = "arm" ] || [ "$arch" = "arm64" ]; then
     testdir=arm
     if [ "$target" = "qemu" ]; then
-        arm_uart_early_addr=0x09000000
+        : "${uart_early_addr:=0x9000000}"
     elif [ "$target" = "kvmtool" ]; then
-        arm_uart_early_addr=0x1000000
+        : "${uart_early_addr:=0x1000000}"
         errata_force=1
     else
         echo "--target must be one of 'qemu' or 'kvmtool'!"
         usage
     fi
-
-    if [ "$earlycon" ]; then
-        IFS=, read -r name type_addr addr <<<"$earlycon"
-        if [ "$name" != "uart" ] && [ "$name" != "uart8250" ] &&
-                [ "$name" != "pl011" ]; then
-            echo "unknown earlycon name: $name"
-            usage
-        fi
-
-        if [ "$name" = "pl011" ]; then
-            if [ -z "$addr" ]; then
-                addr=$type_addr
-            else
-                if [ "$type_addr" != "mmio32" ]; then
-                    echo "unknown $name earlycon type: $type_addr"
-                    usage
-                fi
-            fi
-        else
-            if [ "$type_addr" != "mmio" ]; then
-                echo "unknown $name earlycon type: $type_addr"
-                usage
-            fi
-        fi
-
-        if [ -z "$addr" ]; then
-            echo "missing $name earlycon address"
-            usage
-        fi
-        if [[ $addr =~ ^0(x|X)[0-9a-fA-F]+$ ]] ||
-                [[ $addr =~ ^[0-9]+$ ]]; then
-            arm_uart_early_addr=$addr
-        else
-            echo "invalid $name earlycon address: $addr"
-            usage
-        fi
-    fi
 elif [ "$arch" = "ppc64" ]; then
     testdir=powerpc
     firmware="$testdir/boot_rom.bin"
@@ -351,6 +348,7 @@ elif [ "$arch" = "ppc64" ]; then
 elif [ "$arch" = "riscv32" ] || [ "$arch" = "riscv64" ]; then
     testdir=riscv
     arch_libdir=riscv
+    : "${uart_early_addr:=0x10000000}"
 elif [ "$arch" = "s390x" ]; then
     testdir=s390x
 else
@@ -491,7 +489,7 @@ EOF
 if [ "$arch" = "arm" ] || [ "$arch" = "arm64" ]; then
 cat <<EOF >> lib/config.h
 
-#define CONFIG_UART_EARLY_BASE ${arm_uart_early_addr}
+#define CONFIG_UART_EARLY_BASE ${uart_early_addr}
 #define CONFIG_ERRATA_FORCE ${errata_force}
 
 EOF
@@ -506,7 +504,7 @@ EOF
 elif [ "$arch" = "riscv32" ] || [ "$arch" = "riscv64" ]; then
 cat <<EOF >> lib/config.h
 
-#define CONFIG_UART_EARLY_BASE 0x10000000
+#define CONFIG_UART_EARLY_BASE ${uart_early_addr}
 
 EOF
 fi
Signature · 1 line
2.48.1
#3 lore raw

PATCH 2/2 riscv: Introduce MACHINE_OVERRIDE

In reply to Andrew Jones

From: Andrew Jones <[email protected]>

Allow riscv tests to use QEMU machine types other than virt.

---
 riscv/run | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
riscv/run +4 -2
index 73f2bf54dc32..e2f5a922728c 100755
@@ -10,10 +10,12 @@ if [ -z "$KUT_STANDALONE" ]; then
 fi
 
 # Allow user overrides of some config.mak variables
+mach=$MACHINE_OVERRIDE
 processor=$PROCESSOR_OVERRIDE
 firmware=$FIRMWARE_OVERRIDE
 
 [ "$PROCESSOR" = "$ARCH" ] && PROCESSOR="max"
+: "${mach:=virt}"
 : "${processor:=$PROCESSOR}"
 : "${firmware:=$FIRMWARE}"
 [ "$firmware" ] && firmware="-bios $firmware"
@@ -23,11 +25,11 @@ set_qemu_accelerator || exit $?
 acc="-accel $ACCEL$ACCEL_PROPS"
 
 qemu=$(search_qemu_binary) || exit $?
-if ! $qemu -machine '?' | grep -q 'RISC-V VirtIO board'; then
+if [ "$mach" = 'virt' ] && ! $qemu -machine '?' | grep -q 'RISC-V VirtIO board'; then
 	echo "$qemu doesn't support mach-virt ('-machine virt'). Exiting."
 	exit 2
 fi
-mach='-machine virt'
+mach="-machine $mach"
 
 command="$qemu -nodefaults -nographic -serial mon:stdio"
 command+=" $mach $acc $firmware -cpu $processor "
Signature · 1 line
2.48.1
#4 lore raw
In reply to Andrew Jones
Quoted 5 lines · Andrew Jones

Provide a couple patches allowing a QEMU machine model other than 'virt' to be used. We just need to be able to override 'virt' in the command line and it's also nice to be able to specify a different UART address for any early (pre DT parsing) outputs.

Quoted 10 lines

Andrew Jones (2):
configure: Allow earlycon for all architectures
riscv: Introduce MACHINE_OVERRIDE

 configure | 88 +++++++++++++++++++++++++++----------------------------
 riscv/run |  6 ++--
 2 files changed, 47 insertions(+), 47 deletions(-)
Signature · 1 line
2.48.1

Merged.

Thanks,
drew