Skip to contentSkip to conversation

rockchip: tinker: Add boot from capability

RFC PATCH New Michael Trimarchi 2 participants 7 messages Nov 12, 2019 – Nov 14, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 rockchip: tinker: Add boot from capability

We need to know from what device we are booting in order to save the enviroment in right place

---
 arch/arm/dts/rk3288-tinker-s-u-boot.dtsi     |  1 +
 arch/arm/mach-rockchip/rk3288/rk3288.c       | 46 ++++++++++++++++++++
 board/rockchip/tinker_rk3288/tinker-rk3288.c | 41 +++++++++++++++++
 configs/tinker-rk3288_defconfig              |  2 +
 configs/tinker-s-rk3288_defconfig            |  2 +
 5 files changed, 92 insertions(+)
arch/arm/dts/rk3288-tinker-s-u-boot.dtsi +1 -0
index 538593359a..2193127514 100644
@@ -10,6 +10,7 @@
 	chosen {
 		u-boot,spl-boot-order = \
 			"same-as-spl", &sdmmc, &emmc;
+		u-boot,spl-boot-device = "/dwmmc at ff0f0000";
 	};
 };
 
arch/arm/mach-rockchip/rk3288/rk3288.c +46 -0

58 lines not on this page · raw message

board/rockchip/tinker_rk3288/tinker-rk3288.c +41 -0

50 lines not on this page · raw message

configs/tinker-rk3288_defconfig +2 -0
index c851a93f31..106e24e8ca 100644
@@ -13,7 +13,9 @@ CONFIG_DEBUG_UART=y
 CONFIG_TPL_SYS_MALLOC_F_LEN=0x4000
 CONFIG_SPL_SYS_MALLOC_F_LEN=0x4000
 CONFIG_SYS_MALLOC_F_LEN=0x4000
+CONFIG_SPL_OF_LIBFDT=y
 # CONFIG_ANDROID_BOOT_IMAGE is not set
+CONFIG_MISC_INIT_R=y
 CONFIG_USE_PREBOOT=y
 CONFIG_SILENT_CONSOLE=y
 CONFIG_CONSOLE_MUX=y
configs/tinker-s-rk3288_defconfig +2 -0
index c851a93f31..106e24e8ca 100644
@@ -13,7 +13,9 @@ CONFIG_DEBUG_UART=y
 CONFIG_TPL_SYS_MALLOC_F_LEN=0x4000
 CONFIG_SPL_SYS_MALLOC_F_LEN=0x4000
 CONFIG_SYS_MALLOC_F_LEN=0x4000
+CONFIG_SPL_OF_LIBFDT=y
 # CONFIG_ANDROID_BOOT_IMAGE is not set
+CONFIG_MISC_INIT_R=y
 CONFIG_USE_PREBOOT=y
 CONFIG_SILENT_CONSOLE=y
 CONFIG_CONSOLE_MUX=y
Signature · 1 line
2.17.1
#1 lore raw

RFC PATCH 1/1 rockchip: tinker: Add boot from capability

Hi Michael,

Quoted 1 line · Michael Trimarchi

We need to know from what device we are booting

Please make sure board_spl_was_booted_from() works for rk3288, which

already work for rk3399, after that, we can move those functions from rk3399

only into common code to make everything work.

We are not going to add "spl-boot-device".

Thanks,

- Kever

Quoted 172 lines

in order
to save the enviroment in right place

---
  arch/arm/dts/rk3288-tinker-s-u-boot.dtsi     |  1 +
  arch/arm/mach-rockchip/rk3288/rk3288.c       | 46 ++++++++++++++++++++
  board/rockchip/tinker_rk3288/tinker-rk3288.c | 41 +++++++++++++++++
  configs/tinker-rk3288_defconfig              |  2 +
  configs/tinker-s-rk3288_defconfig            |  2 +
  5 files changed, 92 insertions(+)
arch/arm/dts/rk3288-tinker-s-u-boot.dtsi +1 -0
index 538593359a..2193127514 100644
@@ -10,6 +10,7 @@
  	chosen {
  		u-boot,spl-boot-order = \
  			"same-as-spl", &sdmmc, &emmc;
+		u-boot,spl-boot-device = "/dwmmc at ff0f0000";
  	};
  };
 
arch/arm/mach-rockchip/rk3288/rk3288.c +46 -0
index 987b4e0d58..002d1508e5 100644
@@ -3,6 +3,8 @@
   * Copyright (c) 2016 Rockchip Electronics Co., Ltd
   */
  #include <common.h>
+#include <spl.h>
+#include <fdt_support.h>
  #include <dm.h>
  #include <env.h>
  #include <clk.h>
@@ -26,6 +28,50 @@ const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = {
  	[BROM_BOOTSOURCE_SD] = "/dwmmc at ff0c0000",
  };
 
