summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonas Jelonek2025-12-21 23:13:10 +0000
committerHauke Mehrtens2025-12-22 23:26:34 +0000
commitb1c1b713f004a74a0138c6f67851c39ce1038112 (patch)
tree650438ab11a051e5e2b8131078580ea6b81f3296
parentbdbb4bdfa030add96abef59b43adadf1050d678d (diff)
downloadopenwrt-b1c1b713f004a74a0138c6f67851c39ce1038112.tar.gz
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@gmail.com> Link: https://github.com/openwrt/openwrt/pull/21248 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
-rw-r--r--target/linux/realtek/image/rt-loader/Makefile19
-rw-r--r--target/linux/realtek/image/rt-loader/src/main.c3
2 files changed, 21 insertions, 1 deletions
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