mailarchive of the pengutronix oss-tools mailing list
 help / color / mirror / Atom feed
* [OSS-Tools] [PATCH dt-utils 0/6] barebox-state sync
@ 2024-02-27 14:26 Marco Felsch
  2024-02-27 14:26 ` [OSS-Tools] [PATCH dt-utils 1/6] state: align state_backend_bucket_direct_create with barebox Marco Felsch
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Marco Felsch @ 2024-02-27 14:26 UTC (permalink / raw)
  To: oss-tools

Hi,

this re-sync the barebox_state user-space tool with the barebox code.
The reason for the sync is to avoid error prints in case of fresh
initialized barebox state backends.

While on it, I ported a few other commit as well to align the code with
barebox.

Regards,
  Marco

Marco Felsch (6):
  state: align state_backend_bucket_direct_create with barebox
  state: don't mix goto labels and statements on same line
  state: drop null pointer checks around of_delete_node
  treewide: rename struct device_d to device
  state: make uninitialized state less verbose
  state: backend_bucket_direct: add debug prints on read/write

 src/barebox-state.c                         |  4 +++-
 src/barebox-state/backend_bucket_circular.c |  4 ++--
 src/barebox-state/backend_bucket_direct.c   | 25 +++++++++++++++------
 src/barebox-state/backend_format_dtb.c      |  4 ++--
 src/barebox-state/backend_format_raw.c      | 11 +++++----
 src/barebox-state/backend_storage.c         | 24 ++++++++++++--------
 src/barebox-state/state.c                   | 19 +++++++++-------
 src/barebox-state/state.h                   | 24 ++++++++++++--------
 src/barebox-state/state_variables.c         |  9 +++++---
 src/dt/common.h                             | 22 +++++++++---------
 src/dt/dt.h                                 |  8 +++----
 src/libdt.c                                 |  2 +-
 12 files changed, 93 insertions(+), 63 deletions(-)

-- 
2.39.2




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

* [OSS-Tools] [PATCH dt-utils 1/6] state: align state_backend_bucket_direct_create with barebox
  2024-02-27 14:26 [OSS-Tools] [PATCH dt-utils 0/6] barebox-state sync Marco Felsch
@ 2024-02-27 14:26 ` Marco Felsch
  2024-02-27 14:26 ` [OSS-Tools] [PATCH dt-utils 2/6] state: don't mix goto labels and statements on same line Marco Felsch
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Marco Felsch @ 2024-02-27 14:26 UTC (permalink / raw)
  To: oss-tools

Just a cosmetic commit to reduce the diff to barebox.

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
 src/barebox-state/backend_bucket_direct.c | 3 +--
 src/barebox-state/state.h                 | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/src/barebox-state/backend_bucket_direct.c b/src/barebox-state/backend_bucket_direct.c
index 1518ef679f63..dd9c8570ad3d 100644
--- a/src/barebox-state/backend_bucket_direct.c
+++ b/src/barebox-state/backend_bucket_direct.c
@@ -165,8 +165,7 @@ static void state_backend_bucket_direct_free(struct
 
 int state_backend_bucket_direct_create(struct device_d *dev, const char *path,
 				       struct state_backend_storage_bucket **bucket,
-				       off_t offset, ssize_t max_size,
-				       bool readonly)
+				       off_t offset, ssize_t max_size, bool readonly)
 {
 	int fd;
 	struct state_backend_storage_bucket_direct *direct;
diff --git a/src/barebox-state/state.h b/src/barebox-state/state.h
index 8b87554d90fe..8d279fb4cc11 100644
--- a/src/barebox-state/state.h
+++ b/src/barebox-state/state.h
@@ -227,8 +227,7 @@ void state_backend_set_readonly(struct state *state);
 void state_storage_free(struct state_backend_storage *storage);
 int state_backend_bucket_direct_create(struct device_d *dev, const char *path,
 				       struct state_backend_storage_bucket **bucket,
-				       off_t offset, ssize_t max_size,
-				       bool readonly);
+				       off_t offset, ssize_t max_size, bool readonly);
 int state_storage_write(struct state_backend_storage *storage,
 			const void * buf, ssize_t len);
 int state_storage_read(struct state_backend_storage *storage,
-- 
2.39.2




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

* [OSS-Tools] [PATCH dt-utils 2/6] state: don't mix goto labels and statements on same line
  2024-02-27 14:26 [OSS-Tools] [PATCH dt-utils 0/6] barebox-state sync Marco Felsch
  2024-02-27 14:26 ` [OSS-Tools] [PATCH dt-utils 1/6] state: align state_backend_bucket_direct_create with barebox Marco Felsch
