[meta-arm,2/2] arm-autonomy/xen-devicetree: check if kernel Image size is correct

Submitted by Kamil Dziezyk on Nov. 20, 2020, 11:37 a.m. | Patch ID: 178076

Details

Message ID 20201120113725.30265-2-kamil.dziezyk@arm.com
State New
Headers show

Commit Message

Kamil Dziezyk Nov. 20, 2020, 11:37 a.m.
This patch brings following improvements:
 * Adds a check for kernel size defined by XEN_DEVICETREE_DOM0_SIZE variable,
   whether it is greater or equal to actual kernel size.
   If not, bitbake warns user and adjusts value of XEN_DEVICETREE_DOM0_SIZE.
 * Adds 'virtual/kernel:do_deploy' as a mandatory xen-devicetree dependency via
   XEN_DEVICETREE_DEPEND variable.

Issue-Id: SCM-1567
Signed-off-by: Kamil Dziezyk <kamil.dziezyk@arm.com>

Change-Id: I4f250172f1fa599b7a3673ba0887cd49372b7556
---
 .../xen-devicetree/xen-devicetree.bb          | 31 ++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

-- 
2.17.1
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#1407): https://lists.yoctoproject.org/g/meta-arm/message/1407
Mute This Topic: https://lists.yoctoproject.org/mt/78387125/1003190
Group Owner: meta-arm+owner@lists.yoctoproject.org
Unsubscribe: https://lists.yoctoproject.org/g/meta-arm/unsub [mhalstead@linuxfoundation.org]
-=-=-=-=-=-=-=-=-=-=-=-

Patch hide | download patch | download mbox

diff --git a/meta-arm-autonomy/recipes-extended/xen-devicetree/xen-devicetree.bb b/meta-arm-autonomy/recipes-extended/xen-devicetree/xen-devicetree.bb
index ccbb387..0369b96 100644
--- a/meta-arm-autonomy/recipes-extended/xen-devicetree/xen-devicetree.bb
+++ b/meta-arm-autonomy/recipes-extended/xen-devicetree/xen-devicetree.bb
@@ -14,7 +14,9 @@  DESCRIPTION = "Add entries in DTB for Xen and Dom0"
 
 # Please refer to documentation/xen-devicetree.md for documentation on those
 # parameters
-XEN_DEVICETREE_DEPEND ?= "virtual/kernel:do_deploy"
+# kernel size is passed to xen via xen.dtb so wee need to add
+# 'virtual/kernel:do_deploy' as a dependency
+XEN_DEVICETREE_DEPEND_append = " virtual/kernel:do_deploy"
 XEN_DEVICETREE_DTBS ?= "${KERNEL_DEVICETREE}"
 XEN_DEVICETREE_XEN_BOOTARGS ?= "noreboot dom0_mem=${XEN_DEVICETREE_DOM0_MEM}"
 XEN_DEVICETREE_DOM0_MEM ?= "1024M"
@@ -67,6 +69,33 @@  do_deploy() {
     done
 }
 do_deploy[depends] += "${XEN_DEVICETREE_DEPEND}"
+do_deploy[prefuncs] += "calc_xen_dtb_dom0_size"
 
 addtask deploy after do_install
 
+python calc_xen_dtb_dom0_size() {
+    from math import ceil
+    size = 0
+    if d.getVar('KERNEL_IMAGE_MAXSIZE'):
+        bb.note('size calculation based on KERNEL_IMAGE_MAXSIZE')
+        size = int(d.getVar('KERNEL_IMAGE_MAXSIZE')) * 1024
+    else:
+        kernel = os.path.realpath(d.getVar('DEPLOY_DIR_IMAGE') + '/' +\
+                 d.getVar('KERNEL_IMAGETYPE'))
+        size = os.stat(kernel).st_size
+        bb.note('size calculation based on kernel Image file: %s' % kernel)
+
+    bb.note('size in bytes: %d' % size)
+    # Ceil to MiB
+    size_required = ceil(size / (2 ** 20)) * (2 ** 20)
+    size_defined = int(d.getVar('XEN_DEVICETREE_DOM0_SIZE'), 16)
+
+    if size_required > size_defined:
+        bb.warn ("Wrong kernel size setting inside xen dtb!\n"\
+                 "Required:\t%(req)d (%(req)#010X)\n"\
+                 "Requested:\t%(def)d (%(def)#010X)"\
+                 % {"req": size_required, "def": size_defined})
+        bb.warn ("Overriding XEN_DEVICETREE_DOM0_SIZE with "\
+                 "%(req)d (%(req)#010X)" % {"req": size_required})
+        d.setVar('XEN_DEVICETREE_DOM0_SIZE', hex(size_required))
+}

Comments

Kamil Dziezyk Nov. 24, 2020, 2:02 p.m.
Please backport this patch to gatesgarth.
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#1436): https://lists.yoctoproject.org/g/meta-arm/message/1436
Mute This Topic: https://lists.yoctoproject.org/mt/78387125/1003190
Group Owner: meta-arm+owner@lists.yoctoproject.org
Unsubscribe: https://lists.yoctoproject.org/g/meta-arm/unsub [mhalstead@linuxfoundation.org]
-=-=-=-=-=-=-=-=-=-=-=-