Use the new fitblk driver on the BananaPi R2 as well as UniElec U7623.
Introduce boot device selection for fitblk's /chosen/rootdisk
handle, similar to how it is already done on MT7622, MT7986 and MT7988.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
case "$board" in
bananapi,bpi-r2)
- . /lib/upgrade/common.sh
- export_bootdevice
- export_partdevice ubootpart 1
- ubootenv_add_uci_config "/dev/$ubootpart" "0xb0000" "0x10000" "0x10000" "1"
+ . /lib/upgrade/platform.sh
+ bootdev="$(platform_get_bootdev)"
+ ubootenv_add_uci_config "/dev/${bootdev%p[0-9]*}p1" "0xb0000" "0x10000" "0x10000" "1"
;;
unielec,u7623-02)
ubootenv_add_uci_config "/dev/mmcblk0p1" "0xc0000" "0x10000" "0x10000" "1"
--- /dev/null
+--- a/board/mediatek/mt7623/mt7623_rfb.c
++++ b/board/mediatek/mt7623/mt7623_rfb.c
+@@ -5,6 +5,7 @@
+
+ #include <common.h>
+ #include <mmc.h>
++#include <part.h>
+ #include <asm/global_data.h>
+
+ DECLARE_GLOBAL_DATA_PTR;
+@@ -22,8 +23,9 @@ int mmc_get_boot_dev(void)
+ {
+ int g_mmc_devid = -1;
+ char *uflag = (char *)0x81DFFFF0;
++ struct blk_desc *desc;
+
+- if (!find_mmc_device(1))
++ if (blk_get_device_by_str("mmc", "1", &desc) < 0)
+ return 0;
+
+ if (strncmp(uflag,"eMMC",4)==0) {
+@@ -38,6 +40,23 @@ int mmc_get_boot_dev(void)
+
+ int mmc_get_env_dev(void)
+ {
+- return mmc_get_boot_dev();
++ struct udevice *dev;
++ const char *mmcdev;
++
++ switch (mmc_get_boot_dev()) {
++ case 0:
++ mmcdev = "mmc@11230000";
++ break;
++ case 1:
++ mmcdev = "mmc@11240000";
++ break;
++ default:
++ return -1;
++ }
++
++ if (uclass_get_device_by_name(UCLASS_MMC, mmcdev, &dev))
++ return -1;
++
++ return dev_seq(dev);
+ }
+ #endif
--- a/board/mediatek/mt7623/mt7623_rfb.c
+++ b/board/mediatek/mt7623/mt7623_rfb.c
-@@ -4,8 +4,17 @@
+@@ -4,9 +4,18 @@
*/
#include <common.h>
+#include <env.h>
+#include <init.h>
#include <mmc.h>
+ #include <part.h>
#include <asm/global_data.h>
+#include <linux/delay.h>
+
DECLARE_GLOBAL_DATA_PTR;
-@@ -41,3 +50,25 @@ int mmc_get_env_dev(void)
- return mmc_get_boot_dev();
+@@ -60,3 +69,25 @@ int mmc_get_env_dev(void)
+ return dev_seq(dev);
}
#endif
+
--- /dev/null
+--- a/board/mediatek/mt7623/mt7623_rfb.c
++++ b/board/mediatek/mt7623/mt7623_rfb.c
+@@ -91,3 +91,43 @@ int board_late_init(void)
+ env_relocate();
+ return 0;
+ }
++
++int ft_system_setup(void *blob, struct bd_info *bd)
++{
++ const u32 *media_handle_p;
++ int chosen, len, ret;
++ const char *media;
++ u32 media_handle;
++
++#ifdef CONFIG_MMC
++ switch (mmc_get_boot_dev()) {
++ case 0:
++ media = "rootdisk-emmc";
++ break
++ ;;
++ case 1:
++ 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));
++#endif
++
++ return 0;
++}
--- a/configs/mt7623n_bpir2_defconfig
+++ b/configs/mt7623n_bpir2_defconfig
-@@ -7,34 +7,105 @@ CONFIG_SYS_MALLOC_F_LEN=0x4000
+@@ -7,34 +7,106 @@ CONFIG_SYS_MALLOC_F_LEN=0x4000
CONFIG_NR_DRAM_BANKS=1
CONFIG_HAS_CUSTOM_SYS_INIT_SP_ADDR=y
CONFIG_CUSTOM_SYS_INIT_SP_ADDR=0x81ffff10
+CONFIG_LED_GPIO=y
+CONFIG_LOGLEVEL=7
+CONFIG_LOG=y
++CONFIG_OF_SYSTEM_SETUP=y
+CONFIG_AUTOBOOT_KEYED=y
+CONFIG_AUTOBOOT_MENU_SHOW=y
+CONFIG_BOARD_LATE_INIT=y
CONFIG_USE_IPADDR=y
CONFIG_IPADDR="192.168.1.1"
CONFIG_USE_SERVERIP=y
-@@ -46,6 +117,12 @@ CONFIG_CLK=y
+@@ -46,6 +118,12 @@ CONFIG_CLK=y
CONFIG_SUPPORT_EMMC_BOOT=y
CONFIG_MMC_HS400_SUPPORT=y
CONFIG_MMC_MTK=y
CONFIG_PHY_FIXED=y
CONFIG_MEDIATEK_ETH=y
CONFIG_PINCTRL=y
-@@ -55,10 +132,13 @@ CONFIG_POWER_DOMAIN=y
+@@ -55,10 +133,13 @@ CONFIG_POWER_DOMAIN=y
CONFIG_MTK_POWER_DOMAIN=y
CONFIG_DM_SERIAL=y
CONFIG_MTK_SERIAL=y
# CONFIG_EFI_GRUB_ARM32_WORKAROUND is not set
--- /dev/null
+++ b/bananapi_bpi-r2_env
-@@ -0,0 +1,70 @@
+@@ -0,0 +1,69 @@
+ipaddr=192.168.1.1
+serverip=192.168.1.254
+loadaddr=0x88000000
+sdmmc_write_recovery=iminfo $fileaddr && mmc dev 1 && part start mmc 1 $part_recovery part_addr && part size mmc 1 $part_recovery part_size && run mmc_write_vol
+_checkbootedfrom=setenv _checkbootedfrom ; if itest.l *81dffff0 == 434d4d65 ; then setenv bootedfrom eMMC ; else setenv bootedfrom SD ; fi
+_init_env=setenv _init_env ; setenv _create_env ; saveenv ; saveenv
-+_firstboot=setenv _firstboot ; led $bootled_pwr off ;led $bootled_rec on ; run _checkbootedfrom _switch_to_menu _update_bootdev _update_bootcmd _update_bootcmd2 _init_env boot_first
++_firstboot=setenv _firstboot ; led $bootled_pwr off ;led $bootled_rec on ; run _checkbootedfrom _switch_to_menu _update_bootcmd _update_bootcmd2 _init_env boot_first
+_set_bootcmd_sdmmc=setenv boot_production "led $bootled_rec off ; led $bootled_pwr on ; run sdmmc_read_production && bootm $loadaddr ; led $bootled_pwr off"
+_set_bootcmd_emmc=setenv boot_production "led $bootled_rec off ; led $bootled_pwr on ; run emmc_read_production && bootm $loadaddr ; led $bootled_pwr off"
+_update_bootcmd=setenv _update_bootcmd ; if test "$bootedfrom" = "SD" ; then run _set_bootcmd_sdmmc ; else run _set_bootcmd_emmc ; fi ; setenv _set_bootcmd_sdmmc ; setenv _set_bootcmd_emmc
+_set_bootcmd2_sdmmc=setenv boot_recovery "led $bootled_pwr off ; led $bootled_rec on ; run sdmmc_read_recovery && bootm $loadaddr ; led $bootled_rec off"
+_set_bootcmd2_emmc=setenv boot_recovery "led $bootled_pwr off ; led $bootled_rec on ; run emmc_read_recovery && bootm $loadaddr ; led $bootled_rec off"
+_update_bootcmd2=setenv _update_bootcmd2 ; if test "$bootedfrom" = "SD" ; then run _set_bootcmd2_sdmmc ; else run _set_bootcmd2_emmc ; fi ; setenv _set_bootcmd2_sdmmc ; setenv _set_bootcmd2_emmc
-+_update_bootdev=setenv _update_bootdev ; if test "$bootedfrom" = "SD" ; then setenv bootargs "$console root=/dev/mmcblk1p65" ; else setenv bootargs "$console root=/dev/mmcblk0p65" ; fi
+_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 \e[0;36m[$bootedfrom]\e[0m \e[33m$ver\e[0m" ; run _set_bm2
+_set_bm2=setenv _set_bm2 ; setenv bootmenu_2 "Boot production system from $bootedfrom.=run boot_production ; run bootmenu_confirm_return" ; run _set_bm3
+++ /dev/null
---- a/board/mediatek/mt7623/mt7623_rfb.c
-+++ b/board/mediatek/mt7623/mt7623_rfb.c
-@@ -9,6 +9,7 @@
- #include <env.h>
- #include <init.h>
- #include <mmc.h>
-+#include <part.h>
- #include <asm/global_data.h>
- #include <linux/delay.h>
-
-@@ -31,8 +32,9 @@ int mmc_get_boot_dev(void)
- {
- int g_mmc_devid = -1;
- char *uflag = (char *)0x81DFFFF0;
-+ struct blk_desc *desc;
-
-- if (!find_mmc_device(1))
-+ if (blk_get_device_by_str("mmc", "1", &desc) < 0)
- return 0;
-
- if (strncmp(uflag,"eMMC",4)==0) {
/ {
model = "UniElec U7623-02 eMMC";
compatible = "unielec,u7623-02", "mediatek,mt7623";
+
+ chosen {
+ stdout-path = "serial0:115200n8";
+ bootargs = "earlycon=uart8250,mmio32,0x11004000 root=/dev/fit0";
+ rootdisk = <&emmc_rootdisk>;
+ };
+};
+
+&mmc0 {
+ card@0 {
+ compatible = "mmc-card";
+ reg = <0>;
+
+ block {
+ compatible = "block-device";
+ partitions {
+ emmc_rootdisk: block-partition-env {
+ partno = <3>;
+ };
+ };
+ };
+ };
};
gzip
ARTIFACTS := u-boot.bin preloader.bin sdcard.img.gz
SUPPORTED_DEVICES := bananapi,bpi-r2
+ DEVICE_COMPAT_VERSION := 1.1
+ DEVICE_COMPAT_MESSAGE := Bootloader update required for switch to fitblk
endef
TARGET_DEVICES += bananapi_bpi-r2
REQUIRE_IMAGE_METADATA=1
+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
+}
+
# Legacy full system upgrade including preloader for MediaTek SoCs on eMMC or SD
legacy_mtk_mmc_full_upgrade() {
local diskdev partdev diff oldrecovery
case "$board" in
bananapi,bpi-r2|\
unielec,u7623-02)
- export_bootdevice
- export_partdevice fitpart 3
- [ "$fitpart" ] || return 1
- EMMC_KERN_DEV="/dev/$fitpart"
+ [ -e /dev/fit0 ] && fitblk /dev/fit0
+ [ -e /dev/fitrw ] && fitblk /dev/fitrw
+ bootdev="$(platform_get_bootdev)"
+ EMMC_KERN_DEV="/dev/$bootdev"
emmc_do_upgrade "$1"
;;
unielec,u7623-02-emmc-512m)
CONFIG_FB_SYS_FILLRECT=y
CONFIG_FB_SYS_FOPS=y
CONFIG_FB_SYS_IMAGEBLIT=y
-CONFIG_FIT_PARTITION=y
+# CONFIG_FIT_PARTITION is not set
CONFIG_FIXED_PHY=y
CONFIG_FIX_EARLYCON_MEM=y
CONFIG_FONT_8x16=y
# CONFIG_UACCE is not set
CONFIG_UBIFS_FS=y
CONFIG_UEVENT_HELPER_PATH=""
+CONFIG_UIMAGE_FIT_BLK=y
CONFIG_UNCOMPRESS_INCLUDE="debug/uncompress.h"
CONFIG_UNINLINE_SPIN_UNLOCK=y
CONFIG_UNWINDER_ARM=y
--- /dev/null
+--- a/arch/arm/boot/dts/mt7623n-bananapi-bpi-r2.dts
++++ b/arch/arm/boot/dts/mt7623n-bananapi-bpi-r2.dts
+@@ -27,6 +27,8 @@
+ chosen {
+ stdout-path = "serial2:115200n8";
+ bootargs = "earlycon=uart8250,mmio32,0x11004000 console=ttyS2,115200n8 console=tty1";
++ rootdisk-emmc = <&emmc_rootdisk>;
++ rootdisk-sd = <&sd_rootdisk>;
+ };
+
+ connector {
+@@ -315,6 +317,20 @@
+ vmmc-supply = <®_3p3v>;
+ vqmmc-supply = <®_1p8v>;
+ non-removable;
++
++ card@0 {
++ compatible = "mmc-card";
++ reg = <0>;
++
++ block {
++ compatible = "block-device";
++ partitions {
++ emmc_rootdisk: block-partition-fit {
++ partno = <3>;
++ };
++ };
++ };
++ };
+ };
+
+ &mmc1 {
+@@ -328,6 +344,20 @@
+ cd-gpios = <&pio 261 GPIO_ACTIVE_LOW>;
+ vmmc-supply = <®_3p3v>;
+ vqmmc-supply = <®_3p3v>;
++
++ card@0 {
++ compatible = "mmc-card";
++ reg = <0>;
++
++ block {
++ compatible = "block-device";
++ partitions {
++ sd_rootdisk: block-partition-fit {
++ partno = <3>;
++ };
++ };
++ };
++ };
+ };
+
+ &mt6323_leds {