diff mbox series

[isar-cip-core,RFC,4/5] image_uuid: read target_image_uuid

Message ID 20221110124503.274124-5-Quirin.Gylstorff@siemens.com (mailing list archive)
State Superseded
Headers show
Series SWUpdate abort on installing indentical image | expand

Commit Message

Gylstorff Quirin Nov. 10, 2022, 12:45 p.m. UTC
From: Quirin Gylstorff <quirin.gylstorff@siemens.com>

This writes the target_image_uuid to the Variable TARGET_IMAGE_UUID
which can be used to validate a update against the root file system.

Signed-off-by: Quirin Gylstorff <quirin.gylstorff@siemens.com>
---
 classes/image_uuid.bbclass | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

Comments

Jan Kiszka Nov. 10, 2022, 1:56 p.m. UTC | #1
On 10.11.22 13:45, Quirin Gylstorff wrote:
> From: Quirin Gylstorff <quirin.gylstorff@siemens.com>
> 
> This writes the target_image_uuid to the Variable TARGET_IMAGE_UUID
> which can be used to validate a update against the root file system.
> 
> Signed-off-by: Quirin Gylstorff <quirin.gylstorff@siemens.com>
> ---
>  classes/image_uuid.bbclass | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
> 
> diff --git a/classes/image_uuid.bbclass b/classes/image_uuid.bbclass
> index 277941b..3e2e3de 100644
> --- a/classes/image_uuid.bbclass
> +++ b/classes/image_uuid.bbclass
> @@ -13,6 +13,8 @@
>  inherit rootfs
>  inherit image
>  
> +# Generate the uuid from BB_TASKHASH to ensure a new
> +# hash on each rebuild
>  def generate_image_uuid(d):
>      import uuid
>  
> @@ -23,6 +25,23 @@ def generate_image_uuid(d):
>  
>  IMAGE_UUID ?= "${@generate_image_uuid(d)}"
>  
> +def read_target_image_uuid(d):
> +    import os.path
> +
> +    deploy_dir = d.getVar("DEPLOY_DIR_IMAGE")
> +    image_full_name = d.getVar("IMAGE_FULLNAME")
> +    uuid_file = f"{deploy_dir}/{image_full_name}.uuid.env"
> +    if not os.path.isfile(uuid_file):
> +        return None
> +
> +    target_image_uuid = None
> +    with open(uuid_file, "r") as f:
> +       uuid_file_content = f.read()
> +       target_image_uuid = uuid_file_content.split('=')[1].strip(' \t\n\r').strip('\"')
> +    return target_image_uuid
> +
> +TARGET_IMAGE_UUID = "${@read_target_image_uuid(d)}"

When is this evaluated by bitbake? Only on every access, inside a task
context? Because the file it reads from only exists after
do_generate_image_uuid, obviously.

Jan

> +
>  do_generate_image_uuid[vardeps] += "IMAGE_UUID"
>  do_generate_image_uuid[depends] = "buildchroot-target:do_build"
>  do_generate_image_uuid[dirs] = "${DEPLOY_DIR_IMAGE}"
Gylstorff Quirin Nov. 10, 2022, 2:09 p.m. UTC | #2
On 11/10/22 14:56, Jan Kiszka wrote:
> On 10.11.22 13:45, Quirin Gylstorff wrote:
>> From: Quirin Gylstorff <quirin.gylstorff@siemens.com>
>>
>> This writes the target_image_uuid to the Variable TARGET_IMAGE_UUID
>> which can be used to validate a update against the root file system.
>>
>> Signed-off-by: Quirin Gylstorff <quirin.gylstorff@siemens.com>
>> ---
>>   classes/image_uuid.bbclass | 19 +++++++++++++++++++
>>   1 file changed, 19 insertions(+)
>>
>> diff --git a/classes/image_uuid.bbclass b/classes/image_uuid.bbclass
>> index 277941b..3e2e3de 100644
>> --- a/classes/image_uuid.bbclass
>> +++ b/classes/image_uuid.bbclass
>> @@ -13,6 +13,8 @@
>>   inherit rootfs
>>   inherit image
>>   
>> +# Generate the uuid from BB_TASKHASH to ensure a new
>> +# hash on each rebuild
>>   def generate_image_uuid(d):
>>       import uuid
>>   
>> @@ -23,6 +25,23 @@ def generate_image_uuid(d):
>>   
>>   IMAGE_UUID ?= "${@generate_image_uuid(d)}"
>>   
>> +def read_target_image_uuid(d):
>> +    import os.path
>> +
>> +    deploy_dir = d.getVar("DEPLOY_DIR_IMAGE")
>> +    image_full_name = d.getVar("IMAGE_FULLNAME")
>> +    uuid_file = f"{deploy_dir}/{image_full_name}.uuid.env"
>> +    if not os.path.isfile(uuid_file):
>> +        return None
>> +
>> +    target_image_uuid = None
>> +    with open(uuid_file, "r") as f:
>> +       uuid_file_content = f.read()
>> +       target_image_uuid = uuid_file_content.split('=')[1].strip(' \t\n\r').strip('\"')
>> +    return target_image_uuid
>> +
>> +TARGET_IMAGE_UUID = "${@read_target_image_uuid(d)}"
> 
> When is this evaluated by bitbake? Only on every access, inside a task
> context? Because the file it reads from only exists after
> do_generate_image_uuid, obviously.
> 
> Jan

The variable will be evaluated on access from my testing.

I tried to set the variable during do_generate_image_uuid which let to a 
empty variable in the followup tasks.


Quirin
> 
>> +
>>   do_generate_image_uuid[vardeps] += "IMAGE_UUID"
>>   do_generate_image_uuid[depends] = "buildchroot-target:do_build"
>>   do_generate_image_uuid[dirs] = "${DEPLOY_DIR_IMAGE}"
>
diff mbox series

Patch

diff --git a/classes/image_uuid.bbclass b/classes/image_uuid.bbclass
index 277941b..3e2e3de 100644
--- a/classes/image_uuid.bbclass
+++ b/classes/image_uuid.bbclass
@@ -13,6 +13,8 @@ 
 inherit rootfs
 inherit image
 
+# Generate the uuid from BB_TASKHASH to ensure a new
+# hash on each rebuild
 def generate_image_uuid(d):
     import uuid
 
@@ -23,6 +25,23 @@  def generate_image_uuid(d):
 
 IMAGE_UUID ?= "${@generate_image_uuid(d)}"
 
+def read_target_image_uuid(d):
+    import os.path
+
+    deploy_dir = d.getVar("DEPLOY_DIR_IMAGE")
+    image_full_name = d.getVar("IMAGE_FULLNAME")
+    uuid_file = f"{deploy_dir}/{image_full_name}.uuid.env"
+    if not os.path.isfile(uuid_file):
+        return None
+
+    target_image_uuid = None
+    with open(uuid_file, "r") as f:
+       uuid_file_content = f.read()
+       target_image_uuid = uuid_file_content.split('=')[1].strip(' \t\n\r').strip('\"')
+    return target_image_uuid
+
+TARGET_IMAGE_UUID = "${@read_target_image_uuid(d)}"
+
 do_generate_image_uuid[vardeps] += "IMAGE_UUID"
 do_generate_image_uuid[depends] = "buildchroot-target:do_build"
 do_generate_image_uuid[dirs] = "${DEPLOY_DIR_IMAGE}"