From mboxrd@z Thu Jan 1 00:00:00 1970 Delivery-date: Fri, 14 Oct 2022 18:42:16 +0200 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by lore.white.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1ojNlJ-008iES-KD for lore@lore.pengutronix.de; Fri, 14 Oct 2022 18:42:16 +0200 Received: from localhost ([127.0.0.1] helo=metis.ext.pengutronix.de) by metis.ext.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1ojNlE-0006Uk-S9; Fri, 14 Oct 2022 18:42:12 +0200 Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ojNlB-0006GH-Ov; Fri, 14 Oct 2022 18:42:09 +0200 Received: from [2a0a:edc0:0:1101:1d::28] (helo=dude02.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.94.2) (envelope-from ) id 1ojNlB-001WU7-35; Fri, 14 Oct 2022 18:42:09 +0200 Received: from mfe by dude02.red.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1ojNl8-00FzpO-MF; Fri, 14 Oct 2022 18:42:06 +0200 From: Marco Felsch To: oss-tools@pengutronix.de Date: Fri, 14 Oct 2022 18:41:54 +0200 Message-Id: <20221014164204.3812506-5-m.felsch@pengutronix.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221014164204.3812506-1-m.felsch@pengutronix.de> References: <20221014164204.3812506-1-m.felsch@pengutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [OSS-Tools] [PATCH dt-utils 04/14] state: treat state with all-invalid buckets as dirty 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: , Cc: mfe@pengutronix.de 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.ext.pengutronix.de); SAEximRunCond expanded to false This ports the following barebox commit | commit f41e5160c8618455064a4ff4227105010cd56aaa | Author: Ahmad Fatoum | 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 | Signed-off-by: Sascha Hauer Signed-off-by: Marco Felsch --- 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