Skip to contentSkip to conversation

Xilinx Zynq 7000 Start of CPU1

DISCUSSION Sebastian Huber 1 participant 2 messages Sep 18, 2024 – Sep 19, 2024 Arm/Zynq architecture

lore
Share & tools
lore
#0 lore raw

Hello,

I recently added the support for CPU1 to the xilinx-zynq-a9 machine (hw/arm/xilinx_zynq.c). However, the reset behaviour doesn't match exactly with the hardware. After a system reset (SRST), the CPU1 should execute a wfe instruction and then load the start address from 0xfffffff0:

https://docs.amd.com/r/en-US/ug585-zynq-7000-SoC-TRM/Starting-Code-on-CPU-1

It would be great if someone has a hint for me how I can add this startup code for CPU1 at address region 0xFFFFFE00 to 0xFFFFFFF0.

Kind regards, Sebastian

Signature · 14 lines
embedded brains GmbH & Co. KG
Herr Sebastian HUBER
Dornierstr. 4
82178 Puchheim
Germany
email: [email protected]
phone: +49-89-18 94 741 - 16
fax:   +49-89-18 94 741 - 08

Registergericht: Amtsgericht München
Registernummer: HRB 157899
Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler
Unsere Datenschutzerklärung finden Sie hier:
https://embedded-brains.de/datenschutzerklaerung/
#1 lore raw

----- Am 18. Sep 2024 um 11:13 schrieb Sebastian Huber [email protected]:

Quoted 11 lines

Hello,

I recently added the support for CPU1 to the xilinx-zynq-a9 machine (hw/arm/xilinx_zynq.c). However, the reset behaviour doesn't match exactly with the hardware. After a system reset (SRST), the CPU1 should execute a wfe instruction and then load the start address from 0xfffffff0:

https://docs.amd.com/r/en-US/ug585-zynq-7000-SoC-TRM/Starting-Code-on-CPU-1

It would be great if someone has a hint for me how I can add this startup code for CPU1 at address region 0xFFFFFE00 to 0xFFFFFFF0.

I got it working with some hacks in arm_load_kernel() and do_cpu_reset(). In arm_load_kernel() had to remove the:

        /*
         * No secondary boot stub; don't use the reset hook that would
         * have set the CPU up to call it
         */
        info->write_secondary_boot = NULL;
        info->secondary_cpu_reset_hook = NULL;

This change probably breaks a lot of things. I am not sure how to address this issue.

Signature · 14 lines
embedded brains GmbH & Co. KG
Herr Sebastian HUBER
Dornierstr. 4
82178 Puchheim
Germany
email: [email protected]
phone: +49-89-18 94 741 - 16
fax:   +49-89-18 94 741 - 08

Registergericht: Amtsgericht München
Registernummer: HRB 157899
Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler
Unsere Datenschutzerklärung finden Sie hier:
https://embedded-brains.de/datenschutzerklaerung/

From ea8ef3df07530ed22152264bbcff2a13ccb70975 Mon Sep 17 00:00:00 2001
From: Sebastian Huber <[email protected]>
Date: Thu, 19 Sep 2024 02:24:53 +0200
Subject: [PATCH] hw/arm/xilinx_zynq: Add CPU1 reset

After a system reset (SRST), the CPU1 should execute a wfe instruction and then load the start address from 0xfffffff0:

https://docs.amd.com/r/en-US/ug585-zynq-7000-SoC-TRM/Starting-Code-on-CPU-1

---
 hw/arm/boot.c        | 15 +++++++--------
 hw/arm/xilinx_zynq.c | 19 +++++++++++++++++++
 2 files changed, 26 insertions(+), 8 deletions(-)
hw/arm/boot.c +7 -8
index 7c10818c4f..ed5909b086 100644
@@ -722,7 +722,11 @@ static void do_cpu_reset(void *opaque)
                 g_assert_not_reached();
             }
 
-            cpu_set_pc(cs, entry);
+            if (cs == first_cpu || !info->secondary_cpu_reset_hook) {
+                cpu_set_pc(cs, entry);
+            } else {
+                info->secondary_cpu_reset_hook(cpu, info);
+            }
         } else {
             /* If we are booting Linux then we need to check whether we are
              * booting into secure or non-secure state and adjust the state
@@ -1380,13 +1384,8 @@ void arm_load_kernel(ARMCPU *cpu, MachineState *ms, struct arm_boot_info *info)
             info->write_secondary_boot = default_write_secondary;
         }
         info->write_secondary_boot(cpu, info);
-    } else {
-        /*
-         * No secondary boot stub; don't use the reset hook that would
-         * have set the CPU up to call it
-         */
-        info->write_secondary_boot = NULL;
-        info->secondary_cpu_reset_hook = NULL;
+    } else if (info->write_secondary_boot) {
+        info->write_secondary_boot(cpu, info);
     }
 
     /*
hw/arm/xilinx_zynq.c +19 -0
index e4e1a619e2..7040520b80 100644
@@ -62,6 +62,8 @@ static const int dma_irqs[8] = {
 
 #define BOARD_SETUP_ADDR        0x100
 
+#define SECONDARY_SETUP_ADDR    0xFFFFFFE8
+
 #define SLCR_LOCK_OFFSET        0x004
 #define SLCR_UNLOCK_OFFSET      0x008
 #define SLCR_ARM_PLL_OFFSET     0x100
@@ -109,6 +111,22 @@ static void zynq_write_board_setup(ARMCPU *cpu,
                        sizeof(board_setup_blob), BOARD_SETUP_ADDR);
 }
 
+static void zynq_secondary_cpu_reset(ARMCPU *cpu,
+                                     const struct arm_boot_info *info)
+{
+    uint32_t secondary_setup_blob[] = {
+        0xe320f002, /* wfe */
+        0xe51ff004, /* ldr pc, [pc, #-4] */
+        SECONDARY_SETUP_ADDR
+    };
+    for (int n = 0; n < ARRAY_SIZE(secondary_setup_blob); n++) {
+        secondary_setup_blob[n] = tswap32(secondary_setup_blob[n]);
+    }
+    rom_add_blob_fixed("secondary-setup", secondary_setup_blob,
+                       sizeof(secondary_setup_blob), SECONDARY_SETUP_ADDR);
+    cpu_set_pc(CPU(cpu), SECONDARY_SETUP_ADDR);
+}
+
 static struct arm_boot_info zynq_binfo = {};
 
 static void gem_init(NICInfo *nd, uint32_t base, qemu_irq irq)
@@ -363,6 +381,7 @@ static void zynq_init(MachineState *machine)
     zynq_binfo.loader_start = 0;
     zynq_binfo.board_setup_addr = BOARD_SETUP_ADDR;
     zynq_binfo.write_board_setup = zynq_write_board_setup;
+    zynq_binfo.secondary_cpu_reset_hook = zynq_secondary_cpu_reset;
 
     arm_load_kernel(zynq_machine->cpu[0], machine, &zynq_binfo);
 }
Signature · 1 line
2.43.0