<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 &lt;<a href="mailto:raj.khem@gmail.com" target="_blank">raj.khem@gmail.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, Jan 27, 2020 at 2:01 AM Alejandro Enedino Hernandez Samaniego<br>
&lt;<a href="mailto:alejandro@enedino.org" rel="noreferrer" target="_blank">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" rel="noreferrer" target="_blank">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 think MIT or Apache-2.0 would be much nicer.<br></blockquote></div></div><br>I agree but this wasn&#39;t by choice, the original code written for the versatile architecture was licensed on CC-BY-SA, which AFAIC wouldn&#39;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&#39;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>
&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>
<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&#39;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>
&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>
<br>
this setting should be abstracted into something like  baremetal.bbclass<br>
<br>
<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>
<br>
copying sources to B why is that needed ?<br>
<br>
<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>
<br>
hmmm bad example to start of.<br>
<br>
&gt; +# Borrowed from meta-freertos<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>
<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&#39;ll have a lot on my plate and I&#39;m trying to split the work in chunks, so it doesn&#39;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>
&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><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>
&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>
&gt;<br>
&gt; --<br>
&gt; _______________________________________________<br>
&gt; Openembedded-core mailing list<br>
&gt; <a href="mailto:Openembedded-core@lists.openembedded.org" rel="noreferrer" target="_blank">Openembedded-core@lists.openembedded.org</a><br>
&gt; <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>