Message ID | 20230425033246.1199444-2-felix.moessbauer@siemens.com (mailing list archive) |
---|---|
State | Accepted |
Headers | show |
Series | [isar-cip-core,1/2] refactor deploy of OVMF binaries | expand |
On 25.04.23 05:32, Felix Moessbauer wrote: > For some targets, dedicated firmware is compiled and copied into the > DEPLOY_DIR_IMAGE. Instead of implementing this logic for each firmware > individually, we move the common logic into a class and inherit. > > This reduces the amount of code duplication and simplifies the maintenance. > > Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com> > --- > classes/deploy-firmware.bbclass | 32 +++++++++++++++++++++++ > recipes-bsp/opensbi/opensbi.inc | 16 ++---------- > recipes-bsp/u-boot/u-boot-qemu-common.inc | 18 +++---------- > 3 files changed, 37 insertions(+), 29 deletions(-) > create mode 100644 classes/deploy-firmware.bbclass > > diff --git a/classes/deploy-firmware.bbclass b/classes/deploy-firmware.bbclass > new file mode 100644 > index 0000000..a4b754a > --- /dev/null > +++ b/classes/deploy-firmware.bbclass > @@ -0,0 +1,32 @@ > +# > +# CIP Core, generic profile > +# > +# Copyright (c) Siemens AG, 2023 > +# > +# Authors: > +# Felix Moessbauer <felix.moessbauer@siemens.com> > +# > +# SPDX-License-Identifier: MIT > +# > +# This class adds a mechanism to deploy files to the DEPLOY_DIR_IMAGE > +# directory. Simply overwrite the deploy_firmware task and copy the > +# to-be-deployed files into DEPLOYDIR_FIRMWARE. > + > +inherit dpkg-base > + > +DEPLOYDIR_FIRMWARE = "${WORKDIR}/deploy-fw" > +SSTATETASKS += "do_deploy_firmware" > + > +do_deploy_firmware[cleandirs] += "${DEPLOYDIR_FIRMWARE}" > +do_deploy_firmware[sstate-inputdirs] = "${DEPLOYDIR_FIRMWARE}" > +do_deploy_firmware[sstate-outputdirs] = "${DEPLOY_DIR_IMAGE}" > +do_deploy_firmware() { > + die "This should never be called, overwrite it in your derived class" > +} > + > +python do_deploy_firmware_setscene () { > + sstate_setscene(d) > +} > +addtask do_deploy_firmware_setscene > + > +addtask deploy_firmware after do_dpkg_build before do_deploy_deb > diff --git a/recipes-bsp/opensbi/opensbi.inc b/recipes-bsp/opensbi/opensbi.inc > index 0108231..6d84026 100644 > --- a/recipes-bsp/opensbi/opensbi.inc > +++ b/recipes-bsp/opensbi/opensbi.inc > @@ -4,13 +4,11 @@ > # SPDX-License-Identifier: MIT > > inherit dpkg > +inherit deploy-firmware > > U_BOOT_PACKAGE ?= "u-boot-${MACHINE}" > PLATFORM ?= "generic" > > -DEPLOYDIR_FIRMWARE = "${WORKDIR}/deploy-fw" > -SSTATETASKS += "do_deploy" > - > SRC_URI = " \ > https://github.com/riscv/opensbi/archive/v${PV}.tar.gz;downloadfilename=opensbi-${PV}.tar.gz;name=opensbi" > > @@ -27,18 +25,8 @@ do_prepare_build() { > echo "build/platform/${PLATFORM}/firmware/fw_payload.bin /usr/lib/opensbi/${MACHINE}/" > ${S}/debian/install > } > > -do_deploy[cleandirs] += "${DEPLOYDIR_FIRMWARE}" > -do_deploy[sstate-inputdirs] = "${DEPLOYDIR_FIRMWARE}" > -do_deploy[sstate-outputdirs] = "${DEPLOY_DIR_IMAGE}" > -do_deploy() { > +do_deploy_firmware() { > dpkg --fsys-tarfile "${WORKDIR}/${PN}_${PV}_${DISTRO_ARCH}.deb" | \ > tar xOf - "./usr/lib/opensbi/${MACHINE}/fw_payload.bin" \ > > "${DEPLOYDIR_FIRMWARE}/fw_payload.bin" > } > - > -python do_deploy_setscene () { > - sstate_setscene(d) > -} > -addtask do_deploy_setscene > - > -addtask deploy after do_dpkg_build before do_deploy_deb > diff --git a/recipes-bsp/u-boot/u-boot-qemu-common.inc b/recipes-bsp/u-boot/u-boot-qemu-common.inc > index 4d8b240..b222155 100644 > --- a/recipes-bsp/u-boot/u-boot-qemu-common.inc > +++ b/recipes-bsp/u-boot/u-boot-qemu-common.inc > @@ -9,25 +9,13 @@ > # SPDX-License-Identifier: MIT > # > > +inherit deploy-firmware > require recipes-bsp/u-boot/u-boot-common.inc > > U_BOOT_BIN = "u-boot.bin" > > -DEPLOYDIR_U_BOOT = "${WORKDIR}/deploy-u-boot" > -SSTATETASKS += "do_deploy" > - > -do_deploy[cleandirs] += "${DEPLOYDIR_U_BOOT}" > -do_deploy[sstate-inputdirs] = "${DEPLOYDIR_U_BOOT}" > -do_deploy[sstate-outputdirs] = "${DEPLOY_DIR_IMAGE}" > -do_deploy() { > +do_deploy_firmware() { > dpkg --fsys-tarfile "${WORKDIR}/u-boot-${MACHINE}_${PV}_${DISTRO_ARCH}.deb" | \ > tar xOf - "./usr/lib/u-boot/${MACHINE}/${U_BOOT_BIN}" \ > - > "${DEPLOYDIR_U_BOOT}/firmware.bin" > -} > - > -python do_deploy_setscene () { > - sstate_setscene(d) > + > "${DEPLOYDIR_FIRMWARE}/firmware.bin" > } > -addtask do_deploy_setscene > - > -addtask deploy after do_dpkg_build before do_deploy_deb Thanks, both applied. Jan
diff --git a/classes/deploy-firmware.bbclass b/classes/deploy-firmware.bbclass new file mode 100644 index 0000000..a4b754a --- /dev/null +++ b/classes/deploy-firmware.bbclass @@ -0,0 +1,32 @@ +# +# CIP Core, generic profile +# +# Copyright (c) Siemens AG, 2023 +# +# Authors: +# Felix Moessbauer <felix.moessbauer@siemens.com> +# +# SPDX-License-Identifier: MIT +# +# This class adds a mechanism to deploy files to the DEPLOY_DIR_IMAGE +# directory. Simply overwrite the deploy_firmware task and copy the +# to-be-deployed files into DEPLOYDIR_FIRMWARE. + +inherit dpkg-base + +DEPLOYDIR_FIRMWARE = "${WORKDIR}/deploy-fw" +SSTATETASKS += "do_deploy_firmware" + +do_deploy_firmware[cleandirs] += "${DEPLOYDIR_FIRMWARE}" +do_deploy_firmware[sstate-inputdirs] = "${DEPLOYDIR_FIRMWARE}" +do_deploy_firmware[sstate-outputdirs] = "${DEPLOY_DIR_IMAGE}" +do_deploy_firmware() { + die "This should never be called, overwrite it in your derived class" +} + +python do_deploy_firmware_setscene () { + sstate_setscene(d) +} +addtask do_deploy_firmware_setscene + +addtask deploy_firmware after do_dpkg_build before do_deploy_deb diff --git a/recipes-bsp/opensbi/opensbi.inc b/recipes-bsp/opensbi/opensbi.inc index 0108231..6d84026 100644 --- a/recipes-bsp/opensbi/opensbi.inc +++ b/recipes-bsp/opensbi/opensbi.inc @@ -4,13 +4,11 @@ # SPDX-License-Identifier: MIT inherit dpkg +inherit deploy-firmware U_BOOT_PACKAGE ?= "u-boot-${MACHINE}" PLATFORM ?= "generic" -DEPLOYDIR_FIRMWARE = "${WORKDIR}/deploy-fw" -SSTATETASKS += "do_deploy" - SRC_URI = " \ https://github.com/riscv/opensbi/archive/v${PV}.tar.gz;downloadfilename=opensbi-${PV}.tar.gz;name=opensbi" @@ -27,18 +25,8 @@ do_prepare_build() { echo "build/platform/${PLATFORM}/firmware/fw_payload.bin /usr/lib/opensbi/${MACHINE}/" > ${S}/debian/install } -do_deploy[cleandirs] += "${DEPLOYDIR_FIRMWARE}" -do_deploy[sstate-inputdirs] = "${DEPLOYDIR_FIRMWARE}" -do_deploy[sstate-outputdirs] = "${DEPLOY_DIR_IMAGE}" -do_deploy() { +do_deploy_firmware() { dpkg --fsys-tarfile "${WORKDIR}/${PN}_${PV}_${DISTRO_ARCH}.deb" | \ tar xOf - "./usr/lib/opensbi/${MACHINE}/fw_payload.bin" \ > "${DEPLOYDIR_FIRMWARE}/fw_payload.bin" } - -python do_deploy_setscene () { - sstate_setscene(d) -} -addtask do_deploy_setscene - -addtask deploy after do_dpkg_build before do_deploy_deb diff --git a/recipes-bsp/u-boot/u-boot-qemu-common.inc b/recipes-bsp/u-boot/u-boot-qemu-common.inc index 4d8b240..b222155 100644 --- a/recipes-bsp/u-boot/u-boot-qemu-common.inc +++ b/recipes-bsp/u-boot/u-boot-qemu-common.inc @@ -9,25 +9,13 @@ # SPDX-License-Identifier: MIT # +inherit deploy-firmware require recipes-bsp/u-boot/u-boot-common.inc U_BOOT_BIN = "u-boot.bin" -DEPLOYDIR_U_BOOT = "${WORKDIR}/deploy-u-boot" -SSTATETASKS += "do_deploy" - -do_deploy[cleandirs] += "${DEPLOYDIR_U_BOOT}" -do_deploy[sstate-inputdirs] = "${DEPLOYDIR_U_BOOT}" -do_deploy[sstate-outputdirs] = "${DEPLOY_DIR_IMAGE}" -do_deploy() { +do_deploy_firmware() { dpkg --fsys-tarfile "${WORKDIR}/u-boot-${MACHINE}_${PV}_${DISTRO_ARCH}.deb" | \ tar xOf - "./usr/lib/u-boot/${MACHINE}/${U_BOOT_BIN}" \ - > "${DEPLOYDIR_U_BOOT}/firmware.bin" -} - -python do_deploy_setscene () { - sstate_setscene(d) + > "${DEPLOYDIR_FIRMWARE}/firmware.bin" } -addtask do_deploy_setscene - -addtask deploy after do_dpkg_build before do_deploy_deb
For some targets, dedicated firmware is compiled and copied into the DEPLOY_DIR_IMAGE. Instead of implementing this logic for each firmware individually, we move the common logic into a class and inherit. This reduces the amount of code duplication and simplifies the maintenance. Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com> --- classes/deploy-firmware.bbclass | 32 +++++++++++++++++++++++ recipes-bsp/opensbi/opensbi.inc | 16 ++---------- recipes-bsp/u-boot/u-boot-qemu-common.inc | 18 +++---------- 3 files changed, 37 insertions(+), 29 deletions(-) create mode 100644 classes/deploy-firmware.bbclass