hw/arm: Add Allwinner H618 SoC and Orange Pi Zero 2W machine
Subsystems (2)
v2 cover hw/arm: Add Allwinner H618 SoC and Orange Pi Zero 2W machine
This patch series adds emulation support for the Allwinner H618 SoC and the Xunlong Orange Pi Zero 2W single-board computer (SBC).
The Allwinner H618 is a quad-core 64-bit ARM Cortex-A53 SoC. This series follows the incremental skeleton design established for Allwinner SoCs:
- Patch 1: Introduces the basic H618 SoC model with 4x Cortex-A53 cores, GICv2, ARM Generic Timer PPIs, UART0/1, SRAM A1/A2, and stubbed unimp MMIO.
- Patch 2: Adds the Orange Pi Zero 2W machine with 1 GiB SDRAM and kernel loader.
- Patch 3: Separates the ALLWINNER_SID Kconfig symbol so other SoCs can reuse it.
- Patch 4: Extends the Allwinner SID eFuse controller to support configurable capacity up to 512 bytes (AW_SID_SIZE_MAX), preserving backward compatibility.
- Patch 5: Connects the SID controller into the H618 SoC (256 bytes capacity) and sets the default UID.
- Patch 6: Separates the ALLWINNER_SDHOST Kconfig symbol for independent reuse.
- Patch 7: Connects Allwinner SD/MMC host controller 0 (sun50i-a64 compatible) at 0x04020000 into the H618 SoC.
- Patch 8: Wires up the SD card bus to Orange Pi Zero 2W machine and supports loading bootloader firmware via -bios.
Changes since v1:
- hw/misc/allwinner-sid: Use extract32(s->control, 16, 9) to extract the 9-bit PRCTL offset and return 0 on out-of-bounds eFuse reads.
- hw/arm/allwinner-h618: Set SID size property to 256 bytes (0x100) to match physical H618 eFuse capacity, consistent with Linux and Zephyr DTS.
- hw/sd/allwinner-sdhost: Separate CONFIG_ALLWINNER_SDHOST symbol from H3.
- hw/arm/allwinner-h618: Connect SD/MMC host controller 0.
- hw/arm/orangepi-zero2w: Wire up SD bus and support raw firmware loading via -bios (e.g. for U-Boot SPL).
Verification:
- The series has been tested using Zephyr RTOS (v4.5) running on the orangepi-zero2w target:
* UART0 console & kernel boot: PASS
* Multi-threading with ARM Generic Timer PPIs (k_msleep): PASS
* HWINFO UID reading from SID eFuse: PASS (16 bytes UID)
* SID OTP driver: PASS (Offset 0..15, Offset 240..255, and Offset 256 returning -EINVAL out-of-bounds error)
- Tested raw firmware loading (-bios) with U-Boot SPL.
- All patches pass ./scripts/checkpatch.pl with 0 errors and 0 warnings.
Khai Do (8):
hw/arm/allwinner-h618: Add Allwinner H618 SoC emulation hw/arm/orangepi-zero2w: Add Orange Pi Zero 2W machine hw/misc/allwinner-sid: Separate ALLWINNER_SID config symbol hw/misc/allwinner-sid: Support configurable eFuse capacity up to 512
bytes
hw/arm/allwinner-h618: Connect Allwinner SID controller hw/sd/allwinner-sdhost: Separate ALLWINNER_SDHOST config symbol hw/arm/allwinner-h618: Connect Allwinner SD/MMC host controller 0 hw/arm/orangepi-zero2w: Wire up SD card and support firmware loading
MAINTAINERS | 8 ++ hw/arm/Kconfig | 11 ++ hw/arm/allwinner-h618.c | 247 ++++++++++++++++++++++++++++++++ hw/arm/meson.build | 1 + hw/arm/orangepi-zero2w.c | 114 +++++++++++++++ hw/misc/Kconfig | 3 + hw/misc/allwinner-sid.c | 12 +- hw/misc/meson.build | 2 +- hw/sd/Kconfig | 4 + hw/sd/meson.build | 2 +- include/hw/arm/allwinner-h618.h | 63 ++++++++ include/hw/misc/allwinner-sid.h | 8 ++ 12 files changed, 471 insertions(+), 4 deletions(-) create mode 100644 hw/arm/allwinner-h618.c create mode 100644 hw/arm/orangepi-zero2w.c create mode 100644 include/hw/arm/allwinner-h618.h
Signature · 1 line
2.43.0
PATCH v2 1/8 hw/arm/allwinner-h618: Add Allwinner H618 SoC emulation
The Allwinner H618 is a 64-bit quad-core Cortex-A53 SoC. This commit adds baseline SoC emulation including:
- 4x Cortex-A53 cores with PSCI conduit for SMP
- ARM GICv2 interrupt controller and generic timer PPI connections
- SRAM A1, SRAM A2, and 16550 UART0/1 controllers
- Unimplemented memory regions for non-critical peripherals
--- MAINTAINERS | 7 + hw/arm/Kconfig | 7 + hw/arm/allwinner-h618.c | 224 ++++++++++++++++++++++++++++++++ hw/arm/meson.build | 1 + include/hw/arm/allwinner-h618.h | 57 ++++++++ 5 files changed, 296 insertions(+) create mode 100644 hw/arm/allwinner-h618.c create mode 100644 include/hw/arm/allwinner-h618.h
MAINTAINERS +7 -0
@@ -779,6 +779,13 @@ F: hw/arm/orangepi.c F: docs/system/arm/orangepi.rst F: tests/functional/arm/test_orangepi.py +Allwinner-h618 +M: Khai Do <[email protected]> +L: [email protected] +S: Maintained +F: hw/*/allwinner-h618* +F: include/hw/*/allwinner-h618* + ARM PrimeCell and CMSDK devices M: Peter Maydell <[email protected]> L: [email protected]
hw/arm/Kconfig +7 -0
@@ -333,6 +333,13 @@ config ALLWINNER_R40 select USB_EHCI_SYSBUS select SD +config ALLWINNER_H618 + bool + default y if TCG && AARCH64 + select SERIAL_MM + select ARM_GIC + select UNIMP + config MAX78000_SOC bool select ARM_V7M
hw/arm/allwinner-h618.c new file +224 -0
224 lines not on this page · raw message
hw/arm/meson.build +1 -0
@@ -24,6 +24,7 @@ arm_common_ss.add(when: 'CONFIG_OMAP', if_true: files('omap1.c')) arm_common_ss.add(when: 'CONFIG_ALLWINNER_A10', if_true: files('allwinner-a10.c', 'cubieboard.c')) arm_common_ss.add(when: 'CONFIG_ALLWINNER_H3', if_true: files('allwinner-h3.c', 'orangepi.c')) arm_common_ss.add(when: 'CONFIG_ALLWINNER_R40', if_true: files('allwinner-r40.c', 'bananapi_m2u.c')) +arm_common_ss.add(when: 'CONFIG_ALLWINNER_H618', if_true: files('allwinner-h618.c')) arm_common_ss.add(when: 'CONFIG_MAX78000_SOC', if_true: files('max78000_soc.c')) arm_common_ss.add(when: 'CONFIG_RASPI', if_true: files( 'bcm2836.c',
include/hw/arm/allwinner-h618.h new file +57 -0
57 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v2 2/8 hw/arm/orangepi-zero2w: Add Orange Pi Zero 2W machine
In reply to Khai DoThe Orange Pi Zero 2W is a single-board computer powered by the Allwinner H618 SoC. This commit adds machine emulation with:
- Allwinner H618 SoC instance
- 1 GiB default system SDRAM at 0x40000000
- Kernel and firmware loading via arm_load_kernel
--- MAINTAINERS | 1 + hw/arm/meson.build | 2 +- hw/arm/orangepi-zero2w.c | 77 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 hw/arm/orangepi-zero2w.c
MAINTAINERS +1 -0
@@ -785,6 +785,7 @@ L: [email protected] S: Maintained F: hw/*/allwinner-h618* F: include/hw/*/allwinner-h618* +F: hw/arm/orangepi-zero2w.c ARM PrimeCell and CMSDK devices M: Peter Maydell <[email protected]>
hw/arm/meson.build +1 -1
@@ -24,7 +24,7 @@ arm_common_ss.add(when: 'CONFIG_OMAP', if_true: files('omap1.c')) arm_common_ss.add(when: 'CONFIG_ALLWINNER_A10', if_true: files('allwinner-a10.c', 'cubieboard.c')) arm_common_ss.add(when: 'CONFIG_ALLWINNER_H3', if_true: files('allwinner-h3.c', 'orangepi.c')) arm_common_ss.add(when: 'CONFIG_ALLWINNER_R40', if_true: files('allwinner-r40.c', 'bananapi_m2u.c')) -arm_common_ss.add(when: 'CONFIG_ALLWINNER_H618', if_true: files('allwinner-h618.c')) +arm_common_ss.add(when: 'CONFIG_ALLWINNER_H618', if_true: files('allwinner-h618.c', 'orangepi-zero2w.c')) arm_common_ss.add(when: 'CONFIG_MAX78000_SOC', if_true: files('max78000_soc.c')) arm_common_ss.add(when: 'CONFIG_RASPI', if_true: files( 'bcm2836.c',
hw/arm/orangepi-zero2w.c new file +77 -0
77 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v2 3/8 hw/misc/allwinner-sid: Separate ALLWINNER_SID config symbol
In reply to Khai DoIntroduce a dedicated CONFIG_ALLWINNER_SID Kconfig symbol and select it from CONFIG_ALLWINNER_H3 so the SID controller can be reused by other Allwinner SoCs.
--- hw/arm/Kconfig | 1 + hw/misc/Kconfig | 3 +++ hw/misc/meson.build | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-)
hw/arm/Kconfig +1 -0
@@ -309,6 +309,7 @@ config ALLWINNER_H3 select ALLWINNER_SUN8I_EMAC select ALLWINNER_I2C select ALLWINNER_WDT + select ALLWINNER_SID select SERIAL_MM select ARM_TIMER select ARM_GIC
hw/misc/Kconfig +3 -0
@@ -268,6 +268,9 @@ config LASI config ALLWINNER_SRAMC bool +config ALLWINNER_SID + bool + config ALLWINNER_A10_CCM bool
hw/misc/meson.build +1 -1
@@ -55,7 +55,7 @@ system_ss.add(when: 'CONFIG_ALLWINNER_H3', if_true: files('allwinner-h3-ccu.c')) system_ss.add(when: 'CONFIG_ALLWINNER_H3', if_true: files('allwinner-cpucfg.c')) system_ss.add(when: 'CONFIG_ALLWINNER_H3', if_true: files('allwinner-h3-dramc.c')) system_ss.add(when: 'CONFIG_ALLWINNER_H3', if_true: files('allwinner-h3-sysctrl.c')) -system_ss.add(when: 'CONFIG_ALLWINNER_H3', if_true: files('allwinner-sid.c')) +system_ss.add(when: 'CONFIG_ALLWINNER_SID', if_true: files('allwinner-sid.c')) system_ss.add(when: 'CONFIG_ALLWINNER_R40', if_true: files('allwinner-r40-ccu.c')) system_ss.add(when: 'CONFIG_ALLWINNER_R40', if_true: files('allwinner-r40-dramc.c')) system_ss.add(when: 'CONFIG_AXP2XX_PMU', if_true: files('axp2xx.c'))
Signature · 1 line
2.43.0
PATCH v2 4/8 hw/misc/allwinner-sid: Support configurable eFuse capacity up to 512 bytes
In reply to Khai DoAllwinner SoCs provide different eFuse capacities: older SoCs have 16 to 256 bytes, while newer 64-bit SoCs (e.g. H618) provide up to 512 bytes of eFuse storage.
Add a "size" property (defaulting to 16 bytes for backward compatibility) and an internal storage buffer up to 512 bytes (AW_SID_SIZE_MAX).
--- hw/misc/allwinner-sid.c | 12 ++++++++++-- include/hw/misc/allwinner-sid.h | 8 ++++++++ 2 files changed, 18 insertions(+), 2 deletions(-)
hw/misc/allwinner-sid.c +10 -2
@@ -79,10 +79,15 @@ static void allwinner_sid_write(void *opaque, hwaddr offset,if ((s->control ®_PRCTL_OP_LOCK ) && (s->control ®_PRCTL_WRITE )) { -uint32_t id = s->control >>16 ; +uint32_t id =extract32 (s->control,16 ,9 );if (id <=sizeof (QemuUUID) -sizeof (s->rdkey)) { s->rdkey =ldl_be_p (&s->identifier.data[id]); + }else if (s->size >=sizeof (s->rdkey) && + id <= s->size -sizeof (s->rdkey)) { + s->rdkey =ldl_be_p (&s->storage[id]); + }else { + s->rdkey =0 ; } } s->control &= ~REG_PRCTL_WRITE ;
@@ -129,16 +134,19 @@ static void allwinner_sid_init(Object *obj)static const Property allwinner_sid_properties[] = {DEFINE_PROP_UUID_NODEFAULT ("identifier" , AwSidState, identifier), +DEFINE_PROP_UINT32 ("size" , AwSidState, size,sizeof (QemuUUID)), };static const VMStateDescription allwinner_sid_vmstate = { .name ="allwinner-sid" , - .version_id =1 , + .version_id =2 , .minimum_version_id =1 , .fields = (const VMStateField []) {VMSTATE_UINT32 (control, AwSidState),VMSTATE_UINT32 (rdkey, AwSidState),VMSTATE_UINT8_ARRAY_V (identifier.data, AwSidState,sizeof (QemuUUID),1 ), +VMSTATE_UINT32_V (size, AwSidState,2 ), +VMSTATE_UINT8_ARRAY_V (storage, AwSidState,AW_SID_SIZE_MAX ,2 ),VMSTATE_END_OF_LIST () } };
include/hw/misc/allwinner-sid.h +8 -0
@@ -24,6 +24,9 @@#include "hw/core/sysbus.h" #include "qemu/uuid.h" +/** Maximum eFuse storage size supported */ +#define AW_SID_SIZE_MAX (512) +/** * Object model * @{
@@ -54,6 +57,11 @@ struct AwSidState {/** Stores the emulated device identifier */ QemuUUID identifier; +/** Size of eFuse storage */ +uint32_t size; + +/** eFuse storage buffer */ + uint8_t storage[AW_SID_SIZE_MAX]; };#endif /* HW_MISC_ALLWINNER_SID_H */
Signature · 1 line
2.43.0
PATCH v2 5/8 hw/arm/allwinner-h618: Connect Allwinner SID controller
In reply to Khai DoWire up the Allwinner Security ID (SID) eFuse controller into the H618 SoC model:
- Map SID MMIO registers at 0x03006000 with 256 bytes capacity
- Remove sid from unimplemented peripheral list
- Configure default fixed SID identifier in Orange Pi Zero 2W machine
- Select ALLWINNER_SID in Kconfig
--- hw/arm/Kconfig | 1 + hw/arm/allwinner-h618.c | 11 ++++++++++- hw/arm/orangepi-zero2w.c | 8 ++++++++ include/hw/arm/allwinner-h618.h | 3 +++ 4 files changed, 22 insertions(+), 1 deletion(-)
hw/arm/Kconfig +1 -0
@@ -339,6 +339,7 @@ config ALLWINNER_H618 default y if TCG && AARCH64 select SERIAL_MM select ARM_GIC + select ALLWINNER_SID select UNIMP config MAX78000_SOC
hw/arm/allwinner-h618.c +10 -1
@@ -29,6 +29,7 @@ const hwaddr allwinner_h618_memmap[] = { [AW_H618_DEV_GIC_CPU] = 0x03022000, [AW_H618_DEV_GIC_HYP] = 0x03024000, [AW_H618_DEV_GIC_VCPU] = 0x03026000, + [AW_H618_DEV_SID] = 0x03006000, [AW_H618_DEV_UART0] = 0x05000000, [AW_H618_DEV_UART1] = 0x05000400, [AW_H618_DEV_UART2] = 0x05000800,
@@ -44,7 +45,6 @@ static const struct AwH618Unimplemented { } unimplemented[] = { { "ccu", 0x03001000, 4 * KiB }, { "dma", 0x03002000, 4 * KiB }, - { "sid", 0x03006000, 4 * KiB }, { "smc", 0x03007000, 4 * KiB }, { "timer", 0x03009000, 4 * KiB }, { "pwm", 0x0300a000, 4 * KiB },
@@ -91,6 +91,10 @@ static void allwinner_h618_init(Object *obj) }object_initialize_child (obj,"gic" , &s->gic,TYPE_ARM_GIC ); + +object_initialize_child (obj,"sid" , &s->sid,TYPE_AW_SID ); +object_property_add_alias (obj,"identifier" ,OBJECT (&s->sid), +"identifier" ); }static void allwinner_h618_realize (DeviceState *dev,Error **errp)
@@ -172,6 +176,11 @@ static void allwinner_h618_realize(DeviceState *dev, Error **errp) ppibase + AW_H618_GIC_PPI_MAINT)); } +/* Security Identifier */ +qdev_prop_set_uint32 (DEVICE (&s->sid),"size" ,256 ); +sysbus_realize (SYS_BUS_DEVICE (&s->sid), &error_fatal); +sysbus_mmio_map (SYS_BUS_DEVICE (&s->sid),0 , s->memmap[AW_H618_DEV_SID ]); +/* SRAM */ memory_region_init_ram (&s->sram_a1,OBJECT (dev),"sram A1" ,64 * KiB, &error_abort);
hw/arm/orangepi-zero2w.c +8 -0
@@ -40,6 +40,14 @@ static void orangepi_zero2w_init(MachineState *machine)object_property_add_child (OBJECT (machine),"soc" ,OBJECT (h618));object_unref (OBJECT (h618)); +/* Setup SID properties. Currently using a default fixed SID identifier. */ +if (qemu_uuid_is_null (&h618->sid.identifier)) { +qdev_prop_set_string (DEVICE (h618),"identifier" , +"03006180-1111-2222-3333-000044556677" ); + }else if (ldl_be_p (&h618->sid.identifier.data[0 ]) !=0x03006180 ) { +warn_report ("Security Identifier value does not include H618 prefix" ); + } +/* Mark H618 object realized */ qdev_realize (DEVICE (h618),NULL , &error_abort);
include/hw/arm/allwinner-h618.h +3 -0
@@ -11,6 +11,7 @@#include "qom/object.h" #include "hw/intc/arm_gic.h" +#include "hw/misc/allwinner-sid.h" #include "target/arm/cpu.h" /**
@@ -23,6 +24,7 @@ enum {AW_H618_DEV_GIC_CPU ,AW_H618_DEV_GIC_HYP ,AW_H618_DEV_GIC_VCPU , +AW_H618_DEV_SID ,AW_H618_DEV_UART0 ,AW_H618_DEV_UART1 , AW_H618_DEV_UART2,
@@ -50,6 +52,7 @@ struct AwH618State {ARMCPU cpus[AW_H618_NUM_CPUS ];const hwaddr *memmap;GICState gic; +AwSidState sid;MemoryRegion sram_a1;MemoryRegion sram_a2; };
Signature · 1 line
2.43.0
PATCH v2 6/8 hw/sd/allwinner-sdhost: Separate ALLWINNER_SDHOST config symbol
In reply to Khai DoIntroduce a dedicated Kconfig symbol ALLWINNER_SDHOST for the Allwinner SD/MMC host controller. Previously it was conditionally built only when CONFIG_ALLWINNER_H3 was enabled.
Select ALLWINNER_SDHOST in ALLWINNER_H3.
--- hw/arm/Kconfig | 1 + hw/sd/Kconfig | 4 ++++ hw/sd/meson.build | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-)
hw/arm/Kconfig +1 -0
@@ -310,6 +310,7 @@ config ALLWINNER_H3 select ALLWINNER_I2C select ALLWINNER_WDT select ALLWINNER_SID + select ALLWINNER_SDHOST select SERIAL_MM select ARM_TIMER select ARM_GIC
hw/sd/Kconfig +4 -0
@@ -1,3 +1,7 @@ +config ALLWINNER_SDHOST + bool + select SD + config PL181 bool select SD
hw/sd/meson.build +1 -1
@@ -7,7 +7,7 @@ system_ss.add(when: 'CONFIG_SSI_SD', if_true: files('ssi-sd.c')) system_ss.add(when: 'CONFIG_OMAP', if_true: files('omap_mmc.c')) system_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2835_sdhost.c')) system_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_sdhci.c')) -system_ss.add(when: 'CONFIG_ALLWINNER_H3', if_true: files('allwinner-sdhost.c')) +system_ss.add(when: 'CONFIG_ALLWINNER_SDHOST', if_true: files('allwinner-sdhost.c')) system_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_sdhci.c')) system_ss.add(when: 'CONFIG_CADENCE_SDHCI', if_true: files('cadence_sdhci.c')) system_ss.add(when: 'CONFIG_AXIADO_SDHCI', if_true: files('axiado_sdhci.c'))
Signature · 1 line
2.43.0
PATCH v2 7/8 hw/arm/allwinner-h618: Connect Allwinner SD/MMC host controller 0
In reply to Khai DoWire up the Allwinner SD/MMC host controller 0 (SMHC0) into the Allwinner H618 SoC model:
- Map MMC0 MMIO registers at 0x04020000
- Connect GIC interrupt SPI 35 (AW_H618_GIC_SPI_MMC0)
- Remove mmc0 from unimplemented peripheral list
- Alias "sd-bus" property from mmc0
- Select ALLWINNER_SDHOST in ALLWINNER_H618 Kconfig
--- hw/arm/Kconfig | 1 + hw/arm/allwinner-h618.c | 16 +++++++++++++++- include/hw/arm/allwinner-h618.h | 3 +++ 3 files changed, 19 insertions(+), 1 deletion(-)
hw/arm/Kconfig +1 -0
@@ -341,6 +341,7 @@ config ALLWINNER_H618 select SERIAL_MM select ARM_GIC select ALLWINNER_SID + select ALLWINNER_SDHOST select UNIMP config MAX78000_SOC
hw/arm/allwinner-h618.c +15 -1
@@ -29,6 +29,7 @@ const hwaddr allwinner_h618_memmap[] = { [AW_H618_DEV_GIC_CPU] = 0x03022000, [AW_H618_DEV_GIC_HYP] = 0x03024000, [AW_H618_DEV_GIC_VCPU] = 0x03026000, + [AW_H618_DEV_MMC0] = 0x04020000, [AW_H618_DEV_SID] = 0x03006000, [AW_H618_DEV_UART0] = 0x05000000, [AW_H618_DEV_UART1] = 0x05000400,
@@ -49,7 +50,6 @@ static const struct AwH618Unimplemented { { "timer", 0x03009000, 4 * KiB }, { "pwm", 0x0300a000, 4 * KiB }, { "pio", 0x0300b000, 4 * KiB }, - { "mmc0", 0x04020000, 4 * KiB }, { "mmc1", 0x04021000, 4 * KiB }, { "mmc2", 0x04022000, 4 * KiB }, { "rtc", 0x07000000, 4 * KiB },
@@ -72,6 +72,7 @@ enum {AW_H618_GIC_SPI_UART1 =1 ,AW_H618_GIC_SPI_UART2 =2 ,AW_H618_GIC_SPI_UART3 =3 , + AW_H618_GIC_SPI_MMC0 = 35, }; enum {
@@ -95,6 +96,8 @@ static void allwinner_h618_init(Object *obj)object_initialize_child (obj,"sid" , &s->sid,TYPE_AW_SID );object_property_add_alias (obj,"identifier" ,OBJECT (&s->sid),"identifier" ); + +object_initialize_child (obj,"mmc0" , &s->mmc0,TYPE_AW_SDHOST_SUN50I_A64 ); }static void allwinner_h618_realize (DeviceState *dev,Error **errp)
@@ -181,6 +184,17 @@ static void allwinner_h618_realize(DeviceState *dev, Error **errp)sysbus_realize (SYS_BUS_DEVICE (&s->sid), &error_fatal);sysbus_mmio_map (SYS_BUS_DEVICE (&s->sid),0 , s->memmap[AW_H618_DEV_SID ]); +/* SD/MMC 0 */ +object_property_set_link (OBJECT (&s->mmc0),"dma-memory" , +OBJECT (get_system_memory ()), &error_fatal); +sysbus_realize (SYS_BUS_DEVICE (&s->mmc0), &error_fatal); +sysbus_mmio_map (SYS_BUS_DEVICE (&s->mmc0),0 , s->memmap[AW_H618_DEV_MMC0 ]); +sysbus_connect_irq (SYS_BUS_DEVICE (&s->mmc0),0 , +qdev_get_gpio_in (DEVICE (&s->gic),AW_H618_GIC_SPI_MMC0 )); + +object_property_add_alias (OBJECT (s),"sd-bus" ,OBJECT (&s->mmc0), +"sd-bus" ); +/* SRAM */ memory_region_init_ram (&s->sram_a1,OBJECT (dev),"sram A1" ,64 * KiB, &error_abort);
include/hw/arm/allwinner-h618.h +3 -0
@@ -12,6 +12,7 @@#include "qom/object.h" #include "hw/intc/arm_gic.h" #include "hw/misc/allwinner-sid.h" +#include "hw/sd/allwinner-sdhost.h" #include "target/arm/cpu.h" /**
@@ -24,6 +25,7 @@ enum {AW_H618_DEV_GIC_CPU ,AW_H618_DEV_GIC_HYP ,AW_H618_DEV_GIC_VCPU , +AW_H618_DEV_MMC0 ,AW_H618_DEV_SID ,AW_H618_DEV_UART0 , AW_H618_DEV_UART1,
@@ -53,6 +55,7 @@ struct AwH618State {const hwaddr *memmap;GICState gic;AwSidState sid; +AwSdHostState mmc0;MemoryRegion sram_a1;MemoryRegion sram_a2; };
Signature · 1 line
2.43.0
PATCH v2 8/8 hw/arm/orangepi-zero2w: Wire up SD card and support firmware loading
In reply to Khai DoConnect the SD card block backend to the H618 "sd-bus", allowing booting from MicroSD card images via -drive if=sd,format=raw,file=....
In addition, support loading raw firmware binaries (such as EDK2 UEFI or U-Boot) at 0x40080000 via the -bios command-line option.
--- hw/arm/orangepi-zero2w.c | 41 ++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-)
hw/arm/orangepi-zero2w.c +35 -6
@@ -13,8 +13,12 @@#include "qemu/error-report.h" #include "hw/core/boards.h" #include "hw/core/qdev-properties.h" +#include "hw/core/qdev-properties-system.h" #include "hw/arm/allwinner-h618.h" #include "hw/arm/boot.h" +#include "hw/core/loader.h" +#include "hw/sd/sd.h" +#include "system/blockdev.h" #define TYPE_ORANGEPI_ZERO2W_MACHINE MACHINE_TYPE_NAME("orangepi-zero2w")OBJECT_DECLARE_SIMPLE_TYPE (OrangePiZero2WMachineState,ORANGEPI_ZERO2W_MACHINE )
@@ -29,12 +33,10 @@ static void orangepi_zero2w_init(MachineState *machine) {OrangePiZero2WMachineState *opms =ORANGEPI_ZERO2W_MACHINE (machine);AwH618State *h618; - -/* BIOS is not supported by this board */ -if (machine->firmware) { -error_report ("BIOS not supported for this machine" ); -exit (1 ); - } +DriveInfo *di; +BlockBackend *blk; +BusState *bus; +DeviceState *carddev; h618 =AW_H618 (object_new (TYPE_AW_H618 ));object_property_add_child (OBJECT (machine),"soc" ,OBJECT (h618));
@@ -51,6 +53,15 @@ static void orangepi_zero2w_init(MachineState *machine)/* Mark H618 object realized */ qdev_realize (DEVICE (h618),NULL , &error_abort); +/* Retrieve SD bus and plug in SD card */ + di =drive_get (IF_SD ,0 ,0 ); + blk = di ?blk_by_legacy_dinfo (di) :NULL ; + bus =qdev_get_child_bus (DEVICE (h618),"sd-bus" ); + + carddev =qdev_new (TYPE_SD_CARD ); +qdev_prop_set_drive_err (carddev,"drive" , blk, &error_fatal); +qdev_realize_and_unref (carddev, bus, &error_fatal); +/* SDRAM */ memory_region_add_subregion(get_system_memory(), h618->memmap[AW_H618_DEV_SDRAM],
@@ -59,6 +70,24 @@ static void orangepi_zero2w_init(MachineState *machine) opms->bootinfo.loader_start = h618->memmap[AW_H618_DEV_SDRAM ]; opms->bootinfo.ram_size = machine->ram_size; opms->bootinfo.psci_conduit =QEMU_PSCI_CONDUIT_SMC ; + +/* Load firmware if specified (-bios) */ +if (machine->firmware) { +hwaddr firmware_addr =0x40080000 ; +int r; + + r =load_image_targphys (machine->firmware, firmware_addr, + machine->ram_size - + (firmware_addr -0x40000000 ),NULL ); +if (r <0 ) { +error_report ("Failed to load firmware from %s" , machine->firmware); +exit (1 ); + } + + opms->bootinfo.entry = firmware_addr; + opms->bootinfo.firmware_loaded = true; + } +arm_load_kernel (&h618->cpus[0 ], machine, &opms->bootinfo); }
Signature · 1 line
2.43.0