@ 2024-02-27 14:26 ` Marco Felsch
  2024-02-27 14:26 ` [OSS-Tools] [PATCH dt-utils 3/6] state: drop null pointer checks around of_delete_node Marco Felsch
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Marco Felsch @ 2024-02-27 14:26 UTC (permalink / raw)
  To: oss-tools

This is a partial port of:

| commit a81a28f9be1c9d40c20add6a4093d260df8c6049
| Author: Ahmad Fatoum <a.fatoum@pengutronix.de>
| Date:   Fri May 19 12:01:15 2023 +0200
|
|     treewide: don't mix goto labels and statements on same line
|
|     Coding style across the project is not to indent goto labels and
|     to not mix them with code on the same line. Let's fix the few outliers
|     that are there.
|
|     No functional change.
|
|     Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
|     Link: https://lore.barebox.org/20230519100120.2365970-2-a.fatoum@pengutronix.de
|     Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
 src/barebox-state/state.c           | 12 ++++++++----
 src/barebox-state/state_variables.c |  9 ++++++---
 2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/src/barebox-state/state.c b/src/barebox-state/state.c
index 3b02624be756..13d406e6a38b 100644
--- a/src/barebox-state/state.c
+++ b/src/barebox-state/state.c
@@ -335,8 +335,10 @@ static int state_convert_node_variable(struct state *state,
 		goto out;
 
 	return 0;
- out_free:free(name);
- out:	return ret;
+out_free:
+	free(name);
+out:
+	return ret;
 }
 
 struct device_node *state_to_node(struct state *state,
@@ -363,7 +365,8 @@ struct device_node *state_to_node(struct state *state,
 	}
 
 	return root;
- out:	of_delete_node(root);
+out:
+	of_delete_node(root);
 	return ERR_PTR(ret);
 }
 
@@ -563,7 +566,8 @@ static int of_state_fixup(struct device_node *root, void *ctx)
 
 	return 0;
 
- out:	of_delete_node(new_node);
+out:
+	of_delete_node(new_node);
 	return ret;
 }
 
diff --git a/src/barebox-state/state_variables.c b/src/barebox-state/state_variables.c
index a94ccce9b739..daceef6bf427 100644
--- a/src/barebox-state/state_variables.c
+++ b/src/barebox-state/state_variables.c
@@ -264,7 +264,8 @@ static struct state_variable *state_enum32_create(struct state *state,
 	}
 
 	return &enum32->var;
- out:	for (i--; i >= 0; i--)
+out:
+	for (i--; i >= 0; i--)
 		free((char *)enum32->names[i]);
 	free(enum32->names);
 	free(enum32);
@@ -330,7 +331,8 @@ static struct state_variable *state_mac_create(struct state *state,
 	}
 
 	return &mac->var;
- out:	free(mac);
+out:
+	free(mac);
 	return ERR_PTR(ret);
 }
 
@@ -445,7 +447,8 @@ static struct state_variable *state_string_create(struct state *state,
 	}
 
 	return &string->var;
- out:	free(string);
+out:
+	free(string);
 	return ERR_PTR(ret);
 }
 
-- 
2.39.2




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

* [OSS-Tools] [PATCH dt-utils 3/6] state: drop null pointer checks around of_delete_node
  2024-02-27 14:26 [OSS-Tools] [PATCH dt-utils 0/6] barebox-state sync Marco Felsch
  2024-02-27 14:26 ` [OSS-Tools] [PATCH dt-utils 1/6] state: align state_backend_bucket_direct_create with barebox Marco Felsch
  2024-02-27 14:26 ` [OSS-Tools] [PATCH dt-utils 2/6] state: don't mix goto labels and statements on same line Marco Felsch
@ 2024-02-27 14:26 ` Marco Felsch
  2024-02-27 14:26 ` [OSS-Tools] [PATCH dt-utils 4/6] treewide: rename struct device_d to device Marco Felsch
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Marco Felsch @ 2024-02-27 14:26 UTC (permalink / raw)
  To: oss-tools

This is a partial port of:

| commit 035ca2a10ef2b5776629eadb6ea97b22b7978ccb
| Author: Ahmad Fatoum <a.fatoum@pengutronix.de>
| Date:   Fri May 19 12:01:16 2023 +0200
|
|     treewide: drop null pointer checks around of_delete_node
|
|     of_delete_node is a no-op when called on a null pointer, so remove the
|     useless null checks around it.
|
|     Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
|     Link: https://lore.barebox.org/20230519100120.2365970-3-a.fatoum@pengutronix.de
|     Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
 src/barebox-state/state.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/barebox-state/state.c b/src/barebox-state/state.c
