There is a corner case where the filesizes of the xen and Linux kernel images
are not sufficient. These binaries likely contain .NOLOAD sections, 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.hildebr...@amd.com>
---
 scripts/uboot-script-gen | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/scripts/uboot-script-gen b/scripts/uboot-script-gen
index 9656a458ac00..50fe525e7145 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,17 @@ function add_size()
 {
     local filename=$1
     local size=`stat -L --printf="%s" $filename`
+
+    if [ "$(od -j 56 -N 4 -t x4 ${filename} | head -n 1 | awk -F' ' '{ print 
$2 }')" = "644d5241" ]
+    then
+        local size_header=$(od -j 16 -N 8 -t u8 ${filename} | head -n 1 | awk 
-F' ' '{ print $2 }')
+
+        if [ "${size_header}" -gt "${size}" ]
+        then
+            size=${size_header}
+        fi
+    fi
+
     memaddr=$(( $memaddr + $size + $offset - 1))
     memaddr=$(( $memaddr & ~($offset - 1) ))
     memaddr=`printf "0x%X\n" $memaddr`
-- 
2.42.0


Reply via email to