+#if defined(CONFIG_SPL_BUILD) && !defined(CONFIG_TPL_BUILD)
+const char *spl_decode_boot_device(u32 boot_device)
+{
+	int i;
+	static const struct {
+		u32 boot_device;
+		const char *ofpath;
+	} spl_boot_devices_tbl[] = {
+		{ BOOT_DEVICE_MMC2, "/dwmmc at ff0f0000" },
+		{ BOOT_DEVICE_MMC1, "/dwmmc at ff0c0000" },
+	};
+
+	for (i = 0; i < ARRAY_SIZE(spl_boot_devices_tbl); ++i)
+		if (spl_boot_devices_tbl[i].boot_device == boot_device)
+			return spl_boot_devices_tbl[i].ofpath;
+
+	return NULL;
+}
+
+void spl_perform_fixups(struct spl_image_info *spl_image)
+{
+	void *blob = (void *)gd->fdt_blob;
+	const char *boot_ofpath;
+	int chosen;
+
+	if (!blob)
+		return;
+
+	boot_ofpath = spl_decode_boot_device(spl_image->boot_device);
+	if (!boot_ofpath) {
+		pr_err("%s: could not map boot_device to ofpath\n", __func__);
+		return;
+	}
+
+	chosen = fdt_find_or_add_subnode(blob, 0, "chosen");
+	if (chosen < 0) {
+		pr_err("%s: could not find/create '/chosen'\n", __func__);
+		return;
+	}
+	fdt_setprop_string(blob, chosen,
+			   "u-boot,spl-boot-device", boot_ofpath);
+}
+#endif
+
  #ifdef CONFIG_SPL_BUILD
  static void configure_l2ctlr(void)
  {
board/rockchip/tinker_rk3288/tinker-rk3288.c +41 -0
index 6c76c3c25c..66a7394d95 100644
@@ -9,6 +9,34 @@
  #include <i2c_eeprom.h>
  #include <netdev.h>
 
+static int tinker_boot_device = CONFIG_SYS_MMC_ENV_DEV;
+
+/*
+ * Select the boot device according to what was set in spl step
+ */
+static int setup_boottargets(void)
+{
+	const char *boot_device =
+		ofnode_get_chosen_prop("u-boot,spl-boot-device");
+
+	if (!boot_device) {
+		debug("%s: /chosen/u-boot,spl-boot-device not set\n",
+		      __func__);
+		return -1;
+	}
+	debug("%s: booted from %s\n", __func__, boot_device);
+
+	if (!strcmp(boot_device, "/dwmmc at ff0f0000")) {
+		/* eMMC boot device */
+		tinker_boot_device = 1;
+	} else {
+		/* sdcard boot device */
+		tinker_boot_device = 0;
+	}
+
+	return 0;
+}
+
  static int get_ethaddr_from_eeprom(u8 *addr)
  {
  	int ret;
@@ -33,3 +61,16 @@ int rk3288_board_late_init(void)
 
  	return 0;
  }
+
+int misc_init_r(void)
+{
+	setup_boottargets();
+
+	return 0;
+}
+
+int mmc_get_env_dev(void)
+{
+	debug("boot device %d\n", tinker_boot_device);
+	return tinker_boot_device;
+}
configs/tinker-rk3288_defconfig +2 -0
index c851a93f31..106e24e8ca 100644
@@ -13,7 +13,9 @@ CONFIG_DEBUG_UART=y
  CONFIG_TPL_SYS_MALLOC_F_LEN=0x4000
  CONFIG_SPL_SYS_MALLOC_F_LEN=0x4000
  CONFIG_SYS_MALLOC_F_LEN=0x4000
+CONFIG_SPL_OF_LIBFDT=y
  # CONFIG_ANDROID_BOOT_IMAGE is not set
+CONFIG_MISC_INIT_R=y
  CONFIG_USE_PREBOOT=y
  CONFIG_SILENT_CONSOLE=y
  CONFIG_CONSOLE_MUX=y
configs/tinker-s-rk3288_defconfig +2 -0
index c851a93f31..106e24e8ca 100644
@@ -13,7 +13,9 @@ CONFIG_DEBUG_UART=y
  CONFIG_TPL_SYS_MALLOC_F_LEN=0x4000
  CONFIG_SPL_SYS_MALLOC_F_LEN=0x4000
  CONFIG_SYS_MALLOC_F_LEN=0x4000
+CONFIG_SPL_OF_LIBFDT=y
  # CONFIG_ANDROID_BOOT_IMAGE is not set
+CONFIG_MISC_INIT_R=y
  CONFIG_USE_PREBOOT=y
  CONFIG_SILENT_CONSOLE=y
  CONFIG_CONSOLE_MUX=y
#2 lore raw

RFC PATCH 1/1 rockchip: tinker: Add boot from capability

Hi Kever

Quoted 6 lines · Kever Yang

Hi Michael,

Quoted 1 line · Michael Trimarchi

We need to know from what device we are booting

Quoted 7 lines

Please make sure board_spl_was_booted_from() works for rk3288, which

already work for rk3399, after that, we can move those functions from rk3399

only into common code to make everything work.

We are not going to add "spl-boot-device".

That implementation has no sense in my use case. You need fit image. I don't need any special change

Michael

Quoted 180 lines

Thanks,

- Kever

Quoted 172 lines

in order
to save the enviroment in right place

---
  arch/arm/dts/rk3288-tinker-s-u-boot.dtsi     |  1 +
  arch/arm/mach-rockchip/rk3288/rk3288.c       | 46 ++++++++++++++++++++
  board/rockchip/tinker_rk3288/tinker-rk3288.c | 41 +++++++++++++++++
  configs/tinker-rk3288_defconfig              |  2 +
  configs/tinker-s-rk3288_defconfig            |  2 +
  5 files changed, 92 insertions(+)
arch/arm/dts/rk3288-tinker-s-u-boot.dtsi +1 -0
index 538593359a..2193127514 100644
@@ -10,6 +10,7 @@
      chosen {
              u-boot,spl-boot-order = \
                      "same-as-spl", &sdmmc, &emmc;
+             u-boot,spl-boot-device = "/dwmmc at ff0f0000";
      };
  };
 
arch/arm/mach-rockchip/rk3288/rk3288.c +46 -0
index 987b4e0d58..002d1508e5 100644
@@ -3,6 +3,8 @@
   * Copyright (c) 2016 Rockchip Electronics Co., Ltd
   */
  #include <common.h>
+#include <spl.h>
+#include <fdt_support.h>
  #include <dm.h>
  #include <env.h>
  #include <clk.h>
@@ -26,6 +28,50 @@ const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = {
      [BROM_BOOTSOURCE_SD] = "/dwmmc at ff0c0000",
  };
 
