diff mbox series

[cip-dec,isar-cip-core,RFC,v2,3/3] swupdate: Extend sw-description to update efibootguard

Message ID 20231211122528.486786-4-Quirin.Gylstorff@siemens.com (mailing list archive)
State Superseded
Headers show
Series Add Bootloader to Update binary | expand

Commit Message

Gylstorff Quirin Dec. 11, 2023, 12:19 p.m. UTC
From: Quirin Gylstorff <quirin.gylstorff@siemens.com>

If the variable `SWU_EBG_UPDATE` is set to `1` an additional file
element is added to the sw-description to replace the ebg.

Use python as newlines are part of the sw-description syntax an
therefore cannot be hold in a bitbake variable, see note in[1].

IMPORTANT: Even if the property 'atomic-install' is set FAT does not
support atomic writes or renames so a powercut can still corrupt the
system[1].

[1]: https://docs.yoctoproject.org/bitbake/2.2/bitbake-user-manual/bitbake-user-manual-metadata.html#line-joining
[2]: https://lore.kernel.org/linux-fsdevel/20191022105413.pj6i3ydetnfgnkzh@pali/

Signed-off-by: Quirin Gylstorff <quirin.gylstorff@siemens.com>
---
 classes/swupdate.bbclass                    | 35 +++++++++++++++++++--
 recipes-core/images/swu/sw-description.tmpl |  2 +-
 2 files changed, 34 insertions(+), 3 deletions(-)

Comments

Jan Kiszka Dec. 11, 2023, 1:45 p.m. UTC | #1
On 11.12.23 13:19, Quirin Gylstorff wrote:
> From: Quirin Gylstorff <quirin.gylstorff@siemens.com>
> 
> If the variable `SWU_EBG_UPDATE` is set to `1` an additional file
> element is added to the sw-description to replace the ebg.
> 
> Use python as newlines are part of the sw-description syntax an
> therefore cannot be hold in a bitbake variable, see note in[1].
> 
> IMPORTANT: Even if the property 'atomic-install' is set FAT does not
> support atomic writes or renames so a powercut can still corrupt the
> system[1].

"system[2]".

But you are not implementing option B described there, just the even
more risky option C. Doing flushes before the renaming and after it
should reduce - though not eliminate - the corruption window.

