]> git.ipfire.org Git - thirdparty/openwrt.git/commitdiff
realtek: rt-loader bootbase device enhancement 19253/head
authorMarkus Stockhausen <markus.stockhausen@gmx.de>
Sat, 28 Jun 2025 15:39:27 +0000 (11:39 -0400)
committerRobert Marko <robimarko@gmail.com>
Sun, 29 Jun 2025 15:41:20 +0000 (17:41 +0200)
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@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/19253
Signed-off-by: Robert Marko <robimarko@gmail.com>
target/linux/realtek/image/rt-loader/include/globals.h
target/linux/realtek/image/rt-loader/src/board.c
target/linux/realtek/image/rt-loader/src/main.c
target/linux/realtek/image/rt-loader/src/startup.S

index 49052b81559b03a7c586d0f9e5ff1e2543062255..5ed65ba67093a71014c36590903262cd79cfab5e 100644 (file)
 #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
 
index d6d5865673d1a7fde46c0d82b8d0e996e6756ddf..c90b86d2542b30c8f1d749499c239efbd8481576 100644 (file)
 #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)
index 747881ea0671b58efd10f4e653190c0150cc0de5..0a53fcef7dd28310eb7a9356019bf197140a96ea 100644 (file)
@@ -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);
 }
 
index 898f7e1a163be61e7937dba9236bf7e86388a25e..60eb1e480ee35ceca9987d21b6f85a6ebe77f5a2 100644 (file)
        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?)