mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] of: overlay: do not parse phandles as properties
@ 2021-01-13  7:57 Rouven Czerwinski
  2021-01-13  7:57 ` [PATCH 2/2] ARM: qemu: support for state & env via DT overlay Rouven Czerwinski
  2021-01-13  9:22 ` [PATCH 1/2] of: overlay: do not parse phandles as properties Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Rouven Czerwinski @ 2021-01-13  7:57 UTC (permalink / raw)
  To: barebox; +Cc: Rouven Czerwinski

Instead of handling phandles as properties, assign them directly as a
handle to the node. This allows phandles within nodes inside the device
tree overlays to be handled correctly.

Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
---
 drivers/of/overlay.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c
index b79dbff94d..0bebe26e39 100644
--- a/drivers/of/overlay.c
+++ b/drivers/of/overlay.c
@@ -58,6 +58,11 @@ static int of_overlay_apply(struct device_node *target,
 		if (of_prop_cmp(prop->name, "name") == 0)
 			continue;
 
+		if (of_prop_cmp(prop->name, "phandle") == 0) {
+			target->phandle = be32_to_cpup(prop->value);
+			continue;
+		}
+
 		err = of_set_property(target, prop->name, prop->value,
 				      prop->length, true);
 		if (err)
-- 
2.29.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 2/2] ARM: qemu: support for state & env via DT overlay
  2021-01-13  7:57 [PATCH 1/2] of: overlay: do not parse phandles as properties Rouven Czerwinski
@ 2021-01-13  7:57 ` Rouven Czerwinski
  2021-01-13  9:22 ` [PATCH 1/2] of: overlay: do not parse phandles as properties Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Rouven Czerwinski @ 2021-01-13  7:57 UTC (permalink / raw)
  To: barebox; +Cc: Rouven Czerwinski

Add support for state and barebox environment by applying an overlay on
top of the qemu generated device tree. If qemu is used with a persistent
flash partition, this allows usage of environments and state across qemu
reboots.
Simple testing can be performed by starting with

  qemu-system-arm -m 256M -M virt -kernel images/barebox-dt-2nd.img -nographic

Storing data, changing into the qemu console via Ctrl-A Ctrl-C, issuing
'system_reset' and Ctrl-A Ctrl-C to get back into the barebox console.

Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
---
 arch/arm/boards/qemu-virt/.gitignore          |  1 +
 arch/arm/boards/qemu-virt/Makefile            |  1 +
 arch/arm/boards/qemu-virt/board.c             | 34 +++++++
 .../arm/boards/qemu-virt/overlay-of-flash.dts | 97 +++++++++++++++++++
 arch/arm/configs/vexpress_defconfig           |  1 +
 arch/arm/mach-vexpress/Kconfig                |  1 +
 6 files changed, 135 insertions(+)
 create mode 100644 arch/arm/boards/qemu-virt/.gitignore
 create mode 100644 arch/arm/boards/qemu-virt/overlay-of-flash.dts

diff --git a/arch/arm/boards/qemu-virt/.gitignore b/arch/arm/boards/qemu-virt/.gitignore
new file mode 100644
index 0000000000..5d65b54bf1
--- /dev/null
+++ b/arch/arm/boards/qemu-virt/.gitignore
@@ -0,0 +1 @@
+*.dtb*
diff --git a/arch/arm/boards/qemu-virt/Makefile b/arch/arm/boards/qemu-virt/Makefile
index dcfc2937d3..8451c7832d 100644
--- a/arch/arm/boards/qemu-virt/Makefile
+++ b/arch/arm/boards/qemu-virt/Makefile
@@ -1 +1,2 @@
 obj-y += board.o
+obj-y += overlay-of-flash.dtb.o
diff --git a/arch/arm/boards/qemu-virt/board.c b/arch/arm/boards/qemu-virt/board.c
index 3aeea1a017..9d8c90eb5b 100644
--- a/arch/arm/boards/qemu-virt/board.c
+++ b/arch/arm/boards/qemu-virt/board.c
@@ -5,7 +5,41 @@
  */
 #include <common.h>
 #include <init.h>
+#include <of.h>
 #include <asm/system_info.h>
