[openwrt/openwrt] uboot-mediatek: detect rootdisk on MT7981
LEDE Commits
lede-commits at lists.infradead.org
Wed Aug 28 07:12:18 PDT 2024
dangole pushed a commit to openwrt/openwrt.git, branch main:
https://git.openwrt.org/e64b92c63bb4fc2f60ab43eea969a9d1b47998f4
commit e64b92c63bb4fc2f60ab43eea969a9d1b47998f4
Author: Daniel Golle <daniel at makrotopia.org>
AuthorDate: Thu Aug 8 19:00:27 2024 +0100
uboot-mediatek: detect rootdisk on MT7981
Set /chosen/rootdisk according to boot_mode register, similar to
MT7986.
Signed-off-by: Daniel Golle <daniel at makrotopia.org>
---
.../patches/314-mt7981-select-rootdisk.patch | 102 +++++++++++++++++++++
1 file changed, 102 insertions(+)
diff --git a/package/boot/uboot-mediatek/patches/314-mt7981-select-rootdisk.patch b/package/boot/uboot-mediatek/patches/314-mt7981-select-rootdisk.patch
new file mode 100644
index 0000000000..c53e4a8752
--- /dev/null
+++ b/package/boot/uboot-mediatek/patches/314-mt7981-select-rootdisk.patch
@@ -0,0 +1,102 @@
+--- a/board/mediatek/mt7981/mt7981_rfb.c
++++ b/board/mediatek/mt7981/mt7981_rfb.c
+@@ -11,7 +11,9 @@
+ #include <env.h>
+ #include <init.h>
+ #include <asm/global_data.h>
++#include <asm/io.h>
+ #include <linux/delay.h>
++#include <linux/libfdt.h>
+
+ #ifndef CONFIG_RESET_BUTTON_LABEL
+ #define CONFIG_RESET_BUTTON_LABEL "reset"
+@@ -81,3 +83,54 @@ int board_nmbm_init(void)
+
+ return 0;
+ }
++
++#define MT7981_BOOT_NOR 0
++#define MT7981_BOOT_SPIM_NAND 1 /* ToDo: fallback to SD */
++#define MT7981_BOOT_EMMC 2
++#define MT7981_BOOT_SNFI_NAND 3 /* ToDo (treated as SD) */
++
++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;
++
++ switch ((readl(0x11d006f0) & 0xc0) >> 6) {
++ case MT7981_BOOT_NOR:
++ media = "rootdisk-nor";
++ break
++ ;;
++ case MT7981_BOOT_SPIM_NAND:
++ media = "rootdisk-spim-nand";
++ break
++ ;;
++ case MT7981_BOOT_EMMC:
++ media = "rootdisk-emmc";
++ break
++ ;;
++ case MT7981_BOOT_SNFI_NAND:
++ 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;
++}
+--- a/configs/mt7981_emmc_rfb_defconfig
++++ b/configs/mt7981_emmc_rfb_defconfig
+@@ -114,3 +114,4 @@ CONFIG_FAT_WRITE=y
+ CONFIG_HEXDUMP=y
+ # CONFIG_EFI_LOADER is not set
+ CONFIG_LMB_MAX_REGIONS=64
++CONFIG_OF_SYSTEM_SETUP=y
+--- a/configs/mt7981_nor_rfb_defconfig
++++ b/configs/mt7981_nor_rfb_defconfig
+@@ -126,3 +126,4 @@ CONFIG_DM_SPI=y
+ CONFIG_MTK_SPIM=y
+ CONFIG_HEXDUMP=y
+ CONFIG_LMB_MAX_REGIONS=64
++CONFIG_OF_SYSTEM_SETUP=y
+--- a/configs/mt7981_rfb_defconfig
++++ b/configs/mt7981_rfb_defconfig
+@@ -135,3 +135,4 @@ CONFIG_DM_SPI=y
+ CONFIG_MTK_SPIM=y
+ CONFIG_HEXDUMP=y
+ CONFIG_LMB_MAX_REGIONS=64
++CONFIG_OF_SYSTEM_SETUP=y
+--- a/configs/mt7981_sd_rfb_defconfig
++++ b/configs/mt7981_sd_rfb_defconfig
+@@ -114,3 +114,4 @@ CONFIG_FAT_WRITE=y
+ CONFIG_HEXDUMP=y
+ # CONFIG_EFI_LOADER is not set
+ CONFIG_LMB_MAX_REGIONS=64
++CONFIG_OF_SYSTEM_SETUP=y
+--- a/configs/mt7981_snfi_nand_rfb_defconfig
++++ b/configs/mt7981_snfi_nand_rfb_defconfig
+@@ -120,3 +120,4 @@ CONFIG_DM_SERIAL=y
+ CONFIG_MTK_SERIAL=y
+ CONFIG_HEXDUMP=y
+ CONFIG_LMB_MAX_REGIONS=64
++CONFIG_OF_SYSTEM_SETUP=y
More information about the lede-commits
mailing list