Skip to content

Commit

Permalink
mediatek: mt7622: modernize Linksys E8450 / Belkin RT3200 UBI build
Browse files Browse the repository at this point in the history
Move fip and factory into UBI static volumes.
Use fitblk instead of partition parser.

 !! RUN INSTALLER FIRST !!
Existing users of previous OpenWrt releases or snapshot builds will
have to **re-run the updated installer** before upgrading to firmware
after this commit.
DO NOT flash or run even just the initramfs image unless you have
run the updated installer which moves the content of the 'factory'
partition into a UBI volume.

tl;dr: DON'T USE YET!

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
  • Loading branch information
dangowrt committed Feb 15, 2024
1 parent 41c0531 commit 6aec3c7
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 45 deletions.
4 changes: 2 additions & 2 deletions package/boot/uboot-mediatek/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ define U-Boot/mt7622_linksys_e8450
BUILD_DEVICES:=linksys_e8450-ubi
BUILD_SUBTARGET:=mt7622
UBOOT_IMAGE:=u-boot.fip
BL2_BOOTDEV:=snand
BL2_BOOTDEV:=snand-ubi
BL2_DDRBLOB:=1
DEPENDS:=+trusted-firmware-a-mt7622-snand-1ddr
DEPENDS:=+trusted-firmware-a-mt7622-snand-ubi-1ddr
endef

