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

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


  • To: Stefano Stabellini <sstabellini@xxxxxxxxxx>
  • From: Stewart Hildebrand <stewart.hildebrand@xxxxxxx>
  • Date: Tue, 29 Aug 2023 15:58:33 -0400
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.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=CwMxruHWYc2va5Z9r+cMPxsJwA/nd+0XhTUuzNFCIK4=; b=Vz0ZSuVAXsKbcmZiwrk9BVVERLapqtpuRbDjGuii1Z7eCoixKETUl2Mn1rkjQi37a2JIcV6Ogqj1ufyQbn1kT1uqe0EvpT/ObNpYib5D2gIeh4JY6PLH8TNc1QS650wKZonyCLdZKmHVUoWOXOwneukeFwW/u6ez8UUOjSSKdFPJDTmFmzkmxMDSp1oFiQsloCj6Tlwr4h3NHNqNtj7iPZUCgG5LxIgbx7vsN9hlgyAkNz5L3bMacZP0iSYjeyq7hlN6k3oac2wIOuEjJQQVSf5Y3y31A+dAkIvnTP2tSL8GQ6rLPpIqHe8/x1sD3bzspFjEsmIqbvp7YasAvuXJrA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BJcW+05uAOzzppJLgUw5hIChgf+Bcc8jMHtupBNYZNEwoErxuiwLE5wCS/lb6v/nFEaYO52fKspHzqAyWxtZd5kyzU9D64m0KdaXK6RViIgnsJKlI013rhYlXBkX9PrJFiQuRetIIAU4kLTmdEn5JtBWCNNJAlahdvCvZnzg/H/0XGhJsIPavJ+QPuspKpa/9CaeXR32w2GJ9UZ6kU24wJPQWSn2NDgITg7n8md4fc9CIjswmo/KZOrn+DgfAyi+riVGN2YSsYss+pnJjylAIhrxPt+52kIkEv4u/8RCjzpEFanm68BPV45IvW32Bi4R5pScl0IYlGm4hCTo4kMzxg==
  • Cc: <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>
  • Delivery-date: Tue, 29 Aug 2023 19:59:03 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 8/24/23 19:19, Stefano Stabellini wrote:
> On Thu, 24 Aug 2023, Stewart Hildebrand wrote:
>> 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.hildebrand@xxxxxxx>
>> ---
>>  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
> 
> 
> Thanks Stewart this is great! Can you please add a good in-code comment
> to explain what field you are reading of the header exactly and what is
> the value 644d5241 you are comparing against?

Yes

> Also I think it would be easier to read if you used "cut" instead of
> awk and split the line a bit more like this:
> 
> 
>     # read header field XXX
>     local field_xxx =$(od -j 56 -N 4 -t x4 ${filename} | head -n 1 | cut -d " 
> " -f2)
>     # comparing against XXX
>     if [ $field_xxx = "644d5241" ]
>     then
>         # read header field "size" which indicates ....
>         local size_header=$(od -j 16 -N 8 -t u8 ${filename} | head -n 1 | cut 
> -d " " -f2)

od seems to output a varying amount of whitespace between the address and 
value. In this case, the cut command would seem to want to become cut -d" " 
-f14 to account for the whitespace. awk is more predictable here, so I will 
keep awk.



 


Rackspace

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