index 13d406e6a38b..df76407d4d33 100644
--- a/src/barebox-state/state.c
+++ b/src/barebox-state/state.c
@@ -561,8 +561,7 @@ static int of_state_fixup(struct device_node *root, void *ctx)
 		goto out;
 
 	/* delete existing node */
-	if (node)
-		of_delete_node(node);
+	of_delete_node(node);
 
 	return 0;
 
-- 
2.39.2




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

* [OSS-Tools] [PATCH dt-utils 4/6] treewide: rename struct device_d to device
  2024-02-27 14:26 [OSS-Tools] [PATCH dt-utils 0/6] barebox-state sync Marco Felsch
                   ` (2 preceding siblings ...)
  2024-02-27 14:26 ` [OSS-Tools] [PATCH dt-utils 3/6] state: drop null pointer checks around of_delete_node Marco Felsch
@ 2024-02-27 14:26 ` Marco Felsch
  2024-02-27 14:26 ` [OSS-Tools] [PATCH dt-utils 5/6] state: make uninitialized state less verbose Marco Felsch
  2024-02-27 14:26 ` [OSS-Tools] [PATCH dt-utils 6/6] state: backend_bucket_direct: add debug prints on read/write Marco Felsch
  5 siblings, 0 replies; 7+ messages in thread
From: Marco Felsch @ 2024-02-27 14:26 UTC (permalink / raw)
  To: oss-tools

This ports barebox commit:

| commit c0afc799fb9a19a11f651596fe23b4b755593887
| Author: Sascha Hauer <s.hauer@pengutronix.de>
| Date:   Wed Dec 14 13:35:09 2022 +0100
|
|     Rename struct device_d to device
|
|     The '_d' suffix was originally introduced in case we want to import
|     Linux struct device as a separate struct into barebox. Over time it
|     became clear that this won't happen, instead barebox struct device_d
|     is basically the same as Linux struct device. Rename the struct name
|     accordingly to make porting Linux code easier.
|
|     Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
|     Reviewed-by: Marco Felsch <m.felsch@pengutronix.de>
|     Link: https://lore.barebox.org/20221214123512.189688-3-s.hauer@pengutronix.de
|     Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
 src/barebox-state/backend_bucket_circular.c |  4 ++--
 src/barebox-state/backend_bucket_direct.c   |  4 ++--
 src/barebox-state/backend_format_dtb.c      |  4 ++--
 src/barebox-state/backend_format_raw.c      |  4 ++--
 src/barebox-state/state.h                   | 14 ++++++-------
 src/dt/common.h                             | 22 ++++++++++-----------
 src/dt/dt.h                                 |  8 ++++----
 src/libdt.c                                 |  2 +-
 8 files changed, 31 insertions(+), 31 deletions(-)

diff --git a/src/barebox-state/backend_bucket_circular.c b/src/barebox-state/backend_bucket_circular.c
index 0906268f5e7c..b84463c4be5e 100644
--- a/src/barebox-state/backend_bucket_circular.c
+++ b/src/barebox-state/backend_bucket_circular.c
@@ -63,7 +63,7 @@ struct state_backend_storage_bucket_circular {
 #endif
 
 	/* For outputs */
-	struct device_d *dev;
+	struct device *dev;
 };
 
 /*
@@ -457,7 +457,7 @@ static int bucket_circular_is_block_bad(struct state_backend_storage_bucket_circ
 }
 #endif
 
-int state_backend_bucket_circular_create(struct device_d *dev, const char *path,
+int state_backend_bucket_circular_create(struct device *dev, const char *path,
 					 struct state_backend_storage_bucket **bucket,
 					 unsigned int eraseblock,
 					 ssize_t writesize,
diff --git a/src/barebox-state/backend_bucket_direct.c b/src/barebox-state/backend_bucket_direct.c
index dd9c8570ad3d..cf77c3f6a0df 100644
--- a/src/barebox-state/backend_bucket_direct.c
+++ b/src/barebox-state/backend_bucket_direct.c
@@ -30,7 +30,7 @@ struct state_backend_storage_bucket_direct {
 
 	int fd;
 
-	struct device_d *dev;
+	struct device *dev;
 };
 
 struct __attribute__((__packed__)) state_backend_storage_bucket_direct_meta {
@@ -163,7 +163,7 @@ static void state_backend_bucket_direct_free(struct
 	free(direct);
 }
 
-int state_backend_bucket_direct_create(struct device_d *dev, const char *path,
+int state_backend_bucket_direct_create(struct device *dev, const char *path,
 				       struct state_backend_storage_bucket **bucket,
 				       off_t offset, ssize_t max_size, bool readonly)
 {
diff --git a/src/barebox-state/backend_format_dtb.c b/src/barebox-state/backend_format_dtb.c
index 1d701efb3709..ab57990a8dc5 100644
--- a/src/barebox-state/backend_format_dtb.c
+++ b/src/barebox-state/backend_format_dtb.c
@@ -29,7 +29,7 @@ struct state_backend_format_dtb {
 	struct device_node *root;
 
 	/* For outputs */
-	struct device_d *dev;
+	struct device *dev;
 };
 
 static inline struct state_backend_format_dtb *get_format_dtb(struct
@@ -132,7 +132,7 @@ static void state_backend_format_dtb_free(struct state_backend_format *format)
 }
 
 int backend_format_dtb_create(struct state_backend_format **format,
-			      struct device_d *dev)
+			      struct device *dev)
 {
 	struct state_backend_format_dtb *dtb;
 
diff --git a/src/barebox-state/backend_format_raw.c b/src/barebox-state/backend_format_raw.c
index 686eb983bfba..8127a27e5732 100644
--- a/src/barebox-state/backend_format_raw.c
+++ b/src/barebox-state/backend_format_raw.c
@@ -33,7 +33,7 @@ struct state_backend_format_raw {
 	unsigned int digest_length;
 
 	/* For outputs */
-	struct device_d *dev;
+	struct device *dev;
 
 	char *secret_name;
 	int needs_secret;
@@ -301,7 +301,7 @@ static int backend_format_raw_init_digest(struct state_backend_format_raw *raw,
 
 int backend_format_raw_create(struct state_backend_format **format,
 			      struct device_node *node, const char *secret_name,
-			      struct device_d *dev)
+			      struct device *dev)
 {
 	struct state_backend_format_raw *raw;
 	int ret;
diff --git a/src/barebox-state/state.h b/src/barebox-state/state.h
index 8d279fb4cc11..c8217a382070 100644
--- a/src/barebox-state/state.h
+++ b/src/barebox-state/state.h
@@ -91,7 +91,7 @@ struct state_backend_storage {
 	struct list_head buckets;
 
 	/* For outputs */
-	struct device_d *dev;
+	struct device *dev;
 
 	const char *name;
 
@@ -106,7 +106,7 @@ struct state_backend_storage {
 struct state {
 	struct list_head list; /* Entry to enqueue on list of states */
 
-	struct device_d dev;
+	struct device dev;
 	char *of_path;
 	const char *name;
 	uint32_t magic;
@@ -203,21 +203,21 @@ struct device_node *state_to_node(struct state *state,
 				  enum state_convert conv);
 int backend_format_raw_create(struct state_backend_format **format,
 			      struct device_node *node, const char *secret_name,
-			      struct device_d *dev);
+			      struct device *dev);
 int backend_format_dtb_create(struct state_backend_format **format,
-			      struct device_d *dev);
+			      struct device *dev);
 int state_storage_init(struct state *state, const char *path,
 		       off_t offset, size_t max_size, uint32_t stridesize,
 		       const char *storagetype);
 void state_storage_set_readonly(struct state_backend_storage *storage);
 void state_add_var(struct state *state, struct state_variable *var);
 struct variable_type *state_find_type_by_name(const char *name);
-int state_backend_bucket_circular_create(struct device_d *dev, const char *path,
+int state_backend_bucket_circular_create(struct device *dev, const char *path,
 					 struct state_backend_storage_bucket **bucket,
 					 unsigned int eraseblock,
 					 ssize_t writesize,
 					 struct mtd_info_user *mtd_uinfo);
-int state_backend_bucket_cached_create(struct device_d *dev,
+int state_backend_bucket_cached_create(struct device *dev,
 				       struct state_backend_storage_bucket *raw,
 				       struct state_backend_storage_bucket **out);
 struct state_variable *state_find_var(struct state *state, const char *name);
@@ -225,7 +225,7 @@ struct digest *state_backend_format_raw_get_digest(struct state_backend_format
 						   *format);
 void state_backend_set_readonly(struct state *state);
 void state_storage_free(struct state_backend_storage *storage);
-int state_backend_bucket_direct_create(struct device_d *dev, const char *path,
+int state_backend_bucket_direct_create(struct device *dev, const char *path,
 				       struct state_backend_storage_bucket **bucket,
 				       off_t offset, ssize_t max_size, bool readonly);
 int state_storage_write(struct state_backend_storage *storage,
diff --git a/src/dt/common.h b/src/dt/common.h
index 7ba1bed1d475..a3c2642c0ec8 100644
--- a/src/dt/common.h
+++ b/src/dt/common.h
@@ -45,14 +45,14 @@ typedef uint64_t u64;
 	(void) (&_min1 == &_min2);		\
 	_min1 < _min2 ? _min1 : _min2; })
 
-struct device_d;
+struct device;
 
 void pr_level_set(int level);
 int pr_level_get(void);
 
 int pr_printf(int level, const char *format, ...)
         __attribute__ ((format(__printf__, 2, 3)));
-int dev_printf(int level, const struct device_d *dev, const char *format, ...)
+int dev_printf(int level, const struct device *dev, const char *format, ...)
         __attribute__ ((format(__printf__, 3, 4)));
 
 #define pr_err(fmt, arg...)	pr_printf(3, fmt, ##arg)
@@ -372,13 +372,13 @@ static inline int is_zero_ether_addr(const u8 *addr)
 #define MAX_DRIVER_NAME		32
 #define DEVICE_ID_SINGLE	-1
 
-struct device_d {
+struct device {
 	char name[MAX_DRIVER_NAME];
 	int id;
 	struct device_node *device_node;
 };
 
-static inline struct param_d *dev_add_param_enum(struct device_d *dev, const char *name,
+static inline struct param_d *dev_add_param_enum(struct device *dev, const char *name,
 		int (*set)(struct param_d *p, void *priv),
 		int (*get)(struct param_d *p, void *priv),
 		uint32_t *value, const char * const *names, int max, void *priv)
@@ -387,7 +387,7 @@ static inline struct param_d *dev_add_param_enum(struct device_d *dev, const cha
 	return NULL;
 }
 
-static inline struct param_d *dev_add_param_bool(struct device_d *dev, const char *name,
+static inline struct param_d *dev_add_param_bool(struct device *dev, const char *name,
 		int (*set)(struct param_d *p, void *priv),
 		int (*get)(struct param_d *p, void *priv),
 		uint32_t *value, void *priv)
@@ -395,7 +395,7 @@ static inline struct param_d *dev_add_param_bool(struct device_d *dev, const cha
 	return NULL;
 }
 
-static inline struct param_d *dev_add_param_mac(struct device_d *dev, const char *name,
+static inline struct param_d *dev_add_param_mac(struct device *dev, const char *name,
 		int (*set)(struct param_d *p, void *priv),
 		int (*get)(struct param_d *p, void *priv),
 		u8 *mac, void *priv)
@@ -403,7 +403,7 @@ static inline struct param_d *dev_add_param_mac(struct device_d *dev, const char
 	return NULL;
 }
 
-static inline struct param_d *dev_add_param_string(struct device_d *dev, const char *name,
+static inline struct param_d *dev_add_param_string(struct device *dev, const char *name,
 		int (*set)(struct param_d *p, void *priv),
 		int (*get)(struct param_d *p, void *priv),
 		char **value, void *priv)
@@ -411,7 +411,7 @@ static inline struct param_d *dev_add_param_string(struct device_d *dev, const c
 	return NULL;
 }
 
-static inline struct param_d *dev_add_param_uint32(struct device_d *dev, const char *name,
+static inline struct param_d *dev_add_param_uint32(struct device *dev, const char *name,
 		int (*set)(struct param_d *p, void *priv),
 		int (*get)(struct param_d *p, void *priv),
 		uint32_t *value, const char *format, void *priv)
@@ -424,7 +424,7 @@ static inline struct param_d *dev_add_param_uint32(struct device_d *dev, const c
  * @dev: device
  * @fmt: format string for the device's name
  */
-static inline int dev_set_name(struct device_d *dev, const char *fmt, ...)
+static inline int dev_set_name(struct device *dev, const char *fmt, ...)
 {
 	char newname[MAX_DRIVER_NAME];
 	va_list vargs;
@@ -454,11 +454,11 @@ static inline int register_driver(struct driver_d *d)
 	return 0;
 }
 
-static inline int register_device(struct device_d *d)
+static inline int register_device(struct device *d)
 {
 	return 0;
 }
-static inline int unregister_device(struct device_d *d)
+static inline int unregister_device(struct device *d)
 {
 	return 0;
 }
diff --git a/src/dt/dt.h b/src/dt/dt.h
index e473b4e7cea5..a5a2da269a24 100644
--- a/src/dt/dt.h
+++ b/src/dt/dt.h
@@ -62,10 +62,10 @@ struct of_reserve_map *of_get_reserve_map(void);
 void of_clean_reserve_map(void);
 void fdt_add_reserve_map(void *fdt);
 
-struct device_d;
+struct device;
 struct driver_d;
 
-int of_match(struct device_d *dev, struct driver_d *drv);
+int of_match(struct device *dev, struct driver_d *drv);
 
 struct fdt_header *fdt_get_tree(void);
 
@@ -222,9 +222,9 @@ extern int of_set_root_node(struct device_node *node);
 
 extern int of_platform_populate(struct device_node *root,
 				const struct of_device_id *matches,
-				struct device_d *parent);
+				struct device *parent);
 
-int of_device_is_stdout_path(struct device_d *dev);
+int of_device_is_stdout_path(struct device *dev);
 const char *of_get_model(void);
 void *of_flatten_dtb(struct device_node *node);
 int of_add_memory(struct device_node *node, bool dump);
diff --git a/src/libdt.c b/src/libdt.c
index 72e8ab41e09b..0cfce4af9b39 100644
--- a/src/libdt.c
+++ b/src/libdt.c
@@ -74,7 +74,7 @@ int pr_printf(int level, const char *format, ...)
 	return ret;
 }
 
-int dev_printf(int level, const struct device_d *dev, const char *format, ...)
+int dev_printf(int level, const struct device *dev, const char *format, ...)
 {
 	va_list args;
 	int ret = 0;
-- 
2.39.2




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

* [OSS-Tools] [PATCH dt-utils 5/6] state: make uninitialized state less verbose
  2024-02-27 14:26 [OSS-Tools] [PATCH dt-utils 0/6] barebox-state sync Marco Felsch
                   ` (3 preceding siblings ...)
  2024-02-27 14:26 ` [OSS-Tools] [PATCH dt-utils 4/6] treewide: rename struct device_d to device Marco Felsch
@ 2024-02-27 14:26 ` Marco Felsch
  2024-02-27 14:26 ` [OSS-Tools] [PATCH dt-utils 6/6] state: backend_bucket_direct: add debug prints on read/write Marco Felsch
  5 siblings, 0 replies; 7+ messages in thread
From: Marco Felsch @ 2024-02-27 14:26 UTC (permalink / raw)
  To: oss-tools

This patch ports barebox commits:

| commit 22d06d7d72d781d16db7f8292181d51752e2a860
| Author: Ahmad Fatoum <a.fatoum@pengutronix.de>
| Date:   Thu Nov 25 17:10:36 2021 +0100
|
|     state: mark state init errors specially
|
|     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>
|     Link: https://lore.barebox.org/20211125161042.3829996-2-a.fatoum@pengutronix.de
|     Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>

| commit 863a2251393e5ee5ecdd6d696ee0e23c3b945f9a
| Author: Ahmad Fatoum <a.fatoum@pengutronix.de>
| Date:   Thu Nov 25 17:10:37 2021 +0100
|
|     state: make first boot less verbose
|
|     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>
|     Link: https://lore.barebox.org/20211125161042.3829996-3-a.fatoum@pengutronix.de
|     Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>

| commit 818d180da1c709f3d2789925662222019b3cf439
| Author: Ahmad Fatoum <ahmad@a3f.at>
| Date:   Mon Nov 29 08:22:35 2021 +0100
|
|     state: make first boot with uninitialized legacy state less verbose
|
|     With non-legacy state, barebox checks a header for a specific magic
|     signature. This can be all zero on an uninitialized state, so in that
|     particular case, bump down the log message severity.
|
|     Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
|     Link: https://lore.barebox.org/20211129072235.2016324-1-ahmad@a3f.at
|     Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
 src/barebox-state.c                       |  4 +++-
 src/barebox-state/backend_bucket_direct.c |  4 ++--
 src/barebox-state/backend_format_raw.c    |  7 +++----
 src/barebox-state/backend_storage.c       | 24 ++++++++++++++---------
 src/barebox-state/state.c                 |  4 ++--
 src/barebox-state/state.h                 |  7 +++++++
 6 files changed, 32 insertions(+), 18 deletions(-)

diff --git a/src/barebox-state.c b/src/barebox-state.c
index e74ba1992286..1a515d30dde4 100644
--- a/src/barebox-state.c
+++ b/src/barebox-state.c
@@ -409,7 +409,9 @@ struct state *state_get(const char *name, const char *filename, bool readonly, b
 	else
 		ret = state_load_no_auth(state);
 
-	if (ret)
+	if (ret == -ENOMEDIUM)
+		pr_info("Fresh state detected, continuing with defaults\n");
+	else if (ret)
 		pr_err("Failed to load persistent state, continuing with defaults, %d\n", ret);
 
 	return state;
diff --git a/src/barebox-state/backend_bucket_direct.c b/src/barebox-state/backend_bucket_direct.c
index cf77c3f6a0df..bf060ebed4c0 100644
--- a/src/barebox-state/backend_bucket_direct.c
+++ b/src/barebox-state/backend_bucket_direct.c
@@ -77,9 +77,9 @@ static int state_backend_bucket_direct_read(struct state_backend_storage_bucket
 		if (meta.magic != ~0 && !!meta.magic)
 			bucket->wrong_magic = 1;
 		if (!IS_ENABLED(CONFIG_STATE_BACKWARD_COMPATIBLE)) {
-			dev_err(direct->dev, "No meta data header found\n");
 			dev_dbg(direct->dev, "Enable backward compatibility or increase stride size\n");
-			return -EINVAL;
+			return dev_err_state_init(direct->dev, meta.magic ? -EINVAL : -ENOMEDIUM,
+						  "No meta data header found\n");
 		}
 		read_len = direct->max_size;
 		if (lseek(direct->fd, direct->offset, SEEK_SET) !=
diff --git a/src/barebox-state/backend_format_raw.c b/src/barebox-state/backend_format_raw.c
index 8127a27e5732..85ea539657dc 100644
--- a/src/barebox-state/backend_format_raw.c
+++ b/src/barebox-state/backend_format_raw.c
@@ -114,11 +114,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) {
-		dev_err(backend_raw->dev, "Error, invalid 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);
-		return -EINVAL;
-	}
 
 	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/src/barebox-state/backend_storage.c b/src/barebox-state/backend_storage.c
index 6d659c1fd85a..135c7aad0e81 100644
--- a/src/barebox-state/backend_storage.c
+++ b/src/barebox-state/backend_storage.c
@@ -145,6 +145,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");
@@ -153,30 +154,35 @@ 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)
+		if (ret == -EUCLEAN) {
 			bucket->needs_refresh = 1;
-		else if (ret)
+		} else if (ret) {
+			if (ret == -ENOMEDIUM)
+				zerobuckets++;
 			continue;
+		}
 
 		/*
 		 * Verify the buffer crcs. The buffer length is passed in the len argument,
 		 * .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) {
-		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, 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/src/barebox-state/state.c b/src/barebox-state/state.c
index df76407d4d33..d842bf1de0ec 100644
--- a/src/barebox-state/state.c
+++ b/src/barebox-state/state.c
@@ -102,8 +102,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/src/barebox-state/state.h b/src/barebox-state/state.h
index c8217a382070..734899b075b1 100644
--- a/src/barebox-state/state.h
+++ b/src/barebox-state/state.h
@@ -290,3 +290,10 @@ static inline int open_exclusive(const char *path, int flags)
 
 	return fd;
 }
+
+#define dev_err_state_init(dev, ret, fmt, ...) ({ \
+	int __ret = (ret); \
+	dev_printf(__ret == -ENOMEDIUM ? 7 : 3, \
+		   (dev), "init error: %pe: " fmt, ERR_PTR(__ret), ##__VA_ARGS__); \
+	__ret; \
+})
-- 
2.39.2




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

* [OSS-Tools] [PATCH dt-utils 6/6] state: backend_bucket_direct: add debug prints on read/write
  2024-02-27 14:26 [OSS-Tools] [PATCH dt-utils 0/6] barebox-state sync Marco Felsch
                   ` (4 preceding siblings ...)
  2024-02-27 14:26 ` [OSS-Tools] [PATCH dt-utils 5/6] state: make uninitialized state less verbose Marco Felsch
@ 2024-02-27 14:26 ` Marco Felsch
  5 siblings, 0 replies; 7+ messages in thread
