All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH u-boot-mvebu 1/2] ARM: dts: armada-385-turris-omnia: add `u-boot-env` NOR partition
@ 2021-07-15 17:21 Marek Behún
  2021-07-15 17:21 ` [PATCH u-boot-mvebu 2/2] arm: mvebu: turris_omnia: fixup MTD partitions in Linux' DTB Marek Behún
  2021-07-19  7:04 ` [PATCH u-boot-mvebu 1/2] ARM: dts: armada-385-turris-omnia: add `u-boot-env` NOR partition Stefan Roese
  0 siblings, 2 replies; 4+ messages in thread
From: Marek Behún @ 2021-07-15 17:21 UTC (permalink / raw
  To: Stefan Roese; +Cc: u-boot, pali, Marek Behún

Specify a separate partition `u-boot-env` for U-Boot's env settings for
the Turris Omnia board.

Do this only in U-Boot's specific DTS. We do not want to do this in
Linux' official DTS, because Omnia's stock U-Boot stores env at a
different address, and there are still boards with stock U-Boot.

In a subsequent patch will add board code that fixes Linux's DTB before
booting Linux.

Signed-off-by: Marek Behún <marek.behun@nic.cz>
---
 arch/arm/dts/armada-385-turris-omnia-u-boot.dtsi | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/arch/arm/dts/armada-385-turris-omnia-u-boot.dtsi b/arch/arm/dts/armada-385-turris-omnia-u-boot.dtsi
index af0655daaa..3ff76c9462 100644
--- a/arch/arm/dts/armada-385-turris-omnia-u-boot.dtsi
+++ b/arch/arm/dts/armada-385-turris-omnia-u-boot.dtsi
@@ -43,6 +43,17 @@
 
 	spi-nor@0 {
 		u-boot,dm-pre-reloc;
+
+		partitions {
+			partition@0 {
+				reg = <0x0 CONFIG_ENV_OFFSET>;
+			};
+
+			partition@f0000 {
+				reg = <CONFIG_ENV_OFFSET CONFIG_ENV_SIZE>;
+				label = "u-boot-env";
+			};
+		};
 	};
 };
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH u-boot-mvebu 2/2] arm: mvebu: turris_omnia: fixup MTD partitions in Linux' DTB
  2021-07-15 17:21 [PATCH u-boot-mvebu 1/2] ARM: dts: armada-385-turris-omnia: add `u-boot-env` NOR partition Marek Behún
