baremetal-image.bbclass 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. SSTATETASKS += "do_image_complete"
  47. SSTATE_SKIP_CREATION_task-image-complete = '1'
  48. do_image_complete[sstate-inputdirs] = "${IMGDEPLOYDIR}"
  49. do_image_complete[sstate-outputdirs] = "${DEPLOY_DIR_IMAGE}"
  50. do_image_complete[stamp-extra-info] = "${MACHINE_ARCH}"
  51. addtask do_image_complete after do_image before do_build
  52. python do_image_complete_setscene () {
  53. sstate_setscene(d)
  54. }
  55. addtask do_image_complete_setscene
  56. # QEMU generic Baremetal/RTOS parameters
  57. QB_DEFAULT_KERNEL ?= "${IMAGE_LINK_NAME}.bin"
  58. QB_MEM ?= "-m 256"
  59. QB_DEFAULT_FSTYPE ?= "bin"
  60. QB_DTB ?= ""
  61. QB_OPT_APPEND_append = " -nographic"
  62. # RISC-V tunes set the BIOS, unset, and instruct QEMU to
  63. # ignore the BIOS and boot from -kernel
  64. QB_DEFAULT_BIOS_qemuriscv64 = ""
  65. QB_OPT_APPEND_append_qemuriscv64 = " -bios none"
  66. # Use the medium-any code model for the RISC-V 64 bit implementation,
  67. # since medlow can only access addresses below 0x80000000 and RAM
  68. # starts at 0x80000000 on RISC-V 64
  69. CFLAGS_append_qemuriscv64 = " -mcmodel=medany"
  70. # This next part is necessary to trick the build system into thinking
  71. # its building an image recipe so it generates the qemuboot.conf
  72. addtask do_rootfs before do_image after do_install
  73. addtask do_image after do_rootfs before do_image_complete
  74. addtask do_image_complete after do_image before do_build
  75. inherit qemuboot
  76. # Based on image.bbclass to make sure we build qemu
  77. python(){
  78. # do_addto_recipe_sysroot doesnt exist for all recipes, but we need it to have
  79. # /usr/bin on recipe-sysroot (qemu) populated
  80. def extraimage_getdepends(task):
  81. deps = ""
  82. for dep in (d.getVar('EXTRA_IMAGEDEPENDS') or "").split():
  83. # Make sure we only add it for qemu
  84. if 'qemu' in dep:
  85. deps += " %s:%s" % (dep, task)
  86. return deps
  87. d.appendVarFlag('do_image', 'depends', extraimage_getdepends('do_addto_recipe_sysroot'))
  88. d.appendVarFlag('do_image', 'depends', extraimage_getdepends('do_populate_sysroot'))
  89. }