swupdate-image.bbclass 2.1 KB

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