Andrew Geissler | 9347dd4 | 2023-03-03 12:38:41 -0600 | [diff] [blame^] | 1 | # This class generates UEFI capsules |
| 2 | # The current class supports generating a capsule with single firmware binary |
| 3 | |
| 4 | DEPENDS += "gettext-native" |
| 5 | inherit python3native |
| 6 | |
| 7 | IMAGE_TYPES += "uefi_capsule" |
| 8 | |
| 9 | # edk2 base tools should be installed in the native sysroot directory |
| 10 | do_image_uefi_capsule[depends] += "edk2-basetools-native:do_populate_sysroot" |
| 11 | |
| 12 | # By default the wic image is used to create a capsule |
| 13 | CAPSULE_IMGTYPE ?= "wic" |
| 14 | |
| 15 | # IMGDEPLOYDIR is used as the default location of firmware binary for which the capsule needs to be created |
| 16 | CAPSULE_IMGLOCATION ?= "${IMGDEPLOYDIR}" |
| 17 | |
| 18 | # The generated capsule by default has uefi.capsule extension |
| 19 | CAPSULE_EXTENSION ?= "uefi.capsule" |
| 20 | |
| 21 | # The following variables must be set to be able to generate a capsule update |
| 22 | UEFI_FIRMWARE_BINARY ?= "" |
| 23 | UEFI_CAPSULE_CONFIG ?= "" |
| 24 | |
| 25 | # Check if the required variables are set |
| 26 | python() { |
| 27 | for var in ["UEFI_FIRMWARE_BINARY", "UEFI_CAPSULE_CONFIG"]: |
| 28 | if not d.getVar(var): |
| 29 | raise bb.parse.SkipRecipe(f"{var} not set") |
| 30 | } |
| 31 | |
| 32 | IMAGE_CMD:uefi_capsule(){ |
| 33 | |
| 34 | # Force the GenerateCapsule script to use python3 |
| 35 | export PYTHON_COMMAND=${PYTHON} |
| 36 | |
| 37 | # Copy the firmware and the capsule config json to current directory |
| 38 | if [ -e ${CAPSULE_IMGLOCATION}/${UEFI_FIRMWARE_BINARY} ]; then |
| 39 | cp ${CAPSULE_IMGLOCATION}/${UEFI_FIRMWARE_BINARY} . ; |
| 40 | fi |
| 41 | |
| 42 | export UEFI_FIRMWARE_BINARY=${UEFI_FIRMWARE_BINARY} |
| 43 | envsubst < ${UEFI_CAPSULE_CONFIG} > ./${MACHINE}-capsule-update-image.json |
| 44 | |
| 45 | ${STAGING_DIR_NATIVE}/usr/bin/edk2-BaseTools/BinWrappers/PosixLike/GenerateCapsule \ |
| 46 | -e -o ${IMGDEPLOYDIR}/${UEFI_FIRMWARE_BINARY}.${CAPSULE_EXTENSION} -j \ |
| 47 | ${MACHINE}-capsule-update-image.json |
| 48 | |
| 49 | # Remove the firmware to avoid contamination of IMGDEPLOYDIR |
| 50 | rm ${UEFI_FIRMWARE_BINARY} |
| 51 | |
| 52 | } |
| 53 | |
| 54 | # The firmware binary should be created before generating the capsule |
| 55 | IMAGE_TYPEDEP:uefi_capsule:append = "${CAPSULE_IMGTYPE}" |