qemu-armv8a/rpserver and rpproxy: support the rpmsg port uart

Use virtio-serial as the rpmsg-port-uart serial device, so we
can bringup the rpmsg-port-uart in qemu platform.

Server command:
qemu-system-aarch64 -cpu cortex-a53 -nographic \
-machine virt,virtualization=on,gic-version=3 \
-chardev stdio,id=con,mux=on -serial chardev:con \
-object memory-backend-file,discard-data=on,id=shmmem-shmem0,mem-path=/dev/shm/my_shmem0,size=4194304,share=yes \
-device ivshmem-plain,id=shmem0,memdev=shmmem-shmem0,addr=0xb \
-device virtio-serial-device,bus=virtio-mmio-bus.0 \
-chardev socket,path=/tmp/rpmsg_port_uart_socket,server=on,wait=off,id=foo \
-device virtconsole,chardev=foo \
-mon chardev=con,mode=readline -kernel ./out/nuttx_qemu-armv8a_rpserver_ivshmem/nuttx \
-gdb tcp::7775

Proxy command:
qemu-system-aarch64 -cpu cortex-a53 -nographic \
-machine virt,virtualization=on,gic-version=3 \
-chardev stdio,id=con,mux=on -serial chardev:con \
-object memory-backend-file,discard-data=on,id=shmmem-shmem0,mem-path=/dev/shm/my_shmem0,size=4194304,share=yes \
-device ivshmem-plain,id=shmem0,memdev=shmmem-shmem0,addr=0xb \
-device virtio-serial-device,bus=virtio-mmio-bus.0 \
-chardev socket,path=/tmp/rpmsg_port_uart_socket,server=off,id=foo \
-device virtconsole,chardev=foo \
-mon chardev=con,mode=readline -kernel ./out/nuttx_qemu-armv8a_rpproxy_ivshmem/nuttx \
-gdb tcp::7776

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
This commit is contained in:
Bowen Wang 2026-01-04 22:44:00 +08:00 committed by Xiang Xiao
parent 4cad404831
commit aa0467057c
4 changed files with 77 additions and 2 deletions

View file

@ -450,7 +450,10 @@ Steps for Using NuttX as IVSHMEM host and guest
$ qemu-system-aarch64 -cpu cortex-a53 -nographic -machine virt,virtualization=on,gic-version=3 -kernel server/nuttx \
-device ivshmem-plain,id=shmem0,memdev=shmmem-shmem0,addr=0xb \
-object memory-backend-file,id=shmmem-shmem0,mem-path=/dev/shm/ivshmem0,size=4194304,share=yes
-object memory-backend-file,id=shmmem-shmem0,mem-path=/dev/shm/ivshmem0,size=4194304,share=yes \
-device virtio-serial-device,bus=virtio-mmio-bus.0 \
-chardev socket,path=/tmp/rpmsg_port_uart_socket,server=on,wait=off,id=foo \
-device virtconsole,chardev=foo
b. Start ``rpproxy_ivshmem``
@ -458,7 +461,10 @@ Steps for Using NuttX as IVSHMEM host and guest
$ qemu-system-aarch64 -cpu cortex-a53 -nographic -machine virt,virtualization=on,gic-version=3 -kernel proxy/nuttx \
-device ivshmem-plain,id=shmem0,memdev=shmmem-shmem0,addr=0xb \
-object memory-backend-file,discard-data=on,id=shmmem-shmem0,mem-path=/dev/shm/ivshmem0,size=4194304,share=yes
-object memory-backend-file,discard-data=on,id=shmmem-shmem0,mem-path=/dev/shm/ivshmem0,size=4194304,share=yes \
-device virtio-serial-device,bus=virtio-mmio-bus.0 \
-chardev socket,path=/tmp/rpmsg_port_uart_socket,server=off,id=foo \
-device virtconsole,chardev=foo
c. Check the RPMSG Syslog in rpserver shell:

View file

