[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ImageBuilder PATCH v3] uboot-script-gen: use size from arm64 Image header


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Stewart Hildebrand <stewart.hildebrand@xxxxxxx>
  • Date: Wed, 13 Sep 2023 10:13:10 -0400
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=LmwDyZb8YRQkjeT/5fhlCcDSgiRc55DW8fgXBndKQZ4=; b=DgAxe3U5QWCNvy6ePp1SqchB132hRF3t9+RgJCYAYgGq7Xo39yWFm2bSvGPT+DH/EgooFhW8ZxVXqotgg1Ng86qfw25ctLoekDPWH/MyaOnVBahzy7T/j6kpI9tf4NleTI/mNN5QdG9Xfaq46jI/LmGtBTGUpTsW6XL7qJshNPDAETLMI1oMwPKDPUFbpo/huuqKTlkojlub9sMLLj/bxM/MOmJR5NZg+WLRhVdePIc5qaztyWtG1pryVKFwg/uKc08kO2mZ1210U7taUcH8kA7GFkCOM6ofYy4UcdmTFySGf+9sElG0Nq+n782/AmagMB0XltdVeHbb+2eD0MKwoQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hpx0JlWkJZ/rw/WGiIFUzHP7GnHN15ITjAReHIxZHMWRjmLllTfKGMil2QLlMDZlP8zfI05g+jdID0Ns/eXDdwkb+q1enzGfcJM6BHiUoWiFYPwjocONg9FDx8sAVGAvpOCkbyuMpqz/Zla5lCxtHkznehKUAwPJWr0MBX4ij/w5awEkx/Rj+pvP/KrPdH1WTNYcXjSweuwhi+XFwihZZQt72NsECD1U4A2qrzQas0FiGzroz+KuHLmnzLWwkpSSmeLkTOb/BWnms7wklH1SqRLTV5Ck2DxLZL+0rEYDpuLbJjEeeqjh49DhhOPF5lmFtw8ctdFTuq2CqlApSeouhQ==
  • Cc: Stewart Hildebrand <stewart.hildebrand@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>
  • Delivery-date: Wed, 13 Sep 2023 14:14:00 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

There is a corner case where the filesizes of the xen and Linux kernel images
are not sufficient. These binaries likely contain NOLOAD sections (e.g. bss),
which are not accounted in the filesize.

Check for the presence of an arm64 kernel image header, and get the effective
image size from the header. Use the effective image size for calculating the
next load address and for populating the size in the /chosen/dom*/reg property.

Signed-off-by: Stewart Hildebrand <stewart.hildebrand@xxxxxxx>
Reviewed-by: Michal Orzel <michal.orzel@xxxxxxx>
---
v2->v3:
* simplify awk parsing
* add R-b

v1->v2:
* add in-code comments
* use variables more
---
 scripts/uboot-script-gen | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/scripts/uboot-script-gen b/scripts/uboot-script-gen
index 9656a458ac00..b284887f065e 100755
--- a/scripts/uboot-script-gen
+++ b/scripts/uboot-script-gen
@@ -2,7 +2,7 @@
 
 offset=$((2*1024*1024))
 filesize=0
-prog_req=(mkimage file fdtput mktemp awk)
+prog_req=(mkimage file fdtput mktemp awk od)
 
 function cleanup_and_return_err()
 {
@@ -435,6 +435,21 @@ function add_size()
 {
     local filename=$1
     local size=`stat -L --printf="%s" $filename`
+    # Read arm64 header magic 
(https://www.kernel.org/doc/Documentation/arm64/booting.txt)
+    local arm64_header_magic=$(od -j 56 -N 4 -t x4 ${filename} | awk 'NR==1 
{print $2}')
+
+    # Check for valid arm64 header magic value 0x644d5241
+    if [ "${arm64_header_magic}" = "644d5241" ]
+    then
+        # Read effective size, which may be larger than the filesize due to 
noload sections, e.g. bss
+        local arm64_header_size=$(od -j 16 -N 8 -t u8 ${filename} | awk 'NR==1 
{print $2}')
+
+        if [ "${arm64_header_size}" -gt "${size}" ]
+        then
+            size=${arm64_header_size}
+        fi
+    fi
+
     memaddr=$(( $memaddr + $size + $offset - 1))
     memaddr=$(( $memaddr & ~($offset - 1) ))
     memaddr=`printf "0x%X\n" $memaddr`
-- 
2.42.0




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.