> 
> [1]: https://docs.yoctoproject.org/bitbake/2.2/bitbake-user-manual/bitbake-user-manual-metadata.html#line-joining
> [2]: https://lore.kernel.org/linux-fsdevel/20191022105413.pj6i3ydetnfgnkzh@pali/
> 
> Signed-off-by: Quirin Gylstorff <quirin.gylstorff@siemens.com>
> ---
>  classes/swupdate.bbclass                    | 35 +++++++++++++++++++--
>  recipes-core/images/swu/sw-description.tmpl |  2 +-
>  2 files changed, 34 insertions(+), 3 deletions(-)
> 
> diff --git a/classes/swupdate.bbclass b/classes/swupdate.bbclass
> index 0e95e3c..99a4c6f 100644
> --- a/classes/swupdate.bbclass
> +++ b/classes/swupdate.bbclass
> @@ -21,7 +21,8 @@ SWU_VERSION ?= "0.2"
>  SWU_NAME ?= "cip software update"
>  # space separated list of supported hw. Leave empty to leave out
>  SWU_HW_COMPAT ?= ""
> -
> +SWU_EBG_UPDATE ?= ""
> +SWU_EFI_BOOT_DEVICE ?= "/dev/disk/by-uuid/4321-DCBA"
>  
>  SWU_IMAGE_FILE ?= "${DEPLOY_DIR_IMAGE}/${IMAGE_FULLNAME}.swu"
>  SWU_DESCRIPTION_FILE ?= "sw-description"
> @@ -48,7 +49,9 @@ IMAGE_TEMPLATE_VARS:swu = " \
>      SWU_HW_COMPAT_NODE \
>      SWU_COMPRESSION_NODE \
>      SWU_VERSION \
> -    SWU_NAME"
> +    SWU_NAME \
> +    SWU_FILE_NODES \
> +    "
>  
>  # TARGET_IMAGE_UUID needs to be generated before completing the template
>  addtask do_transform_template after do_generate_image_uuid
> @@ -84,6 +87,34 @@ python add_swu_compression(){
>          d.setVar('SWU_COMPRESSION_NODE', '')
>  }
>  
> +SWU_EXTEND_SW_DESCRIPTION += "${@ 'add_ebg_update' if d.getVar('SWU_EBG_UPDATE') == '1' else ''}"
> +python add_ebg_update(){
> +    distro_arch = d.getVar('DISTRO_ARCH')
> +    distro_to_efi_arch = {
> +            "amd64": "x64",
> +            "arm64": "aa64",
> +            "armhf": "arm",
> +            "i386": "ia32",
> +            "riscv64": "riscv64"
> +    }
> +    efi_boot_loader_file = "boot{}.efi".format(distro_to_efi_arch[distro_arch])
> +    efi_boot_device = d.getVar('SWU_EFI_BOOT_DEVICE')
> +    swu_ebg_update_node = f""",
> +    {{
> +           filename = "{efi_boot_loader_file}";
> +           path = "EFI/BOOT/{efi_boot_loader_file}";
> +           device = "{efi_boot_device}";
> +           filesystem = "vfat";
> +           sha256 = "{efi_boot_loader_file}-sha256";
> +           properties: {{
> +                atomic-install = true;
> +           }};
> +    }}
> +    """
> +    d.appendVar('SWU_FILE_NODES', swu_ebg_update_node)
> +    d.appendVar('SWU_ADDITIONAL_FILES', " " + efi_boot_loader_file)
> +}
> +

Unneeded newline here.

>  
>  # convert between swupdate compressor name and imagetype extension
>  def get_swu_compression_type(d):
> diff --git a/recipes-core/images/swu/sw-description.tmpl b/recipes-core/images/swu/sw-description.tmpl
> index 6b53a3c..c52372c 100644
> --- a/recipes-core/images/swu/sw-description.tmpl
> +++ b/recipes-core/images/swu/sw-description.tmpl
> @@ -34,5 +34,5 @@ software =
>                          subtype = "kernel";
>              };
>              sha256 = "linux.efi-sha256";
> -    });
> +    }${SWU_FILE_NODES});
>  }

Jan
Jan Kiszka Dec. 11, 2023, 1:46 p.m. UTC | #2
On 11.12.23 14:45, Jan Kiszka wrote:
> On 11.12.23 13:19, Quirin Gylstorff wrote:
>> From: Quirin Gylstorff <quirin.gylstorff@siemens.com>
>>
>> If the variable `SWU_EBG_UPDATE` is set to `1` an additional file
>> element is added to the sw-description to replace the ebg.
>>
>> Use python as newlines are part of the sw-description syntax an
>> therefore cannot be hold in a bitbake variable, see note in[1].
>>
>> IMPORTANT: Even if the property 'atomic-install' is set FAT does not
>> support atomic writes or renames so a powercut can still corrupt the
>> system[1].
> 
> "system[2]".
> 
> But you are not implementing option B described there, just the even
> more risky option C. Doing flushes before the renaming and after it
> should reduce - though not eliminate - the corruption window.
> 
>>
>> [1]: https://docs.yoctoproject.org/bitbake/2.2/bitbake-user-manual/bitbake-user-manual-metadata.html#line-joining
>> [2]: https://lore.kernel.org/linux-fsdevel/20191022105413.pj6i3ydetnfgnkzh@pali/
>>
>> Signed-off-by: Quirin Gylstorff <quirin.gylstorff@siemens.com>
>> ---
>>  classes/swupdate.bbclass                    | 35 +++++++++++++++++++--
>>  recipes-core/images/swu/sw-description.tmpl |  2 +-
>>  2 files changed, 34 insertions(+), 3 deletions(-)
>>
>> diff --git a/classes/swupdate.bbclass b/classes/swupdate.bbclass
>> index 0e95e3c..99a4c6f 100644
>> --- a/classes/swupdate.bbclass
>> +++ b/classes/swupdate.bbclass
>> @@ -21,7 +21,8 @@ SWU_VERSION ?= "0.2"
>>  SWU_NAME ?= "cip software update"
>>  # space separated list of supported hw. Leave empty to leave out
>>  SWU_HW_COMPAT ?= ""
>> -
>> +SWU_EBG_UPDATE ?= ""
>> +SWU_EFI_BOOT_DEVICE ?= "/dev/disk/by-uuid/4321-DCBA"

