Using Zephyr to Build Smaller Driver Domains for Virtualized Vehicle Systems
TOKITA Hiroshi
Zephyr Maintainer
Who am I?
I’m TOKITA Hiroshi.
I contribute to Zephyr since 2018.
I taken on maintainer of the Raspberry Pi Pico and Renesas RA.
Today I speak as an individual.
License: CC-BY-4.0
Agenda
What is Zephyr and SDV?
Zephyr in SDV
What’s need to run Zephyr on Xen as VirtIO backend?
Running Zephyr based VirtIO Backend
Real World/Hardware Problem
License: CC-BY-4.0
Before beginning session…
License: CC-BY-4.0
What is Zephyr and SDV?
What is Zephyr?
But In this session, I will talk about usage that is not on the MCUs.
License: CC-BY-4.0
What is SDV?
License: CC-BY-4.0
Automotive Grade Linux
Automotive Grade Linux(AGL) is Open Source Project for building Linux systems for Automotive.
Project is since 2012, Many car OEM companies joined.
Last year, we launched a platform named “SoDeV” for realize SDV concept.
License: CC-BY-4.0
SoDeV platform by Automotive Grade Linux
License: CC-BY-4.0
Our booth: SoDeV Runs AGL and AAOS on Xen
Today, we are demonstrating the SoDeV system in our booth.
License: CC-BY-4.0
Zephyr in SoDeV
Virtualization
License: CC-BY-4.0
Xen and VirtIO
License: CC-BY-4.0
Zephyr in SoDeV platform
Zephyr appears in SDV system with following contexts …
License: CC-BY-4.0
Xen Domain concept
Xen
Hardware
Dom0
DomD
VirtIO Backend
Driver
DomU
VM Management & Monitoring
VirtIO Frontend
Application
Xen and Dom0, and DomU should not have any device depend implementation.
DomU uses only VirtIO devices.
DomD handles VirtIO requests with delegating to real devices.
Passthrough
License: CC-BY-4.0
Linux DomD is huge.
Can we split and reduce it?
Xen
Hardware
DomD
Linux
VirtIO BE
Driver
DomU
App
Driver
Driver
VirtIO BE
VirtIO BE
VirtIO FE
DomU
App
VirtIO FE
DomU
App
VirtIO FE
License: CC-BY-4.0
SoDeV Platform Architecture (My proposal)
Type 1 Hypervisor (e.g. Xen)
Automotive SoC or Virtual Environment
Dom 0
Linux/Zephyr
Control Domain�(Optional)
Dom D #0
Zephyr
VirtIO Backend
Zephyr Driver�(CAN, Sound, SPI,...)
VM Management & Monitoring
Dom0 Kernel
Guest & Function Domains
Dom U
Cluster
Dom U
ADAS/AD
VirtIO Frontend
VirtIO Frontend
AGL
Zephyr
Dom U
IVM
VirtIO Frontend
Android
Unified HMI
Dom D #1
Zephyr
VirtIO Backend
Zephyr Driver�(Ether, GPU,
block, ...)
Adding Zephyr's VirtIO BE Framework.�(My patch)
DomD
Linux
Driver Domain �(HW Access)
VM Management & Monitoring
Dom0 Kernel
Replacing Linux Dom-D with multiple Zephyr Dom-D.
This helps target function safety authorization for the driver domain
License: CC-BY-4.0
What’s need to run Zephyr on Xen
as VirtIO backend?
Process outline
Setup virtual MMIO register
Setup event
Query configuration
License: CC-BY-4.0
XenStore
XenStore is a mechanism for sharing information with the hypervisor.�It stores virtio configuration information.
/local/domain/1/backend/virtio/2/0 = ""
/local/domain/1/backend/virtio/2/0/frontend = "/local/domain/2/device/virtio/0"
/local/domain/1/backend/virtio/2/0/frontend-id = "2"
/local/domain/1/backend/virtio/2/0/online = "1"
/local/domain/1/backend/virtio/2/0/state = "1"
/local/domain/1/backend/virtio/2/0/irq = "33"
/local/domain/1/backend/virtio/2/0/base = "0x2000000"
/local/domain/1/backend/virtio/2/0/type = "virtio,device2"
/local/domain/1/backend/virtio/2/0/transport = "mmio"
/local/domain/1/backend/virtio/2/0/grant_usage = "1"
License: CC-BY-4.0
(Virtual) MMIO Register / Interrupt
DomD
VirtIO Backend
DomU
VirtIO Frontend
(Virtual)
MMIO Register
When read/write accesses to (virtual) mmio register are occurred, �call internal callbacks.
Configure (Virtual) interrupt to FE refer the Xen configuration.
License: CC-BY-4.0
Query Virtqueue Address
The (virtual) MMIO register configuration is defined in VirtIO spec.
We can found Virtqueue Address from register layout.
License: CC-BY-4.0
Access Virtqueue
DomD
VirtIO BE
DomU
VirtIO FE
(Virtual)
MMIO Register
BE read and write virtqueue with given pointer.
Response QueueDesc request with �Virtqueue Address.
Virtqueue
FE allocate virtqueue and tell to BE via MMIO.
Virtqueue Ref
License: CC-BY-4.0
Two rings: arteries and veins
Descriptor
Descriptor
Descriptor
Data
Data
Data
Frontend (Guest)
Backend (Host)
Used
Avail
Ring entity points to a descriptor by index
Descriptor points to a memory region (address, length)
Frontend picks free descriptor and writes a request, and post to the avail ring.
Backend reads�from the avail ring, processes, then returns it to used ring.
License: CC-BY-4.0
Running Zephyr based VirtIO Backend
Configure VM to enable VirtIO
virtio = [ "type=virtio,device2,transport=mmio,backend=domd,grant_usage=1" ]
This is DomU/FE side configuration.
DomD/BE should behave according to FE configurations.
License: CC-BY-4.0
Launch VMs in Pause state
Launch DomD/BE in pause state.�(FE configuration declare as depends to BE, need to be launched preceding to FE.)
Launch DomU/FE in pause state.
(BE is not ready because that is in pause state.)
Unpause DomD/BE.
(XenStore configuration is ready.)
Unpause DomU/FE.
(All Green.)
License: CC-BY-4.0
Demo: virtio-blk on QEMU
Ubuntu on WSL2
QEMU
Xen
Zephyr (DomD)
Linux (Dom0)
Linux (DomU)
Virtual
Disk (mem)
R/W
Launch
/dev/pts/X
/dev/vport0p1
socat
License: CC-BY-4.0
How much reduced?
Compare the image size.
While the comparison conditions aren't strictly aligned, it's clear that a large infrastructure is necessary for Linux.
License: CC-BY-4.0
Current Status
Progress in underwater
And last week, many new VirtIO frontend drivers PRs are published.
License: CC-BY-4.0
Real World/Hardware Problem
Retronix SparrowHawk R-Car V4H SBC
Renesas RCar V4H SoC
License: CC-BY-4.0
Peripheral address and pages
Xen can assign memory to a VM by page (4KB aligned).�The same applies to registers; if plural peripheral registers are in same page, it raises complexity in design.��Solution Ideas:
E6050000: gpio0�(PinFuncCtrl part)
E6050180: gpio0�(GPIO part)
E6050800: gpio1�(PinFuncCtrl part)
E6050980: gpio1�(GPIO part)
1page�(4KB)
This case, we need to delegate gpio0 and 1 for single DomD
License: CC-BY-4.0
PinControl and ClockControl drivers
Typically, Zephyr driver set pinctrl and clock control at initializing.
I couldn't find a simple solution.�This is obstacle.
Timer0-2
DMA0,1
SD
Serial0,1,3,4
static int pwm_rcar_init(const struct device *dev)
{
/* Configure dt provided device signals when available */
ret = pinctrl_apply_state(config->pcfg, PINCTRL_STATE_DEFAULT);
…
ret = clock_control_on(config->clock_dev, (clock_control_subsys_t)&config->mod_clk);
…
For example, the clock register has bits set for each function.
License: CC-BY-4.0
Hardware Security Module
The parts related to ARM TrustZone etc. are SoC-specific.
Likely to be related to proprietary specifications.
Sometimes a random number generator
It is tied to Hardware Security Module(HSM), so it may not be possible to use it simply.
SoC
OS
ROM IPL
OS verification
Complex interactions to use SoC-specific security features
RNG, SHA256�Accelerator driver, etc
License: CC-BY-4.0
Configuring Virtio for Zephyr Virtio FE
DeviceTree fragment injection is not work with Zephyr because Zephyr not handle DTB.
Solution idea:�Most of the information can also be obtained from XenStore. But not all.
�
💻
Linux Kernel
DTB
Launch
Xen HV
virtio@2000000 {
compatible = "virtio,mmio";
reg = <...>;
dma-coherent;
xen,dev-domid = <1>;
};
Xen inject devicetree fragment to existing DTB for configuring VirtIO component.
License: CC-BY-4.0
Next: Supporting virtio-blk on SD-Card
License: CC-BY-4.0
Conclusion
Conclusion
License: CC-BY-4.0
Thank you for your attention.
Anyone have questions?