From: Marco Felsch <m.felsch@pengutronix.de> To: oss-tools@pengutronix.de Cc: mfe@pengutronix.de Subject: [OSS-Tools] [PATCH dt-utils 04/14] state: treat state with all-invalid buckets as dirty Date: Fri, 14 Oct 2022 18:41:54 +0200 [thread overview] Message-ID: <20221014164204.3812506-5-m.felsch@pengutronix.de> (raw) In-Reply-To: <20221014164204.3812506-1-m.felsch@pengutronix.de> This ports the following barebox commit | commit f41e5160c8618455064a4ff4227105010cd56aaa | Author: Ahmad Fatoum <a.fatoum@pengutronix.de> | Date: Thu Mar 5 08:40:32 2020 +0100 | | state: treat state with all-invalid buckets as dirty | | The state.dirty flag controls whether state_save will actually | persist state. It is cleared when we successfully load or save | state and set on writing a state parameter. | | When the state however becomes corrupt during barebox runtime and | state.dirty == 0, reinitializing the state to defaults is quite | cumbersome: | | 1. We reset twice. After the first reset, the dirty flag is reset | and before the second, state_save will reinitialize to defaults | 2. We write any state variable and then run the state -s command | | Both workarounds are quite obscure, improve the user experience | by having state -l set the dirty flag when it fails, so a subsequent | state -s may persist the default values to state. | | Steps to reproduce: | | barebox$ state -l | state: Using bucket 0@0x00000000 | barebox$ memcpy -s /dev/zero -d /dev/eeprom0.state 0 0 0x400 | barebox$ state -s | barebox$ state -l | ERROR: state: No meta data header found | ERROR: state: No meta data header found | ERROR: state: No meta data header found | ERROR: state: Failed to find any valid state copy in any bucket | ERROR: state: Failed to read state with format raw, -2 | state: No such file or directory | | Signed-off-by: Ahmad Fatoum <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 | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/barebox-state/state.c b/src/barebox-state/state.c index f528b3e..f6b7817 100644 --- a/src/barebox-state/state.c +++ b/src/barebox-state/state.c @@ -93,7 +93,7 @@ out: */ static int state_do_load(struct state *state, enum state_flags flags) { - void *buf; + void *buf = NULL; ssize_t len; int ret; @@ -102,7 +102,7 @@ static int state_do_load(struct state *state, enum state_flags flags) if (ret) { dev_err(&state->dev, "Failed to read state with format %s, %d\n", state->format->name, ret); - return ret; + goto out; } ret = state->format->unpack(state->format, state, buf, len); @@ -113,9 +113,8 @@ static int state_do_load(struct state *state, enum state_flags flags) } state->init_from_defaults = 0; - state->dirty = 0; - out: + state->dirty = !!ret; /* mark dirty on error */ free(buf); return ret; } -- 2.30.2
next prev parent reply other threads:[~2022-10-14 16:42 UTC|newest] Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-10-14 16:41 [OSS-Tools] [PATCH dt-utils 00/14] Sync Barebox-State code base Marco Felsch 2022-10-14 16:41 ` [OSS-Tools] [PATCH dt-utils 01/14] state: Remove duplicate incudes Marco Felsch 2022-10-14 16:41 ` [OSS-Tools] [PATCH dt-utils 02/14] state: backend_raw: fix ignoring unpack failures Marco Felsch 2022-10-14 16:41 ` [OSS-Tools] [PATCH dt-utils 03/14] state: backend_storage: deal gracefully with runtime bucket corruption Marco Felsch 2022-10-14 16:41 ` Marco Felsch [this message] 2022-10-14 16:41 ` [OSS-Tools] [PATCH dt-utils 05/14] state: remove param member from struct state_string Marco Felsch 2022-10-14 16:41 ` [OSS-Tools] [PATCH dt-utils 06/14] state: remove param member from state_uint32, state_enum32, state_mac Marco Felsch 2022-10-14 16:41 ` [OSS-Tools] [PATCH dt-utils 07/14] state: remove unused function Marco Felsch 2022-10-14 16:41 ` [OSS-Tools] [PATCH dt-utils 08/14] state: propagate failure to fixup enum32 into DT Marco Felsch 2022-10-14 16:41 ` [OSS-Tools] [PATCH dt-utils 09/14] state: add SPDX-License-Identifier for files without explicit license Marco Felsch 2022-10-14 16:42 ` [OSS-Tools] [PATCH dt-utils 10/14] state: fix typos found with codespell Marco Felsch 2022-10-14 16:42 ` [OSS-Tools] [PATCH dt-utils 11/14] common: xstrdup: don't panic on xstrdup(NULL) Marco Felsch 2022-10-14 16:42 ` [OSS-Tools] [PATCH dt-utils 12/14] libdt: add of_property_write_strings support Marco Felsch 2022-10-14 16:42 ` [OSS-Tools] [PATCH dt-utils 13/14] libdt: add partition search function Marco Felsch 2022-10-14 16:42 ` [OSS-Tools] [PATCH dt-utils 14/14] state: sync with barebox to support new backend type Marco Felsch 2022-10-21 7:37 ` [OSS-Tools] [PATCH dt-utils 00/14] Sync Barebox-State code base Marco Felsch
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20221014164204.3812506-5-m.felsch@pengutronix.de \ --to=m.felsch@pengutronix.de \ --cc=mfe@pengutronix.de \ --cc=oss-tools@pengutronix.de \ --subject='Re: [OSS-Tools] [PATCH dt-utils 04/14] state: treat state with all-invalid buckets as dirty' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox