[openwrt/openwrt] realtek: rt-loader: fix RTL839x/RTL93xx version detection

LEDE Commits lede-commits at lists.infradead.org
Fri Feb 13 03:43:47 PST 2026


robimarko pushed a commit to openwrt/openwrt.git, branch main:
https://git.openwrt.org/086f1d347811e63487759ced90c5bc5985c86eda

commit 086f1d347811e63487759ced90c5bc5985c86eda
Author: Markus Stockhausen <markus.stockhausen at gmx.de>
AuthorDate: Wed Feb 11 22:08:17 2026 +0100

    realtek: rt-loader: fix RTL839x/RTL93xx version detection
    
    There is a misunderstanding of the chip version detection in the
    rt-loader. For all SoCs the data is gathered from the registers
    MODEL_NAME_INFO and CHIP_INFO. Sadly the bits are shuffled around
    with each hardware. Currently the loader gathers the wrong bits
    for RTL839x and RTL93xx. Fix that.
    
    While we are here write the if statements vice versa for better
    readability and give some variables better names. Align the
    ouput with that from the kernel.
    
    Fixes: ccbff8b ("realtek: add rt-loader (runtime loader)"
    Signed-off-by: Markus Stockhausen <markus.stockhausen at gmx.de>
    Link: https://github.com/openwrt/openwrt/pull/21994
    Signed-off-by: Robert Marko <robimarko at gmail.com>
---
 target/linux/realtek/image/rt-loader/src/board.c | 37 ++++++++++++------------
 target/linux/realtek/image/rt-loader/src/main.c  |  2 +-
 2 files changed, 19 insertions(+), 20 deletions(-)

diff --git a/target/linux/realtek/image/rt-loader/src/board.c b/target/linux/realtek/image/rt-loader/src/board.c
index 881c7cde24..55a98c6ef3 100644
--- a/target/linux/realtek/image/rt-loader/src/board.c
+++ b/target/linux/realtek/image/rt-loader/src/board.c
@@ -65,42 +65,41 @@ unsigned int board_get_memory(void)
 void board_get_system(char *buffer, int len)
 {
 	unsigned int chip_id, model_id, model_version, chip_version;
-	unsigned int reg, val, act;
+	unsigned int reg, act, minfo, cinfo;
 
 	act = RTL93XX_CHIP_INFO_EN;
 	reg = RTL93XX_MODEL_NAME_INFO_REG;
-	val = ioread32(reg);
+	minfo = ioread32(reg);
 
-	if ((val & 0xffec0000) == 0x93000000)
+	if ((minfo & 0xffec0000) == 0x93000000)
 		goto found;
 
 	act = RTL83XX_CHIP_INFO_EN;
 	reg = RTL839X_MODEL_NAME_INFO_REG;
-	val = ioread32(reg);
-	if ((val & 0xfff80000) == 0x83900000)
+	minfo = ioread32(reg);
+	if ((minfo & 0xfff80000) == 0x83900000)
 		goto found;
 
 	iowrite32(0x3, RTL838X_INT_RW_CTRL_REG);
 	reg = RTL838X_MODEL_NAME_INFO_REG;
-	val = ioread32(reg);
+	minfo = ioread32(reg);
 found:
-	model_id = val >> 16;
-	model_version = (val >> 11) & 0x1f;
-
 	iowrite32(act, reg + 4);
-	val = ioread32(reg + 4);
-	chip_id = val & 0xffff;
+	cinfo = ioread32(reg + 4);
+
+	model_id = minfo >> 16;
+	model_version = (minfo >> 11) & 0x1f;
+	chip_id = cinfo & 0xffff;
 
-	if (model_id < 0x8390)
-		chip_version = (val >> 16) & 0x1f;
-	else if (model_id < 0x9300)
-		chip_version = ((val >> 16) & 0x1f) + 1;
+	if (model_id >= 0x9300)
+		chip_version = minfo & 0xf;
+	else if (model_id >= 0x8390)
+		chip_version = (minfo >> 1) & 0x1f;
 	else
-		chip_version = ((val >> 28) & 0x0f) + 1;
+		chip_version = ((cinfo >> 16) & 0x1f) - 1;
 
-	snprintf(buffer, len, "RTL%04X%c (chip id %04x%c)",
-		 model_id, model_version ? model_version + 64 : 0,
-		 chip_id, chip_version ? chip_version + 64 : 0);
+	snprintf(buffer, len, "RTL%04X%c rev %c (%04x)", model_id, 
+		 model_version ? model_version + 64 : 0, chip_version + 65, chip_id);
 }
 
 /*
diff --git a/target/linux/realtek/image/rt-loader/src/main.c b/target/linux/realtek/image/rt-loader/src/main.c
index 80c8ba85d0..51f28d839a 100644
--- a/target/linux/realtek/image/rt-loader/src/main.c
+++ b/target/linux/realtek/image/rt-loader/src/main.c
@@ -90,7 +90,7 @@ void welcome(void)
 	board_get_system(system, sizeof(system));
 
 	printf("\nrt-loader\n");
-	printf("Running on %s with %dMB\n", system, board_get_memory() >> 20);
+	printf("Running on %s SoC with %d MB\n", system, board_get_memory() >> 20);
 }
 
 void decompress_error(char *x)




More information about the lede-commits mailing list