Jan 30, 2023

Booting QEMU Cubieboard from Yocto SD card

This is part 6 of the QEMU Board Emulation post series.

Posts in this post series so far have been focused on the Versatile Express board, since it has wide range of supported peripherals and is easy to start with.

I have recently worked on contributing to Allwinner A10 and Cubieboard support in QEMU. I have added several components (clock controller module and DRAM controller) as well as I2C controller in order to be able to execute U-Boot and SPL code from SD card. By reusing the bootrom approach from Allwinner H3, the Cubieboard can now be started just by supplying the SD card image, and it will perform boot similar to the one executed on a real board.

In this blog post I will focus on Yocto support for Cubieboard and how to use new QEMU support. I will also extend Cubieboard with the previously developed I2C sensor peripheral, to test that application can be shared between Vexpress and Cubieboard.


Items that will be covered in this post are

Sources for the Yocto build environment for Cubieboard can be found in following repositories:

Note: The organization has been updated for Vexpress as well in kirkstone brances, so the only difference are the manifest repositories (qemu-vexpress-yocto vs qemu-sunxi-yocto) and platform support layers (meta-vexpress vs meta-sunxi).

Yocto for Cubieboard

The official meta-sunxi layer (available at https://github.com/linux-sunxi/meta-sunxi) supports Cubieboard out-of-the-box, so the machine part is already prepared (unlike the Versatile Express board, where we had to create our meta-vexpress to contain the machine information).

Organizing layers

We can reuse the meta-mistra-base and meta-mistra-apps layers that were used for Versatile Express board demonstration (in part 4 and part 5 of post series).

Note: the layer organization in parts 4 and 5 was a bit different - meta-vexpress had both the machine and distro specification, while meta-vexpress-apps had applications; the design in kirkstone branch for Versatile Express has been updated to use the meta-mistra-base and meta-mistra-apps layers.

The meta-mistra-base layer contains the distribution definition (same distributions, mistra-framebuffer and mistra-x11), while the meta-mistra-apps contains i2c-sens application and mistra-image definition.

Building

Building is similar to the way it was done for Versatile Express board.

After initializing the qemu-sunxi-yocto repo

$ repo init -u https://github.com/straxy/qemu-sunxi-yocto -m default.xml
$ repo sync

the environment is initialized using

$ source setup-environment build_fb

The build for framebuffer distro is done using

DISTRO=mistra-framebuffer MACHINE=cubieboard bitbake mistra-image

The final result is in ./tmp/deploy/images/cubieboard, the file with extension *.sunxi-sdimage. This is the SD card image which can be either copied (dd) to an SD card image created with qemu-img, or can be just resized using qemu-img to a power of 2 size. For instance

$ qemu-img resize ./tmp/deploy/images/cubieboard/mistra-image.sunxi-sdimage 1G

Testing SD card boot

The patches that allow Cubieboard SD card boot are in latest QEMU (patch series and specific code change).

In order to do the boot, the QEMU should be called without the -kernel parameter, and only with -sd parameter.

$ qemu-system-arm -M cubieboard -nographic -sd mistra-image.sunxi-sdimage

After this, the emulated board will go through the regular boot process: SPL -> U-Boot -> Linux, and we will be presented with the prompt to login to the image.

Testing I2C sensor

In order to attach the I2C sensor to Cubieboard, few lines (similar to ones used for Vexpress) have to be added to cubieboard.c.

  i2c = I2C_BUS(qdev_get_child_bus(DEVICE(&a10->i2c0), "i2c"));
  i2c_slave_create_simple(i2c, "mistra.i2csens", 0x36);

After this, when QEMU is started, we can test if I2C sensor is working using i2c-tools

# read ID register
$ i2cget -y 0 0x36 0x0
0x5a
# enable I2C component
$ i2cset -y 0 0x36 0x1 0x1
$ i2cget -y 0 0x36 0x1
0x01
# read data register
$ i2cget -y 0 0x36 0x2
0x2c

We can also use the old i2csens-app application from meta-mistra-apps to obtain similar results.

$ i2csens-app /dev/i2c-0
Measured 18
Measured 22.5

Summary

In this post instructions for using Yocto with Cubieboard were shown. Since QEMU Cubieboard supports SD card boot, that has been used for testing. This can be very useful for initial testing, without available hardware.

No comments:

Post a Comment