From 208f6c1232901835708eb4ace44ae17628fc12f5 Mon Sep 17 00:00:00 2001 From: Daniel Golle Date: Sun, 21 Jan 2024 23:50:02 +0000 Subject: [PATCH] mediatek: mt7622: convert BPi-R64 to all-UBI layout and fitblk Modernize bootloader and flash memory layout of the BPi-R64 similar to how it has also been done for the BPi-R3. Signed-off-by: Daniel Golle --- .../boot/uboot-envtools/files/mediatek_mt7622 | 32 ++-- package/boot/uboot-mediatek/Makefile | 4 +- .../patches/312-mt7622-select-rootdisk.patch | 141 ++++++++++++++++++ .../403-add-bananapi_bpi-r64-snand.patch | 22 ++- .../404-add-bananapi_bpi-r64_defconfigs.patch | 55 ++++--- target/linux/mediatek/image/mt7622.mk | 10 +- .../base-files/etc/board.d/05_compat-version | 2 +- .../etc/uci-defaults/05_fix-compat-version | 5 +- .../mt7622/base-files/lib/upgrade/platform.sh | 36 +++-- target/linux/mediatek/mt7622/config-6.1 | 1 + .../113-dts-fix-bpi64-leds-and-buttons.patch | 8 +- .../114-dts-bpi64-disable-rtc.patch | 2 +- .../115-dts-bpi64-add-snand-support.patch | 2 +- ...80-dts-mt7622-bpi-r64-add-mt7531-irq.patch | 2 +- ...mt7622-bpi-r64-aliases-for-dtoverlay.patch | 2 +- .../910-dts-mt7622-bpi-r64-wifi-eeprom.patch | 2 +- .../911-dts-mt7622-bpi-r64-add-rootdisk.patch | 103 +++++++++++++ 17 files changed, 358 insertions(+), 71 deletions(-) create mode 100644 package/boot/uboot-mediatek/patches/312-mt7622-select-rootdisk.patch create mode 100644 target/linux/mediatek/patches-6.1/911-dts-mt7622-bpi-r64-add-rootdisk.patch diff --git a/package/boot/uboot-envtools/files/mediatek_mt7622 b/package/boot/uboot-envtools/files/mediatek_mt7622 index fdf0d331fc5..732f7d5a0e5 100644 --- a/package/boot/uboot-envtools/files/mediatek_mt7622 +++ b/package/boot/uboot-envtools/files/mediatek_mt7622 @@ -9,6 +9,21 @@ touch /etc/config/ubootenv . /lib/uboot-envtools.sh . /lib/functions.sh +ubootenv_add_mmc_default() { + local envdev="$(find_mmc_part "ubootenv" "${1:-mmcblk0}")" + ubootenv_add_uci_config "$envdev" "0x0" "0x80000" "0x80000" "1" + ubootenv_add_uci_config "$envdev" "0x80000" "0x80000" "0x80000" "1" +} + +ubootenv_add_ubi_default() { + . /lib/upgrade/nand.sh + local envubi=$(nand_find_ubi ubi) + local envdev=/dev/$(nand_find_volume $envubi ubootenv) + local envdev2=/dev/$(nand_find_volume $envubi ubootenv2) + ubootenv_add_uci_config "$envdev" "0x0" "0x1f000" "0x1f000" "1" + ubootenv_add_uci_config "$envdev2" "0x0" "0x1f000" "0x1f000" "1" +} + board=$(board_name) case "$board" in @@ -17,22 +32,17 @@ dlink,eagle-pro-ai-r32-a1) ubootenv_add_uci_config "/dev/mtd3" "0x0" "0x2000" "0x2000" ;; linksys,e8450-ubi) - ubootenv_add_uci_config "/dev/ubi0_0" "0x0" "0x1f000" "0x1f000" "1" - ubootenv_add_uci_config "/dev/ubi0_1" "0x0" "0x1f000" "0x1f000" "1" + ubootenv_add_ubi_default ;; bananapi,bpi-r64) - rootdev="$(cmdline_get_var root)" - rootdev="${rootdev##*/}" - rootdev="${rootdev%%p[0-9]*}" - case "$rootdev" in + . /lib/upgrade/platform.sh + bootdev="$(platform_get_bootdev)" + case "$bootdev" in mmc*) - local envdev=$(find_mmc_part "ubootenv" $rootdev) - ubootenv_add_uci_config "$envdev" "0x0" "0x80000" "0x80000" "1" - ubootenv_add_uci_config "$envdev" "0x80000" "0x80000" "0x80000" "1" + ubootenv_add_mmc_default "${bootdev%p[0-9]*}" ;; ubi*) - ubootenv_add_uci_config "/dev/ubi0_0" "0x0" "0x1f000" "0x1f000" "1" - ubootenv_add_uci_config "/dev/ubi0_1" "0x0" "0x1f000" "0x1f000" "1" + ubootenv_add_ubi_default ;; esac ;; diff --git a/package/boot/uboot-mediatek/Makefile b/package/boot/uboot-mediatek/Makefile index 1458ff01eef..32d3b995de6 100644 --- a/package/boot/uboot-mediatek/Makefile +++ b/package/boot/uboot-mediatek/Makefile @@ -130,9 +130,9 @@ define U-Boot/mt7622_bananapi_bpi-r64-snand BUILD_DEVICES:=bananapi_bpi-r64 BUILD_SUBTARGET:=mt7622 UBOOT_IMAGE:=u-boot.fip - BL2_BOOTDEV:=snand + BL2_BOOTDEV:=snand-ubi BL2_DDRBLOB:=2 - DEPENDS:=+trusted-firmware-a-mt7622-snand-2ddr + DEPENDS:=+trusted-firmware-a-mt7622-snand-ubi-2ddr endef define U-Boot/mt7622_ubnt_unifi-6-lr-v1 diff --git a/package/boot/uboot-mediatek/patches/312-mt7622-select-rootdisk.patch b/package/boot/uboot-mediatek/patches/312-mt7622-select-rootdisk.patch new file mode 100644 index 00000000000..70cbf6b4630 --- /dev/null +++ b/package/boot/uboot-mediatek/patches/312-mt7622-select-rootdisk.patch @@ -0,0 +1,141 @@ +--- a/board/mediatek/mt7622/mt7622_rfb.c ++++ b/board/mediatek/mt7622/mt7622_rfb.c +@@ -11,7 +11,9 @@ + #include + #include + #include ++#include + #include ++#include + + #ifndef CONFIG_RESET_BUTTON_LABEL + #define CONFIG_RESET_BUTTON_LABEL "reset" +@@ -22,10 +24,43 @@ + #include + #include + ++#define MT7622_TOPRGUSTRAP_PAR 0x10212060 ++#define MT7622_BOOT_SEQ_MASK 0x18 ++#define MT7622_BOOT_SEQ_SHIFT 3 ++#define MT7622_BOOT_SEQ_NOR_EMMC_SDXC 0x0 ++#define MT7622_BOOT_SEQ_SPI_NAND_EMMC_SDXC 0x1 ++#define MT7622_BOOT_SEQ_NAND_EMMC_SDXC 0x2 ++#define MT7622_BOOT_SEQ_SDXC_EMMC_NAND 0x3 ++ ++#define MT7622_GPIO_MODE0 0x10211300 ++#define MT7622_GPIO_NAND_MODE_MASK 0x00f00000 ++#define MT7622_GPIO_NAND_MODE_SHIFT 20 ++#define MT7622_GPIO_NAND_MODE_EMMC 0x2 ++#define MT7622_GPIO_RGMII_MODE_MASK 0x0000f000 ++#define MT7622_GPIO_RGMII_MODE_SHIFT 12 ++#define MT7622_GPIO_RGMII_MODE_SDCX 0x2 ++#define MT7622_GPIO_SPI_MODE_MASK 0x00000f00 ++#define MT7622_GPIO_SPI_MODE_SHIFT 8 ++#define MT7622_GPIO_SPI_MODE_NAND 0x2 ++ ++#define MT7622_MSDC_INT 0x1124000C ++#define MT7622_MSDC_INT_BD_CS_ERR 0x200 ++ + DECLARE_GLOBAL_DATA_PTR; + ++static int gpio_mode0; ++static int msdc_int; ++ + int board_init(void) + { ++ /* ++ * Save content of GPIO_MODE0 as left behind by the BootROM. ++ * Also grab MSDC1 INT status to see if BootROM has been reading ++ * from SD card. ++ * Together this will allow to infer the device used for booting. ++ */ ++ gpio_mode0 = readl(MT7622_GPIO_MODE0); ++ msdc_int = readl(MT7622_MSDC_INT); + return 0; + } + +@@ -83,3 +118,84 @@ int board_nmbm_init(void) + + return 0; + } ++ ++int ft_system_setup(void *blob, struct bd_info *bd) ++{ ++ bool pinctrl_set_mmc = false; ++ bool pinctrl_set_snfi = false; ++ bool pinctrl_set_emmc = false; ++ bool msdc_bd_cs_err = false; ++ ++ const u32 *media_handle_p; ++ int chosen, len, ret; ++ const char *media; ++ u32 media_handle, strap; ++ ++ if ((gpio_mode0 & MT7622_GPIO_RGMII_MODE_MASK) >> ++ MT7622_GPIO_RGMII_MODE_SHIFT == MT7622_GPIO_RGMII_MODE_SDCX) ++ pinctrl_set_mmc = true; ++ ++ if ((gpio_mode0 & MT7622_GPIO_SPI_MODE_MASK) >> ++ MT7622_GPIO_SPI_MODE_SHIFT == MT7622_GPIO_SPI_MODE_NAND) ++ pinctrl_set_snfi = true; ++ ++ if ((gpio_mode0 & MT7622_GPIO_NAND_MODE_MASK) >> ++ MT7622_GPIO_NAND_MODE_SHIFT == MT7622_GPIO_NAND_MODE_EMMC) ++ pinctrl_set_emmc = true; ++ ++ if (msdc_int & MT7622_MSDC_INT_BD_CS_ERR) ++ msdc_bd_cs_err = true; ++ ++ strap = readl(MT7622_TOPRGUSTRAP_PAR); ++ strap &= MT7622_BOOT_SEQ_MASK; ++ strap >>= MT7622_BOOT_SEQ_SHIFT; ++ switch (strap) { ++ case MT7622_BOOT_SEQ_NOR_EMMC_SDXC: ++ if (!pinctrl_set_emmc) ++ media = "rootdisk-nor"; ++ else if (pinctrl_set_mmc) ++ media = "rootdisk-emmc"; ++ else ++ media = "rootdisk-sd"; ++ break ++ ;; ++ case MT7622_BOOT_SEQ_SPI_NAND_EMMC_SDXC: ++ if (pinctrl_set_snfi) ++ media = "rootdisk-snfi"; ++ else if (pinctrl_set_emmc) ++ media = "rootdisk-emmc"; ++ else ++ media = "rootdisk-sd"; ++ break ++ ;; ++ case MT7622_BOOT_SEQ_NAND_EMMC_SDXC: ++ case MT7622_BOOT_SEQ_SDXC_EMMC_NAND: ++ if (!pinctrl_set_emmc && pinctrl_set_mmc) ++ media = "rootdisk-nand"; ++ else if (pinctrl_set_emmc) ++ media = "rootdisk-emmc"; ++ else ++ media = "rootdisk-sd"; ++ break ++ ;; ++ } ++ ++ chosen = fdt_path_offset(blob, "/chosen"); ++ if (chosen <= 0) ++ return 0; ++ ++ media_handle_p = fdt_getprop(blob, chosen, media, &len); ++ if (media_handle_p <= 0 || len != 4) ++ return 0; ++ ++ media_handle = *media_handle_p; ++ ret = fdt_setprop(blob, chosen, "rootdisk", &media_handle, sizeof(media_handle)); ++ if (ret) { ++ printf("cannot set media phandle %s as rootdisk /chosen node\n", media); ++ return ret; ++ } ++ ++ printf("set /chosen/rootdisk to bootrom media: %s (phandle 0x%08x)\n", media, fdt32_to_cpu(media_handle)); ++ ++ return 0; ++} diff --git a/package/boot/uboot-mediatek/patches/403-add-bananapi_bpi-r64-snand.patch b/package/boot/uboot-mediatek/patches/403-add-bananapi_bpi-r64-snand.patch index c9da03c7254..2ec57708067 100644 --- a/package/boot/uboot-mediatek/patches/403-add-bananapi_bpi-r64-snand.patch +++ b/package/boot/uboot-mediatek/patches/403-add-bananapi_bpi-r64-snand.patch @@ -9,7 +9,7 @@ ethernet0 = ð }; -@@ -208,17 +208,11 @@ +@@ -208,16 +208,27 @@ }; }; @@ -22,12 +22,26 @@ + pinctrl-0 = <&snfi_pins>; + quad-spi; status = "okay"; -- + - spi-flash@0{ - compatible = "jedec,spi-nor"; - reg = <0>; - bootph-all; -- }; ++ 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 { diff --git a/package/boot/uboot-mediatek/patches/404-add-bananapi_bpi-r64_defconfigs.patch b/package/boot/uboot-mediatek/patches/404-add-bananapi_bpi-r64_defconfigs.patch index f3d9499e171..1a9b859e7ad 100644 --- a/package/boot/uboot-mediatek/patches/404-add-bananapi_bpi-r64_defconfigs.patch +++ b/package/boot/uboot-mediatek/patches/404-add-bananapi_bpi-r64_defconfigs.patch @@ -17,6 +17,7 @@ +CONFIG_DEBUG_UART_CLOCK=25000000 +CONFIG_DEFAULT_DEVICE_TREE="mt7622-bananapi-bpi-r64" +CONFIG_OF_LIBFDT_OVERLAY=y ++CONFIG_OF_SYSTEM_SETUP=y +CONFIG_DEBUG_UART=y +CONFIG_DEFAULT_ENV_FILE="bananapi_bpi-r64-sdmmc_env" +CONFIG_NET_RANDOM_ETHADDR=y @@ -126,7 +127,6 @@ +CONFIG_PCI=y +CONFIG_MTD=y +CONFIG_MTD_UBI_FASTMAP=y -+CONFIG_MTDPARTS_DEFAULT="mtdparts=spi-nand0:512k(bl2),2048k(fip),-(ubi)" +CONFIG_DM_PCI=y +CONFIG_PCIE_MEDIATEK=y +CONFIG_PINCTRL=y @@ -167,11 +167,11 @@ +CONFIG_SERVERIP="192.168.1.254" --- /dev/null +++ b/bananapi_bpi-r64-sdmmc_env -@@ -0,0 +1,82 @@ +@@ -0,0 +1,81 @@ +ipaddr=192.168.1.1 +serverip=192.168.1.254 +loadaddr=0x48000000 -+bootargs=root=/dev/mmcblk1p65 ++bootargs=root=/dev/fit0 +bootcmd=if pstore check ; then run boot_recovery ; else run boot_sdmmc ; fi +bootconf=config-1#mt7622-bananapi-bpi-r64-pcie1 +bootconf_pcie=config-1#mt7622-bananapi-bpi-r64-pcie1 @@ -210,7 +210,6 @@ +boot_ubi=ubi part ubi && setenv bootargs && run boot_ubi_production ; run boot_ubi_recovery +boot_ubi_production=led $bootled_pwr on ; run ubi_read_production && bootm $loadaddr ; led $bootled_pwr off +boot_ubi_recovery=led $bootled_rec on ; run ubi_read_recovery ; bootm $loadaddr#$bootconf ; ubi remove recovery ; led $bootled_rec off -+check_ubi=ubi part ubi || run ubi_format +emmc_init=run emmc_init_bl && run emmc_init_openwrt ; env default bootcmd ; saveenv ; saveenv +emmc_init_bl=run sdmmc_read_emmc_bl2 && run emmc_write_bl2 && run sdmmc_read_emmc_hdr && run emmc_write_hdr && run sdmmc_read_emmc_fip && run emmc_write_fip +emmc_init_openwrt=run sdmmc_read_recovery && iminfo $loadaddr && run emmc_write_recovery ; run sdmmc_read_production && iminfo $loadaddr && run emmc_write_production @@ -220,7 +219,7 @@ +emmc_write_production=mmc dev 0 && part start mmc 0 $part_default part_addr && part size mmc 0 $part_default part_size && run mmc_write_vol +emmc_write_recovery=mmc dev 0 && part start mmc 0 $part_recovery part_addr && part size mmc 0 $part_recovery part_size && run mmc_write_vol +mmc_write_vol=imszb $loadaddr image_size && test 0x$image_size -le 0x$part_size && mmc erase 0x$part_addr 0x$image_size && mmc write $loadaddr 0x$part_addr 0x$image_size -+mmc_read_vol=mmc read $loadaddr $part_addr 0x8 && imszb $loadaddr image_size && test 0x$image_size -le 0x$part_size && mmc read $loadaddr 0x$part_addr 0x$image_size && setexpr filesize $image_size * 0x200 ++mmc_read_vol=mmc read $loadaddr $part_addr 0x100 && imszb $loadaddr image_size && test 0x$image_size -le 0x$part_size && mmc read $loadaddr 0x$part_addr 0x$image_size && setexpr filesize $image_size * 0x200 +part_default=production +part_recovery=recovery +reset_factory=eraseenv && reset @@ -233,26 +232,26 @@ +sdmmc_read_snand_fip=mmc dev 1 && part start mmc 1 install part_addr && setexpr offset $part_addr + 0x2400 && mmc read $loadaddr $offset 0x1000 +sdmmc_write_production=mmc dev 1 && part start mmc 1 $part_default part_addr && part size mmc 1 $part_default part_size && run mmc_write_vol +sdmmc_write_recovery=mmc dev 1 && part start mmc 1 $part_recovery part_addr && part size mmc 1 $part_recovery part_size && run mmc_write_vol -+snand_write_fip=mtd erase fip && mtd write fip $loadaddr -+snand_write_bl2=mtd erase bl2 && mtd write bl2 $loadaddr -+ubi_create_env=ubi create ubootenv 0x100000 dynamic 0 ; ubi create ubootenv2 0x100000 dynamic 1 ; ubi create fit 0x100000 dynamic 2 ; ubi create recovery 0x100000 dynamic 3 -+ubi_format=ubi detach ; mtd erase ubi && ubi part ubi ; reset -+ubi_init=run ubi_init_bl && ubi detach && mtd erase ubi && ubi part ubi && run ubi_create_env && run ubi_init_openwrt ++snand_write_bl2=mtd erase bl2 && mtd write bl2 $loadaddr 0x0 0x20000 && mtd write bl2 $loadaddr 0x20000 0x20000 && mtd write bl2 $loadaddr 0x40000 0x20000 && mtd write bl2 $loadaddr 0x60000 0x20000 ++ubi_create_env=ubi create ubootenv 0x1f000 dynamic ; ubi create ubootenv2 0x1f000 dynamic ++ubi_format=ubi detach ; mtd erase ubi && ubi part ubi ++ubi_init=run ubi_format && run ubi_init_bl && run ubi_create_env && run ubi_init_openwrt +ubi_init_openwrt=run sdmmc_read_recovery && iminfo $loadaddr && run ubi_write_recovery ; run sdmmc_read_production && iminfo $loadaddr && run ubi_write_production -+ubi_init_bl=run sdmmc_read_snand_bl2 && run snand_write_bl2 && run sdmmc_read_snand_fip && run snand_write_fip ++ubi_init_bl=run sdmmc_read_snand_bl2 && run snand_write_bl2 && run sdmmc_read_snand_fip && run ubi_write_fip +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_production=ubi check fit && ubi remove fit ; run ubi_remove_rootfs ; ubi create fit $filesize dynamic 2 && ubi write $loadaddr fit $filesize -+ubi_write_recovery=ubi check recovery && ubi remove recovery ; run ubi_remove_rootfs ; ubi create recovery $filesize dynamic 3 && ubi write $loadaddr recovery $filesize ++ubi_write_fip=ubi check fip && ubi remove fip ; ubi create fip 0x200000 static ; ubi write $loadaddr fip 0x200000 ++ubi_write_production=ubi check fit && ubi remove fit ; run ubi_remove_rootfs ; ubi create fit $filesize dynamic && ubi write $loadaddr fit $filesize ++ubi_write_recovery=ubi check recovery && ubi remove recovery ; run ubi_remove_rootfs ; ubi create recovery $filesize dynamic && ubi write $loadaddr recovery $filesize +_init_env=setenv _init_env ; setenv _create_env ; saveenv ; saveenv +_firstboot=setenv _firstboot ; run _switch_to_menu ; 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" --- /dev/null +++ b/configs/mt7622_bananapi_bpi-r64-emmc_defconfig -@@ -0,0 +1,151 @@ +@@ -0,0 +1,152 @@ +CONFIG_ARM=y +CONFIG_POSITION_INDEPENDENT=y +CONFIG_ARCH_MEDIATEK=y @@ -269,6 +268,7 @@ +CONFIG_DEBUG_UART_CLOCK=25000000 +CONFIG_DEFAULT_DEVICE_TREE="mt7622-bananapi-bpi-r64" +CONFIG_OF_LIBFDT_OVERLAY=y ++CONFIG_OF_SYSTEM_SETUP=y +CONFIG_DEBUG_UART=y +CONFIG_DEFAULT_ENV_FILE="bananapi_bpi-r64-emmc_env" +CONFIG_NET_RANDOM_ETHADDR=y @@ -411,7 +411,7 @@ +serverip=192.168.1.254 +loadaddr=0x48000000 +bootcmd=if pstore check ; then run boot_recovery ; else run boot_emmc ; fi -+bootargs=root=/dev/mmcblk0p65 ++bootargs=root=/dev/fit0 +bootconf=config-1#mt7622-bananapi-bpi-r64-pcie1 +bootconf_pcie=config-1#mt7622-bananapi-bpi-r64-pcie1 +bootconf_sata=config-1#mt7622-bananapi-bpi-r64-sata @@ -455,7 +455,7 @@ +emmc_read_production=mmc dev 0 && part start mmc 0 $part_default part_addr && part size mmc 0 $part_default part_size && run mmc_read_vol +emmc_read_recovery=mmc dev 0 && part start mmc 0 $part_recovery part_addr && part size mmc 0 $part_recovery part_size && run mmc_read_vol +mmc_write_vol=imszb $fileaddr image_size && test 0x$image_size -le 0x$part_size && mmc erase 0x$part_addr 0x$image_size && mmc write $fileaddr 0x$part_addr 0x$image_size -+mmc_read_vol=mmc read $loadaddr $part_addr 0x8 && imszb $loadaddr image_size && test 0x$image_size -le 0x$part_size && mmc read $loadaddr 0x$part_addr 0x$image_size ++mmc_read_vol=mmc read $loadaddr $part_addr 0x100 && imszb $loadaddr image_size && test 0x$image_size -le 0x$part_size && mmc read $loadaddr 0x$part_addr 0x$image_size +part_default=production +part_recovery=recovery +reset_factory=eraseenv && reset @@ -481,6 +481,7 @@ +CONFIG_DEBUG_UART_CLOCK=25000000 +CONFIG_DEFAULT_DEVICE_TREE="mt7622-bananapi-bpi-r64" +CONFIG_OF_LIBFDT_OVERLAY=y ++CONFIG_OF_SYSTEM_SETUP=y +CONFIG_DEBUG_UART=y +CONFIG_DEFAULT_ENV_FILE="bananapi_bpi-r64-snand_env" +CONFIG_DISTRO_DEFAULTS=y @@ -574,7 +575,6 @@ +CONFIG_PCI=y +CONFIG_MTD=y +CONFIG_MTD_UBI_FASTMAP=y -+CONFIG_MTDPARTS_DEFAULT="mtdparts=spi-nand0:512k(bl2),2048k(fip),-(ubi)" +CONFIG_DM_PCI=y +CONFIG_PCIE_MEDIATEK=y +CONFIG_PINCTRL=y @@ -613,11 +613,11 @@ +CONFIG_SERVERIP="192.168.1.3" --- /dev/null +++ b/bananapi_bpi-r64-snand_env -@@ -0,0 +1,57 @@ +@@ -0,0 +1,56 @@ +ipaddr=192.168.1.1 +serverip=192.168.1.254 +loadaddr=0x48000000 -+bootargs=root=/dev/ubiblock0_2p1 ++bootargs=ubi.block=0,fit root=/dev/fit0 +bootcmd=if pstore check ; then run boot_recovery ; else run boot_ubi ; fi +bootconf=config-1#mt7622-bananapi-bpi-r64-pcie1 +bootconf_pcie=config-1#mt7622-bananapi-bpi-r64-pcie1 @@ -652,22 +652,21 @@ +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 ++snand_write_bl2=mtd erase bl2 && mtd write bl2 $loadaddr 0x0 0x20000 && mtd write bl2 $loadaddr 0x20000 0x20000 && mtd write bl2 $loadaddr 0x40000 0x20000 && mtd write bl2 $loadaddr 0x60000 0x20000 +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 ++reset_factory=mw $loadaddr 0x0 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 remove 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 2 && 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 3 && ubi write $loadaddr recovery $filesize ; fi -+_create_env=ubi create ubootenv 0x100000 dynamic 0 ; ubi create ubootenv2 0x100000 dynamic 1 ; ubi create fit 0x100000 dynamic 2 ; ubi create recovery 0x100000 dynamic 3 -+_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 check_ubi ; run _init_env ; run boot_first ++_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 ; saveenv ++_firstboot=setenv _firstboot ; run _switch_to_menu ; 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" diff --git a/target/linux/mediatek/image/mt7622.mk b/target/linux/mediatek/image/mt7622.mk index 7df5eade822..0d631c19963 100644 --- a/target/linux/mediatek/image/mt7622.mk +++ b/target/linux/mediatek/image/mt7622.mk @@ -90,7 +90,7 @@ define Device/bananapi_bpi-r64 DEVICE_MODEL := BPi-R64 DEVICE_DTS := mt7622-bananapi-bpi-r64 DEVICE_DTS_OVERLAY := mt7622-bananapi-bpi-r64-pcie1 mt7622-bananapi-bpi-r64-sata - DEVICE_PACKAGES := kmod-ata-ahci-mtk kmod-btmtkuart kmod-usb3 e2fsprogs mkf2fs f2fsck + DEVICE_PACKAGES := fitblk kmod-ata-ahci-mtk kmod-btmtkuart kmod-usb3 e2fsprogs mkf2fs f2fsck DEVICE_DTC_FLAGS := --pad 4096 DEVICE_DTS_LOADADDR := 0x43f00000 ARTIFACTS := emmc-preloader.bin emmc-bl31-uboot.fip sdcard.img.gz snand-preloader.bin snand-bl31-uboot.fip @@ -98,7 +98,7 @@ define Device/bananapi_bpi-r64 KERNEL_INITRAMFS_SUFFIX := -recovery.itb ARTIFACT/emmc-preloader.bin := bl2 emmc-2ddr ARTIFACT/emmc-bl31-uboot.fip := bl31-uboot bananapi_bpi-r64-emmc - ARTIFACT/snand-preloader.bin := bl2 snand-2ddr + ARTIFACT/snand-preloader.bin := bl2 snand-ubi-2ddr ARTIFACT/snand-bl31-uboot.fip := bl31-uboot bananapi_bpi-r64-snand ARTIFACT/sdcard.img.gz := mt7622-gpt sdmmc |\ pad-to 512k | bl2 sdmmc-2ddr |\ @@ -109,7 +109,7 @@ define Device/bananapi_bpi-r64 pad-to 38912k | mt7622-gpt emmc |\ pad-to 39424k | bl2 emmc-2ddr |\ pad-to 40960k | bl31-uboot bananapi_bpi-r64-emmc |\ - pad-to 43008k | bl2 snand-2ddr |\ + pad-to 43008k | bl2 snand-ubi-2ddr |\ pad-to 43520k | bl31-uboot bananapi_bpi-r64-snand |\ $(if $(CONFIG_TARGET_ROOTFS_SQUASHFS), \ pad-to 46080k | append-image squashfs-sysupgrade.itb | check-size |\ @@ -121,8 +121,8 @@ endif KERNEL := kernel-bin | gzip KERNEL_INITRAMFS := kernel-bin | lzma | fit lzma $$(DTS_DIR)/$$(DEVICE_DTS).dtb with-initrd | pad-to 128k IMAGE/sysupgrade.itb := append-kernel | fit gzip $$(DTS_DIR)/$$(DEVICE_DTS).dtb external-static-with-rootfs | append-metadata - DEVICE_COMPAT_VERSION := 1.1 - DEVICE_COMPAT_MESSAGE := Device tree overlay mechanism needs bootloader update + DEVICE_COMPAT_VERSION := 1.2 + DEVICE_COMPAT_MESSAGE := SPI-NAND flash layout changes require bootloader update endef TARGET_DEVICES += bananapi_bpi-r64 diff --git a/target/linux/mediatek/mt7622/base-files/etc/board.d/05_compat-version b/target/linux/mediatek/mt7622/base-files/etc/board.d/05_compat-version index c8fb2c08f69..2fdbe764073 100644 --- a/target/linux/mediatek/mt7622/base-files/etc/board.d/05_compat-version +++ b/target/linux/mediatek/mt7622/base-files/etc/board.d/05_compat-version @@ -6,7 +6,7 @@ board_config_update case "$(board_name)" in bananapi,bpi-r64) - ucidef_set_compat_version "1.1" + ucidef_set_compat_version "1.2" ;; esac diff --git a/target/linux/mediatek/mt7622/base-files/etc/uci-defaults/05_fix-compat-version b/target/linux/mediatek/mt7622/base-files/etc/uci-defaults/05_fix-compat-version index 83310378694..3359d4a4001 100644 --- a/target/linux/mediatek/mt7622/base-files/etc/uci-defaults/05_fix-compat-version +++ b/target/linux/mediatek/mt7622/base-files/etc/uci-defaults/05_fix-compat-version @@ -1,7 +1,10 @@ . /lib/functions.sh case "$(board_name)" in - bananapi,bpi-r64|\ + bananapi,bpi-r64) + uci set system.@system[0].compat_version="1.2" + uci commit system + ;; buffalo,wsr-2533dhp2) uci set system.@system[0].compat_version="1.1" uci commit system diff --git a/target/linux/mediatek/mt7622/base-files/lib/upgrade/platform.sh b/target/linux/mediatek/mt7622/base-files/lib/upgrade/platform.sh index 3a2d7a4cd62..5836e1aa3ee 100755 --- a/target/linux/mediatek/mt7622/base-files/lib/upgrade/platform.sh +++ b/target/linux/mediatek/mt7622/base-files/lib/upgrade/platform.sh @@ -1,4 +1,20 @@ REQUIRE_IMAGE_METADATA=1 +RAMFS_COPY_BIN='fitblk' + +platform_get_bootdev() { + local rootdisk="$(cat /sys/firmware/devicetree/base/chosen/rootdisk)" + local handle bootdev + for handle in /sys/class/block/*/of_node/phandle /sys/class/block/*/device/of_node/phandle; do + [ ! -e "$handle" ] && continue + if [ "$rootdisk" = "$(cat $handle)" ]; then + bootdev="${handle%/of_node/phandle}" + bootdev="${bootdev%/device}" + bootdev="${bootdev#/sys/class/block/}" + echo "$bootdev" + break + fi + done +} platform_do_upgrade() { local board=$(board_name) @@ -6,21 +22,21 @@ platform_do_upgrade() { case "$board" in bananapi,bpi-r64) - local rootdev="$(cmdline_get_var root)" - rootdev="${rootdev##*/}" - rootdev="${rootdev%p[0-9]*}" - case "$rootdev" in - mmc*) - CI_ROOTDEV="$rootdev" - CI_KERNPART="production" + [ -e /dev/fit0 ] && fitblk /dev/fit0 + [ -e /dev/fitrw ] && fitblk /dev/fitrw + bootdev="$(platform_get_bootdev)" + case "$bootdev" in + mmcblk*) + EMMC_KERN_DEV="/dev/$bootdev" emmc_do_upgrade "$1" ;; - *) + ubiblock*) CI_KERNPART="fit" nand_do_upgrade "$1" ;; esac ;; + buffalo,wsr-2533dhp2|\ buffalo,wsr-3200ax4s) local magic="$(get_magic_long "$1")" @@ -99,9 +115,7 @@ platform_check_image() { platform_copy_config() { case "$(board_name)" in bananapi,bpi-r64) - export_bootdevice - export_partdevice rootdev 0 - if echo $rootdev | grep -q mmc; then + if platform_get_bootdev | grep -q mmc; then emmc_copy_config fi ;; diff --git a/target/linux/mediatek/mt7622/config-6.1 b/target/linux/mediatek/mt7622/config-6.1 index 0a876bce74e..cdaae0fe25c 100644 --- a/target/linux/mediatek/mt7622/config-6.1 +++ b/target/linux/mediatek/mt7622/config-6.1 @@ -455,6 +455,7 @@ CONFIG_TREE_RCU=y CONFIG_TREE_SRCU=y CONFIG_UBIFS_FS=y # CONFIG_UCLAMP_TASK is not set +CONFIG_UIMAGE_FIT_BLK=y # CONFIG_UNMAP_KERNEL_AT_EL0 is not set CONFIG_USB_SUPPORT=y CONFIG_VMAP_STACK=y diff --git a/target/linux/mediatek/patches-6.1/113-dts-fix-bpi64-leds-and-buttons.patch b/target/linux/mediatek/patches-6.1/113-dts-fix-bpi64-leds-and-buttons.patch index bf1912a9163..1cca6f35341 100644 --- a/target/linux/mediatek/patches-6.1/113-dts-fix-bpi64-leds-and-buttons.patch +++ b/target/linux/mediatek/patches-6.1/113-dts-fix-bpi64-leds-and-buttons.patch @@ -1,6 +1,6 @@ --- a/arch/arm64/boot/dts/mediatek/mt7622-bananapi-bpi-r64.dts +++ b/arch/arm64/boot/dts/mediatek/mt7622-bananapi-bpi-r64.dts -@@ -21,6 +21,10 @@ +@@ -21,6 +21,12 @@ aliases { serial0 = &uart0; ethernet0 = &gmac0; @@ -8,10 +8,12 @@ + led-failsafe = &led_system_blue; + led-running = &led_system_green; + led-upgrade = &led_system_blue; ++ mmc0 = &mmc0; ++ mmc1 = &mmc1; }; chosen { -@@ -44,8 +48,8 @@ +@@ -44,8 +50,8 @@ compatible = "gpio-keys"; factory-key { @@ -22,7 +24,7 @@ gpios = <&pio 0 GPIO_ACTIVE_HIGH>; }; -@@ -59,17 +63,17 @@ +@@ -59,17 +65,17 @@ leds { compatible = "gpio-leds"; diff --git a/target/linux/mediatek/patches-6.1/114-dts-bpi64-disable-rtc.patch b/target/linux/mediatek/patches-6.1/114-dts-bpi64-disable-rtc.patch index e30d9e5e12a..0d324084b1c 100644 --- a/target/linux/mediatek/patches-6.1/114-dts-bpi64-disable-rtc.patch +++ b/target/linux/mediatek/patches-6.1/114-dts-bpi64-disable-rtc.patch @@ -1,6 +1,6 @@ --- a/arch/arm64/boot/dts/mediatek/mt7622-bananapi-bpi-r64.dts +++ b/arch/arm64/boot/dts/mediatek/mt7622-bananapi-bpi-r64.dts -@@ -554,12 +554,16 @@ +@@ -556,12 +556,16 @@ status = "okay"; }; diff --git a/target/linux/mediatek/patches-6.1/115-dts-bpi64-add-snand-support.patch b/target/linux/mediatek/patches-6.1/115-dts-bpi64-add-snand-support.patch index 93f87fe697f..16aed70b44e 100644 --- a/target/linux/mediatek/patches-6.1/115-dts-bpi64-add-snand-support.patch +++ b/target/linux/mediatek/patches-6.1/115-dts-bpi64-add-snand-support.patch @@ -1,6 +1,6 @@ --- a/arch/arm64/boot/dts/mediatek/mt7622-bananapi-bpi-r64.dts +++ b/arch/arm64/boot/dts/mediatek/mt7622-bananapi-bpi-r64.dts -@@ -251,14 +251,42 @@ +@@ -253,14 +253,42 @@ status = "disabled"; }; diff --git a/target/linux/mediatek/patches-6.1/180-dts-mt7622-bpi-r64-add-mt7531-irq.patch b/target/linux/mediatek/patches-6.1/180-dts-mt7622-bpi-r64-add-mt7531-irq.patch index 676c09f656c..03e7aef9f03 100644 --- a/target/linux/mediatek/patches-6.1/180-dts-mt7622-bpi-r64-add-mt7531-irq.patch +++ b/target/linux/mediatek/patches-6.1/180-dts-mt7622-bpi-r64-add-mt7531-irq.patch @@ -1,6 +1,6 @@ --- a/arch/arm64/boot/dts/mediatek/mt7622-bananapi-bpi-r64.dts +++ b/arch/arm64/boot/dts/mediatek/mt7622-bananapi-bpi-r64.dts -@@ -152,6 +152,10 @@ +@@ -154,6 +154,10 @@ switch@0 { compatible = "mediatek,mt7531"; reg = <0>; diff --git a/target/linux/mediatek/patches-6.1/900-dts-mt7622-bpi-r64-aliases-for-dtoverlay.patch b/target/linux/mediatek/patches-6.1/900-dts-mt7622-bpi-r64-aliases-for-dtoverlay.patch index 8e56be9ff44..6dede02003a 100644 --- a/target/linux/mediatek/patches-6.1/900-dts-mt7622-bpi-r64-aliases-for-dtoverlay.patch +++ b/target/linux/mediatek/patches-6.1/900-dts-mt7622-bpi-r64-aliases-for-dtoverlay.patch @@ -1,6 +1,6 @@ --- a/arch/arm64/boot/dts/mediatek/mt7622-bananapi-bpi-r64.dts +++ b/arch/arm64/boot/dts/mediatek/mt7622-bananapi-bpi-r64.dts -@@ -310,7 +310,7 @@ +@@ -312,7 +312,7 @@ /* Attention: GPIO 90 is used to switch between PCIe@1,0 and * SATA functions. i.e. output-high: PCIe, output-low: SATA */ diff --git a/target/linux/mediatek/patches-6.1/910-dts-mt7622-bpi-r64-wifi-eeprom.patch b/target/linux/mediatek/patches-6.1/910-dts-mt7622-bpi-r64-wifi-eeprom.patch index b6762e29ac0..09ce417c351 100644 --- a/target/linux/mediatek/patches-6.1/910-dts-mt7622-bpi-r64-wifi-eeprom.patch +++ b/target/linux/mediatek/patches-6.1/910-dts-mt7622-bpi-r64-wifi-eeprom.patch @@ -1,6 +1,6 @@ --- a/arch/arm64/boot/dts/mediatek/mt7622-bananapi-bpi-r64.dts +++ b/arch/arm64/boot/dts/mediatek/mt7622-bananapi-bpi-r64.dts -@@ -637,5 +637,28 @@ +@@ -639,5 +639,28 @@ }; &wmac { diff --git a/target/linux/mediatek/patches-6.1/911-dts-mt7622-bpi-r64-add-rootdisk.patch b/target/linux/mediatek/patches-6.1/911-dts-mt7622-bpi-r64-add-rootdisk.patch new file mode 100644 index 00000000000..a141743194f --- /dev/null +++ b/target/linux/mediatek/patches-6.1/911-dts-mt7622-bpi-r64-add-rootdisk.patch @@ -0,0 +1,103 @@ +--- a/arch/arm64/boot/dts/mediatek/mt7622-bananapi-bpi-r64.dts ++++ b/arch/arm64/boot/dts/mediatek/mt7622-bananapi-bpi-r64.dts +@@ -32,6 +32,9 @@ + chosen { + stdout-path = "serial0:115200n8"; + bootargs = "earlycon=uart8250,mmio32,0x11002000 console=ttyS0,115200n1 swiotlb=512"; ++ rootdisk-emmc = <&emmc_rootfs>; ++ rootdisk-sd = <&sd_rootfs>; ++ rootdisk-snfi = <&ubi_rootfs>; + }; + + cpus { +@@ -233,6 +236,26 @@ + assigned-clocks = <&topckgen CLK_TOP_MSDC30_0_SEL>; + assigned-clock-parents = <&topckgen CLK_TOP_UNIV48M>; + non-removable; ++ ++ card@0 { ++ compatible = "mmc-card"; ++ reg = <0>; ++ ++ block { ++ compatible = "block-device"; ++ partitions { ++ block-partition-env { ++ partname = "ubootenv"; ++ nvmem-layout { ++ compatible = "u-boot,env-layout"; ++ }; ++ }; ++ emmc_rootfs: block-partition-production { ++ partname = "production"; ++ }; ++ }; ++ }; ++ }; + }; + + &mmc1 { +@@ -249,6 +272,26 @@ + vqmmc-supply = <®_3p3v>; + assigned-clocks = <&topckgen CLK_TOP_MSDC30_1_SEL>; + assigned-clock-parents = <&topckgen CLK_TOP_UNIV48M>; ++ ++ card@0 { ++ compatible = "mmc-card"; ++ reg = <0>; ++ ++ block { ++ compatible = "block-device"; ++ partitions { ++ block-partition-env { ++ partname = "ubootenv"; ++ nvmem-layout { ++ compatible = "u-boot,env-layout"; ++ }; ++ }; ++ sd_rootfs: block-partition-production { ++ partname = "production"; ++ }; ++ }; ++ }; ++ }; + }; + + &nandc { +@@ -283,14 +326,29 @@ + }; + + partition@80000 { +- label = "fip"; +- reg = <0x80000 0x200000>; +- read-only; +- }; +- +- partition@280000 { + label = "ubi"; +- reg = <0x280000 0x7d80000>; ++ reg = <0x80000 0x7f80000>; ++ compatible = "linux,ubi"; ++ ++ volumes { ++ ubi-volume-ubootenv { ++ volname = "ubootenv"; ++ nvmem-layout { ++ compatible = "u-boot,env-redundant-bool-layout"; ++ }; ++ }; ++ ++ ubi-volume-ubootenv2 { ++ volname = "ubootenv2"; ++ nvmem-layout { ++ compatible = "u-boot,env-redundant-bool-layout"; ++ }; ++ }; ++ ++ ubi_rootfs: ubi-volume-fit { ++ volname = "fit"; ++ }; ++ }; + }; + }; + };