Message ID | 20191029100113.27287-3-adrian.freihofer@siemens.com |
---|---|
State | Changes Requested |
Headers | show |
Series | simplify swupdate config | expand |
Hi Adrian, On 29/10/19 11:01, Adrian Freihofer wrote: > Try to make the swupdate.bbclass a little bit smarter in finding the > image files added to the swu archive. The implementation is also a bit > more Yocto like. By default, files are searched automatically whereas > MACHINE specific files get priority over files without the MACHINE in > the filename. > This makes the SWUPDATE_IMAGES_NOAPPEND_MACHINE VarFlag more optional. > Most standard use cases are expected to "just work" without setting > this flag. Agree - and I have never seen a case where both files (with and without MACHINE in name) are in DEPLOYDIR. I introduced SWUPDATE_IMAGES_NOAPPEND_MACHINE as a trick for some files, typically kernel (uIMage), but it is much better if the recipe finds itself the correct one. > > Add support for files in a sub-folder of DEPLOY_DIR_IMAGE. > > Add documentation to the header of the swupdate.bbclass file. > > Signed-off-by: Adrian Freihofer <adrian.freihofer@siemens.com> > --- > classes/swupdate.bbclass | 77 +++++++++++++++++++++++++++++++++--------------- > 1 file changed, 54 insertions(+), 23 deletions(-) > > diff --git a/classes/swupdate.bbclass b/classes/swupdate.bbclass > index 1d74eef..79c9aae 100644 > --- a/classes/swupdate.bbclass > +++ b/classes/swupdate.bbclass > @@ -7,10 +7,30 @@ > # in field. > # See also http://sbabic.github.io/swupdate/ > # > +# To use this class, add swupdate to the inherit clause of the update image bb file. > +# The generated output file is an swu archive ready to be uploaded to a device running > +# swupdate. > # > -# To use, add swupdate to the inherit clause and set > -# set the images (all of them must be found in deploy directory) > -# that are part of the compound image. > +# Files listed in the SRC_URI variable are added the the swu archive. > +# > +# For each entry in the SWUPDATE_IMAGES variable an image file is searched for in the > +# ${DEPLOY_DIR_IMAGE} folder and added to the swu archive. Different types of entries > +# are supported: > +# * image name(s) and fstype(s): > +# Example: > +# SWUPDATE_IMAGES = "core-image-full-cmdline" > +# SWUPDATE_IMAGES_FSTYPES[core-image-full-cmdline] = ".ext4.gz" > +# For this example either a file core-image-full-cmdline-${MACHINE}.ext4.gz or a file > +# core-image-full-cmdline.ext4.gz gets added the swu archive. Optionally the variable > +# SWUPDATE_IMAGES_NOAPPEND_MACHINE allows to explicitley define if the MACHINE name > +# must be part of the image file name or not. > +# * image file name(s) > +# Example: > +# SWUPDATE_IMAGES = "core-image-full-cmdline.ext4.gz" > +# If SWUPDATE_IMAGES_FSTYPES is not defined for an entry in SWUPDATE_IMAGES or the > +# corresponding image files cannot be found in the ${DEPLOY_DIR_IMAGE} folder, an > +# image file with exactly the name as specified in SWUPDATE_IMAGES is searched for. > + > inherit swupdate-common.bbclass > > S = "${WORKDIR}/${PN}" > @@ -74,6 +94,7 @@ python do_swuimage () { > if d.getVar('SWUPDATE_SIGNING', True): > list_for_cpio.append('sw-description.sig') > > + # Add files listed in SRC_URI to the swu file > for url in fetch.urls: > local = fetch.localpath(url) > filename = os.path.basename(local) > @@ -81,30 +102,40 @@ python do_swuimage () { > shutil.copyfile(local, os.path.join(s, "%s" % filename )) > list_for_cpio.append(filename) > > -# SWUPDATE_IMAGES refers to images in the DEPLOY directory > -# If they are not there, additional file can be added > -# by fetching from URLs > + def add_image_to_swu(deploydir, imagename, s): > + src = os.path.join(deploydir, imagename) > + if not os.path.isfile(src): > + return False > + target_imagename = os.path.basename(imagename) # allow images in subfolders of DEPLOY_DIR_IMAGE > + dst = os.path.join(s, target_imagename) > + shutil.copyfile(src, dst) > + list_for_cpio.append(target_imagename) > + return True > + > + # Search for images listed in SWUPDATE_IMAGES in the DEPLOY directory. > deploydir = d.getVar('DEPLOY_DIR_IMAGE', True) > imgdeploydir = d.getVar('IMGDEPLOYDIR', True) > - > for image in images: > fstypes = (d.getVarFlag("SWUPDATE_IMAGES_FSTYPES", image, True) or "").split() > - if not fstypes: > - fstypes = [""] > - > - for fstype in fstypes: > - > - appendmachine = d.getVarFlag("SWUPDATE_IMAGES_NOAPPEND_MACHINE", image, True) > - if appendmachine == None: > - imagebase = image + '-' + d.getVar('MACHINE', True) > - else: > - imagebase = image > - > - imagename = imagebase + fstype > - src = os.path.join(deploydir, "%s" % imagename) > - dst = os.path.join(s, "%s" % imagename) > - shutil.copyfile(src, dst) > - list_for_cpio.append(imagename) > + if fstypes: > + noappend_machine = d.getVarFlag("SWUPDATE_IMAGES_NOAPPEND_MACHINE", image, True) > + if noappend_machine == False: # Search for a file explicitely with MACHINE > + imagebases = [ image + '-' + d.getVar('MACHINE', True) ] > + elif noappend_machine == True: # Search for a file explicitely without MACHINE > + imagebases = [ image ] > + else: # None, means auto mode. Just try to find an image file with MACHINE or without MACHINE > + imagebases = [ image + '-' + d.getVar('MACHINE', True), image ] > + for fstype in fstypes: > + image_found = False > + for imagebase in imagebases: > + image_found = add_image_to_swu(deploydir, imagebase + fstype, s) > + if image_found: > + break > + if not image_found: > + bb.fatal("swupdate cannot find image file: %s" % os.path.join(deploydir, imagebase + fstype)) > + else: # Allow also complete entries like "image.ext4.gz" in SWUPDATE_IMAGES > + if not add_image_to_swu(deploydir, image, s): > + bb.fatal("swupdate cannot find %s image file" % image) > > prepare_sw_description(d, s, list_for_cpio) > > Looks great for me. Acked-by: Stefano Babic <sbabic@denx.de> Best regards, Stefano Babic
diff --git a/classes/swupdate.bbclass b/classes/swupdate.bbclass index 1d74eef..79c9aae 100644 --- a/classes/swupdate.bbclass +++ b/classes/swupdate.bbclass @@ -7,10 +7,30 @@ # in field. # See also http://sbabic.github.io/swupdate/ # +# To use this class, add swupdate to the inherit clause of the update image bb file. +# The generated output file is an swu archive ready to be uploaded to a device running +# swupdate. # -# To use, add swupdate to the inherit clause and set -# set the images (all of them must be found in deploy directory) -# that are part of the compound image. +# Files listed in the SRC_URI variable are added the the swu archive. +# +# For each entry in the SWUPDATE_IMAGES variable an image file is searched for in the +# ${DEPLOY_DIR_IMAGE} folder and added to the swu archive. Different types of entries +# are supported: +# * image name(s) and fstype(s): +# Example: +# SWUPDATE_IMAGES = "core-image-full-cmdline" +# SWUPDATE_IMAGES_FSTYPES[core-image-full-cmdline] = ".ext4.gz" +# For this example either a file core-image-full-cmdline-${MACHINE}.ext4.gz or a file +# core-image-full-cmdline.ext4.gz gets added the swu archive. Optionally the variable +# SWUPDATE_IMAGES_NOAPPEND_MACHINE allows to explicitley define if the MACHINE name +# must be part of the image file name or not. +# * image file name(s) +# Example: +# SWUPDATE_IMAGES = "core-image-full-cmdline.ext4.gz" +# If SWUPDATE_IMAGES_FSTYPES is not defined for an entry in SWUPDATE_IMAGES or the +# corresponding image files cannot be found in the ${DEPLOY_DIR_IMAGE} folder, an +# image file with exactly the name as specified in SWUPDATE_IMAGES is searched for. + inherit swupdate-common.bbclass S = "${WORKDIR}/${PN}" @@ -74,6 +94,7 @@ python do_swuimage () { if d.getVar('SWUPDATE_SIGNING', True): list_for_cpio.append('sw-description.sig') + # Add files listed in SRC_URI to the swu file for url in fetch.urls: local = fetch.localpath(url) filename = os.path.basename(local) @@ -81,30 +102,40 @@ python do_swuimage () { shutil.copyfile(local, os.path.join(s, "%s" % filename )) list_for_cpio.append(filename) -# SWUPDATE_IMAGES refers to images in the DEPLOY directory -# If they are not there, additional file can be added -# by fetching from URLs + def add_image_to_swu(deploydir, imagename, s): + src = os.path.join(deploydir, imagename) + if not os.path.isfile(src): + return False + target_imagename = os.path.basename(imagename) # allow images in subfolders of DEPLOY_DIR_IMAGE + dst = os.path.join(s, target_imagename) + shutil.copyfile(src, dst) + list_for_cpio.append(target_imagename) + return True + + # Search for images listed in SWUPDATE_IMAGES in the DEPLOY directory. deploydir = d.getVar('DEPLOY_DIR_IMAGE', True) imgdeploydir = d.getVar('IMGDEPLOYDIR', True) - for image in images: fstypes = (d.getVarFlag("SWUPDATE_IMAGES_FSTYPES", image, True) or "").split() - if not fstypes: - fstypes = [""] - - for fstype in fstypes: - - appendmachine = d.getVarFlag("SWUPDATE_IMAGES_NOAPPEND_MACHINE", image, True) - if appendmachine == None: - imagebase = image + '-' + d.getVar('MACHINE', True) - else: - imagebase = image - - imagename = imagebase + fstype - src = os.path.join(deploydir, "%s" % imagename) - dst = os.path.join(s, "%s" % imagename) - shutil.copyfile(src, dst) - list_for_cpio.append(imagename) + if fstypes: + noappend_machine = d.getVarFlag("SWUPDATE_IMAGES_NOAPPEND_MACHINE", image, True) + if noappend_machine == False: # Search for a file explicitely with MACHINE + imagebases = [ image + '-' + d.getVar('MACHINE', True) ] + elif noappend_machine == True: # Search for a file explicitely without MACHINE + imagebases = [ image ] + else: # None, means auto mode. Just try to find an image file with MACHINE or without MACHINE + imagebases = [ image + '-' + d.getVar('MACHINE', True), image ] + for fstype in fstypes: + image_found = False + for imagebase in imagebases: + image_found = add_image_to_swu(deploydir, imagebase + fstype, s) + if image_found: + break + if not image_found: + bb.fatal("swupdate cannot find image file: %s" % os.path.join(deploydir, imagebase + fstype)) + else: # Allow also complete entries like "image.ext4.gz" in SWUPDATE_IMAGES + if not add_image_to_swu(deploydir, image, s): + bb.fatal("swupdate cannot find %s image file" % image) prepare_sw_description(d, s, list_for_cpio)
Try to make the swupdate.bbclass a little bit smarter in finding the image files added to the swu archive. The implementation is also a bit more Yocto like. By default, files are searched automatically whereas MACHINE specific files get priority over files without the MACHINE in the filename. This makes the SWUPDATE_IMAGES_NOAPPEND_MACHINE VarFlag more optional. Most standard use cases are expected to "just work" without setting this flag. Add support for files in a sub-folder of DEPLOY_DIR_IMAGE. Add documentation to the header of the swupdate.bbclass file. Signed-off-by: Adrian Freihofer <adrian.freihofer@siemens.com> --- classes/swupdate.bbclass | 77 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 54 insertions(+), 23 deletions(-)