From d0aee0cecb7ab97b8bdecfe3f08a085300419dd7 Mon Sep 17 00:00:00 2001 From: Amneesh Singh Date: Fri, 6 Sep 2024 14:47:45 +0530 Subject: [PATCH 1/4] recipes-demo: xen-oob: init This recipe is a demonstration for how Xen domains operate. It includes a oneshot script which is ran by systemd. It creates a new domain and tries to ping it. When this script is ran by a DomU it will ping Dom0 i.e, the control domain instead. Signed-off-by: Amneesh Singh --- recipes-demos/xen-oob/xen-oob.bb | 45 +++++ .../xen-oob/xen-oob/xen-oob.service.in | 21 +++ recipes-demos/xen-oob/xen-oob/xen-oob.sh | 156 ++++++++++++++++++ 3 files changed, 222 insertions(+) create mode 100644 recipes-demos/xen-oob/xen-oob.bb create mode 100644 recipes-demos/xen-oob/xen-oob/xen-oob.service.in create mode 100644 recipes-demos/xen-oob/xen-oob/xen-oob.sh diff --git a/recipes-demos/xen-oob/xen-oob.bb b/recipes-demos/xen-oob/xen-oob.bb new file mode 100644 index 0000000..ba0d3cc --- /dev/null +++ b/recipes-demos/xen-oob/xen-oob.bb @@ -0,0 +1,45 @@ +SUMMARY = "Out of box demo application for Xen Dom0 and DomU" + +LICENSE = "TI-TFL" +LIC_FILES_CHKSUM = "file://${COREBASE}/../meta-ti/meta-ti-bsp/licenses/TI-TFL;md5=a1b59cb7ba626b9dbbcbf00f3fbc438a" + +PR = "r0" + +SRC_URI = " \ + file://xen-oob.service.in \ + file://xen-oob.sh \ +" + +RDEPENDS:${PN} += "bash net-tools iputils" +SYSTEMD_SERVICE:${PN} = "xen-oob.service" + +inherit systemd + +XEN_NET_BRIDGE ??= "xenbr0" +XEN_DOMU_IFACE ??= "enX0" +XEN_BOOT_DOM0LESS ??= "" +DOM0_IP ??= "192.168.44.1" +DOMU_IP ??= "192.168.44.2" +RAMDISK_PATH ??= "${@'\/boot\/${XEN_RAMFS_IMAGE}-${MACHINE}.rootfs.cpio' if d.getVar('XEN_RAMFS_IMAGE') else '' }" + +do_install() { + sed -e 's/@@XEN_NET_BRIDGE@@/${XEN_NET_BRIDGE}/' \ + -e 's/@@XEN_DOMU_IFACE@@/${XEN_DOMU_IFACE}/' \ + -e 's/@@XEN_BOOT_DOM0LESS@@/${XEN_BOOT_DOM0LESS}/' \ + -e 's/@@RAMDISK_PATH@@/${RAMDISK_PATH}/' \ + -e 's/@@DOM0_IP@@/${DOM0_IP}/' \ + -e 's/@@DOMU_IP@@/${DOMU_IP}/' \ + "${WORKDIR}/xen-oob.service.in" > "${WORKDIR}/xen-oob.service" + + # Install the service + install -d ${D}${systemd_system_unitdir} + install -m 0755 ${WORKDIR}/xen-oob.service ${D}${systemd_system_unitdir} + + # Install the oneshot script + install -d ${D}${datadir}/demo + install -m 0755 ${WORKDIR}/xen-oob.sh ${D}${datadir}/demo +} + +FILES:${PN} += " \ + ${datadir}/demo \ +" diff --git a/recipes-demos/xen-oob/xen-oob/xen-oob.service.in b/recipes-demos/xen-oob/xen-oob/xen-oob.service.in new file mode 100644 index 0000000..59f0580 --- /dev/null +++ b/recipes-demos/xen-oob/xen-oob/xen-oob.service.in @@ -0,0 +1,21 @@ +# This is a unit for spawning an OOB Xen DomU and pinging it + +[Unit] +Description=Xen OOB +After=systemd-logind.service +Wants=systemd-logind.service + +[Service] +Type=oneshot +ExecStart=/usr/share/demo/xen-oob.sh +StandardOutput=append:/var/log/xen-oob.log +StandardError=append:/var/log/xen-oob.error.log +Environment="XEN_NET_BRIDGE=@@XEN_NET_BRIDGE@@" +Environment="XEN_DOMU_IFACE=@@XEN_DOMU_IFACE@@" +Environment="XEN_BOOT_DOM0LESS=@@XEN_BOOT_DOM0LESS@@" +Environment="RAMDISK_PATH=@@RAMDISK_PATH@@" +Environment="DOM0_IP=@@DOM0_IP@@" +Environment="DOMU_IP=@@DOMU_IP@@" + +[Install] +WantedBy=multi-user.target diff --git a/recipes-demos/xen-oob/xen-oob/xen-oob.sh b/recipes-demos/xen-oob/xen-oob/xen-oob.sh new file mode 100644 index 0000000..8df0bb5 --- /dev/null +++ b/recipes-demos/xen-oob/xen-oob/xen-oob.sh @@ -0,0 +1,156 @@ +#!/usr/bin/env bash + +XEN_NET_BRIDGE="${XEN_NET_BRIDGE:-xenbr0}" +XEN_DOMU_IFACE="${XEN_DOMU_IFACE:-enX0}" +RAMDISK_PATH="${RAMDISK_PATH:-/boot/initramfs.cpio}" + +DOM0_IP="${DOM0_IP:-192.168.44.1}" +DOMU_IP="${DOMU_IP:-192.168.44.2}" + +DOM0LESS="${XEN_BOOT_DOM0LESS}" +INIT_DOM0LESS="${INIT_DOM0LESS:-/usr/lib/xen/bin/init-dom0less}" + +is_dom0() { + local cap_file=/proc/xen/capabilities + local dom0_str=control_d + + [ -f ${cap_file} ] && grep -q "${dom0_str}" ${cap_file} +} + +create_bridge() { + brctl addbr ${XEN_NET_BRIDGE} + ifconfig ${XEN_NET_BRIDGE} ${DOM0_IP} +} + +spawn_domU() { + # interfaces with pattern veth* are ignored by systemd-networkd + local vifname=veth-demo + local config=$(mktemp) + + cat >${config} </dev/null 2>&1; do + tries=$((tries + 1)) + + if [ $tries -eq 5 ]; then + return 1 + fi + + echo "could not detect the interface ${XEN_DOMU_IFACE}, wait - 5s" + sleep 5 + done + + return 0 +} + +check_conn_with_other_vm() { + local tries=0 + local ip=$1 + + # wait for the domain to boot + echo "waiting for VM with ip ${ip} to boot up - 5s" + sleep 5 + + # check if the other domain's interface is pingable + while ! ping -w 1 -c 1 ${ip} >/dev/null 2>&1; do + tries=$((tries + 1)) + + if [ $tries -eq 5 ]; then + return 1 + fi + + echo "could not connect to VM with ip ${ip}, wait - 5s" + sleep 5 + done + + return 0 +} + +ping_n_times() { + local n=$1 + local ip=$2 + + # test connection by pinging n times + for ping in $(eval echo {1..$n}); do + if ping -w 1 -c 1 $ip >/dev/null; then + echo "ping $ping to $ip successful" + else + echo "ping $ping to $ip unsuccessful" + fi + done +} + +# dom0 +if is_dom0; then + # create bridge + if ! create_bridge; then + echo "failed to create bridge ${XEN_NET_BRIDGE}" + exit 1 + fi + + # if not dom0less + if [ -z "$DOM0LESS" ]; then + # spawn domU + if ! spawn_domU; then + echo "failed to spawn domU" + exit 1 + fi + + elif ! init_dom0less; then + echo "failed to initialize xenstore for dom0less domU" + exit 1 + fi + + # check if domU is up or not + if ! check_conn_with_other_vm ${DOMU_IP}; then + echo "failed to establish connection with domU" + exit 1 + fi + + echo "pinging domU 10 times" + ping_n_times 10 ${DOMU_IP} + +# domU +else + # check if the interface is up yet or not + if [ -n "${DOM0LESS}" ] && ! dom0less_wait_domu_iface; then + echo "failed to detect the interface ${XEN_DOMU_IFACE}" + exit 1 + fi + + # assign an ip to the interface + ifconfig ${XEN_DOMU_IFACE} ${DOMU_IP} + + # check if the dom0 is up or not + if [ -n "${DOM0LESS}" ] && ! check_conn_with_other_vm ${DOM0_IP}; then + echo "failed to establish connection with dom0" + exit 1 + fi + + echo "pinging dom0 10 times" + ping_n_times 10 ${DOM0_IP} +fi From 3690d836db687e5325a50b5faed6a624324411c3 Mon Sep 17 00:00:00 2001 From: Amneesh Singh Date: Fri, 6 Sep 2024 14:58:18 +0530 Subject: [PATCH 2/4] recipes-core: images: add arago xen image bbappends - tisdk-xen-domu: This is an initramfs based image. This bbappend adds the xen-oob package to the DomU for demonstration purposes. - tisdk-xen-image: This is the base image containing xen and xen-tools, this bbappend adds the xen-oob package as well as installs tisdk-xen-domu as a cpio under /boot so that DomU can use it as root. Signed-off-by: Amneesh Singh --- recipes-core/images/tisdk-xen-domu.bbappend | 3 +++ recipes-core/images/tisdk-xen-image.bbappend | 22 ++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 recipes-core/images/tisdk-xen-domu.bbappend create mode 100644 recipes-core/images/tisdk-xen-image.bbappend diff --git a/recipes-core/images/tisdk-xen-domu.bbappend b/recipes-core/images/tisdk-xen-domu.bbappend new file mode 100644 index 0000000..bf95d79 --- /dev/null +++ b/recipes-core/images/tisdk-xen-domu.bbappend @@ -0,0 +1,3 @@ +PR:append = "_tisdk_0" + +PACKAGE_INSTALL += "xen-oob" diff --git a/recipes-core/images/tisdk-xen-image.bbappend b/recipes-core/images/tisdk-xen-image.bbappend new file mode 100644 index 0000000..04a628c --- /dev/null +++ b/recipes-core/images/tisdk-xen-image.bbappend @@ -0,0 +1,22 @@ +PR:append = "_tisdk_0" + +IMAGE_INSTALL:append = " xen-oob u-boot-xen-scr" +IMAGE_BOOT_FILES:append = " boot.xen.scr;boot.scr" + +ROOTFS_POSTINSTALL_COMMAND:append = "install_ramdisk; " +install_ramdisk () { + # Install the ramdisk which domu will use as root + if [ -n "${XEN_RAMFS_IMAGE}" ]; then + if [ -f ${DEPLOY_DIR_IMAGE}/${XEN_RAMFS_IMAGE}*-${MACHINE}.rootfs.cpio ]; then + install -m 0644 ${DEPLOY_DIR_IMAGE}/${XEN_RAMFS_IMAGE}*-${MACHINE}.rootfs.cpio ${IMAGE_ROOTFS}/boot + else + bberror "Could not find XEN_RAMFS_IMAGE (${XEN_RAMFS_IMAGE}*-${MACHINE}.rootfs.cpio)!" + bberror "Please make sure that \"cpio\" is in IMAGE_FSTYPES." + fi + fi +} + +python __anonymous () { + if d.getVar('XEN_RAMFS_IMAGE', True): + d.appendVarFlag('do_rootfs', 'depends', ' ${XEN_RAMFS_IMAGE}:do_image_complete') +} From a235ef3da57e9dc11b19c9bc8d86de611bb3dea4 Mon Sep 17 00:00:00 2001 From: Amneesh Singh Date: Fri, 6 Sep 2024 14:59:50 +0530 Subject: [PATCH 3/4] recipes-kernel: linux: add support for Xen This patch adds support to enable Xen for ti-linux-staging. This involves a kernel fragment specifying desired defconfig options as well as two patches: fix-rpmsg-xen.patch: This patch fixes the rpmsg_probe failure that happens otherwise. drivers-...-protocol.patch: This patch [1] is required for compatibility with a patchset [2] for xen which fixes init-dom0less and hotplugging for dom0less domains. [1]: https://lore.kernel.org/xen-devel/20240517011516.1451087-1-xin.wang2@amd.com/ [2]: https://lore.kernel.org/all/alpine.DEB.2.22.394.2405241552240.2557291@ubuntu-linux-20-04-desktop/ Signed-off-by: Amneesh Singh --- recipes-kernel/linux/linux-ti-enable-xen.inc | 9 ++ .../linux/linux-ti-staging-rt_%.bbappend | 2 + .../linux/linux-ti-staging_%.bbappend | 3 +- ...rove-the-late-xenstore-init-protocol.patch | 116 ++++++++++++++++++ recipes-kernel/linux/xen/fix-rpmsg-xen.patch | 13 ++ recipes-kernel/linux/xen/xen.cfg | 55 +++++++++ 6 files changed, 197 insertions(+), 1 deletion(-) create mode 100644 recipes-kernel/linux/linux-ti-enable-xen.inc create mode 100644 recipes-kernel/linux/xen/drivers-xen-improve-the-late-xenstore-init-protocol.patch create mode 100644 recipes-kernel/linux/xen/fix-rpmsg-xen.patch create mode 100644 recipes-kernel/linux/xen/xen.cfg diff --git a/recipes-kernel/linux/linux-ti-enable-xen.inc b/recipes-kernel/linux/linux-ti-enable-xen.inc new file mode 100644 index 0000000..130c7cc --- /dev/null +++ b/recipes-kernel/linux/linux-ti-enable-xen.inc @@ -0,0 +1,9 @@ +FILESEXTRAPATHS:prepend := "${THISDIR}/xen:" + +SRC_URI:append = " \ + file://drivers-xen-improve-the-late-xenstore-init-protocol.patch \ + file://fix-rpmsg-xen.patch \ + file://xen.cfg \ + " + +KERNEL_CONFIG_FRAGMENTS:append = " ${WORKDIR}/xen.cfg" diff --git a/recipes-kernel/linux/linux-ti-staging-rt_%.bbappend b/recipes-kernel/linux/linux-ti-staging-rt_%.bbappend index 7292b6b..e59ca1a 100644 --- a/recipes-kernel/linux/linux-ti-staging-rt_%.bbappend +++ b/recipes-kernel/linux/linux-ti-staging-rt_%.bbappend @@ -1,4 +1,6 @@ SRCREV:tie-jailhouse = "782a2e18a2af099d5c53bc4ba9f59d24a0ce8467" +include ${@bb.utils.contains('DISTRO_FEATURES', 'xen', 'linux-ti-enable-xen.inc', '', d)} + PR:append = "_tisdk_8" diff --git a/recipes-kernel/linux/linux-ti-staging_%.bbappend b/recipes-kernel/linux/linux-ti-staging_%.bbappend index 0811832..9cdf7be 100644 --- a/recipes-kernel/linux/linux-ti-staging_%.bbappend +++ b/recipes-kernel/linux/linux-ti-staging_%.bbappend @@ -1,4 +1,5 @@ SRCREV:tie-jailhouse = "c76373e447c96b32fe08beceef7a499d16eaed96" -PR:append = "_tisdk_5" +include ${@bb.utils.contains('DISTRO_FEATURES', 'xen', 'linux-ti-enable-xen.inc', '', d)} +PR:append = "_tisdk_5" diff --git a/recipes-kernel/linux/xen/drivers-xen-improve-the-late-xenstore-init-protocol.patch b/recipes-kernel/linux/xen/drivers-xen-improve-the-late-xenstore-init-protocol.patch new file mode 100644 index 0000000..a3196d0 --- /dev/null +++ b/recipes-kernel/linux/xen/drivers-xen-improve-the-late-xenstore-init-protocol.patch @@ -0,0 +1,116 @@ +Subject: [PATCH v2] drivers/xen: Improve the late XenStore init + +Currently, the late XenStore init protocol is only triggered properly +for the case that HVM_PARAM_STORE_PFN is ~0ULL (invalid). For the +case that XenStore interface is allocated but not ready (the connection +status is not XENSTORE_CONNECTED), Linux should also wait until the +XenStore is set up properly. + +Introduce a macro to describe the XenStore interface is ready, use +it in xenbus_probe_initcall() to select the code path of doing the +late XenStore init protocol or not. Since now we have more than one +condition for XenStore late init, rework the check in xenbus_probe() +for the free_irq(). + +Take the opportunity to enhance the check of the allocated XenStore +interface can be properly mapped, and return error early if the +memremap() fails. + +Fixes: 5b3353949e89 ("xen: add support for initializing xenstore later as HVM domain") +Signed-off-by: Henry Wang +Signed-off-by: Michal Orzel +--- +v2: +- Use -EINVAL for the memremap() check. (Stefano) +- Add Fixes: tag. (Stefano) +- Rework the condition for free_irq() in xenbus_probe(). (Stefano) +--- + drivers/xen/xenbus/xenbus_probe.c | 36 ++++++++++++++++++++----------- + 1 file changed, 23 insertions(+), 13 deletions(-) + +diff --git a/drivers/xen/xenbus/xenbus_probe.c b/drivers/xen/xenbus/xenbus_probe.c +index 3205e5d724c8..1a9ded0cddcb 100644 +--- a/drivers/xen/xenbus/xenbus_probe.c ++++ b/drivers/xen/xenbus/xenbus_probe.c +@@ -65,13 +65,17 @@ + #include "xenbus.h" + + +-static int xs_init_irq; ++static int xs_init_irq = -1; + int xen_store_evtchn; + EXPORT_SYMBOL_GPL(xen_store_evtchn); + + struct xenstore_domain_interface *xen_store_interface; + EXPORT_SYMBOL_GPL(xen_store_interface); + ++#define XS_INTERFACE_READY \ ++ ((xen_store_interface != NULL) && \ ++ (xen_store_interface->connection == XENSTORE_CONNECTED)) ++ + enum xenstore_init xen_store_domain_type; + EXPORT_SYMBOL_GPL(xen_store_domain_type); + +@@ -751,19 +755,19 @@ static void xenbus_probe(void) + { + xenstored_ready = 1; + +- if (!xen_store_interface) { ++ if (!xen_store_interface) + xen_store_interface = memremap(xen_store_gfn << XEN_PAGE_SHIFT, + XEN_PAGE_SIZE, MEMREMAP_WB); +- /* +- * Now it is safe to free the IRQ used for xenstore late +- * initialization. No need to unbind: it is about to be +- * bound again from xb_init_comms. Note that calling +- * unbind_from_irqhandler now would result in xen_evtchn_close() +- * being called and the event channel not being enabled again +- * afterwards, resulting in missed event notifications. +- */ ++ /* ++ * Now it is safe to free the IRQ used for xenstore late ++ * initialization. No need to unbind: it is about to be ++ * bound again from xb_init_comms. Note that calling ++ * unbind_from_irqhandler now would result in xen_evtchn_close() ++ * being called and the event channel not being enabled again ++ * afterwards, resulting in missed event notifications. ++ */ ++ if (xs_init_irq >= 0) + free_irq(xs_init_irq, &xb_waitq); +- } + + /* + * In the HVM case, xenbus_init() deferred its call to +@@ -822,7 +826,7 @@ static int __init xenbus_probe_initcall(void) + if (xen_store_domain_type == XS_PV || + (xen_store_domain_type == XS_HVM && + !xs_hvm_defer_init_for_callback() && +- xen_store_interface != NULL)) ++ XS_INTERFACE_READY)) + xenbus_probe(); + + /* +@@ -831,7 +835,7 @@ static int __init xenbus_probe_initcall(void) + * started, then probe. It will be triggered when communication + * starts happening, by waiting on xb_waitq. + */ +- if (xen_store_domain_type == XS_LOCAL || xen_store_interface == NULL) { ++ if (xen_store_domain_type == XS_LOCAL || !XS_INTERFACE_READY) { + struct task_struct *probe_task; + + probe_task = kthread_run(xenbus_probe_thread, NULL, +@@ -1014,6 +1018,12 @@ static int __init xenbus_init(void) + xen_store_interface = + memremap(xen_store_gfn << XEN_PAGE_SHIFT, + XEN_PAGE_SIZE, MEMREMAP_WB); ++ if (!xen_store_interface) { ++ pr_err("%s: cannot map HVM_PARAM_STORE_PFN=%llx\n", ++ __func__, v); ++ err = -EINVAL; ++ goto out_error; ++ } + if (xen_store_interface->connection != XENSTORE_CONNECTED) + wait = true; + } +-- +2.34.1 diff --git a/recipes-kernel/linux/xen/fix-rpmsg-xen.patch b/recipes-kernel/linux/xen/fix-rpmsg-xen.patch new file mode 100644 index 0000000..e7aefca --- /dev/null +++ b/recipes-kernel/linux/xen/fix-rpmsg-xen.patch @@ -0,0 +1,13 @@ +diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c +index 7d320f799ca1..96ba831cf73f 100644 +--- a/drivers/virtio/virtio_ring.c ++++ b/drivers/virtio/virtio_ring.c +@@ -279,7 +279,7 @@ static bool vring_use_dma_api(struct virtio_device *vdev) + * the DMA API if we're a Xen guest, which at least allows + * all of the sensible Xen configurations to work correctly. + */ +- if (xen_domain()) ++ if (xen_pv_domain()) + return true; + + return false; diff --git a/recipes-kernel/linux/xen/xen.cfg b/recipes-kernel/linux/xen/xen.cfg new file mode 100644 index 0000000..00bb14a --- /dev/null +++ b/recipes-kernel/linux/xen/xen.cfg @@ -0,0 +1,55 @@ +# +# Xen Options +# +CONFIG_XEN=y +CONFIG_XEN_DOM0=y +CONFIG_MMU_NOTIFIER=y +CONFIG_HIBERNATE_CALLBACKS=y +CONFIG_SYS_HYPERVISOR=y +CONFIG_XEN_BLKDEV_FRONTEND=y +CONFIG_XEN_BLKDEV_BACKEND=y +CONFIG_XEN_SCSI_FRONTEND=y +CONFIG_XEN_NETDEV_FRONTEND=y +CONFIG_XEN_NETDEV_BACKEND=y +CONFIG_INPUT_MISC=y +CONFIG_INPUT_XEN_KBDDEV_FRONTEND=y +CONFIG_HVC_IRQ=y +CONFIG_HVC_XEN=y +CONFIG_HVC_XEN_FRONTEND=y +CONFIG_XEN_WDT=m +CONFIG_FB_SYS_FILLRECT=y +CONFIG_FB_SYS_COPYAREA=y +CONFIG_FB_SYS_IMAGEBLIT=y +CONFIG_FB_SYS_FOPS=y +CONFIG_FB_DEFERRED_IO=y +CONFIG_XEN_FBDEV_FRONTEND=y +CONFIG_XEN_BALLOON=y +CONFIG_XEN_BALLOON_MEMORY_HOTPLUG=y +CONFIG_XEN_SCRUB_PAGES_DEFAULT=y +CONFIG_XEN_DEV_EVTCHN=y +CONFIG_XEN_BACKEND=y +CONFIG_XENFS=y +CONFIG_XEN_COMPAT_XENFS=y +CONFIG_XEN_SYS_HYPERVISOR=y +CONFIG_XEN_XENBUS_FRONTEND=y +CONFIG_XEN_GNTDEV=y +CONFIG_XEN_GNTDEV_DMABUF=y +CONFIG_XEN_GRANT_DEV_ALLOC=y +CONFIG_XEN_GRANT_DMA_ALLOC=y +CONFIG_SWIOTLB_XEN=y +CONFIG_XEN_PRIVCMD=y +CONFIG_DRM_XEN=y +CONFIG_DRM_XEN_FRONTEND=y + +# +# PL011 support +# +CONFIG_SERIAL_AMBA_PL011=y +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y + +# +# Userspace IO Options +# +CONFIG_UIO=y +CONFIG_UIO_CIF=y +CONFIG_UIO_PDRV_GENIRQ=y From 558a1a31610fdcc1d7da9a701e2db0d800f63272 Mon Sep 17 00:00:00 2001 From: Amneesh Singh Date: Fri, 6 Sep 2024 15:08:49 +0530 Subject: [PATCH 4/4] recipes-bsp: u-boot: add mechanism to boot xen This patch provides a custom CONFIG_BOOTCOMMAND when user has enabled xen under DISTRO_FEATURES. This bootcommand runs a script from boot partition, which is boot.scr by default. The script is also provided and is compiled using mkimage as a FIT image. This script loads the Xen image, the kernel image and the FDT and then modifies the FDT to allow suitable Xen configuration and other features like shared memory and UIO. Signed-off-by: Amneesh Singh --- recipes-bsp/u-boot-xen-scr/files/boot.xen.its | 19 +++ .../u-boot-xen-scr/files/boot.xen.source.in | 155 ++++++++++++++++++ recipes-bsp/u-boot-xen-scr/u-boot-xen-scr.bb | 66 ++++++++ recipes-bsp/u-boot/files/bootmethscript.cfg | 1 + .../u-boot/u-boot-ti-staging_%.bbappend | 8 +- 5 files changed, 248 insertions(+), 1 deletion(-) create mode 100644 recipes-bsp/u-boot-xen-scr/files/boot.xen.its create mode 100644 recipes-bsp/u-boot-xen-scr/files/boot.xen.source.in create mode 100644 recipes-bsp/u-boot-xen-scr/u-boot-xen-scr.bb create mode 100644 recipes-bsp/u-boot/files/bootmethscript.cfg diff --git a/recipes-bsp/u-boot-xen-scr/files/boot.xen.its b/recipes-bsp/u-boot-xen-scr/files/boot.xen.its new file mode 100644 index 0000000..78a38a0 --- /dev/null +++ b/recipes-bsp/u-boot-xen-scr/files/boot.xen.its @@ -0,0 +1,19 @@ +/dts-v1/; +/ { + description = "Configuration to load Xen/Linux"; + #address-cells = <1>; + images { + default = "boot_scr"; + boot_scr { + description = "default xen boot script"; + data = /incbin/("boot.xen.source"); + type = "script"; + compression = "none"; + load = <0x82000000>; + entry = <0x82000000>; + hash { + algo = "md5"; + }; + }; + }; +}; diff --git a/recipes-bsp/u-boot-xen-scr/files/boot.xen.source.in b/recipes-bsp/u-boot-xen-scr/files/boot.xen.source.in new file mode 100644 index 0000000..31c62a9 --- /dev/null +++ b/recipes-bsp/u-boot-xen-scr/files/boot.xen.source.in @@ -0,0 +1,155 @@ +xen_name=@@XEN_IMAGE_NAME@@ +kernel_name=@@XEN_KERNEL_IMAGE_NAME@@ +ramdisk_name=@@XEN_RAMDISK_NAME@@ + +xen_addr=@@XEN_ADDRESS@@ +kernel_addr=@@XEN_KERNEL_ADDRESS@@ +ramdisk_addr=@@XEN_RAMDISK_ADDRESS@@ + +dom0less=@@XEN_BOOT_DOM0LESS@@ + +setenv fdtaddr @@XEN_FDT_ADDRESS@@ + +for boot_target in ${boot_targets}; +do + # only support searching mmc for now and break if kernel is scanned + if test -z "${kernel_size}" && test "${boot_target}" = "mmc0" || test "${boot_target}" = "mmc1"; then + setenv devtype mmc + setenv bootdir /boot + setenv dtbdir ${bootdir}/dtb + + if test "${boot_target}" = "mmc0"; then + setenv devnum 0 + elif test "${boot_target}" = "mmc1"; then + setenv devnum 1 + fi + + setenv loadboot ${devtype} ${devnum}:1 + setenv loadroot ${devtype} ${devnum}:2 + + # check xen image in boot partition then root partition + if test -e ${loadboot} ${xen_name}; then + echo "Loading ${xen_name}"; + fatload ${loadboot} ${xen_addr} ${xen_name}; + elif test -e ${loadroot} ${bootdir}/${xen_name}; then + echo "Loading ${xen_name}"; + load ${loadroot} ${xen_addr} ${bootdir}/${xen_name}; + fi + + # check kernel image in boot partition then root partition + if test -e ${loadboot} ${kernel_name}; then + echo "Loading ${kernel_name}"; + fatload ${loadboot} ${kernel_addr} ${kernel_name}; + setenv kernel_size 0x$filesize; + elif test -e ${loadroot} ${bootdir}/$kernel_name}; then + echo "Loading ${kernel_name}"; + load ${loadroot} ${kernel_addr} ${bootdir}/${kernel_name}; + setenv kernel_size 0x$filesize; + fi + + # load fdt from root partition + if test -e ${loadroot} ${dtbdir}/${fdtfile}; then + echo "Loading ${dtbdir}/${fdtfile}"; + load ${loadroot} ${fdtaddr} ${dtbdir}/${fdtfile}; + part uuid ${loadroot} rootfs_partuuid + fi + + # load ramdisk for DomU from root partition + if test -n "${dom0less}" && test -e ${loadroot} ${bootdir}/${ramdisk_name}; then + echo "Loading ${bootdir}/${ramdisk_name}"; + load ${loadroot} ${ramdisk_addr} ${bootdir}/${ramdisk_name}; + setenv ramdisk_size 0x$filesize; + fi + fi +done + +if test -z "${kernel_size}"; then + echo "No kernel image found" + exit +fi + +fdt addr ${fdtaddr} +fdt resize 1024 + +# fdt operations +fdt set /chosen \#address-cells <0x2> +fdt set /chosen \#size-cells <0x2> +setenv xen_bootargs "console=dtuart dtuart=@@XEN_DTUART_SERIAL@@ dom0_mem=@@DOM0_MEM@@ dom0_max_vcpus=@@DOM0_MAX_VCPUS@@" +fdt set /chosen xen,xen-bootargs \"${xen_bootargs}\" + +# dom0 +fdt mknod /chosen dom0 +fdt set /chosen/dom0 compatible "xen,linux-zimage" "xen,multiboot-module" "multiboot,module" +fdt set /chosen/dom0 reg <0x0 ${kernel_addr} 0x0 ${kernel_size}> +setenv dom0_bootargs "console=hvc0 earlyprintk=xen root=PARTUUID=${rootfs_partuuid} rw rootfstype=ext4 rootwait clk_ignore_unused" + +# domU +echo outside +if test -n "${dom0less}" && test -n "${ramdisk_size}"; then + setexpr kernel_addr_u ${kernel_addr} + 0x03000000 + setenv kernel_addr_u "0x${kernel_addr_u}" + cp.b ${kernel_addr} ${kernel_addr_u} ${kernel_size} + fdt mknod /chosen domU + fdt set /chosen/domU compatible "xen,domain" + fdt set /chosen/domU xen,enhanced "enabled" + fdt set /chosen/domU \#address-cells <0x2> + fdt set /chosen/domU \#size-cells <0x2> + fdt set /chosen/domU memory <0 1048576> + fdt set /chosen/domU cpus <4> + fdt set /chosen/domU vpl011 + fdt mknod /chosen/domU module${kernel_addr_u} + fdt set /chosen/domU/module${kernel_addr_u} compatible "multiboot,kernel" "multiboot,module" + fdt set /chosen/domU/module${kernel_addr_u} reg <0x0 ${kernel_addr_u} 0x0 ${kernel_size} > + fdt set /chosen/domU/module${kernel_addr_u} bootargs "console=ttyAMA0" + fdt mknod /chosen/domU module${ramdisk_addr} + fdt set /chosen/domU/module${ramdisk_addr} compatible "multiboot,ramdisk" "multiboot,module" + fdt set /chosen/domU/module${ramdisk_addr} reg <0x0 ${ramdisk_addr} 0x0 ${ramdisk_size} > +fi + +# shared memory +if test -n "@@XEN_SHMEM_START@@"; then + shmem_start=@@XEN_SHMEM_START@@ + shmem_size=@@XEN_SHMEM_SIZE@@ + shmem_node=xen_shmem@@@XEN_SHMEM_START@@ + uio_node=xen_uio@@@XEN_SHMEM_START@@ + + # mark it as shared + fdt mknod /reserved-memory ${shmem_node} + fdt set /reserved-memory/${shmem_node} compatible "xen,shared-memory-v1" + fdt set /reserved-memory/${shmem_node} reg <0x00 ${shmem_start} 0x00 ${shmem_size}> + + # expose as UIO to Dom0 + fdt mknod / ${uio_node} + fdt set /${uio_node} compatible @@XEN_SHMEM_UIO_NAME@@ + fdt set /${uio_node} reg <0x00 ${shmem_start} 0x00 ${shmem_size}> + + # append uio to bootargs + setenv dom0_bootargs "${dom0_bootargs} uio_pdrv_genirq.of_id=@@XEN_SHMEM_UIO_NAME@@" +fi + +fdt set /chosen xen,dom0-bootargs \"${dom0_bootargs}\" + +fdt print /chosen + +# Specify interrupts explicitly for the following instead of relying on ti,interrupt-ranges +for dev_path in @@XEN_IRQ_DEVICES@@; do + fdt get value irq_cur ${dev_path} ti,interrupt-ranges 0 + fdt get value irq_num ${dev_path} ti,interrupt-ranges 2 + + setexpr irq_cur ${irq_cur} + 0x20 + setexpr irq_end ${irq_cur} + ${irq_num} + setenv irq_prop "<" + + while itest ${irq_cur} < ${irq_end}; do + setenv irq_prop "${irq_prop}0 0x${irq_cur} 4 " + setexpr irq_cur ${irq_cur} + 1 + done + + setenv irq_prop "${irq_prop}>" + fdt set ${dev_path} interrupts ${irq_prop} +done + +setenv fdt_high 0xffffffffffffffff +echo "Booting" + +booti ${xen_addr} - ${fdtaddr} diff --git a/recipes-bsp/u-boot-xen-scr/u-boot-xen-scr.bb b/recipes-bsp/u-boot-xen-scr/u-boot-xen-scr.bb new file mode 100644 index 0000000..084c243 --- /dev/null +++ b/recipes-bsp/u-boot-xen-scr/u-boot-xen-scr.bb @@ -0,0 +1,66 @@ +SUMMARY = "U-Boot script to boot Xen" + +LICENSE = "TI-TFL" +LIC_FILES_CHKSUM = "file://${COREBASE}/../meta-ti/meta-ti-bsp/licenses/TI-TFL;md5=a1b59cb7ba626b9dbbcbf00f3fbc438a" + +PR = "r0" + +SRC_URI = " \ + file://boot.xen.source.in \ + file://boot.xen.its \ +" + +DEPENDS = "u-boot-mkimage-native dtc-native" + +XEN_IMAGE_NAME ??= "xen" +XEN_KERNEL_IMAGE_NAME ??= "Image" +XEN_RAMDISK_NAME ??= "${XEN_RAMFS_IMAGE}-${MACHINE}.rootfs.cpio" +XEN_FDT_ADDRESS ??= "0x80400000" +XEN_ADDRESS ??= "0x81000000" +XEN_KERNEL_ADDRESS ??= "0x83000000" +XEN_RAMDISK_ADDRESS ??= "0x89000000" +XEN_BOOT_DOM0LESS ??= "" +DOM0_MEM ??= "1G" +DOM0_MAX_VCPUS ??= "1" +XEN_SHMEM_UIO_NAME ??= "xen-uio" +XEN_SHMEM_START ??= "0x80400000" +XEN_SHMEM_SIZE ??= "0x1000" + +XEN_DTUART_SERIAL ??= "" +XEN_DTUART_SERIAL:am62xx ??= "serial2" +XEN_DTUART_SERIAL:am62pxx ??= "serial2" + +XEN_IRQ_DEVICES ??= "" +XEN_IRQ_DEVICES:am62xx ??= "\/bus@f0000\/bus@48000000\/interrupt-controller@48000000" +XEN_IRQ_DEVICES:am62pxx ??= "\/bus@f0000\/bus@48000000\/interrupt-controller@48000000" + +S = "${WORKDIR}" + +do_compile () { + sed -e 's/@@XEN_IMAGE_NAME@@/${XEN_IMAGE_NAME}/' \ + -e 's/@@XEN_KERNEL_IMAGE_NAME@@/${XEN_KERNEL_IMAGE_NAME}/' \ + -e 's/@@XEN_RAMDISK_NAME@@/${XEN_RAMDISK_NAME}/' \ + -e 's/@@XEN_FDT_ADDRESS@@/${XEN_FDT_ADDRESS}/' \ + -e 's/@@XEN_ADDRESS@@/${XEN_ADDRESS}/' \ + -e 's/@@XEN_KERNEL_ADDRESS@@/${XEN_KERNEL_ADDRESS}/' \ + -e 's/@@XEN_RAMDISK_ADDRESS@@/${XEN_RAMDISK_ADDRESS}/' \ + -e 's/@@XEN_BOOT_DOM0LESS@@/${XEN_BOOT_DOM0LESS}/' \ + -e 's/@@XEN_DTUART_SERIAL@@/${XEN_DTUART_SERIAL}/' \ + -e 's/@@DOM0_MEM@@/${DOM0_MEM}/' \ + -e 's/@@DOM0_MAX_VCPUS@@/${DOM0_MAX_VCPUS}/' \ + -e 's/@@XEN_IRQ_DEVICES@@/${XEN_IRQ_DEVICES}/' \ + -e 's/@@XEN_SHMEM_ID@@/${XEN_SHMEM_ID}/' \ + -e 's/@@XEN_SHMEM_UIO_NAME@@/${XEN_SHMEM_UIO_NAME}/' \ + -e 's/@@XEN_SHMEM_START@@/${XEN_SHMEM_START}/' \ + -e 's/@@XEN_SHMEM_SIZE@@/${XEN_SHMEM_SIZE}/' \ + "${S}/boot.xen.source.in" > "${S}/boot.xen.source" + + mkimage -f ${S}/boot.xen.its ${S}/boot.xen.scr +} + +inherit deploy +do_deploy () { + install -d ${DEPLOYDIR} + install -m 0644 ${S}/boot.xen.scr ${DEPLOYDIR} +} +addtask deploy before do_build after do_unpack diff --git a/recipes-bsp/u-boot/files/bootmethscript.cfg b/recipes-bsp/u-boot/files/bootmethscript.cfg new file mode 100644 index 0000000..a1c9f7c --- /dev/null +++ b/recipes-bsp/u-boot/files/bootmethscript.cfg @@ -0,0 +1 @@ +CONFIG_BOOTCOMMAND="run envboot; setenv bootmeths 'script'; bootflow scan -lb" diff --git a/recipes-bsp/u-boot/u-boot-ti-staging_%.bbappend b/recipes-bsp/u-boot/u-boot-ti-staging_%.bbappend index d36fa2e..5b723ed 100644 --- a/recipes-bsp/u-boot/u-boot-ti-staging_%.bbappend +++ b/recipes-bsp/u-boot/u-boot-ti-staging_%.bbappend @@ -1,5 +1,7 @@ SRCREV:tie-jailhouse = "6301979bc99cd27951ee140df4b29bcfa4823fdd" +FILESEXTRAPATHS:prepend := "${THISDIR}/files:" + IPC_DM_FW = "ipc_echo_testb_mcu1_0_release_strip.xer5f" # DM FW to be used only for AM62P tisdk-display-cluster image @@ -11,5 +13,9 @@ TI_DM="${STAGING_DIR_HOST}${nonarch_base_libdir}/firmware/ti-dm/${PLAT_SFX}/${DM EXTRA_OEMAKE += "TI_DM=${TI_DM}" -PR:append = "_tisdk_5" +SRC_URI:append:k3 = " \ + ${@bb.utils.contains('DISTRO_FEATURES', 'xen', 'file://bootmethscript.cfg', '', d)} \ +" + +PR:append = "_tisdk_6"