Skip to contentSkip to conversation

arm: mvebu: turris_mox: Add support for distroboot $fdt_addr

PATCH In review Pali Rohár 2 participants 3 messages Aug 29, 2022 – Sep 13, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm: mvebu: turris_mox: Add support for distroboot $fdt_addr

$fdt_addr is mandatory for systems which provides DTB in HW (e.g. ROM) and wishes to pass that DTB to Linux.

Turris Mox contains DTB binary in SPI NOR memory at "dtb" partition which starts at offset 0x7f0000 and is 0x10000 bytes long.

Armada 3700 CPU does not allow mapping SPI NOR memory into physical address space like on other architectures and therefore set $fdt_addr variable to memory range in RAM and loads this DTB binary from SPI NOR in misc_init_r() function.

---
 board/CZ.NIC/turris_mox/turris_mox.c | 48 ++++++++++++++++++++++++++++
 include/configs/turris_mox.h         |  1 +
 2 files changed, 49 insertions(+)
board/CZ.NIC/turris_mox/turris_mox.c +48 -0
index 3dbd68e52366..3402515bbae2 100644
@@ -23,6 +23,7 @@
 #include <linux/string.h>
 #include <miiphy.h>
 #include <spi.h>
+#include <spi_flash.h>
 
 #include "mox_sp.h"
 
@@ -339,6 +340,51 @@ static int get_reset_gpio(struct gpio_desc *reset_gpio)
 	return 0;
 }
 
+/* Load default system DTB binary to $fdr_addr */
+static void load_spi_dtb(void)
+{
+	const char *const env_name[1] = { "fdt_addr" };
+	unsigned long size, offset;
+	struct udevice *spi_dev;
+	struct spi_flash *flash;
+	const char *addr_str;
+	unsigned long addr;
+	void *buf;
+
+	addr_str = env_get(env_name[0]);
+	if (!addr_str) {
+		env_set_default_vars(1, (char * const *)env_name, 0);
+		addr_str = env_get(env_name[0]);
+	}
+
+	if (!addr_str)
+		return;
+
+	addr = hextoul(addr_str, NULL);
+	if (!addr)
+		return;
+
+	spi_flash_probe_bus_cs(CONFIG_SF_DEFAULT_BUS, CONFIG_SF_DEFAULT_CS, &spi_dev);
+	flash = dev_get_uclass_priv(spi_dev);
+	if (!flash)
+		return;
+
+	/*
+	 * SPI NOR "dtb" partition offset & size hardcoded for now because the
+	 * mtd subsystem does not offer finding the partition yet and we do not
+	 * want to reimplement OF partition parser here.
+	 */
+	offset = 0x7f0000;
+	size = 0x10000;
+
+	buf = map_physmem(addr, size, MAP_WRBACK);
+	if (!buf)
+		return;
+
+	spi_flash_read(flash, offset, size, buf);
+	unmap_physmem(buf, size);
+}
+
 int misc_init_r(void)
 {
 	u8 mac[2][6];
@@ -358,6 +404,8 @@ int misc_init_r(void)
 			eth_env_set_enetaddr_by_index("eth", i, mac[i]);
 	}
 
+	load_spi_dtb();
+
 	return 0;
 }
 
include/configs/turris_mox.h +1 -0
index b8ff705ac923..f549f9f7ad06 100644
@@ -36,6 +36,7 @@
 	"bootm 0x5800000"
 
 #define CONFIG_EXTRA_ENV_SETTINGS				\
+	"fdt_addr=0x4c00000\0"					\
 	"scriptaddr=0x4d00000\0"				\
 	"pxefile_addr_r=0x4e00000\0"				\
 	"fdt_addr_r=0x4f00000\0"				\
Signature · 1 line
2.20.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Pali Rohár

$fdt_addr is mandatory for systems which provides DTB in HW (e.g. ROM) and wishes to pass that DTB to Linux.

Turris Mox contains DTB binary in SPI NOR memory at "dtb" partition which starts at offset 0x7f0000 and is 0x10000 bytes long.

Quoted 6 lines

Armada 3700 CPU does not allow mapping SPI NOR memory into physical address space like on other architectures and therefore set $fdt_addr variable to memory range in RAM and loads this DTB binary from SPI NOR in misc_init_r() function.

Thanks,
Stefan

Quoted 83 lines
---
  board/CZ.NIC/turris_mox/turris_mox.c | 48 ++++++++++++++++++++++++++++
  include/configs/turris_mox.h         |  1 +
  2 files changed, 49 insertions(+)
board/CZ.NIC/turris_mox/turris_mox.c +48 -0
index 3dbd68e52366..3402515bbae2 100644
@@ -23,6 +23,7 @@
  #include <linux/string.h>
  #include <miiphy.h>
  #include <spi.h>
+#include <spi_flash.h>
 
  #include "mox_sp.h"
 
@@ -339,6 +340,51 @@ static int get_reset_gpio(struct gpio_desc *reset_gpio)
  	return 0;
  }
 
