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>
1 parent dc5100e commit f41e5160c8618455064a4ff4227105010cd56aaa
@Ahmad Fatoum Ahmad Fatoum authored on 5 Mar 2020
Sascha Hauer committed on 9 Mar 2020
Showing 1 changed file
View
common/state/state.c