From: Chao Liu <[email protected]> Connect an XT25F128 to chip select 0 of the ROCK 5B SFC. An optional if=mtd,index=0 drive provides the flash contents and must be exactly 16 MiB; without a drive the flash starts erased.
Signed-off-by: Chao Liu <[email protected]> Signed-off-by: Yifan Wang <[email protected]> --- hw/arm/Kconfig | 1 + hw/arm/rock-5b.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig index 40f7de823c..01ae699fee 100644 --- a/hw/arm/Kconfig +++ b/hw/arm/Kconfig @@ -789,3 +789,4 @@ config ROCK5B default y depends on TCG && AARCH64 select RK3588 + select SSI_M25P80 diff --git a/hw/arm/rock-5b.c b/hw/arm/rock-5b.c index 7906d53175..abc898c50c 100644 --- a/hw/arm/rock-5b.c +++ b/hw/arm/rock-5b.c @@ -17,8 +17,12 @@ #include "hw/arm/boot.h" #include "hw/arm/rk3588.h" #include "hw/core/boards.h" +#include "hw/core/qdev-properties.h" #include "hw/core/qdev-properties-system.h" +#include "hw/ssi/ssi.h" #include "system/address-spaces.h" +#include "system/block-backend.h" +#include "system/blockdev.h" #include "system/device_tree.h" #include "system/kvm.h" #include "system/qtest.h" @@ -37,6 +41,7 @@ static const MemMapEntry rock5b_memmap[] = { [ROCK5B_HIGH_RAM] = { 0x100000000, 0x310000000 }, }; +#define ROCK5B_FLASH_SIZE (16 * MiB) /* Match the low-memory reservation made by Rockchip U-Boot for BL31. */ #define ROCK5B_FIRMWARE_RESERVED_SIZE (2 * MiB) /* UART2 drives the board's debug header. */ @@ -70,6 +75,28 @@ static void rock5b_connect_serial(Rock5BMachineState *s) } } +static void rock5b_create_flash(Rock5BMachineState *s) +{ + DriveInfo *di = drive_get(IF_MTD, 0, 0); + DeviceState *flash = qdev_new("xt25f128"); + + object_property_add_child(OBJECT(s), "spi-nor", OBJECT(flash)); + if (di) { + BlockBackend *blk = blk_by_legacy_dinfo(di); + int64_t length = blk_getlength(blk); + + if (length != ROCK5B_FLASH_SIZE) { + error_report("rock-5b: SPI NOR image must be exactly 16 MiB"); + exit(EXIT_FAILURE); + } + qdev_prop_set_drive_err(flash, "drive", blk, &error_fatal); + } + qdev_realize_and_unref(flash, qdev_get_child_bus(s->soc.sfc, "spi"), + &error_fatal); + qdev_connect_gpio_out_named(s->soc.sfc, "cs", 0, + qdev_get_gpio_in_named(flash, SSI_GPIO_CS, 0)); +} + /* * arm_load_dtb() replaces the memory nodes with a single node for low RAM; * add the RAM above the peripheral hole. @@ -168,6 +195,8 @@ static void rock5b_init(MachineState *ms) &s->high_ram); } + rock5b_create_flash(s); + rock5b_direct_boot(s); } -- 2.53.0
