diff options
author | Alejandro Enedino Hernandez Samaniego <alejandro@enedino.org> | 2020-01-31 01:54:42 -0800 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2020-02-05 12:00:34 +0000 |
commit | 2534c1379c641c99fcb67b4873d5d0b67de25b51 (patch) | |
tree | 124a1ed9d15cdd5edcdf463e8cd596a0acce4e5b /meta-skeleton/recipes-baremetal | |
parent | 3c6978c8db59f152693f9fae65dbab13ecfcaad4 (diff) | |
download | poky-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.bb | 105 |
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 @@ | |||
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 | do_deploy[dirs] = "${DEPLOYDIR} ${DEPLOY_DIR_IMAGE}" | ||
41 | do_rootfs[dirs] = "${DEPLOYDIR} ${DEPLOY_DIR_IMAGE}" | ||
42 | DEPLOYDIR = "${IMGDEPLOYDIR}" | ||
43 | IMAGE_LINK_NAME ?= "baremetal-helloworld-image-${MACHINE}" | ||
44 | IMAGE_NAME_SUFFIX ?= "" | ||
45 | |||
46 | do_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 | |||
51 | do_image(){ | ||
52 | : | ||
53 | } | ||
54 | |||
55 | FILES_${PN} += " \ | ||
56 | ${datadir}/hello_baremetal_${MACHINE}.bin \ | ||
57 | ${datadir}/hello_baremetal_${MACHINE}.elf \ | ||
58 | " | ||
59 | |||
60 | python 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 | ||
79 | QB_DEFAULT_KERNEL = "${IMAGE_LINK_NAME}.bin" | ||
80 | QB_MEM = "-m 256" | ||
81 | QB_OPT_APPEND = "-nographic" | ||
82 | QB_DEFAULT_FSTYPE = "bin" | ||
83 | QB_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 | ||
87 | addtask do_deploy after do_write_qemuboot_conf before do_build | ||
88 | addtask do_rootfs before do_deploy after do_install | ||
89 | addtask do_image after do_rootfs before do_build | ||
90 | inherit qemuboot | ||
91 | |||
92 | # Based on image.bbclass to make sure we build qemu | ||
93 | python(){ | ||
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 | } | ||