Let me answer yout questions later, and just quote my mail, sent to ML.
Hi!
Chuanhong Guo ezt írta (időpont: 2020. ápr. 19., V, 17:42):
Hi!
My original thought on this device is to use a different loader. The first
4MB of SPI-NOR flash on mt7621 is mapped to 0x1fc00000 and lzma
loader can read compressed kernel directly from flash. If the kernel
can be put at a fixed offset in flash, we could compress lzma loader
separately and let u-boot decompress only the loader.
You could take a look at the tp-link-nolzma recipe in:
target/linux/ath79/image/common-tp-link.mk
and see if you could implement a similar solution for mt7621.
Note: You need to fix AR71XX_FLASH_START defined in:
target/linux/ramips/image/lzma-loader/src/loader.c
to 0x1fc00000 for this method to work.I managed to make the loader-okli recipes work on this DIR-860L router.
It's ugly:
target/linux/ramips/image/Makefile | 20 ++++++++++++++++++++
target/linux/ramips/image/lzma-loader/src/loader.c | 2 +-
target/linux/ramips/image/mt7621.mk | 9 ++++++++-
3 files changed, 29 insertions(+), 2 deletions(-)... compared to the my original change:
target/linux/ramips/image/mt7621.mk | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)And it's fragile!
LOADER_FLASH_OFFS
consists of:
- the address of the firmware partition (0x500000)
- loader-okli recipe's "kernel offset" argument (and the compressed size of the loader)
- the 64 byte length header from the Device/seama recipe
- and the
AR71XX_FLASH_START
value inloader.c
And there is a "pad to 32k" step while building the loader separately
and I don't know why it's needed to be 32k - sure it doesn't work with 24k, 16k and below.About the
AR71XX_FLASH_START= 0x10000000
inloader.c
:
This is now 100% DIR-860L specific value. As you can see in the serial log
that the loader finds the kernel at 0xb0501040 which consits of the following components:
0x00000040
: SEAMA header and metadata (see Device/seama)0x00001000
: the 4096 "kernel offset" argument of loader-okli0x00500000
: start adress of "firmware" partition0xa0000000
: KSEG1 addressThe rest (
0x10000000
) isAR71XX_FLASH_START
and other unknown (at lest to me) parts.
So I choseAR71XX_FLASH_START= 0x10000000
.
Sure there is a room to improvement. At least moveAR71XX_FLASH_START
to the board file, and rename!The 4096 byte "kernel offset" is a freely chosen value: it's little bigger than the compressed lzma loader and it is padded to 4k.
Anyway! It works! And it works nicely!
Check the timestamped serial logs below!
The double compressed lzma-loader method needs
- 1.9s for u-boot ("Uncompressing SEAMA linux.lzma ... OK")
- 1.1s for the kernel loader ("Decompressing kernel... done!")
The OKLI method needs:
- no time (0.05s) for u-boot
- 1.4s for the kernel loader
Serial log without this patch:
2020-05-03 20:09:55.367155157: 3: System Boot system code via Flash.
2020-05-03 20:09:55.373933177: ## Booting image at bfc50000 ...
2020-05-03 20:09:57.300117502: addr:80500000
2020-05-03 20:09:57.308441445: We have SEAMA, Image Size = 2490304
2020-05-03 20:09:57.315410096: Verifying Checksum ...
2020-05-03 20:09:59.205312048: Uncompressing SEAMA linux.lzma ... OK
2020-05-03 20:09:59.216341009: ## Transferring control to Linux (at address 00000000) ...
2020-05-03 20:09:59.222500408: ## Giving linux memsize in MB, 128
2020-05-03 20:09:59.224349797:
2020-05-03 20:09:59.226204307: Starting kernel ...
2020-05-03 20:09:59.227824058:
2020-05-03 20:09:59.289356732:
2020-05-03 20:09:59.290995300:
2020-05-03 20:09:59.297258876: OpenWrt kernel loader for MIPS based SoC
2020-05-03 20:09:59.306245212: Copyright (C) 2011 Gabor Juhos
2020-05-03 20:10:00.417134281: Decompressing kernel... done!
2020-05-03 20:10:00.425918694: Starting kernel at 80001000...
2020-05-03 20:10:00.432489649:
2020-05-03 20:10:00.453684838: [ 0.000000] Linux version 5.4.35 (builder@buildhost) (gcc version 8.4.0 (OpenWrt GCC 8.4.0 r13108-87c909e969)) #0 SMP Mon Apr 27 23:10:48 2020
2020-05-03 20:10:00.462322280: [ 0.000000] SoC Type: MediaTek MT7621 ver:1 eco:3
2020-05-03 20:10:00.471916788: [ 0.000000] printk: bootconsole [early0] enabled
2020-05-03 20:10:00.480939230: [ 0.000000] CPU0 revision is: 0001992f (MIPS 1004Kc)
2020-05-03 20:10:00.491938368: [ 0.000000] MIPS: machine is D-Link DIR-860L B1
2020-05-03 20:10:00.503935082: [ 0.000000] Initrd not found or empty - disabling initrdSerial log with OKLI:
2020-05-03 22:36:18.360052605: 3: System Boot system code via Flash.
2020-05-03 22:36:18.365448792: ## Booting image at bfc50000 ...
2020-05-03 22:36:20.299329593: addr:80500000
2020-05-03 22:36:20.320272229: We have SEAMA, Image Size = 2490304
2020-05-03 22:36:20.333914984: Verifying Checksum ...
2020-05-03 22:36:20.381790212: Uncompressing SEAMA linux.lzma ... OK
2020-05-03 22:36:20.397034839: ## Transferring control to Linux (at address 00000000) ...
2020-05-03 22:36:20.413734125: ## Giving linux memsize in MB, 128
2020-05-03 22:36:20.426230940:
2020-05-03 22:36:20.429622961: Starting kernel ...
2020-05-03 22:36:20.437932564:
2020-05-03 22:36:20.440335376:
2020-05-03 22:36:20.444103378:
2020-05-03 22:36:20.451227117: OpenWrt kernel loader for MIPS based SoC
2020-05-03 22:36:20.453709985: Copyright (C) 2011 Gabor Juhos
2020-05-03 22:36:20.491573227: Looking for OpenWrt image... found at 0xb0501040
2020-05-03 22:36:21.845561224: Decompressing kernel... done!
2020-05-03 22:36:21.854485577: Starting kernel at 80001000...
2020-05-03 22:36:21.866553455:
2020-05-03 22:36:21.895973592: [ 0.000000] Linux version 5.4.36 (xabolcs@ut1804) (gcc version 8.4.0 (OpenWrt GCC 8.4.0 r13060-471b8bf8c1)) #0 SMP Sat May 2 23:19:08 2020
2020-05-03 22:36:21.902983786: [ 0.000000] SoC Type: MediaTek MT7621 ver:1 eco:3
2020-05-03 22:36:21.907483498: [ 0.000000] printk: bootconsole [early0] enabled
2020-05-03 22:36:21.912569091: [ 0.000000] CPU0 revision is: 0001992f (MIPS 1004Kc)
2020-05-03 22:36:21.920921080: [ 0.000000] MIPS: machine is D-Link DIR-860L B1
2020-05-03 22:36:21.931420797: [ 0.000000] Initrd not found or empty - disabling initrdI'm glad, that I had success with this OKLI method, but does it really worth it?
Cheers,
Szabolcs--
Regards,
Chuanhong Guo
And the WIP patch is:
target/linux/ramips/image/Makefile | 20 +++++++++++++++++++
.../ramips/image/lzma-loader/src/loader.c | 2 +-
target/linux/ramips/image/mt7621.mk | 9 ++++++++-
3 files changed, 29 insertions(+), 2 deletions(-)
diff --git a/target/linux/ramips/image/Makefile b/target/linux/ramips/image/Makefile
index f93ea8ab2a..76568d7c6c 100644
--- a/target/linux/ramips/image/Makefile
+++ b/target/linux/ramips/image/Makefile
@@ -88,6 +88,26 @@ define Build/loader-kernel
$(call Build/loader-common,LOADER_DATA="$@")
endef
+define Build/loader-okli-compile
+ $(call Build/loader-common,FLASH_OFFS=$(LOADER_FLASH_OFFS) FLASH_MAX=0)
+endef
+
+# Arguments: <output name> <kernel offset> <loader type>
+define Build/loader-okli-with-type
+ dd if=$(KDIR)/loader-$(word 1,$(1)).$(word 3,$(1)) bs=$(word 2,$(1)) conv=sync of="$@.new"
+ cat "$@" >> "$@.new"
+ mv "$@.new" "$@"
+endef
+
+# Arguments: <output name> <kernel offset>
+define Build/loader-okli
+ $(call Build/loader-okli-with-type,$(word 1,$(1)) $(word 2,$(1)) $(LOADER_TYPE))
+endef
+
+define Build/append-loader-okli
+ cat "$(KDIR)/loader-$(word 1,$(1)).$(LOADER_TYPE)" >> "$@"
+endef
+
define Build/relocate-kernel
rm -rf $@.relocate
$(CP) ../../generic/image/relocate $@.relocate
diff --git a/target/linux/ramips/image/lzma-loader/src/loader.c b/target/linux/ramips/image/lzma-loader/src/loader.c
index c73b60b351..8b7756b931 100644
--- a/target/linux/ramips/image/lzma-loader/src/loader.c
+++ b/target/linux/ramips/image/lzma-loader/src/loader.c
@@ -28,7 +28,7 @@
#include "printf.h"
#include "LzmaDecode.h"
-#define AR71XX_FLASH_START 0x1f000000
+#define AR71XX_FLASH_START 0x10000000
#define AR71XX_FLASH_END 0x1fe00000
#define KSEG0 0x80000000
diff --git a/target/linux/ramips/image/mt7621.mk b/target/linux/ramips/image/mt7621.mk
index 88db43cb65..9438e5c09e 100644
--- a/target/linux/ramips/image/mt7621.mk
+++ b/target/linux/ramips/image/mt7621.mk
@@ -221,7 +221,14 @@ define Device/dlink_dir-860l-b1
BLOCKSIZE := 64k
SEAMA_SIGNATURE := wrgac13_dlink.2013gui_dir860lb
LOADER_TYPE := bin
- KERNEL := kernel-bin | append-dtb | lzma | loader-kernel | \
+ LOADER_FLASH_OFFS := 0x501040
+ COMPILE := loader-$(1).bin loader-$(1).lzma
+ COMPILE/loader-$(1).bin := loader-okli-compile
+ COMPILE/loader-$(1).lzma := append-loader-okli $(1) | pad-to 32k | \
+ relocate-kernel | lzma
+ KERNEL := kernel-bin | append-dtb | lzma | uImage lzma -M 0x4f4b4c49 | \
+ loader-okli-with-type $(1) 4096 lzma
+ KERNEL_INITRAMFS := kernel-bin | append-dtb | lzma | loader-kernel | \
relocate-kernel | lzma -a0 | uImage lzma
IMAGE_SIZE := 16064k
DEVICE_VENDOR := D-Link