<div dir="ltr"><div dir="auto"><div>Hey Khem,<br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jan 27, 2020, 12:51 PM Khem Raj <<a href="mailto:raj.khem@gmail.com" target="_blank">raj.khem@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Mon, Jan 27, 2020 at 2:01 AM Alejandro Enedino Hernandez Samaniego<br>
<<a href="mailto:alejandro@enedino.org" rel="noreferrer" target="_blank">alejandro@enedino.org</a>> wrote:<br>
><br>
> Create HelloWorld examples that run on several of the QEMU architectures<br>
> supported by the build system.<br>
><br>
> This recipe can be used by anyone to understand how baremetal applications<br>
> can be built using OpenEmbedded and how the wiring to set them up could be.<br>
><br>
> This should also facilitate creating/extending the OE testing infrastructure<br>
> to allow baremetal applications or RTOSs to be tested in the same way that<br>
> Linux currently is.<br>
><br>
> This can easily be extended to work on other MACHINES in the future.<br>
><br>
> To run this example:<br>
><br>
> # Source the oe environment as usual<br>
> $ source oe-init-buildenv<br>
><br>
> # Set TCLIBC to either newlib or baremetal<br>
> $ echo "TCLIBC = \"newlib\"" >> ./conf/local.conf<br>
><br>
> # Use one of the supported architectures (qemuarm64, qemuarm or qemuarmv5)<br>
> $ echo "MACHINE = \"qemuarm64\"" >> ./conf/local.conf<br>
><br>
> # Build<br>
> $ bitbake baremetal-helloworld<br>
><br>
> # Launch QEMU<br>
> $ runqemu<br>
><br>
> runqemu - INFO - Running bitbake -e ...<br>
> runqemu - INFO - Continuing with the following parameters:<br>
> KERNEL: [tmp/deploy/images/qemuarm64/baremetal-helloworld-qemuarm64.bin]<br>
> MACHINE: [qemuarm64]<br>
> FSTYPE: [bin]<br>
> ROOTFS: [tmp/deploy/images/qemuarm64/baremetal-helloworld-qemuarm64.bin]<br>
> CONFFILE: [tmp/deploy/images/qemuarm64/baremetal-helloworld-qemuarm64.qemuboot.conf]<br>
><br>
> Hello OpenEmbedded!<br>
><br>
> Signed-off-by: Alejandro Enedino Hernandez Samaniego <<a href="mailto:alejandro@enedino.org" rel="noreferrer" target="_blank">alejandro@enedino.org</a>><br>
> ---<br>
> .../baremetal-examples/<a href="http://baremetal-helloworld_git.bb" rel="noreferrer noreferrer" target="_blank">baremetal-helloworld_git.bb</a> | 114 +++++++++++++++++++++<br>
> 1 file changed, 114 insertions(+)<br>
> create mode 100644 meta/recipes-extended/baremetal-examples/<a href="http://baremetal-helloworld_git.bb" rel="noreferrer noreferrer" target="_blank">baremetal-helloworld_git.bb</a><br>
><br>
> diff --git a/meta/recipes-extended/baremetal-examples/<a href="http://baremetal-helloworld_git.bb" rel="noreferrer noreferrer" target="_blank">baremetal-helloworld_git.bb</a> b/meta/recipes-extended/baremetal-examples/<a href="http://baremetal-helloworld_git.bb" rel="noreferrer noreferrer" target="_blank">baremetal-helloworld_git.bb</a><br>
> new file mode 100644<br>
> index 0000000..aab48b1<br>
> --- /dev/null<br>
> +++ b/meta/recipes-extended/baremetal-examples/<a href="http://baremetal-helloworld_git.bb" rel="noreferrer noreferrer" target="_blank">baremetal-helloworld_git.bb</a><br>
> @@ -0,0 +1,114 @@<br>
> +SUMMARY = "Baremetal examples to work with the several QEMU architectures supported on OpenEmbedded"<br>
> +HOMEPAGE = "<a href="https://github.com/aehs29/baremetal-helloqemu" rel="noreferrer noreferrer" target="_blank">https://github.com/aehs29/baremetal-helloqemu</a>"<br>
> +LICENSE = "CC-BY-SA-4.0"<br>
<br>
I think MIT or Apache-2.0 would be much nicer.<br></blockquote></div></div><br>I agree but this wasn't by choice, the original code written for the versatile architecture was licensed on CC-BY-SA, which AFAIC wouldn't be compatible with those, this is the best I could come up with since this way, something that uses this could use GPLv3 if there's a better way let me know<div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
> +LIC_FILES_CHKSUM = "file://LICENSE;md5=4084714af41157e38872e798eb3fe1b1"<br>
> +<br>
> +SRCREV = "fe81742f1159725408dd7305e40e7bd4dfd1e264"<br>
> +<br>
> +SRC_URI = "git://<a href="http://github.com/aehs29/baremetal-helloqemu.git;protocol=https" rel="noreferrer noreferrer" target="_blank">github.com/aehs29/baremetal-helloqemu.git;protocol=https</a> "<br>
> +<br>
> +S = "${WORKDIR}/git"<br>
> +B = "${WORKDIR}/build"<br>
> +<br>
> +# These examples are not meant to be built when using either musl or glibc<br>
> +COMPATIBLE_HOST_libc-musl_class-target = "null"<br>
> +COMPATIBLE_HOST_libc-glibc_class-target = "null"<br>
<br>
Perhaps check for TARGET_OS instead of LIBC<br></blockquote></div></div><div dir="auto"><br></div>We had decided this to avoid bitbake world errors, if you think TARGET_OS is better I'm okay with that.<div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
> +# This will be translated automatically to the architecture and<br>
> +# machine that QEMU uses on OE, e.g. -machine virt -cpu cortex-a57<br>
> +# but the examples can also be run on other architectures/machines<br>
> +# such as vexpress-a15 by overriding the setting on the machine.conf<br>
> +COMPATIBLE_MACHINE = "qemuarmv5|qemuarm|qemuarm64"<br>
> +<br>
> +BAREMETAL_QEMUARCH ?= ""<br>
> +BAREMETAL_QEMUARCH_qemuarmv5 = "versatile"<br>
> +BAREMETAL_QEMUARCH_qemuarm = "arm"<br>
> +BAREMETAL_QEMUARCH_qemuarm64 = "aarch64"<br>
> +<br>
<br>
this setting should be abstracted into something like baremetal.bbclass<br>
<br>
<br>
> +<br>
> +EXTRA_OEMAKE_append = " QEMUARCH=${BAREMETAL_QEMUARCH}"<br>
> +<br>
> +do_configure(){<br>
> + # Avoid building on the source directory<br>
> + cp ${S}/* ${B}<br>
> +}<br>
<br>
copying sources to B why is that needed ?<br>
<br>
<br>
> +<br>
> +do_install(){<br>
> + install -d ${D}/${datadir}<br>
> + install -m 755 ${B}/hello_baremetal_${BAREMETAL_QEMUARCH}.bin ${D}/${datadir}/hello_baremetal_${MACHINE}.bin<br>
> + install -m 755 ${B}/hello_baremetal_${BAREMETAL_QEMUARCH}.elf ${D}/${datadir}/hello_baremetal_${MACHINE}.elf<br>
> +}<br>
> +<br>
> +# Make sure there are no race conditions when<br>
> +# assembling compiling and linking steps<br>
> +PARALLEL_MAKE = ""<br>
> +<br>
<br>
hmmm bad example to start of.<br>
<br>
> +# Borrowed from meta-freertos<br>
> +inherit rootfs-postcommands<br>
> +inherit deploy<br>
> +do_deploy[dirs] = "${DEPLOYDIR} ${DEPLOY_DIR_IMAGE}"<br>
> +do_rootfs[dirs] = "${DEPLOYDIR} ${DEPLOY_DIR_IMAGE}"<br>
> +DEPLOYDIR = "${IMGDEPLOYDIR}"<br>
> +IMAGE_LINK_NAME ?= "baremetal-helloworld-image-${MACHINE}"<br>
> +IMAGE_NAME_SUFFIX ?= ""<br>
> +<br>
> +do_deploy(){<br>
> + install ${D}/${datadir}/hello_baremetal_${MACHINE}.bin ${DEPLOYDIR}/${IMAGE_LINK_NAME}.bin<br>
> + install ${D}/${datadir}/hello_baremetal_${MACHINE}.elf ${DEPLOYDIR}/${IMAGE_LINK_NAME}.elf<br>
> +}<br>
> +<br>
> +do_image(){<br>
> + :<br>
> +}<br>
> +<br>
> +FILES_${PN} += " \<br>
> + ${datadir}/hello_baremetal_${MACHINE}.bin \<br>
> + ${datadir}/hello_baremetal_${MACHINE}.elf \<br>
> +"<br>
> +<br>
> +python do_rootfs(){<br>
> + from oe.utils import execute_pre_post_process<br>
> + from pathlib import Path<br>
> +<br>
> + # Write empty manifest testdate file<br>
> + deploy_dir = d.getVar('DEPLOYDIR')<br>
> + link_name = d.getVar('IMAGE_LINK_NAME')<br>
> + manifest_name = d.getVar('IMAGE_MANIFEST')<br>
> +<br>
> + Path(manifest_name).touch()<br>
> + if os.path.exists(manifest_name) and link_name:<br>
> + manifest_link = deploy_dir + "/" + link_name + ".manifest"<br>
> + if os.path.lexists(manifest_link):<br>
> + os.remove(manifest_link)<br>
> + os.symlink(os.path.basename(manifest_name), manifest_link)<br>
> + execute_pre_post_process(d, d.getVar('ROOTFS_POSTPROCESS_COMMAND'))<br>
> +}<br>
> +<br>
<br>
<br>
these all should be abstracted<br></blockquote></div></div><div dir="auto"><br></div>Ok, of all the above, my intention is to create a class that abstracts this, it actually already is a class on meta-freertos, even the code below, but I have WIP on testimage, oe-selftest, FreeRTOS and for the next couple of days I'll have a lot on my plate and I'm trying to split the work in chunks, so it doesn't break other WIP and at the same time I get things done, I agree its not ideal, but its less confusing for me to have a single class for now (the meta-freertos one), along with these recipes already being built for the test cases and once I can upstream the work, all this will be abstracted in a class in oe-core, I can file a bug in bugzilla and take it to keep track of this if that helps.<div dir="auto"><br></div>v2 fixes:<br>Copying sources<br>Paralell make<div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
> +# QEMU generic FreeRTOS parameters<br>
> +QB_DEFAULT_KERNEL = "${IMAGE_LINK_NAME}.bin"<br>
> +QB_MEM = "-m 256"<br>
> +QB_OPT_APPEND = "-nographic"<br>
> +QB_DEFAULT_FSTYPE = "bin"<br>
> +QB_DTB = ""<br>
> +<br><br>
this setting perhaps should be in machine conf ?<br></blockquote></div></div><div dir="auto"><br></div>Those are already on the machine.conf, these are overriding the Linux configurations so QEMU loads the baremetal application correctly , e.g. FSTYPE=bin<div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
> +# This next part is necessary to trick the build system into thinking<br>
> +# its building an image recipe so it generates the qemuboot.conf<br>
> +addtask do_deploy after do_write_qemuboot_conf before do_build<br>
> +addtask do_rootfs before do_deploy after do_install<br>
> +addtask do_image after do_rootfs before do_build<br>
> +inherit qemuboot<br>
> +<br>
> +# Based on image.bbclass to make sure we build qemu<br>
> +python(){<br>
> + # do_addto_recipe_sysroot doesnt exist for all recipes, but we need it to have<br>
> + # /usr/bin on recipe-sysroot (qemu) populated<br>
> + def extraimage_getdepends(task):<br>
> + deps = ""<br>
> + for dep in (d.getVar('EXTRA_IMAGEDEPENDS') or "").split():<br>
> + # Make sure we only add it for qemu<br>
> + if 'qemu' in dep:<br>
> + deps += " %s:%s" % (dep, task)<br>
> + return deps<br>
> + d.appendVarFlag('do_image', 'depends', extraimage_getdepends('do_addto_recipe_sysroot'))<br>
> + d.appendVarFlag('do_image', 'depends', extraimage_getdepends('do_populate_sysroot'))<br>
> +}<br>
> --<br>
> 2.7.4<br>
><br>
> --<br>
> _______________________________________________<br>
> Openembedded-core mailing list<br>
> <a href="mailto:Openembedded-core@lists.openembedded.org" rel="noreferrer" target="_blank">Openembedded-core@lists.openembedded.org</a><br>
> <a href="http://lists.openembedded.org/mailman/listinfo/openembedded-core" rel="noreferrer noreferrer" target="_blank">http://lists.openembedded.org/mailman/listinfo/openembedded-core</a><br>
</blockquote></div></div></div>
</div>