Oh, and where does this UUID come from? Is it a wic default?

Jan

>>  
>>  SWU_IMAGE_FILE ?= "${DEPLOY_DIR_IMAGE}/${IMAGE_FULLNAME}.swu"
>>  SWU_DESCRIPTION_FILE ?= "sw-description"
>> @@ -48,7 +49,9 @@ IMAGE_TEMPLATE_VARS:swu = " \
>>      SWU_HW_COMPAT_NODE \
>>      SWU_COMPRESSION_NODE \
>>      SWU_VERSION \
>> -    SWU_NAME"
>> +    SWU_NAME \
>> +    SWU_FILE_NODES \
>> +    "
>>  
>>  # TARGET_IMAGE_UUID needs to be generated before completing the template
>>  addtask do_transform_template after do_generate_image_uuid
>> @@ -84,6 +87,34 @@ python add_swu_compression(){
>>          d.setVar('SWU_COMPRESSION_NODE', '')
>>  }
>>  
>> +SWU_EXTEND_SW_DESCRIPTION += "${@ 'add_ebg_update' if d.getVar('SWU_EBG_UPDATE') == '1' else ''}"
>> +python add_ebg_update(){
>> +    distro_arch = d.getVar('DISTRO_ARCH')
>> +    distro_to_efi_arch = {
>> +            "amd64": "x64",
>> +            "arm64": "aa64",
>> +            "armhf": "arm",
>> +            "i386": "ia32",
>> +            "riscv64": "riscv64"
>> +    }
>> +    efi_boot_loader_file = "boot{}.efi".format(distro_to_efi_arch[distro_arch])
>> +    efi_boot_device = d.getVar('SWU_EFI_BOOT_DEVICE')
>> +    swu_ebg_update_node = f""",
>> +    {{
>> +           filename = "{efi_boot_loader_file}";
>> +           path = "EFI/BOOT/{efi_boot_loader_file}";
>> +           device = "{efi_boot_device}";
>> +           filesystem = "vfat";
>> +           sha256 = "{efi_boot_loader_file}-sha256";
>> +           properties: {{
>> +                atomic-install = true;
>> +           }};
>> +    }}
>> +    """
>> +    d.appendVar('SWU_FILE_NODES', swu_ebg_update_node)
>> +    d.appendVar('SWU_ADDITIONAL_FILES', " " + efi_boot_loader_file)
>> +}
>> +
> 
> Unneeded newline here.
> 
>>  
>>  # convert between swupdate compressor name and imagetype extension
>>  def get_swu_compression_type(d):
>> diff --git a/recipes-core/images/swu/sw-description.tmpl b/recipes-core/images/swu/sw-description.tmpl
>> index 6b53a3c..c52372c 100644
>> --- a/recipes-core/images/swu/sw-description.tmpl
>> +++ b/recipes-core/images/swu/sw-description.tmpl
>> @@ -34,5 +34,5 @@ software =
>>                          subtype = "kernel";
>>              };
>>              sha256 = "linux.efi-sha256";
>> -    });
>> +    }${SWU_FILE_NODES});
>>  }
> 
> Jan
>
Gylstorff Quirin Dec. 11, 2023, 2:07 p.m. UTC | #3
On 12/11/23 14:45, Jan Kiszka wrote:
> On 11.12.23 13:19, Quirin Gylstorff wrote:
>> From: Quirin Gylstorff <quirin.gylstorff@siemens.com>
>>
>> If the variable `SWU_EBG_UPDATE` is set to `1` an additional file
>> element is added to the sw-description to replace the ebg.
>>
>> Use python as newlines are part of the sw-description syntax an
>> therefore cannot be hold in a bitbake variable, see note in[1].
>>
>> IMPORTANT: Even if the property 'atomic-install' is set FAT does not
>> support atomic writes or renames so a powercut can still corrupt the
>> system[1].
> 
> "system[2]".
> 
> But you are not implementing option B described there, just the even
> more risky option C. Doing flushes before the renaming and after it
> should reduce - though not eliminate - the corruption window.

