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

[ImageBuilder] uboot-script-gen: use size from arm32 zImage header


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Michal Orzel <michal.orzel@xxxxxxx>
  • Date: Mon, 20 Nov 2023 16:13:15 +0100
  • 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 (0)
  • 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=Z/PiRdYgrtDdEJE4tNAgZp4K4hnRT1QsFVLpTkw9TnE=; b=KEjYJEIRWQ5k2G5dtSKamO4NllQwnV534xuJVMAsH/dufgBwiYeWx7WzxFprTJmdiQ+A9UFQkVgVJJE73mlopxlZtRRcKu53q8geXEoq7lUaxqcI9YW+lVWDP4+/9fpt1ZVdlVQM+v1eDwkKSDWq2njGlr0ENfIrg2dVSn6uC7LK59gRQm4XdzsWW49ZwAAE0t9xg02dtu5bRjR0EjZW/mw3zavnNTd8akUXOvUwZ70F3d7pQWeS5e22W20s5R52fkQsU4m2ShRyCqiWoXJzSa8U+T/CPH7TlWX+Bttd8k4bW4K83KNKWXfqdv/5y8EhR5WeAgHNjVbi2+3OYXK0ag==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jFrG1TrMd/e0kh+Sdl95eMt08tN7krfMiKlnWMjdYI5w9hayHZOsGYgrl95RBKU4hXA6Y4oVtflZPXb1ivLbaSuclkSC0R5GUEUeB9sNPSlYJoQahZoGMawoVvBWldDNwc98de6AB+ezPGJGumUf6W3h8ArHnVosnYjhkEd589pnpD/cn18iYLE2/ntFDVE2I9Z/+KGxJYxIsOGdH7F6UeW98hAHdx3JGY0zp2fcqExApAY3RjOKBrc+Pc7BiALsLP2Pq6zwcYxm/LaHTLaSvI+GdZ0V8lNrIPrMaVyHKaTcPzimPG/3oKv3oyshjwrb6DiagETX9iUQ/rr7afjrAQ==
  • Cc: <sstabellini@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>
  • Delivery-date: Mon, 20 Nov 2023 15:13:28 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Take an example from commit 8bf401c99035 ("uboot-script-gen: use size from
arm64 Image header") and add support for calculating the effective image
size from arm32 zImage header.

Introduce get_image_size() function and use it to to probe the supported
header magic values and to retrieve the effective image size. Use this
value in add_size(), whenever it's bigger than the one obtained using
'stat -L'.

Signed-off-by: Michal Orzel <michal.orzel@xxxxxxx>
---
This patch together with 'bootz' support will allow us to enable testing Xen
on arm{32,64} in gitlab CI with UBSAN enabled.
---
 scripts/uboot-script-gen | 38 ++++++++++++++++++++++++++++----------
 1 file changed, 28 insertions(+), 10 deletions(-)

diff --git a/scripts/uboot-script-gen b/scripts/uboot-script-gen
index 9e3d86e4743a..078a667c61ab 100755
--- a/scripts/uboot-script-gen
+++ b/scripts/uboot-script-gen
@@ -431,23 +431,41 @@ function device_tree_editing()
     fi
 }
 
-function add_size()
+# Read effective image size from a header, which may be larger than the 
filesize
+# due to noload sections, e.g. bss.
+function get_image_size()
 {
-    local filename=$1
-    local size=`stat -L --printf="%s" $filename`
+    local image=$1
+    local effective_size=0
     # 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}')
+    local arm64_header_magic=$(od -j 56 -N 4 -t x4 ${image} | awk 'NR==1 
{print $2}')
+    # Read arm32 header magic 
(http://www.simtec.co.uk/products/SWLINUX/files/booting_article.html)
+    local arm32_header_magic=$(od -j 36 -N 4 -t x4 ${image} | 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}')
+        effective_size=$(od -j 16 -N 8 -t u8 ${image} | awk 'NR==1 {print $2}')
+    # Check for valid arm32 header magic value 0x016f2818
+    elif [ "${arm32_header_magic}" = "016f2818" ]
+    then
+        local start=$(od -j 40 -N 4 -t u4 ${image} | awk 'NR==1 {print $2}')
+        local end=$(od -j 44 -N 4 -t u4 ${image} | awk 'NR==1 {print $2}')
+        effective_size=$(( end - start ))
+    fi
 
-        if [ "${arm64_header_size}" -gt "${size}" ]
-        then
-            size=${arm64_header_size}
-        fi
+    printf "%u" $effective_size
+}
+
+function add_size()
+{
+    local filename=$1
+    local size=`stat -L --printf="%s" $filename`
+    local image_size=`get_image_size $filename`
+
+    if [ "${image_size}" -gt "${size}" ]
+    then
+        size=${image_size}
     fi
 
     memaddr=$(( $memaddr + $size + $offset - 1))
-- 
2.25.1




 


Rackspace

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