From 279cad8ed38c186aebce3502f9f1ebc52e22b281 Mon Sep 17 00:00:00 2001
From: Chris Kay <chris.kay@arm.com>
Date: Mon, 4 Nov 2024 17:15:22 +0000
Subject: [PATCH 1/2] fix(rk3399): mark INCBIN-generated sections as SHF_ALLOC

When assembling with Clang, sections generated via the `INCBIN` macro
are not assigned the `SHF_ALLOC` attribute, and the linker therefore
does not know to include them in the binary.

This change is simple: explicitly tell the assembler that the section
should have the `SHF_ALLOC` attribute.

For reference: https://man7.org/linux/man-pages/man5/elf.5.html

>   SHF_ALLOC
>       This section occupies memory during process execution. Some
>       control sections do not reside in the memory image of an object
>       file. This attribute is off for those sections.

Change-Id: I626162eae9030b5ffbd03af2be76f89a248af9ca
Signed-off-by: Chris Kay <chris.kay@arm.com>
Signed-off-by: Quentin Schulz <quentin.schulz@cherry.de>
---
 plat/rockchip/rk3399/drivers/pmu/pmu_fw.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/plat/rockchip/rk3399/drivers/pmu/pmu_fw.S b/plat/rockchip/rk3399/drivers/pmu/pmu_fw.S
index 26f331317..74f569402 100644
--- a/plat/rockchip/rk3399/drivers/pmu/pmu_fw.S
+++ b/plat/rockchip/rk3399/drivers/pmu/pmu_fw.S
@@ -6,7 +6,7 @@
 
 /* convoluted way to make sure that the define is pasted just the right way */
 .macro INCBIN file sym sec
-	.section \sec
+	.section \sec, "a"
 	.global \sym
 	.type \sym, @object
 	.align 4

From ddd70f199bd0b09a229aa624497b86dbff5b8db5 Mon Sep 17 00:00:00 2001
From: Quentin Schulz <quentin.schulz@cherry.de>
Date: Mon, 4 Nov 2024 18:36:15 +0100
Subject: [PATCH 2/2] fix(rk3399): fix unquoted .incbin for clang

While GCC doesn't complain about anything for .incbin, clang does:
"""
<instantiation>:6:10: error: expected string in '.incbin' directive
 .incbin /build/rk3399/release/m0/rk3399m0.bin
         ^
plat/rockchip/rk3399/drivers/pmu/pmu_fw.S:20:1: note: while in macro instantiation
INCBIN """/build/rk3399/release/m0/rk3399m0.bin""", "rk3399m0_bin", ".sram.incbin"
^
<instantiation>:6:10: error: expected string in '.incbin' directive
 .incbin /build/rk3399/release/m0/rk3399m0pmu.bin
         ^
plat/rockchip/rk3399/drivers/pmu/pmu_fw.S:21:1: note: while in macro instantiation
INCBIN """/build/rk3399/release/m0/rk3399m0pmu.bin""", "rk3399m0pmu_bin", ".pmusram.incbin"
^
"""

Adding quotes around \file in .incbin fixes the clang issue but GCC now
complains:
"""
plat/rockchip/rk3399/drivers/pmu/pmu_fw.S: Assembler messages:
plat/rockchip/rk3399/drivers/pmu/pmu_fw.S:14: Error: junk at end of line, first unrecognized character is `/'
plat/rockchip/rk3399/drivers/pmu/pmu_fw.S:20:  Info: macro invoked from here
plat/rockchip/rk3399/drivers/pmu/pmu_fw.S:14: Error: unable to include `./'
plat/rockchip/rk3399/drivers/pmu/pmu_fw.S:20:  Info: macro invoked from here
plat/rockchip/rk3399/drivers/pmu/pmu_fw.S:14: Error: junk at end of line, first unrecognized character is `/'
plat/rockchip/rk3399/drivers/pmu/pmu_fw.S:21:  Info: macro invoked from here
plat/rockchip/rk3399/drivers/pmu/pmu_fw.S:14: Error: unable to include `./'
plat/rockchip/rk3399/drivers/pmu/pmu_fw.S:21:  Info: macro invoked from here
"""

Considering that the symbol is defined with escaped quotes, it is
probably safe to remove the double quotes around the INBCIN macro
parameter, so let's do that to make both compilers happy.

Signed-off-by: Quentin Schulz <quentin.schulz@cherry.de>
Change-Id: Id18b0341353ffc00e44e2d3c643ccdd05cc20c4f
---
 plat/rockchip/rk3399/drivers/pmu/pmu_fw.S | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/plat/rockchip/rk3399/drivers/pmu/pmu_fw.S b/plat/rockchip/rk3399/drivers/pmu/pmu_fw.S
index 74f569402..db2d4219a 100644
--- a/plat/rockchip/rk3399/drivers/pmu/pmu_fw.S
+++ b/plat/rockchip/rk3399/drivers/pmu/pmu_fw.S
@@ -11,11 +11,11 @@
 	.type \sym, @object
 	.align 4
 \sym :
-	.incbin \file
+	.incbin "\file"
 	.size \sym , .-\sym
 	.global \sym\()_end
 \sym\()_end :
 .endm
 
-INCBIN ""RK3399M0FW"", "rk3399m0_bin", ".sram.incbin"
-INCBIN ""RK3399M0PMUFW"", "rk3399m0pmu_bin", ".pmusram.incbin"
+INCBIN RK3399M0FW, "rk3399m0_bin", ".sram.incbin"
+INCBIN RK3399M0PMUFW, "rk3399m0pmu_bin", ".pmusram.incbin"