swupdate installs files the property `atomic-install` with option B

copy file to tmp path:
https://github.com/sbabic/swupdate/blob/37d13dc2eef557f9bbd10a85ddfc7ba4384740fb/handlers/raw_handler.c#L185

fsync
https://github.com/sbabic/swupdate/blob/37d13dc2eef557f9bbd10a85ddfc7ba4384740fb/handlers/raw_handler.c#L222

rename
https://github.com/sbabic/swupdate/blob/37d13dc2eef557f9bbd10a85ddfc7ba4384740fb/handlers/raw_handler.c#L233

If this is unclear a will add some additional comment to the patch.

Quirin

> 
>>
>> [1]: https://docs.yoctoproject.org/bitbake/2.2/bitbake-user-manual/bitbake-user-manual-metadata.html#line-joining
>> [2]: https://lore.kernel.org/linux-fsdevel/20191022105413.pj6i3ydetnfgnkzh@pali/
>>
>> Signed-off-by: Quirin Gylstorff <quirin.gylstorff@siemens.com>
>> ---
>>   classes/swupdate.bbclass                    | 35 +++++++++++++++++++--
>>   recipes-core/images/swu/sw-description.tmpl |  2 +-
>>   2 files changed, 34 insertions(+), 3 deletions(-)
>>
>> diff --git a/classes/swupdate.bbclass b/classes/swupdate.bbclass
>> index 0e95e3c..99a4c6f 100644
>> --- a/classes/swupdate.bbclass
>> +++ b/classes/swupdate.bbclass
>> @@ -21,7 +21,8 @@ SWU_VERSION ?= "0.2"
>>   SWU_NAME ?= "cip software update"
>>   # space separated list of supported hw. Leave empty to leave out
>>   SWU_HW_COMPAT ?= ""
>> -
>> +SWU_EBG_UPDATE ?= ""
>> +SWU_EFI_BOOT_DEVICE ?= "/dev/disk/by-uuid/4321-DCBA"
>>   
>>   SWU_IMAGE_FILE ?= "${DEPLOY_DIR_IMAGE}/${IMAGE_FULLNAME}.swu"
>>   SWU_DESCRIPTION_FILE ?= "sw-description"
>> @@ -48,7 +49,9 @@ IMAGE_TEMPLATE_VARS:swu = " \
>>       SWU_HW_COMPAT_NODE \
>>       SWU_COMPRESSION_NODE \
>>       SWU_VERSION \
>> -    SWU_NAME"
>> +    SWU_NAME \
>> +    SWU_FILE_NODES \
>> +    "
>>   
>>   # TARGET_IMAGE_UUID needs to be generated before completing the template
>>   addtask do_transform_template after do_generate_image_uuid
>> @@ -84,6 +87,34 @@ python add_swu_compression(){
>>           d.setVar('SWU_COMPRESSION_NODE', '')
>>   }
>>   
>> +SWU_EXTEND_SW_DESCRIPTION += "${@ 'add_ebg_update' if d.getVar('SWU_EBG_UPDATE') == '1' else ''}"
>> +python add_ebg_update(){
>> +    distro_arch = d.getVar('DISTRO_ARCH')
>> +    distro_to_efi_arch = {
>> +            "amd64": "x64",
>> +            "arm64": "aa64",
>> +            "armhf": "arm",
>> +            "i386": "ia32",
>> +            "riscv64": "riscv64"
>> +    }
>> +    efi_boot_loader_file = "boot{}.efi".format(distro_to_efi_arch[distro_arch])
>> +    efi_boot_device = d.getVar('SWU_EFI_BOOT_DEVICE')
>> +    swu_ebg_update_node = f""",
>> +    {{
>> +           filename = "{efi_boot_loader_file}";
>> +           path = "EFI/BOOT/{efi_boot_loader_file}";
>> +           device = "{efi_boot_device}";
>> +           filesystem = "vfat";
>> +           sha256 = "{efi_boot_loader_file}-sha256";
>> +           properties: {{
>> +                atomic-install = true;
>> +           }};
>> +    }}
>> +    """
>> +    d.appendVar('SWU_FILE_NODES', swu_ebg_update_node)
>> +    d.appendVar('SWU_ADDITIONAL_FILES', " " + efi_boot_loader_file)
>> +}
>> +
> 
> Unneeded newline here.
> 
>>   
>>   # convert between swupdate compressor name and imagetype extension
>>   def get_swu_compression_type(d):
>> diff --git a/recipes-core/images/swu/sw-description.tmpl b/recipes-core/images/swu/sw-description.tmpl
>> index 6b53a3c..c52372c 100644
>> --- a/recipes-core/images/swu/sw-description.tmpl
>> +++ b/recipes-core/images/swu/sw-description.tmpl
>> @@ -34,5 +34,5 @@ software =
>>                           subtype = "kernel";
>>               };
>>               sha256 = "linux.efi-sha256";
>> -    });
>> +    }${SWU_FILE_NODES});
>>   }
> 
> Jan
>
Gylstorff Quirin Dec. 11, 2023, 2:10 p.m. UTC | #4
On 12/11/23 14:46, Jan Kiszka wrote:
> On 11.12.23 14:45, Jan Kiszka wrote:
>> On 11.12.23 13:19, Quirin Gylstorff wrote:
>>> From: Quirin Gylstorff <quirin.gylstorff@siemens.com>
>>>
>>> If the variable `SWU_EBG_UPDATE` is set to `1` an additional file
>>> element is added to the sw-description to replace the ebg.
>>>
>>> Use python as newlines are part of the sw-description syntax an
>>> therefore cannot be hold in a bitbake variable, see note in[1].
>>>
>>> IMPORTANT: Even if the property 'atomic-install' is set FAT does not
>>> support atomic writes or renames so a powercut can still corrupt the
>>> system[1].
>>
>> "system[2]".
>>
>> But you are not implementing option B described there, just the even
>> more risky option C. Doing flushes before the renaming and after it
>> should reduce - though not eliminate - the corruption window.
>>
>>>
>>> [1]: https://docs.yoctoproject.org/bitbake/2.2/bitbake-user-manual/bitbake-user-manual-metadata.html#line-joining
>>> [2]: https://lore.kernel.org/linux-fsdevel/20191022105413.pj6i3ydetnfgnkzh@pali/
>>>
>>> Signed-off-by: Quirin Gylstorff <quirin.gylstorff@siemens.com>
>>> ---
>>>   classes/swupdate.bbclass                    | 35 +++++++++++++++++++--
>>>   recipes-core/images/swu/sw-description.tmpl |  2 +-
>>>   2 files changed, 34 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/classes/swupdate.bbclass b/classes/swupdate.bbclass
>>> index 0e95e3c..99a4c6f 100644
>>> --- a/classes/swupdate.bbclass
>>> +++ b/classes/swupdate.bbclass
>>> @@ -21,7 +21,8 @@ SWU_VERSION ?= "0.2"
>>>   SWU_NAME ?= "cip software update"
>>>   # space separated list of supported hw. Leave empty to leave out
>>>   SWU_HW_COMPAT ?= ""
>>> -
>>> +SWU_EBG_UPDATE ?= ""
>>> +SWU_EFI_BOOT_DEVICE ?= "/dev/disk/by-uuid/4321-DCBA"
> 
> Oh, and where does this UUID come from? Is it a wic default?

