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
This commit is contained in:
Samuel Dolt 2023-05-15 17:51:50 +02:00
parent fb4702780b
commit 518c651ef9
3 changed files with 53 additions and 15 deletions

View File

@ -1,15 +0,0 @@
# MBR disk are still supported by CoreOS, but only for legacy product
# This ensure that efibootguard / swupdate work with MBR disk
# MBR can't disk can't use partition label, but may use filesystem label
# This will only work with an initramfs. If no initramfs is used, this will
# have to be set to the right disk device inside the machine configuration
# like that COREOS_PLATFORMx_ROOT = "/dev/mmcblk<DISK>p<PART>"
COREOS_PLATFORM0_ROOT ?= "LABEL=platform0"
COREOS_PLATFORM1_ROOT ?= "LABEL=platform1"
# MBR disk can't use --part-type but can use system-id
WKS_PART_EFI ?= 'part --source efibootguard-efi --label efi --system-id 0xef'
WKS_PART_EFIBOOTGUARD_A ?= 'part --source efibootguard-boot --label boot0 --sourceparams "watchdog=${EFIBOOTGUARD_TIMEOUT},revision=2,kernel=kernel0-${MACHINE}.efi;KERNEL0.EFI"'
WKS_PART_EFIBOOTGUARD_B ?= 'part --source efibootguard-boot --label boot1 --sourceparams "watchdog=${EFIBOOTGUARD_TIMEOUT},revision=1,kernel=kernel1-${MACHINE}.efi;KERNEL1.EFI"'

View File

@ -38,3 +38,38 @@ python () {
} }
FILESEXTRAPATHS:append := ":${COREOS_ROOT}/layers/meta-belden-coreos/files" 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}

View File

@ -16,6 +16,9 @@ software =
type = "raw"; type = "raw";
sha256 = "$swupdate_get_sha256(@@PN@@-@@MACHINE@@.ext4.zst)"; 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: ( files: (
@ -33,6 +36,9 @@ software =
filesystem = "vfat"; filesystem = "vfat";
sha256 = "$swupdate_get_sha256(@@COREOS_EFIBOOTGUARD_FILENAME@@)"; 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: ( bootenv: (
@ -49,6 +55,9 @@ software =
value = "C:BOOT0:KERNEL.EFI"; 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"; type = "raw";
sha256 = "$swupdate_get_sha256(@@PN@@-@@MACHINE@@.ext4.zst)"; 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: ( files: (
@ -81,6 +93,9 @@ software =
filesystem = "vfat"; filesystem = "vfat";
sha256 = "$swupdate_get_sha256(@@COREOS_EFIBOOTGUARD_FILENAME@@)"; 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: ( bootenv: (
{ {
@ -96,6 +111,9 @@ software =
value = "C:BOOT1:KERNEL.EFI"; 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)
); );
} }
} }