[PATCH 2/7] firmware: fw_base.ldS: add .fw_dynamic_info output section before .bss

Zong Li zong.li at sifive.com
Mon Jul 6 20:39:49 PDT 2026


Add a dedicated .fw_dynamic_info output section placed right before the
.bss section. Because .bss is NOBITS and gets dropped by objcopy when
generating the flat binary, any data placed after it would not be part
of the file. Putting .fw_dynamic_info before .bss makes it the last
PROGBITS content and therefore the tail of the .bin image.

This section is collected with KEEP() so --gc-sections never discards
it. The whole block is wrapped in #ifdef FW_DYNAMIC_APPEND, which is
defined only by fw_dynamic_append.elf.ldS before it includes this file.
For FW_DYNAMIC, FW_JUMP and FW_PAYLOAD the section does not exist at
all, so their layout is byte-for-byte unchanged.

Signed-off-by: Zong Li <zong.li at sifive.com>
---
 firmware/fw_base.ldS | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/firmware/fw_base.ldS b/firmware/fw_base.ldS
index 12c7a844..6ae6fe62 100644
--- a/firmware/fw_base.ldS
+++ b/firmware/fw_base.ldS
@@ -82,6 +82,30 @@
 		PROVIDE(_data_end = .);
 	}
 
+#ifdef FW_DYNAMIC_APPEND
+	/*
+	 * Appended fw_dynamic_info used by the FW_DYNAMIC_APPEND firmware type.
+	 *
+	 * This MUST stay immediately before .bss: .bss is a NOBITS section and
+	 * is stripped by 'objcopy -O binary', so it is not reflected in the
+	 * flat binary file size.
+	 * Placing the structure here makes it the last PROGBITS content,
+	 * i.e. it sits exactly at the tail of the .bin file,
+	 * so the previous booting stage can locate it from the image size.
+	 *
+	 * The whole section is compiled in only for FW_DYNAMIC_APPEND (the
+	 * enclosing #ifdef is defined in fw_dynamic_append.elf.ldS before this
+	 * file is included).
+	 */
+	.fw_dynamic_info :
+	{
+		PROVIDE(_fw_dynamic_info_start = .);
+		KEEP(*(.fw_dynamic_info))
+		. = ALIGN(8);
+		PROVIDE(_fw_dynamic_info_end = .);
+	}
+#endif
+
 	. = ALIGN(0x1000); /* Ensure next section is page aligned */
 
 	.bss :
-- 
2.43.7




More information about the opensbi mailing list