It was added with 
https://gitlab.com/cip-project/cip-core/isar-cip-core/-/commit/b1bc585877549dabca78873f6bada730cd56cf71

Quirin
> 
> Jan
> 
>>>   
>>>   SWU_IMAGE_FILE ?= "${DEPLOY_DIR_IMAGE}/${IMAGE_FULLNAME}.swu"
>>>   SWU_DESCRIPTION_FILE ?= "sw-description"
>>> @@ -48,7 +49,9 @@ IMAGE_TEMPLATE_VARS:swu = " \
>>>       SWU_HW_COMPAT_NODE \
>>>       SWU_COMPRESSION_NODE \
>>>       SWU_VERSION \
>>> -    SWU_NAME"
>>> +    SWU_NAME \
>>> +    SWU_FILE_NODES \
>>> +    "
>>>   
>>>   # TARGET_IMAGE_UUID needs to be generated before completing the template
>>>   addtask do_transform_template after do_generate_image_uuid
>>> @@ -84,6 +87,34 @@ python add_swu_compression(){
>>>           d.setVar('SWU_COMPRESSION_NODE', '')
>>>   }
>>>   
>>> +SWU_EXTEND_SW_DESCRIPTION += "${@ 'add_ebg_update' if d.getVar('SWU_EBG_UPDATE') == '1' else ''}"
>>> +python add_ebg_update(){
>>> +    distro_arch = d.getVar('DISTRO_ARCH')
>>> +    distro_to_efi_arch = {
>>> +            "amd64": "x64",
>>> +            "arm64": "aa64",
>>> +            "armhf": "arm",
>>> +            "i386": "ia32",
>>> +            "riscv64": "riscv64"
>>> +    }
>>> +    efi_boot_loader_file = "boot{}.efi".format(distro_to_efi_arch[distro_arch])
>>> +    efi_boot_device = d.getVar('SWU_EFI_BOOT_DEVICE')
>>> +    swu_ebg_update_node = f""",
>>> +    {{
>>> +           filename = "{efi_boot_loader_file}";
>>> +           path = "EFI/BOOT/{efi_boot_loader_file}";
>>> +           device = "{efi_boot_device}";
>>> +           filesystem = "vfat";
>>> +           sha256 = "{efi_boot_loader_file}-sha256";
>>> +           properties: {{
>>> +                atomic-install = true;
>>> +           }};
>>> +    }}
>>> +    """
>>> +    d.appendVar('SWU_FILE_NODES', swu_ebg_update_node)
>>> +    d.appendVar('SWU_ADDITIONAL_FILES', " " + efi_boot_loader_file)
>>> +}
>>> +
>>
>> Unneeded newline here.
>>
>>>   
>>>   # convert between swupdate compressor name and imagetype extension
>>>   def get_swu_compression_type(d):
>>> diff --git a/recipes-core/images/swu/sw-description.tmpl b/recipes-core/images/swu/sw-description.tmpl
>>> index 6b53a3c..c52372c 100644
>>> --- a/recipes-core/images/swu/sw-description.tmpl
>>> +++ b/recipes-core/images/swu/sw-description.tmpl
>>> @@ -34,5 +34,5 @@ software =
>>>                           subtype = "kernel";
>>>               };
>>>               sha256 = "linux.efi-sha256";
>>> -    });
>>> +    }${SWU_FILE_NODES});
>>>   }
>>
>> Jan
>>
>
Jan Kiszka Dec. 11, 2023, 2:56 p.m. UTC | #5
On 11.12.23 15:07, Gylstorff Quirin wrote:
> 
> 
> On 12/11/23 14:45, Jan Kiszka wrote:
>> On 11.12.23 13:19, Quirin Gylstorff wrote:
>>> From: Quirin Gylstorff <quirin.gylstorff@siemens.com>
>>>
>>> If the variable `SWU_EBG_UPDATE` is set to `1` an additional file
>>> element is added to the sw-description to replace the ebg.
>>>
>>> Use python as newlines are part of the sw-description syntax an
>>> therefore cannot be hold in a bitbake variable, see note in[1].
>>>
>>> IMPORTANT: Even if the property 'atomic-install' is set FAT does not
>>> support atomic writes or renames so a powercut can still corrupt the
>>> system[1].
>>
>> "system[2]".
>>
>> But you are not implementing option B described there, just the even
>> more risky option C. Doing flushes before the renaming and after it
>> should reduce - though not eliminate - the corruption window.
> 
> swupdate installs files the property `atomic-install` with option B
> 
> copy file to tmp path:
> https://github.com/sbabic/swupdate/blob/37d13dc2eef557f9bbd10a85ddfc7ba4384740fb/handlers/raw_handler.c#L185
> 
> fsync
> https://github.com/sbabic/swupdate/blob/37d13dc2eef557f9bbd10a85ddfc7ba4384740fb/handlers/raw_handler.c#L222
> 
> rename
> https://github.com/sbabic/swupdate/blob/37d13dc2eef557f9bbd10a85ddfc7ba4384740fb/handlers/raw_handler.c#L233
> 
> If this is unclear a will add some additional comment to the patch.
> 