+#if defined(CONFIG_SPL_BUILD) && !defined(CONFIG_TPL_BUILD)
+const char *spl_decode_boot_device(u32 boot_device)
+{
+     int i;
+     static const struct {
+             u32 boot_device;
+             const char *ofpath;
+     } spl_boot_devices_tbl[] = {
+             { BOOT_DEVICE_MMC2, "/dwmmc at ff0f0000" },
+             { BOOT_DEVICE_MMC1, "/dwmmc at ff0c0000" },
+     };
+
+     for (i = 0; i < ARRAY_SIZE(spl_boot_devices_tbl); ++i)
+             if (spl_boot_devices_tbl[i].boot_device == boot_device)
+                     return spl_boot_devices_tbl[i].ofpath;
+
+     return NULL;
+}
+
+void spl_perform_fixups(struct spl_image_info *spl_image)
+{
+     void *blob = (void *)gd->fdt_blob;
+     const char *boot_ofpath;
+     int chosen;
+
+     if (!blob)
+             return;
+
+     boot_ofpath = spl_decode_boot_device(spl_image->boot_device);
+     if (!boot_ofpath) {
+             pr_err("%s: could not map boot_device to ofpath\n", __func__);
+             return;
+     }
+
+     chosen = fdt_find_or_add_subnode(blob, 0, "chosen");
+     if (chosen < 0) {
+             pr_err("%s: could not find/create '/chosen'\n", __func__);
+             return;
+     }
+     fdt_setprop_string(blob, chosen,
+                        "u-boot,spl-boot-device", boot_ofpath);
+}
+#endif
+
  #ifdef CONFIG_SPL_BUILD
  static void configure_l2ctlr(void)
  {
board/rockchip/tinker_rk3288/tinker-rk3288.c +41 -0
index 6c76c3c25c..66a7394d95 100644
@@ -9,6 +9,34 @@
  #include <i2c_eeprom.h>
  #include <netdev.h>
 
+static int tinker_boot_device = CONFIG_SYS_MMC_ENV_DEV;
+
+/*
+ * Select the boot device according to what was set in spl step
+ */
+static int setup_boottargets(void)
+{
+     const char *boot_device =
+             ofnode_get_chosen_prop("u-boot,spl-boot-device");
+
+     if (!boot_device) {
+             debug("%s: /chosen/u-boot,spl-boot-device not set\n",
+                   __func__);
+             return -1;
+     }
+     debug("%s: booted from %s\n", __func__, boot_device);
+
+     if (!strcmp(boot_device, "/dwmmc at ff0f0000")) {
+             /* eMMC boot device */
+             tinker_boot_device = 1;
+     } else {
+             /* sdcard boot device */
+             tinker_boot_device = 0;
+     }
+
+     return 0;
+}
+
  static int get_ethaddr_from_eeprom(u8 *addr)
  {
      int ret;
@@ -33,3 +61,16 @@ int rk3288_board_late_init(void)
 
      return 0;
  }
+
+int misc_init_r(void)
+{
+     setup_boottargets();
+
+     return 0;
+}
+
+int mmc_get_env_dev(void)
+{
+     debug("boot device %d\n", tinker_boot_device);
+     return tinker_boot_device;
+}
configs/tinker-rk3288_defconfig +2 -0
index c851a93f31..106e24e8ca 100644
@@ -13,7 +13,9 @@ CONFIG_DEBUG_UART=y
  CONFIG_TPL_SYS_MALLOC_F_LEN=0x4000
  CONFIG_SPL_SYS_MALLOC_F_LEN=0x4000
  CONFIG_SYS_MALLOC_F_LEN=0x4000
+CONFIG_SPL_OF_LIBFDT=y
  # CONFIG_ANDROID_BOOT_IMAGE is not set
+CONFIG_MISC_INIT_R=y
  CONFIG_USE_PREBOOT=y
  CONFIG_SILENT_CONSOLE=y
  CONFIG_CONSOLE_MUX=y
configs/tinker-s-rk3288_defconfig +2 -0
index c851a93f31..106e24e8ca 100644
@@ -13,7 +13,9 @@ CONFIG_DEBUG_UART=y
  CONFIG_TPL_SYS_MALLOC_F_LEN=0x4000
  CONFIG_SPL_SYS_MALLOC_F_LEN=0x4000
  CONFIG_SYS_MALLOC_F_LEN=0x4000
+CONFIG_SPL_OF_LIBFDT=y
  # CONFIG_ANDROID_BOOT_IMAGE is not set
+CONFIG_MISC_INIT_R=y
  CONFIG_USE_PREBOOT=y
  CONFIG_SILENT_CONSOLE=y
  CONFIG_CONSOLE_MUX=y
Signature · 4 lines
| Michael Nazzareno Trimarchi                     Amarula Solutions BV |
| COO  -  Founder                                      Cruquiuskade 47 |
| +31(0)851119172                                 Amsterdam 1018 AM NL |
|                  [`as] http://www.amarulasolutions.com               |
#3 lore raw

RFC PATCH 1/1 rockchip: tinker: Add boot from capability

Hi Kever

Let me more clear

Quoted 12 lines · Michael Nazzareno Trimarchi

Hi Kever

Quoted 8 lines · Kever Yang

Hi Michael,

Quoted 1 line · Michael Trimarchi

We need to know from what device we are booting

Please make sure board_spl_was_booted_from() works for rk3288, which

Quoted 8 lines
Quoted 5 lines

already work for rk3399, after that, we can move those functions from rk3399

only into common code to make everything work.

We are not going to add "spl-boot-device".

That implementation has no sense in my use case. You need fit image. I don't need any special change

I don't re-allocate the dtb so the size in no-fit image is the same. I think that we can use
some meta-tag for bootloader to store information from spl to second stage. You need to keep
in the same size or you have -ENOSPACE. This can be generic but depends what the maintair
think.

Michael

Quoted 189 lines

Michael

Quoted 170 lines

Thanks,

- Kever

Quoted 164 lines

in order
to save the enviroment in right place

---
  arch/arm/dts/rk3288-tinker-s-u-boot.dtsi     |  1 +
  arch/arm/mach-rockchip/rk3288/rk3288.c       | 46 ++++++++++++++++++++
  board/rockchip/tinker_rk3288/tinker-rk3288.c | 41 +++++++++++++++++
  configs/tinker-rk3288_defconfig              |  2 +
  configs/tinker-s-rk3288_defconfig            |  2 +
  5 files changed, 92 insertions(+)
arch/arm/dts/rk3288-tinker-s-u-boot.dtsi +1 -0
index 538593359a..2193127514 100644
@@ -10,6 +10,7 @@
      chosen {
              u-boot,spl-boot-order = \
                      "same-as-spl", &sdmmc, &emmc;
+             u-boot,spl-boot-device = "/dwmmc at ff0f0000";
      };
  };
 
arch/arm/mach-rockchip/rk3288/rk3288.c +46 -0
index 987b4e0d58..002d1508e5 100644
@@ -3,6 +3,8 @@
   * Copyright (c) 2016 Rockchip Electronics Co., Ltd
   */
  #include <common.h>
+#include <spl.h>
+#include <fdt_support.h>
  #include <dm.h>
  #include <env.h>
  #include <clk.h>
@@ -26,6 +28,50 @@ const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = {
      [BROM_BOOTSOURCE_SD] = "/dwmmc at ff0c0000",
  };
 
+#if defined(CONFIG_SPL_BUILD) && !defined(CONFIG_TPL_BUILD)
+const char *spl_decode_boot_device(u32 boot_device)
+{
+     int i;
+     static const struct {
+             u32 boot_device;
+             const char *ofpath;
+     } spl_boot_devices_tbl[] = {
+             { BOOT_DEVICE_MMC2, "/dwmmc at ff0f0000" },
+             { BOOT_DEVICE_MMC1, "/dwmmc at ff0c0000" },
+     };
+
+     for (i = 0; i < ARRAY_SIZE(spl_boot_devices_tbl); ++i)
+             if (spl_boot_devices_tbl[i].boot_device == boot_device)
+                     return spl_boot_devices_tbl[i].ofpath;
+
+     return NULL;
+}
+
+void spl_perform_fixups(struct spl_image_info *spl_image)
+{
+     void *blob = (void *)gd->fdt_blob;
+     const char *boot_ofpath;
+     int chosen;
+
+     if (!blob)
+             return;
+
+     boot_ofpath = spl_decode_boot_device(spl_image->boot_device);
+     if (!boot_ofpath) {
+             pr_err("%s: could not map boot_device to ofpath\n", __func__);
+             return;
+     }
+
+     chosen = fdt_find_or_add_subnode(blob, 0, "chosen");
+     if (chosen < 0) {
+             pr_err("%s: could not find/create '/chosen'\n", __func__);
+             return;
+     }
+     fdt_setprop_string(blob, chosen,
+                        "u-boot,spl-boot-device", boot_ofpath);
+}
+#endif
+
  #ifdef CONFIG_SPL_BUILD
  static void configure_l2ctlr(void)
  {
board/rockchip/tinker_rk3288/tinker-rk3288.c +41 -0
index 6c76c3c25c..66a7394d95 100644
@@ -9,6 +9,34 @@
  #include <i2c_eeprom.h>
  #include <netdev.h>
 
+static int tinker_boot_device = CONFIG_SYS_MMC_ENV_DEV;
+
+/*
+ * Select the boot device according to what was set in spl step
+ */
+static int setup_boottargets(void)
+{
+     const char *boot_device =
+             ofnode_get_chosen_prop("u-boot,spl-boot-device");
+
+     if (!boot_device) {
+             debug("%s: /chosen/u-boot,spl-boot-device not set\n",
+                   __func__);
+             return -1;
+     }
+     debug("%s: booted from %s\n", __func__, boot_device);
+
+     if (!strcmp(boot_device, "/dwmmc at ff0f0000")) {
+             /* eMMC boot device */
+             tinker_boot_device = 1;
+     } else {
+             /* sdcard boot device */
+             tinker_boot_device = 0;
+     }
+
+     return 0;
+}
+
  static int get_ethaddr_from_eeprom(u8 *addr)
  {
      int ret;
@@ -33,3 +61,16 @@ int rk3288_board_late_init(void)
 
      return 0;
  }
+
+int misc_init_r(void)
+{
+     setup_boottargets();
+
+     return 0;
+}
+
+int mmc_get_env_dev(void)
+{
+     debug("boot device %d\n", tinker_boot_device);
+     return tinker_boot_device;
+}
configs/tinker-rk3288_defconfig +2 -0
index c851a93f31..106e24e8ca 100644
@@ -13,7 +13,9 @@ CONFIG_DEBUG_UART=y
  CONFIG_TPL_SYS_MALLOC_F_LEN=0x4000
  CONFIG_SPL_SYS_MALLOC_F_LEN=0x4000
  CONFIG_SYS_MALLOC_F_LEN=0x4000
+CONFIG_SPL_OF_LIBFDT=y
  # CONFIG_ANDROID_BOOT_IMAGE is not set
+CONFIG_MISC_INIT_R=y
  CONFIG_USE_PREBOOT=y
  CONFIG_SILENT_CONSOLE=y
  CONFIG_CONSOLE_MUX=y
configs/tinker-s-rk3288_defconfig +0 -0
index c851a93f31..106e24e8ca 100644
@@ -13,7 +13,9 @@ CONFIG_DEBUG_UART=y
  CONFIG_TPL_SYS_MALLOC_F_LEN=0x4000
Quoted 10 lines

configs/tinker-s-rk3288_defconfig CONFIG_DEBUG_UART=y · line 21

Quoted 8 lines
configs/tinker-s-rk3288_defconfig +2 -0
  CONFIG_SPL_SYS_MALLOC_F_LEN=0x4000
  CONFIG_SYS_MALLOC_F_LEN=0x4000
+CONFIG_SPL_OF_LIBFDT=y
  # CONFIG_ANDROID_BOOT_IMAGE is not set
+CONFIG_MISC_INIT_R=y
  CONFIG_USE_PREBOOT=y
  CONFIG_SILENT_CONSOLE=y
  CONFIG_CONSOLE_MUX=y

--

| Michael Nazzareno Trimarchi                     Amarula Solutions BV |
| COO  -  Founder                                      Cruquiuskade 47 |
| +31(0)851119172                                 Amsterdam 1018 AM NL |
|                  [`as] http://www.amarulasolutions.com               |
Signature · 4 lines
| Michael Nazzareno Trimarchi                     Amarula Solutions BV |
| COO  -  Founder                                      Cruquiuskade 47 |
| +31(0)851119172                                 Amsterdam 1018 AM NL |
|                  [`as] http://www.amarulasolutions.com               |
#4 lore raw

RFC PATCH 1/1 rockchip: tinker: Add boot from capability

In reply to Michael Nazzareno Trimarchi
Quoted 9 lines · Michael Nazzareno Trimarchi

Hi Kever

Quoted 6 lines · Kever Yang

Hi Michael,

Quoted 1 line · Michael Trimarchi

We need to know from what device we are booting

Please make sure board_spl_was_booted_from() works for rk3288, which

Quoted 7 lines
Quoted 5 lines

already work for rk3399, after that, we can move those functions from rk3399

only into common code to make everything work.

We are not going to add "spl-boot-device".

That implementation has no sense in my use case. You need fit image. I don't need any special change

I don't understand what you want to do.

The implementation is to get boot device from bootRom and convert it to the device in SPL dt,

why it has no sense?

Thanks,

- Kever

Quoted 180 lines

Michael

Quoted 178 lines

Thanks,

- Kever

Quoted 172 lines

in order
to save the enviroment in right place

---
   arch/arm/dts/rk3288-tinker-s-u-boot.dtsi     |  1 +
   arch/arm/mach-rockchip/rk3288/rk3288.c       | 46 ++++++++++++++++++++
   board/rockchip/tinker_rk3288/tinker-rk3288.c | 41 +++++++++++++++++
   configs/tinker-rk3288_defconfig              |  2 +
   configs/tinker-s-rk3288_defconfig            |  2 +
   5 files changed, 92 insertions(+)
arch/arm/dts/rk3288-tinker-s-u-boot.dtsi +1 -0
index 538593359a..2193127514 100644
@@ -10,6 +10,7 @@
       chosen {
               u-boot,spl-boot-order = \
                       "same-as-spl", &sdmmc, &emmc;
+             u-boot,spl-boot-device = "/dwmmc at ff0f0000";
       };
   };
 
arch/arm/mach-rockchip/rk3288/rk3288.c +46 -0
index 987b4e0d58..002d1508e5 100644
@@ -3,6 +3,8 @@
    * Copyright (c) 2016 Rockchip Electronics Co., Ltd
    */
   #include <common.h>
+#include <spl.h>
+#include <fdt_support.h>
   #include <dm.h>
   #include <env.h>
   #include <clk.h>
@@ -26,6 +28,50 @@ const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = {
       [BROM_BOOTSOURCE_SD] = "/dwmmc at ff0c0000",
   };
 
+#if defined(CONFIG_SPL_BUILD) && !defined(CONFIG_TPL_BUILD)
+const char *spl_decode_boot_device(u32 boot_device)
+{
+     int i;
+     static const struct {
+             u32 boot_device;
+             const char *ofpath;
+     } spl_boot_devices_tbl[] = {
+             { BOOT_DEVICE_MMC2, "/dwmmc at ff0f0000" },
+             { BOOT_DEVICE_MMC1, "/dwmmc at ff0c0000" },
+     };
+
+     for (i = 0; i < ARRAY_SIZE(spl_boot_devices_tbl); ++i)
+             if (spl_boot_devices_tbl[i].boot_device == boot_device)
+                     return spl_boot_devices_tbl[i].ofpath;
+
+     return NULL;
+}
+
+void spl_perform_fixups(struct spl_image_info *spl_image)
+{
+     void *blob = (void *)gd->fdt_blob;
+     const char *boot_ofpath;
+     int chosen;
+
+     if (!blob)
+             return;
+
+     boot_ofpath = spl_decode_boot_device(spl_image->boot_device);
+     if (!boot_ofpath) {
+             pr_err("%s: could not map boot_device to ofpath\n", __func__);
+             return;
+     }
+
+     chosen = fdt_find_or_add_subnode(blob, 0, "chosen");
+     if (chosen < 0) {
+             pr_err("%s: could not find/create '/chosen'\n", __func__);
+             return;
+     }
+     fdt_setprop_string(blob, chosen,
+                        "u-boot,spl-boot-device", boot_ofpath);
+}
+#endif
+
   #ifdef CONFIG_SPL_BUILD
   static void configure_l2ctlr(void)
   {
board/rockchip/tinker_rk3288/tinker-rk3288.c +41 -0
index 6c76c3c25c..66a7394d95 100644
@@ -9,6 +9,34 @@
   #include <i2c_eeprom.h>
   #include <netdev.h>
 
+static int tinker_boot_device = CONFIG_SYS_MMC_ENV_DEV;
+
+/*
+ * Select the boot device according to what was set in spl step
+ */
+static int setup_boottargets(void)
+{
+     const char *boot_device =
+             ofnode_get_chosen_prop("u-boot,spl-boot-device");
+
+     if (!boot_device) {
+             debug("%s: /chosen/u-boot,spl-boot-device not set\n",
+                   __func__);
+             return -1;
+     }
+     debug("%s: booted from %s\n", __func__, boot_device);
+
+     if (!strcmp(boot_device, "/dwmmc at ff0f0000")) {
+             /* eMMC boot device */
+             tinker_boot_device = 1;
+     } else {
+             /* sdcard boot device */
+             tinker_boot_device = 0;
+     }
+
+     return 0;
+}
+
   static int get_ethaddr_from_eeprom(u8 *addr)
   {
       int ret;
@@ -33,3 +61,16 @@ int rk3288_board_late_init(void)
 
       return 0;
   }
+
+int misc_init_r(void)
+{
+     setup_boottargets();
+
+     return 0;
+}
+
+int mmc_get_env_dev(void)
+{
+     debug("boot device %d\n", tinker_boot_device);
+     return tinker_boot_device;
+}
configs/tinker-rk3288_defconfig +2 -0
index c851a93f31..106e24e8ca 100644
@@ -13,7 +13,9 @@ CONFIG_DEBUG_UART=y
   CONFIG_TPL_SYS_MALLOC_F_LEN=0x4000
   CONFIG_SPL_SYS_MALLOC_F_LEN=0x4000
   CONFIG_SYS_MALLOC_F_LEN=0x4000
+CONFIG_SPL_OF_LIBFDT=y
   # CONFIG_ANDROID_BOOT_IMAGE is not set
+CONFIG_MISC_INIT_R=y
   CONFIG_USE_PREBOOT=y
   CONFIG_SILENT_CONSOLE=y
   CONFIG_CONSOLE_MUX=y
configs/tinker-s-rk3288_defconfig +2 -0
index c851a93f31..106e24e8ca 100644
@@ -13,7 +13,9 @@ CONFIG_DEBUG_UART=y
   CONFIG_TPL_SYS_MALLOC_F_LEN=0x4000
   CONFIG_SPL_SYS_MALLOC_F_LEN=0x4000
   CONFIG_SYS_MALLOC_F_LEN=0x4000
+CONFIG_SPL_OF_LIBFDT=y
   # CONFIG_ANDROID_BOOT_IMAGE is not set
+CONFIG_MISC_INIT_R=y
   CONFIG_USE_PREBOOT=y
   CONFIG_SILENT_CONSOLE=y
   CONFIG_CONSOLE_MUX=y
#5 lore raw

RFC PATCH 1/1 rockchip: tinker: Add boot from capability

Hi Kever

Quoted 21 lines · Kever Yang
Quoted 9 lines · Michael Nazzareno Trimarchi

Hi Kever

Quoted 6 lines · Kever Yang

Hi Michael,

Quoted 1 line · Michael Trimarchi

We need to know from what device we are booting

Please make sure board_spl_was_booted_from() works for rk3288, which

Quoted 7 lines
Quoted 5 lines

already work for rk3399, after that, we can move those functions from rk3399

only into common code to make everything work.

We are not going to add "spl-boot-device".

That implementation has no sense in my use case. You need fit image. I don't need any special change

Quoted 6 lines

I don't understand what you want to do.

The implementation is to get boot device from bootRom and convert it to the device in SPL dt,

why it has no sense?

commit 75014470aec60580978962071972f2962695938d

Author: Philipp Tomsich <[email protected]>
Date:   Wed Sep 13 21:29:30 2017 +0200

spl: add a fdt_addr field to spl_image_info

When loading a full U-Boot with detached device-tree using the SPL FIT backend, we should store the address of the FDT loaded as part of the SPL image info: this allows us to fixup the FDT with additional info we may want to propagate onward.

The change rk3399 use is a detached device-tree. This not cover all the use case. I'm using some place holder
to pass the information to next stage without detach it

Michael

Quoted 188 lines

Thanks,

- Kever

Quoted 180 lines

Michael

Quoted 178 lines

Thanks,

- Kever

Quoted 172 lines

in order
to save the enviroment in right place

---
   arch/arm/dts/rk3288-tinker-s-u-boot.dtsi     |  1 +
   arch/arm/mach-rockchip/rk3288/rk3288.c       | 46 ++++++++++++++++++++
   board/rockchip/tinker_rk3288/tinker-rk3288.c | 41 +++++++++++++++++
   configs/tinker-rk3288_defconfig              |  2 +
   configs/tinker-s-rk3288_defconfig            |  2 +
   5 files changed, 92 insertions(+)
arch/arm/dts/rk3288-tinker-s-u-boot.dtsi +1 -0
index 538593359a..2193127514 100644
@@ -10,6 +10,7 @@
       chosen {
               u-boot,spl-boot-order = \
                       "same-as-spl", &sdmmc, &emmc;
+             u-boot,spl-boot-device = "/dwmmc at ff0f0000";
       };
   };
 
arch/arm/mach-rockchip/rk3288/rk3288.c +46 -0
index 987b4e0d58..002d1508e5 100644
@@ -3,6 +3,8 @@
    * Copyright (c) 2016 Rockchip Electronics Co., Ltd
    */
   #include <common.h>
+#include <spl.h>
+#include <fdt_support.h>
   #include <dm.h>
   #include <env.h>
   #include <clk.h>
@@ -26,6 +28,50 @@ const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = {
       [BROM_BOOTSOURCE_SD] = "/dwmmc at ff0c0000",
   };
 
+#if defined(CONFIG_SPL_BUILD) && !defined(CONFIG_TPL_BUILD)
+const char *spl_decode_boot_device(u32 boot_device)
+{
+     int i;
+     static const struct {
+             u32 boot_device;
+             const char *ofpath;
+     } spl_boot_devices_tbl[] = {
+             { BOOT_DEVICE_MMC2, "/dwmmc at ff0f0000" },
+             { BOOT_DEVICE_MMC1, "/dwmmc at ff0c0000" },
+     };
+
+     for (i = 0; i < ARRAY_SIZE(spl_boot_devices_tbl); ++i)
+             if (spl_boot_devices_tbl[i].boot_device == boot_device)
+                     return spl_boot_devices_tbl[i].ofpath;
+
+     return NULL;
+}
+
+void spl_perform_fixups(struct spl_image_info *spl_image)
+{
+     void *blob = (void *)gd->fdt_blob;
+     const char *boot_ofpath;
+     int chosen;
+
+     if (!blob)
+             return;
+
+     boot_ofpath = spl_decode_boot_device(spl_image->boot_device);
+     if (!boot_ofpath) {
+             pr_err("%s: could not map boot_device to ofpath\n", __func__);
+             return;
+     }
+
+     chosen = fdt_find_or_add_subnode(blob, 0, "chosen");
+     if (chosen < 0) {
+             pr_err("%s: could not find/create '/chosen'\n", __func__);
+             return;
+     }
+     fdt_setprop_string(blob, chosen,
+                        "u-boot,spl-boot-device", boot_ofpath);
+}
+#endif
+
   #ifdef CONFIG_SPL_BUILD
   static void configure_l2ctlr(void)
   {
board/rockchip/tinker_rk3288/tinker-rk3288.c +41 -0
index 6c76c3c25c..66a7394d95 100644
@@ -9,6 +9,34 @@
   #include <i2c_eeprom.h>
   #include <netdev.h>
 
+static int tinker_boot_device = CONFIG_SYS_MMC_ENV_DEV;
+
+/*
+ * Select the boot device according to what was set in spl step
+ */
+static int setup_boottargets(void)
+{
+     const char *boot_device =
+             ofnode_get_chosen_prop("u-boot,spl-boot-device");
+
+     if (!boot_device) {
+             debug("%s: /chosen/u-boot,spl-boot-device not set\n",
+                   __func__);
+             return -1;
+     }
+     debug("%s: booted from %s\n", __func__, boot_device);
+
+     if (!strcmp(boot_device, "/dwmmc at ff0f0000")) {
+             /* eMMC boot device */
+             tinker_boot_device = 1;
+     } else {
+             /* sdcard boot device */
+             tinker_boot_device = 0;
+     }
+
+     return 0;
+}
+
   static int get_ethaddr_from_eeprom(u8 *addr)
   {
       int ret;
@@ -33,3 +61,16 @@ int rk3288_board_late_init(void)
 
       return 0;
   }
+
+int misc_init_r(void)
+{
+     setup_boottargets();
+
+     return 0;
+}
+
+int mmc_get_env_dev(void)
+{
+     debug("boot device %d\n", tinker_boot_device);
+     return tinker_boot_device;
+}
configs/tinker-rk3288_defconfig +2 -0
index c851a93f31..106e24e8ca 100644
@@ -13,7 +13,9 @@ CONFIG_DEBUG_UART=y
   CONFIG_TPL_SYS_MALLOC_F_LEN=0x4000
   CONFIG_SPL_SYS_MALLOC_F_LEN=0x4000
   CONFIG_SYS_MALLOC_F_LEN=0x4000
+CONFIG_SPL_OF_LIBFDT=y
   # CONFIG_ANDROID_BOOT_IMAGE is not set
+CONFIG_MISC_INIT_R=y
   CONFIG_USE_PREBOOT=y
   CONFIG_SILENT_CONSOLE=y
   CONFIG_CONSOLE_MUX=y
configs/tinker-s-rk3288_defconfig +2 -0
index c851a93f31..106e24e8ca 100644
@@ -13,7 +13,9 @@ CONFIG_DEBUG_UART=y
   CONFIG_TPL_SYS_MALLOC_F_LEN=0x4000
   CONFIG_SPL_SYS_MALLOC_F_LEN=0x4000
   CONFIG_SYS_MALLOC_F_LEN=0x4000
+CONFIG_SPL_OF_LIBFDT=y
   # CONFIG_ANDROID_BOOT_IMAGE is not set
+CONFIG_MISC_INIT_R=y
   CONFIG_USE_PREBOOT=y
   CONFIG_SILENT_CONSOLE=y
   CONFIG_CONSOLE_MUX=y
Signature · 4 lines
| Michael Nazzareno Trimarchi                     Amarula Solutions BV |
| COO  -  Founder                                      Cruquiuskade 47 |
| +31(0)851119172                                 Amsterdam 1018 AM NL |
|                  [`as] http://www.amarulasolutions.com               |
#6 lore raw

RFC PATCH 1/1 rockchip: tinker: Add boot from capability

Hi

Drop it

+int mmc_get_env_dev(void)
+{
+ u32 bootdevice_brom_id = readl(BROM_BOOTSOURCE_ID_ADDR);
+
+ if (bootdevice_brom_id == BROM_BOOTSOURCE_EMMC)
+ return 0;
+
+ return 1;
+}

THis is enough for tinker

Michael

Quoted 246 lines · Michael Nazzareno Trimarchi

Hi Kever

Quoted 21 lines · Kever Yang
Quoted 9 lines · Michael Nazzareno Trimarchi

Hi Kever

Quoted 6 lines · Kever Yang

Hi Michael,

Quoted 1 line · Michael Trimarchi

We need to know from what device we are booting

Please make sure board_spl_was_booted_from() works for rk3288, which

Quoted 7 lines
Quoted 5 lines

already work for rk3399, after that, we can move those functions from rk3399

only into common code to make everything work.

We are not going to add "spl-boot-device".

That implementation has no sense in my use case. You need fit image. I don't need any special change

Quoted 6 lines

I don't understand what you want to do.

The implementation is to get boot device from bootRom and convert it to the device in SPL dt,

why it has no sense?

commit 75014470aec60580978962071972f2962695938d

Author: Philipp Tomsich <[email protected]>
Date:   Wed Sep 13 21:29:30 2017 +0200

spl: add a fdt_addr field to spl_image_info

When loading a full U-Boot with detached device-tree using the SPL FIT backend, we should store the address of the FDT loaded as part of the SPL image info: this allows us to fixup the FDT with additional info we may want to propagate onward.

The change rk3399 use is a detached device-tree. This not cover all the use case. I'm using some place holder
to pass the information to next stage without detach it

Michael

Quoted 188 lines

Thanks,

- Kever

Quoted 180 lines

Michael

Quoted 178 lines

Thanks,

- Kever

Quoted 172 lines

in order
to save the enviroment in right place

---
   arch/arm/dts/rk3288-tinker-s-u-boot.dtsi     |  1 +
   arch/arm/mach-rockchip/rk3288/rk3288.c       | 46 ++++++++++++++++++++
   board/rockchip/tinker_rk3288/tinker-rk3288.c | 41 +++++++++++++++++
   configs/tinker-rk3288_defconfig              |  2 +
   configs/tinker-s-rk3288_defconfig            |  2 +
   5 files changed, 92 insertions(+)
arch/arm/dts/rk3288-tinker-s-u-boot.dtsi +1 -0
index 538593359a..2193127514 100644
@@ -10,6 +10,7 @@
       chosen {
               u-boot,spl-boot-order = \
                       "same-as-spl", &sdmmc, &emmc;
+             u-boot,spl-boot-device = "/dwmmc at ff0f0000";
       };
   };
 
