[openwrt/openwrt] realtek: rt-loader: enhance is_uimage()
LEDE Commits
lede-commits at lists.infradead.org
Fri Jan 2 09:03:51 PST 2026
robimarko pushed a commit to openwrt/openwrt.git, branch main:
https://git.openwrt.org/8f66b335036f762ad0d4b97afd5a25ce75104f5c
commit 8f66b335036f762ad0d4b97afd5a25ce75104f5c
Author: Markus Stockhausen <markus.stockhausen at gmx.de>
AuthorDate: Tue Dec 30 16:43:37 2025 +0100
realtek: rt-loader: enhance is_uimage()
Until now is_uimage() is only a crc check and the caller
still needs to check other bits of the uimage header. Make
this function what it is meant to be.
Signed-off-by: Markus Stockhausen <markus.stockhausen at gmx.de>
Link: https://github.com/openwrt/openwrt/pull/21332
Signed-off-by: Robert Marko <robimarko at gmail.com>
---
target/linux/realtek/image/rt-loader/src/main.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/target/linux/realtek/image/rt-loader/src/main.c b/target/linux/realtek/image/rt-loader/src/main.c
index 6ea301159f..697ee6723a 100644
--- a/target/linux/realtek/image/rt-loader/src/main.c
+++ b/target/linux/realtek/image/rt-loader/src/main.c
@@ -41,11 +41,20 @@ typedef void (*entry_func_t)(unsigned long reg_a0, unsigned long reg_a1,
unsigned long reg_a2, unsigned long reg_a3);
-static bool is_uimage(void *m)
+static bool is_uimage(unsigned char *m)
{
unsigned int data[UIMAGE_HDR_SIZE / sizeof(int)];
unsigned int image_crc;
+ /*
+ * The most basic way to find a uImage is to lookup the operating system
+ * opcode (for Linux it is 5). Then verify the header checksum. This is
+ * reasonably fast and all other magic value or constants can be avoided.
+ */
+
+ if (m[28] != UIMAGE_OS_LINUX)
+ return false;
+
memcpy(data, m, UIMAGE_HDR_SIZE);
image_crc = data[1];
data[1] = 0;
@@ -127,14 +136,9 @@ void search_image(void **flash_addr, int *flash_size, void **load_addr)
printf("Searching for uImage starting at 0x%08x ...\n", addr);
- /*
- * The most basic way to find a uImage is to lookup the operating system
- * opcode (for Linux it is 5). Then verify the header checksum. This is
- * reasonably fast and all other magic value or constants can be avoided.
- */
*flash_addr = NULL;
for (int i = 0; i < 256 * 1024; i += 4, addr += 4) {
- if ((addr[28] == UIMAGE_OS_LINUX) && is_uimage(addr)) {
+ if (is_uimage(addr)) {
*flash_addr = addr;
*flash_size = *(int *)(addr + 12);
*load_addr = *(void **)(addr + 16);
More information about the lede-commits
mailing list