diff mbox series

[isar-cip-core,v2,4/4] fix do not add files to each image recipe

Message ID 20240305110311.2073425-5-Quirin.Gylstorff@siemens.com (mailing list archive)
State Superseded
Headers show
Series Make swupdate signing more robust | expand

Commit Message

Gylstorff Quirin March 5, 2024, 11:02 a.m. UTC
From: Quirin Gylstorff <quirin.gylstorff@siemens.com>

Due to the use of an anonym python function each image recipe was
partial build even if not requested.
To avoid this remove the anonym image function by adding
it as an prefunc to do_image_swu and do_transform_template.

The SRC_URI is appended with a function.

Signed-off-by: Quirin Gylstorff <quirin.gylstorff@siemens.com>
---
 classes/efibootguard.bbclass |  1 -
 classes/swupdate.bbclass     | 42 ++++++++++++++++++++++++------------
 2 files changed, 28 insertions(+), 15 deletions(-)

Comments

Jan Kiszka March 5, 2024, 2:17 p.m. UTC | #1
On 05.03.24 12:02, Quirin Gylstorff wrote:
> From: Quirin Gylstorff <quirin.gylstorff@siemens.com>
> 
> Due to the use of an anonym python function each image recipe was

anonymous

> partial build even if not requested.

built

> To avoid this remove the anonym image function by adding

anonymous

