baremetal-image.bbclass 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. # Baremetal image class
  2. #
  3. # This class is meant to be inherited by recipes for baremetal/RTOS applications
  4. # It contains code that would be used by all of them, every recipe just needs to
  5. # override certain variables.
  6. #
  7. # For scalability purposes, code within this class focuses on the "image" wiring
  8. # to satisfy the OpenEmbedded image creation and testing infrastructure.
  9. #
  10. # See meta-skeleton for a working example.
  11. # Toolchain should be baremetal or newlib based.
  12. # TCLIBC="baremetal" or TCLIBC="newlib"
  13. COMPATIBLE_HOST_libc-musl_class-target = "null"
  14. COMPATIBLE_HOST_libc-glibc_class-target = "null"
  15. inherit rootfs-postcommands
  16. # Set some defaults, but these should be overriden by each recipe if required
  17. IMGDEPLOYDIR ?= "${WORKDIR}/deploy-${PN}-image-complete"
  18. BAREMETAL_BINNAME ?= "hello_baremetal_${MACHINE}"
  19. IMAGE_LINK_NAME ?= "baremetal-helloworld-image-${MACHINE}"
  20. IMAGE_NAME_SUFFIX ?= ""
  21. do_rootfs[dirs] = "${IMGDEPLOYDIR} ${DEPLOY_DIR_IMAGE}"
  22. do_image(){
  23. install ${D}/${base_libdir}/firmware/${BAREMETAL_BINNAME}.bin ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.bin
  24. install ${D}/${base_libdir}/firmware/${BAREMETAL_BINNAME}.elf ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.elf
  25. }
  26. do_image_complete(){
  27. :
  28. }
  29. python do_rootfs(){
  30. from oe.utils import execute_pre_post_process
  31. from pathlib import Path
  32. # Write empty manifest file to satisfy test infrastructure
  33. deploy_dir = d.getVar('IMGDEPLOYDIR')
  34. link_name = d.getVar('IMAGE_LINK_NAME')
  35. manifest_name = d.getVar('IMAGE_MANIFEST')
  36. Path(manifest_name).touch()
  37. if os.path.exists(manifest_name) and link_name:
  38. manifest_link = deploy_dir + "/" + link_name + ".manifest"
  39. if os.path.lexists(manifest_link):
  40. os.remove(manifest_link)
  41. os.symlink(os.path.basename(manifest_name), manifest_link)
  42. execute_pre_post_process(d, d.getVar('ROOTFS_POSTPROCESS_COMMAND'))
  43. }
  44. # Assure binaries, manifest and qemubootconf are populated on DEPLOY_DIR_IMAGE
  45. do_image_complete[dirs] = "${TOPDIR}"
  46. do_image_complete[umask] = "022"
  47. SSTATETASKS += "do_image_complete"
  48. SSTATE_SKIP_CREATION_task-image-complete = '1'
  49. do_image_complete[sstate-inputdirs] = "${IMGDEPLOYDIR}"
  50. do_image_complete[sstate-outputdirs] = "${DEPLOY_DIR_IMAGE}"
  51. do_image_complete[stamp-extra-info] = "${MACHINE_ARCH}"
  52. addtask do_image_complete after do_image before do_build
  53. python do_image_complete_setscene () {
  54. sstate_setscene(d)
  55. }
  56. addtask do_image_complete_setscene
  57. # QEMU generic Baremetal/RTOS parameters
  58. QB_DEFAULT_KERNEL ?= "${IMAGE_LINK_NAME}.bin"
  59. QB_MEM ?= "-m 256"
  60. QB_DEFAULT_FSTYPE ?= "bin"
  61. QB_DTB ?= ""
  62. QB_OPT_APPEND = "-nographic"
  63. # This next part is necessary to trick the build system into thinking
  64. # its building an image recipe so it generates the qemuboot.conf
  65. addtask do_rootfs before do_image after do_install
  66. addtask do_image after do_rootfs before do_image_complete
  67. addtask do_image_complete after do_image before do_build
  68. inherit qemuboot
  69. # Based on image.bbclass to make sure we build qemu
  70. python(){
  71. # do_addto_recipe_sysroot doesnt exist for all recipes, but we need it to have
  72. # /usr/bin on recipe-sysroot (qemu) populated
  73. def extraimage_getdepends(task):
  74. deps = ""
  75. for dep in (d.getVar('EXTRA_IMAGEDEPENDS') or "").split():
  76. # Make sure we only add it for qemu
  77. if 'qemu' in dep:
  78. deps += " %s:%s" % (dep, task)
  79. return deps
  80. d.appendVarFlag('do_image', 'depends', extraimage_getdepends('do_addto_recipe_sysroot'))
  81. d.appendVarFlag('do_image', 'depends', extraimage_getdepends('do_populate_sysroot'))
  82. }