DistroKit Mailinglist
 help / color / mirror / Atom feed
From: Oleksij Rempel <o.rempel@pengutronix.de>
To: pmamonov@gmail.com, antonynpavlov@gmail.com,
	distrokit@pengutronix.de, rsh@pengutronix.de, mol@pengutronix.de
Cc: Oleksij Rempel <o.rempel@pengutronix.de>
Subject: [DistroKit] [PATCH v1 3/3] platform-mips: add qemu support for malta
Date: Wed,  5 Feb 2020 08:14:53 +0100	[thread overview]
Message-ID: <20200205071453.24804-4-o.rempel@pengutronix.de> (raw)
In-Reply-To: <20200205071453.24804-1-o.rempel@pengutronix.de>

port platform-v7a qemu scripts to MIPS QEMU Malta. Currently it was
tested only with barebox

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 configs/platform-mips/qemu-common |  92 +++++++++++++++++++++++++
 configs/platform-mips/run         | 111 ++++++++++++++++++++++++++++++
 2 files changed, 203 insertions(+)
 create mode 100755 configs/platform-mips/qemu-common
 create mode 100755 configs/platform-mips/run

diff --git a/configs/platform-mips/qemu-common b/configs/platform-mips/qemu-common
new file mode 100755
index 0000000..86e2584
--- /dev/null
+++ b/configs/platform-mips/qemu-common
@@ -0,0 +1,92 @@
+#!/bin/bash
+#
+# This is sourced by the run scripts.
+
+platformconfig=selected_platformconfig
+# fallback to platformconfig in the same dir as this script
+if [ ! -e "$platformconfig" ]; then
+	platformconfig=$(dirname $0)/platformconfig
+fi
+
+#
+# we need information about the platform
+#
+if [ ! -e "$platformconfig" ]; then
+	echo "error: selected_platformconfig does not exist"
+	echo "       please use 'ptxdist platform ...' or 'ptxdist --platformconfig=...'"
+	exit 1
+fi
+
+source $platformconfig
+
+if [ -n "${PTXCONF_PLATFORM}" ]; then
+	PTXDIST_PLATFORMDIR="./platform-${PTXCONF_PLATFORM}"
+else
+	PTXDIST_PLATFORMDIR="."
+fi
+
+if [ ! -e "${PTXDIST_PLATFORMDIR}/images/linuximage" ]; then
+	echo "error: run 'ptxdist go' first"
+	exit 1
+fi
+
+if [ ! -e "${PTXDIST_PLATFORMDIR}/images/hd.img" ]; then
+	echo "error: run 'ptxdist images' first"
+	exit 1
+fi
+
+#if [ ! -e "${PTXDIST_PLATFORMDIR}/images/nor0.img" ]; then
+#	echo "error: run 'ptxdist images' first"
+#	exit 1
+#fi
+
+# the emulator to run
+QEMU_EXEC="${PTXDIST_PLATFORMDIR}/sysroot-host/bin/qemu-system-arm"
+
+if [ ! -e "${QEMU_EXEC}" ]; then
+	echo "error: enable and install 'host-qemu' first"
+	exit 1
+fi
+
+# disable this, if you want to have some graphics output
+QEMU_NOGRAPHIC=-nographic
+
+# Machine to emulate: The default kernel is prepared to run on "versatile pb"
+QEMU_MACHINE=vexpress-a9
+
+#
+# 'user mode' network related settings
+#
+PLATFORM_IP="10.0.2.7"
+
+#
+# *_INTERNAL_PORT: the port a service would connect (in the emulated system)
+# *_EXTERNAL_PORT: port QEMU opens at the host side to give access to the ${*_INTERNAL_PORT}
+#
+TELNET_INTERNAL_PORT=23
+TELNET_EXTERNAL_PORT=20023
+
+HTTP_INTERNAL_PORT=80
+HTTP_EXTERNAL_PORT=20080
+
+if [ -z "${VDE_SOCKET}" ]; then
+	for dir in $(ls -d /var/run/vde2/*.ctl 2>/dev/null); do
+		if [ -r "${dir}" ]; then
+			VDE_SOCKET="${dir}"
+		fi
+	done
+fi
+if [ -n "${VDE_SOCKET}" ]; then
+	if ${QEMU_EXEC} --help | grep -q -- '-net vde'; then
+		QEMU_NET="-net vde,vlan=1,sock=${VDE_SOCKET}"
+	fi
+fi
+if [ -z "${QEMU_NET}" ]; then
+	QEMU_NET="-net user,vlan=1"
+	PLATFORM_IP=""
+fi
+
+QEMU_REDIR=" \
+	-redir tcp:${TELNET_EXTERNAL_PORT}:${PLATFORM_IP}:${TELNET_INTERNAL_PORT} \
+	-redir tcp:${HTTP_EXTERNAL_PORT}:${PLATFORM_IP}:${HTTP_INTERNAL_PORT} \
+"
diff --git a/configs/platform-mips/run b/configs/platform-mips/run
new file mode 100755
index 0000000..c417f04
--- /dev/null
+++ b/configs/platform-mips/run
@@ -0,0 +1,111 @@
+#!/bin/bash
+
+platformconfig=selected_platformconfig
+# fallback to platformconfig in the same dir as this script
+if [ ! -e "$platformconfig" ]; then
+	platformconfig=$(dirname $0)/platformconfig
+fi
+
+#
+# we need information about the platform
+#
+if [ ! -e "$platformconfig" ]; then
+	echo "error: selected_platformconfig does not exist"
+	echo "       please use 'ptxdist platform ...' or 'ptxdist --platformconfig=...'"
+	exit 1
+fi
+
+source $platformconfig
+
+if [ -n "${PTXCONF_PLATFORM}" ]; then
+	PTXDIST_PLATFORMDIR="./platform-${PTXCONF_PLATFORM}"
+else
+	PTXDIST_PLATFORMDIR="."
+fi
+
+if [ ! -e "${PTXDIST_PLATFORMDIR}/images/linuximage" ]; then
+	echo "error: run 'ptxdist go' first"
+	exit 1
+fi
+
+# the emulator to run
+QEMU_EXEC="${PTXDIST_PLATFORMDIR}/sysroot-host/bin/qemu-system-mips"
+
+if [ ! -e "${QEMU_EXEC}" ]; then
+	echo "error: enable and install 'host-qemu' first"
+	exit 1
+fi
+
+# the port a 'telned' would connect to (in the emulated sysem)
+TELNET_INTERNAL_PORT=23
+# port QEMU opens at the host side to give access to the ${TELNET_INTERNAL_PORT}
+TELNET_EXTERNAL_PORT=4444
+
+# dito for ssh
+SSH_INTERNAL_PORT=22
+SSH_EXTERNAL_PORT=4445
+
+# check if vde is available for networking
+if [ -z "${VDE_SOCKET}" ]; then
+	for dir in $(ls -d /var/run/vde2/*.ctl 2>/dev/null); do
+		if [ -r "${dir}" ]; then
+			VDE_SOCKET="${dir}"
+		fi
+	done
+fi
+if [ -n "${VDE_SOCKET}" ]; then
+	# make sure qemu supports vde networking
+	if ${QEMU_EXEC} --help | grep -q -- '-net.*vde'; then
+		QEMU_NET=( -netdev vde,id=net1,sock=${VDE_SOCKET} )
+	fi
+fi
+
+# fall back to user network if necessary
+if [ -z "${QEMU_NET}" ]; then
+	QEMU_NET=(-netdev user,id=net1,hostfwd=tcp:127.0.0.1:${TELNET_EXTERNAL_PORT}-:${TELNET_INTERNAL_PORT},hostfwd=tcp:127.0.0.1:${SSH_EXTERNAL_PORT}-:${SSH_INTERNAL_PORT} )
+fi
+
+BASE_CMDLINE="console=ttyS0,115200 loglevel=5 systemd.log_level=warning systemd.show_status=auto"
+
+# Machine to emulate
+QEMU_ARGS=( -M malta -m 256 -serial stdio -monitor null)
+# disable graphics output
+QEMU_ARGS[${#QEMU_ARGS[@]}]="-nographic"
+# Exit qemu on reboot
+QEMU_ARGS[${#QEMU_ARGS[@]}]="-no-reboot"
+# Configure networking
+QEMU_ARGS=( "${QEMU_ARGS[@]}" -net nic,netdev=net1 "${QEMU_NET[@]}" )
+# Set base time to test NTP and time handling
+QEMU_ARGS=( "${QEMU_ARGS[@]}" -rtc base=2000-01-01 )
+
+QEMU_LINUX_ARGS=( -kernel ${PTXDIST_PLATFORMDIR}/images/linuximage -dtb ${PTXDIST_PLATFORMDIR}/images/malta-v2p-ca9.dtb )
+# the barebox device tree has a state node for bootchooser
+QEMU_BAREBOX_ARGS=( -bios  ${PTXDIST_PLATFORMDIR}/images/barebox-qemu-malta.img )
+
+check_hd() {
+	if [ ! -e "${PTXDIST_PLATFORMDIR}/images/malta.hdimg" ]; then
+		echo "error: malta.hdimg is missing. Run 'ptxdist images' first"
+		exit 1
+	fi
+}
+
+run_qemu_nfs() {
+	exec ${QEMU_EXEC} \
+		"${QEMU_ARGS[@]}" \
+		"${QEMU_EXTRA_ARGS[@]}" \
+		"${QEMU_LINUX_ARGS[@]}" \
+		-append "root=/dev/nfs nfsroot=/root,v3,tcp,port=2049,mountport=2049 ip=dhcp ${BASE_CMDLINE}"
+}
+
+run_qemu_barebox() {
+	check_hd
+	exec ${QEMU_EXEC} \
+		"${QEMU_ARGS[@]}" \
+		"${QEMU_EXTRA_ARGS[@]}" \
+		"${QEMU_BAREBOX_ARGS[@]}"
+}
+
+target="${1:-9p}"
+
+#set -x
+run_qemu_${target}
-- 
2.25.0


_______________________________________________
DistroKit mailing list
DistroKit@pengutronix.de

      parent reply	other threads:[~2020-02-05  7:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-05  7:14 [DistroKit] [PATCH v1 0/3] add MIPS platform support Oleksij Rempel
2020-02-05  7:14 ` [DistroKit] [PATCH v1 1/3] platform-mips: add basic qemu malta support Oleksij Rempel
2020-02-05  9:58   ` Roland Hieber
2020-02-05  7:14 ` [DistroKit] [PATCH v1 2/3] platform-mips: libffi version 3.3 Oleksij Rempel
2020-02-05  8:49   ` Michael Olbrich
2020-02-05  7:14 ` Oleksij Rempel [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200205071453.24804-4-o.rempel@pengutronix.de \
    --to=o.rempel@pengutronix.de \
    --cc=antonynpavlov@gmail.com \
    --cc=distrokit@pengutronix.de \
    --cc=mol@pengutronix.de \
    --cc=pmamonov@gmail.com \
    --cc=rsh@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox