Skip to content

Commit

Permalink
initial qemu support
Browse files Browse the repository at this point in the history
Signed-off-by: enes.colpan <[email protected]>
  • Loading branch information
colpane authored and BaochengSu committed Jul 26, 2023
1 parent fdc6eee commit 406467d
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 5 deletions.
20 changes: 19 additions & 1 deletion Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ endif
# Provide two entries so that the help text can be adjusted to the image.
config SECURE_BOOT
bool "Secure boot & Data encryption"
depends on IMAGE_SWUPDATE
depends on IMAGE_SWUPDATE && !IMAGE_QEMU
help
Enable signing of boot artifacts (boot loader, unified kernel image).
Furthermore activate dm-verity integrity protection for the read-only
Expand Down Expand Up @@ -149,6 +149,24 @@ config RPMB_SETUP
only in a secure environment on the target device, then replace it
with signed production firmware and enable secure boot.

config IMAGE_QEMU
bool "QEMU Image"
depends on IMAGE_EXAMPLE || IMAGE_SWUPDATE
help
QEMU image to boot image without real hardware. The device emulated
by QEMU is not identical to a physical IOT2050. This leads to missing
or limited features such as Arduino I/Os, only one ethernet port,
virtual debug serial port, qemu version of u-boot, no watchdog, only
virtual drives, performance issues etc.

WARNING: Please be aware of potential problems when using the image
for testing purposes.

config KAS_INCLUDE_QEMU_IMAGE
string
default "kas-iot2050-qemu.yml"
depends on IMAGE_QEMU

config KAS_INCLUDE_SECURE_BOOT
string
default "kas/opt/secure-boot.yml"
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,24 @@ The SDK is also available as docker image. To import it into a docker host, run
docker load -i build/tmp/deploy/images/iot2050/sdk-iot2050-debian-arm64-docker-archive.tar.xz
```

## Build qemu image

To boot IOT2050 image from qemu, you need a customized image for proper booting.
Please use kas menu with the following command and select qemu image for target build
with example image or example image with swupdate support

```shell
./kas-container menu
```

Then below command can be used to boot qemu image on a platform that
qemu-system-aarch64 is installed.

Run qemu:
```shell
/bin/sh start-qemu-iot2050.sh"
```
## Clean build result
```shell
Expand Down
19 changes: 19 additions & 0 deletions conf/machine/iot2050-qemu.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# Copyright (c) Siemens AG, 2023
#
# Authors:
# Enes Colpan <[email protected]>
#
# This file is subject to the terms and conditions of the MIT License. See
# COPYING.MIT file in the top-level directory.
#

require conf/machine/iot2050.conf

DTB_FILES = ""

CONSOLE_KERNEL_PARAMS = ""

QEMU_IMAGE = "1"

PREFERRED_PROVIDER_u-boot-${MACHINE} = "u-boot-qemu-arm64"
2 changes: 2 additions & 0 deletions conf/machine/iot2050.conf
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ IMAGE_INSTALL += "u-boot-script"

# only relevant for SWUpdate image
SWUPDATE_BOOTLOADER = "efibootguard"

CONSOLE_KERNEL_PARAMS ?= "console=ttyS3,115200n8 earlycon=ns16550a,mmio32,0x02810000"
16 changes: 16 additions & 0 deletions kas-iot2050-qemu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#
# Copyright (c) Siemens AG, 2023
#
# This file is subject to the terms and conditions of the MIT License. See
# COPYING.MIT file in the top-level directory.
#

header:
version: 10

machine: iot2050-qemu

local_conf_header:
firmware-binaries: |
# Add U-Boot for qemu
IMAGER_BUILD_DEPS:append:iot2050-qemu = " u-boot-iot2050-qemu"
2 changes: 1 addition & 1 deletion recipes-core/images/iot2050-image-base.bb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ inherit image

DESCRIPTION = "IOT2050 Debian Base Image"

IMAGE_INSTALL += "u-boot-iot2050-config"
IMAGE_INSTALL += "${@ 'u-boot-${MACHINE}-config' if d.getVar('QEMU_IMAGE') != '1' else '' }"
IMAGE_INSTALL += "iot2050-firmware"
IMAGE_INSTALL += "customizations-base"

Expand Down
2 changes: 1 addition & 1 deletion recipes-core/images/iot2050-image-example.bb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ IMAGE_INSTALL += " \
node-red \
node-red-gpio \
node-red-preinstalled-nodes \
board-conf-tools \
${@ 'board-conf-tools' if d.getVar('QEMU_IMAGE') != '1' else '' } \
libteec1 \
optee-client-dev \
tee-supplicant \
Expand Down
2 changes: 1 addition & 1 deletion recipes-core/images/iot2050-image-swu-example.bb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ IMAGE_INSTALL:remove = "u-boot-script"
IMAGE_INSTALL += "customizations-swupdate"
IMAGE_INSTALL += "swupdate-handler-roundrobin"
IMAGE_INSTALL += "swupdate-complete-update-helper"
IMAGE_INSTALL += "iot2050-watchdog"
IMAGE_INSTALL += "${@ 'iot2050-watchdog' if d.getVar('QEMU_IMAGE') != '1' else '' }"

IMAGE_INSTALL:append:secureboot = " iot2050-efivarfs-helper"
81 changes: 81 additions & 0 deletions start-qemu-iot2050.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/bin/sh
#
# This script is derived from isar-cip-core
# repository for meta-iot2050.
#
# Copyright (c) Siemens AG, 2023
#
# Authors:
# Enes Colpan <[email protected]>
#
# SPDX-License-Identifier: MIT
#

DISTRO_RELEASE="iot2050-debian"
MACHINE="iot2050-qemu"

usage()
{
echo "Usage: $0 [QEMU_OPTIONS]"
echo
echo "The architecture defaults to the setting in .config.yaml and can be left out"
echo "if the built was done via \"kas-container menu\"."
echo
echo "Environment variables (default to settings in .config.yaml):"
echo " QEMU_PATH use a locally built QEMU version"
echo " IMAGE_SWUPDATE boot swupdate image"
echo " IMAGE_EXAMPLE boot example image"
exit 1
}

if grep -s -q "IMAGE_QEMU: false" .config.yaml; then
echo "Please select IMAGE_QEMU and rebuild image. The current image is not compatible with QEMU!"
usage
fi

QEMU=qemu-system-aarch64
QEMU_COMMON_OPTIONS=" \
-cpu cortex-a53 \
-smp 4 \
-m 2G \
-serial mon:stdio \
-netdev user,id=net,hostfwd=tcp:127.0.0.1:22222-:22 \
-machine virt \
-device virtio-serial-device \
-device virtconsole,chardev=con -chardev vc,id=con \
-device virtio-blk-device,drive=disk \
-device virtio-net-device,netdev=net"
KERNEL_CMDLINE=" \
root=/dev/vda1 rw"

if grep -s -q "IMAGE_EXAMPLE: true" .config.yaml; then
TARGET_IMAGE="iot2050-image-example"
elif grep -s -q "IMAGE_SWUPDATE: true" .config.yaml; then
SWUPDATE_BOOT="true"
TARGET_IMAGE="iot2050-image-swu-example"
fi

BASE_DIR=$(readlink -f $(dirname $0))
IMAGE_PREFIX="${BASE_DIR}/build/tmp/deploy/images/${MACHINE}/${TARGET_IMAGE}-${DISTRO_RELEASE}-${MACHINE}"

if [ -n "${SWUPDATE_BOOT}" ]; then

u_boot_bin=${FIRMWARE_BIN:-./build/tmp/deploy/images/${MACHINE}/firmware.bin}

${QEMU_PATH}${QEMU} \
-drive file=${IMAGE_PREFIX}.wic,discard=unmap,if=none,id=disk,format=raw \
-bios ${u_boot_bin} \
${QEMU_COMMON_OPTIONS} ${QEMU_EXTRA_ARGS} "$@"

else
IMAGE_FILE=$(ls ${IMAGE_PREFIX}.wic)

KERNEL_FILE=$(ls ${IMAGE_PREFIX}-vmlinu* | tail -1)
INITRD_FILE=$(ls ${IMAGE_PREFIX}-initrd.img* | tail -1)

${QEMU_PATH}${QEMU} \
-drive file=${IMAGE_FILE},discard=unmap,if=none,id=disk,format=raw \
-kernel ${KERNEL_FILE} -append "${KERNEL_CMDLINE}" \
-initrd ${INITRD_FILE} \
${QEMU_COMMON_OPTIONS} "$@"
fi
2 changes: 1 addition & 1 deletion wic/iot2050-swu.wks.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ part --source empty --align 1024 --fixed-size 4G --uuid "${ABROOTFS_PART_UUID_B}
part /var --source rootfs --rootfs-dir=${IMAGE_ROOTFS}/var --label var --fstype=ext4 --mkfs-extraopts "-T default" --ondisk sda --align 1024 --size 512M
part /home --source rootfs --rootfs-dir=${IMAGE_ROOTFS}/home --label home --fstype=ext4 --mkfs-extraopts "-T default" --ondisk sda --align 1024 --size 512M

bootloader --ptable gpt --append "console=ttyS3,115200n8 earlycon=ns16550a,mmio32,0x02810000 rootwait watchdog.handle_boot_enabled=0 ${EXTRA_KERNEL_PARAMS}"
bootloader --ptable gpt --append "${CONSOLE_KERNEL_PARAMS} rootwait watchdog.handle_boot_enabled=0 ${EXTRA_KERNEL_PARAMS}"

0 comments on commit 406467d

Please sign in to comment.