swupdate.bbclass 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. # Copyright (C) 2015 Stefano Babic <sbabic@denx.de>
  2. #
  3. # Some parts from the patch class
  4. #
  5. # swupdate allows to generate a compound image for the
  6. # in the "swupdate" format, used for updating the targets
  7. # in field.
  8. # See also http://sbabic.github.io/swupdate/
  9. #
  10. #
  11. # To use, add swupdate to the inherit clause and set
  12. # set the images (all of them must be found in deploy directory)
  13. # that are part of the compound image.
  14. inherit swupdate-common.bbclass
  15. S = "${WORKDIR}/${PN}"
  16. DEPENDS += "${@ 'openssl-native' if d.getVar('SWUPDATE_SIGNING', True) else ''}"
  17. IMAGE_DEPENDS ?= ""
  18. def swupdate_getdepends(d):
  19. def adddep(depstr, deps):
  20. for i in (depstr or "").split():
  21. if i not in deps:
  22. deps.append(i)
  23. deps = []
  24. images = (d.getVar('IMAGE_DEPENDS', True) or "").split()
  25. for image in images:
  26. adddep(image , deps)
  27. depstr = ""
  28. for dep in deps:
  29. depstr += " " + dep + ":do_build"
  30. return depstr
  31. IMGDEPLOYDIR = "${WORKDIR}/deploy-${PN}-swuimage"
  32. do_swuimage[dirs] = "${TOPDIR}"
  33. do_swuimage[cleandirs] += "${S} ${IMGDEPLOYDIR}"
  34. do_swuimage[umask] = "022"
  35. SSTATETASKS += "do_swuimage"
  36. SSTATE_SKIP_CREATION_task-swuimage = '1'
  37. do_swuimage[sstate-inputdirs] = "${IMGDEPLOYDIR}"
  38. do_swuimage[sstate-outputdirs] = "${DEPLOY_DIR_IMAGE}"
  39. do_swuimage[stamp-extra-info] = "${MACHINE}"
  40. do_configure[noexec] = "1"
  41. do_compile[noexec] = "1"
  42. do_install[noexec] = "1"
  43. deltask do_populate_sysroot
  44. do_package[noexec] = "1"
  45. deltask do_package_qa
  46. do_packagedata[noexec] = "1"
  47. do_package_write_ipk[noexec] = "1"
  48. do_package_write_deb[noexec] = "1"
  49. do_package_write_rpm[noexec] = "1"
  50. python () {
  51. deps = " " + swupdate_getdepends(d)
  52. d.appendVarFlag('do_swuimage', 'depends', deps)
  53. }
  54. python do_swuimage () {
  55. import shutil
  56. workdir = d.getVar('WORKDIR', True)
  57. images = (d.getVar('SWUPDATE_IMAGES', True) or "").split()
  58. s = d.getVar('S', True)
  59. shutil.copyfile(os.path.join(workdir, "sw-description"), os.path.join(s, "sw-description"))
  60. fetch = bb.fetch2.Fetch([], d)
  61. list_for_cpio = ["sw-description"]
  62. if d.getVar('SWUPDATE_SIGNING', True):
  63. list_for_cpio.append('sw-description.sig')
  64. for url in fetch.urls:
  65. local = fetch.localpath(url)
  66. filename = os.path.basename(local)
  67. if (filename != 'sw-description'):
  68. shutil.copyfile(local, os.path.join(s, "%s" % filename ))
  69. list_for_cpio.append(filename)
  70. # SWUPDATE_IMAGES refers to images in the DEPLOY directory
  71. # If they are not there, additional file can be added
  72. # by fetching from URLs
  73. deploydir = d.getVar('DEPLOY_DIR_IMAGE', True)
  74. imgdeploydir = d.getVar('IMGDEPLOYDIR', True)
  75. for image in images:
  76. fstypes = (d.getVarFlag("SWUPDATE_IMAGES_FSTYPES", image, True) or "").split()
  77. if not fstypes:
  78. fstypes = [""]
  79. for fstype in fstypes:
  80. appendmachine = d.getVarFlag("SWUPDATE_IMAGES_NOAPPEND_MACHINE", image, True)
  81. if appendmachine == None:
  82. imagebase = image + '-' + d.getVar('MACHINE', True)
  83. else:
  84. imagebase = image
  85. imagename = imagebase + fstype
  86. src = os.path.join(deploydir, "%s" % imagename)
  87. dst = os.path.join(s, "%s" % imagename)
  88. shutil.copyfile(src, dst)
  89. list_for_cpio.append(imagename)
  90. prepare_sw_description(d, s, list_for_cpio)
  91. line = 'for i in ' + ' '.join(list_for_cpio) + '; do echo $i;done | cpio -ov -H crc >' + os.path.join(imgdeploydir,d.getVar('IMAGE_NAME', True) + '.swu')
  92. os.system("cd " + s + ";" + line)
  93. line = 'ln -sf ' + d.getVar('IMAGE_NAME', True) + '.swu ' + d.getVar('IMAGE_LINK_NAME', True) + '.swu'
  94. os.system("cd " + imgdeploydir + "; " + line)
  95. }
  96. COMPRESSIONTYPES = ""
  97. PACKAGE_ARCH = "${MACHINE_ARCH}"
  98. INHIBIT_DEFAULT_DEPS = "1"
  99. EXCLUDE_FROM_WORLD = "1"
  100. addtask do_swuimage after do_unpack after do_prepare_recipe_sysroot before do_build