summaryrefslogtreecommitdiffstats
path: root/common/state/state.c
Commit message (Collapse)AuthorAgeFilesLines
* treewide: Print device nodes with %pOFSascha Hauer2023-07-031-4/+4
| | | | | | | We have the %pOF format specifier for printing device nodes. Use it where appropriate. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/state'Sascha Hauer2023-06-221-11/+39
|\
| * state: allow lookup of barebox state partition by Type GUIDAhmad Fatoum2023-06-121-0/+16
| | | | | | | | | | | | | | | | | | | | | | | | The backend device tree property so far always pointed at a partition. Let's allow pointing it at GPT storage devices directly and lookup the correct barebox state partition by the well-known type GUID: 4778ed65-bf42-45fa-9c5b-287a1dc4aab1 Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230607120714.3083182-20-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * state: factor device path lookup into helper functionAhmad Fatoum2023-06-121-7/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | The #ifdef __BAREBOX__ is meant for easier synchronization with dt-utils. We'll keep that intact, but move it out of the function to not break reading flow. After sync, dt-utils would now need to implement of_cdev_find cdev_to_devpath Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230607120714.3083182-17-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * of: of_path: always call of_partition_ensure_probed before resolvingAhmad Fatoum2023-06-081-10/+0
| | | | | | | | | | | | | | | | | | | | | | | | of_find_path may be called on a partition, whose parent device is not yet probed. state code solves that by calling of_partition_ensure_probed before of_find_path_by_node, but really we should be doing that for all calls to of_find_path. Do so. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Reviewed-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.barebox.org/20230607120714.3083182-7-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * state: fix deep probe handlingAhmad Fatoum2023-06-081-3/+9
| | | | | | | | | | | | | | | | | | | | | | | | State backend doesn't necessarily point at a device tree node that has a device associated, e.g. when we have a top-level fixed-partitions node with the barebox-specific partuuid binding. As of_find_path_by_node will iterate over all available cdev's we need not handle the error and can just call of_find_path_by_node. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230607120714.3083182-6-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | treewide: drop null pointer checks around of_delete_nodeAhmad Fatoum2023-05-251-2/+1
| | | | | | | | | | | | | | | | | | of_delete_node is a no-op when called on a null pointer, so remove the useless null checks around it. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230519100120.2365970-3-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | treewide: don't mix goto labels and statements on same lineAhmad Fatoum2023-05-251-4/+8
|/ | | | | | | | | | | | Coding style across the project is not to indent goto labels and to not mix them with code on the same line. Let's fix the few outliers that are there. No functional change. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230519100120.2365970-2-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: backend: direct: open backend in read-only mode if possibleAhmad Fatoum2023-01-161-3/+3
| | | | | | | | | | | | | | | | | We unconditionally open the device backing a direct bucket in read-write mode. We already populate struct state_backend_storage::readonly though, which we could consult at device open time. Do so. This could possibly be done for MTD as well, but until that's tested, for now, we do it only for the direct backend meant for use with block devices. This has no functional change for barebox, which calls state_new_from_node in the DT driver and in the EFI initcall always with readonly=false, but we can benefit from this in barebox_state to open a device in read-only mode when possible (e.g. when called to --dump). Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230116125443.713033-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: add deep probe aware helpers to get stateAhmad Fatoum2022-02-071-1/+19
| | | | | | | | | | | | | | state_by_name itself can't be made deep probe aware as it doesn't have enough information on what to probe. Board code calling it must instead itself ensure that the state has been proved (either via initcall ordering or by calling e.g. of_ensure_probed_by_alias). For state_by_node we can do it better: We can ensure probe of the supplied device node. For most purposes, users just want to probe the default state. This can now be done with state_by_alias("state"). Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20220202111932.1227416-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: mark state init errors speciallyAhmad Fatoum2021-12-071-2/+2
| | | | | | | | | | 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 <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20211125161042.3829996-2-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: support deep probeAhmad Fatoum2021-07-181-0/+4
| | | | | | | | | | | | With deep probe, drivers registered before of_populate_initcall must themselves take care to ensure their dependencies had a chance to probe. For barebox-state, this means the backend partition provider must be probed. Do so by calling of_partition_ensure_probed on it. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20210628064517.28636-5-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* treewide: replace strerror(-PTR_ERR(errno)) with %pe format specifierAhmad Fatoum2020-09-291-2/+1
| | | | | | | | | Using %pe instead of PTR_ERR has the benefit of being less verbose and less error-prone (no negation necessary) while potentially reducing code size. Make use of it. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: fix typos found with codespellYegor Yefremov2020-03-231-1/+1
| | | | | Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: treat state with all-invalid buckets as dirtyAhmad Fatoum2020-03-091-4/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* state: drop unused code and declarations for non-existing functionsUwe Kleine-König2019-10-141-7/+0
| | | | | | | | | state_get_name() is not used and so can be removed. state_backend_dtb_file() and state_backend_raw_file() were dropped in c999b507da98 ("state: Refactor state framework"). Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: state: harmonize code with dt-utilsUlrich Ölmann2019-02-111-2/+8
| | | | | | | | | Other than in barebox the offset and size of a state's backend device do not necessarily equal zero in Linux userspace (EEPROMs & block devices), so barebox' and dt-utils' state code differ here. Signed-off-by: Ulrich Ölmann <u.oelmann@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: state: fix typoUlrich Ölmann2019-02-071-1/+1
| | | | | Signed-off-by: Ulrich Ölmann <u.oelmann@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/state'Sascha Hauer2018-11-091-1/+1
|\
| * common: state: fix typoUlrich Ölmann2018-10-101-1/+1
| | | | | | | | | | Signed-off-by: Ulrich Ölmann <u.oelmann@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | Merge branch 'for-next/net-switch-mv88e6xxx'Sascha Hauer2018-11-091-1/+1
|\ \
| * | drivers: Introduce dev_set_name()Andrey Smirnov2018-10-181-1/+1
| |/ | | | | | | | | | | | | | | Introduce dev_set_name() in order to hide implementation details of setting device's name so it'd be easier to change it. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | state: fix indentationUlrich Ölmann2018-10-191-1/+1
| | | | | | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | state: fix documentation of state_new_from_node()Ulrich Ölmann2018-10-121-0/+1
|/ | | | | | | | Commit a66a8d79871c ("state: remove unused arguments from state_new_from_node()") removed a little bit too much. Signed-off-by: Ulrich Ölmann <u.oelmann@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: state: Add property to protect existing dataDaniel Schultz2018-04-161-1/+18
| | | | | | | | | | | After an update to a newer barebox version with an enabled state framework, existing data in storage memories could be overwritten. Add a new property to check in front of every write task, if the meta magic field only contains the magic number, zeros or ones. Signed-off-by: Daniel Schultz <d.schultz@phytec.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: find backend node with its reproducible nameSascha Hauer2018-02-221-1/+5
| | | | | | | | | | | | When fixing up the kernels state nodes we depended on the full node path of the input device tree. This does not work when the kernel device tree has different names. This has happened lately when the i.MX6 device trees got their leading zeroes removed from the node names. Use of_find_node_by_reproducible_name() to find the node corresponding to the storage backend node in the kernel device tree. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: remove unused arguments from state_new_from_node()Sascha Hauer2018-02-221-28/+16
| | | | | | | | state_new_from_node() has arguments describing the backend path. These are never used in barebox, the backend path is always derived from the device nodes backend description. Remove these arguments. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: Add 'init_from_defaults' parameterSascha Hauer2018-02-061-0/+7
| | | | | | | The init_from_defaults parameter allows to detect if a state has been initialized from default values, i.e. state_load failed. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: refuse to set dirty parameter via setenvSascha Hauer2018-02-061-1/+6
| | | | | | The dirty parameter is readonly, so refuse to set it. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: state: Add function to read state MACDaniel Schultz2017-11-071-0/+21
| | | | | | | | This API function allows to receive a copy of a MAC address from variables in a state. Signed-off-by: Daniel Schultz <d.schultz@phytec.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: state: Add variable_type to state_variableDaniel Schultz2017-11-071-1/+1
| | | | | | | | Add a pointer in state_variable to the corresponding variable_type array element. Signed-off-by: Daniel Schultz <d.schultz@phytec.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: provide an error message when an error occursJuergen Borleis2017-09-061-0/+1
| | | | | | | | A simple typo makes the state framework fail, but without an error message the developer is lost in the dark. Signed-off-by: Juergen Borleis <jbe@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: add debugging helpJuergen Borleis2017-09-061-0/+2
| | | | | | | | | While working on the state documentation it turns out to be helpful to have more debug messages while a developer implements a 'state' variable set and tries to configure it correctly. Signed-off-by: Juergen Borleis <jbe@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: do not complain about missing backend-storage-typeSascha Hauer2017-05-231-7/+2
| | | | | | | | backend-storage-type is irrelevant for mtd devices, so do not complain about this option missing. The mtd backend will print messages if necessary. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: remove unused variablesSascha Hauer2017-05-111-9/+0
| | | | | | | | There's no need to check for the existence of the backend property as this is done implicitly later anyway. With this check removed of_path is only assigned, but never used. Remove the unused code. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: Create alias in of_state_fixup()Sascha Hauer2017-05-041-1/+12
| | | | | | | | When the kernel device tree is fixed up we assume that it doesn't have a state node, so we must also assume that it doesn't have a alias. Create it. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: Make an alias mandatorySascha Hauer2017-05-041-2/+4
| | | | | | | | The userspace barebox-state utility gets confused when no alias exists. Make the alias mandatory, so that people make it right^tm without having to ask. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: warn when a state node will be overwrittenSascha Hauer2017-05-041-0/+9
| | | | | | | | | People do not seem to know that a state node in the kernel device tree will be overwritten by barebox. Print a warning when this happens so that people can get an idea why changes in the kernel device tree state node do not have any effect. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: Fix error return valueSascha Hauer2017-04-191-0/+1
| | | | | | | When the backend phandle cannot be resolved we jump to the error return path without initializing ret. Fix this. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: remove unused variable typeSascha Hauer2017-04-041-1/+0
| | | | | | enum state_variable_type is never used. Remove it. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: find device node from device path, not from device node pathSascha Hauer2017-03-311-5/+5
| | | | | | | | | The device node path may change from the internal device tree to the one Linux is started with, so using this path to fixup the tree is not very robust. Instead, use of_find_node_by_devpath() which has been created for exactly this purpose. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: Do not load state during state_new_from_nodeSascha Hauer2017-03-311-5/+0
| | | | | | | | The caller of state_new_from_node() may have it's own ideas what to do when loading the state fails, so do not load it in the initialization function, but instead let the caller do it. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: Allow to load without authentificationSascha Hauer2017-03-311-2/+12
| | | | | | | Sometimes it's useful to be able to load a state even when it can't be authentificated. Add an option for this. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: Convert all bufs to void *Sascha Hauer2017-03-311-2/+2
| | | | | | | | A void * is a much better type for a buffer than a u8 * as it can be casted to any other type implicitly. Convert all buffers used by the state framework to void *. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: pass struct state * to storage functionsSascha Hauer2017-03-311-1/+1
| | | | | | | We can get a state_backend_storage * and the device * from struct state, so pass this to the storage functions rather than the two pointers. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: remove unnecessary argument from state_format_initSascha Hauer2017-03-311-7/+6
| | | | | | | The device pointer is already in struct state, no need to pass it around when a struct state * is already passed. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: open code state_backend_init in callerSascha Hauer2017-03-311-57/+13
| | | | | | | Safes a lot of argument passing to a function that is used only once. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: merge backend.c into state.cSascha Hauer2017-03-311-0/+161
| | | | | | | The code in backend.c is too small to justify an extra file. Merge it into state.c. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: Drop backend as extra struct typeSascha Hauer2017-03-311-17/+17
| | | | | | | struct state_backend is embedded into struct state. This additional indirection does not have any real gain. Drop it. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: Make pointing to the backend using a phandle the only supported methodSascha Hauer2017-03-311-12/+9
| | | | | | | | | | All other methods are broken for some time already: When starting the kernel the state code rewrites the state node in the device tree and replaced the "backend" property with a phandle - even when the target can't be described as a phandle. Since using phandles is the nicest way to point to the storage device anyway remove the other methods. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>