Skip to contentSkip to conversation

Add boot-mode property for zynq

PATCH Superseded Sai Pavan Boddu 2 participants 6 messages Jun 13, 2024 – Jun 19, 2024 Arm/Zynq architecture

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover Add boot-mode property for zynq

Add a way to update the boot-mode via machine properties.

Sai Pavan Boddu (2):
hw/misc/zynq_slcr: Add BootMode property
hw/arm/xilinx_zynq: Add boot-mode property

 hw/arm/xilinx_zynq.c | 22 ++++++++++++++++++++++
 hw/misc/zynq_slcr.c  | 11 ++++++++++-
 2 files changed, 32 insertions(+), 1 deletion(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/2 hw/misc/zynq_slcr: Add BootMode property

BootMode property sets user values into BOOT_MODE register, on hardware these are derived from board switches.

---
 hw/misc/zynq_slcr.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
hw/misc/zynq_slcr.c +10 -1
index 3412ff099e..72703e92a5 100644
@@ -24,6 +24,7 @@
 #include "hw/registerfields.h"
 #include "hw/qdev-clock.h"
 #include "qom/object.h"
+#include "hw/qdev-properties.h"
 
 #ifndef ZYNQ_SLCR_ERR_DEBUG
 #define ZYNQ_SLCR_ERR_DEBUG 0
@@ -121,6 +122,7 @@ REG32(RST_REASON, 0x250)
 
 REG32(REBOOT_STATUS, 0x258)
 REG32(BOOT_MODE, 0x25c)
+    FIELD(BOOT_MODE, BOOT_MODE, 0, 4)
 
 REG32(APU_CTRL, 0x300)
 REG32(WDT_CLK_SEL, 0x304)
@@ -195,6 +197,7 @@ struct ZynqSLCRState {
     Clock *ps_clk;
     Clock *uart0_ref_clk;
     Clock *uart1_ref_clk;
+    uint8_t BootMode;
 };
 
 /*
@@ -371,7 +374,7 @@ static void zynq_slcr_reset_init(Object *obj, ResetType type)
     s->regs[R_FPGA_RST_CTRL]  = 0x01F33F0F;
     s->regs[R_RST_REASON]     = 0x00000040;
 
-    s->regs[R_BOOT_MODE]      = 0x00000001;
+    s->regs[R_BOOT_MODE]      = s->BootMode & R_BOOT_MODE_BOOT_MODE_MASK;
 
     /* 0x700 - 0x7D4 */
     for (i = 0; i < 54; i++) {
@@ -610,6 +613,11 @@ static const VMStateDescription vmstate_zynq_slcr = {
     }
 };
 
+static Property zynq_slcr_props[] = {
+    DEFINE_PROP_UINT8("boot-mode", ZynqSLCRState, BootMode, 1),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
 static void zynq_slcr_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
@@ -619,6 +627,7 @@ static void zynq_slcr_class_init(ObjectClass *klass, void *data)
     rc->phases.enter = zynq_slcr_reset_init;
     rc->phases.hold  = zynq_slcr_reset_hold;
     rc->phases.exit  = zynq_slcr_reset_exit;
+    device_class_set_props(dc, zynq_slcr_props);
 }
 
 static const TypeInfo zynq_slcr_info = {
Signature · 1 line
2.34.1
#2 lore raw

PATCH 2/2 hw/arm/xilinx_zynq: Add boot-mode property

In reply to Sai Pavan Boddu

Read boot-mode value as machine property and propagate that to SLCR.BOOT_MODE register.

---
 hw/arm/xilinx_zynq.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
hw/arm/xilinx_zynq.c +22 -0
index 7f7a3d23fb..4dfa9184ac 100644
@@ -38,6 +38,7 @@
 #include "qom/object.h"
 #include "exec/tswap.h"
 #include "target/arm/cpu-qom.h"
+#include "qapi/visitor.h"
 
 #define TYPE_ZYNQ_MACHINE MACHINE_TYPE_NAME("xilinx-zynq-a9")
 OBJECT_DECLARE_SIMPLE_TYPE(ZynqMachineState, ZYNQ_MACHINE)
@@ -90,6 +91,7 @@ struct ZynqMachineState {
     MachineState parent;
     Clock *ps_clk;
     ARMCPU *cpu[ZYNQ_MAX_CPUS];
+    uint8_t BootMode;
 };
 
 static void zynq_write_board_setup(ARMCPU *cpu,
@@ -176,6 +178,19 @@ static inline int zynq_init_spi_flashes(uint32_t base_addr, qemu_irq irq,
     return unit;
 }
 
+static void zynq_set_boot_mode(Object *obj, Visitor *v,
+                               const char *name, void *opaque,
+                               Error **errp)
+{
+    ZynqMachineState *m = ZYNQ_MACHINE(obj);
+    uint8_t val;
+
+    if (!visit_type_uint8(v, name, &val, errp)) {
+        return;
+    }
+    m->BootMode = val;
+}
+
 static void zynq_init(MachineState *machine)
 {
     ZynqMachineState *zynq_machine = ZYNQ_MACHINE(machine);
@@ -241,6 +256,7 @@ static void zynq_init(MachineState *machine)
     /* Create slcr, keep a pointer to connect clocks */
     slcr = qdev_new("xilinx-zynq_slcr");
     qdev_connect_clock_in(slcr, "ps_clk", zynq_machine->ps_clk);
+    qdev_prop_set_uint8(slcr, "boot-mode", zynq_machine->BootMode);
     sysbus_realize_and_unref(SYS_BUS_DEVICE(slcr), &error_fatal);
     sysbus_mmio_map(SYS_BUS_DEVICE(slcr), 0, 0xF8000000);
 
@@ -372,6 +388,7 @@ static void zynq_machine_class_init(ObjectClass *oc, void *data)
         NULL
     };
     MachineClass *mc = MACHINE_CLASS(oc);
+    ObjectProperty *prop;
     mc->desc = "Xilinx Zynq Platform Baseboard for Cortex-A9";
     mc->init = zynq_init;
     mc->max_cpus = ZYNQ_MAX_CPUS;
@@ -379,6 +396,11 @@ static void zynq_machine_class_init(ObjectClass *oc, void *data)
     mc->ignore_memory_transaction_failures = true;
     mc->valid_cpu_types = valid_cpu_types;
     mc->default_ram_id = "zynq.ext_ram";
+    prop = object_class_property_add(oc, "boot-mode", "uint8_t", NULL,
+                              zynq_set_boot_mode, NULL, NULL);
+    object_class_property_set_description(oc, "boot-mode",
+                                          "Update SLCR.BOOT_MODE register");
+    object_property_set_default_uint(prop, 1);
 }
 
 static const TypeInfo zynq_machine_type = {
Signature · 1 line
2.34.1
#3 lore raw

Re: [PATCH 2/2] hw/arm/xilinx_zynq: Add boot-mode property

Quoted 4 lines · Sai Pavan Boddu

Read boot-mode value as machine property and propagate that to SLCR.BOOT_MODE register.

Hi Sai,

Directly exposing the register field to the user to set on the command-line probably makes usability a little too rough (user has to check the register specs in the TRM to change boot-mode).
We could perhaps add friendly names that we internally map to the register field values.

Another question, can we use the existing -boot command-line arg for this? Something along the lines of what x86 PC does:
https://github.com/qemu/qemu/blob/master/hw/i386/pc.c#L395

I don't know if the framework allows for long names but something like the following would be nice:
qemu -boot spi,ethernet,jtag,uart,etc

Would also be great to document a small example, perhaps in
https://github.com/qemu/qemu/tree/master/docs/system/arm

Best regards,
Edgar

Quoted 81 lines
---
 hw/arm/xilinx_zynq.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
hw/arm/xilinx_zynq.c +15 -0
index 7f7a3d23fb..4dfa9184ac 100644
@@ -38,6 +38,7 @@
 #include "qom/object.h"
 #include "exec/tswap.h"
 #include "target/arm/cpu-qom.h"
+#include "qapi/visitor.h"
 
 #define TYPE_ZYNQ_MACHINE MACHINE_TYPE_NAME("xilinx-zynq-a9")
 OBJECT_DECLARE_SIMPLE_TYPE(ZynqMachineState, ZYNQ_MACHINE)
@@ -90,6 +91,7 @@ struct ZynqMachineState {
     MachineState parent;
     Clock *ps_clk;
     ARMCPU *cpu[ZYNQ_MAX_CPUS];
+    uint8_t BootMode;
 };
 
 static void zynq_write_board_setup(ARMCPU *cpu,
@@ -176,6 +178,19 @@ static inline int zynq_init_spi_flashes(uint32_t
 base_addr, qemu_irq irq,
     return unit;
 }
 
+static void zynq_set_boot_mode(Object *obj, Visitor *v,
+                               const char *name, void *opaque,
+                               Error **errp)
+{
+    ZynqMachineState *m = ZYNQ_MACHINE(obj);
+    uint8_t val;
+
+    if (!visit_type_uint8(v, name, &val, errp)) {
+        return;
+    }
+    m->BootMode = val;
+}
+
 static void zynq_init(MachineState *machine)
 {
     ZynqMachineState *zynq_machine = ZYNQ_MACHINE(machine);
hw/arm/xilinx_zynq.c +2 -0
@@ -241,6 +256,7 @@ static void zynq_init(MachineState *machine)
     /* Create slcr, keep a pointer to connect clocks */
     slcr = qdev_new("xilinx-zynq_slcr");
     qdev_connect_clock_in(slcr, "ps_clk", zynq_machine->ps_clk);
+    qdev_prop_set_uint8(slcr, "boot-mode", zynq_machine->BootMode);
     sysbus_realize_and_unref(SYS_BUS_DEVICE(slcr), &error_fatal);
     sysbus_mmio_map(SYS_BUS_DEVICE(slcr), 0, 0xF8000000);
 
@@ -372,6 +388,7 @@ static void zynq_machine_class_init(ObjectClass *oc,
 void *data)
         NULL
     };
     MachineClass *mc = MACHINE_CLASS(oc);
+    ObjectProperty *prop;
     mc->desc = "Xilinx Zynq Platform Baseboard for Cortex-A9";
     mc->init = zynq_init;
     mc->max_cpus = ZYNQ_MAX_CPUS;
hw/arm/xilinx_zynq.c +5 -0
@@ -379,6 +396,11 @@ static void zynq_machine_class_init(ObjectClass *oc,
 void *data)
     mc->ignore_memory_transaction_failures = true;
     mc->valid_cpu_types = valid_cpu_types;
     mc->default_ram_id = "zynq.ext_ram";
+    prop = object_class_property_add(oc, "boot-mode", "uint8_t", NULL,
+                              zynq_set_boot_mode, NULL, NULL);
+    object_class_property_set_description(oc, "boot-mode",
+                                          "Update SLCR.BOOT_MODE
 register");
+    object_property_set_default_uint(prop, 1);
 }

static const TypeInfo zynq_machine_type = {
--
2.34.1

#4 lore raw

RE: [PATCH 2/2] hw/arm/xilinx_zynq: Add boot-mode property

Hi Edgar,

From: Edgar E. Iglesias <[email protected]>
Sent: Friday, June 14, 2024 4:38 PM
To: Boddu, Sai Pavan <[email protected]>
Cc: [email protected]; [email protected]; Alistair Francis <[email protected]>; Peter Maydell <[email protected]>; Iglesias, Francisco <[email protected]>
Subject: Re: [PATCH 2/2] hw/arm/xilinx_zynq: Add boot-mode property

On Thu, Jun 13, 2024 at 5:36 PM Sai Pavan Boddu <[email protected]<mailto:[email protected]>> wrote:
Read boot-mode value as machine property and propagate that to
SLCR.BOOT_MODE register.

Hi Sai,

Directly exposing the register field to the user to set on the command-line probably makes usability a little too rough (user has to check the register specs in the TRM to change boot-mode). We could perhaps add friendly names that we internally map to the register field values.

Another question, can we use the existing -boot command-line arg for this? Something along the lines of what x86 PC does:
https://github.com/qemu/qemu/blob/master/hw/i386/pc.c#L395

I don't know if the framework allows for long names but something like the following would be nice:
qemu -boot spi,ethernet,jtag,uart,etc
[Boddu, Sai Pavan] Ok it makes much sense, Otherwise I would add more details in the description of the new property about the possible boot modes.

Would also be great to document a small example, perhaps in https://github.com/qemu/qemu/tree/master/docs/system/arm
[Boddu, Sai Pavan] Sure.

Regards,
Sai Pavan

Best regards,
Edgar

---
 hw/arm/xilinx_zynq.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
hw/arm/xilinx_zynq.c +22 -0
index 7f7a3d23fb..4dfa9184ac 100644
@@ -38,6 +38,7 @@
 #include "qom/object.h"
 #include "exec/tswap.h"
 #include "target/arm/cpu-qom.h"
+#include "qapi/visitor.h"
 
 #define TYPE_ZYNQ_MACHINE MACHINE_TYPE_NAME("xilinx-zynq-a9")
 OBJECT_DECLARE_SIMPLE_TYPE(ZynqMachineState, ZYNQ_MACHINE)
@@ -90,6 +91,7 @@ struct ZynqMachineState {
     MachineState parent;
     Clock *ps_clk;
     ARMCPU *cpu[ZYNQ_MAX_CPUS];
+    uint8_t BootMode;
 };
 
 static void zynq_write_board_setup(ARMCPU *cpu,
@@ -176,6 +178,19 @@ static inline int zynq_init_spi_flashes(uint32_t base_addr, qemu_irq irq,
     return unit;
 }
 
+static void zynq_set_boot_mode(Object *obj, Visitor *v,
+                               const char *name, void *opaque,
+                               Error **errp)
+{
+    ZynqMachineState *m = ZYNQ_MACHINE(obj);
+    uint8_t val;
+
+    if (!visit_type_uint8(v, name, &val, errp)) {
+        return;
+    }
+    m->BootMode = val;
+}
+
 static void zynq_init(MachineState *machine)
 {
     ZynqMachineState *zynq_machine = ZYNQ_MACHINE(machine);
@@ -241,6 +256,7 @@ static void zynq_init(MachineState *machine)
     /* Create slcr, keep a pointer to connect clocks */
     slcr = qdev_new("xilinx-zynq_slcr");
     qdev_connect_clock_in(slcr, "ps_clk", zynq_machine->ps_clk);
+    qdev_prop_set_uint8(slcr, "boot-mode", zynq_machine->BootMode);
     sysbus_realize_and_unref(SYS_BUS_DEVICE(slcr), &error_fatal);
     sysbus_mmio_map(SYS_BUS_DEVICE(slcr), 0, 0xF8000000);
 
@@ -372,6 +388,7 @@ static void zynq_machine_class_init(ObjectClass *oc, void *data)
         NULL
     };
     MachineClass *mc = MACHINE_CLASS(oc);
+    ObjectProperty *prop;
     mc->desc = "Xilinx Zynq Platform Baseboard for Cortex-A9";
     mc->init = zynq_init;
     mc->max_cpus = ZYNQ_MAX_CPUS;
@@ -379,6 +396,11 @@ static void zynq_machine_class_init(ObjectClass *oc, void *data)
     mc->ignore_memory_transaction_failures = true;
     mc->valid_cpu_types = valid_cpu_types;
     mc->default_ram_id = "zynq.ext_ram";
+    prop = object_class_property_add(oc, "boot-mode", "uint8_t", NULL,
+                              zynq_set_boot_mode, NULL, NULL);
+    object_class_property_set_description(oc, "boot-mode",
+                                          "Update SLCR.BOOT_MODE register");
+    object_property_set_default_uint(prop, 1);
 }
 
 static const TypeInfo zynq_machine_type = {

--
2.34.1

#5 lore raw

RE: [PATCH 2/2] hw/arm/xilinx_zynq: Add boot-mode property

Hi Edgar,

From: Boddu, Sai Pavan
Sent: Friday, June 14, 2024 8:37 PM
To: Edgar E. Iglesias <[email protected]>
Cc: [email protected]; [email protected]; Alistair Francis <[email protected]>; Peter Maydell <[email protected]>; Iglesias, Francisco <[email protected]>
Subject: RE: [PATCH 2/2] hw/arm/xilinx_zynq: Add boot-mode property

Hi Edgar,

I examined -boot switch to configure boot mode.
It would become little complex to map zynq boot devices to below expected mapping.

* a-b: floppy disk drives
* c-f: IDE disk drives
* g-m: machine implementation dependent drives
* n-p: network devices

With above options, we may need to use “g-m” flags for our boot modes, which becomes a little confusing. So in order to make it user friendly, I would convert the proposed boot-mode property to accept strings like “jtag/qspi/sd”.

Regards,
Sai Pavan
From: Edgar E. Iglesias <[email protected]<mailto:[email protected]>>
Sent: Friday, June 14, 2024 4:38 PM
To: Boddu, Sai Pavan <[email protected]<mailto:[email protected]>>
Cc: [email protected]<mailto:[email protected]>; [email protected]<mailto:[email protected]>; Alistair Francis <[email protected]<mailto:[email protected]>>; Peter Maydell <[email protected]<mailto:[email protected]>>; Iglesias, Francisco <[email protected]<mailto:[email protected]>>
Subject: Re: [PATCH 2/2] hw/arm/xilinx_zynq: Add boot-mode property

On Thu, Jun 13, 2024 at 5:36 PM Sai Pavan Boddu <[email protected]<mailto:[email protected]>> wrote:
Read boot-mode value as machine property and propagate that to
SLCR.BOOT_MODE register.

Hi Sai,

Directly exposing the register field to the user to set on the command-line probably makes usability a little too rough (user has to check the register specs in the TRM to change boot-mode). We could perhaps add friendly names that we internally map to the register field values.

Another question, can we use the existing -boot command-line arg for this? Something along the lines of what x86 PC does:
https://github.com/qemu/qemu/blob/master/hw/i386/pc.c#L395

I don't know if the framework allows for long names but something like the following would be nice:
qemu -boot spi,ethernet,jtag,uart,etc
[Boddu, Sai Pavan] Ok it makes much sense, Otherwise I would add more details in the description of the new property about the possible boot modes.

Would also be great to document a small example, perhaps in https://github.com/qemu/qemu/tree/master/docs/system/arm
[Boddu, Sai Pavan] Sure.

Regards,
Sai Pavan

Best regards,
Edgar

---
 hw/arm/xilinx_zynq.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
hw/arm/xilinx_zynq.c +22 -0
index 7f7a3d23fb..4dfa9184ac 100644
@@ -38,6 +38,7 @@
 #include "qom/object.h"
 #include "exec/tswap.h"
 #include "target/arm/cpu-qom.h"
+#include "qapi/visitor.h"
 
 #define TYPE_ZYNQ_MACHINE MACHINE_TYPE_NAME("xilinx-zynq-a9")
 OBJECT_DECLARE_SIMPLE_TYPE(ZynqMachineState, ZYNQ_MACHINE)
@@ -90,6 +91,7 @@ struct ZynqMachineState {
     MachineState parent;
     Clock *ps_clk;
     ARMCPU *cpu[ZYNQ_MAX_CPUS];
+    uint8_t BootMode;
 };
 
 static void zynq_write_board_setup(ARMCPU *cpu,
@@ -176,6 +178,19 @@ static inline int zynq_init_spi_flashes(uint32_t base_addr, qemu_irq irq,
     return unit;
 }
 
+static void zynq_set_boot_mode(Object *obj, Visitor *v,
+                               const char *name, void *opaque,
+                               Error **errp)
+{
+    ZynqMachineState *m = ZYNQ_MACHINE(obj);
+    uint8_t val;
+
+    if (!visit_type_uint8(v, name, &val, errp)) {
+        return;
+    }
+    m->BootMode = val;
+}
+
 static void zynq_init(MachineState *machine)
 {
     ZynqMachineState *zynq_machine = ZYNQ_MACHINE(machine);
@@ -241,6 +256,7 @@ static void zynq_init(MachineState *machine)
     /* Create slcr, keep a pointer to connect clocks */
     slcr = qdev_new("xilinx-zynq_slcr");
     qdev_connect_clock_in(slcr, "ps_clk", zynq_machine->ps_clk);
+    qdev_prop_set_uint8(slcr, "boot-mode", zynq_machine->BootMode);
     sysbus_realize_and_unref(SYS_BUS_DEVICE(slcr), &error_fatal);
     sysbus_mmio_map(SYS_BUS_DEVICE(slcr), 0, 0xF8000000);
 
@@ -372,6 +388,7 @@ static void zynq_machine_class_init(ObjectClass *oc, void *data)
         NULL
     };
     MachineClass *mc = MACHINE_CLASS(oc);
+    ObjectProperty *prop;
     mc->desc = "Xilinx Zynq Platform Baseboard for Cortex-A9";
     mc->init = zynq_init;
     mc->max_cpus = ZYNQ_MAX_CPUS;
@@ -379,6 +396,11 @@ static void zynq_machine_class_init(ObjectClass *oc, void *data)
     mc->ignore_memory_transaction_failures = true;
     mc->valid_cpu_types = valid_cpu_types;
     mc->default_ram_id = "zynq.ext_ram";
+    prop = object_class_property_add(oc, "boot-mode", "uint8_t", NULL,
+                              zynq_set_boot_mode, NULL, NULL);
+    object_class_property_set_description(oc, "boot-mode",
+                                          "Update SLCR.BOOT_MODE register");
+    object_property_set_default_uint(prop, 1);
 }
 
 static const TypeInfo zynq_machine_type = {

--
2.34.1