<div dir="auto"><div>Hey Paul,<div dir="auto"><br></div><br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jan 27, 2020, 2:09 AM Paul Barker &lt;<a href="mailto:pbarker@konsulko.com">pbarker@konsulko.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Mon, 27 Jan 2020 at 10:00, Alejandro Enedino Hernandez Samaniego<br>
&lt;<a href="mailto:alejandro@enedino.org" target="_blank" rel="noreferrer">alejandro@enedino.org</a>&gt; wrote:<br>
&gt;<br>
&gt; Create HelloWorld examples that run on several of the QEMU architectures<br>
&gt; supported by the build system.<br>
&gt;<br>
&gt; This recipe can be used by anyone to understand how baremetal applications<br>
&gt; can be built using OpenEmbedded and how the wiring to set them up could be.<br>
&gt;<br>
&gt; This should also facilitate creating/extending the OE testing infrastructure<br>
&gt; to allow baremetal applications or RTOSs to be tested in the same way that<br>
&gt; Linux currently is.<br>
&gt;<br>
&gt; This can easily be extended to work on other MACHINES in the future.<br>
&gt;<br>
&gt; To run this example:<br>
&gt;<br>
&gt; # Source the oe environment as usual<br>
&gt; $ source oe-init-buildenv<br>
&gt;<br>
&gt; # Set TCLIBC to either newlib or baremetal<br>
&gt; $ echo &quot;TCLIBC = \&quot;newlib\&quot;&quot; &gt;&gt; ./conf/local.conf<br>
&gt;<br>
&gt; # Use one of the supported architectures (qemuarm64, qemuarm or qemuarmv5)<br>
&gt; $ echo &quot;MACHINE = \&quot;qemuarm64\&quot;&quot; &gt;&gt; ./conf/local.conf<br>
&gt;<br>
&gt; # Build<br>
&gt; $ bitbake baremetal-helloworld<br>
&gt;<br>
&gt; # Launch QEMU<br>
&gt; $ runqemu<br>
&gt;<br>
&gt; runqemu - INFO - Running bitbake -e ...<br>
&gt; runqemu - INFO - Continuing with the following parameters:<br>
&gt; KERNEL: [tmp/deploy/images/qemuarm64/baremetal-helloworld-qemuarm64.bin]<br>
&gt; MACHINE: [qemuarm64]<br>
&gt; FSTYPE: [bin]<br>
&gt; ROOTFS: [tmp/deploy/images/qemuarm64/baremetal-helloworld-qemuarm64.bin]<br>
&gt; CONFFILE: [tmp/deploy/images/qemuarm64/baremetal-helloworld-qemuarm64.qemuboot.conf]<br>
&gt;<br>
&gt; Hello OpenEmbedded!<br>
&gt;<br>
&gt; Signed-off-by: Alejandro Enedino Hernandez Samaniego &lt;<a href="mailto:alejandro@enedino.org" target="_blank" rel="noreferrer">alejandro@enedino.org</a>&gt;<br>
&gt; ---<br>
&gt;  .../baremetal-examples/<a href="http://baremetal-helloworld_git.bb" rel="noreferrer noreferrer" target="_blank">baremetal-helloworld_git.bb</a> | 114 +++++++++++++++++++++<br>
&gt;  1 file changed, 114 insertions(+)<br>
&gt;  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>
&gt;<br>
&gt; 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>
&gt; new file mode 100644<br>
&gt; index 0000000..aab48b1<br>
&gt; --- /dev/null<br>
&gt; +++ b/meta/recipes-extended/baremetal-examples/<a href="http://baremetal-helloworld_git.bb" rel="noreferrer noreferrer" target="_blank">baremetal-helloworld_git.bb</a><br>
&gt; @@ -0,0 +1,114 @@<br>
&gt; +SUMMARY = &quot;Baremetal examples to work with the several QEMU architectures supported on OpenEmbedded&quot;<br>
&gt; +HOMEPAGE = &quot;<a href="https://github.com/aehs29/baremetal-helloqemu" rel="noreferrer noreferrer" target="_blank">https://github.com/aehs29/baremetal-helloqemu</a>&quot;<br>
&gt; +LICENSE = &quot;CC-BY-SA-4.0&quot;<br>
<br>
I&#39;ve raised <a href="https://github.com/aehs29/baremetal-helloqemu/issues/1" rel="noreferrer noreferrer" target="_blank">https://github.com/aehs29/baremetal-helloqemu/issues/1</a> as<br>
CC licenses aren&#39;t recommended for software.<br>
<br><br></blockquote></div></div><div dir="auto"><br></div><div dir="auto"><span style="font-family:sans-serif">I do agree, I originally had it as MIT, although I did base this on the original work of someone who made it work for the versatile architecture and they licensed that with CC-BY-SA and as I was reading I have to use the same license as them.</span><br></div><div dir="auto"><span style="font-family:sans-serif"><br></span></div><div dir="auto"><span style="font-family:sans-serif">I thought about it and for the Hello OpenEmbedded examples it would be ok since they should serve mostly as basis for the wiring that users can use to build, run and test their baremetal apps on OE, so the license wouldn&#39;t affect them, but I&#39;m open to suggestions here.</span></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>
&gt; +LIC_FILES_CHKSUM = &quot;file://LICENSE;md5=4084714af41157e38872e798eb3fe1b1&quot;<br>
&gt; +<br>
&gt; +SRCREV = &quot;fe81742f1159725408dd7305e40e7bd4dfd1e264&quot;<br>
&gt; +<br>
&gt; +SRC_URI = &quot;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> &quot;<br>
&gt; +<br>
&gt; +S = &quot;${WORKDIR}/git&quot;<br>
&gt; +B = &quot;${WORKDIR}/build&quot;<br>
&gt; +<br>
&gt; +# These examples are not meant to be built when using either musl or glibc<br>
&gt; +COMPATIBLE_HOST_libc-musl_class-target = &quot;null&quot;<br>
&gt; +COMPATIBLE_HOST_libc-glibc_class-target = &quot;null&quot;<br>
&gt; +<br>
&gt; +# This will be translated automatically to the architecture and<br>
&gt; +# machine that QEMU uses on OE, e.g. -machine virt -cpu cortex-a57<br>
&gt; +# but the examples can also be run on other architectures/machines<br>
&gt; +# such as vexpress-a15 by overriding the setting on the machine.conf<br>
&gt; +COMPATIBLE_MACHINE = &quot;qemuarmv5|qemuarm|qemuarm64&quot;<br>
&gt; +<br>
&gt; +BAREMETAL_QEMUARCH ?= &quot;&quot;<br>
&gt; +BAREMETAL_QEMUARCH_qemuarmv5 = &quot;versatile&quot;<br>
&gt; +BAREMETAL_QEMUARCH_qemuarm = &quot;arm&quot;<br>
&gt; +BAREMETAL_QEMUARCH_qemuarm64 = &quot;aarch64&quot;<br>
&gt; +<br>
&gt; +<br>
&gt; +EXTRA_OEMAKE_append = &quot; QEMUARCH=${BAREMETAL_QEMUARCH}&quot;<br>
&gt; +<br>
&gt; +do_configure(){<br>
&gt; +    # Avoid building on the source directory<br>
&gt; +    cp ${S}/* ${B}<br>
&gt; +}<br>
&gt; +<br>
&gt; +do_install(){<br>
&gt; +    install -d ${D}/${datadir}<br>
&gt; +    install -m 755 ${B}/hello_baremetal_${BAREMETAL_QEMUARCH}.bin ${D}/${datadir}/hello_baremetal_${MACHINE}.bin<br>
&gt; +    install -m 755 ${B}/hello_baremetal_${BAREMETAL_QEMUARCH}.elf ${D}/${datadir}/hello_baremetal_${MACHINE}.elf<br>
&gt; +}<br>
&gt; +<br>
&gt; +# Make sure there are no race conditions when<br>
&gt; +# assembling compiling and linking steps<br>
&gt; +PARALLEL_MAKE = &quot;&quot;<br>
&gt; +<br>
&gt; +# Borrowed from meta-freertos<br>
<br>
Can these borrowed sections go into a bbclass to make the example<br>
simpler? meta-freertos might then be able to use the bbclass from<br>
openembedded-core.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">Yup, I am in the process pf upstreaming to core part of the FreeRTOS work, this will go on a class eventually, but as part of the work I am writing some oeqa tests and I wanted to have this merged for now, will move this to a class later.</div><div dir="auto"><br></div><div dir="auto">Cheers,</div><div dir="auto"><br></div><div dir="auto">Alejandro</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>
&gt; +inherit rootfs-postcommands<br>
&gt; +inherit deploy<br>
&gt; +do_deploy[dirs] = &quot;${DEPLOYDIR} ${DEPLOY_DIR_IMAGE}&quot;<br>
&gt; +do_rootfs[dirs] = &quot;${DEPLOYDIR} ${DEPLOY_DIR_IMAGE}&quot;<br>
&gt; +DEPLOYDIR = &quot;${IMGDEPLOYDIR}&quot;<br>
&gt; +IMAGE_LINK_NAME ?= &quot;baremetal-helloworld-image-${MACHINE}&quot;<br>
&gt; +IMAGE_NAME_SUFFIX ?= &quot;&quot;<br>
&gt; +<br>
&gt; +do_deploy(){<br>
&gt; +    install ${D}/${datadir}/hello_baremetal_${MACHINE}.bin ${DEPLOYDIR}/${IMAGE_LINK_NAME}.bin<br>
&gt; +    install ${D}/${datadir}/hello_baremetal_${MACHINE}.elf ${DEPLOYDIR}/${IMAGE_LINK_NAME}.elf<br>
&gt; +}<br>
&gt; +<br>
&gt; +do_image(){<br>
&gt; +    :<br>
&gt; +}<br>
&gt; +<br>
&gt; +FILES_${PN} += &quot; \<br>
&gt; +    ${datadir}/hello_baremetal_${MACHINE}.bin \<br>
&gt; +    ${datadir}/hello_baremetal_${MACHINE}.elf \<br>
&gt; +&quot;<br>
&gt; +<br>
&gt; +python do_rootfs(){<br>
&gt; +    from oe.utils import execute_pre_post_process<br>
&gt; +    from pathlib import Path<br>
&gt; +<br>
&gt; +    # Write empty manifest testdate file<br>
&gt; +    deploy_dir = d.getVar(&#39;DEPLOYDIR&#39;)<br>
&gt; +    link_name = d.getVar(&#39;IMAGE_LINK_NAME&#39;)<br>
&gt; +    manifest_name = d.getVar(&#39;IMAGE_MANIFEST&#39;)<br>
&gt; +<br>
&gt; +    Path(manifest_name).touch()<br>
&gt; +    if os.path.exists(manifest_name) and link_name:<br>
&gt; +        manifest_link = deploy_dir + &quot;/&quot; + link_name + &quot;.manifest&quot;<br>
&gt; +        if os.path.lexists(manifest_link):<br>
&gt; +            os.remove(manifest_link)<br>
&gt; +        os.symlink(os.path.basename(manifest_name), manifest_link)<br>
&gt; +    execute_pre_post_process(d, d.getVar(&#39;ROOTFS_POSTPROCESS_COMMAND&#39;))<br>
&gt; +}<br>
&gt; +<br>
&gt; +# QEMU generic FreeRTOS parameters<br>
&gt; +QB_DEFAULT_KERNEL = &quot;${IMAGE_LINK_NAME}.bin&quot;<br>
&gt; +QB_MEM = &quot;-m 256&quot;<br>
&gt; +QB_OPT_APPEND = &quot;-nographic&quot;<br>
&gt; +QB_DEFAULT_FSTYPE = &quot;bin&quot;<br>
&gt; +QB_DTB = &quot;&quot;<br>
&gt; +<br>
&gt; +# This next part is necessary to trick the build system into thinking<br>
&gt; +# its building an image recipe so it generates the qemuboot.conf<br>
&gt; +addtask do_deploy after do_write_qemuboot_conf before do_build<br>
&gt; +addtask do_rootfs before do_deploy after do_install<br>
&gt; +addtask do_image after do_rootfs before do_build<br>
&gt; +inherit qemuboot<br>
&gt; +<br>
&gt; +# Based on image.bbclass to make sure we build qemu<br>
&gt; +python(){<br>
&gt; +    # do_addto_recipe_sysroot doesnt exist for all recipes, but we need it to have<br>
&gt; +    # /usr/bin on recipe-sysroot (qemu) populated<br>
&gt; +    def extraimage_getdepends(task):<br>
&gt; +        deps = &quot;&quot;<br>
&gt; +        for dep in (d.getVar(&#39;EXTRA_IMAGEDEPENDS&#39;) or &quot;&quot;).split():<br>
&gt; +        # Make sure we only add it for qemu<br>
&gt; +            if &#39;qemu&#39; in dep:<br>
&gt; +                deps += &quot; %s:%s&quot; % (dep, task)<br>
&gt; +        return deps<br>
&gt; +    d.appendVarFlag(&#39;do_image&#39;, &#39;depends&#39;, extraimage_getdepends(&#39;do_addto_recipe_sysroot&#39;))<br>
&gt; +    d.appendVarFlag(&#39;do_image&#39;, &#39;depends&#39;, extraimage_getdepends(&#39;do_populate_sysroot&#39;))<br>
&gt; +}<br>
&gt; --<br>
&gt; 2.7.4<br>
<br>
Thanks,<br>
Paul<br>
</blockquote></div></div></div>