From: Marco Felsch @ 2024-02-27 14:26 UTC (permalink / raw)
  To: oss-tools

This ports barebox commit:

| commit 2cc9777631ac22e2f8831727a7463000ba83c80e
| Author: Ahmad Fatoum <a.fatoum@pengutronix.de>
| Date:   Fri Jul 28 15:31:58 2023 +0200
|
|     state: backend_bucket_direct: add debug prints on read/write
|
|     We already have debug prints for the circular backend to help see how
|     much data is read/written for each bucket. Add similar debugging info
|     for the direct backend as well. Example with stride size of 2048 and
|     44 bytes for the variable set:
|
|       barebox@board:/ state -l
|       state: Read state from 0 length 68
|       state: Read state from 2048 length 68
|       state: Read state from 4096 length 68
|
|       barebox@board:/ state -s
|       state: Written state to offset 0 length 68 data length 60
|       state: Written state to offset 2048 length 68 data length 60
|       state: Written state to offset 4096 length 68 data length 60
|
|     Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
|     Reviewed-by: Johannes Zink <j.zink@pengutronix.de>
|     Link: https://lore.barebox.org/20230728133158.3828436-1-a.fatoum@pengutronix.de
|     Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
 src/barebox-state/backend_bucket_direct.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/barebox-state/backend_bucket_direct.c b/src/barebox-state/backend_bucket_direct.c
