Hi all,
I’d like to add I2C support for aarch64 virt board. So I modified hw/arm/virt.c
as follows.
1. Add [VIRT_I2C] = { 0x09100000, 0x00001000 } entry in base_memmap to
define a memory region
2. Use the following to emulate a I2C device
dev = sysbus_create_simple(TYPE_VERSATILE_I2C, vms->memmap[VIRT_I2C].base,
NULL);
i2c = (I2CBus *)qdev_get_child_bus(dev, "i2c");
i2c_slave_create_simple(i2c, "sii9022", 0x39);
1. Use the following to add device tree file entry
nodename = g_strdup_printf("/i2c@%" PRIx64, base);
qemu_fdt_add_subnode(vms->fdt, nodename);
qemu_fdt_setprop_string(vms->fdt, nodename, "compatible", "arm,versatile-i2c");
qemu_fdt_setprop_sized_cells(vms->fdt, nodename, "reg", 1, base, 1, size);
After modification, QEMU can compile successfully. However, when I run it
(qemu-system-aarch64 -M virt -m 2048 -cpu cortex-a53 -kernel ./Image -nographic
-hda rootfs.ext2 --append "root=/dev/vda"), I got the following error:
* qemu-system-aarch64: qemu-5.1.0/softmmu/memory.c:2388:
memory_region_add_subregion_common: Assertion `!subregion->container' failed
The assertion exists in qemu-5.1.0\softmmu\memory.c:
memory_region_add_subregion_common() and is triggered by dev =
sysbus_create_simple(TYPE_VERSATILE_I2C, vms->memmap[VIRT_I2C].base, NULL);. I
think it means I’m using a memory region that has been used. But I think the
memory region in base_memap I’ve chosen is available. Besides, the assertion
“subregion->container” is derived from dev = qdev_new(name) (located in
hw/core/sysbus.c), which I have no control over when calling
sysbus_create_simple(). Could someone tell me which part is wrong?
Any help is appreciated. Thanks in advance.
Regards,
Weiqi