summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2021-11-25 17:10:37 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2021-12-07 15:03:31 +0100
commit863a2251393e5ee5ecdd6d696ee0e23c3b945f9a (patch)
tree75667279ccba0ca22318016ed300b16d7a5dd7d0 /common
parent22d06d7d72d781d16db7f8292181d51752e2a860 (diff)
downloadbarebox-863a2251393e5ee5ecdd6d696ee0e23c3b945f9a.tar.gz
barebox-863a2251393e5ee5ecdd6d696ee0e23c3b945f9a.tar.xz
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>
Diffstat (limited to 'common')
-rw-r--r--common/state/backend_format_raw.c6
-rw-r--r--common/state/backend_storage.c12
-rw-r--r--common/state/state.h9
3 files changed, 20 insertions, 7 deletions
diff --git a/common/state/backend_format_raw.c b/common/state/backend_format_raw.c
index aeee41d07c..1fecdeb9cf 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 2d7d9a4a63..72f8bcf521 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 d858c9e427..48572c5d41 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; \
})