diff mbox series

[v3,3/5] bcm53xx: Add support for D-Link DIR-890L

Message ID 20230619063618.2595217-4-linus.walleij@linaro.org
State Accepted
Delegated to: Rafał Miłecki
Headers show
Series bcm53xx: Support D-Link DIR-890L | expand

Commit Message

Linus Walleij June 19, 2023, 6:36 a.m. UTC
The DIR-890L is very similar to DIR-885L, but has both USB2
and USB3. The signature for the wrgac36 board was copied from
DD-Wrt.

The DIR-890L bootstrap will only load the first 2 MB after
the SEAMA header in the NAND flash, uncompress it with LZMA
and execute it. Since the compressed kernel will not fit in
2 MB we have a problem. Solve this by putting a LZMA
compressed U-Boot into the first 128 KB of the flash
followed by the kernel. The bootstrap will then uncompress
and execute U-Boot and then we let U-Boot read the kernel
from flash and execute it.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
ChangeLog v2->v3:
- Rebased on master
- Test with kernel v6.1
ChangeLog v1->v2:
- Rebased on master
---
 .../base-files/etc/uci-defaults/09_fix_crc    |  3 ++-
 .../base-files/lib/upgrade/platform.sh        |  1 +
 target/linux/bcm53xx/image/Makefile           | 21 +++++++++++++++++++
 3 files changed, 24 insertions(+), 1 deletion(-)

Comments

Arınç ÜNAL Sept. 2, 2023, 1:46 p.m. UTC | #1
On 19.06.2023 09:36, Linus Walleij wrote:
> 
> The DIR-890L is very similar to DIR-885L, but has both USB2
> and USB3. The signature for the wrgac36 board was copied from
> DD-Wrt.
> 
> The DIR-890L bootstrap will only load the first 2 MB after
> the SEAMA header in the NAND flash, uncompress it with LZMA
> and execute it. Since the compressed kernel will not fit in
> 2 MB we have a problem. Solve this by putting a LZMA
> compressed U-Boot into the first 128 KB of the flash
> followed by the kernel. The bootstrap will then uncompress
> and execute U-Boot and then we let U-Boot read the kernel
> from flash and execute it.
> 
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> ---
> ChangeLog v2->v3:
> - Rebased on master
> - Test with kernel v6.1
> ChangeLog v1->v2:
> - Rebased on master
> ---
>   .../base-files/etc/uci-defaults/09_fix_crc    |  3 ++-
>   .../base-files/lib/upgrade/platform.sh        |  1 +
>   target/linux/bcm53xx/image/Makefile           | 21 +++++++++++++++++++
>   3 files changed, 24 insertions(+), 1 deletion(-)
> 
> diff --git a/target/linux/bcm53xx/base-files/etc/uci-defaults/09_fix_crc b/target/linux/bcm53xx/base-files/etc/uci-defaults/09_fix_crc
> index 89ce8970d75a..c39625b86536 100644
> --- a/target/linux/bcm53xx/base-files/etc/uci-defaults/09_fix_crc
> +++ b/target/linux/bcm53xx/base-files/etc/uci-defaults/09_fix_crc
> @@ -13,7 +13,8 @@ fixseama() {
>   }
>   
>   case "$board" in
> -dlink,dir-885l)
> +dlink,dir-885l | \
> +dlink,dir-890l)
>   	fixseama
>   	;;
>   *)
> diff --git a/target/linux/bcm53xx/base-files/lib/upgrade/platform.sh b/target/linux/bcm53xx/base-files/lib/upgrade/platform.sh
> index 3ebde77d3f94..958a9fd247ab 100644
> --- a/target/linux/bcm53xx/base-files/lib/upgrade/platform.sh
> +++ b/target/linux/bcm53xx/base-files/lib/upgrade/platform.sh
> @@ -37,6 +37,7 @@ platform_expected_image() {
>   
>   	case "$machine" in
>   		"dlink,dir-885l")	echo "seamaseal wrgac42_dlink.2015_dir885l"; return;;
> +		"dlink,dir-890l")	echo "seamaseal wrgac36_dlink.2013gui_dir890"; return;;
>   		"luxul,abr-4500-v1")	echo "lxl ABR-4500"; return;;
>   		"luxul,xap-810-v1")	echo "lxl XAP-810"; return;;
>   		"luxul,xap-1410v1")	echo "lxl XAP-1410"; return;;
> diff --git a/target/linux/bcm53xx/image/Makefile b/target/linux/bcm53xx/image/Makefile
> index defa68e59f98..eb9f27c91eb5 100644
> --- a/target/linux/bcm53xx/image/Makefile
> +++ b/target/linux/bcm53xx/image/Makefile
> @@ -88,6 +88,12 @@ define Build/luxul-lxl
>   	mv $@.new $@
>   endef
>   
> +# Outputs a lzma compressed U-Boot that start at 0x00008000
> +# just like the D-Link boot loaders expect
> +define Build/dlink-uboot-bin
> +	$(STAGING_DIR_HOST)/bin/lzma e $(STAGING_DIR_IMAGE)/$(DEVICE_NAME)-u-boot.bin -d16 $@
> +endef

I see this patch is applied. $(STAGING_DIR_IMAGE)/$(DEVICE_NAME)-u-boot.bin
won't be created unless PACKAGE_u-boot-dir-890l is enabled. For some
reason, regardless of which device is selected on menuconfig, the OpenWrt
SDK will compile an image for every device on the target. So if any device
other than D-Link DIR-890L is selected on menuconfig,
PACKAGE_u-boot-dir-890l won't be enabled. Therefore, the compilation
process will fail while preparing an image for DIR-890L.

/mnt/Work/openwrt/staging_dir/host/bin/lzma e /mnt/Work/openwrt/staging_dir/target-arm_cortex-a9_musl_eabi/image/dlink_dir-890l-u-boot.bin -d16 /mnt/Work/openwrt/build_dir/target-arm_cortex-a9_musl_eabi/linux-bcm53xx_generic/dlink_dir-890l-kernel.bin

Error: can not open input file /mnt/Work/openwrt/staging_dir/target-arm_cortex-a9_musl_eabi/image/dlink_dir-890l-u-boot.bin
make[5]: *** [Makefile:536: /mnt/Work/openwrt/build_dir/target-arm_cortex-a9_musl_eabi/linux-bcm53xx_generic/dlink_dir-890l-kernel.bin] Error 1
make[5]: Leaving directory '/mnt/Work/openwrt/target/linux/bcm53xx/image'
make[4]: *** [Makefile:30: install] Error 2
make[4]: Leaving directory '/mnt/Work/openwrt/target/linux/bcm53xx'
make[3]: *** [Makefile:11: install] Error 2
make[3]: Leaving directory '/mnt/Work/openwrt/target/linux'
time: target/linux/install#16.33#2.41#12.48
     ERROR: target/linux failed to build.
make[2]: *** [target/Makefile:30: target/linux/install] Error 1
make[2]: Leaving directory '/mnt/Work/openwrt'
make[1]: *** [target/Makefile:24: /mnt/Work/openwrt/staging_dir/target-arm_cortex-a9_musl_eabi/stamp/.target_install] Error 2
make[1]: Leaving directory '/mnt/Work/openwrt'
make: *** [/mnt/Work/openwrt/include/toplevel.mk:232: world] Error 2

Arınç

> +
>   define Build/seama-nand
>   	# Seama entity
>   	$(STAGING_DIR_HOST)/bin/oseama \
> @@ -266,6 +272,21 @@ define Device/dlink_dir-885l
>   endef
>   TARGET_DEVICES += dlink_dir-885l
>   
> +define Device/dlink_dir-890l
> +  DEVICE_VENDOR := D-Link
> +  DEVICE_MODEL := DIR-890L
> +  DEVICE_PACKAGES := $(BRCMFMAC_43602A1) $(USB2_PACKAGES) $(USB3_PACKAGES)
> +  # Layout: U-boot (128kb max) followed by kernel and appended DTB.
> +  # This is done because the boot loader will only read the first 2 MB
> +  # from the flash and decompress the LZMA it finds there after the
> +  # SEAMA header. Since the compressed kernel will not fit in 2 MB,
> +  # we put U-Boot there and let U-Boot read and execute the kernel.
> +  KERNEL := dlink-uboot-bin | pad-to 128k | append-kernel | append-dtb
> +  $(Device/dlink)
> +  SIGNATURE := wrgac36_dlink.2013gui_dir890
> +endef
> +TARGET_DEVICES += dlink_dir-890l
> +
>   define Device/dlink_dwl-8610ap
>     DEVICE_VENDOR := D-Link
>     DEVICE_MODEL := DWL-8610AP
Linus Walleij Sept. 2, 2023, 4:36 p.m. UTC | #2
On Sat, Sep 2, 2023 at 3:46 PM Arınç ÜNAL <arinc.unal@arinc9.com> wrote:

> > +# Outputs a lzma compressed U-Boot that start at 0x00008000
> > +# just like the D-Link boot loaders expect
> > +define Build/dlink-uboot-bin
> > +     $(STAGING_DIR_HOST)/bin/lzma e $(STAGING_DIR_IMAGE)/$(DEVICE_NAME)-u-boot.bin -d16 $@
> > +endef
>
> I see this patch is applied. $(STAGING_DIR_IMAGE)/$(DEVICE_NAME)-u-boot.bin
> won't be created unless PACKAGE_u-boot-dir-890l is enabled.

I'm sorry if I get anything wrong here, default-selecting packages
for targets isn't my strong game and sometime I don't know if I
can ever get it right ...

package/boot/uboot-bcm53xx/Makefile looks like this:

define U-Boot/dir-890l
  NAME:=D-Link DIR-890L
  BUILD_DEVICES:=dlink_dir-890l
endef

So my understanding of was BUILD_DEVICES that this will make
sure the package is built for the listed device(s) and thus
$(STAGING_DIR_IMAGE)/$(DEVICE_NAME)-u-boot.bin
will be there. But I guess it doesn't work as expected.

