From mboxrd@z Thu Jan 1 00:00:00 1970 Delivery-date: Tue, 27 Feb 2024 15:26:16 +0100 Received: from metis.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::104]) by lore.white.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1reyPQ-00AlBy-15 for lore@lore.pengutronix.de; Tue, 27 Feb 2024 15:26:16 +0100 Received: from localhost ([127.0.0.1] helo=metis.whiteo.stw.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1reyPP-00045Y-5G; Tue, 27 Feb 2024 15:26:15 +0100 Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1reyPM-00040E-OL for oss-tools@pengutronix.de; Tue, 27 Feb 2024 15:26:12 +0100 Received: from [2a0a:edc0:0:1101:1d::28] (helo=dude02.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1reyPM-003Dbi-8y for oss-tools@pengutronix.de; Tue, 27 Feb 2024 15:26:12 +0100 Received: from mfe by dude02.red.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1reyPM-00AA2D-0h for oss-tools@pengutronix.de; Tue, 27 Feb 2024 15:26:12 +0100 From: Marco Felsch To: oss-tools@pengutronix.de Date: Tue, 27 Feb 2024 15:26:10 +0100 Message-Id: <20240227142611.2421711-6-m.felsch@pengutronix.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240227142611.2421711-1-m.felsch@pengutronix.de> References: <20240227142611.2421711-1-m.felsch@pengutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [OSS-Tools] [PATCH dt-utils 5/6] state: make uninitialized state less verbose X-BeenThere: oss-tools@pengutronix.de X-Mailman-Version: 2.1.29 Precedence: list List-Id: Pengutronix Public Open-Source-Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "OSS-Tools" X-SA-Exim-Connect-IP: 127.0.0.1 X-SA-Exim-Mail-From: oss-tools-bounces@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false This patch ports barebox commits: | commit 22d06d7d72d781d16db7f8292181d51752e2a860 | Author: Ahmad Fatoum | 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 | Link: https://lore.barebox.org/20211125161042.3829996-2-a.fatoum@pengutronix.de | Signed-off-by: Sascha Hauer | commit 863a2251393e5ee5ecdd6d696ee0e23c3b945f9a | Author: Ahmad Fatoum | 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 | Link: https://lore.barebox.org/20211125161042.3829996-3-a.fatoum@pengutronix.de | Signed-off-by: Sascha Hauer | commit 818d180da1c709f3d2789925662222019b3cf439 | Author: Ahmad Fatoum | 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 | Link: https://lore.barebox.org/20211129072235.2016324-1-ahmad@a3f.at | Signed-off-by: Sascha Hauer Signed-off-by: Marco Felsch --- 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