mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 0/7] ARM/RISC-V: qemu-virt: share common cleaned up state/env support
@ 2021-11-25 16:10 Ahmad Fatoum
  2021-11-25 16:10 ` [PATCH 1/7] state: mark state init errors specially Ahmad Fatoum
                   ` (6 more replies)
  0 siblings, 7 replies; 10+ messages in thread
From: Ahmad Fatoum @ 2021-11-25 16:10 UTC (permalink / raw)
  To: barebox

ARM QEMU Virt has support for environment/state. Make this available in
RISC-V as well, while cleaning up the code a bit and fixing a bug due to
too early of_probe at pure_initcall level.

Ahmad Fatoum (7):
  state: mark state init errors specially
  state: make first boot less verbose
  of: overlay: rescan aliases calling of_overlay_apply_tree on live tree
  ARM: qemu: enable deep probe support
  ARM: qemu: move board code to central location
  common: boards: qemu-virt: genericize to support non-ARM architectures
  RISC-V: qemu-virt: add overlay for environment and state

 arch/arm/Kconfig                              |  1 +
 arch/arm/boards/Makefile                      |  1 -
 arch/arm/boards/qemu-virt/Makefile            |  1 -
 arch/riscv/Kconfig.socs                       | 10 +++
 arch/riscv/configs/virt32_defconfig           |  4 ++
 arch/riscv/configs/virt64_defconfig           |  4 ++
 common/Kconfig                                |  2 +
 common/Makefile                               |  1 +
 common/boards/Kconfig                         |  4 ++
 common/boards/Makefile                        |  3 +
 common/boards/qemu-virt/Makefile              |  7 +++
 {arch/arm => common}/boards/qemu-virt/board.c | 61 ++++++++-----------
 .../boards/qemu-virt/overlay-of-flash.dts     | 13 +++-
 common/state/backend_format_raw.c             |  7 +--
 common/state/backend_storage.c                | 17 +++---
 common/state/state.c                          |  4 +-
 common/state/state.h                          | 14 +++++
 drivers/misc/state.c                          |  4 +-
 drivers/of/overlay.c                          |  4 ++
 19 files changed, 110 insertions(+), 52 deletions(-)
 create mode 100644 common/boards/Kconfig
 create mode 100644 common/boards/Makefile
 create mode 100644 common/boards/qemu-virt/Makefile
 rename {arch/arm => common}/boards/qemu-virt/board.c (64%)
 rename {arch/arm => common}/boards/qemu-virt/overlay-of-flash.dts (83%)

-- 
2.30.2


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


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

* [PATCH 1/7] state: mark state init errors specially
  2021-11-25 16:10 [PATCH 0/7] ARM/RISC-V: qemu-virt: share common cleaned up state/env support Ahmad Fatoum
@ 2021-11-25 16:10 ` Ahmad Fatoum
  2021-11-25 16:10 ` [PATCH 2/7] state: make first boot less verbose Ahmad Fatoum
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Ahmad Fatoum @ 2021-11-25 16:10 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

First boot with uninitialized state is needlessly verbose. As
preparation for making boot less noisy on fresh state, mark all the
error messages with newly introduced dev_err_state_init().

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/state/backend_format_raw.c | 3 +--
 common/state/backend_storage.c    | 7 ++-----
 common/state/state.c              | 4 ++--
 common/state/state.h              | 7 +++++++
 4 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/common/state/backend_format_raw.c b/common/state/backend_format_raw.c
