summaryrefslogtreecommitdiffstats
path: root/classes/qemuboot-xen-u-boot.bbclass
diff options
context:
space:
mode:
Diffstat (limited to 'classes/qemuboot-xen-u-boot.bbclass')
-rw-r--r--classes/qemuboot-xen-u-boot.bbclass128
1 files changed, 128 insertions, 0 deletions
diff --git a/classes/qemuboot-xen-u-boot.bbclass b/classes/qemuboot-xen-u-boot.bbclass
new file mode 100644
index 00000000..4401eba2
--- /dev/null
+++ b/classes/qemuboot-xen-u-boot.bbclass
@@ -0,0 +1,128 @@
1# Enable booting Xen with qemuboot / runqemu: u-boot configuration
2#
3# Copyright (c) 2021-2022 Star Lab Corp. All rights reserved.
4#
5# Author: Christopher Clark <christopher.clark@starlab.io>
6
7# Interface variables:
8#
9# QB_XEN_U_BOOT_SCR :
10# If this variable is set, this class will generate the u-boot script image file
11# It must be set to the name of the compiled command file that u-boot will tftp
12# from the image deploy directory during boot, currently: "boot.scr.uimg"
13#
14# QB_XEN_CMDLINE_EXTRA :
15# A string to be appended to the default Xen hypervisor boot command line,
16# for supplying Xen boot options.
17# The device tree that this bbclass generates will contain Xen command
18# line options to connect the Xen console to the Qemu serial port.
19#
20# QB_XEN_LOAD_ADDR :
21# The hypervisor load address
22#
23# QB_XEN_DOM0_BOOTARGS :
24# A string for specifying Dom0 boot options for the Xen section of the device
25# tree.
26#
27# QB_XEN_UBOOT_SCR_TASK_DEPENDS:
28# The task dependencies for the u-boot script generation. A default is provided.
29#
30# QB_XEN_DOMAIN_MODULES:
31# A space-separated list of colon-separated entries:
32# "<file for the module>:<load memory address>:<module compatibility string>"
33
34# Set the default value for this variable to empty: no file generated.
35QB_XEN_U_BOOT_SCR ??= ""
36
37write_add_chosen_module() {
38 CMD_FILE="$1"
39 ADDR="$2"
40 SIZE="$3"
41 MODULE_TYPE="$4"
42 cat <<EOF >>"${CMD_FILE}"
43fdt mknod /chosen module@${ADDR}
44fdt set /chosen/module@${ADDR} compatible "multiboot,module" "${MODULE_TYPE}"
45fdt set /chosen/module@${ADDR} reg <${ADDR} ${SIZE}>
46EOF
47}
48
49generate_xen_u_boot_conf() {
50 CMD_FILE="${B}/qemuboot-xen.cmd"
51 cat <<EOF >"${CMD_FILE}"
52echo "Running u-boot launch script"
53fdt addr 0x40000000
54fdt resize
55echo "Device tree resized"
56
57fdt set /chosen \#address-cells <1>
58fdt set /chosen \#size-cells <1>
59
60fdt set /chosen xen,xen-bootargs "console=dtuart dtuart=/pl011@9000000 ${QB_XEN_CMDLINE_EXTRA}"
61fdt set /chosen xen,dom0-bootargs "${QB_XEN_DOM0_BOOTARGS}"
62EOF
63
64 if [ -z "${QB_XEN_DOMAIN_MODULES}" ]; then
65 bbwarn "No domain modules: please set QB_XEN_DOMAIN_MODULES"
66 fi
67
68 for DOMAIN_MODULE in ${QB_XEN_DOMAIN_MODULES}
69 do
70 MODULE_FILE="$(echo ${DOMAIN_MODULE} | cut -f1 -d:)"
71 ADDR="$(echo ${DOMAIN_MODULE} | cut -f2 -d:)"
72 MODULE_TYPE="$(echo ${DOMAIN_MODULE} | cut -f3 -d:)"
73 RESOLVED_FILE="$(readlink -f ${MODULE_FILE})"
74 SIZE=$(printf '0x%x\n' $(stat -c '%s' "${RESOLVED_FILE}"))
75 [ "x${SIZE}" != "x0x0" ] || bbfatal No module: "${MODULE_FILE}"
76 write_add_chosen_module "${CMD_FILE}" "${ADDR}" "${SIZE}" "${MODULE_TYPE}"
77 done
78
79 cat <<EOF >>"${CMD_FILE}"
80fdt print /chosen
81
82echo Boot Xen
83bootz ${QB_XEN_LOAD_ADDR} - 0x40000000
84EOF
85
86 uboot-mkimage -A "${UBOOT_ARCH}" -T script -C none \
87 -a 0x20000 -e 0x20000 \
88 -d "${CMD_FILE}" "${CMD_FILE}.uimg"
89
90 # u-boot tftps this filename from DEPLOY_DIR_IMAGE:
91 install -m 0644 "${CMD_FILE}.uimg" "${DEPLOY_DIR_IMAGE}/${QB_XEN_U_BOOT_SCR}"
92}
93
94do_write_qemuboot_xen_u_boot_conf() {
95 # Not all architectures qemuboot with u-boot, so check to see if this
96 # is needed. This allows this bbclass file to be used in the same image
97 # recipe for multiple architectures.
98
99 if [ -n "${QB_XEN_U_BOOT_SCR}" ] && [ -n "${QB_SYSTEM_NAME}" ] ; then
100 generate_xen_u_boot_conf
101 fi
102}
103
104addtask do_write_qemuboot_xen_u_boot_conf after do_write_qemuboot_conf before do_image
105# Task dependency:
106# An expected common case is that the kernel for at least one of the initial
107# domains (eg. dom0) is deployed from the virtual/kernel recipe, so
108# add that as a task dependency here since the kernel size needs to be known
109# for generating the device tree.
110# Dependencies are only introduced if a device tree will be generated.
111QB_XEN_UBOOT_SCR_TASK_DEPENDS ?= " \
112 ${@[ ' \
113 u-boot-tools-native:do_populate_sysroot \
114 u-boot:do_deploy \
115 virtual/kernel:do_deploy \
116 ', ''][d.getVar('QB_XEN_U_BOOT_SCR') == '']} \
117 "
118do_write_qemuboot_xen_u_boot_conf[depends] = "${QB_XEN_UBOOT_SCR_TASK_DEPENDS}"
119
120def qemuboot_xen_u_boot_vars(d):
121 build_vars = ['MACHINE', 'TUNE_ARCH', 'DEPLOY_DIR_IMAGE',
122 'KERNEL_IMAGETYPE', 'IMAGE_NAME', 'IMAGE_LINK_NAME',
123 'STAGING_DIR_NATIVE', 'STAGING_BINDIR_NATIVE',
124 'STAGING_DIR_HOST', 'SERIAL_CONSOLES']
125 return build_vars + [k for k in d.keys() if k.startswith('QB_')]
126
127do_write_qemuboot_xen_u_boot[vardeps] += "${@' '.join(qemuboot_xen_u_boot_vars(d))}"
128do_write_qemuboot_xen_u_boot[vardepsexclude] += "TOPDIR"