]> git.ipfire.org Git - thirdparty/openwrt.git/commitdiff
realtek: rt-loader: fix RTL839x/RTL93xx version detection 21994/head
authorMarkus Stockhausen <markus.stockhausen@gmx.de>
Wed, 11 Feb 2026 21:08:17 +0000 (22:08 +0100)
committerRobert Marko <robimarko@gmail.com>
Fri, 13 Feb 2026 11:43:43 +0000 (12:43 +0100)
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@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/21994
Signed-off-by: Robert Marko <robimarko@gmail.com>
target/linux/realtek/image/rt-loader/src/board.c
target/linux/realtek/image/rt-loader/src/main.c

index 881c7cde244ebff4e054e58f71d5fd9292530857..55a98c6ef37bc9478069a00f1f5fe27b0c872325 100644 (file)
@@ -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);
 }
 
 /*
index 80c8ba85d0915a12bbaf2741858b32561fba9299..51f28d839ac764b5cb9ad34b35d30a4328d8ccea 100644 (file)
@@ -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)