Skip to content

Commit

Permalink
recipes-bsp: u-boot: add mechanism to boot xen
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
natto1784 committed Sep 13, 2024
1 parent a235ef3 commit 76e94fa
Show file tree
Hide file tree
Showing 5 changed files with 255 additions and 1 deletion.
19 changes: 19 additions & 0 deletions recipes-bsp/u-boot-xen-scr/files/boot.xen.its
Original file line number Diff line number Diff line change
@@ -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";
};
};
};
};
156 changes: 156 additions & 0 deletions recipes-bsp/u-boot-xen-scr/files/boot.xen.source.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
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@@ bootscrub=0 conswitch=sx"
setenv xen_bootargs "console=dtuart dtuart=@@XEN_DTUART_SERIAL@@ dom0_mem=@@DOM0_MEM@@"
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}
72 changes: 72 additions & 0 deletions recipes-bsp/u-boot-xen-scr/u-boot-xen-scr.bb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
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 ??= "2G"
DOM0_MAX_VCPUS ??= "1"
XEN_SHMEM_UIO_NAME ??= "xen-uio"
XEN_SHMEM_START ??= "0x80000000"
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
}

do_install () {
install -d ${D}/board-support/prebuilt-images
install -m 0644 ${S}/boot.xen.scr ${D}/board-support/prebuilt-images/
}
FILES:${PN} += "board-support/*"

inherit deploy
do_deploy () {
install -d ${DEPLOYDIR}
install -m 0644 ${S}/boot.xen.scr ${DEPLOYDIR}
}
addtask deploy before do_build after do_unpack
1 change: 1 addition & 0 deletions recipes-bsp/u-boot/files/bootmethscript.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CONFIG_BOOTCOMMAND="run envboot; setenv bootmeths 'script'; bootflow scan -lb"
8 changes: 7 additions & 1 deletion recipes-bsp/u-boot/u-boot-ti-staging_%.bbappend
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"

0 comments on commit 76e94fa

Please sign in to comment.