swupdate.bbclass 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. S = "${WORKDIR}/${PN}"
  15. IMAGE_DEPENDS ?= ""
  16. def swupdate_getdepends(d):
  17. def adddep(depstr, deps):
  18. for i in (depstr or "").split():
  19. if i not in deps:
  20. deps.append(i)
  21. deps = []
  22. images = (d.getVar('IMAGE_DEPENDS', True) or "").split()
  23. for image in images:
  24. adddep(image , deps)
  25. depstr = ""
  26. for dep in deps:
  27. depstr += " " + dep + ":do_rootfs"
  28. return depstr
  29. do_swuimage[dirs] = "${TOPDIR}"
  30. do_swuimage[cleandirs] += "${S}"
  31. do_swuimage[umask] = "022"
  32. do_configure[noexec] = "1"
  33. do_compile[noexec] = "1"
  34. do_install[noexec] = "1"
  35. do_package[noexec] = "1"
  36. do_package_qa[noexec] = "1"
  37. do_packagedata[noexec] = "1"
  38. do_package_write_ipk[noexec] = "1"
  39. do_package_write_deb[noexec] = "1"
  40. do_package_write_rpm[noexec] = "1"
  41. python () {
  42. deps = " " + swupdate_getdepends(d)
  43. d.appendVarFlag('do_build', 'depends', deps)
  44. }
  45. do_install () {
  46. }
  47. do_createlink () {
  48. cd ${DEPLOY_DIR_IMAGE}
  49. ln -sf ${IMAGE_NAME}.swu ${IMAGE_LINK_NAME}.swu
  50. }
  51. python do_swuimage () {
  52. import shutil
  53. workdir = d.getVar('WORKDIR', True)
  54. images = (d.getVar('SWUPDATE_IMAGES', True) or "").split()
  55. s = d.getVar('S', True)
  56. shutil.copyfile(os.path.join(workdir, "sw-description"), os.path.join(s, "sw-description"))
  57. fetch = bb.fetch2.Fetch([], d)
  58. list_for_cpio = "sw-description"
  59. for url in fetch.urls:
  60. local = fetch.localpath(url)
  61. filename = os.path.basename(local)
  62. shutil.copyfile(local, os.path.join(s, "%s" % filename ))
  63. if (filename != 'sw-description'):
  64. list_for_cpio += " " + filename
  65. deploydir = d.getVar('DEPLOY_DIR_IMAGE', True)
  66. for image in images:
  67. imagename = image + '-' + d.getVar('MACHINE', True) + d.getVarFlag("SWUPDATE_IMAGES_FSTYPES", image, True)
  68. src = os.path.join(deploydir, "%s" % imagename)
  69. dst = os.path.join(s, "%s" % imagename)
  70. shutil.copyfile(src, dst)
  71. list_for_cpio += " " + imagename
  72. line = 'for i in ' + list_for_cpio + '; do echo $i;done | cpio -ov -H crc >' + os.path.join(deploydir,d.getVar('IMAGE_NAME', True) + '.swu')
  73. os.system("cd " + s + ";" + line)
  74. }
  75. COMPRESSIONTYPES = ""
  76. PACKAGE_ARCH = "${MACHINE_ARCH}"
  77. addtask do_swuimage after do_unpack before do_install
  78. addtask do_createlink after do_swuimage before do_install