@ 2021-07-15 17:21 ` Marek Behún
  2021-07-19  7:03   ` Stefan Roese
  2021-07-19  7:04 ` [PATCH u-boot-mvebu 1/2] ARM: dts: armada-385-turris-omnia: add `u-boot-env` NOR partition Stefan Roese
  1 sibling, 1 reply; 4+ messages in thread
From: Marek Behún @ 2021-07-15 17:21 UTC (permalink / raw
  To: Stefan Roese; +Cc: u-boot, pali, Marek Behún

Fixup SPI NOR partition nodes in Linux' device tree prior booting Linux.

Linux' devicetree does not contain "u-boot-env" partition and we do not
want to add it there because the address is different between stock
U-Boot and current upstream U-Boot.

Instead we add code that recreates partition nodes from scratch
according to how U-Boot sees them (which is defined in U-Boot's device
tree).

Signed-off-by: Marek Behún <marek.behun@nic.cz>
---
Hi Stefan,

the code of the fixup_mtd_partitions() function I am adding with this
patch is generic enough to be potentially used on other boards (for
example EspressoBIN's board code does something similar, so it could use
this function).

Indeed I want to generalize it, since there are multiple boards fixing
partition nodes in DTS prior booting Linux and there is already code for
this in common/fdt_support.c. The problem is that that code does not work
with DM_MTD, but rather with the obsolete MTDPARTS and several boards use
it. I want to convert those boards into using this new API, but this will
take some time and should be done via u-boot-spi tree.

So please for now merge this code via the mvebu tree. In the meantime
till this is merged into Tom's tree I shall be working on converting
those other boards that use fdt_fixup_mtdparts() to use device tree for
defining MTD partitions so that we can remove fdt_fixup_mtdparts(), move
this new code into common/fdt_support.c and covert those boards to use
this new code.
---
 board/CZ.NIC/turris_omnia/turris_omnia.c | 90 ++++++++++++++++++++++++
 configs/turris_omnia_defconfig           |  1 +
 2 files changed, 91 insertions(+)

diff --git a/board/CZ.NIC/turris_omnia/turris_omnia.c b/board/CZ.NIC/turris_omnia/turris_omnia.c
index 8b2f94f959..a7e5f56eed 100644
--- a/board/CZ.NIC/turris_omnia/turris_omnia.c
+++ b/board/CZ.NIC/turris_omnia/turris_omnia.c
@@ -13,6 +13,7 @@
 #include <init.h>
 #include <log.h>
 #include <miiphy.h>
+#include <mtd.h>
 #include <net.h>
 #include <netdev.h>
 #include <asm/global_data.h>
@@ -31,6 +32,8 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
+#define OMNIA_SPI_NOR_PATH		"/soc/spi@10600/spi-nor@0"
+
 #define OMNIA_I2C_BUS_NAME		"i2c@11000->i2cmux@70->i2c@0"
 
 #define OMNIA_I2C_MCU_CHIP_ADDR		0x2a
@@ -557,3 +560,90 @@ out:
 	return 0;
 }
 
+#if defined(CONFIG_OF_BOARD_SETUP)
+/*
+ * I plan to generalize this function and move it to common/fdt_support.c.
+ * This will require some more work on multiple boards, though, so for now leave
+ * it here.
+ */
+static bool fixup_mtd_partitions(void *blob, int offset, struct mtd_info *mtd)
+{
+	struct mtd_info *slave;
+	int parts;
+
+	parts = fdt_subnode_offset(blob, offset, "partitions");
+	if (parts < 0)
+		return false;
+
+	if (fdt_del_node(blob, parts) < 0)
+		return false;
+
+	parts = fdt_add_subnode(blob, offset, "partitions");
+	if (parts < 0)
+		return false;
+
+	if (fdt_setprop_u32(blob, parts, "#address-cells", 1) < 0)
+		return false;
+
+	if (fdt_setprop_u32(blob, parts, "#size-cells", 1) < 0)
+		return false;
+
+	if (fdt_setprop_string(blob, parts, "compatible",
+			       "fixed-partitions") < 0)
+		return false;
+
+	mtd_probe_devices();
+
+	list_for_each_entry(slave, &mtd->partitions, node) {
+		char name[32];
+		int part;
+
+		snprintf(name, sizeof(name), "partition@%llx", slave->offset);
+		part = fdt_add_subnode(blob, parts, name);
+		if (part < 0)
+			return false;
+
+		if (fdt_setprop_u32(blob, part, "reg", slave->offset) < 0)
+			return false;
+
+		if (fdt_appendprop_u32(blob, part, "reg", slave->size) < 0)
+			return false;
+
+		if (fdt_setprop_string(blob, part, "label", slave->name) < 0)
+			return false;
+
+		if (!(slave->flags & MTD_WRITEABLE))
+			if (fdt_setprop_empty(blob, part, "read-only") < 0)
+				return false;
+
+		if (slave->flags & MTD_POWERUP_LOCK)
+			if (fdt_setprop_empty(blob, part, "lock") < 0)
+				return false;
+	}
+
+	return true;
+}
+
+int ft_board_setup(void *blob, struct bd_info *bd)
+{
+	struct mtd_info *mtd;
+	int node;
+
+	mtd = get_mtd_device_nm(OMNIA_SPI_NOR_PATH);
+	if (IS_ERR_OR_NULL(mtd))
+		goto fail;
+
+	node = fdt_path_offset(blob, OMNIA_SPI_NOR_PATH);
+	if (node < 0)
+		goto fail;
+
+	if (!fixup_mtd_partitions(blob, node, mtd))
+		goto fail;
+
+	return 0;
+
+fail:
+	printf("Failed fixing SPI NOR partitions!\n");
+	return 0;
+}
+#endif
diff --git a/configs/turris_omnia_defconfig b/configs/turris_omnia_defconfig
index f860cf5e7d..5f7b1a67a2 100644
--- a/configs/turris_omnia_defconfig
+++ b/configs/turris_omnia_defconfig
@@ -23,6 +23,7 @@ CONFIG_SPL=y
 CONFIG_DEBUG_UART_BASE=0xd0012000
 CONFIG_DEBUG_UART_CLOCK=250000000
 CONFIG_DEBUG_UART=y
+CONFIG_OF_BOARD_SETUP=y
 CONFIG_AHCI=y
 CONFIG_DISTRO_DEFAULTS=y
 CONFIG_FIT=y
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH u-boot-mvebu 2/2] arm: mvebu: turris_omnia: fixup MTD partitions in Linux' DTB
  2021-07-15 17:21 ` [PATCH u-boot-mvebu 2/2] arm: mvebu: turris_omnia: fixup MTD partitions in Linux' DTB Marek Behún
