summaryrefslogtreecommitdiffstats
path: root/common/state/state.c
Commit message (Collapse)AuthorAgeFilesLines
* 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>
* treewide: Use of_property_write_string() where appropriateSascha Hauer2017-03-301-3/+2
| | | | | | | Replace users which use of_set_property() to set a property to a string with of_property_write_string(). Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: Use dev_* for information rather than pr_*Sascha Hauer2016-10-201-4/+4
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: pass error code instead of inventing new oneSascha Hauer2016-10-201-3/+4
| | | | | | | | Both of_find_path() and of_find_path_by_node() return a meaningful error code, so forward it instead of inventing a new one. Do this especially for the -EPROBE_DEFER case which currently does not work. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: fix finding the correct parent nodeMichael Olbrich2016-09-201-2/+2
| | | | | | | | | | Looking for the parent node during fixup is broken. The path of the parent node is not correctly terminated ('0' vs '\0'). Also, the new state node should be added to the supplied device tree not the barebox device tree used by of_find_node_by_path(). Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: don't keep pointers to device tree nodesMichael Olbrich2016-09-201-7/+12
| | | | | | | | | | Caching pointers to device tree nodes or is not save. The barebox internal device tree may be changed by loading a new device tree or through fixup handlers. As a result, the node may be deleted and replaced with a new one. Keep a copy of the full path instead and resolve the node as needed. Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: Save on shutdownSascha Hauer2016-07-221-0/+15
| | | | | | | | | The state framework is meant for storing persistent variables. To make the state more persistent automatically save it on shutdown. This is now the default behaviour, but can be disabled using a 'save_on_shutdown' variable attached to the state. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: also append backend storage stridesizeMichael Grzeschik2016-07-081-0/+7
| | | | | Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: Refactor state frameworkMarkus Pargmann2016-07-081-0/+566
The state framework grew organically over the time. Unfortunately the architecture and abstractions disappeared during this period. This patch refactors the framework to recreate the abstractions. The main focus was the backend with its storage. The main use-case was to offer better NAND support with less erase cycles and interchangeable data formats (dtb,raw). The general architecture now has a backend which consists of a data format and storage. The storage consists of multiple storage buckets each holding exactly one copy of the state data. A data format describes a data serialization for the state framework. This can be either dtb or raw. A storage bucket is a storage location which is used to store any data. There is a (new) circular type which writes changes behind the last written data and therefore reduces the number of erases. The other type is a direct bucket which writes directly to a storage offset for all non-erase storage. Furthermore this patch splits up all classes into different files in a subdirectory. This is currently all in one patch as I can't see a good way to split the changes up without having a non-working state framework in between. The following diagram shows the new architecture roughly: .----------. | state | '----------' | | v .----------------------------. | state_backend | |----------------------------| | + state_load(*state); | | + state_save(*state); | | + state_backend_init(...); | | | | | '----------------------------' | | The format describes | | how the state data | '-------------> is serialized | .--------------------------------------------. | | state_backend_format <INTERFACE> | | |--------------------------------------------| | | + verify(*format, magic, *buf, len); | | | + pack(*format, *state, **buf, len); | | | + unpack(*format, *state, *buf, len); | | | + get_packed_len(*format, *state); | | | + free(*format); | | '--------------------------------------------' | ^ ^ | * * | * * | .--------------------. .--------------------. | | backend_format_dtb | | backend_format_raw | | '--------------------' '--------------------' | | | v .----------------------------------------------------------. | state_backend_storage | |----------------------------------------------------------| | + init(...); | | + free(*storage); | | + read(*storage, *format, magic, **buf, *len, len_hint); | | + write(*storage, *buf, len); | | + restore_consistency(*storage, *buf, len); | '----------------------------------------------------------' | The backend storage is responsible to manage multiple data copies and distribute them onto several buckets. Read data is verified against the given format to ensure that the read data is correct. | | | | | v .------------------------------------------. | state_backend_storage_bucket <INTERFACE> | |------------------------------------------| | + init(*bucket); | | + write(*bucket, *buf, len); | | + read(*bucket, **buf, len_hint); | | + free(*bucket); | '------------------------------------------' ^ ^ ^ * * * * * * A storage bucket represents*exactly one data copy at one data location. A circular b*cket writes any new data to the end of the bucket (for *educed erases on NAND). A direct bucket directly writ*s at one location. * * * * * * * * * .-----------------------. * .-------------------------. | backend_bucket_direct | * | backend_bucket_circular | '-----------------------' * '-------------------------' ^ * ^ | * | | * | | * | | .-----------------------. | '--| backend_bucket_cached |---' '-----------------------' A backend_bucket_cached is a transparent bucket that directly uses another bucket as backend device and caches all accesses. Signed-off-by: Markus Pargmann <mpa@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>