> For some
> reason, regardless of which device is selected on menuconfig, the OpenWrt
> SDK will compile an image for every device on the target. So if any device
> other than D-Link DIR-890L is selected on menuconfig,
> PACKAGE_u-boot-dir-890l won't be enabled. Therefore, the compilation
> process will fail while preparing an image for DIR-890L.

I suppose this oneliner is needed:

diff --git a/target/linux/bcm53xx/image/Makefile
b/target/linux/bcm53xx/image/Makefile
index 39b7efbef789..9483812facca 100644
--- a/target/linux/bcm53xx/image/Makefile
+++ b/target/linux/bcm53xx/image/Makefile
@@ -283,7 +283,7 @@ TARGET_DEVICES += dlink_dir-885l
 define Device/dlink_dir-890l
   DEVICE_VENDOR := D-Link
   DEVICE_MODEL := DIR-890L
-  DEVICE_PACKAGES := $(BRCMFMAC_43602A1) $(USB2_PACKAGES) $(USB3_PACKAGES)
+  DEVICE_PACKAGES := uboot-bcm53xx $(BRCMFMAC_43602A1)
$(USB2_PACKAGES) $(USB3_PACKAGES)
   # Layout: U-boot (128kb max) followed by kernel and appended DTB.
   # This is done because the boot loader will only read the first 2 MB
   # from the flash and decompress the LZMA it finds there after the

I sent a patch!

Yours,
Linus Walleij
diff mbox series

Patch

diff --git a/target/linux/bcm53xx/base-files/etc/uci-defaults/09_fix_crc b/target/linux/bcm53xx/base-files/etc/uci-defaults/09_fix_crc
index 89ce8970d75a..c39625b86536 100644
--- a/target/linux/bcm53xx/base-files/etc/uci-defaults/09_fix_crc
+++ b/target/linux/bcm53xx/base-files/etc/uci-defaults/09_fix_crc
@@ -13,7 +13,8 @@  fixseama() {
 }
 
 case "$board" in
-dlink,dir-885l)
+dlink,dir-885l | \
+dlink,dir-890l)
 	fixseama
 	;;
 *)
diff --git a/target/linux/bcm53xx/base-files/lib/upgrade/platform.sh b/target/linux/bcm53xx/base-files/lib/upgrade/platform.sh
index 3ebde77d3f94..958a9fd247ab 100644
--- a/target/linux/bcm53xx/base-files/lib/upgrade/platform.sh
+++ b/target/linux/bcm53xx/base-files/lib/upgrade/platform.sh
@@ -37,6 +37,7 @@  platform_expected_image() {
 
 	case "$machine" in
 		"dlink,dir-885l")	echo "seamaseal wrgac42_dlink.2015_dir885l"; return;;
+		"dlink,dir-890l")	echo "seamaseal wrgac36_dlink.2013gui_dir890"; return;;
 		"luxul,abr-4500-v1")	echo "lxl ABR-4500"; return;;
 		"luxul,xap-810-v1")	echo "lxl XAP-810"; return;;
 		"luxul,xap-1410v1")	echo "lxl XAP-1410"; return;;
diff --git a/target/linux/bcm53xx/image/Makefile b/target/linux/bcm53xx/image/Makefile
index defa68e59f98..eb9f27c91eb5 100644
--- a/target/linux/bcm53xx/image/Makefile
+++ b/target/linux/bcm53xx/image/Makefile
@@ -88,6 +88,12 @@  define Build/luxul-lxl
 	mv $@.new $@
 endef
 
+# Outputs a lzma compressed U-Boot that start at 0x00008000
+# just like the D-Link boot loaders expect
+define Build/dlink-uboot-bin
+	$(STAGING_DIR_HOST)/bin/lzma e $(STAGING_DIR_IMAGE)/$(DEVICE_NAME)-u-boot.bin -d16 $@
+endef
+
 define Build/seama-nand
 	# Seama entity
 	$(STAGING_DIR_HOST)/bin/oseama \
@@ -266,6 +272,21 @@  define Device/dlink_dir-885l
 endef
 TARGET_DEVICES += dlink_dir-885l
 
+define Device/dlink_dir-890l
+  DEVICE_VENDOR := D-Link
+  DEVICE_MODEL := DIR-890L
+  DEVICE_PACKAGES := $(BRCMFMAC_43602A1) $(USB2_PACKAGES) $(USB3_PACKAGES)
+  # Layout: U-boot (128kb max) followed by kernel and appended DTB.
+  # This is done because the boot loader will only read the first 2 MB
+  # from the flash and decompress the LZMA it finds there after the
+  # SEAMA header. Since the compressed kernel will not fit in 2 MB,
+  # we put U-Boot there and let U-Boot read and execute the kernel.
+  KERNEL := dlink-uboot-bin | pad-to 128k | append-kernel | append-dtb
+  $(Device/dlink)
+  SIGNATURE := wrgac36_dlink.2013gui_dir890
+endef
+TARGET_DEVICES += dlink_dir-890l
+
 define Device/dlink_dwl-8610ap
   DEVICE_VENDOR := D-Link
   DEVICE_MODEL := DWL-8610AP