Ah, that would be good.

Jan
Jan Kiszka Dec. 11, 2023, 2:57 p.m. UTC | #6
On 11.12.23 15:10, Gylstorff Quirin wrote:
> 
> 
> On 12/11/23 14:46, Jan Kiszka wrote:
>> On 11.12.23 14:45, Jan Kiszka wrote:
>>> On 11.12.23 13:19, Quirin Gylstorff wrote:
>>>> From: Quirin Gylstorff <quirin.gylstorff@siemens.com>
>>>>
>>>> If the variable `SWU_EBG_UPDATE` is set to `1` an additional file
>>>> element is added to the sw-description to replace the ebg.
>>>>
>>>> Use python as newlines are part of the sw-description syntax an
>>>> therefore cannot be hold in a bitbake variable, see note in[1].
>>>>
>>>> IMPORTANT: Even if the property 'atomic-install' is set FAT does not
>>>> support atomic writes or renames so a powercut can still corrupt the
>>>> system[1].
>>>
>>> "system[2]".
>>>
>>> But you are not implementing option B described there, just the even
>>> more risky option C. Doing flushes before the renaming and after it
>>> should reduce - though not eliminate - the corruption window.
>>>
>>>>
>>>> [1]:
>>>> https://docs.yoctoproject.org/bitbake/2.2/bitbake-user-manual/bitbake-user-manual-metadata.html#line-joining
>>>> [2]:
>>>> https://lore.kernel.org/linux-fsdevel/20191022105413.pj6i3ydetnfgnkzh@pali/
>>>>
>>>> Signed-off-by: Quirin Gylstorff <quirin.gylstorff@siemens.com>
>>>> ---
>>>>   classes/swupdate.bbclass                    | 35
>>>> +++++++++++++++++++--
>>>>   recipes-core/images/swu/sw-description.tmpl |  2 +-
>>>>   2 files changed, 34 insertions(+), 3 deletions(-)
>>>>
>>>> diff --git a/classes/swupdate.bbclass b/classes/swupdate.bbclass
>>>> index 0e95e3c..99a4c6f 100644
>>>> --- a/classes/swupdate.bbclass
>>>> +++ b/classes/swupdate.bbclass
>>>> @@ -21,7 +21,8 @@ SWU_VERSION ?= "0.2"
>>>>   SWU_NAME ?= "cip software update"
>>>>   # space separated list of supported hw. Leave empty to leave out
>>>>   SWU_HW_COMPAT ?= ""
>>>> -
>>>> +SWU_EBG_UPDATE ?= ""
>>>> +SWU_EFI_BOOT_DEVICE ?= "/dev/disk/by-uuid/4321-DCBA"
>>
>> Oh, and where does this UUID come from? Is it a wic default?
> 
> It was added with
> https://gitlab.com/cip-project/cip-core/isar-cip-core/-/commit/b1bc585877549dabca78873f6bada730cd56cf71
> 

