Skip to content

Instantly share code, notes, and snippets.

@dbouras
Last active April 13, 2022 16:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbouras/4018fcdc5084dcb20fb460ee7b71a2e8 to your computer and use it in GitHub Desktop.
Save dbouras/4018fcdc5084dcb20fb460ee7b71a2e8 to your computer and use it in GitHub Desktop.
Patching local files before they're added into a SWU CPIO archive
# Copyright (C) 2022 Dimitri Bouras <dimitrios.bouras@gmail.com>
# Released under the MIT license (see COPYING.MIT for the terms)
DESCRIPTION = "Example for patching recipe-specific scripts at package build-time"
SECTION = ""
PV = "1.0"
PR = "r0"
# Note: sw-description is mandatory
SRC_URI_example-imx6ul = "file://sw-description \
file://partition.sh \
file://chgroup.sh \
file://led-blink.sh \
"
inherit swupdate
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
# IMAGE_DEPENDS: list of images that include a root filesystem,
# ensuring they are built before creating the swupdate package
IMAGE_DEPENDS = "os-image"
DEPENDS += "u-boot-script"
# SWUPDATE_IMAGES: list of images and binary files that will be part
# of the compound image - images must be in the DEPLOY directory.
# There's nothing stopping us from adding scripts as images: this is
# a workaround for patching scripts during package build time. Note
# the removal of the ".sh" extension for scripts added in this way.
SWUPDATE_IMAGES = " \
os-image \
boot.scr \
u-boot \
itbImage\
chgroup \
led-blink \
"
# Images may have multiple formats so define the format selected for the
# compound image. Note the ".sh" extension for scripts added as images.
SWUPDATE_IMAGES_FSTYPES[os-image] = ".cpio.gz.u-boot"
SWUPDATE_IMAGES_FSTYPES[u-boot] = ".imx-emmc"
SWUPDATE_IMAGES_FSTYPES[itbImage] = ".bin"
#
SWUPDATE_IMAGES_FSTYPES[chgroup] = ".sh"
SWUPDATE_IMAGES_FSTYPES[led-blink] = ".sh"
# Indicate that $MACHINE should not be appended to script files
# added to the SWU CPIO package via SWUPDATE_IMAGES.
SWUPDATE_IMAGES_NOAPPEND_MACHINE[chgroup] = "true"
SWUPDATE_IMAGES_NOAPPEND_MACHINE[led-blink] = "true"
# Patching files in $WORKDIR has meaning only for sw-description as
# this is the only file do_swupdate copies from $WORKDIR; it copies
# all other files directly from their SRC_URI location so patching
# in $WORKDIR has no effect.
# By adding the scripts we want to patch to SWUPDATE_IMAGES, we instruct
# do_swupdate to copy them from $DEPLOY_DIR_IMAGE. Then we save patched
# script output in ${DEPLOY_DIR_IMAGE}/<script name>.
# do_swupdate will then overwrite the non-patched scripts copied from
# SRC_URI with the patched ones from $DEPLOY_DIR_IMAGE.
do_patchswupdate() {
# sw-decription is OK in $WORKDIR
sed -i -e 's/__VERSION__/${PV}-${PR}/g' ${WORKDIR}/sw-description
# the rest must go in $DEPLOY_DIR_IMAGE
sed -e 's/__UPDATEGROUP__/postmfg/g' ${WORKDIR}/chgroup.sh > ${DEPLOY_DIR_IMAGE}/chgroup.sh
sed -e 's/__LEDNO__/2/g' ${WORKDIR}/led-blink.sh > ${DEPLOY_DIR_IMAGE}/led-blink.sh
}
# run do_patchswupdate unconditionally before do_swuimage, not just after do_unpack
addtask do_patchswupdate before do_swuimage after do_unpack
do_patchswupdate[nostamp] = "1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment