Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add zephyr uos support #39

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions docs/getting-started-zephyr.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
Getting Started
---------------

Build acrn sos image having zephyr uos.

Dependencies
------------

This layer depends on:

| meta layer | git repository |
|-------------------|------------------------------------------------|
| poky | https://git.yoctoproject.org/git/poky |
| meta-intel | https://git.yoctoproject.org/git/meta-intel |
| meta-acrnl | https://github.com/intel/meta-acrn.git |
| meta-zephyr | https://git.yoctoproject.org/git/meta-zephyr |
| meta-openembedded | https://git.openembedded.org/meta-openembedded |

Add meta-openembedded/meta-oe and meta-openembedded/meta-python to bblayer.conf

Configuration
-------------

############################################################################################

Append below configuration to local.conf as follows:

```
MACHINE = "intel-corei7-64"
TMPDIR = "${TOPDIR}/master-acrn-sos"
DISTRO = "acrn-demo-sos"
PREFERRED_PROVIDER_virtual/kernel = "linux-intel-acrn-sos"

# Also use the 'uos' & 'zephyr' configuration
BBMULTICONFIG = "uos zephyr"

# The packages-from-images class (container-package.bbclass) needs to know where images are
CONTAINER_PACKAGE_DEPLOY_DIR = "${TOPDIR}/master-acrn-uos/deploy/images/${MACHINE}"
CONTAINER_PACKAGE_ZEPHYR_DEPLOY_DIR = "${TOPDIR}/master-zephyr-app/deploy/images/acrn"
CONTAINER_PACKAGE_MC = "uos"

# Zephyr application to be build & run
ZEPHYR_APP = "zephyr-helloworld"

# Add zephyr-image-base-package to acrn-image-base
IMAGE_INSTALL_append_pn-acrn-image-base = " zephyr-image-package"
```
############################################################################################

Configure `conf/multiconfig/uos.conf` as follows:

```
DISTRO="acrn-demo-uos"
TMPDIR = "${TOPDIR}/master-acrn-uos"
PREFERRED_PROVIDER_virtual/kernel = "linux-intel-acrn-uos"
```
############################################################################################

Configure `conf/multiconfig/zephyr.conf` as follows:

```
MACHINE= "acrn"
DISTRO = "zephyr"
TMPDIR="${TOPDIR}/master-zephyr-app"
```
############################################################################################

Note: Remember to keep TMPDIR in sync.


Build
-----


Execute below commands sequentially in order to build the sos image shipped with zephyr uos:


```
$ bitbake mc:zephyr:zephyr-helloworld
```
This should build you a `*.elf` in the master-zephyr-app image directory.
Now prepare zephyr image with grub-efi:


```
$ bitbake mc:uos:zephyr-image
```
This should build you a `zephyr.img` in the uosp image directory. Time to build your acrn image:


```
$ bitbake acrn-image-base
```

Building `acrn-image-base` will build a `wic.acrn` image that on first boot will be normal Linux
but will setup EFI entries so that subsequent boots are inside ACRN. Alternatively use the EFI
shell, assuming you've got the image on a USB stick something like this works:

```
> fs1:
> \EFI\BOOT\acrn.efi
```

Run zephyr uos
--------------
```
$/var/lib/machines/launch_zephyr.sh
```
18 changes: 18 additions & 0 deletions recipes-bsp/grub/zephyr-grub-efi_2.04.bb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require recipes-bsp/grub/grub-efi_2.04.bb

FILESEXTRAPATHS_append = ":${COREBASE}/meta/recipes-bsp/grub/files"

do_mkimage() {
cd ${B}
# Search for the grub.cfg on the local boot media by using the
# built in cfg file provided via this recipe
grub-mkimage -p ${EFIDIR} -d ./grub-core/ \
-O ${GRUB_TARGET}-efi -o ./${GRUB_IMAGE_PREFIX}${GRUB_IMAGE} \
boot efifwsetup efi_gop efinet efi_uga lsefimmap lsefi lsefisystab \
exfat fat multiboot2 multiboot terminal part_msdos part_gpt normal \
all_video aout configfile echo file fixvideo fshelp gfxterm gfxmenu \
gfxterm_background gfxterm_menu legacycfg video_bochs video_cirrus \
video_colors video_fb videoinfo video net tftp

}
SECURITY_CFLAGS = ""
44 changes: 44 additions & 0 deletions recipes-bsp/zephyr-image/zephyr-image.bb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
SUMMARY = "Create zephyr.img having grub, application image and grub config"
LICENSE = "CLOSED"
inherit deploy
do_deploy[depends] += "dosfstools-native:do_populate_sysroot \
mtools-native:do_populate_sysroot \
"

SRC_URI = "file://grub.cfg"
DEPENDS += " zephyr-grub-efi"

#Below variables must be set in local.conf
CONTAINER_PACKAGE_DEPLOY_DIR ??=""
CONTAINER_PACKAGE_ZEPHYR_DEPLOY_DIR ??=""
CONTAINER_PACKAGE_MC ?= ""
ZEPHYR_APP ??=""

do_deploy[mcdepends] += "multiconfig::${CONTAINER_PACKAGE_MC}:zephyr-grub-efi:do_deploy"

do_deploy () {
if [ -d ${DEPLOYDIR}/efi ]; then
rm -r ${DEPLOYDIR}/efi
fi

if [ -d ${DEPLOYDIR}/kernel ]; then
rm -r ${DEPLOYDIR}/kernel
fi
if [ -e ${DEPLOYDIR}/zephyr.img ]; then
rm ${DEPLOYDIR}/zephyr.img
fi

mkdir ${DEPLOYDIR}/efi
mkdir ${DEPLOYDIR}/kernel
mkdir ${DEPLOYDIR}/efi/boot
cp ${CONTAINER_PACKAGE_DEPLOY_DIR}/grub-efi-bootx64.efi ${DEPLOYDIR}/efi/boot/bootx64.efi
cp ${CONTAINER_PACKAGE_ZEPHYR_DEPLOY_DIR}/${ZEPHYR_APP}.elf ${DEPLOYDIR}/kernel/zephyr.elf
cp ${WORKDIR}/grub.cfg ${DEPLOYDIR}/efi/boot/
mkdosfs -F 32 -C ${DEPLOYDIR}/zephyr.img 35840
mcopy -i ${DEPLOYDIR}/zephyr.img -s ${DEPLOYDIR}/efi ${DEPLOYDIR}/kernel ::/
chmod 644 ${DEPLOYDIR}/zephyr.img
rm -rf ${DEPLOYDIR}/kernel ${DEPLOYDIR}/efi
}

addtask deploy after do_compile
do_install[noexec] = "1"
6 changes: 6 additions & 0 deletions recipes-bsp/zephyr-image/zephyr-image/grub.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
set default=0
set timeout=10

menuentry "Zephyr Kernel" {
multiboot /kernel/zephyr.elf
}
24 changes: 24 additions & 0 deletions recipes-guests/yocto/zephyr-image-package.bb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
SUMMARY = "Package for ${IMAGE_NAME}"
# This license statement is a lie. Ideally set it to something more appropriate.
LICENSE = "CLOSED"

PACKAGE_ARCH = "${MACHINE_ARCH}"
PACKAGES = "${PN}"

INHIBIT_DEFAULT_DEPS = "1"

# Variables to control where images are found: the multiconfig name, and the deploy dir.
CONTAINER_PACKAGE_DEPLOY_DIR ?= "${DEPLOY_DIR_IMAGE}"

# Where to install the image
containerdir ?= "${localstatedir}/lib/machines"

SRC_URI = "file://launch_zephyr.sh"

do_install() {
install -d ${D}${containerdir}
install ${CONTAINER_PACKAGE_DEPLOY_DIR}/zephyr.img ${D}${containerdir}/
install -m 755 ${WORKDIR}/launch_zephyr.sh ${D}/var/lib/machines/
}

RDEPENDS_${PN} += "bash procps"
44 changes: 44 additions & 0 deletions recipes-guests/yocto/zephyr-image-package/launch_zephyr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash
# Copyright (C) 2019 Intel Corporation.
# SPDX-License-Identifier: BSD-3-Clause

function launch_zephyr()
{
vm_name=zephyr_vm$1

#check if the vm is running or not
vm_ps=$(pgrep -a -f acrn-dm)
result=$(echo $vm_ps | grep -w "${vm_name}")
if [[ "$result" != "" ]]; then
echo "$vm_name is running, can't create twice!"
exit
fi

#for memsize setting
mem_size=128M

acrn-dm -A -m $mem_size -s 0:0,hostbridge -s 1:0,lpc -l com1,stdio \
-s 5,virtio-console,@pty:pty_port \
-s 3,virtio-blk,/var/lib/machines/zephyr.img \
--ovmf /usr/share/acrn/bios/OVMF.fd \
$vm_name
}

# offline SOS CPUs except BSP before launch UOS
for i in `ls -d /sys/devices/system/cpu/cpu[1-99]`; do
online=`cat $i/online`
idx=`echo $i | tr -cd "[1-99]"`
echo cpu$idx online=$online
if [ "$online" = "1" ]; then
echo 0 > $i/online
# during boot time, cpu hotplug may be disabled by pci_device_probe during a pci module insmod
while [ "$online" = "1" ]; do
sleep 1
echo 0 > $i/online
online=`cat $i/online`
done
echo $idx > /sys/class/vhm/acrn_vhm/offline_cpu
fi
done

launch_zephyr 1