Thanks - was searching for the wrong string.

Jan
diff mbox series

Patch

diff --git a/classes/swupdate.bbclass b/classes/swupdate.bbclass
index 0e95e3c..99a4c6f 100644
--- a/classes/swupdate.bbclass
+++ b/classes/swupdate.bbclass
@@ -21,7 +21,8 @@  SWU_VERSION ?= "0.2"
 SWU_NAME ?= "cip software update"
 # space separated list of supported hw. Leave empty to leave out
 SWU_HW_COMPAT ?= ""
-
+SWU_EBG_UPDATE ?= ""
+SWU_EFI_BOOT_DEVICE ?= "/dev/disk/by-uuid/4321-DCBA"
 
 SWU_IMAGE_FILE ?= "${DEPLOY_DIR_IMAGE}/${IMAGE_FULLNAME}.swu"
 SWU_DESCRIPTION_FILE ?= "sw-description"
@@ -48,7 +49,9 @@  IMAGE_TEMPLATE_VARS:swu = " \
     SWU_HW_COMPAT_NODE \
     SWU_COMPRESSION_NODE \
     SWU_VERSION \
-    SWU_NAME"
+    SWU_NAME \
+    SWU_FILE_NODES \
+    "
 
 # TARGET_IMAGE_UUID needs to be generated before completing the template
 addtask do_transform_template after do_generate_image_uuid
