Skip to content

Commit 6b6d561

Browse files
committed
Added support for initializting the GICv2 interrupt controller. This is required for QNX kernel boot.
1 parent e7446c5 commit 6b6d561

4 files changed

Lines changed: 55 additions & 9 deletions

File tree

IDE/XilinxSDK/.cproject

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/src}&quot;"/>
3737
</option>
3838
<option id="xilinx.gnu.compiler.symbols.defined.980385157" name="Defined symbols (-D)" superClass="xilinx.gnu.compiler.symbols.defined" valueType="definedSymbols">
39+
<listOptionValue builtIn="false" value="USE_BUILTIN_STARTUP"/>
3940
<listOptionValue builtIn="false" value="DEBUG=1"/>
4041
<listOptionValue builtIn="false" value="__WOLFBOOT"/>
4142
<listOptionValue builtIn="false" value="PART_UPDATE_EXT=1"/>
@@ -94,7 +95,7 @@
9495
</toolChain>
9596
</folderInfo>
9697
<sourceEntries>
97-
<entry excluding="src/boot_aarch64_start.S|tools|test-app|src/xmalloc_ecc.c|src/vector_riscv.S|src/update_flash.c|src/update_flash_hwswap.c|src/boot_riscv.c|src/boot_arm.c|hal" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
98+
<entry excluding="tools|test-app|src/xmalloc_ecc.c|src/vector_riscv.S|src/update_flash.c|src/update_flash_hwswap.c|src/boot_riscv.c|src/boot_arm.c|hal" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
9899
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="hal"/>
99100
</sourceEntries>
100101
</configuration>
@@ -130,6 +131,7 @@
130131
</option>
131132
<option id="xilinx.gnu.compiler.inferred.swplatform.flags.1801302027" name="Software Platform Inferred Flags" superClass="xilinx.gnu.compiler.inferred.swplatform.flags" value=" " valueType="string"/>
132133
<option id="xilinx.gnu.compiler.symbols.defined.1649249146" name="Defined symbols (-D)" superClass="xilinx.gnu.compiler.symbols.defined" valueType="definedSymbols">
134+
<listOptionValue builtIn="false" value="USE_BUILTIN_STARTUP"/>
133135
<listOptionValue builtIn="false" value="__WOLFBOOT"/>
134136
<listOptionValue builtIn="false" value="PART_UPDATE_EXT=1"/>
135137
<listOptionValue builtIn="false" value="PART_SWAP_EXT=1"/>
@@ -190,7 +192,7 @@
190192
</toolChain>
191193
</folderInfo>
192194
<sourceEntries>
193-
<entry excluding="src/boot_aarch64_start.S|tools|test-app|src/xmalloc_ecc.c|src/vector_riscv.S|src/update_flash.c|src/update_flash_hwswap.c|src/boot_riscv.c|src/boot_arm.c|hal" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
195+
<entry excluding="tools|test-app|src/xmalloc_ecc.c|src/vector_riscv.S|src/update_flash.c|src/update_flash_hwswap.c|src/boot_riscv.c|src/boot_arm.c|hal" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
194196
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="hal"/>
195197
</sourceEntries>
196198
</configuration>

hal/zynq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ void hal_init(void)
798798
uint32_t cpu_freq = 0;
799799

800800
#ifdef DEBUG_ZYNQ
801-
xil_printf("wolfBoot Secure Boot\n");
801+
xil_printf("\nwolfBoot Secure Boot\n");
802802
#endif
803803

804804
asm volatile("msr cntfrq_el0, %0" : : "r" (cpu_freq) : "memory");

src/boot_aarch64.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ static volatile unsigned int cpu_id;
3131
extern unsigned int *END_STACK;
3232

3333
extern void main(void);
34+
extern void gicv2_init_secure(void);
3435

3536
void boot_entry_C(void)
3637
{
@@ -59,21 +60,27 @@ void RAMFUNCTION do_boot(const uint32_t *app_offset, const uint32_t* dts_offset)
5960
void RAMFUNCTION do_boot(const uint32_t *app_offset)
6061
#endif
6162
{
62-
/* Set application address via x4 */
63-
asm volatile("mov x4, %0" : : "r"(app_offset));
63+
/* Set application address via x4 */
64+
asm volatile("mov x4, %0" : : "r"(app_offset));
6465

6566
#ifdef MMU
66-
/* move the dts pointer to x0 (as first argument) */
67-
asm volatile("mov x0, %0" : : "r"(dts_offset));
67+
/* Move the dts pointer to x5 (as first argument) */
68+
asm volatile("mov x5, %0" : : "r"(dts_offset));
6869
#else
69-
asm volatile("mov x0, xzr");
70+
asm volatile("mov x5, xzr");
7071
#endif
7172

72-
/* zero registers x1, x2, x3 */
73+
/* Initialize GICv2 for Kernel */
74+
gicv2_init_secure();
75+
76+
/* Zero registers x1, x2, x3 */
7377
asm volatile("mov x3, xzr");
7478
asm volatile("mov x2, xzr");
7579
asm volatile("mov x1, xzr");
7680

81+
/* Move the dts pointer to x0 (as first argument) */
82+
asm volatile("mov x0, x5");
83+
7784
/* Unconditionally jump to app_entry at x4 */
7885
asm volatile("br x4");
7986
}

src/boot_aarch64_start.S

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@
1919
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
2020
*/
2121

22+
23+
#define GICD_BASE 0xF9010000
24+
#define GICD_CTLR 0x0000
25+
#define GICD_TYPER 0x0004
26+
#define GICD_SGIR 0x0F00
27+
#define GICD_IGROUPRn 0x0080
28+
29+
#define GICC_BASE 0xF9020000
30+
#define GICC_PMR 0x0004
31+
32+
#ifndef USE_BUILTIN_STARTUP
2233
.section ".boot"
2334
.global _vector_table
2435
_vector_table:
@@ -61,4 +72,30 @@ _vector_table:
6172
8: mov sp, x1 // set stack pointer
6273
bl boot_entry_C // boot_entry_C never returns
6374
b 7b // go to sleep anyhow in case.
75+
#endif /* USE_BUILTIN_STARTUP */
76+
77+
78+
/* Initialize GIC 400 (GICv2) */
79+
.global gicv2_init_secure
80+
gicv2_init_secure:
81+
ldr x0, =GICD_BASE
82+
mov w9, #0x3 /* EnableGrp0 | EnableGrp1 */
83+
str w9, [x0, GICD_CTLR] /* Secure GICD_CTLR */
84+
ldr w9, [x0, GICD_TYPER]
85+
and w10, w9, #0x1f /* ITLinesNumber */
86+
cbz w10, 1f /* No SPIs */
87+
add x11, x0, GICD_IGROUPRn
88+
mov w9, #~0 /* Config SPIs as Grp1 */
89+
str w9, [x11], #0x4
90+
0: str w9, [x11], #0x4
91+
sub w10, w10, #0x1
92+
cbnz w10, 0b
93+
94+
ldr x1, =GICC_BASE /* GICC_CTLR */
95+
mov w0, #3 /* EnableGrp0 | EnableGrp1 */
96+
str w0, [x1]
6497

98+
mov w0, #1 << 7 /* Allow NS access to GICC_PMR */
99+
str w0, [x1, #4] /* GICC_PMR */
100+
1:
101+
ret

0 commit comments

Comments
 (0)