[openwrt/openwrt] realtek: rt-loader bootbase device enhancement

LEDE Commits lede-commits at lists.infradead.org
Sun Jun 29 08:41:24 PDT 2025


robimarko pushed a commit to openwrt/openwrt.git, branch main:
https://git.openwrt.org/978d24ce406b59d906cf9a6b96c33d2b60ee39a8

commit 978d24ce406b59d906cf9a6b96c33d2b60ee39a8
Author: Markus Stockhausen <markus.stockhausen at gmx.de>
AuthorDate: Sat Jun 28 11:39:27 2025 -0400

    realtek: rt-loader bootbase device enhancement
    
    Until now the rt-loader only works on U-Boot driven devices where the
    environment (e.g. coprocessor) is usually setup properly. Devices like
    the ZyXEL GS1920 series use BootBase as start environment and skip
    some of the basic initialization steps. rt-loader will fail in these
    cases. Take care about the CP0 registers.
    
    Additionally enhance the documentation of the printf implementation.
    It was optimized during the different revisions of the initial PR.
    
    Signed-off-by: Markus Stockhausen <markus.stockhausen at gmx.de>
    Link: https://github.com/openwrt/openwrt/pull/19253
    Signed-off-by: Robert Marko <robimarko at gmail.com>
---
 .../linux/realtek/image/rt-loader/include/globals.h   |  7 +++++++
 target/linux/realtek/image/rt-loader/src/board.c      |  6 ++----
 target/linux/realtek/image/rt-loader/src/main.c       |  2 +-
 target/linux/realtek/image/rt-loader/src/startup.S    | 19 +++++++++++++++++++
 4 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/target/linux/realtek/image/rt-loader/include/globals.h b/target/linux/realtek/image/rt-loader/include/globals.h
index 49052b8155..5ed65ba670 100644
--- a/target/linux/realtek/image/rt-loader/include/globals.h
+++ b/target/linux/realtek/image/rt-loader/include/globals.h
@@ -11,6 +11,13 @@
 #define HEAP_SIZE		0x40000
 #define MEMORY_ALIGNMENT	32
 
+#define CP0_COUNT		$9
+#define CP0_COMPARE		$11
+#define CP0_STATUS		$12
+#define CP0_CAUSE		$13
+#define CP0_WATCHLO		$18
+#define CP0_WATCHHI		$19
+
 #define printf(fmt, ...)	npf_pprintf(board_putchar, NULL, fmt, ##__VA_ARGS__)
 #define snprintf		npf_snprintf
 
diff --git a/target/linux/realtek/image/rt-loader/src/board.c b/target/linux/realtek/image/rt-loader/src/board.c
index d6d5865673..c90b86d254 100644
--- a/target/linux/realtek/image/rt-loader/src/board.c
+++ b/target/linux/realtek/image/rt-loader/src/board.c
@@ -21,10 +21,8 @@
 #define RTL93XX_CHIP_INFO_EN		0xa0000
 
 /*
- * board_putchar() is the central function to write to serial console of the device. Some printf
- * libraries (e.g. https://github.com/mpaland/printf) need a fixed function name like _putchar.
- * To keep the original library as is, link the two functions with gcc compiler option
- * -D_putchar=board_putchar
+ * board_putchar() is the central function to write to serial console of the device. This is
+ * linked to printf() and the provider library via globals.h.
  */
 
 void board_putchar(int ch, void *ctx)
diff --git a/target/linux/realtek/image/rt-loader/src/main.c b/target/linux/realtek/image/rt-loader/src/main.c
index 747881ea06..0a53fcef7d 100644
--- a/target/linux/realtek/image/rt-loader/src/main.c
+++ b/target/linux/realtek/image/rt-loader/src/main.c
@@ -69,7 +69,7 @@ void welcome(void)
 
 	board_get_system(system, sizeof(system));
 
-	printf("rt-loader\n");
+	printf("\nrt-loader\n");
 	printf("Running on %s with %dMB\n", system, board_get_memory() >> 20);
 }
 
diff --git a/target/linux/realtek/image/rt-loader/src/startup.S b/target/linux/realtek/image/rt-loader/src/startup.S
index 898f7e1a16..60eb1e480e 100644
--- a/target/linux/realtek/image/rt-loader/src/startup.S
+++ b/target/linux/realtek/image/rt-loader/src/startup.S
@@ -14,6 +14,10 @@
 	add \reg, $t9
 .endm
 
+.macro  _EHB
+	sll     $zero, 3
+.endm
+
 	.section .text
 	.globl _start
 	.ent _start
@@ -28,6 +32,21 @@ _where_am_i:
 	move	$t9, $ra
 	subu	$t9, $t9, 0x8
 
+# This loader might be run in environments that are not properly initialized - e.g. ZyXEL
+# devices with BootBase loader. Be careful and setup the coprocessor registers.
+
+	mtc0	$zero, CP0_WATCHLO
+	mtc0	$zero, CP0_WATCHHI
+	mtc0	$zero, CP0_CAUSE
+	mfc0	$t0, CP0_STATUS
+	li	$t1, 0x1000001f
+	or	$t0, $t1
+	xori	$t0, 0x1f
+	mtc0	$t0, CP0_STATUS
+	_EHB
+	mtc0	$zero, CP0_COUNT
+	mtc0	$zero, CP0_COMPARE
+	_EHB
 
 # Check if this our first run (_kernel_load_addr = 0?)
 




More information about the lede-commits mailing list