@@ -84,6 +87,34 @@  python add_swu_compression(){
         d.setVar('SWU_COMPRESSION_NODE', '')
 }
 
+SWU_EXTEND_SW_DESCRIPTION += "${@ 'add_ebg_update' if d.getVar('SWU_EBG_UPDATE') == '1' else ''}"
+python add_ebg_update(){
+    distro_arch = d.getVar('DISTRO_ARCH')
+    distro_to_efi_arch = {
+            "amd64": "x64",
+            "arm64": "aa64",
+            "armhf": "arm",
+            "i386": "ia32",
+            "riscv64": "riscv64"
+    }
+    efi_boot_loader_file = "boot{}.efi".format(distro_to_efi_arch[distro_arch])
+    efi_boot_device = d.getVar('SWU_EFI_BOOT_DEVICE')
+    swu_ebg_update_node = f""",
+    {{
+           filename = "{efi_boot_loader_file}";
+           path = "EFI/BOOT/{efi_boot_loader_file}";
+           device = "{efi_boot_device}";
+           filesystem = "vfat";
+           sha256 = "{efi_boot_loader_file}-sha256";
+           properties: {{
+                atomic-install = true;
+           }};
+    }}
+    """
+    d.appendVar('SWU_FILE_NODES', swu_ebg_update_node)
+    d.appendVar('SWU_ADDITIONAL_FILES', " " + efi_boot_loader_file)
+}
+
 
 # convert between swupdate compressor name and imagetype extension
 def get_swu_compression_type(d):
diff --git a/recipes-core/images/swu/sw-description.tmpl b/recipes-core/images/swu/sw-description.tmpl
index 6b53a3c..c52372c 100644
--- a/recipes-core/images/swu/sw-description.tmpl
+++ b/recipes-core/images/swu/sw-description.tmpl
@@ -34,5 +34,5 @@  software =
                         subtype = "kernel";
             };
             sha256 = "linux.efi-sha256";
-    });
+    }${SWU_FILE_NODES});
 }