> it as an prefunc to do_image_swu and do_transform_template.
> 
> The SRC_URI is appended with a function.
> 
> Signed-off-by: Quirin Gylstorff <quirin.gylstorff@siemens.com>
> ---
>  classes/efibootguard.bbclass |  1 -
>  classes/swupdate.bbclass     | 42 ++++++++++++++++++++++++------------
>  2 files changed, 28 insertions(+), 15 deletions(-)
> 
> diff --git a/classes/efibootguard.bbclass b/classes/efibootguard.bbclass
> index 31fcdcc..2b4f09e 100644
> --- a/classes/efibootguard.bbclass
> +++ b/classes/efibootguard.bbclass
> @@ -67,5 +67,4 @@ python add_ebg_update(){
>     ebg_update = d.getVar('SWU_EBG_UPDATE') or ""
>     if ebg_update:
>       d.appendVar('SWU_FILE_NODES', "," + swu_ebg_update_node)

Indention looks fishy, but that is nothing this patch caused.

> -   d.appendVar('SWU_ADDITIONAL_FILES', " " + efi_boot_loader_file)
>  }
> diff --git a/classes/swupdate.bbclass b/classes/swupdate.bbclass
> index c62f43f..c82d20c 100644
> --- a/classes/swupdate.bbclass
> +++ b/classes/swupdate.bbclass
> @@ -63,7 +63,7 @@ IMAGE_TEMPLATE_VARS:swu = " \
>  # TARGET_IMAGE_UUID needs to be generated before completing the template
>  addtask do_transform_template after do_generate_image_uuid
>  
> -python(){
> +python do_extend_sw_description(){

() {

>      cmds = d.getVar("SWU_EXTEND_SW_DESCRIPTION")
>      if cmds is None or not cmds.strip():
>          return
> @@ -71,6 +71,7 @@ python(){
>      for cmd in cmds:
>          bb.build.exec_func(cmd, d)
>  }
> +do_transform_template[prefuncs] += "do_extend_sw_description"
>  
>  SWU_EXTEND_SW_DESCRIPTION += "add_swu_hw_compat"
>  python add_swu_hw_compat(){
> @@ -94,9 +95,22 @@ python add_swu_compression(){
>          d.setVar('SWU_COMPRESSION_NODE', '')
>  }
>  
> +def add_scripts_to_src_uri(d):
> +    swu_scripts = d.getVar('SWU_SCRIPTS')
> +    if not swu_scripts:
> +        return ""
> +    swu_script_entries = swu_scripts.split()
> +    script_file_list = []
> +    for entry in swu_script_entries:
> +        script_entry = f"SWU_SCRIPT_{entry}"
> +        script_file = d.getVarFlag(script_entry, "file")
> +        script_file_list.append(f" file://{script_file}")
> +    return ' '.join([n for n in script_file_list])
>  
> -SWU_EXTEND_SW_DESCRIPTION += "add_scripts"
> -python add_scripts(){
> +SRC_URI += "${@add_scripts_to_src_uri(d)}"
> +
> +SWU_EXTEND_SW_DESCRIPTION += "add_scripts_node"
> +python add_scripts_node(){
>      swu_scripts = d.getVar('SWU_SCRIPTS')
>      if not swu_scripts:
>          return
> @@ -129,8 +143,6 @@ python add_scripts(){
>            sha256 = "{script_file}-sha256";
>          }}"""
>          script_node_list.append(node)
> -        d.appendVar('SWU_ADDITIONAL_FILES', " " + script_file)
> -        d.appendVar('SRC_URI', f" file://{script_file}")
>  
>      swu_scripts_node = "scripts: (" + ','.join([n for n in script_node_list]) + ");"
>      d.appendVar('SWU_SCRIPTS_NODE', swu_scripts_node)
> @@ -155,6 +167,7 @@ FILESEXTRAPATHS:append = ":${LAYERDIR_cip-core}/recipes-core/images/swu"
>  do_image_swu[depends] += "${PN}:do_transform_template"
>  do_image_swu[stamp-extra-info] = "${DISTRO}-${MACHINE}"
>  do_image_swu[cleandirs] += "${WORKDIR}/swu ${WORKDIR}/swu-${SWU_BOOTLOADER}"
> +do_image_swu[prefuncs] = "do_extend_sw_description"
>  IMAGE_CMD:swu() {
>      rm -f '${DEPLOY_DIR_IMAGE}/${SWU_IMAGE_FILE}'*.swu
>      cp '${WORKDIR}/${SWU_DESCRIPTION_FILE}' '${WORKDIR}/swu/${SWU_DESCRIPTION_FILE}'
> @@ -165,13 +178,14 @@ IMAGE_CMD:swu() {
>      for swu_file in "${WORKDIR}"/swu*; do
>          swu_file_base=$(basename $swu_file)
>          # Create symlinks for files used in the update image
> -        for file in ${SWU_ADDITIONAL_FILES}; do
> -            if grep -q "$file" "${WORKDIR}/$swu_file_base/${SWU_DESCRIPTION_FILE}"; then
> -                if [ -e "${WORKDIR}/$file" ]; then
> -                    ln -s "${PP_WORK}/$file" "${WORKDIR}/$swu_file_base/$file"
> -                else
> -                    ln -s "${PP_DEPLOY}/$file" "${WORKDIR}/$swu_file_base/$file"
> -                fi
> +        swu_files=$(awk '$1=="filename"{gsub(/[",;]/, "", $3); print $3}' \
> +            "${WORKDIR}/$swu_file_base/${SWU_DESCRIPTION_FILE}")
> +        export swu_files
> +        for file in $swu_files; do
> +            if [ -e "${WORKDIR}/$file" ]; then
> +                ln -s "${PP_WORK}/$file" "${WORKDIR}/$swu_file_base/$file"
> +            else
> +                ln -s "${PP_DEPLOY}/$file" "${WORKDIR}/$swu_file_base/$file"
>              fi
>          done
>  
> @@ -186,7 +200,7 @@ IMAGE_CMD:swu() {
>          export swu_file_extension
>          imager_run -p -d ${PP_WORK} -u root <<'EOIMAGER'
>              # Fill in file check sums
> -            for file in ${SWU_ADDITIONAL_FILES}; do
> +            for file in $swu_files; do
>                  sed -i "s:$file-sha256:$(sha256sum "${PP_WORK}/$swu_file_base/"$file | cut -f 1 -d " "):g" \
>                      "${PP_WORK}/$swu_file_base/${SWU_DESCRIPTION_FILE}"
>              done
> @@ -205,7 +219,7 @@ IMAGE_CMD:swu() {
>              fi
>  
>              # sw-description must be first file in *.swu
> -            for cpio_file in $cpio_files ${SWU_ADDITIONAL_FILES}; do
> +            for cpio_file in $cpio_files $swu_files; do
>                  if [ -f "$cpio_file" ]; then
>                      # Set file timestamps for reproducible builds
>                      if [ -n "${SOURCE_DATE_EPOCH}" ]; then

Jan
Gylstorff Quirin March 5, 2024, 2:34 p.m. UTC | #2
On 3/5/24 3:17 PM, Jan Kiszka wrote:
> On 05.03.24 12:02, Quirin Gylstorff wrote:
>> From: Quirin Gylstorff <quirin.gylstorff@siemens.com>
>>
>> Due to the use of an anonym python function each image recipe was
> 
> anonymous
> 
>> partial build even if not requested.
> 
> built
> 
>> To avoid this remove the anonym image function by adding
> 
> anonymous
> 
>> it as an prefunc to do_image_swu and do_transform_template.
>>
>> The SRC_URI is appended with a function.
>>
>> Signed-off-by: Quirin Gylstorff <quirin.gylstorff@siemens.com>
>> ---
>>   classes/efibootguard.bbclass |  1 -
>>   classes/swupdate.bbclass     | 42 ++++++++++++++++++++++++------------
>>   2 files changed, 28 insertions(+), 15 deletions(-)
>>
>> diff --git a/classes/efibootguard.bbclass b/classes/efibootguard.bbclass
>> index 31fcdcc..2b4f09e 100644
>> --- a/classes/efibootguard.bbclass
>> +++ b/classes/efibootguard.bbclass
>> @@ -67,5 +67,4 @@ python add_ebg_update(){
>>      ebg_update = d.getVar('SWU_EBG_UPDATE') or ""
>>      if ebg_update:
>>        d.appendVar('SWU_FILE_NODES', "," + swu_ebg_update_node)
> 
> Indention looks fishy, but that is nothing this patch caused.

I will fix it in a separate patch.

Quirin
> 
>> -   d.appendVar('SWU_ADDITIONAL_FILES', " " + efi_boot_loader_file)
>>   }
>> diff --git a/classes/swupdate.bbclass b/classes/swupdate.bbclass
>> index c62f43f..c82d20c 100644
>> --- a/classes/swupdate.bbclass
>> +++ b/classes/swupdate.bbclass
>> @@ -63,7 +63,7 @@ IMAGE_TEMPLATE_VARS:swu = " \
>>   # TARGET_IMAGE_UUID needs to be generated before completing the template
>>   addtask do_transform_template after do_generate_image_uuid
>>   
>> -python(){
>> +python do_extend_sw_description(){
> 
> () {
> 
>>       cmds = d.getVar("SWU_EXTEND_SW_DESCRIPTION")
>>       if cmds is None or not cmds.strip():
>>           return
>> @@ -71,6 +71,7 @@ python(){
>>       for cmd in cmds:
>>           bb.build.exec_func(cmd, d)
>>   }
>> +do_transform_template[prefuncs] += "do_extend_sw_description"
>>   
>>   SWU_EXTEND_SW_DESCRIPTION += "add_swu_hw_compat"
>>   python add_swu_hw_compat(){
>> @@ -94,9 +95,22 @@ python add_swu_compression(){
>>           d.setVar('SWU_COMPRESSION_NODE', '')
>>   }
>>   
>> +def add_scripts_to_src_uri(d):
>> +    swu_scripts = d.getVar('SWU_SCRIPTS')
>> +    if not swu_scripts:
>> +        return ""
>> +    swu_script_entries = swu_scripts.split()
>> +    script_file_list = []
>> +    for entry in swu_script_entries:
>> +        script_entry = f"SWU_SCRIPT_{entry}"
>> +        script_file = d.getVarFlag(script_entry, "file")
>> +        script_file_list.append(f" file://{script_file}")
>> +    return ' '.join([n for n in script_file_list])
>>   
>> -SWU_EXTEND_SW_DESCRIPTION += "add_scripts"
>> -python add_scripts(){
>> +SRC_URI += "${@add_scripts_to_src_uri(d)}"
>> +
>> +SWU_EXTEND_SW_DESCRIPTION += "add_scripts_node"
>> +python add_scripts_node(){
>>       swu_scripts = d.getVar('SWU_SCRIPTS')
>>       if not swu_scripts:
>>           return
>> @@ -129,8 +143,6 @@ python add_scripts(){
>>             sha256 = "{script_file}-sha256";
>>           }}"""
>>           script_node_list.append(node)
>> -        d.appendVar('SWU_ADDITIONAL_FILES', " " + script_file)
>> -        d.appendVar('SRC_URI', f" file://{script_file}")
>>   
>>       swu_scripts_node = "scripts: (" + ','.join([n for n in script_node_list]) + ");"
>>       d.appendVar('SWU_SCRIPTS_NODE', swu_scripts_node)
>> @@ -155,6 +167,7 @@ FILESEXTRAPATHS:append = ":${LAYERDIR_cip-core}/recipes-core/images/swu"
>>   do_image_swu[depends] += "${PN}:do_transform_template"
>>   do_image_swu[stamp-extra-info] = "${DISTRO}-${MACHINE}"
>>   do_image_swu[cleandirs] += "${WORKDIR}/swu ${WORKDIR}/swu-${SWU_BOOTLOADER}"
>> +do_image_swu[prefuncs] = "do_extend_sw_description"
>>   IMAGE_CMD:swu() {
>>       rm -f '${DEPLOY_DIR_IMAGE}/${SWU_IMAGE_FILE}'*.swu
>>       cp '${WORKDIR}/${SWU_DESCRIPTION_FILE}' '${WORKDIR}/swu/${SWU_DESCRIPTION_FILE}'
>> @@ -165,13 +178,14 @@ IMAGE_CMD:swu() {
>>       for swu_file in "${WORKDIR}"/swu*; do
>>           swu_file_base=$(basename $swu_file)
>>           # Create symlinks for files used in the update image
>> -        for file in ${SWU_ADDITIONAL_FILES}; do
>> -            if grep -q "$file" "${WORKDIR}/$swu_file_base/${SWU_DESCRIPTION_FILE}"; then
>> -                if [ -e "${WORKDIR}/$file" ]; then
>> -                    ln -s "${PP_WORK}/$file" "${WORKDIR}/$swu_file_base/$file"
>> -                else
>> -                    ln -s "${PP_DEPLOY}/$file" "${WORKDIR}/$swu_file_base/$file"
>> -                fi
>> +        swu_files=$(awk '$1=="filename"{gsub(/[",;]/, "", $3); print $3}' \
>> +            "${WORKDIR}/$swu_file_base/${SWU_DESCRIPTION_FILE}")
>> +        export swu_files
>> +        for file in $swu_files; do
>> +            if [ -e "${WORKDIR}/$file" ]; then
>> +                ln -s "${PP_WORK}/$file" "${WORKDIR}/$swu_file_base/$file"
>> +            else
>> +                ln -s "${PP_DEPLOY}/$file" "${WORKDIR}/$swu_file_base/$file"
>>               fi
>>           done
>>   
>> @@ -186,7 +200,7 @@ IMAGE_CMD:swu() {
>>           export swu_file_extension
>>           imager_run -p -d ${PP_WORK} -u root <<'EOIMAGER'
>>               # Fill in file check sums
>> -            for file in ${SWU_ADDITIONAL_FILES}; do
>> +            for file in $swu_files; do
>>                   sed -i "s:$file-sha256:$(sha256sum "${PP_WORK}/$swu_file_base/"$file | cut -f 1 -d " "):g" \
>>                       "${PP_WORK}/$swu_file_base/${SWU_DESCRIPTION_FILE}"
>>               done
>> @@ -205,7 +219,7 @@ IMAGE_CMD:swu() {
>>               fi
>>   
>>               # sw-description must be first file in *.swu
>> -            for cpio_file in $cpio_files ${SWU_ADDITIONAL_FILES}; do
>> +            for cpio_file in $cpio_files $swu_files; do
>>                   if [ -f "$cpio_file" ]; then
>>                       # Set file timestamps for reproducible builds
>>                       if [ -n "${SOURCE_DATE_EPOCH}" ]; then
> 
> Jan
>
diff mbox series

Patch

diff --git a/classes/efibootguard.bbclass b/classes/efibootguard.bbclass
index 31fcdcc..2b4f09e 100644
--- a/classes/efibootguard.bbclass
+++ b/classes/efibootguard.bbclass
@@ -67,5 +67,4 @@  python add_ebg_update(){
    ebg_update = d.getVar('SWU_EBG_UPDATE') or ""
    if ebg_update:
      d.appendVar('SWU_FILE_NODES', "," + swu_ebg_update_node)
-   d.appendVar('SWU_ADDITIONAL_FILES', " " + efi_boot_loader_file)
 }
diff --git a/classes/swupdate.bbclass b/classes/swupdate.bbclass
index c62f43f..c82d20c 100644
--- a/classes/swupdate.bbclass
+++ b/classes/swupdate.bbclass
@@ -63,7 +63,7 @@  IMAGE_TEMPLATE_VARS:swu = " \
 # TARGET_IMAGE_UUID needs to be generated before completing the template
 addtask do_transform_template after do_generate_image_uuid
 
-python(){
+python do_extend_sw_description(){
     cmds = d.getVar("SWU_EXTEND_SW_DESCRIPTION")
     if cmds is None or not cmds.strip():
         return
@@ -71,6 +71,7 @@  python(){
     for cmd in cmds:
         bb.build.exec_func(cmd, d)
 }
+do_transform_template[prefuncs] += "do_extend_sw_description"
 
 SWU_EXTEND_SW_DESCRIPTION += "add_swu_hw_compat"
 python add_swu_hw_compat(){
@@ -94,9 +95,22 @@  python add_swu_compression(){
         d.setVar('SWU_COMPRESSION_NODE', '')
 }
 
+def add_scripts_to_src_uri(d):
+    swu_scripts = d.getVar('SWU_SCRIPTS')
+    if not swu_scripts:
+        return ""
+    swu_script_entries = swu_scripts.split()
+    script_file_list = []
+    for entry in swu_script_entries:
+        script_entry = f"SWU_SCRIPT_{entry}"
+        script_file = d.getVarFlag(script_entry, "file")
+        script_file_list.append(f" file://{script_file}")
+    return ' '.join([n for n in script_file_list])
 
-SWU_EXTEND_SW_DESCRIPTION += "add_scripts"
-python add_scripts(){
+SRC_URI += "${@add_scripts_to_src_uri(d)}"
+
+SWU_EXTEND_SW_DESCRIPTION += "add_scripts_node"
+python add_scripts_node(){
     swu_scripts = d.getVar('SWU_SCRIPTS')
     if not swu_scripts:
         return
@@ -129,8 +143,6 @@  python add_scripts(){
           sha256 = "{script_file}-sha256";
         }}"""
         script_node_list.append(node)
-        d.appendVar('SWU_ADDITIONAL_FILES', " " + script_file)
-        d.appendVar('SRC_URI', f" file://{script_file}")
 
     swu_scripts_node = "scripts: (" + ','.join([n for n in script_node_list]) + ");"
     d.appendVar('SWU_SCRIPTS_NODE', swu_scripts_node)
@@ -155,6 +167,7 @@  FILESEXTRAPATHS:append = ":${LAYERDIR_cip-core}/recipes-core/images/swu"
 do_image_swu[depends] += "${PN}:do_transform_template"
 do_image_swu[stamp-extra-info] = "${DISTRO}-${MACHINE}"
 do_image_swu[cleandirs] += "${WORKDIR}/swu ${WORKDIR}/swu-${SWU_BOOTLOADER}"
+do_image_swu[prefuncs] = "do_extend_sw_description"
 IMAGE_CMD:swu() {
     rm -f '${DEPLOY_DIR_IMAGE}/${SWU_IMAGE_FILE}'*.swu
     cp '${WORKDIR}/${SWU_DESCRIPTION_FILE}' '${WORKDIR}/swu/${SWU_DESCRIPTION_FILE}'
@@ -165,13 +178,14 @@  IMAGE_CMD:swu() {
     for swu_file in "${WORKDIR}"/swu*; do
         swu_file_base=$(basename $swu_file)
         # Create symlinks for files used in the update image
-        for file in ${SWU_ADDITIONAL_FILES}; do
-            if grep -q "$file" "${WORKDIR}/$swu_file_base/${SWU_DESCRIPTION_FILE}"; then
-                if [ -e "${WORKDIR}/$file" ]; then
-                    ln -s "${PP_WORK}/$file" "${WORKDIR}/$swu_file_base/$file"
-                else
-                    ln -s "${PP_DEPLOY}/$file" "${WORKDIR}/$swu_file_base/$file"
-                fi
+        swu_files=$(awk '$1=="filename"{gsub(/[",;]/, "", $3); print $3}' \
+            "${WORKDIR}/$swu_file_base/${SWU_DESCRIPTION_FILE}")
+        export swu_files
+        for file in $swu_files; do
+            if [ -e "${WORKDIR}/$file" ]; then
+                ln -s "${PP_WORK}/$file" "${WORKDIR}/$swu_file_base/$file"
+            else
+                ln -s "${PP_DEPLOY}/$file" "${WORKDIR}/$swu_file_base/$file"
             fi
         done
 
@@ -186,7 +200,7 @@  IMAGE_CMD:swu() {
         export swu_file_extension
         imager_run -p -d ${PP_WORK} -u root <<'EOIMAGER'
             # Fill in file check sums
-            for file in ${SWU_ADDITIONAL_FILES}; do
+            for file in $swu_files; do
                 sed -i "s:$file-sha256:$(sha256sum "${PP_WORK}/$swu_file_base/"$file | cut -f 1 -d " "):g" \
                     "${PP_WORK}/$swu_file_base/${SWU_DESCRIPTION_FILE}"
             done
@@ -205,7 +219,7 @@  IMAGE_CMD:swu() {
             fi
 
             # sw-description must be first file in *.swu
-            for cpio_file in $cpio_files ${SWU_ADDITIONAL_FILES}; do
+            for cpio_file in $cpio_files $swu_files; do
                 if [ -f "$cpio_file" ]; then
                     # Set file timestamps for reproducible builds
                     if [ -n "${SOURCE_DATE_EPOCH}" ]; then