index ea962606ccdb..aeee41d07ce9 100644
--- a/common/state/backend_format_raw.c
+++ b/common/state/backend_format_raw.c
@@ -116,9 +116,8 @@ static int backend_format_raw_verify(struct state_backend_format *format,
 	header = (struct backend_raw_header *)buf;
 	crc = crc32(0, header, sizeof(*header) - sizeof(uint32_t));
 	if (crc != header->header_crc) {
-		dev_err(backend_raw->dev, "Error, invalid header crc in raw format, calculated 0x%08x, found 0x%08x\n",
+		return dev_err_state_init(backend_raw->dev, -EINVAL, "header crc in raw format, calculated 0x%08x, found 0x%08x\n",
 			crc, header->header_crc);
-		return -EINVAL;
 	}
 
 	if (magic && magic != header->magic) {
diff --git a/common/state/backend_storage.c b/common/state/backend_storage.c
index 7fc7acfdcbc8..2d7d9a4a63c0 100644
--- a/common/state/backend_storage.c
+++ b/common/state/backend_storage.c
@@ -171,11 +171,8 @@ int state_storage_read(struct state_backend_storage *storage,
 
 	dev_dbg(storage->dev, "Checking redundant buckets finished.\n");
 
-	if (!bucket_used) {
-		dev_err(storage->dev, "Failed to find any valid state copy in any bucket\n");
-
-		return -ENOENT;
-	}
+	if (!bucket_used)
+		return dev_err_state_init(storage->dev, -ENOENT, "no valid state copy in any bucket\n");
 
 	dev_info(storage->dev, "Using bucket %d@0x%08llx\n", bucket_used->num, (long long) bucket_used->offset);
 
diff --git a/common/state/state.c b/common/state/state.c
index 469ee62d4012..8c34ae83e52b 100644
--- a/common/state/state.c
+++ b/common/state/state.c
@@ -101,8 +101,8 @@ static int state_do_load(struct state *state, enum state_flags flags)
 	ret = state_storage_read(&state->storage, state->format,
 				 state->magic, &buf, &len, flags);
 	if (ret) {
-		dev_err(&state->dev, "Failed to read state with format %s, %d\n",
-			state->format->name, ret);
+		dev_err_state_init(&state->dev, ret, "format %s read failed\n",
+				   state->format->name);
 		goto out;
 	}
 
diff --git a/common/state/state.h b/common/state/state.h
index 1881d92ea7fe..d858c9e42735 100644
--- a/common/state/state.h
+++ b/common/state/state.h
@@ -1,5 +1,6 @@
 #include <linux/types.h>
 #include <linux/list.h>
+#include <linux/err.h>
 #include <driver.h>
 
 struct state;
@@ -266,3 +267,9 @@ static inline int state_string_copy_to_raw(struct state_string *string,
 
 	return 0;
 }
+
+#define dev_err_state_init(dev, ret, fmt, ...) ({ \
+	int __ret = (ret); \
+	dev_err((dev), "init error: %pe: " fmt, ERR_PTR(__ret), ##__VA_ARGS__); \
+	__ret; \
+})
-- 
2.30.2


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


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

* [PATCH 2/7] state: make first boot less verbose
  2021-11-25 16:10 [PATCH 0/7] ARM/RISC-V: qemu-virt: share common cleaned up state/env support Ahmad Fatoum
  2021-11-25 16:10 ` [PATCH 1/7] state: mark state init errors specially Ahmad Fatoum
@ 2021-11-25 16:10 ` Ahmad Fatoum
  2021-11-30 10:47   ` Sascha Hauer
  2021-11-25 16:10 ` [PATCH 3/7] of: overlay: rescan aliases calling of_overlay_apply_tree on live tree Ahmad Fatoum
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 10+ messages in thread
From: Ahmad Fatoum @ 2021-11-25 16:10 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

First boot with uninitialized state is needlessly verbose:

  state: New state registered 'state'
  state: Detected old on-storage format
  ERROR: state: Error, invalid header crc in raw format, calculated 0x7bd5c66f, found 0x00000000
  state: Ignoring broken bucket 0@0x00000000...
  state: Detected old on-storage format
  ERROR: state: Error, invalid header crc in raw format, calculated 0x7bd5c66f, found 0x00000000
  state: Ignoring broken bucket 1@0x00040000...
  state: Detected old on-storage format
  ERROR: state: Error, invalid header crc in raw format, calculated 0x7bd5c66f, found 0x00000000
  state: Ignoring broken bucket 2@0x00080000...
  ERROR: state: Failed to find any valid state copy in any bucket
  ERROR: state: Failed to read state with format raw, -2

This has confused barebox-state novices more than once. Let's handle
the zeroed state case specially and reduce output in that case, so
it now looks like this:

  state: New state registered 'state'
  state: Detected old on-storage format
  state: Detected old on-storage format
  state: Detected old on-storage format
  state state.of: Fresh state detected, continuing with defaults

This is only the output when CRC is zero (hinting at zeroed state
partition). If crc != zero, then output is a little more verbose than
before:

  state: New state registered 'state'
  state: Detected old on-storage format
  ERROR: state: init error: Invalid argument: header crc in raw format, calculated 0x7bd5c66f, found 0x00000000
  state: Ignoring broken bucket 0@0x00000000...
  state: Detected old on-storage format
  ERROR: state: init error: Invalid argument: header crc in raw format, calculated 0x7bd5c66f, found 0x00000000
  state: Ignoring broken bucket 1@0x00040000...
  state: Detected old on-storage format
  ERROR: state: init error: Invalid argument: header crc in raw format, calculated 0x7bd5c66f, found 0x00000000
  state: Ignoring broken bucket 2@0x00080000...
  ERROR: state: init error: No such file or directory: no valid state copy in any bucket
  ERROR: state: init error: No such file or directory: format raw read failed
  WARNING: state state.of: Failed to load persistent state, continuing with defaults, -2

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/state/backend_format_raw.c |  6 +++---
 common/state/backend_storage.c    | 12 +++++++++---
 common/state/state.h              |  9 ++++++++-
 drivers/misc/state.c              |  4 +++-
 4 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/common/state/backend_format_raw.c b/common/state/backend_format_raw.c
index aeee41d07ce9..1fecdeb9cf57 100644
--- a/common/state/backend_format_raw.c
+++ b/common/state/backend_format_raw.c
@@ -115,10 +115,10 @@ static int backend_format_raw_verify(struct state_backend_format *format,
 
 	header = (struct backend_raw_header *)buf;
 	crc = crc32(0, header, sizeof(*header) - sizeof(uint32_t));
-	if (crc != header->header_crc) {
-		return dev_err_state_init(backend_raw->dev, -EINVAL, "header crc in raw format, calculated 0x%08x, found 0x%08x\n",
+	if (crc != header->header_crc)
+		return dev_err_state_init(backend_raw->dev, header->header_crc ? -EINVAL : -ENOMEDIUM,
+			"header crc in raw format, calculated 0x%08x, found 0x%08x\n",
 			crc, header->header_crc);
-	}
 
 	if (magic && magic != header->magic) {
 		dev_err(backend_raw->dev, "Error, invalid magic in raw format 0x%08x, should be 0x%08x\n",
diff --git a/common/state/backend_storage.c b/common/state/backend_storage.c
index 2d7d9a4a63c0..72f8bcf521ad 100644
--- a/common/state/backend_storage.c
+++ b/common/state/backend_storage.c
@@ -144,6 +144,7 @@ int state_storage_read(struct state_backend_storage *storage,
 		       enum state_flags flags)
 {
 	struct state_backend_storage_bucket *bucket, *bucket_used = NULL;
+	int zerobuckets = 0, totalbuckets = 0;
 	int ret;
 
 	dev_dbg(storage->dev, "Checking redundant buckets...\n");
@@ -152,6 +153,8 @@ int state_storage_read(struct state_backend_storage *storage,
 	 * one we want to use.
 	 */
 	list_for_each_entry(bucket, &storage->buckets, bucket_list) {
+		totalbuckets++;
+
 		ret = bucket->read(bucket, &bucket->buf, &bucket->len);
 		if (ret == -EUCLEAN)
 			bucket->needs_refresh = 1;
@@ -163,16 +166,19 @@ int state_storage_read(struct state_backend_storage *storage,
 		 * .verify overwrites it with the length actually used.
 		 */
 		ret = format->verify(format, magic, bucket->buf, &bucket->len, flags);
-		if (!ret && !bucket_used)
+		if (ret == -ENOMEDIUM)
+			zerobuckets++;
+		else if (!ret && !bucket_used)
 			bucket_used = bucket;
-		if (ret)
+		else if (ret)
 			dev_info(storage->dev, "Ignoring broken bucket %d@0x%08llx...\n", bucket->num, (long long) bucket->offset);
 	}
 
 	dev_dbg(storage->dev, "Checking redundant buckets finished.\n");
 
 	if (!bucket_used)
-		return dev_err_state_init(storage->dev, -ENOENT, "no valid state copy in any bucket\n");
+		return dev_err_state_init(storage->dev, zerobuckets == totalbuckets ? -ENOMEDIUM : -ENOENT,
+					  "no valid state copy in any bucket\n");
 
 	dev_info(storage->dev, "Using bucket %d@0x%08llx\n", bucket_used->num, (long long) bucket_used->offset);
 
diff --git a/common/state/state.h b/common/state/state.h
index d858c9e42735..48572c5d4137 100644
--- a/common/state/state.h
+++ b/common/state/state.h
@@ -268,8 +268,15 @@ static inline int state_string_copy_to_raw(struct state_string *string,
 	return 0;
 }
 
+#ifdef DEBUG
+#define MSG_STATE_ZERO_INIT	MSG_INFO
+#else
+#define MSG_STATE_ZERO_INIT	MSG_DEBUG
+#endif
+
 #define dev_err_state_init(dev, ret, fmt, ...) ({ \
 	int __ret = (ret); \
-	dev_err((dev), "init error: %pe: " fmt, ERR_PTR(__ret), ##__VA_ARGS__); \
+	__dev_printf(__ret == -ENOMEDIUM ? MSG_STATE_ZERO_INIT : MSG_ERR, \
+		     (dev), "init error: %pe: " fmt, ERR_PTR(__ret), ##__VA_ARGS__); \
 	__ret; \
 })
diff --git a/drivers/misc/state.c b/drivers/misc/state.c
index 5da8e4ef915a..cb0d9cf3ad09 100644
--- a/drivers/misc/state.c
+++ b/drivers/misc/state.c
@@ -28,7 +28,9 @@ static int state_probe(struct device_d *dev)
 	}
 
 	ret = state_load(state);
-	if (ret)
+	if (ret == -ENOMEDIUM)
+		dev_info(dev, "Fresh state detected, continuing with defaults\n");
+	else if (ret)
 		dev_warn(dev, "Failed to load persistent state, continuing with defaults, %d\n",
 			 ret);
 
-- 
2.30.2


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


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

* [PATCH 3/7] of: overlay: rescan aliases calling of_overlay_apply_tree on live tree
  2021-11-25 16:10 [PATCH 0/7] ARM/RISC-V: qemu-virt: share common cleaned up state/env support Ahmad Fatoum
  2021-11-25 16:10 ` [PATCH 1/7] state: mark state init errors specially Ahmad Fatoum
  2021-11-25 16:10 ` [PATCH 2/7] state: make first boot less verbose Ahmad Fatoum
@ 2021-11-25 16:10 ` Ahmad Fatoum
  2021-11-25 16:10 ` [PATCH 4/7] ARM: qemu: enable deep probe support Ahmad Fatoum
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Ahmad Fatoum @ 2021-11-25 16:10 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Couple of drivers in-tree, like state, depend on aliases for correct
operation. If state node is added via overlay and oftree -p is called,
driver would start probing, but fail because aliases weren't reloaded.

Fix this corner case by always just calling of_alias_scan() on every
successful of_overlay_apply_tree to the live tree. No functional change
yet, as the only user of this function is overlay application code of
ARM QEMU machine, which happens at pure_initcall level, making
of_alias_scan a no-op. Follow-up commit will move overlay application to
happen after device tree is registered, necessitating this change.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/of/overlay.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c
index e6f6634d6042..20a43f5170c8 100644
--- a/drivers/of/overlay.c
+++ b/drivers/of/overlay.c
@@ -199,6 +199,10 @@ int of_overlay_apply_tree(struct device_node *root,
 			pr_warn("failed to apply %s\n", fragment->name);
 	}
 
+	/* We are patching the live tree, reload aliases */
+	if (root == of_get_root_node())
+		of_alias_scan();
+
 out_err:
 	of_delete_node(resolved);
 
-- 
2.30.2


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


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

* [PATCH 4/7] ARM: qemu: enable deep probe support
  2021-11-25 16:10 [PATCH 0/7] ARM/RISC-V: qemu-virt: share common cleaned up state/env support Ahmad Fatoum
                   ` (2 preceding siblings ...)
  2021-11-25 16:10 ` [PATCH 3/7] of: overlay: rescan aliases calling of_overlay_apply_tree on live tree Ahmad Fatoum
@ 2021-11-25 16:10 ` Ahmad Fatoum
  2021-11-25 16:10 ` [PATCH 5/7] ARM: qemu: move board code to central location Ahmad Fatoum
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Ahmad Fatoum @ 2021-11-25 16:10 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum, Rouven Czerwinski

It's a bug to call barebox_register_of at pure_initcall level, because
device tree probe may depend on other initialization done at pure_initcall.
For example, if the QEMU-supplied Virt device tree had a model, barebox
would attempt to register a new global variable before the global device
is even initialized. With the move to deep probe we can just do overlay
fixup in the board driver at safe postcore level.

Fixes: ff8b098a4ad2 ("ARM: qemu: support for state & env via DT overlay")
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
Cc: Rouven Czerwinski <r.czerwinski@pengutronix.de>
---
 arch/arm/boards/qemu-virt/board.c | 37 ++++++-------------------------
 1 file changed, 7 insertions(+), 30 deletions(-)

diff --git a/arch/arm/boards/qemu-virt/board.c b/arch/arm/boards/qemu-virt/board.c
index b2a3cb29ab09..1333687918e1 100644
--- a/arch/arm/boards/qemu-virt/board.c
+++ b/arch/arm/boards/qemu-virt/board.c
@@ -6,8 +6,8 @@
 #include <common.h>
 #include <init.h>
 #include <of.h>
+#include <deep-probe.h>
 #include <asm/system_info.h>
-#include <asm/barebox-arm.h>
 
 #ifdef CONFIG_64BIT
 #define MACHINE "virt64"
@@ -17,38 +17,10 @@
 
 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, INT_MAX);
-
-	if (!of_device_is_compatible(root, "linux,dummy-virt")) {
-		of_delete_node(root);
-		return 0;
-	}
-
-	overlay = of_unflatten_dtb(__dtb_overlay_of_flash_start, INT_MAX);
-	of_overlay_apply_tree(root, overlay);
-
-	return barebox_register_of(root);
-}
-
-pure_initcall(replace_dtb);
-
 static int virt_probe(struct device_d *dev)
 {
 	const char *hostname = MACHINE;
+	struct device_node *overlay;
 
 	if (cpu_is_cortex_a7())
 		hostname = "virt-a7";
@@ -58,6 +30,10 @@ static int virt_probe(struct device_d *dev)
 	barebox_set_model("ARM QEMU " MACHINE);
 	barebox_set_hostname(hostname);
 
+	overlay = of_unflatten_dtb(__dtb_overlay_of_flash_start, INT_MAX);
+	of_overlay_apply_tree(dev->device_node, overlay);
+	/* of_probe() will happen later at of_populate_initcall */
+
 	return 0;
 }
 
@@ -65,6 +41,7 @@ static const struct of_device_id virt_of_match[] = {
 	{ .compatible = "linux,dummy-virt" },
 	{ /* Sentinel */},
 };
+BAREBOX_DEEP_PROBE_ENABLE(virt_of_match);
 
 static struct driver_d virt_board_driver = {
 	.name = "board-qemu-virt",
-- 
2.30.2


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


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

* [PATCH 5/7] ARM: qemu: move board code to central location
  2021-11-25 16:10 [PATCH 0/7] ARM/RISC-V: qemu-virt: share common cleaned up state/env support Ahmad Fatoum
                   ` (3 preceding siblings ...)
  2021-11-25 16:10 ` [PATCH 4/7] ARM: qemu: enable deep probe support Ahmad Fatoum
@ 2021-11-25 16:10 ` Ahmad Fatoum
  2021-11-25 16:10 ` [PATCH 6/7] common: boards: qemu-virt: genericize to support non-ARM architectures Ahmad Fatoum
  2021-11-25 16:10 ` [PATCH 7/7] RISC-V: qemu-virt: add overlay for environment and state Ahmad Fatoum
  6 siblings, 0 replies; 10+ messages in thread
From: Ahmad Fatoum @ 2021-11-25 16:10 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

The state/environment overlay applied on top of QEMU is applicable to
other virt platforms as well, like RISC-V. In preparation for sharing
code across architectures, add a new common/boards and move the board
code there.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 arch/arm/Kconfig                                           | 1 +
 arch/arm/boards/Makefile                                   | 1 -
 arch/arm/boards/qemu-virt/Makefile                         | 1 -
 common/Kconfig                                             | 2 ++
 common/Makefile                                            | 1 +
 common/boards/Kconfig                                      | 4 ++++
 common/boards/Makefile                                     | 3 +++
 common/boards/qemu-virt/Makefile                           | 4 ++++
 {arch/arm => common}/boards/qemu-virt/board.c              | 0
 {arch/arm => common}/boards/qemu-virt/overlay-of-flash.dts | 0
 10 files changed, 15 insertions(+), 2 deletions(-)
 create mode 100644 common/boards/Kconfig
 create mode 100644 common/boards/Makefile
 create mode 100644 common/boards/qemu-virt/Makefile
 rename {arch/arm => common}/boards/qemu-virt/board.c (100%)
 rename {arch/arm => common}/boards/qemu-virt/overlay-of-flash.dts (100%)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 14aa7e26af29..b532d3fe2fc2 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -308,6 +308,7 @@ source "arch/arm/mach-zynqmp/Kconfig"
 config BOARD_ARM_VIRT
 	bool
 	select BOARD_ARM_GENERIC_DT
+	select BOARD_QEMU_VIRT
 	select OF_OVERLAY
 
 config BOARD_ARM_GENERIC_DT
diff --git a/arch/arm/boards/Makefile b/arch/arm/boards/Makefile
index 08815d79ec43..50b07462bb78 100644
--- a/arch/arm/boards/Makefile
+++ b/arch/arm/boards/Makefile
@@ -167,7 +167,6 @@ obj-$(CONFIG_MACH_ZEDBOARD)			+= avnet-zedboard/
 obj-$(CONFIG_MACH_ZYLONITE)			+= zylonite/
 obj-$(CONFIG_MACH_VARISCITE_MX6)		+= variscite-mx6/
 obj-$(CONFIG_MACH_VSCOM_BALTOS)			+= vscom-baltos/
-obj-$(CONFIG_BOARD_ARM_VIRT)			+= qemu-virt/
 obj-$(CONFIG_MACH_WARP7)			+= element14-warp7/
 obj-$(CONFIG_MACH_WEBASTO_CCBV2)		+= webasto-ccbv2/
 obj-$(CONFIG_MACH_VF610_TWR)			+= freescale-vf610-twr/
diff --git a/arch/arm/boards/qemu-virt/Makefile b/arch/arm/boards/qemu-virt/Makefile
index 8451c7832d03..dcfc2937d325 100644
--- a/arch/arm/boards/qemu-virt/Makefile
+++ b/arch/arm/boards/qemu-virt/Makefile
@@ -1,2 +1 @@
 obj-y += board.o
-obj-y += overlay-of-flash.dtb.o
diff --git a/common/Kconfig b/common/Kconfig
index ab6258d90f40..9ddccc85ba26 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -1,3 +1,5 @@
+source "common/boards/Kconfig"
+
 config GREGORIAN_CALENDER
 	bool
 
diff --git a/common/Makefile b/common/Makefile
index 4b45f678c7de..96808ecd35e5 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -1,3 +1,4 @@
+obj-y				+= boards/
 obj-y				+= memory.o
 obj-y				+= memory_display.o
 pbl-$(CONFIG_PBL_CONSOLE)	+= memory_display.o
diff --git a/common/boards/Kconfig b/common/boards/Kconfig
new file mode 100644
index 000000000000..e27273b7671d
--- /dev/null
+++ b/common/boards/Kconfig
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+config BOARD_QEMU_VIRT
+	bool
diff --git a/common/boards/Makefile b/common/boards/Makefile
new file mode 100644
index 000000000000..5b4e429c13e9
--- /dev/null
+++ b/common/boards/Makefile
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+obj-$(CONFIG_BOARD_QEMU_VIRT)	+= qemu-virt/
diff --git a/common/boards/qemu-virt/Makefile b/common/boards/qemu-virt/Makefile
new file mode 100644
index 000000000000..f10d39138578
--- /dev/null
+++ b/common/boards/qemu-virt/Makefile
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+obj-y += board.o
+obj-y += overlay-of-flash.dtb.o
diff --git a/arch/arm/boards/qemu-virt/board.c b/common/boards/qemu-virt/board.c
similarity index 100%
rename from arch/arm/boards/qemu-virt/board.c
rename to common/boards/qemu-virt/board.c
diff --git a/arch/arm/boards/qemu-virt/overlay-of-flash.dts b/common/boards/qemu-virt/overlay-of-flash.dts
similarity index 100%
rename from arch/arm/boards/qemu-virt/overlay-of-flash.dts
rename to common/boards/qemu-virt/overlay-of-flash.dts
-- 
2.30.2


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


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

* [PATCH 6/7] common: boards: qemu-virt: genericize to support non-ARM architectures
  2021-11-25 16:10 [PATCH 0/7] ARM/RISC-V: qemu-virt: share common cleaned up state/env support Ahmad Fatoum
                   ` (4 preceding siblings ...)
  2021-11-25 16:10 ` [PATCH 5/7] ARM: qemu: move board code to central location Ahmad Fatoum
@ 2021-11-25 16:10 ` Ahmad Fatoum
  2021-11-25 16:10 ` [PATCH 7/7] RISC-V: qemu-virt: add overlay for environment and state Ahmad Fatoum
  6 siblings, 0 replies; 10+ messages in thread
From: Ahmad Fatoum @ 2021-11-25 16:10 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

In preparation for extending support to RISC-V, sprinkle around some
preprocessor directives.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/boards/qemu-virt/board.c              | 25 ++++++++++++++++----
 common/boards/qemu-virt/overlay-of-flash.dts |  8 +++++--
 2 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/common/boards/qemu-virt/board.c b/common/boards/qemu-virt/board.c
index 1333687918e1..f10608e30343 100644
--- a/common/boards/qemu-virt/board.c
+++ b/common/boards/qemu-virt/board.c
@@ -7,7 +7,6 @@
 #include <init.h>
 #include <of.h>
 #include <deep-probe.h>
-#include <asm/system_info.h>
 
 #ifdef CONFIG_64BIT
 #define MACHINE "virt64"
@@ -15,12 +14,12 @@
 #define MACHINE "virt"
 #endif
 
-extern char __dtb_overlay_of_flash_start[];
+#ifdef CONFIG_ARM
+#include <asm/system_info.h>
 
-static int virt_probe(struct device_d *dev)
+static inline void arm_virt_init(void)
 {
 	const char *hostname = MACHINE;
-	struct device_node *overlay;
 
 	if (cpu_is_cortex_a7())
 		hostname = "virt-a7";
@@ -29,6 +28,22 @@ static int virt_probe(struct device_d *dev)
 
 	barebox_set_model("ARM QEMU " MACHINE);
 	barebox_set_hostname(hostname);
+}
+
+#else
+static inline void arm_virt_init(void) {}
+#endif
+
+extern char __dtb_overlay_of_flash_start[];
+
+static int virt_probe(struct device_d *dev)
+{
+	struct device_node *overlay;
+	void (*init)(void);
+
+	init = device_get_match_data(dev);
+	if (init)
+		init();
 
 	overlay = of_unflatten_dtb(__dtb_overlay_of_flash_start, INT_MAX);
 	of_overlay_apply_tree(dev->device_node, overlay);
@@ -38,7 +53,7 @@ static int virt_probe(struct device_d *dev)
 }
 
 static const struct of_device_id virt_of_match[] = {
-	{ .compatible = "linux,dummy-virt" },
+	{ .compatible = "linux,dummy-virt", .data = arm_virt_init },
 	{ /* Sentinel */},
 };
 BAREBOX_DEEP_PROBE_ENABLE(virt_of_match);
diff --git a/common/boards/qemu-virt/overlay-of-flash.dts b/common/boards/qemu-virt/overlay-of-flash.dts
index e00dc5d7e233..ed6ad0072b55 100644
--- a/common/boards/qemu-virt/overlay-of-flash.dts
+++ b/common/boards/qemu-virt/overlay-of-flash.dts
@@ -1,8 +1,12 @@
 /dts-v1/;
 /plugin/;
+
+#define PARTS_TARGET_PATH	"/flash@0"
+#define ENV_DEVICE_PATH		"/flash@0/partitions/partition@3c00000"
+
 / {
 	fragment@0 {
-		target-path = "/flash@0";
+		target-path = PARTS_TARGET_PATH;
 		__overlay__ {
 			partitions {
 				compatible = "fixed-partitions";
@@ -32,7 +36,7 @@
 			chosen {
 				environment {
 					compatible = "barebox,environment";
-					device-path = "/flash@0/partitions/partition@3c00000";
+					device-path = ENV_DEVICE_PATH;
 				};
 			};
 			aliases {
-- 
2.30.2


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


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

* [PATCH 7/7] RISC-V: qemu-virt: add overlay for environment and state
  2021-11-25 16:10 [PATCH 0/7] ARM/RISC-V: qemu-virt: share common cleaned up state/env support Ahmad Fatoum
                   ` (5 preceding siblings ...)
  2021-11-25 16:10 ` [PATCH 6/7] common: boards: qemu-virt: genericize to support non-ARM architectures Ahmad Fatoum
@ 2021-11-25 16:10 ` Ahmad Fatoum
  6 siblings, 0 replies; 10+ messages in thread
From: Ahmad Fatoum @ 2021-11-25 16:10 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Like we do on ARM, let's add state and environment to RISC-V QEMU Virt
as well.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 arch/riscv/Kconfig.socs                      | 10 ++++++++++
 arch/riscv/configs/virt32_defconfig          |  4 ++++
 arch/riscv/configs/virt64_defconfig          |  4 ++++
 common/boards/qemu-virt/Makefile             |  3 +++
 common/boards/qemu-virt/board.c              |  1 +
 common/boards/qemu-virt/overlay-of-flash.dts |  5 +++++
 6 files changed, 27 insertions(+)

diff --git a/arch/riscv/Kconfig.socs b/arch/riscv/Kconfig.socs
index b12c795041b0..9f2a4f825ebb 100644
--- a/arch/riscv/Kconfig.socs
+++ b/arch/riscv/Kconfig.socs
@@ -23,6 +23,16 @@ config SOC_VIRT
 	  Generates an image tht can be be booted by QEMU. The image is called
 	  barebox-dt-2nd.img
 
+config BOARD_RISCV_VIRT
+	depends on SOC_VIRT
+	bool "QEMU Virt Machine"
+	select OF_OVERLAY
+	select BOARD_QEMU_VIRT
+	default y
+	help
+	  Enables environment and state on top of QEMU RISC-V Virt machine
+	  cfi-flash.
+
 config BOARD_RISCVEMU
 	depends on SOC_VIRT
 	bool "TinyEMU Virt Machine (riscvemu)"
diff --git a/arch/riscv/configs/virt32_defconfig b/arch/riscv/configs/virt32_defconfig
index 6a8443d6d565..1d7b70fc0fbc 100644
--- a/arch/riscv/configs/virt32_defconfig
+++ b/arch/riscv/configs/virt32_defconfig
@@ -69,11 +69,14 @@ CONFIG_CMD_OF_FIXUP_STATUS=y
 CONFIG_CMD_OF_OVERLAY=y
 CONFIG_CMD_OFTREE=y
 CONFIG_CMD_TIME=y
+CONFIG_CMD_STATE=y
 CONFIG_CMD_DHRYSTONE=y
 CONFIG_NET=y
 CONFIG_NET_NFS=y
 CONFIG_NET_NETCONSOLE=y
 CONFIG_NET_FASTBOOT=y
+CONFIG_OF_BAREBOX_DRIVERS=y
+CONFIG_OF_BAREBOX_ENV_IN_FS=y
 CONFIG_DRIVER_SERIAL_NS16550=y
 CONFIG_VIRTIO_CONSOLE=y
 CONFIG_DRIVER_NET_VIRTIO=y
@@ -94,6 +97,7 @@ CONFIG_FRAMEBUFFER_CONSOLE=y
 CONFIG_DRIVER_VIDEO_BOCHS_PCI=y
 CONFIG_DRIVER_VIDEO_SIMPLEFB_CLIENT=y
 CONFIG_CLOCKSOURCE_DUMMY_RATE=60000
+CONFIG_STATE_DRV=y
 CONFIG_EEPROM_AT24=y
 CONFIG_HWRNG=y
 CONFIG_HW_RANDOM_VIRTIO=y
diff --git a/arch/riscv/configs/virt64_defconfig b/arch/riscv/configs/virt64_defconfig
index 604292d4f4fd..8c66e3e574ff 100644
--- a/arch/riscv/configs/virt64_defconfig
+++ b/arch/riscv/configs/virt64_defconfig
@@ -70,11 +70,14 @@ CONFIG_CMD_OF_FIXUP_STATUS=y
 CONFIG_CMD_OF_OVERLAY=y
 CONFIG_CMD_OFTREE=y
 CONFIG_CMD_TIME=y
+CONFIG_CMD_STATE=y
 CONFIG_CMD_DHRYSTONE=y
 CONFIG_NET=y
 CONFIG_NET_NFS=y
 CONFIG_NET_NETCONSOLE=y
 CONFIG_NET_FASTBOOT=y
+CONFIG_OF_BAREBOX_DRIVERS=y
+CONFIG_OF_BAREBOX_ENV_IN_FS=y
 CONFIG_DRIVER_SERIAL_NS16550=y
 CONFIG_VIRTIO_CONSOLE=y
 CONFIG_DRIVER_NET_VIRTIO=y
@@ -95,6 +98,7 @@ CONFIG_FRAMEBUFFER_CONSOLE=y
 CONFIG_DRIVER_VIDEO_BOCHS_PCI=y
 CONFIG_DRIVER_VIDEO_SIMPLEFB_CLIENT=y
 CONFIG_CLOCKSOURCE_DUMMY_RATE=60000
+CONFIG_STATE_DRV=y
 CONFIG_EEPROM_AT24=y
 CONFIG_HWRNG=y
 CONFIG_HW_RANDOM_VIRTIO=y
diff --git a/common/boards/qemu-virt/Makefile b/common/boards/qemu-virt/Makefile
index f10d39138578..88184e9a7969 100644
--- a/common/boards/qemu-virt/Makefile
+++ b/common/boards/qemu-virt/Makefile
@@ -2,3 +2,6 @@
 
 obj-y += board.o
 obj-y += overlay-of-flash.dtb.o
+ifeq ($(CONFIG_RISCV),y)
+DTC_CPP_FLAGS_overlay-of-flash.dtb := -DRISCV_VIRT=1
+endif
diff --git a/common/boards/qemu-virt/board.c b/common/boards/qemu-virt/board.c
index f10608e30343..4064409c80d3 100644
--- a/common/boards/qemu-virt/board.c
+++ b/common/boards/qemu-virt/board.c
@@ -54,6 +54,7 @@ static int virt_probe(struct device_d *dev)
 
 static const struct of_device_id virt_of_match[] = {
 	{ .compatible = "linux,dummy-virt", .data = arm_virt_init },
+	{ .compatible = "riscv-virtio" },
 	{ /* Sentinel */},
 };
 BAREBOX_DEEP_PROBE_ENABLE(virt_of_match);
diff --git a/common/boards/qemu-virt/overlay-of-flash.dts b/common/boards/qemu-virt/overlay-of-flash.dts
index ed6ad0072b55..a271a455105f 100644
--- a/common/boards/qemu-virt/overlay-of-flash.dts
+++ b/common/boards/qemu-virt/overlay-of-flash.dts
@@ -1,8 +1,13 @@
 /dts-v1/;
 /plugin/;
 
+#ifdef RISCV_VIRT
+#define PARTS_TARGET_PATH	"/soc/flash@20000000"
+#define ENV_DEVICE_PATH		"/soc/flash@20000000/partitions/partition@3c00000"
+#else
 #define PARTS_TARGET_PATH	"/flash@0"
 #define ENV_DEVICE_PATH		"/flash@0/partitions/partition@3c00000"
+#endif
 
 / {
 	fragment@0 {
-- 
2.30.2


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


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

* Re: [PATCH 2/7] state: make first boot less verbose
  2021-11-25 16:10 ` [PATCH 2/7] state: make first boot less verbose Ahmad Fatoum
@ 2021-11-30 10:47   ` Sascha Hauer
  2021-11-30 13:52     ` Ahmad Fatoum
  0 siblings, 1 reply; 10+ messages in thread
From: Sascha Hauer @ 2021-11-30 10:47 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Thu, Nov 25, 2021 at 05:10:37PM +0100, Ahmad Fatoum wrote:
> First boot with uninitialized state is needlessly verbose:
> 
>   state: New state registered 'state'
>   state: Detected old on-storage format
>   ERROR: state: Error, invalid header crc in raw format, calculated 0x7bd5c66f, found 0x00000000
>   state: Ignoring broken bucket 0@0x00000000...
>   state: Detected old on-storage format
>   ERROR: state: Error, invalid header crc in raw format, calculated 0x7bd5c66f, found 0x00000000
>   state: Ignoring broken bucket 1@0x00040000...
>   state: Detected old on-storage format
>   ERROR: state: Error, invalid header crc in raw format, calculated 0x7bd5c66f, found 0x00000000
>   state: Ignoring broken bucket 2@0x00080000...
>   ERROR: state: Failed to find any valid state copy in any bucket
>   ERROR: state: Failed to read state with format raw, -2
> 
> This has confused barebox-state novices more than once. Let's handle
> the zeroed state case specially and reduce output in that case, so
> it now looks like this:
> 
>   state: New state registered 'state'
>   state: Detected old on-storage format
>   state: Detected old on-storage format
>   state: Detected old on-storage format
>   state state.of: Fresh state detected, continuing with defaults
> 
> This is only the output when CRC is zero (hinting at zeroed state
> partition). If crc != zero, then output is a little more verbose than
> before:

Should we handle crc == 0xffffffff in the same way for flash devices?

Sascha

-- 
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] 10+ messages in thread

* Re: [PATCH 2/7] state: make first boot less verbose
  2021-11-30 10:47   ` Sascha Hauer
@ 2021-11-30 13:52     ` Ahmad Fatoum
  0 siblings, 0 replies; 10+ messages in thread
From: Ahmad Fatoum @ 2021-11-30 13:52 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

Hello Sascha,

On 30.11.21 11:47, Sascha Hauer wrote:
> On Thu, Nov 25, 2021 at 05:10:37PM +0100, Ahmad Fatoum wrote:
>> First boot with uninitialized state is needlessly verbose:
>>
>>   state: New state registered 'state'
>>   state: Detected old on-storage format
>>   ERROR: state: Error, invalid header crc in raw format, calculated 0x7bd5c66f, found 0x00000000
>>   state: Ignoring broken bucket 0@0x00000000...
>>   state: Detected old on-storage format
>>   ERROR: state: Error, invalid header crc in raw format, calculated 0x7bd5c66f, found 0x00000000
>>   state: Ignoring broken bucket 1@0x00040000...
>>   state: Detected old on-storage format
>>   ERROR: state: Error, invalid header crc in raw format, calculated 0x7bd5c66f, found 0x00000000
>>   state: Ignoring broken bucket 2@0x00080000...
>>   ERROR: state: Failed to find any valid state copy in any bucket
>>   ERROR: state: Failed to read state with format raw, -2
>>
>> This has confused barebox-state novices more than once. Let's handle
>> the zeroed state case specially and reduce output in that case, so
>> it now looks like this:
>>
>>   state: New state registered 'state'
>>   state: Detected old on-storage format
>>   state: Detected old on-storage format
>>   state: Detected old on-storage format
>>   state state.of: Fresh state detected, continuing with defaults
>>
>> This is only the output when CRC is zero (hinting at zeroed state
>> partition). If crc != zero, then output is a little more verbose than
>> before:
> 
> Should we handle crc == 0xffffffff in the same way for flash devices?

I never minded it in practice, because it's only there the very first
time. The problem is with emulated targets, where you see it every time
and sometimes from people who don't know it's expected. I've tested this
with cfi-flash and mtd-ram in QEMU and TinyEMU and there I read zeroes, so
that's what's addressed.

If you think it's worthwhile to do it for crc == ~0 as well, feel free to fix up
on apply. :-)

Cheers,
Ahmad

> 
> Sascha
> 


-- 
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] 10+ messages in thread

end of thread, other threads:[~2021-11-30 13:54 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-25 16:10 [PATCH 0/7] ARM/RISC-V: qemu-virt: share common cleaned up state/env support Ahmad Fatoum
2021-11-25 16:10 ` [PATCH 1/7] state: mark state init errors specially Ahmad Fatoum
2021-11-25 16:10 ` [PATCH 2/7] state: make first boot less verbose Ahmad Fatoum
2021-11-30 10:47   ` Sascha Hauer
2021-11-30 13:52     ` Ahmad Fatoum
2021-11-25 16:10 ` [PATCH 3/7] of: overlay: rescan aliases calling of_overlay_apply_tree on live tree Ahmad Fatoum
2021-11-25 16:10 ` [PATCH 4/7] ARM: qemu: enable deep probe support Ahmad Fatoum
2021-11-25 16:10 ` [PATCH 5/7] ARM: qemu: move board code to central location Ahmad Fatoum
2021-11-25 16:10 ` [PATCH 6/7] common: boards: qemu-virt: genericize to support non-ARM architectures Ahmad Fatoum
2021-11-25 16:10 ` [PATCH 7/7] RISC-V: qemu-virt: add overlay for environment and state Ahmad Fatoum

mail archive of the barebox mailing list

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://lore.barebox.org/barebox/0 barebox/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 barebox barebox/ https://lore.barebox.org/barebox \
		barebox@lists.infradead.org
	public-inbox-index barebox

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git