aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/mediatek/image/mt7622.mk
diff options
context:
space:
mode:
authorDaniel Golle <daniel@makrotopia.org>2021-02-09 23:07:42 +0000
committerDaniel Golle <daniel@makrotopia.org>2021-02-28 01:23:48 +0000
commit02351861824a13ed158db1ef59aede2db6ba7568 (patch)
tree91eee3149bf08b68f8325149b19bd018137d90c6 /target/linux/mediatek/image/mt7622.mk
parent42f3efec962cd4ce0189976fa5b9f293e79eb4e0 (diff)
downloadupstream-02351861824a13ed158db1ef59aede2db6ba7568.tar.gz
upstream-02351861824a13ed158db1ef59aede2db6ba7568.tar.bz2
upstream-02351861824a13ed158db1ef59aede2db6ba7568.zip
mediatek: add alternative UBI NAND layout for Linksys E8450
The vendor flash layout of the Linksys E8450 is problematic as it uses the SPI-NAND chip without any wear-leveling while at the same time wasting a lot of space for padding. Use an all-UBI layout instead, storing the kernel+dtb+squashfs in uImage.FIT standard format in UBI volume 'fit', the read-write overlay in UBI volume 'rootfs_data' as well as reduntant U-Boot environments 'ubootenv' and 'ubootenv2', and a 'recovery' kernel+dtb+initramfs uImage.FIT for dual-boot. ** WARNING ** THIS PROCEDURE CAN EASILY BRICK YOUR DEVICE PERMANENTLY IF NOT CARRIED OUT VERY CAREFULLY AND EXACTLY AS DESCRIBED! Step 0 * Configure your PC to have the static IPv4 address 192.168.1.254/24 * Provide bin/targets/mediatek/mt7622 via TFTP Now continue EITHER with step 1A or 1B, depending on your preference (and on having serial console wired up or not). Step 1A (Using the vendor web interface (or non-UBI OpenWrt install)) In order to update to the new bootloader and UBI-based firmware, use the web browser of your choice to open the routers web-interface accessible on http://192.168.1.1 * Navigate to 'Configuration' -> 'Administration' -> 'Firmware Upgrade' * Upload the file openwrt-mediatek-mt7622-linksys_e8450-ubi-initramfs-recovery.itb and proceed with the upgrade. * Once OpenWrt comes up, use SCP to upload the new bootloader files to /tmp on the router: *-mt7622-linksys_e8450-ubi-preloader.bin *-mt7622-linksys_e8450-ubi-bl31-uboot.fip * Connect via SSH as you will now need to replace the bootloader in the Flash. ssh root@192.168.1.1 (the usual warnings) * First of all, backup all the flash now: for mtd in /dev/mtdblock*; do dd if=$mtd of=/tmp/$(basename $mtd); done * Then use SCP to copy /tmp/mtdblock* from the router and keep them safe. You will need them should you ever want to return to the factory firmware! * Now flow the uploaded files: mtd -e /dev/mtd0 write /tmp/*linksys_e8450-ubi-preloader.bin /dev/mtd0 mtd -e /dev/mtd1 write /tmp/*linksys_e8450-ubi-bl31-uboot.fip /dev/mtd1 If and only if both writes look like the completed successfully reboot the router. Now continue with step 2. Step 1B (Using the vendor bootloader serial console) * Use the serial to backup all /dev/mtd* devices before using the stock firmware (you got root shell when connected to serial). * Then reboot and select 'U-Boot Console' in the boot menu. * Copy the following lines, one by one: tftpboot 0x40080000 openwrt-mediatek-mt7622-linksys_e8450-ubi-preloader.bin tftpboot 0x40100000 openwrt-mediatek-mt7622-linksys_e8450-ubi-bl31-uboot.fip nand erase 0x0 0x180000 nand write 0x40080000 0x0 0x180000 reset Now continue with step 2 Step 2 Once the new bootchain comes up, the loader will initialize UBI and the ubootenv volumes. It will then of course fail to find any bootable volume and hence resort to load kernel via TFTP from server 192.168.1.254 while giving itself the address 192.168.1.1 The requested file is called openwrt-mediatek-mt7622-linksys_e8450-ubi-initramfs-recovery.itb and your TFTP server should provide exactly that :) It will be written to UBI as recovery image and booted. You can then continue and flash the production OS image, either by using sysupgrade in the booted initramfs recovery OS, or by using the bootloader menu and TFTP. That's it. Go ahead and mess around with a bootchain built almost completely from source (only DRAM calibration blobs are fitted in bl2, and the irreplacable on-chip ROM loader remains, of course). And enjoy U-Boot built with many great features out-of-the-box. You can access the bootloader environment from within OpenWrt using the 'fw_printenv' and 'fw_setenv' commands. Don't be afraid, once you got the new bootchain installed the device should be fairly unbrickable (holding reset button before and during power-on resets things and allows reflashing recovery image via TFTP) Special thanks to @dvn0 (Devan Carpenter) for providing amazingly fast infra for test-builds, allowing for `make clean ; make -j$(nproc)` in less than two minutes :) Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Diffstat (limited to 'target/linux/mediatek/image/mt7622.mk')
-rw-r--r--target/linux/mediatek/image/mt7622.mk38
1 files changed, 38 insertions, 0 deletions
diff --git a/target/linux/mediatek/image/mt7622.mk b/target/linux/mediatek/image/mt7622.mk
index dce1fb2055..e113939e17 100644
--- a/target/linux/mediatek/image/mt7622.mk
+++ b/target/linux/mediatek/image/mt7622.mk
@@ -6,6 +6,14 @@ else
KERNEL_LOADADDR := 0x44000000
endif
+define Build/bl2
+ $(CP) $(STAGING_DIR_IMAGE)/mt7622-$1-bl2.img $@
+endef
+
+define Build/bl31-uboot
+ $(CP) $(STAGING_DIR_IMAGE)/mt7622_$1-u-boot.fip $@
+endef
+
define Device/bpi_bananapi-r64
DEVICE_VENDOR := Bpi
DEVICE_MODEL := Banana Pi R64
@@ -50,6 +58,36 @@ define Device/linksys_e8450
endef
TARGET_DEVICES += linksys_e8450
+define Device/linksys_e8450-ubi
+ DEVICE_VENDOR := Linksys
+ DEVICE_MODEL := E8450
+ DEVICE_VARIANT := UBI
+ DEVICE_ALT0_VENDOR := Belkin
+ DEVICE_ALT0_MODEL := RT3200
+ DEVICE_ALT0_VARIANT := UBI
+ DEVICE_DTS := mt7622-linksys-e8450-ubi
+ DEVICE_DTS_DIR := ../dts
+ UBINIZE_OPTS := -E 5
+ BLOCKSIZE := 128k
+ PAGESIZE := 2048
+ UBOOTENV_IN_UBI := 1
+ KERNEL_IN_UBI := 1
+ KERNEL := kernel-bin | gzip
+# recovery can also be used with stock firmware web-ui, hence the padding...
+ KERNEL_INITRAMFS := kernel-bin | lzma | \
+ fit lzma $$(KDIR)/image-$$(firstword $$(DEVICE_DTS)).dtb with-initrd | pad-to 128k
+ KERNEL_INITRAMFS_SUFFIX := -recovery.itb
+ IMAGES := sysupgrade.itb
+ IMAGE/sysupgrade.itb := append-kernel | fit gzip $$(KDIR)/image-$$(firstword $$(DEVICE_DTS)).dtb external-static-with-rootfs | append-metadata
+ DEVICE_PACKAGES := kmod-usb-ohci kmod-usb2 kmod-usb3 kmod-ata-ahci-mtk \
+ kmod-mt7615e kmod-mt7615-firmware kmod-mt7915e \
+ u-boot-mt7622_linksys_e8450 uboot-envtools
+ ARTIFACTS := preloader.bin bl31-uboot.fip
+ ARTIFACT/preloader.bin := bl2 snand-1ddr
+ ARTIFACT/bl31-uboot.fip := bl31-uboot linksys_e8450
+endef
+TARGET_DEVICES += linksys_e8450-ubi
+
define Device/mediatek_mt7622-rfb1
DEVICE_VENDOR := MediaTek
DEVICE_MODEL := MTK7622 rfb1 AP