define U-Boot/mt7622_bananapi_bpi-r64-emmc
Expand Down
46 changes: 30 additions & 16 deletions package/boot/uboot-mediatek/patches/410-add-linksys-e8450.patch
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- /dev/null
+++ b/configs/mt7622_linksys_e8450_defconfig
@@ -0,0 +1,141 @@
@@ -0,0 +1,140 @@
+CONFIG_ARM=y
+CONFIG_POSITION_INDEPENDENT=y
+CONFIG_ARCH_MEDIATEK=y
Expand All @@ -17,7 +17,6 @@
+CONFIG_DEBUG_UART_CLOCK=25000000
+CONFIG_DEFAULT_DEVICE_TREE="mt7622-linksys-e8450-ubi"
+CONFIG_DEBUG_UART=y
+CONFIG_MTDPARTS_DEFAULT="mtdparts=spi-nand0:512k(bl2),1280k(fip),1024k(factory),256k(reserved),-(ubi)"
+CONFIG_SMBIOS_PRODUCT_NAME=""
+CONFIG_AUTOBOOT_KEYED=y
+CONFIG_BOOTDELAY=30
Expand Down Expand Up @@ -144,7 +143,7 @@
+CONFIG_USB_STORAGE=y
--- /dev/null
+++ b/arch/arm/dts/mt7622-linksys-e8450-ubi.dts
@@ -0,0 +1,197 @@
@@ -0,0 +1,214 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2019 MediaTek Inc.
Expand Down Expand Up @@ -307,6 +306,23 @@
+ pinctrl-0 = <&snfi_pins>;
+ status = "okay";
+ quad-spi;
+
+ partitions {
+ compatible = "fixed-partitions";
+ #address-cells = <1>;
+ #size-cells = <1>;
+
+ partition@0 {
+ label = "bl2";
+ reg = <0x0 0x80000>;
+ };
+
+ partition@80000 {
+ label = "ubi";
+ reg = <0x80000 0x7f80000>;
+ compatible = "linux,ubi";
+ };
+ };
+};
+
+&uart0 {
Expand Down Expand Up @@ -354,8 +370,8 @@
mt7981-rfb.dtb \
--- /dev/null
+++ b/linksys_e8450_env
@@ -0,0 +1,57 @@
+ethaddr_factory=mtd read spi-nand0 0x40080000 0x220000 0x20000 && env readmem -b ethaddr 0x4009fff4 0x6 ; setenv ethaddr_factory
@@ -0,0 +1,54 @@
+ethaddr_factory=ubi read 0x40080000 factory && env readmem -b ethaddr 0x400ffff4 0x6 ; setenv ethaddr_factory
+ipaddr=192.168.1.1
+serverip=192.168.1.254
+loadaddr=0x48000000
Expand Down Expand Up @@ -387,28 +403,26 @@
+boot_default=if env exists flag_recover ; then else run bootcmd ; fi ; run boot_recovery ; setenv replacevol 1 ; run boot_tftp_forever
+boot_production=led $bootled_pwr on ; run ubi_read_production && bootm $loadaddr#$bootconf ; led $bootled_pwr off
+boot_recovery=led $bootled_rec on ; run ubi_read_recovery ; bootm $loadaddr#$bootconf ; ubi remove recovery ; led $bootled_rec off
+boot_serial_write_bl2=loadx $loadaddr 115200 && run boot_write_bl2
+boot_serial_write_fip=loadx $loadaddr 115200 && run boot_write_fip
+boot_serial_write_bl2=loadx $loadaddr 115200 && run snand_write_bl2
+boot_serial_write_fip=loadx $loadaddr 115200 && run ubi_write_fip
+boot_tftp=tftpboot $loadaddr $bootfile && bootm $loadaddr#$bootconf
+boot_tftp_forever=led $bootled_rec on ; while true ; do run boot_tftp_recovery ; sleep 1 ; done
+boot_tftp_production=tftpboot $loadaddr $bootfile_upg && iminfo $loadaddr && ubi part ubi && run ubi_write_production ubi_prepare_rootfs ; if env exists noboot ; then else bootm $loadaddr#$bootconf ; fi
+boot_tftp_recovery=tftpboot $loadaddr $bootfile && iminfo $loadaddr && ubi part ubi && run ubi_write_recovery ; if env exists noboot ; then else bootm $loadaddr#$bootconf ; fi
+boot_tftp_write_bl2=tftpboot $loadaddr $bootfile_bl2 && run boot_write_bl2
+boot_tftp_write_fip=tftpboot $loadaddr $bootfile_fip && run boot_write_fip
+boot_tftp_write_bl2=tftpboot $loadaddr $bootfile_bl2 && run snand_write_bl2
+boot_tftp_write_fip=tftpboot $loadaddr $bootfile_fip && run ubi_write_fip
+boot_ubi=ubi part ubi && run boot_production ; run boot_recovery
+boot_write_bl2=mtd erase bl2 && mtd write spi-nand0 $loadaddr 0x0 0x20000 && mtd write spi-nand0 $loadaddr 0x20000 0x20000 && mtd write spi-nand0 $loadaddr 0x40000 0x20000 && mtd write spi-nand0 $loadaddr 0x60000 0x20000
+boot_write_fip=mtd erase fip && mtd write fip $loadaddr
+check_ubi=ubi part ubi || run ubi_format
+reset_factory=mw $loadaddr 0x0 0x100000 ; ubi part ubi ; ubi write $loadaddr ubootenv 0x100000 ; ubi write $loadaddr ubootenv2 0x100000 ; ubi remove rootfs_data
+ubi_format=ubi detach ; mtd erase ubi && ubi part ubi ; reset
+snand_write_bl2=mtd erase bl2 && mtd write spi-nand0 $loadaddr 0x0 0x20000 && mtd write spi-nand0 $loadaddr 0x20000 0x20000 && mtd write spi-nand0 $loadaddr 0x40000 0x20000 && mtd write spi-nand0 $loadaddr 0x60000 0x20000
+reset_factory=mw $loadaddr 0xff 0x1f000 ; ubi part ubi ; ubi write $loadaddr ubootenv 0x1f000 ; ubi write $loadaddr ubootenv2 0x1f000 ; ubi remove rootfs_data
+ubi_prepare_rootfs=if ubi check rootfs_data ; then else if env exists rootfs_data_max ; then ubi create rootfs_data $rootfs_data_max dynamic || ubi create rootfs_data - dynamic ; else ubi create rootfs_data - dynamic ; fi ; fi
+ubi_read_production=ubi read $loadaddr fit && iminfo $loadaddr && run ubi_prepare_rootfs
+ubi_read_recovery=ubi check recovery && ubi read $loadaddr recovery
+ubi_remove_rootfs=ubi check rootfs_data && ubi remove rootfs_data
+ubi_write_fip=ubi check fip || ubi create fip 0x200000 static ; ubi write $loadaddr fip 0x200000
+ubi_write_production=ubi check fit && env exists replacevol && ubi remove fit ; if ubi check fit ; then else run ubi_remove_rootfs ; ubi create fit $filesize dynamic && ubi write $loadaddr fit $filesize ; fi
+ubi_write_recovery=ubi check recovery && env exists replacevol && ubi remove recovery ; if ubi check recovery ; then else run ubi_remove_rootfs ; ubi create recovery $filesize dynamic && ubi write $loadaddr recovery $filesize ; fi
+_create_env=ubi create ubootenv 0x100000 dynamic ; ubi create ubootenv2 0x100000 dynamic
+_create_env=ubi create ubootenv 0x1f000 dynamic ; ubi create ubootenv2 0x1f000 dynamic
+_init_env=setenv _init_env ; if ubi check ubootenv && ubi check ubootenv2 ; then else run _create_env ; fi ; setenv _create_env ; saveenv || run ubi_format ; saveenv || run ubi_format
+_firstboot=setenv _firstboot ; run _switch_to_menu ; run ethaddr_factory ; run check_ubi ; run _init_env ; run boot_first
+_firstboot=setenv _firstboot ; run _switch_to_menu ; run ethaddr_factory ; run _init_env ; run boot_first
+_switch_to_menu=setenv _switch_to_menu ; setenv bootdelay 3 ; setenv bootmenu_delay 3 ; setenv bootmenu_0 $bootmenu_0d ; setenv bootmenu_0d ; run _bootmenu_update_title
+_bootmenu_update_title=setenv _bootmenu_update_title ; setenv bootmenu_title "$bootmenu_title $ver"
72 changes: 51 additions & 21 deletions target/linux/mediatek/dts/mt7622-linksys-e8450-ubi.dts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
aliases {
label-mac-device = &wan;
};

chosen {
rootdisk = <&ubi_rootfs>;
bootargs = "earlycon=uart8250,mmio32,0x11002000 console=ttyS0,115200n1 swiotlb=512 ubi.block=0,fit root=/dev/fit0";
};
};

&snand {
Expand All @@ -25,45 +30,70 @@
};

partition@80000 {
label = "fip";
reg = <0x80000 0x140000>;
read-only;
};
label = "ubi";
reg = <0x80000 0x7f80000>;
compatible = "linux,ubi";

factory: partition@1c0000 {
label = "factory";
reg = <0x1c0000 0x100000>;
read-only;
volumes {
ubi-volume-ubootenv {
volname = "ubootenv";
nvmem-layout {
compatible = "u-boot,env-redundant-bool-layout";
};
};

nvmem-layout {
compatible = "fixed-layout";
#address-cells = <1>;
#size-cells = <1>;
ubi-volume-ubootenv2 {
volname = "ubootenv2";
nvmem-layout {
compatible = "u-boot,env-redundant-bool-layout";
};
};

macaddr_factory_7fff4: macaddr@7fff4 {
reg = <0x7fff4 0x6>;
ubi_rootfs: ubi-volume-fit {
volname = "fit";
};

macaddr_factory_7fffa: macaddr@7fffa {
reg = <0x7fffa 0x6>;
ubi_factory: ubi-volume-factory {
volname = "factory";
};
};
};
};
};

&ubi_factory {
nvmem-layout {
compatible = "fixed-layout";
#address-cells = <1>;
#size-cells = <1>;

eeprom_factory_0: eeprom@0 {
reg = <0x0 0x4da8>; /* actual length 0x400 */
};

partition@300000 {
label = "ubi";
reg = <0x300000 0x7d00000>;
eeprom_factory_5000: eeprom@5000 {
reg = <0x5000 0xe00>;
};

macaddr_factory_7fff4: macaddr@7fff4 {
reg = <0x7fff4 0x6>;
};

macaddr_factory_7fffa: macaddr@7fffa {
reg = <0x7fffa 0x6>;
};
};
};

&wmac {
mediatek,mtd-eeprom = <&factory 0x0>;
nvmem-cells = <&eeprom_factory_0>;
nvmem-cell-names = "eeprom";
status = "okay";
};

&wmac1 {
mediatek,mtd-eeprom = <&factory 0x5000>;
nvmem-cells = <&eeprom_factory_5000>;
nvmem-cell-names = "eeprom";
};

&gmac0 {
Expand Down
6 changes: 4 additions & 2 deletions target/linux/mediatek/image/mt7622.mk
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ define Device/linksys_e8450-ubi
DEVICE_ALT0_VARIANT := UBI
DEVICE_DTS := mt7622-linksys-e8450-ubi
DEVICE_DTS_DIR := ../dts
DEVICE_PACKAGES := kmod-mt7915-firmware kmod-usb3
DEVICE_PACKAGES := fitblk kmod-mt7915-firmware kmod-usb3
UBINIZE_OPTS := -E 5
BLOCKSIZE := 128k
PAGESIZE := 2048
Expand All @@ -270,8 +270,10 @@ define Device/linksys_e8450-ubi
IMAGES := sysupgrade.itb
IMAGE/sysupgrade.itb := append-kernel | fit gzip $$(KDIR)/image-$$(firstword $$(DEVICE_DTS)).dtb external-static-with-rootfs | append-metadata
ARTIFACTS := preloader.bin bl31-uboot.fip
ARTIFACT/preloader.bin := bl2 snand-1ddr
ARTIFACT/preloader.bin := bl2 snand-ubi-1ddr
ARTIFACT/bl31-uboot.fip := bl31-uboot linksys_e8450
DEVICE_COMPAT_VERSION := 2.0
DEVICE_COMPAT_MESSAGE := SPI-NAND flash layout changes require bootloader update
endef
TARGET_DEVICES += linksys_e8450-ubi

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ case "$(board_name)" in
bananapi,bpi-r64)
ucidef_set_compat_version "1.2"
;;
linksys,e8450-ubi)
ucidef_set_compat_version "2.0"
;;
esac

board_config_flush
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ case "$(board_name)" in
uci set system.@system[0].compat_version="1.1"
uci commit system
;;
linksys,e8450-ubi)
uci set system.@system[0].compat_version="2.0"
uci commit system
;;
esac

exit 0
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ platform_do_upgrade() {

case "$board" in
bananapi,bpi-r64|\
linksys,e8450-ubi|\
ubnt,unifi-6-lr-v1-ubootmod|\
ubnt,unifi-6-lr-v2-ubootmod|\
ubnt,unifi-6-lr-v3-ubootmod)
Expand Down Expand Up @@ -66,10 +67,6 @@ platform_do_upgrade() {
xiaomi,redmi-router-ax6s)
nand_do_upgrade "$1"
;;
linksys,e8450-ubi)
CI_KERNPART="fit"
nand_do_upgrade "$1"
;;
linksys,e8450)
if grep -q mtdparts=slave /proc/cmdline; then
PART_NAME=firmware2
Expand Down
1 change: 1 addition & 0 deletions target/linux/mediatek/mt7622/config-6.1
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ CONFIG_MTD_UBI=y
CONFIG_MTD_UBI_BEB_LIMIT=20
CONFIG_MTD_UBI_BLOCK=y
CONFIG_MTD_UBI_FASTMAP=y
CONFIG_MTD_UBI_NVMEM=y
CONFIG_MTD_UBI_WL_THRESHOLD=4096
# CONFIG_MTK_CMDQ is not set
# CONFIG_MTK_CQDMA is not set
Expand Down

10 comments on commit 6aec3c7

@schuettecarsten
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where can I find the updated installer?

@dangowrt
Copy link
Member Author

@dangowrt dangowrt commented on 6aec3c7 Feb 15, 2024 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dangowrt
Copy link
Member Author

@dangowrt dangowrt commented on 6aec3c7 Feb 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@schuettecarsten
Copy link
Contributor

@schuettecarsten schuettecarsten commented on 6aec3c7 Feb 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/dangowrt/owrt-ubi-installer/releases/tag/v1.1.0

Thank you. Can you please describe the steps to "upgrade" the bootloader of a device that already runs OpenWrt? I can see several warnings what not to do, but what are the safe steps to use the installer when OpenWrt already runs on an earlier version?

@ptpt52
Copy link
Contributor

@ptpt52 ptpt52 commented on 6aec3c7 Feb 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dangowrt
step by step to upgrade to latest openwrt from old version?

@dangowrt
Copy link
Member Author

@dangowrt dangowrt commented on 6aec3c7 Feb 28, 2024 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ptpt52
Copy link
Contributor

@ptpt52 ptpt52 commented on 6aec3c7 Mar 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dangowrt tested and works. thanks.

@dangowrt
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Step 5: Set compat_version:

uci set system.@system[0].compat_version="2.0"
uci commit system

@amaumene
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @dangowrt

I followed your procedure and manage to upgrade to r25357-ef34f8f5b5. But it seems I'm now stuck on this version. I sysupgraded to r25396-3e6f64d443 successfully but after reboot, I'm still running r25357-ef34f8f5b5. Any idea why?

Thanks in advance.

@schuettecarsten
Copy link
Contributor

@schuettecarsten schuettecarsten commented on 6aec3c7 Mar 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My Belkin RT3200 is extremely unstable since a few days. It often does not boot. Unplugging the device and wait for 5 minutes sometimes helps. I can see that the USB port is active but the Power LED never turns on, the device seems to be completely dead. After a few tries, it boots without issues. Unfortunately, I do not have a serial connection to the device so I cannot see what's going on.

Please sign in to comment.