summaryrefslogtreecommitdiffstats
path: root/meta
diff options
context:
space:
mode:
authorAlejandro Hernandez <alejandro@enedino.org>2020-07-05 23:50:21 -0700
committerRichard Purdie <richard.purdie@linuxfoundation.org>2020-07-08 10:37:12 +0100
commit9ab3e05ad0ee120d2bb37bf01ca5f02d44f86d33 (patch)
treea3a823b5e850d31c92a21b89de99b294aa966955 /meta
parent5e8f88570be5966d2e26d9662ba53d58f7c4e3f9 (diff)
downloadpoky-9ab3e05ad0ee120d2bb37bf01ca5f02d44f86d33.tar.gz
baremetal-image.bbclass: Create a class for baremetal applications or an RTOS
Baremetal applications or an RTOS built with OpenEmbedded can share the same code to be built as an image, tested and packaged in case they can be updated as a firmware blob from Linux. This class creates the proper wiring to mimic OE Linux image creation and testing infrastructure, inheriting it makes the process of creating a baremetal application transparent to the developer deploying it automatically along with its required bits to be run and tested. (From OE-Core rev: 34df656e1d7070337f62c8fd9b2dc27491275416) Signed-off-by: Alejandro Hernandez Samaniego <alejandro@enedino.org> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta')
-rw-r--r--meta/classes/baremetal-image.bbclass99
1 files changed, 99 insertions, 0 deletions
diff --git a/meta/classes/baremetal-image.bbclass b/meta/classes/baremetal-image.bbclass
new file mode 100644
index 0000000000..90d58f2615
--- /dev/null
+++ b/meta/classes/baremetal-image.bbclass
@@ -0,0 +1,99 @@
1# Baremetal image class
2#
3# This class is meant to be inherited by recipes for baremetal/RTOS applications
4# It contains code that would be used by all of them, every recipe just needs to
5# override certain variables.
6#
7# For scalability purposes, code within this class focuses on the "image" wiring
8# to satisfy the OpenEmbedded image creation and testing infrastructure.
9#
10# See meta-skeleton for a working example.
11
12
13# Toolchain should be baremetal or newlib based.
14# TCLIBC="baremetal" or TCLIBC="newlib"
15COMPATIBLE_HOST_libc-musl_class-target = "null"
16COMPATIBLE_HOST_libc-glibc_class-target = "null"
17
18
19inherit rootfs-postcommands
20
21# Set some defaults, but these should be overriden by each recipe if required
22IMGDEPLOYDIR ?= "${WORKDIR}/deploy-${PN}-image-complete"
23BAREMETAL_BINNAME ?= "hello_baremetal_${MACHINE}"
24IMAGE_LINK_NAME ?= "baremetal-helloworld-image-${MACHINE}"
25IMAGE_NAME_SUFFIX ?= ""
26
27do_rootfs[dirs] = "${IMGDEPLOYDIR} ${DEPLOY_DIR_IMAGE}"
28
29do_image(){
30 install ${D}/${base_libdir}/firmware/${BAREMETAL_BINNAME}.bin ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.bin
31 install ${D}/${base_libdir}/firmware/${BAREMETAL_BINNAME}.elf ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.elf
32}
33
34do_image_complete(){
35 :
36}
37
38python do_rootfs(){
39 from oe.utils import execute_pre_post_process
40 from pathlib import Path
41
42 # Write empty manifest file to satisfy test infrastructure
43 deploy_dir = d.getVar('IMGDEPLOYDIR')
44 link_name = d.getVar('IMAGE_LINK_NAME')
45 manifest_name = d.getVar('IMAGE_MANIFEST')
46
47 Path(manifest_name).touch()
48 if os.path.exists(manifest_name) and link_name:
49 manifest_link = deploy_dir + "/" + link_name + ".manifest"
50 if os.path.lexists(manifest_link):
51 os.remove(manifest_link)
52 os.symlink(os.path.basename(manifest_name), manifest_link)
53 execute_pre_post_process(d, d.getVar('ROOTFS_POSTPROCESS_COMMAND'))
54}
55
56
57# Assure binaries, manifest and qemubootconf are populated on DEPLOY_DIR_IMAGE
58do_image_complete[dirs] = "${TOPDIR}"
59do_image_complete[umask] = "022"
60SSTATETASKS += "do_image_complete"
61SSTATE_SKIP_CREATION_task-image-complete = '1'
62do_image_complete[sstate-inputdirs] = "${IMGDEPLOYDIR}"
63do_image_complete[sstate-outputdirs] = "${DEPLOY_DIR_IMAGE}"
64do_image_complete[stamp-extra-info] = "${MACHINE_ARCH}"
65addtask do_image_complete after do_image before do_build
66
67python do_image_complete_setscene () {
68 sstate_setscene(d)
69}
70addtask do_image_complete_setscene
71
72# QEMU generic Baremetal/RTOS parameters
73QB_DEFAULT_KERNEL ?= "${IMAGE_LINK_NAME}.bin"
74QB_MEM ?= "-m 256"
75QB_DEFAULT_FSTYPE ?= "bin"
76QB_DTB ?= ""
77QB_OPT_APPEND = "-nographic"
78
79# This next part is necessary to trick the build system into thinking
80# its building an image recipe so it generates the qemuboot.conf
81addtask do_rootfs before do_image after do_install
82addtask do_image after do_rootfs before do_image_complete
83addtask do_image_complete after do_image before do_build
84inherit qemuboot
85
86# Based on image.bbclass to make sure we build qemu
87python(){
88 # do_addto_recipe_sysroot doesnt exist for all recipes, but we need it to have
89 # /usr/bin on recipe-sysroot (qemu) populated
90 def extraimage_getdepends(task):
91 deps = ""
92 for dep in (d.getVar('EXTRA_IMAGEDEPENDS') or "").split():
93 # Make sure we only add it for qemu
94 if 'qemu' in dep:
95 deps += " %s:%s" % (dep, task)
96 return deps
97 d.appendVarFlag('do_image', 'depends', extraimage_getdepends('do_addto_recipe_sysroot'))
98 d.appendVarFlag('do_image', 'depends', extraimage_getdepends('do_populate_sysroot'))
99}