@ 2021-07-19  7:03   ` Stefan Roese
  0 siblings, 0 replies; 4+ messages in thread
From: Stefan Roese @ 2021-07-19  7:03 UTC (permalink / raw
  To: Marek Behún; +Cc: u-boot, pali

Hi Marek,

On 15.07.21 19:21, Marek Behún wrote:
> Fixup SPI NOR partition nodes in Linux' device tree prior booting Linux.
> 
> Linux' devicetree does not contain "u-boot-env" partition and we do not
> want to add it there because the address is different between stock
> U-Boot and current upstream U-Boot.
> 
> Instead we add code that recreates partition nodes from scratch
> according to how U-Boot sees them (which is defined in U-Boot's device
> tree).
> 
> Signed-off-by: Marek Behún <marek.behun@nic.cz>
> ---
> Hi Stefan,
> 
> the code of the fixup_mtd_partitions() function I am adding with this
> patch is generic enough to be potentially used on other boards (for
> example EspressoBIN's board code does something similar, so it could use
> this function).
> 
> Indeed I want to generalize it, since there are multiple boards fixing
> partition nodes in DTS prior booting Linux and there is already code for
> this in common/fdt_support.c. The problem is that that code does not work
> with DM_MTD, but rather with the obsolete MTDPARTS and several boards use
> it. I want to convert those boards into using this new API, but this will
> take some time and should be done via u-boot-spi tree.
> 
> So please for now merge this code via the mvebu tree. In the meantime
> till this is merged into Tom's tree I shall be working on converting
> those other boards that use fdt_fixup_mtdparts() to use device tree for
> defining MTD partitions so that we can remove fdt_fixup_mtdparts(), move
> this new code into common/fdt_support.c and covert those boards to use
> this new code.

Thanks for the details explanation and also thanks for working on this
generalization of this "feature".

With this background:

Reviewed-by: Stefan Roese <sr@denx.de>

Thanks,
Stefan

> ---
>   board/CZ.NIC/turris_omnia/turris_omnia.c | 90 ++++++++++++++++++++++++
>   configs/turris_omnia_defconfig           |  1 +
>   2 files changed, 91 insertions(+)
> 
> diff --git a/board/CZ.NIC/turris_omnia/turris_omnia.c b/board/CZ.NIC/turris_omnia/turris_omnia.c
> index 8b2f94f959..a7e5f56eed 100644
> --- a/board/CZ.NIC/turris_omnia/turris_omnia.c
> +++ b/board/CZ.NIC/turris_omnia/turris_omnia.c
> @@ -13,6 +13,7 @@
>   #include <init.h>
>   #include <log.h>
>   #include <miiphy.h>
> +#include <mtd.h>
>   #include <net.h>
>   #include <netdev.h>
>   #include <asm/global_data.h>
> @@ -31,6 +32,8 @@
>   
>   DECLARE_GLOBAL_DATA_PTR;
>   
> +#define OMNIA_SPI_NOR_PATH		"/soc/spi@10600/spi-nor@0"
> +
>   #define OMNIA_I2C_BUS_NAME		"i2c@11000->i2cmux@70->i2c@0"
>   
>   #define OMNIA_I2C_MCU_CHIP_ADDR		0x2a
> @@ -557,3 +560,90 @@ out:
>   	return 0;
>   }
>   
> +#if defined(CONFIG_OF_BOARD_SETUP)
> +/*
> + * I plan to generalize this function and move it to common/fdt_support.c.
> + * This will require some more work on multiple boards, though, so for now leave
> + * it here.
> + */
> +static bool fixup_mtd_partitions(void *blob, int offset, struct mtd_info *mtd)
> +{
> +	struct mtd_info *slave;
> +	int parts;
> +
> +	parts = fdt_subnode_offset(blob, offset, "partitions");
> +	if (parts < 0)
> +		return false;
> +
> +	if (fdt_del_node(blob, parts) < 0)
> +		return false;
> +
> +	parts = fdt_add_subnode(blob, offset, "partitions");
> +	if (parts < 0)
> +		return false;
> +
> +	if (fdt_setprop_u32(blob, parts, "#address-cells", 1) < 0)
> +		return false;
> +
> +	if (fdt_setprop_u32(blob, parts, "#size-cells", 1) < 0)
> +		return false;
> +
> +	if (fdt_setprop_string(blob, parts, "compatible",
> +			       "fixed-partitions") < 0)
> +		return false;
> +
> +	mtd_probe_devices();
> +
> +	list_for_each_entry(slave, &mtd->partitions, node) {
> +		char name[32];
> +		int part;
> +
> +		snprintf(name, sizeof(name), "partition@%llx", slave->offset);
> +		part = fdt_add_subnode(blob, parts, name);
> +		if (part < 0)
> +			return false;
> +
> +		if (fdt_setprop_u32(blob, part, "reg", slave->offset) < 0)
> +			return false;
> +
> +		if (fdt_appendprop_u32(blob, part, "reg", slave->size) < 0)
> +			return false;
> +
> +		if (fdt_setprop_string(blob, part, "label", slave->name) < 0)
> +			return false;
> +
> +		if (!(slave->flags & MTD_WRITEABLE))
> +			if (fdt_setprop_empty(blob, part, "read-only") < 0)
> +				return false;
> +
> +		if (slave->flags & MTD_POWERUP_LOCK)
> +			if (fdt_setprop_empty(blob, part, "lock") < 0)
> +				return false;
> +	}
> +
> +	return true;
> +}
> +
> +int ft_board_setup(void *blob, struct bd_info *bd)
> +{
> +	struct mtd_info *mtd;
> +	int node;
> +
> +	mtd = get_mtd_device_nm(OMNIA_SPI_NOR_PATH);
> +	if (IS_ERR_OR_NULL(mtd))
> +		goto fail;
> +
> +	node = fdt_path_offset(blob, OMNIA_SPI_NOR_PATH);
> +	if (node < 0)
> +		goto fail;
> +
> +	if (!fixup_mtd_partitions(blob, node, mtd))
> +		goto fail;
> +
> +	return 0;
> +
> +fail:
> +	printf("Failed fixing SPI NOR partitions!\n");
> +	return 0;
> +}
> +#endif
> diff --git a/configs/turris_omnia_defconfig b/configs/turris_omnia_defconfig
> index f860cf5e7d..5f7b1a67a2 100644
> --- a/configs/turris_omnia_defconfig
> +++ b/configs/turris_omnia_defconfig
> @@ -23,6 +23,7 @@ CONFIG_SPL=y
>   CONFIG_DEBUG_UART_BASE=0xd0012000
>   CONFIG_DEBUG_UART_CLOCK=250000000
>   CONFIG_DEBUG_UART=y
> +CONFIG_OF_BOARD_SETUP=y
>   CONFIG_AHCI=y
>   CONFIG_DISTRO_DEFAULTS=y
>   CONFIG_FIT=y
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH u-boot-mvebu 1/2] ARM: dts: armada-385-turris-omnia: add `u-boot-env` NOR partition
  2021-07-15 17:21 [PATCH u-boot-mvebu 1/2] ARM: dts: armada-385-turris-omnia: add `u-boot-env` NOR partition Marek Behún
  2021-07-15 17:21 ` [PATCH u-boot-mvebu 2/2] arm: mvebu: turris_omnia: fixup MTD partitions in Linux' DTB Marek Behún
@ 2021-07-19  7:04 ` Stefan Roese
  1 sibling, 0 replies; 4+ messages in thread
From: Stefan Roese @ 2021-07-19  7:04 UTC (permalink / raw
  To: Marek Behún; +Cc: u-boot, pali

On 15.07.21 19:21, Marek Behún wrote:
> Specify a separate partition `u-boot-env` for U-Boot's env settings for
> the Turris Omnia board.
> 
> Do this only in U-Boot's specific DTS. We do not want to do this in
> Linux' official DTS, because Omnia's stock U-Boot stores env at a
> different address, and there are still boards with stock U-Boot.
> 
> In a subsequent patch will add board code that fixes Linux's DTB before
> booting Linux.
> 
> Signed-off-by: Marek Behún <marek.behun@nic.cz>

Reviewed-by: Stefan Roese <sr@denx.de>

Thanks,
Stefan

> ---
>   arch/arm/dts/armada-385-turris-omnia-u-boot.dtsi | 11 +++++++++++
>   1 file changed, 11 insertions(+)
> 
> diff --git a/arch/arm/dts/armada-385-turris-omnia-u-boot.dtsi b/arch/arm/dts/armada-385-turris-omnia-u-boot.dtsi
> index af0655daaa..3ff76c9462 100644
> --- a/arch/arm/dts/armada-385-turris-omnia-u-boot.dtsi
> +++ b/arch/arm/dts/armada-385-turris-omnia-u-boot.dtsi
> @@ -43,6 +43,17 @@
>   
>   	spi-nor@0 {
>   		u-boot,dm-pre-reloc;
> +
> +		partitions {
> +			partition@0 {
> +				reg = <0x0 CONFIG_ENV_OFFSET>;
> +			};
> +
> +			partition@f0000 {
> +				reg = <CONFIG_ENV_OFFSET CONFIG_ENV_SIZE>;
> +				label = "u-boot-env";
> +			};
> +		};
>   	};
>   };
>   
> 


Viele Grüße,
Stefan

-- 
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: sr@denx.de

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-07-19  7:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-07-15 17:21 [PATCH u-boot-mvebu 1/2] ARM: dts: armada-385-turris-omnia: add `u-boot-env` NOR partition Marek Behún
2021-07-15 17:21 ` [PATCH u-boot-mvebu 2/2] arm: mvebu: turris_omnia: fixup MTD partitions in Linux' DTB Marek Behún
2021-07-19  7:03   ` Stefan Roese
2021-07-19  7:04 ` [PATCH u-boot-mvebu 1/2] ARM: dts: armada-385-turris-omnia: add `u-boot-env` NOR partition Stefan Roese

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.