Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 1 | SUMMARY = "Baremetal examples to work with the several QEMU architectures supported on OpenEmbedded" |
| 2 | HOMEPAGE = "https://github.com/aehs29/baremetal-helloqemu" |
| 3 | LICENSE = "MIT" |
| 4 | LIC_FILES_CHKSUM = "file://LICENSE;md5=39346640a23c701e4f459e05f56f4449" |
| 5 | |
| 6 | SRCREV = "99f4fa4a3b266b42b52af302610b0f4f429ba5e3" |
| 7 | PV = "0.1+git${SRCPV}" |
| 8 | |
| 9 | SRC_URI = "git://github.com/aehs29/baremetal-helloqemu.git;protocol=https;branch=master" |
| 10 | |
| 11 | S = "${WORKDIR}/git/" |
| 12 | |
| 13 | # These examples are not meant to be built when using either musl or glibc |
| 14 | COMPATIBLE_HOST_libc-musl_class-target = "null" |
| 15 | COMPATIBLE_HOST_libc-glibc_class-target = "null" |
| 16 | |
| 17 | # This will be translated automatically to the architecture and |
| 18 | # machine that QEMU uses on OE, e.g. -machine virt -cpu cortex-a57 |
| 19 | # but the examples can also be run on other architectures/machines |
| 20 | # such as vexpress-a15 by overriding the setting on the machine.conf |
| 21 | COMPATIBLE_MACHINE = "qemuarmv5|qemuarm|qemuarm64" |
| 22 | |
| 23 | BAREMETAL_QEMUARCH ?= "" |
| 24 | BAREMETAL_QEMUARCH_qemuarmv5 = "versatile" |
| 25 | BAREMETAL_QEMUARCH_qemuarm = "arm" |
| 26 | BAREMETAL_QEMUARCH_qemuarm64 = "aarch64" |
| 27 | |
| 28 | |
| 29 | EXTRA_OEMAKE_append = " QEMUARCH=${BAREMETAL_QEMUARCH} V=1" |
| 30 | |
| 31 | do_install(){ |
| 32 | install -d ${D}/${datadir} |
| 33 | install -m 755 ${B}build/hello_baremetal_${BAREMETAL_QEMUARCH}.bin ${D}/${datadir}/hello_baremetal_${MACHINE}.bin |
| 34 | install -m 755 ${B}build/hello_baremetal_${BAREMETAL_QEMUARCH}.elf ${D}/${datadir}/hello_baremetal_${MACHINE}.elf |
| 35 | } |
| 36 | |
| 37 | # Borrowed from meta-freertos |
| 38 | inherit rootfs-postcommands |
| 39 | inherit deploy |
| 40 | IMGDEPLOYDIR ?= "${WORKDIR}/deploy-${PN}-image-complete" |
| 41 | do_deploy[dirs] = "${DEPLOYDIR} ${DEPLOY_DIR_IMAGE}" |
| 42 | do_rootfs[dirs] = "${DEPLOYDIR} ${DEPLOY_DIR_IMAGE}" |
| 43 | DEPLOYDIR = "${IMGDEPLOYDIR}" |
| 44 | IMAGE_LINK_NAME ?= "baremetal-helloworld-image-${MACHINE}" |
| 45 | IMAGE_NAME_SUFFIX ?= "" |
| 46 | |
| 47 | do_deploy(){ |
| 48 | install ${D}/${datadir}/hello_baremetal_${MACHINE}.bin ${DEPLOYDIR}/${IMAGE_LINK_NAME}.bin |
| 49 | install ${D}/${datadir}/hello_baremetal_${MACHINE}.elf ${DEPLOYDIR}/${IMAGE_LINK_NAME}.elf |
| 50 | } |
| 51 | |
| 52 | do_image(){ |
| 53 | : |
| 54 | } |
| 55 | |
| 56 | FILES_${PN} += " \ |
| 57 | ${datadir}/hello_baremetal_${MACHINE}.bin \ |
| 58 | ${datadir}/hello_baremetal_${MACHINE}.elf \ |
| 59 | " |
| 60 | |
| 61 | python do_rootfs(){ |
| 62 | from oe.utils import execute_pre_post_process |
| 63 | from pathlib import Path |
| 64 | |
| 65 | # Write empty manifest testdate file |
| 66 | deploy_dir = d.getVar('DEPLOYDIR') |
| 67 | link_name = d.getVar('IMAGE_LINK_NAME') |
| 68 | manifest_name = d.getVar('IMAGE_MANIFEST') |
| 69 | |
| 70 | Path(manifest_name).touch() |
| 71 | if os.path.exists(manifest_name) and link_name: |
| 72 | manifest_link = deploy_dir + "/" + link_name + ".manifest" |
| 73 | if os.path.lexists(manifest_link): |
| 74 | os.remove(manifest_link) |
| 75 | os.symlink(os.path.basename(manifest_name), manifest_link) |
| 76 | execute_pre_post_process(d, d.getVar('ROOTFS_POSTPROCESS_COMMAND')) |
| 77 | } |
| 78 | |
| 79 | # QEMU generic FreeRTOS parameters |
| 80 | QB_DEFAULT_KERNEL = "${IMAGE_LINK_NAME}.bin" |
| 81 | QB_MEM = "-m 256" |
| 82 | QB_OPT_APPEND = "-nographic" |
| 83 | QB_DEFAULT_FSTYPE = "bin" |
| 84 | QB_DTB = "" |
| 85 | |
| 86 | # This next part is necessary to trick the build system into thinking |
| 87 | # its building an image recipe so it generates the qemuboot.conf |
| 88 | addtask do_deploy after do_write_qemuboot_conf before do_build |
| 89 | addtask do_rootfs before do_deploy after do_install |
| 90 | addtask do_image after do_rootfs before do_build |
| 91 | inherit qemuboot |
| 92 | |
| 93 | # Based on image.bbclass to make sure we build qemu |
| 94 | python(){ |
| 95 | # do_addto_recipe_sysroot doesnt exist for all recipes, but we need it to have |
| 96 | # /usr/bin on recipe-sysroot (qemu) populated |
| 97 | def extraimage_getdepends(task): |
| 98 | deps = "" |
| 99 | for dep in (d.getVar('EXTRA_IMAGEDEPENDS') or "").split(): |
| 100 | # Make sure we only add it for qemu |
| 101 | if 'qemu' in dep: |
| 102 | deps += " %s:%s" % (dep, task) |
| 103 | return deps |
| 104 | d.appendVarFlag('do_image', 'depends', extraimage_getdepends('do_addto_recipe_sysroot')) |
| 105 | d.appendVarFlag('do_image', 'depends', extraimage_getdepends('do_populate_sysroot')) |
| 106 | } |