blob: cb9e250350084171e32e9a5bbc1d010c1e88083d [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"
Patrick Williams213cb262021-08-07 19:21:33 -050015COMPATIBLE_HOST:libc-musl:class-target = "null"
16COMPATIBLE_HOST:libc-glibc:class-target = "null"
Andrew Geissler475cb722020-07-10 16:00:51 -050017
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"
Andrew Geissler78b72792022-06-14 06:47:25 -050050 if manifest_link != manifest_name:
51 if os.path.lexists(manifest_link):
52 os.remove(manifest_link)
53 os.symlink(os.path.basename(manifest_name), manifest_link)
William A. Kennington IIIac69b482021-06-02 12:28:27 -070054 # A lot of postprocess commands assume the existence of rootfs/etc
55 sysconfdir = d.getVar("IMAGE_ROOTFS") + d.getVar('sysconfdir')
56 bb.utils.mkdirhier(sysconfdir)
57
Andrew Geissler475cb722020-07-10 16:00:51 -050058 execute_pre_post_process(d, d.getVar('ROOTFS_POSTPROCESS_COMMAND'))
59}
60
61
62# Assure binaries, manifest and qemubootconf are populated on DEPLOY_DIR_IMAGE
63do_image_complete[dirs] = "${TOPDIR}"
Andrew Geissler475cb722020-07-10 16:00:51 -050064SSTATETASKS += "do_image_complete"
Patrick Williams213cb262021-08-07 19:21:33 -050065SSTATE_SKIP_CREATION:task-image-complete = '1'
Andrew Geissler475cb722020-07-10 16:00:51 -050066do_image_complete[sstate-inputdirs] = "${IMGDEPLOYDIR}"
67do_image_complete[sstate-outputdirs] = "${DEPLOY_DIR_IMAGE}"
68do_image_complete[stamp-extra-info] = "${MACHINE_ARCH}"
69addtask do_image_complete after do_image before do_build
70
71python do_image_complete_setscene () {
72 sstate_setscene(d)
73}
74addtask do_image_complete_setscene
75
76# QEMU generic Baremetal/RTOS parameters
77QB_DEFAULT_KERNEL ?= "${IMAGE_LINK_NAME}.bin"
78QB_MEM ?= "-m 256"
79QB_DEFAULT_FSTYPE ?= "bin"
80QB_DTB ?= ""
Patrick Williams213cb262021-08-07 19:21:33 -050081QB_OPT_APPEND:append = " -nographic"
William A. Kennington IIIac69b482021-06-02 12:28:27 -070082
83# RISC-V tunes set the BIOS, unset, and instruct QEMU to
84# ignore the BIOS and boot from -kernel
Patrick Williams213cb262021-08-07 19:21:33 -050085QB_DEFAULT_BIOS:qemuriscv64 = ""
Patrick Williams0ca19cc2021-08-16 14:03:13 -050086QB_DEFAULT_BIOS:qemuriscv32 = ""
Patrick Williams213cb262021-08-07 19:21:33 -050087QB_OPT_APPEND:append:qemuriscv64 = " -bios none"
Patrick Williams0ca19cc2021-08-16 14:03:13 -050088QB_OPT_APPEND:append:qemuriscv32 = " -bios none"
William A. Kennington IIIac69b482021-06-02 12:28:27 -070089
90
91# Use the medium-any code model for the RISC-V 64 bit implementation,
92# since medlow can only access addresses below 0x80000000 and RAM
93# starts at 0x80000000 on RISC-V 64
Patrick Williams0ca19cc2021-08-16 14:03:13 -050094# Keep RISC-V 32 using -mcmodel=medlow (symbols lie between -2GB:2GB)
Patrick Williams213cb262021-08-07 19:21:33 -050095CFLAGS:append:qemuriscv64 = " -mcmodel=medany"
William A. Kennington IIIac69b482021-06-02 12:28:27 -070096
Andrew Geissler475cb722020-07-10 16:00:51 -050097
98# This next part is necessary to trick the build system into thinking
99# its building an image recipe so it generates the qemuboot.conf
100addtask do_rootfs before do_image after do_install
101addtask do_image after do_rootfs before do_image_complete
102addtask do_image_complete after do_image before do_build
103inherit qemuboot
104
105# Based on image.bbclass to make sure we build qemu
106python(){
107 # do_addto_recipe_sysroot doesnt exist for all recipes, but we need it to have
108 # /usr/bin on recipe-sysroot (qemu) populated
Andrew Geisslereff27472021-10-29 15:35:00 -0500109 # The do_addto_recipe_sysroot dependency is coming from EXTRA_IMAGDEPENDS now,
110 # we just need to add the logic to add its dependency to do_image.
Andrew Geissler475cb722020-07-10 16:00:51 -0500111 def extraimage_getdepends(task):
112 deps = ""
113 for dep in (d.getVar('EXTRA_IMAGEDEPENDS') or "").split():
114 # Make sure we only add it for qemu
115 if 'qemu' in dep:
Andrew Geisslereff27472021-10-29 15:35:00 -0500116 if ":" in dep:
117 deps += " %s " % (dep)
118 else:
119 deps += " %s:%s" % (dep, task)
Andrew Geissler475cb722020-07-10 16:00:51 -0500120 return deps
Andrew Geisslereff27472021-10-29 15:35:00 -0500121 d.appendVarFlag('do_image', 'depends', extraimage_getdepends('do_populate_sysroot'))
Andrew Geissler475cb722020-07-10 16:00:51 -0500122}