+/* Load default system DTB binary to $fdr_addr */
+static void load_spi_dtb(void)
+{
+	const char *const env_name[1] = { "fdt_addr" };
+	unsigned long size, offset;
+	struct udevice *spi_dev;
+	struct spi_flash *flash;
+	const char *addr_str;
+	unsigned long addr;
+	void *buf;
+
+	addr_str = env_get(env_name[0]);
+	if (!addr_str) {
+		env_set_default_vars(1, (char * const *)env_name, 0);
+		addr_str = env_get(env_name[0]);
+	}
+
+	if (!addr_str)
+		return;
+
+	addr = hextoul(addr_str, NULL);
+	if (!addr)
+		return;
+
+	spi_flash_probe_bus_cs(CONFIG_SF_DEFAULT_BUS, CONFIG_SF_DEFAULT_CS, &spi_dev);
+	flash = dev_get_uclass_priv(spi_dev);
+	if (!flash)
+		return;
+
+	/*
+	 * SPI NOR "dtb" partition offset & size hardcoded for now because the
+	 * mtd subsystem does not offer finding the partition yet and we do not
+	 * want to reimplement OF partition parser here.
+	 */
+	offset = 0x7f0000;
+	size = 0x10000;
+
+	buf = map_physmem(addr, size, MAP_WRBACK);
+	if (!buf)
+		return;
+
+	spi_flash_read(flash, offset, size, buf);
+	unmap_physmem(buf, size);
+}
+
  int misc_init_r(void)
  {
  	u8 mac[2][6];
@@ -358,6 +404,8 @@ int misc_init_r(void)
  			eth_env_set_enetaddr_by_index("eth", i, mac[i]);
  	}
 
+	load_spi_dtb();
+
  	return 0;
  }
 
include/configs/turris_mox.h +0 -0
index b8ff705ac923..f549f9f7ad06 100644

include/configs/turris_mox.h line 42

Quoted 7 lines
include/configs/turris_mox.h +1 -0
@@ -36,6 +36,7 @@
  	"bootm 0x5800000"
 
  #define CONFIG_EXTRA_ENV_SETTINGS				\
+	"fdt_addr=0x4c00000\0"					\
  	"scriptaddr=0x4d00000\0"				\
  	"pxefile_addr_r=0x4e00000\0"				\
  	"fdt_addr_r=0x4f00000\0"				\

Viele Grüße,
Stefan Roese

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]
#2 lore raw
In reply to Pali Rohár
Quoted 6 lines · Pali Rohár

$fdt_addr is mandatory for systems which provides DTB in HW (e.g. ROM) and wishes to pass that DTB to Linux.

Turris Mox contains DTB binary in SPI NOR memory at "dtb" partition which starts at offset 0x7f0000 and is 0x10000 bytes long.

Quoted 6 lines

Armada 3700 CPU does not allow mapping SPI NOR memory into physical address space like on other architectures and therefore set $fdt_addr variable to memory range in RAM and loads this DTB binary from SPI NOR in misc_init_r() function.

Applied to u-boot-marvell/master

Thanks,
Stefan

Quoted 83 lines
---
  board/CZ.NIC/turris_mox/turris_mox.c | 48 ++++++++++++++++++++++++++++
  include/configs/turris_mox.h         |  1 +
  2 files changed, 49 insertions(+)
board/CZ.NIC/turris_mox/turris_mox.c +48 -0
index 3dbd68e52366..3402515bbae2 100644
@@ -23,6 +23,7 @@
  #include <linux/string.h>
  #include <miiphy.h>
  #include <spi.h>
+#include <spi_flash.h>
 
  #include "mox_sp.h"
 
@@ -339,6 +340,51 @@ static int get_reset_gpio(struct gpio_desc *reset_gpio)
  	return 0;
  }
 
+/* Load default system DTB binary to $fdr_addr */
+static void load_spi_dtb(void)
+{
+	const char *const env_name[1] = { "fdt_addr" };
+	unsigned long size, offset;
+	struct udevice *spi_dev;
+	struct spi_flash *flash;
+	const char *addr_str;
+	unsigned long addr;
+	void *buf;
+
+	addr_str = env_get(env_name[0]);
+	if (!addr_str) {
+		env_set_default_vars(1, (char * const *)env_name, 0);
+		addr_str = env_get(env_name[0]);
+	}
+
+	if (!addr_str)
+		return;
+
+	addr = hextoul(addr_str, NULL);
+	if (!addr)
+		return;
+
+	spi_flash_probe_bus_cs(CONFIG_SF_DEFAULT_BUS, CONFIG_SF_DEFAULT_CS, &spi_dev);
+	flash = dev_get_uclass_priv(spi_dev);
+	if (!flash)
+		return;
+
+	/*
+	 * SPI NOR "dtb" partition offset & size hardcoded for now because the
+	 * mtd subsystem does not offer finding the partition yet and we do not
+	 * want to reimplement OF partition parser here.
+	 */
+	offset = 0x7f0000;
+	size = 0x10000;
+
+	buf = map_physmem(addr, size, MAP_WRBACK);
+	if (!buf)
+		return;
+
+	spi_flash_read(flash, offset, size, buf);
+	unmap_physmem(buf, size);
+}
+
  int misc_init_r(void)
  {
  	u8 mac[2][6];
@@ -358,6 +404,8 @@ int misc_init_r(void)
  			eth_env_set_enetaddr_by_index("eth", i, mac[i]);
  	}
 
+	load_spi_dtb();
+
  	return 0;
  }
 
include/configs/turris_mox.h +0 -0
index b8ff705ac923..f549f9f7ad06 100644

include/configs/turris_mox.h line 42

Quoted 7 lines
include/configs/turris_mox.h +1 -0
@@ -36,6 +36,7 @@
  	"bootm 0x5800000"
 
  #define CONFIG_EXTRA_ENV_SETTINGS				\
+	"fdt_addr=0x4c00000\0"					\
  	"scriptaddr=0x4d00000\0"				\
  	"pxefile_addr_r=0x4e00000\0"				\
  	"fdt_addr_r=0x4f00000\0"				\

Viele Grüße,
Stefan Roese

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]