index bf060ebed4c0..3e756e21dd41 100644
--- a/src/barebox-state/backend_bucket_direct.c
+++ b/src/barebox-state/backend_bucket_direct.c
@@ -53,7 +53,7 @@ static int state_backend_bucket_direct_read(struct state_backend_storage_bucket
 	struct state_backend_storage_bucket_direct *direct =
 	    get_bucket_direct(bucket);
 	struct state_backend_storage_bucket_direct_meta meta;
-	uint32_t read_len;
+	uint32_t read_len, header_len = 0;
 	void *buf;
 	int ret;
 
@@ -73,6 +73,8 @@ static int state_backend_bucket_direct_read(struct state_backend_storage_bucket
 			return -EINVAL;
 
 		}
+
+		header_len = sizeof(meta);
 	} else {
 		if (meta.magic != ~0 && !!meta.magic)
 			bucket->wrong_magic = 1;
@@ -88,12 +90,16 @@ static int state_backend_bucket_direct_read(struct state_backend_storage_bucket
 				-errno);
 			return -errno;
 		}
+
 	}
 
 	buf = xmalloc(read_len);
 	if (!buf)
 		return -ENOMEM;
 
+	dev_dbg(direct->dev, "Read state from %lld length %d\n", (long long) direct->offset,
+		header_len + read_len);
+
 	ret = read_full(direct->fd, buf, read_len);
 	if (ret < 0) {
 		dev_err(direct->dev, "Failed to read from file, %d\n", ret);
@@ -113,6 +119,7 @@ static int state_backend_bucket_direct_write(struct state_backend_storage_bucket
 {
 	struct state_backend_storage_bucket_direct *direct =
 	    get_bucket_direct(bucket);
+	size_t header_len = 0;
 	int ret;
 	struct state_backend_storage_bucket_direct_meta meta;
 
@@ -130,6 +137,8 @@ static int state_backend_bucket_direct_write(struct state_backend_storage_bucket
 			dev_err(direct->dev, "Failed to write metadata to file, %d\n", ret);
 			return ret;
 		}
+
+		header_len = sizeof(meta);
 	} else {
 		if (!IS_ENABLED(CONFIG_STATE_BACKWARD_COMPATIBLE)) {
 			dev_dbg(direct->dev, "Too small stride size: must skip metadata! Increase stride size\n");
@@ -149,6 +158,9 @@ static int state_backend_bucket_direct_write(struct state_backend_storage_bucket
 		return ret;
 	}
 
+	dev_dbg(direct->dev, "Written state to offset %lld length %zu data length %zu\n",
+		(long long)direct->offset, len + header_len, len);
+
 	return 0;
 }
 
-- 
2.39.2




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

end of thread, other threads:[~2024-02-27 14:26 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-27 14:26 [OSS-Tools] [PATCH dt-utils 0/6] barebox-state sync Marco Felsch
2024-02-27 14:26 ` [OSS-Tools] [PATCH dt-utils 1/6] state: align state_backend_bucket_direct_create with barebox Marco Felsch
2024-02-27 14:26 ` [OSS-Tools] [PATCH dt-utils 2/6] state: don't mix goto labels and statements on same line Marco Felsch
2024-02-27 14:26 ` [OSS-Tools] [PATCH dt-utils 3/6] state: drop null pointer checks around of_delete_node Marco Felsch
2024-02-27 14:26 ` [OSS-Tools] [PATCH dt-utils 4/6] treewide: rename struct device_d to device Marco Felsch
2024-02-27 14:26 ` [OSS-Tools] [PATCH dt-utils 5/6] state: make uninitialized state less verbose Marco Felsch
2024-02-27 14:26 ` [OSS-Tools] [PATCH dt-utils 6/6] state: backend_bucket_direct: add debug prints on read/write Marco Felsch

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