diff options
author | Alejandro Hernandez Samaniego <alejandro@enedino.org> | 2023-01-08 12:15:23 -0700 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2023-01-12 23:08:58 +0000 |
commit | 1149b4fbb6002aa5a4cfe90bd404834721593968 (patch) | |
tree | d3dc2b84a4390ef02ff8d20d4fd8f2923033755e /meta-skeleton | |
parent | dca9b920e08b102b377d74f870f73d5f3f377394 (diff) | |
download | poky-1149b4fbb6002aa5a4cfe90bd404834721593968.tar.gz |
baremetal-helloworld: Enable x86 and x86-64 ports
- The qemux86 port for helloworld-baremetal builds in the standard way, however,
it uses NASM syntax for the startup code, hence we include a dependency to
nasm-native, QEMU forces us to use an ELF file rather than a bin file to boot
from this architecture using the -kernel parameter.
- QEMU refuses to boot using the -kernel parameter for files containing an ELF64
header [1], instead, it requires a multiboot2 compatible image.
We could create an image that contains a multiboot2 header by piggybacking
into grub2-native, specifically grub-mkrescue, but it requires some extra
runtime dependencies (xorriso which is currently part of meta-oe), and assumes
a grub installation exists on the host.
Due to host contamination and dependency complications, we dont rely on grub2,
but rather do this process manually instead, the x86-64 port contains a stage1
bootloader, stage2 bootloader and a 64 bit baremetal app (multiboot2
compatible), booting into real (16 bit), protected (32 bit) and long (64 bit)
modes, eventually running the helloworld-baremetal app. This is the reason why
we need the code changes to use a separate Makefile, and create an image
specifically for qemux86-64.
$ runqemu nographic
Booting from ROM..
Hello OpenEmbedded on x86!
$ runqemu nographic
Starting Stage 1 Bootloader
Loading Stage 2 Bootloader
Stage 2 Loaded.
Jumping to Stage2 Bootloader
In Stage 2
Done
Hello OpenEmbedded on x86-64!
[1] https://gitlab.com/qemu-project/qemu/-/blob/v7.2.0/hw/i386/multiboot.c#L199
(From OE-Core rev: 1dffd81b2991f90ab95cb36d8ff7626efd21434f)
Signed-off-by: Alejandro Enedino Hernandez Samaniego <alejandro@enedino.org>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta-skeleton')
-rw-r--r-- | meta-skeleton/recipes-baremetal/baremetal-examples/baremetal-helloworld_git.bb | 22 |
1 files changed, 20 insertions, 2 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 index d11e2e530e..fede17b0f0 100644 --- a/meta-skeleton/recipes-baremetal/baremetal-examples/baremetal-helloworld_git.bb +++ b/meta-skeleton/recipes-baremetal/baremetal-examples/baremetal-helloworld_git.bb | |||
@@ -4,7 +4,7 @@ DESCRIPTION = "These are introductory examples to showcase the use of QEMU to ru | |||
4 | LICENSE = "MIT" | 4 | LICENSE = "MIT" |
5 | LIC_FILES_CHKSUM = "file://LICENSE;md5=39346640a23c701e4f459e05f56f4449" | 5 | LIC_FILES_CHKSUM = "file://LICENSE;md5=39346640a23c701e4f459e05f56f4449" |
6 | 6 | ||
7 | SRCREV = "31b4e5a337018b4a00a7426b0e5ed83b81df30c7" | 7 | SRCREV = "22016ecbb9fb6c5f3a7a06698aea7ff8a701c166" |
8 | PV = "0.1+git${SRCPV}" | 8 | PV = "0.1+git${SRCPV}" |
9 | 9 | ||
10 | SRC_URI = "git://github.com/aehs29/baremetal-helloqemu.git;protocol=https;branch=master" | 10 | SRC_URI = "git://github.com/aehs29/baremetal-helloqemu.git;protocol=https;branch=master" |
@@ -23,12 +23,15 @@ IMAGE_NAME_SUFFIX ?= "" | |||
23 | inherit baremetal-image | 23 | inherit baremetal-image |
24 | 24 | ||
25 | 25 | ||
26 | # startup code for x86 uses NASM syntax | ||
27 | DEPENDS:qemux86:append = " nasm-native" | ||
28 | |||
26 | # These parameters are app specific for this example | 29 | # These parameters are app specific for this example |
27 | # This will be translated automatically to the architecture and | 30 | # This will be translated automatically to the architecture and |
28 | # machine that QEMU uses on OE, e.g. -machine virt -cpu cortex-a57 | 31 | # machine that QEMU uses on OE, e.g. -machine virt -cpu cortex-a57 |
29 | # but the examples can also be run on other architectures/machines | 32 | # but the examples can also be run on other architectures/machines |
30 | # such as vexpress-a15 by overriding the setting on the machine.conf | 33 | # such as vexpress-a15 by overriding the setting on the machine.conf |
31 | COMPATIBLE_MACHINE = "qemuarmv5|qemuarm|qemuarm64|qemuriscv64|qemuriscv32" | 34 | COMPATIBLE_MACHINE = "qemuarmv5|qemuarm|qemuarm64|qemuriscv64|qemuriscv32|qemux86|qemux86-64" |
32 | 35 | ||
33 | BAREMETAL_QEMUARCH ?= "" | 36 | BAREMETAL_QEMUARCH ?= "" |
34 | BAREMETAL_QEMUARCH:qemuarmv5 = "versatile" | 37 | BAREMETAL_QEMUARCH:qemuarmv5 = "versatile" |
@@ -36,9 +39,15 @@ BAREMETAL_QEMUARCH:qemuarm = "arm" | |||
36 | BAREMETAL_QEMUARCH:qemuarm64 = "aarch64" | 39 | BAREMETAL_QEMUARCH:qemuarm64 = "aarch64" |
37 | BAREMETAL_QEMUARCH:qemuriscv64 = "riscv64" | 40 | BAREMETAL_QEMUARCH:qemuriscv64 = "riscv64" |
38 | BAREMETAL_QEMUARCH:qemuriscv32 = "riscv32" | 41 | BAREMETAL_QEMUARCH:qemuriscv32 = "riscv32" |
42 | BAREMETAL_QEMUARCH:qemux86 = "x86" | ||
43 | BAREMETAL_QEMUARCH:qemux86-64 = "x86-64" | ||
39 | 44 | ||
40 | EXTRA_OEMAKE:append = " QEMUARCH=${BAREMETAL_QEMUARCH} V=1" | 45 | EXTRA_OEMAKE:append = " QEMUARCH=${BAREMETAL_QEMUARCH} V=1" |
41 | 46 | ||
47 | # qemux86-64 uses a different Makefile | ||
48 | do_compile:prepend:qemux86-64(){ | ||
49 | cd x86-64 | ||
50 | } | ||
42 | 51 | ||
43 | # Install binaries on the proper location for baremetal-image to fetch and deploy | 52 | # Install binaries on the proper location for baremetal-image to fetch and deploy |
44 | do_install(){ | 53 | do_install(){ |
@@ -51,3 +60,12 @@ FILES:${PN} += " \ | |||
51 | ${base_libdir}/firmware/${BAREMETAL_BINNAME}.bin \ | 60 | ${base_libdir}/firmware/${BAREMETAL_BINNAME}.bin \ |
52 | ${base_libdir}/firmware/${BAREMETAL_BINNAME}.elf \ | 61 | ${base_libdir}/firmware/${BAREMETAL_BINNAME}.elf \ |
53 | " | 62 | " |
63 | |||
64 | # qemux86-64 boots from iso rather than -kernel, create image to boot from | ||
65 | do_image:append:qemux86-64(){ | ||
66 | dd if=/dev/zero of=${B}/build/img.iso bs=1M count=10 status=none | ||
67 | dd if=${B}/build/stage1.bin of=${B}/build/img.iso bs=512 count=1 conv=notrunc | ||
68 | dd if=${B}/build/stage2.bin of=${B}/build/img.iso bs=512 seek=1 count=64 conv=notrunc | ||
69 | dd if=${B}/build/hello_baremetal_x86-64.bin of=${B}/build/img.iso bs=512 seek=65 conv=notrunc | ||
70 | install ${B}/build/img.iso ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.iso | ||
71 | } | ||