summaryrefslogtreecommitdiffstats
path: root/meta/classes-recipe/baremetal-image.bbclass
diff options
context:
space:
mode:
Diffstat (limited to 'meta/classes-recipe/baremetal-image.bbclass')
-rw-r--r--meta/classes-recipe/baremetal-image.bbclass128
1 files changed, 128 insertions, 0 deletions
diff --git a/meta/classes-recipe/baremetal-image.bbclass b/meta/classes-recipe/baremetal-image.bbclass
new file mode 100644
index 0000000000..3a979f2ed1
--- /dev/null
+++ b/meta/classes-recipe/baremetal-image.bbclass
@@ -0,0 +1,128 @@
1#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
6
7# Baremetal image class
8#
9# This class is meant to be inherited by recipes for baremetal/RTOS applications
10# It contains code that would be used by all of them, every recipe just needs to
11# override certain variables.
12#
13# For scalability purposes, code within this class focuses on the "image" wiring
14# to satisfy the OpenEmbedded image creation and testing infrastructure.
15#
16# See meta-skeleton for a working example.
17
18
19# Toolchain should be baremetal or newlib based.
20# TCLIBC="baremetal" or TCLIBC="newlib"
21COMPATIBLE_HOST:libc-musl:class-target = "null"
22COMPATIBLE_HOST:libc-glibc:class-target = "null"
23
24
25inherit rootfs-postcommands
26
27# Set some defaults, but these should be overriden by each recipe if required
28IMGDEPLOYDIR ?= "${WORKDIR}/deploy-${PN}-image-complete"
29BAREMETAL_BINNAME ?= "hello_baremetal_${MACHINE}"
30IMAGE_LINK_NAME ?= "baremetal-helloworld-image-${MACHINE}"
31IMAGE_NAME_SUFFIX ?= ""
32
33do_rootfs[dirs] = "${IMGDEPLOYDIR} ${DEPLOY_DIR_IMAGE}"
34
35do_image(){
36 install ${D}/${base_libdir}/firmware/${BAREMETAL_BINNAME}.bin ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.bin
37 install ${D}/${base_libdir}/firmware/${BAREMETAL_BINNAME}.elf ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.elf
38}
39
40do_image_complete(){
41 :
42}
43
44python do_rootfs(){
45 from oe.utils import execute_pre_post_process
46 from pathlib import Path
47
48 # Write empty manifest file to satisfy test infrastructure
49 deploy_dir = d.getVar('IMGDEPLOYDIR')
50 link_name = d.getVar('IMAGE_LINK_NAME')
51 manifest_name = d.getVar('IMAGE_MANIFEST')
52
53 Path(manifest_name).touch()
54 if os.path.exists(manifest_name) and link_name:
55 manifest_link = deploy_dir + "/" + link_name + ".manifest"
56 if manifest_link != manifest_name:
57 if os.path.lexists(manifest_link):
58 os.remove(manifest_link)
59 os.symlink(os.path.basename(manifest_name), manifest_link)
60 # A lot of postprocess commands assume the existence of rootfs/etc
61 sysconfdir = d.getVar("IMAGE_ROOTFS") + d.getVar('sysconfdir')
62 bb.utils.mkdirhier(sysconfdir)
63
64 execute_pre_post_process(d, d.getVar('ROOTFS_POSTPROCESS_COMMAND'))
65}
66
67
68# Assure binaries, manifest and qemubootconf are populated on DEPLOY_DIR_IMAGE
69do_image_complete[dirs] = "${TOPDIR}"
70SSTATETASKS += "do_image_complete"
71SSTATE_SKIP_CREATION:task-image-complete = '1'
72do_image_complete[sstate-inputdirs] = "${IMGDEPLOYDIR}"
73do_image_complete[sstate-outputdirs] = "${DEPLOY_DIR_IMAGE}"
74do_image_complete[stamp-extra-info] = "${MACHINE_ARCH}"
75addtask do_image_complete after do_image before do_build
76
77python do_image_complete_setscene () {
78 sstate_setscene(d)
79}
80addtask do_image_complete_setscene
81
82# QEMU generic Baremetal/RTOS parameters
83QB_DEFAULT_KERNEL ?= "${IMAGE_LINK_NAME}.bin"
84QB_MEM ?= "-m 256"
85QB_DEFAULT_FSTYPE ?= "bin"
86QB_DTB ?= ""
87QB_OPT_APPEND:append = " -nographic"
88
89# RISC-V tunes set the BIOS, unset, and instruct QEMU to
90# ignore the BIOS and boot from -kernel
91QB_DEFAULT_BIOS:qemuriscv64 = ""
92QB_DEFAULT_BIOS:qemuriscv32 = ""
93QB_OPT_APPEND:append:qemuriscv64 = " -bios none"
94QB_OPT_APPEND:append:qemuriscv32 = " -bios none"
95
96
97# Use the medium-any code model for the RISC-V 64 bit implementation,
98# since medlow can only access addresses below 0x80000000 and RAM
99# starts at 0x80000000 on RISC-V 64
100# Keep RISC-V 32 using -mcmodel=medlow (symbols lie between -2GB:2GB)
101CFLAGS:append:qemuriscv64 = " -mcmodel=medany"
102
103
104# This next part is necessary to trick the build system into thinking
105# its building an image recipe so it generates the qemuboot.conf
106addtask do_rootfs before do_image after do_install
107addtask do_image after do_rootfs before do_image_complete
108addtask do_image_complete after do_image before do_build
109inherit qemuboot
110
111# Based on image.bbclass to make sure we build qemu
112python(){
113 # do_addto_recipe_sysroot doesnt exist for all recipes, but we need it to have
114 # /usr/bin on recipe-sysroot (qemu) populated
115 # The do_addto_recipe_sysroot dependency is coming from EXTRA_IMAGDEPENDS now,
116 # we just need to add the logic to add its dependency to do_image.
117 def extraimage_getdepends(task):
118 deps = ""
119 for dep in (d.getVar('EXTRA_IMAGEDEPENDS') or "").split():
120 # Make sure we only add it for qemu
121 if 'qemu' in dep:
122 if ":" in dep:
123 deps += " %s " % (dep)
124 else:
125 deps += " %s:%s" % (dep, task)
126 return deps
127 d.appendVarFlag('do_image', 'depends', extraimage_getdepends('do_populate_sysroot'))
128}