blob: b0f5e885b5ccf77a3650deae357b9a14afdb01da [file] [log] [blame]
Andrew Geissler475cb722020-07-10 16:00:51 -05001# 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}"
Andrew Geissler475cb722020-07-10 16:00:51 -050059SSTATETASKS += "do_image_complete"
60SSTATE_SKIP_CREATION_task-image-complete = '1'
61do_image_complete[sstate-inputdirs] = "${IMGDEPLOYDIR}"
62do_image_complete[sstate-outputdirs] = "${DEPLOY_DIR_IMAGE}"
63do_image_complete[stamp-extra-info] = "${MACHINE_ARCH}"
64addtask do_image_complete after do_image before do_build
65
66python do_image_complete_setscene () {
67 sstate_setscene(d)
68}
69addtask do_image_complete_setscene
70
71# QEMU generic Baremetal/RTOS parameters
72QB_DEFAULT_KERNEL ?= "${IMAGE_LINK_NAME}.bin"
73QB_MEM ?= "-m 256"
74QB_DEFAULT_FSTYPE ?= "bin"
75QB_DTB ?= ""
76QB_OPT_APPEND = "-nographic"
77
78# This next part is necessary to trick the build system into thinking
79# its building an image recipe so it generates the qemuboot.conf
80addtask do_rootfs before do_image after do_install
81addtask do_image after do_rootfs before do_image_complete
82addtask do_image_complete after do_image before do_build
83inherit qemuboot
84
85# Based on image.bbclass to make sure we build qemu
86python(){
87 # do_addto_recipe_sysroot doesnt exist for all recipes, but we need it to have
88 # /usr/bin on recipe-sysroot (qemu) populated
89 def extraimage_getdepends(task):
90 deps = ""
91 for dep in (d.getVar('EXTRA_IMAGEDEPENDS') or "").split():
92 # Make sure we only add it for qemu
93 if 'qemu' in dep:
94 deps += " %s:%s" % (dep, task)
95 return deps
96 d.appendVarFlag('do_image', 'depends', extraimage_getdepends('do_addto_recipe_sysroot'))
97 d.appendVarFlag('do_image', 'depends', extraimage_getdepends('do_populate_sysroot'))
98}