+#include <asm/barebox-arm.h>
+
+extern char __dtb_overlay_of_flash_start[];
+
+static int replace_dtb(void) {
+	struct device_node *overlay;
+	void *fdt;
+	struct device_node *root;
+
+	fdt = barebox_arm_boot_dtb();
+	if (fdt)
+		pr_debug("using boarddata provided DTB\n");
+
+	if (!fdt) {
+		pr_debug("No DTB found\n");
+		return 0;
+	}
+
+	root = of_unflatten_dtb(fdt);
+
+	if (!of_device_is_compatible(root, "linux,dummy-virt")) {
+		of_delete_node(root);
+		return 0;
+	}
+
+	overlay = of_unflatten_dtb(__dtb_overlay_of_flash_start);
+	of_overlay_apply_tree(root, overlay);
+	barebox_register_of(root);
+
+	return 0;
+}
+
+pure_initcall(replace_dtb);
 
 static int virt_probe(struct device_d *dev)
 {
diff --git a/arch/arm/boards/qemu-virt/overlay-of-flash.dts b/arch/arm/boards/qemu-virt/overlay-of-flash.dts
new file mode 100644
index 0000000000..e00dc5d7e2
--- /dev/null
+++ b/arch/arm/boards/qemu-virt/overlay-of-flash.dts
@@ -0,0 +1,97 @@
+/dts-v1/;
+/plugin/;
+/ {
+	fragment@0 {
+		target-path = "/flash@0";
+		__overlay__ {
+			partitions {
+				compatible = "fixed-partitions";
+				#address-cells = <1>;
+				#size-cells = <1>;
+
+				partition@0 {
+					label = "initramfs";
+					reg = <0x0 0x3c00000>;
+				};
+
+				environment_flash: partition@3c00000 {
+					label = "barebox-environment";
+					reg = <0x3c00000 0x200000>;
+				};
+
+				backend_state_flash: partition@3e00000 {
+					label = "barebox-state";
+					reg = <0x3e00000 0x200000>;
+				};
+			};
+		};
+	};
+	fragment@1 {
+		target-path="/";
+		__overlay__ {
+			chosen {
+				environment {
+					compatible = "barebox,environment";
+					device-path = "/flash@0/partitions/partition@3c00000";
+				};
+			};
+			aliases {
+				state = "/state";
+			};
+
+			state {
+				#address-cells = <1>;
+				#size-cells = <1>;
+				compatible = "barebox,state";
+				magic = <0x290cf8c6>;
+				backend-type = "raw";
+				backend = < &backend_state_flash >;
+				backend-stridesize = <0x200>;
+
+				bootstate {
+					#address-cells = <1>;
+					#size-cells = <1>;
+
+					system0 {
+						#address-cells = <1>;
+						#size-cells = <1>;
+
+						remaining_attempts@0 {
+							reg = <0x0 0x4>;
+							type = "uint32";
+							default = <3>;
+						};
+
+						priority@4 {
+							reg = <0x4 0x4>;
+							type = "uint32";
+							default = <20>;
+						};
+					};
+
+					system1 {
+						#address-cells = <1>;
+						#size-cells = <1>;
+
+						remaining_attempts@8 {
+							reg = <0x8 0x4>;
+							type = "uint32";
+							default = <3>;
+						};
+
+						priority@c {
+							reg = <0xc 0x4>;
+							type = "uint32";
+							default = <21>;
+						};
+					};
+
+					last_chosen@10 {
+						reg = <0x10 0x4>;
+						type = "uint32";
+					};
+				};
+			};
+		};
+	};
+};
diff --git a/arch/arm/configs/vexpress_defconfig b/arch/arm/configs/vexpress_defconfig
index f17af2bb95..760e39b440 100644
--- a/arch/arm/configs/vexpress_defconfig
+++ b/arch/arm/configs/vexpress_defconfig
@@ -50,6 +50,7 @@ CONFIG_NET=y
 CONFIG_NET_NFS=y
 CONFIG_NET_NETCONSOLE=y
 CONFIG_OF_BAREBOX_DRIVERS=y
+CONFIG_OF_OVERLAY=y
 CONFIG_SERIAL_AMBA_PL011=y
 CONFIG_DRIVER_NET_SMC91111=y
 # CONFIG_SPI is not set
diff --git a/arch/arm/mach-vexpress/Kconfig b/arch/arm/mach-vexpress/Kconfig
index 9d301f7ae8..557c9653f4 100644
--- a/arch/arm/mach-vexpress/Kconfig
+++ b/arch/arm/mach-vexpress/Kconfig
@@ -11,5 +11,6 @@ config MACH_VIRT
 	bool "QEMU virt"
 	select ARM_PSCI_CLIENT
 	select BOARD_ARM_GENERIC_DT
+	select OF_OVERLAY
 
 endif
-- 
2.29.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 1/2] of: overlay: do not parse phandles as properties
  2021-01-13  7:57 [PATCH 1/2] of: overlay: do not parse phandles as properties Rouven Czerwinski
  2021-01-13  7:57 ` [PATCH 2/2] ARM: qemu: support for state & env via DT overlay Rouven Czerwinski
@ 2021-01-13  9:22 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2021-01-13  9:22 UTC (permalink / raw)
  To: Rouven Czerwinski; +Cc: barebox

On Wed, Jan 13, 2021 at 08:57:56AM +0100, Rouven Czerwinski wrote:
> Instead of handling phandles as properties, assign them directly as a
> handle to the node. This allows phandles within nodes inside the device
> tree overlays to be handled correctly.
> 
> Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
> ---
>  drivers/of/overlay.c | 5 +++++
>  1 file changed, 5 insertions(+)

Applied, thanks

Sascha

> 
> diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c
> index b79dbff94d..0bebe26e39 100644
> --- a/drivers/of/overlay.c
> +++ b/drivers/of/overlay.c
> @@ -58,6 +58,11 @@ static int of_overlay_apply(struct device_node *target,
>  		if (of_prop_cmp(prop->name, "name") == 0)
>  			continue;
>  
> +		if (of_prop_cmp(prop->name, "phandle") == 0) {
> +			target->phandle = be32_to_cpup(prop->value);
> +			continue;
> +		}
> +
>  		err = of_set_property(target, prop->name, prop->value,
>  				      prop->length, true);
>  		if (err)
> -- 
> 2.29.2
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

end of thread, other threads:[~2021-01-13  9:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-13  7:57 [PATCH 1/2] of: overlay: do not parse phandles as properties Rouven Czerwinski
2021-01-13  7:57 ` [PATCH 2/2] ARM: qemu: support for state & env via DT overlay Rouven Czerwinski
2021-01-13  9:22 ` [PATCH 1/2] of: overlay: do not parse phandles as properties Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox