blob: 9b367a7bfb6bee710471b9e1a49d11d21a0a8b45 [file] [log] [blame]
Andrew Geissler9347dd42023-03-03 12:38:41 -06001From b1105e862e8f770fc195bc20e9c64d231dd32f66 Mon Sep 17 00:00:00 2001
Brad Bishopbec4ebc2022-08-03 09:55:16 -04002From: Jaxson Han <jaxson.han@arm.com>
3Date: Wed, 29 Dec 2021 15:33:17 +0800
4Subject: [PATCH] boot: Enable firmware node initialization
5
6Enable the firmware node initialization, so that the next stage
7(hypervisor) could share the EL2 with firmware (boot-wrapper). The next
8stage (hypervisor) get the smccc entry point, code/data sections, the
9sections attrs and firmware node version and so on.
10It is worth noting that this EL2 sharing mechanism is only for Armv8R
11AArch64, thus add flag_v8r to record if the arch is Armv8R AArch64.
12Enable the firmware node initialization only if it is Armv8R AArch64.
13Also, we increase the stack size to 1024 to fix the stack overflow issue
14when using the libfdt.
15
16Add -fno-builtin options to CFLAGS to avoid the issue that the 'memset'
17in common/lib.c conflicts with builtin 'memset' function. GCC version
18>= 10 will have an incorrect compilation without -fno-builtin;
19
20Issue-Id: SCM-3816
21Upstream-Status: Inappropriate [other]
22 Implementation pending further discussion
23Signed-off-by: Jaxson Han <jaxson.han@arm.com>
24Change-Id: Ib274485a34d26215595fd0cd737be86610289817
25---
26 Makefile.am | 4 ++--
27 arch/aarch64/boot.S | 6 ++++++
28 common/boot.c | 4 ++++
29 3 files changed, 12 insertions(+), 2 deletions(-)
30
31diff --git a/Makefile.am b/Makefile.am
Andrew Geissler9347dd42023-03-03 12:38:41 -060032index cc6504e..fbe6b81 100644
Brad Bishopbec4ebc2022-08-03 09:55:16 -040033--- a/Makefile.am
34+++ b/Makefile.am
35@@ -23,7 +23,7 @@ DEFINES += -DCPU_IDS=$(CPU_IDS)
36 DEFINES += -DNR_CPUS=$(NR_CPUS)
37 DEFINES += $(if $(SYSREGS_BASE), -DSYSREGS_BASE=$(SYSREGS_BASE), )
38 DEFINES += -DUART_BASE=$(UART_BASE)
39-DEFINES += -DSTACK_SIZE=256
40+DEFINES += -DSTACK_SIZE=1024
41
42 if KERNEL_32
43 DEFINES += -DKERNEL_32
Andrew Geissler9347dd42023-03-03 12:38:41 -060044@@ -134,7 +134,7 @@ CFLAGS += -I$(top_srcdir)/include/ -I$(top_srcdir)/$(ARCH_SRC)/include/
Brad Bishopbec4ebc2022-08-03 09:55:16 -040045 CFLAGS += -Wall -fomit-frame-pointer
Andrew Geissler9347dd42023-03-03 12:38:41 -060046 CFLAGS += -ffreestanding -nostdlib
47 CFLAGS += -fno-stack-protector
Brad Bishopbec4ebc2022-08-03 09:55:16 -040048-CFLAGS += -fno-stack-protector
49+CFLAGS += -fno-stack-protector -fno-builtin
50 CFLAGS += -ffunction-sections -fdata-sections
51 CFLAGS += -fno-pic -fno-pie
52 LDFLAGS += --gc-sections
53diff --git a/arch/aarch64/boot.S b/arch/aarch64/boot.S
Andrew Geissler9347dd42023-03-03 12:38:41 -060054index c079d22..daaa674 100644
Brad Bishopbec4ebc2022-08-03 09:55:16 -040055--- a/arch/aarch64/boot.S
56+++ b/arch/aarch64/boot.S
Andrew Geissler9347dd42023-03-03 12:38:41 -060057@@ -261,6 +261,10 @@ el2_init:
Brad Bishopbec4ebc2022-08-03 09:55:16 -040058 #endif
59 ldr x1, =spsr_to_elx
60 str w0, [x1]
61+
62+ mov w0, #1
63+ ldr x1, =flag_v8r
64+ str w0, [x1]
65 // fall through
66
67 el_max_init:
Andrew Geissler9347dd42023-03-03 12:38:41 -060068@@ -340,3 +344,5 @@ flag_keep_el:
Brad Bishopbec4ebc2022-08-03 09:55:16 -040069 .long 0
70 ASM_DATA(spsr_to_elx)
71 .long 0
72+ASM_DATA(flag_v8r)
73+ .long 0
74diff --git a/common/boot.c b/common/boot.c
75index ee2bea0..38b2dca 100644
76--- a/common/boot.c
77+++ b/common/boot.c
78@@ -11,6 +11,9 @@
79
80 extern unsigned long entrypoint;
81 extern unsigned long dtb;
82+extern unsigned int flag_v8r;
83+
84+extern void dt_fw_node_init(int enable);
85
86 void init_platform(void);
87
88@@ -64,6 +67,7 @@ void __noreturn first_spin(unsigned int cpu, unsigned long *mbox,
89 if (cpu == 0) {
90 init_platform();
91 dt_add_memreserve();
92+ dt_fw_node_init(flag_v8r == 1);
93
94 *mbox = (unsigned long)&entrypoint;
95 sevl();