swupdate-image.bbclass 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # Copyright (C) 2015-2021 Stefano Babic <sbabic@denx.de>
  2. #
  3. # SPDX-License-Identifier: GPLv3
  4. #
  5. # This class is thought to be used in an image recipe.
  6. # It generates a SWU file from the image itself
  7. # User *must* add a sw-descitpion file
  8. #
  9. # To use this class, add the inherit clause of the update image bb file.
  10. # The generated output file is an swu archive ready to be uploaded to a device running
  11. # swupdate.
  12. inherit swupdate-common
  13. inherit image-artifact-names
  14. S = "${WORKDIR}/${PN}"
  15. SRC_URI += "file://sw-description"
  16. SWUPDATE_IMAGES += "${IMAGE_BASENAME}"
  17. python () {
  18. image = d.getVar('IMAGE_BASENAME')
  19. t = d.getVarFlag("SWUPDATE_IMAGES_FSTYPES", image)
  20. suffix = d.getVar("IMAGE_NAME_SUFFIX") or ""
  21. if t is None:
  22. flag = d.getVarFlag("SWUPDATE_IMAGES_FSTYPES", d.getVar('IMAGE_BASENAME'))
  23. if flag:
  24. d.setVarFlag("SWUPDATE_IMAGES_FSTYPES", image, flag)
  25. else:
  26. fstypes = d.getVar('IMAGE_FSTYPES').split()
  27. if not fstypes:
  28. bb.fatal("SWUPDATE_IMAGES_FSTYPES[%s] is not set !" % image)
  29. for t in fstypes:
  30. bb.warn("SWUPDATE_IMAGES_FSTYPES[%s] not set, setting to %s" % (image, t))
  31. d.setVarFlag("SWUPDATE_IMAGES_FSTYPES", image, suffix + "." + t)
  32. break
  33. else:
  34. d.setVarFlag("SWUPDATE_IMAGES_FSTYPES", image, suffix + t)
  35. }
  36. python do_swupdate_copy_swdescription() {
  37. import shutil
  38. workdir = d.getVar('S')
  39. filespath = d.getVar('FILESPATH')
  40. sw_desc_path = bb.utils.which(filespath, "sw-description")
  41. shutil.copyfile(sw_desc_path, os.path.join(workdir, "sw-description"))
  42. }
  43. addtask swupdate_copy_swdescription before do_image_complete after do_unpack
  44. addtask swuimage after do_swupdate_copy_swdescription do_image_complete before do_build
  45. # define setscene task
  46. python do_swuimage_setscene () {
  47. sstate_setscene(d)
  48. }
  49. addtask do_swuimage_setscene
  50. # Read all variables from sw-description file and add them to the vardeps of the do_swuimage task. Bitbake
  51. # cannot know that the do_swuimage task which evaluates the templated sw-description file needs to be executed
  52. # if a variable which is refered by the sw-description file but not by the recipe itself.
  53. do_swuimage[vardeps] ?= "${@swupdate_find_bitbake_variables(d)}"