[OpenWrt-Devel] [RFC, PATCH] ramips: mt7621: use OKLI lzma-loader for D-Link DIR-860L B1

2020-05-03 Thread Szabolcs Hubai
In commit ce1957100411b0a751d6431d36def9c28048b4dc this device started
using lzma-loader to enable booting bigger kernels from flash.

Chuanhong Guo noted [0], 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.

This patch use this OKLI method for sysupgrade and factory images.

[0]
http://lists.infradead.org/pipermail/openwrt-devel/2020-April/022926.html

Signed-off-by: Szabolcs Hubai 
---
 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:   
+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:  
+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 0x1f00
+#define AR71XX_FLASH_START 0x1000
 #define AR71XX_FLASH_END   0x1fe0
 
 #define KSEG0  0x8000
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
-- 
2.17.1


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [RFC, PATCH] ramips: mt7621: use OKLI lzma-loader for D-Link DIR-860L B1 (was: Re: [PATCH 2/2] ramips: mt7621: use lzma-loader for D-Link DIR-860L)

2020-05-03 Thread Szabolcs Hubai

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 0x1fc0 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 0x1fc0 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 (0x50)
- 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 in loader.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= 0x1000 in loader.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:
- 0x0040: SEAMA header and metadata (see Device/seama)
- 0x1000: the 4096 "kernel offset" argument of loader-okli
- 0x0050: start adress of "firmware" partition
- 0xa000: KSEG1 address

The rest (0x1000) is AR71XX_FLASH_START and other unknown (at lest to me) 
parts.
So I chose AR71XX_FLASH_START= 0x1000.
Sure there is a room to improvement. At least move AR71XX_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! :D 

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 bfc5 ...
2020-05-03 20:09:57.300117502: addr:8050
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 
) ...
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.00] 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.00] SoC Type: MediaTek MT7621 ver:1 eco:3
2020-05-03 20:10:00.471916788: [ 0.00] printk: bootconsole [early0] enabled
2020-05-03 20:10:00.480939230: [ 0.00] CPU0 revision is: 0001992f (MIPS 
1004Kc)
2020-05-03 20:10:00.491938368: [ 0.00] MIPS: machine is D-Link DIR-860L B1
2020-05-03 20:10:00.503935082: [ 0.00] Initrd not found or empty - 
disabling initrd


Serial 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 bfc5 ...
2020-05-03 22:36:20.299329593: addr:8050
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 
) ...
2020-05-03 22:36:20.413734125: ## Giving linux memsize in MB, 128
2020-05-03 22:36:20.