@ -33,6 +33,9 @@ CONFIG_DEBUG_SYMBOLS=y
CONFIG_DEFAULT_TASK_STACKSIZE=8192
CONFIG_DEVICE_TREE=y
CONFIG_DEV_SIMPLE_ADDRENV=y
CONFIG_DRIVERS_VIRTIO=y
CONFIG_DRIVERS_VIRTIO_MMIO=y
CONFIG_DRIVERS_VIRTIO_SERIAL=y
CONFIG_EXAMPLES_HELLO=y
CONFIG_EXAMPLES_RPMSGSOCKET=y
CONFIG_EXPERIMENTAL=y
@ -71,11 +74,13 @@ CONFIG_RAW_BINARY=y
CONFIG_READLINE_CMD_HISTORY=y
CONFIG_READLINE_TABCOMPLETION=y
CONFIG_RPMSG_PING=y
CONFIG_RPMSG_PORT_UART=y
CONFIG_RPTUN=y
CONFIG_RPTUN_IVSHMEM=y
CONFIG_RPTUN_IVSHMEM_NAME="0:server:s"
CONFIG_RPTUN_STACKSIZE=8192
CONFIG_SCHED_BACKTRACE=y
CONFIG_SCHED_EVENTS=y
CONFIG_SCHED_HAVE_PARENT=y
CONFIG_SCHED_HPWORK=y
CONFIG_SCHED_HPWORKPRIORITY=192

View file

@ -33,6 +33,9 @@ CONFIG_DEFAULT_TASK_STACKSIZE=8192
CONFIG_DEVICE_TREE=y
CONFIG_DEV_RPMSG=y
CONFIG_DEV_SIMPLE_ADDRENV=y
CONFIG_DRIVERS_VIRTIO=y
CONFIG_DRIVERS_VIRTIO_MMIO=y
CONFIG_DRIVERS_VIRTIO_SERIAL=y
CONFIG_EXAMPLES_HELLO=y
CONFIG_EXAMPLES_RPMSGSOCKET=y
CONFIG_EXPERIMENTAL=y
@ -72,11 +75,13 @@ CONFIG_RAW_BINARY=y
CONFIG_READLINE_CMD_HISTORY=y
CONFIG_READLINE_TABCOMPLETION=y
CONFIG_RPMSG_PING=y
CONFIG_RPMSG_PORT_UART=y
CONFIG_RPTUN=y
CONFIG_RPTUN_IVSHMEM=y
CONFIG_RPTUN_IVSHMEM_NAME="0:proxy:m"
CONFIG_RPTUN_STACKSIZE=8192
CONFIG_SCHED_BACKTRACE=y
CONFIG_SCHED_EVENTS=y
CONFIG_SCHED_HAVE_PARENT=y
CONFIG_SCHED_HPWORK=y
CONFIG_SCHED_HPWORKPRIORITY=192

View file

@ -26,6 +26,7 @@
#include <nuttx/config.h>
#include <string.h>
#include <sys/types.h>
#include <syslog.h>
@ -33,6 +34,7 @@
#include <nuttx/virtio/virtio-mmio.h>
#include <nuttx/fdt.h>
#include <nuttx/pci/pci_ecam.h>
#include <nuttx/rpmsg/rpmsg_port.h>
#ifdef CONFIG_LIBC_FDT
# include <libfdt.h>
@ -178,6 +180,54 @@ static void register_devices_from_fdt(void)
#endif
/****************************************************************************
* Name: rpmsg_port_uart_init
****************************************************************************/
#ifdef CONFIG_RPMSG_PORT_UART
static int rpmsg_port_uart_init(void)
{
const char *remotecpu;
const char *localcpu;
int ret;
if (strcmp(CONFIG_LIBC_HOSTNAME, "server") == 0)
{
localcpu = "server2";
remotecpu = "proxy2";
}
else if (strcmp(CONFIG_LIBC_HOSTNAME, "proxy") == 0)
{
localcpu = "proxy2";
remotecpu = "server2";
}
else
{
syslog(LOG_ERR, "ERROR: hostname must be server or proxy, now: %s\n",
CONFIG_LIBC_HOSTNAME);
return -EINVAL;
}
const struct rpmsg_port_config_s cfg =
{
.remotecpu = remotecpu,
.txnum = 8,
.rxnum = 8,
.txlen = 2048,
.rxlen = 2048,
};
ret = rpmsg_port_uart_initialize(&cfg, "/dev/ttyV0", localcpu);
if (ret < 0)
{
syslog(LOG_ERR,
"ERROR: Failed to initialize rpmsg port uart: %d\n", ret);
}
return ret;
}
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
@ -218,6 +268,15 @@ int qemu_bringup(void)
register_devices_from_fdt();
#endif
#ifdef CONFIG_RPMSG_PORT_UART
ret = rpmsg_port_uart_init();
if (ret < 0)
{
syslog(LOG_ERR,
"ERROR: Failed to initialize rpmsg port uart: %d\n", ret);
}
#endif
UNUSED(ret);
return OK;
}