summaryrefslogtreecommitdiffstats
path: root/meta-skeleton/recipes-baremetal
diff options
context:
space:
mode:
authorAlejandro Enedino Hernandez Samaniego <alejandro@enedino.org>2020-01-31 01:54:42 -0800
committerRichard Purdie <richard.purdie@linuxfoundation.org>2020-02-05 12:00:34 +0000
commit2534c1379c641c99fcb67b4873d5d0b67de25b51 (patch)
tree124a1ed9d15cdd5edcdf463e8cd596a0acce4e5b /meta-skeleton/recipes-baremetal
parent3c6978c8db59f152693f9fae65dbab13ecfcaad4 (diff)
downloadpoky-2534c1379c641c99fcb67b4873d5d0b67de25b51.tar.gz
baremetal-helloworld: Create recipe for baremetal examples on QEMU
Create HelloWorld examples that run on several of the QEMU architectures supported by the build system. This recipe can be used by anyone to understand how baremetal applications can be built using OpenEmbedded and how the wiring to set them up could be. This should also facilitate creating/extending the OE testing infrastructure to allow baremetal applications or RTOSs to be tested in the same way that Linux currently is. This can easily be extended to work on other MACHINES in the future. To run this example: $ source oe-init-buildenv $ bitbake-layers add-layer ../meta-skeleton # TCLIBC="baremetal" would work as well $ echo "TCLIBC = \"newlib\"" >> ./conf/local.conf $ echo "MACHINE = \"qemuarm64\"" >> ./conf/local.conf $ bitbake baremetal-helloworld $ runqemu runqemu - INFO - Running bitbake -e ... runqemu - INFO - Continuing with the following parameters: KERNEL: [tmp/deploy/images/qemuarm64/baremetal-helloworld-qemuarm64.bin] MACHINE: [qemuarm64] FSTYPE: [bin] ROOTFS: [tmp/deploy/images/qemuarm64/baremetal-helloworld-qemuarm64.bin] CONFFILE: [tmp/deploy/images/qemuarm64/baremetal-helloworld-qemuarm64.qemuboot.conf] Hello OpenEmbedded! (From OE-Core rev: b314e9a0923c8aa95a2f2c3f48d956206e9885a7) Signed-off-by: Alejandro Enedino Hernandez Samaniego <alejandro@enedino.org> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta-skeleton/recipes-baremetal')
-rw-r--r--meta-skeleton/recipes-baremetal/baremetal-examples/baremetal-helloworld_git.bb105
1 files changed, 105 insertions, 0 deletions
diff --git a/meta-skeleton/recipes-baremetal/baremetal-examples/baremetal-helloworld_git.bb b/meta-skeleton/recipes-baremetal/baremetal-examples/baremetal-helloworld_git.bb
new file mode 100644
index 0000000000..d8633702fc
--- /dev/null
+++ b/meta-skeleton/recipes-baremetal/baremetal-examples/baremetal-helloworld_git.bb
@@ -0,0 +1,105 @@
1SUMMARY = "Baremetal examples to work with the several QEMU architectures supported on OpenEmbedded"
2HOMEPAGE = "https://github.com/aehs29/baremetal-helloqemu"
3LICENSE = "MIT"
4LIC_FILES_CHKSUM = "file://LICENSE;md5=39346640a23c701e4f459e05f56f4449"
5
6SRCREV = "99f4fa4a3b266b42b52af302610b0f4f429ba5e3"
7PV = "0.1+git${SRCPV}"
8
9SRC_URI = "git://github.com/aehs29/baremetal-helloqemu.git;protocol=https;branch=master"
10
11S = "${WORKDIR}/git/"
12
13# These examples are not meant to be built when using either musl or glibc
14COMPATIBLE_HOST_libc-musl_class-target = "null"
15COMPATIBLE_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
21COMPATIBLE_MACHINE = "qemuarmv5|qemuarm|qemuarm64"
22
23BAREMETAL_QEMUARCH ?= ""
24BAREMETAL_QEMUARCH_qemuarmv5 = "versatile"
25BAREMETAL_QEMUARCH_qemuarm = "arm"
26BAREMETAL_QEMUARCH_qemuarm64 = "aarch64"
27
28
29EXTRA_OEMAKE_append = " QEMUARCH=${BAREMETAL_QEMUARCH} V=1"
30
31do_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
38inherit rootfs-postcommands
39inherit deploy
40do_deploy[dirs] = "${DEPLOYDIR} ${DEPLOY_DIR_IMAGE}"
41do_rootfs[dirs] = "${DEPLOYDIR} ${DEPLOY_DIR_IMAGE}"
42DEPLOYDIR = "${IMGDEPLOYDIR}"
43IMAGE_LINK_NAME ?= "baremetal-helloworld-image-${MACHINE}"
44IMAGE_NAME_SUFFIX ?= ""
45
46do_deploy(){
47 install ${D}/${datadir}/hello_baremetal_${MACHINE}.bin ${DEPLOYDIR}/${IMAGE_LINK_NAME}.bin
48 install ${D}/${datadir}/hello_baremetal_${MACHINE}.elf ${DEPLOYDIR}/${IMAGE_LINK_NAME}.elf
49}
50
51do_image(){
52 :
53}
54
55FILES_${PN} += " \
56 ${datadir}/hello_baremetal_${MACHINE}.bin \
57 ${datadir}/hello_baremetal_${MACHINE}.elf \
58"
59
60python do_rootfs(){
61 from oe.utils import execute_pre_post_process
62 from pathlib import Path
63
64 # Write empty manifest testdate file
65 deploy_dir = d.getVar('DEPLOYDIR')
66 link_name = d.getVar('IMAGE_LINK_NAME')
67 manifest_name = d.getVar('IMAGE_MANIFEST')
68
69 Path(manifest_name).touch()
70 if os.path.exists(manifest_name) and link_name:
71 manifest_link = deploy_dir + "/" + link_name + ".manifest"
72 if os.path.lexists(manifest_link):
73 os.remove(manifest_link)
74 os.symlink(os.path.basename(manifest_name), manifest_link)
75 execute_pre_post_process(d, d.getVar('ROOTFS_POSTPROCESS_COMMAND'))
76}
77
78# QEMU generic FreeRTOS parameters
79QB_DEFAULT_KERNEL = "${IMAGE_LINK_NAME}.bin"
80QB_MEM = "-m 256"
81QB_OPT_APPEND = "-nographic"
82QB_DEFAULT_FSTYPE = "bin"
83QB_DTB = ""
84
85# This next part is necessary to trick the build system into thinking
86# its building an image recipe so it generates the qemuboot.conf
87addtask do_deploy after do_write_qemuboot_conf before do_build
88addtask do_rootfs before do_deploy after do_install
89addtask do_image after do_rootfs before do_build
90inherit qemuboot
91
92# Based on image.bbclass to make sure we build qemu
93python(){
94 # do_addto_recipe_sysroot doesnt exist for all recipes, but we need it to have
95 # /usr/bin on recipe-sysroot (qemu) populated
96 def extraimage_getdepends(task):
97 deps = ""
98 for dep in (d.getVar('EXTRA_IMAGEDEPENDS') or "").split():
99 # Make sure we only add it for qemu
100 if 'qemu' in dep:
101 deps += " %s:%s" % (dep, task)
102 return deps
103 d.appendVarFlag('do_image', 'depends', extraimage_getdepends('do_addto_recipe_sysroot'))
104 d.appendVarFlag('do_image', 'depends', extraimage_getdepends('do_populate_sysroot'))
105}