If you run "make run-only" for qemu.mk on a system with a slow X11 connection (for instance, remote X11 over ADSL), then the 1 second delay between starting the xterms and starting QEMU may be insufficient for the xterm to actually start and launch the soc_term to listen on the TCP port. If this happens then QEMU will not start, complaining:
qemu-system-arm: -serial tcp:localhost:54320: Failed to connect socket: Connection refused
qemu: could not connect serial device to character backend 'tcp:localhost:54320'
This can be fixed by waiting for the TCP sockets to have something listening on them instead of just sleeping for a fixed delay.
The following patch will do that (I would just attach it to this issue, but apparently github doesn't let you do that, which seems insane for a bug tracking system):
From ac9391d912bfe429e37e181b8f094f7aaf1a9442 Mon Sep 17 00:00:00 2001
From: Peter Maydell <[email protected]>
Date: Thu, 29 Oct 2015 16:31:52 +0000
Subject: [PATCH] qemu.mk: Wait for terminals to be started before running QEMU
At the moment we start several terminals, and then sleep for a second
before running a QEMU instance which will connect to processes run
in those terminals. This will fail if the terminals are displayed on
a slow remote X11 connection, because the terminals won't have
completed startup before the one second delay elapses.
Replace the delay with a loop that checks whether there's anything
listening on the relevant TCP ports yet.
Signed-off-by: Peter Maydell <[email protected]>
---
qemu.mk | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/qemu.mk b/qemu.mk
index 0593c64..534e65b 100644
--- a/qemu.mk
+++ b/qemu.mk
@@ -196,6 +196,10 @@ define launch-terminal
xterm -title $(2) -e $(BASH) -c "$(SOC_TERM_PATH)/soc_term $(1)" &
endef
+define wait-for-ports
+ @while ! nc -z 127.0.0.1 $(1) || ! nc -z 127.0.0.1 $(2); do sleep 1; done
+endef
+
.PHONY: run
# This target enforces updating root fs etc
run: all
@@ -206,7 +210,7 @@ run-only:
$(call run-help)
$(call launch-terminal,54320,"Normal World")
$(call launch-terminal,54321,"Secure World")
- @sleep 1
+ $(call wait-for-ports,54320,54321)
$(QEMU_PATH)/arm-softmmu/qemu-system-arm \
-nographic \
-serial tcp:localhost:54320 -serial tcp:localhost:54321 \
--
1.9.1