Skip to content

Commit b1c1b71

Browse files
jonasjelonekhauke
authored andcommitted
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 <[email protected]> Link: openwrt/openwrt#21248 Signed-off-by: Hauke Mehrtens <[email protected]>
1 parent bdbb4bd commit b1c1b71

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

target/linux/realtek/image/rt-loader/Makefile

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,15 @@
77
#
88
# KERNEL_IMG_IN: The filename of an LZMA compressed kernel. If given the loader
99
# and the kernel will be concatenated (piggy back loading).
10-
# FLASH_ADDR: The kernel address in the ROM. If given, the loeader will be
10+
# FLASH_ADDR: The kernel address in the ROM. If given, the loader will be
1111
# created standalone and search a LZMA compressed uImage on the
1212
# target device starting from this address.
13+
# KERNEL_ADDR: The to-be-used kernel load address to which rt-loader will load
14+
# the kernel and execute it. If not given, rt-loader will use its
15+
# initial run address for this (which is the uImage load address
16+
# when using U-boot images) For non-uImage, this uses an arbitrary
17+
# load address which is independent of rt-loader's initial run
18+
# address.
1319
# KERNEL_IMG_OUT: The filename of the kernel image with the rt-loader prepended.
1420
# If not given it will be created as image.bin into the BUILD_DIR.
1521
# BUILD_DIR: The temporary build dir. If not given it will be set to "build".
@@ -27,6 +33,12 @@
2733
# mv "[email protected]" "$@"
2834
# endef
2935
#
36+
# define Build/rt-loader-non-uImage
37+
# $(MAKE) all clean -C rt-loader CROSS_COMPILE="$(TARGET_CROSS)" \
38+
# KERNEL_ADDR="$(KERNEL_LOADADDR)" KERNEL_IMG_IN="$@" \
39+
# KERNEL_IMG_OUT="[email protected]" BUILD_DIR="[email protected]"
40+
# mv "[email protected]" "$@"
41+
#
3042
# define Build/rt-loader-standalone
3143
# $(MAKE) all clean -C rt-loader CROSS_COMPILE="$(TARGET_CROSS)" \
3244
# FLASH_ADDR=$(FLASH_ADDR) KERNEL_IMG_OUT="[email protected]" BUILD_DIR="[email protected]"
@@ -48,17 +60,22 @@
4860
# KERNEL/rt-loader := rt-loader-standalone
4961
# KERNEL := kernel-bin | append-dtb | rt-compress | uImage lzma
5062
# endef
63+
#
5164

5265
FLASH_ADDR_NONE := 0x0
5366
FLASH_ADDR ?= $(FLASH_ADDR_NONE)
5467

68+
KERNEL_ADDR_NONE := 0x0
69+
KERNEL_ADDR ?= $(KERNEL_ADDR_NONE)
70+
5571
CC := $(CROSS_COMPILE)gcc
5672
LD := $(CROSS_COMPILE)ld
5773
OBJCOPY := $(CROSS_COMPILE)objcopy
5874
OBJDUMP := $(CROSS_COMPILE)objdump
5975

6076
CFLAGS = -fpic -mabicalls -O2 -fno-builtin-printf -Iinclude
6177
CFLAGS += -DFLASH_ADDR=$(FLASH_ADDR)
78+
CFLAGS += -DKERNEL_ADDR=$(KERNEL_ADDR)
6279

6380
ASFLAGS = -fpic -msoft-float -Iinclude
6481

target/linux/realtek/image/rt-loader/src/main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ void main(unsigned long reg_a0, unsigned long reg_a1,
168168
unsigned long reg_a2, unsigned long reg_a3)
169169
{
170170
void *flash_start = (void *)FLASH_ADDR; /* from makefile */
171+
void *kernel_addr = (void *)KERNEL_ADDR; /* from makefile */
171172
entry_func_t fn;
172173

173174
/*
@@ -188,6 +189,8 @@ void main(unsigned long reg_a0, unsigned long reg_a1,
188189
*/
189190
if (flash_start)
190191
load_kernel(flash_start);
192+
else if (kernel_addr)
193+
_kernel_load_addr = kernel_addr;
191194

192195
/*
193196
* Finally extract the attached kernel image to the load address. This is

0 commit comments

Comments
 (0)