From 917f491c5f5b3d1ec61c76e9c03987e89315adbc Mon Sep 17 00:00:00 2001 From: Samuel Dolt Date: Mon, 15 May 2023 17:51:50 +0200 Subject: [PATCH] feat(coreos-image-swupdate.bbclass): add a way to dynamically extends the sw-description files The COREOS_SWUPDATE_EXTENDS_FOR and COREOS_IMAGE_SWUPDATE_EXTRACLASSES variable can now be used to configure the coreos-image-swupdate to dynamically extends some part of the sw-description by calling some python function --- .../classes/coreos-image-swupdate.bbclass | 35 +++++++++++++++++++ .../meta-belden-coreos/files/sw-description | 18 ++++++++++ 2 files changed, 53 insertions(+) diff --git a/layers/meta-belden-coreos/classes/coreos-image-swupdate.bbclass b/layers/meta-belden-coreos/classes/coreos-image-swupdate.bbclass index dca81fd..56cfd4d 100644 --- a/layers/meta-belden-coreos/classes/coreos-image-swupdate.bbclass +++ b/layers/meta-belden-coreos/classes/coreos-image-swupdate.bbclass @@ -38,3 +38,38 @@ python () { } FILESEXTRAPATHS:append := ":${COREOS_ROOT}/layers/meta-belden-coreos/files" + +# Space seperated list of extension points +COREOS_SWUPDATE_EXTENDS_FOR ??= "" + +def coreos_swupdate_extends(d, s, key): + """ + Extends the swupdate for each extension points defined by COREOS_SWUPDATE_EXTENDS_FOR + """ + extends_for = d.getVar('COREOS_SWUPDATE_EXTENDS_FOR', True).replace("-", "_").split() + + def kv_to_sw_description(kv): + swdescr = ",{\n" + for key, value in kv.items(): + swdescr += f'{key} = "{value}";\n' + swdescr += "}\n" + return swdescr + + text = "" + + # BSP and Distro can extends the swupdate by implementing some python + # function that return a list of dictionary. + for extension_point in extends_for: + try: + kv_list = globals()[f"coreos_swupdate_extends_{key}_for_{extension_point}"](d,s) + except KeyError: + # Don't fail if the extension is not implemented + pass + else: + for kv in kv_list: + text += kv_to_sw_description(kv) + + return text + +COREOS_IMAGE_SWUPDATE_EXTRACLASSES ?= "" +inherit ${COREOS_IMAGE_SWUPDATE_EXTRACLASSES} diff --git a/layers/meta-belden-coreos/files/sw-description b/layers/meta-belden-coreos/files/sw-description index b018fee..f19bf9f 100644 --- a/layers/meta-belden-coreos/files/sw-description +++ b/layers/meta-belden-coreos/files/sw-description @@ -16,6 +16,9 @@ software = type = "raw"; sha256 = "$swupdate_get_sha256(@@PN@@-@@MACHINE@@.ext4.zst)"; } + # Don't remove the trailing whitspace on the next line otherwise + # it will not work due to a regex bug in meta-swupdate + $coreos_swupdate_extends(images) ); files: ( @@ -33,6 +36,9 @@ software = filesystem = "vfat"; sha256 = "$swupdate_get_sha256(@@COREOS_EFIBOOTGUARD_FILENAME@@)"; } + # Don't remove the trailing whitspace on the next line otherwise + # it will not work due to a regex bug in meta-swupdate + $coreos_swupdate_extends(files) ); bootenv: ( @@ -49,6 +55,9 @@ software = value = "C:BOOT0:KERNEL.EFI"; } + # Don't remove the trailing whitspace on the next line otherwise + # it will not work due to a regex bug in meta-swupdate + $coreos_swupdate_extends(bootenv) ); } @@ -64,6 +73,9 @@ software = type = "raw"; sha256 = "$swupdate_get_sha256(@@PN@@-@@MACHINE@@.ext4.zst)"; } + # Don't remove the trailing whitspace on the next line otherwise + # it will not work due to a regex bug in meta-swupdate + $coreos_swupdate_extends(images) ); files: ( @@ -81,6 +93,9 @@ software = filesystem = "vfat"; sha256 = "$swupdate_get_sha256(@@COREOS_EFIBOOTGUARD_FILENAME@@)"; } + # Don't remove the trailing whitspace on the next line otherwise + # it will not work due to a regex bug in meta-swupdate + $coreos_swupdate_extends(files) ); bootenv: ( { @@ -96,6 +111,9 @@ software = value = "C:BOOT1:KERNEL.EFI"; } + # Don't remove the trailing whitspace on the next line otherwise + # it will not work due to a regex bug in meta-swupdate + $coreos_swupdate_extends(bootenv) ); } }