diff options
| author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2022-08-10 14:35:29 +0100 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2022-08-12 15:27:17 +0100 |
| commit | fd1517e2b51a170f2427122c6b95396db251d827 (patch) | |
| tree | dabfe3e631339c2fc99a9ee7febb0f9c128e325e /meta/classes-recipe/baremetal-image.bbclass | |
| parent | 10317912ee319ccf7f83605d438b5cbf9663f296 (diff) | |
| download | poky-fd1517e2b51a170f2427122c6b95396db251d827.tar.gz | |
classes: Update classes to match new bitbake class scope functionality
Move classes to classes-global or classes-recipe as appropriate to take
advantage of new bitbake functionality to check class scope/usage.
(From OE-Core rev: f5c128008365e141082c129417eb72d2751e8045)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes-recipe/baremetal-image.bbclass')
| -rw-r--r-- | meta/classes-recipe/baremetal-image.bbclass | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/meta/classes-recipe/baremetal-image.bbclass b/meta/classes-recipe/baremetal-image.bbclass new file mode 100644 index 0000000000..3a979f2ed1 --- /dev/null +++ b/meta/classes-recipe/baremetal-image.bbclass | |||
| @@ -0,0 +1,128 @@ | |||
| 1 | # | ||
| 2 | # Copyright OpenEmbedded Contributors | ||
| 3 | # | ||
| 4 | # SPDX-License-Identifier: MIT | ||
| 5 | # | ||
| 6 | |||
| 7 | # Baremetal image class | ||
| 8 | # | ||
| 9 | # This class is meant to be inherited by recipes for baremetal/RTOS applications | ||
| 10 | # It contains code that would be used by all of them, every recipe just needs to | ||
| 11 | # override certain variables. | ||
| 12 | # | ||
| 13 | # For scalability purposes, code within this class focuses on the "image" wiring | ||
| 14 | # to satisfy the OpenEmbedded image creation and testing infrastructure. | ||
| 15 | # | ||
| 16 | # See meta-skeleton for a working example. | ||
| 17 | |||
| 18 | |||
| 19 | # Toolchain should be baremetal or newlib based. | ||
| 20 | # TCLIBC="baremetal" or TCLIBC="newlib" | ||
| 21 | COMPATIBLE_HOST:libc-musl:class-target = "null" | ||
| 22 | COMPATIBLE_HOST:libc-glibc:class-target = "null" | ||
| 23 | |||
| 24 | |||
| 25 | inherit rootfs-postcommands | ||
| 26 | |||
| 27 | # Set some defaults, but these should be overriden by each recipe if required | ||
| 28 | IMGDEPLOYDIR ?= "${WORKDIR}/deploy-${PN}-image-complete" | ||
| 29 | BAREMETAL_BINNAME ?= "hello_baremetal_${MACHINE}" | ||
| 30 | IMAGE_LINK_NAME ?= "baremetal-helloworld-image-${MACHINE}" | ||
| 31 | IMAGE_NAME_SUFFIX ?= "" | ||
| 32 | |||
| 33 | do_rootfs[dirs] = "${IMGDEPLOYDIR} ${DEPLOY_DIR_IMAGE}" | ||
| 34 | |||
| 35 | do_image(){ | ||
| 36 | install ${D}/${base_libdir}/firmware/${BAREMETAL_BINNAME}.bin ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.bin | ||
| 37 | install ${D}/${base_libdir}/firmware/${BAREMETAL_BINNAME}.elf ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.elf | ||
| 38 | } | ||
| 39 | |||
| 40 | do_image_complete(){ | ||
| 41 | : | ||
| 42 | } | ||
| 43 | |||
| 44 | python do_rootfs(){ | ||
| 45 | from oe.utils import execute_pre_post_process | ||
| 46 | from pathlib import Path | ||
| 47 | |||
| 48 | # Write empty manifest file to satisfy test infrastructure | ||
| 49 | deploy_dir = d.getVar('IMGDEPLOYDIR') | ||
| 50 | link_name = d.getVar('IMAGE_LINK_NAME') | ||
| 51 | manifest_name = d.getVar('IMAGE_MANIFEST') | ||
| 52 | |||
| 53 | Path(manifest_name).touch() | ||
| 54 | if os.path.exists(manifest_name) and link_name: | ||
| 55 | manifest_link = deploy_dir + "/" + link_name + ".manifest" | ||
| 56 | if manifest_link != manifest_name: | ||
| 57 | if os.path.lexists(manifest_link): | ||
| 58 | os.remove(manifest_link) | ||
| 59 | os.symlink(os.path.basename(manifest_name), manifest_link) | ||
| 60 | # A lot of postprocess commands assume the existence of rootfs/etc | ||
| 61 | sysconfdir = d.getVar("IMAGE_ROOTFS") + d.getVar('sysconfdir') | ||
| 62 | bb.utils.mkdirhier(sysconfdir) | ||
| 63 | |||
| 64 | execute_pre_post_process(d, d.getVar('ROOTFS_POSTPROCESS_COMMAND')) | ||
| 65 | } | ||
| 66 | |||
| 67 | |||
| 68 | # Assure binaries, manifest and qemubootconf are populated on DEPLOY_DIR_IMAGE | ||
| 69 | do_image_complete[dirs] = "${TOPDIR}" | ||
| 70 | SSTATETASKS += "do_image_complete" | ||
| 71 | SSTATE_SKIP_CREATION:task-image-complete = '1' | ||
| 72 | do_image_complete[sstate-inputdirs] = "${IMGDEPLOYDIR}" | ||
| 73 | do_image_complete[sstate-outputdirs] = "${DEPLOY_DIR_IMAGE}" | ||
| 74 | do_image_complete[stamp-extra-info] = "${MACHINE_ARCH}" | ||
| 75 | addtask do_image_complete after do_image before do_build | ||
| 76 | |||
| 77 | python do_image_complete_setscene () { | ||
| 78 | sstate_setscene(d) | ||
| 79 | } | ||
| 80 | addtask do_image_complete_setscene | ||
| 81 | |||
| 82 | # QEMU generic Baremetal/RTOS parameters | ||
| 83 | QB_DEFAULT_KERNEL ?= "${IMAGE_LINK_NAME}.bin" | ||
| 84 | QB_MEM ?= "-m 256" | ||
| 85 | QB_DEFAULT_FSTYPE ?= "bin" | ||
| 86 | QB_DTB ?= "" | ||
| 87 | QB_OPT_APPEND:append = " -nographic" | ||
| 88 | |||
| 89 | # RISC-V tunes set the BIOS, unset, and instruct QEMU to | ||
| 90 | # ignore the BIOS and boot from -kernel | ||
| 91 | QB_DEFAULT_BIOS:qemuriscv64 = "" | ||
| 92 | QB_DEFAULT_BIOS:qemuriscv32 = "" | ||
| 93 | QB_OPT_APPEND:append:qemuriscv64 = " -bios none" | ||
| 94 | QB_OPT_APPEND:append:qemuriscv32 = " -bios none" | ||
| 95 | |||
| 96 | |||
| 97 | # Use the medium-any code model for the RISC-V 64 bit implementation, | ||
| 98 | # since medlow can only access addresses below 0x80000000 and RAM | ||
| 99 | # starts at 0x80000000 on RISC-V 64 | ||
| 100 | # Keep RISC-V 32 using -mcmodel=medlow (symbols lie between -2GB:2GB) | ||
| 101 | CFLAGS:append:qemuriscv64 = " -mcmodel=medany" | ||
| 102 | |||
| 103 | |||
| 104 | # This next part is necessary to trick the build system into thinking | ||
| 105 | # its building an image recipe so it generates the qemuboot.conf | ||
| 106 | addtask do_rootfs before do_image after do_install | ||
| 107 | addtask do_image after do_rootfs before do_image_complete | ||
| 108 | addtask do_image_complete after do_image before do_build | ||
| 109 | inherit qemuboot | ||
| 110 | |||
| 111 | # Based on image.bbclass to make sure we build qemu | ||
| 112 | python(){ | ||
| 113 | # do_addto_recipe_sysroot doesnt exist for all recipes, but we need it to have | ||
| 114 | # /usr/bin on recipe-sysroot (qemu) populated | ||
| 115 | # The do_addto_recipe_sysroot dependency is coming from EXTRA_IMAGDEPENDS now, | ||
| 116 | # we just need to add the logic to add its dependency to do_image. | ||
| 117 | def extraimage_getdepends(task): | ||
| 118 | deps = "" | ||
| 119 | for dep in (d.getVar('EXTRA_IMAGEDEPENDS') or "").split(): | ||
| 120 | # Make sure we only add it for qemu | ||
| 121 | if 'qemu' in dep: | ||
| 122 | if ":" in dep: | ||
| 123 | deps += " %s " % (dep) | ||
| 124 | else: | ||
| 125 | deps += " %s:%s" % (dep, task) | ||
| 126 | return deps | ||
| 127 | d.appendVarFlag('do_image', 'depends', extraimage_getdepends('do_populate_sysroot')) | ||
| 128 | } | ||
