Andrew Geissler | 475cb72 | 2020-07-10 16:00:51 -0500 | [diff] [blame] | 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 | |
| 12 | |
| 13 | # Toolchain should be baremetal or newlib based. |
| 14 | # TCLIBC="baremetal" or TCLIBC="newlib" |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 15 | COMPATIBLE_HOST:libc-musl:class-target = "null" |
| 16 | COMPATIBLE_HOST:libc-glibc:class-target = "null" |
Andrew Geissler | 475cb72 | 2020-07-10 16:00:51 -0500 | [diff] [blame] | 17 | |
| 18 | |
| 19 | inherit rootfs-postcommands |
| 20 | |
| 21 | # Set some defaults, but these should be overriden by each recipe if required |
| 22 | IMGDEPLOYDIR ?= "${WORKDIR}/deploy-${PN}-image-complete" |
| 23 | BAREMETAL_BINNAME ?= "hello_baremetal_${MACHINE}" |
| 24 | IMAGE_LINK_NAME ?= "baremetal-helloworld-image-${MACHINE}" |
| 25 | IMAGE_NAME_SUFFIX ?= "" |
| 26 | |
| 27 | do_rootfs[dirs] = "${IMGDEPLOYDIR} ${DEPLOY_DIR_IMAGE}" |
| 28 | |
| 29 | do_image(){ |
| 30 | install ${D}/${base_libdir}/firmware/${BAREMETAL_BINNAME}.bin ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.bin |
| 31 | install ${D}/${base_libdir}/firmware/${BAREMETAL_BINNAME}.elf ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.elf |
| 32 | } |
| 33 | |
| 34 | do_image_complete(){ |
| 35 | : |
| 36 | } |
| 37 | |
| 38 | python do_rootfs(){ |
| 39 | from oe.utils import execute_pre_post_process |
| 40 | from pathlib import Path |
| 41 | |
| 42 | # Write empty manifest file to satisfy test infrastructure |
| 43 | deploy_dir = d.getVar('IMGDEPLOYDIR') |
| 44 | link_name = d.getVar('IMAGE_LINK_NAME') |
| 45 | manifest_name = d.getVar('IMAGE_MANIFEST') |
| 46 | |
| 47 | Path(manifest_name).touch() |
| 48 | if os.path.exists(manifest_name) and link_name: |
| 49 | manifest_link = deploy_dir + "/" + link_name + ".manifest" |
| 50 | if os.path.lexists(manifest_link): |
| 51 | os.remove(manifest_link) |
| 52 | os.symlink(os.path.basename(manifest_name), manifest_link) |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 53 | # A lot of postprocess commands assume the existence of rootfs/etc |
| 54 | sysconfdir = d.getVar("IMAGE_ROOTFS") + d.getVar('sysconfdir') |
| 55 | bb.utils.mkdirhier(sysconfdir) |
| 56 | |
Andrew Geissler | 475cb72 | 2020-07-10 16:00:51 -0500 | [diff] [blame] | 57 | execute_pre_post_process(d, d.getVar('ROOTFS_POSTPROCESS_COMMAND')) |
| 58 | } |
| 59 | |
| 60 | |
| 61 | # Assure binaries, manifest and qemubootconf are populated on DEPLOY_DIR_IMAGE |
| 62 | do_image_complete[dirs] = "${TOPDIR}" |
Andrew Geissler | 475cb72 | 2020-07-10 16:00:51 -0500 | [diff] [blame] | 63 | SSTATETASKS += "do_image_complete" |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 64 | SSTATE_SKIP_CREATION:task-image-complete = '1' |
Andrew Geissler | 475cb72 | 2020-07-10 16:00:51 -0500 | [diff] [blame] | 65 | do_image_complete[sstate-inputdirs] = "${IMGDEPLOYDIR}" |
| 66 | do_image_complete[sstate-outputdirs] = "${DEPLOY_DIR_IMAGE}" |
| 67 | do_image_complete[stamp-extra-info] = "${MACHINE_ARCH}" |
| 68 | addtask do_image_complete after do_image before do_build |
| 69 | |
| 70 | python do_image_complete_setscene () { |
| 71 | sstate_setscene(d) |
| 72 | } |
| 73 | addtask do_image_complete_setscene |
| 74 | |
| 75 | # QEMU generic Baremetal/RTOS parameters |
| 76 | QB_DEFAULT_KERNEL ?= "${IMAGE_LINK_NAME}.bin" |
| 77 | QB_MEM ?= "-m 256" |
| 78 | QB_DEFAULT_FSTYPE ?= "bin" |
| 79 | QB_DTB ?= "" |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 80 | QB_OPT_APPEND:append = " -nographic" |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 81 | |
| 82 | # RISC-V tunes set the BIOS, unset, and instruct QEMU to |
| 83 | # ignore the BIOS and boot from -kernel |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 84 | QB_DEFAULT_BIOS:qemuriscv64 = "" |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame^] | 85 | QB_DEFAULT_BIOS:qemuriscv32 = "" |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 86 | QB_OPT_APPEND:append:qemuriscv64 = " -bios none" |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame^] | 87 | QB_OPT_APPEND:append:qemuriscv32 = " -bios none" |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 88 | |
| 89 | |
| 90 | # Use the medium-any code model for the RISC-V 64 bit implementation, |
| 91 | # since medlow can only access addresses below 0x80000000 and RAM |
| 92 | # starts at 0x80000000 on RISC-V 64 |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame^] | 93 | # Keep RISC-V 32 using -mcmodel=medlow (symbols lie between -2GB:2GB) |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 94 | CFLAGS:append:qemuriscv64 = " -mcmodel=medany" |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 95 | |
Andrew Geissler | 475cb72 | 2020-07-10 16:00:51 -0500 | [diff] [blame] | 96 | |
| 97 | # This next part is necessary to trick the build system into thinking |
| 98 | # its building an image recipe so it generates the qemuboot.conf |
| 99 | addtask do_rootfs before do_image after do_install |
| 100 | addtask do_image after do_rootfs before do_image_complete |
| 101 | addtask do_image_complete after do_image before do_build |
| 102 | inherit qemuboot |
| 103 | |
| 104 | # Based on image.bbclass to make sure we build qemu |
| 105 | python(){ |
| 106 | # do_addto_recipe_sysroot doesnt exist for all recipes, but we need it to have |
| 107 | # /usr/bin on recipe-sysroot (qemu) populated |
| 108 | def extraimage_getdepends(task): |
| 109 | deps = "" |
| 110 | for dep in (d.getVar('EXTRA_IMAGEDEPENDS') or "").split(): |
| 111 | # Make sure we only add it for qemu |
| 112 | if 'qemu' in dep: |
| 113 | deps += " %s:%s" % (dep, task) |
| 114 | return deps |
| 115 | d.appendVarFlag('do_image', 'depends', extraimage_getdepends('do_addto_recipe_sysroot')) |
| 116 | d.appendVarFlag('do_image', 'depends', extraimage_getdepends('do_populate_sysroot')) |
| 117 | } |