[openwrt/openwrt] realtek: rt-loader: allow arbitrary kernel load address
LEDE Commits
lede-commits at lists.infradead.org
Mon Dec 22 15:27:18 PST 2025
hauke pushed a commit to openwrt/openwrt.git, branch main:
https://git.openwrt.org/b1c1b713f004a74a0138c6f67851c39ce1038112
commit b1c1b713f004a74a0138c6f67851c39ce1038112
Author: Jonas Jelonek <jelonek.jonas at gmail.com>
AuthorDate: Sun Dec 21 23:13:10 2025 +0000
realtek: rt-loader: allow arbitrary kernel load address
rt-loader currently has two operation modes, piggy-backed and
standalone. In standalone mode, the kernel load address is read from the
uImage in flash. In piggy-backed mode, rt-loader instead uses its
initial run address (aka run address during first run) as the kernel
load address. This is safe and works fine for all devices either using
U-boot or having no issue uploading an image to the default kernel load
address 0x80100000.
To extend usecases, allow to specify a kernel load address when
building rt-loader. In this case, rt-loader uses this address instead of
the address inferred at runtime.
On certain Zyxel devices, this allows to upload and boot an rt-loader
piggy-backed image to an alternate address but keep the default kernel
load address of 0x80100000. BootExt on these devices occupies memory
above and will crash during transfer when this address is used as upload
location. Using this extension, the image can be uploaded to e.g.
0x80300000 and rt-loader will use 0x80100000 as the final load address.
This avoid taking the pain the adjust the load address of the kernel
itself.
Signed-off-by: Jonas Jelonek <jelonek.jonas at gmail.com>
Link: https://github.com/openwrt/openwrt/pull/21248
Signed-off-by: Hauke Mehrtens <hauke at hauke-m.de>
---
target/linux/realtek/image/rt-loader/Makefile | 19 ++++++++++++++++++-
target/linux/realtek/image/rt-loader/src/main.c | 3 +++
2 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/target/linux/realtek/image/rt-loader/Makefile b/target/linux/realtek/image/rt-loader/Makefile
index a21394420b..198506bce8 100644
--- a/target/linux/realtek/image/rt-loader/Makefile
+++ b/target/linux/realtek/image/rt-loader/Makefile
@@ -7,9 +7,15 @@
#
# KERNEL_IMG_IN: The filename of an LZMA compressed kernel. If given the loader
# and the kernel will be concatenated (piggy back loading).
-# FLASH_ADDR: The kernel address in the ROM. If given, the loeader will be
+# FLASH_ADDR: The kernel address in the ROM. If given, the loader will be
# created standalone and search a LZMA compressed uImage on the
# target device starting from this address.
+# KERNEL_ADDR: The to-be-used kernel load address to which rt-loader will load
+# the kernel and execute it. If not given, rt-loader will use its
+# initial run address for this (which is the uImage load address
+# when using U-boot images) For non-uImage, this uses an arbitrary
+# load address which is independent of rt-loader's initial run
+# address.
# KERNEL_IMG_OUT: The filename of the kernel image with the rt-loader prepended.
# If not given it will be created as image.bin into the BUILD_DIR.
# BUILD_DIR: The temporary build dir. If not given it will be set to "build".
@@ -27,6 +33,12 @@
# mv "$@.new" "$@"
# endef
#
+# define Build/rt-loader-non-uImage
+# $(MAKE) all clean -C rt-loader CROSS_COMPILE="$(TARGET_CROSS)" \
+# KERNEL_ADDR="$(KERNEL_LOADADDR)" KERNEL_IMG_IN="$@" \
+# KERNEL_IMG_OUT="$@.new" BUILD_DIR="$@.build"
+# mv "$@.new" "$@"
+#
# define Build/rt-loader-standalone
# $(MAKE) all clean -C rt-loader CROSS_COMPILE="$(TARGET_CROSS)" \
# FLASH_ADDR=$(FLASH_ADDR) KERNEL_IMG_OUT="$@.new" BUILD_DIR="$@.build"
@@ -48,10 +60,14 @@
# KERNEL/rt-loader := rt-loader-standalone
# KERNEL := kernel-bin | append-dtb | rt-compress | uImage lzma
# endef
+#
FLASH_ADDR_NONE := 0x0
FLASH_ADDR ?= $(FLASH_ADDR_NONE)
+KERNEL_ADDR_NONE := 0x0
+KERNEL_ADDR ?= $(KERNEL_ADDR_NONE)
+
CC := $(CROSS_COMPILE)gcc
LD := $(CROSS_COMPILE)ld
OBJCOPY := $(CROSS_COMPILE)objcopy
@@ -59,6 +75,7 @@ OBJDUMP := $(CROSS_COMPILE)objdump
CFLAGS = -fpic -mabicalls -O2 -fno-builtin-printf -Iinclude
CFLAGS += -DFLASH_ADDR=$(FLASH_ADDR)
+CFLAGS += -DKERNEL_ADDR=$(KERNEL_ADDR)
ASFLAGS = -fpic -msoft-float -Iinclude
diff --git a/target/linux/realtek/image/rt-loader/src/main.c b/target/linux/realtek/image/rt-loader/src/main.c
index acdd782ffd..6ea301159f 100644
--- a/target/linux/realtek/image/rt-loader/src/main.c
+++ b/target/linux/realtek/image/rt-loader/src/main.c
@@ -168,6 +168,7 @@ void main(unsigned long reg_a0, unsigned long reg_a1,
unsigned long reg_a2, unsigned long reg_a3)
{
void *flash_start = (void *)FLASH_ADDR; /* from makefile */
+ void *kernel_addr = (void *)KERNEL_ADDR; /* from makefile */
entry_func_t fn;
/*
@@ -188,6 +189,8 @@ void main(unsigned long reg_a0, unsigned long reg_a1,
*/
if (flash_start)
load_kernel(flash_start);
+ else if (kernel_addr)
+ _kernel_load_addr = kernel_addr;
/*
* Finally extract the attached kernel image to the load address. This is
More information about the lede-commits
mailing list