arch/arm/mach-rockchip/rk3288/rk3288.c +46 -0
index 987b4e0d58..002d1508e5 100644
@@ -3,6 +3,8 @@
    * Copyright (c) 2016 Rockchip Electronics Co., Ltd
    */
   #include <common.h>
+#include <spl.h>
+#include <fdt_support.h>
   #include <dm.h>
   #include <env.h>
   #include <clk.h>
@@ -26,6 +28,50 @@ const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = {
       [BROM_BOOTSOURCE_SD] = "/dwmmc at ff0c0000",
   };
 
+#if defined(CONFIG_SPL_BUILD) && !defined(CONFIG_TPL_BUILD)
+const char *spl_decode_boot_device(u32 boot_device)
+{
+     int i;
+     static const struct {
+             u32 boot_device;
+             const char *ofpath;
+     } spl_boot_devices_tbl[] = {
+             { BOOT_DEVICE_MMC2, "/dwmmc at ff0f0000" },
+             { BOOT_DEVICE_MMC1, "/dwmmc at ff0c0000" },
+     };
+
+     for (i = 0; i < ARRAY_SIZE(spl_boot_devices_tbl); ++i)
+             if (spl_boot_devices_tbl[i].boot_device == boot_device)
+                     return spl_boot_devices_tbl[i].ofpath;
+
+     return NULL;
+}
+
+void spl_perform_fixups(struct spl_image_info *spl_image)
+{
+     void *blob = (void *)gd->fdt_blob;
+     const char *boot_ofpath;
+     int chosen;
+
+     if (!blob)
+             return;
+
+     boot_ofpath = spl_decode_boot_device(spl_image->boot_device);
+     if (!boot_ofpath) {
+             pr_err("%s: could not map boot_device to ofpath\n", __func__);
+             return;
+     }
+
+     chosen = fdt_find_or_add_subnode(blob, 0, "chosen");
+     if (chosen < 0) {
+             pr_err("%s: could not find/create '/chosen'\n", __func__);
+             return;
+     }
+     fdt_setprop_string(blob, chosen,
+                        "u-boot,spl-boot-device", boot_ofpath);
+}
+#endif
+
   #ifdef CONFIG_SPL_BUILD
   static void configure_l2ctlr(void)
   {
board/rockchip/tinker_rk3288/tinker-rk3288.c +41 -0
index 6c76c3c25c..66a7394d95 100644
@@ -9,6 +9,34 @@
   #include <i2c_eeprom.h>
   #include <netdev.h>
 
+static int tinker_boot_device = CONFIG_SYS_MMC_ENV_DEV;
+
+/*
+ * Select the boot device according to what was set in spl step
+ */
+static int setup_boottargets(void)
+{
+     const char *boot_device =
+             ofnode_get_chosen_prop("u-boot,spl-boot-device");
+
+     if (!boot_device) {
+             debug("%s: /chosen/u-boot,spl-boot-device not set\n",
+                   __func__);
+             return -1;
+     }
+     debug("%s: booted from %s\n", __func__, boot_device);
+
+     if (!strcmp(boot_device, "/dwmmc at ff0f0000")) {
+             /* eMMC boot device */
+             tinker_boot_device = 1;
+     } else {
+             /* sdcard boot device */
+             tinker_boot_device = 0;
+     }
+
+     return 0;
+}
+
   static int get_ethaddr_from_eeprom(u8 *addr)
   {
       int ret;
@@ -33,3 +61,16 @@ int rk3288_board_late_init(void)
 
       return 0;
   }
+
+int misc_init_r(void)
+{
+     setup_boottargets();
+
+     return 0;
+}
+
+int mmc_get_env_dev(void)
+{
+     debug("boot device %d\n", tinker_boot_device);
+     return tinker_boot_device;
+}
configs/tinker-rk3288_defconfig +2 -0
index c851a93f31..106e24e8ca 100644
@@ -13,7 +13,9 @@ CONFIG_DEBUG_UART=y
   CONFIG_TPL_SYS_MALLOC_F_LEN=0x4000
   CONFIG_SPL_SYS_MALLOC_F_LEN=0x4000
   CONFIG_SYS_MALLOC_F_LEN=0x4000
+CONFIG_SPL_OF_LIBFDT=y
   # CONFIG_ANDROID_BOOT_IMAGE is not set
+CONFIG_MISC_INIT_R=y
   CONFIG_USE_PREBOOT=y
   CONFIG_SILENT_CONSOLE=y
   CONFIG_CONSOLE_MUX=y
configs/tinker-s-rk3288_defconfig +2 -0
index c851a93f31..106e24e8ca 100644
@@ -13,7 +13,9 @@ CONFIG_DEBUG_UART=y
   CONFIG_TPL_SYS_MALLOC_F_LEN=0x4000
   CONFIG_SPL_SYS_MALLOC_F_LEN=0x4000
   CONFIG_SYS_MALLOC_F_LEN=0x4000
+CONFIG_SPL_OF_LIBFDT=y
   # CONFIG_ANDROID_BOOT_IMAGE is not set
+CONFIG_MISC_INIT_R=y
   CONFIG_USE_PREBOOT=y
   CONFIG_SILENT_CONSOLE=y
   CONFIG_CONSOLE_MUX=y

--

| Michael Nazzareno Trimarchi                     Amarula Solutions BV |
| COO  -  Founder                                      Cruquiuskade 47 |
| +31(0)851119172                                 Amsterdam 1018 AM NL |
|                  [`as] http://www.amarulasolutions.com               |
Signature · 4 lines
| Michael Nazzareno Trimarchi                     Amarula Solutions BV |
| COO  -  Founder                                      Cruquiuskade 47 |
| +31(0)851119172                                 Amsterdam 1018 AM NL |
|                  [`as] http://www.amarulasolutions.com               |