summaryrefslogtreecommitdiffstats
path: root/common/state
Commit message (Collapse)AuthorAgeFilesLines
* Merge branch 'for-next/state'Sascha Hauer2016-11-145-12/+13
|\
| * state: fix indentationStefan Lengfeld2016-11-031-3/+3
| | | | | | | | | | Signed-off-by: Stefan Lengfeld <s.lengfeld@phytec.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * state: use packed attribute for on storage structsStefan Lengfeld2016-11-033-3/+3
| | | | | | | | | | | | | | | | | | | | | | These structs are used for on-storage data layouts. They should be not affected by different integer precisions and alignment optimizations of 32bit or 64bit machines. Using the architecture independent integer data types, like uint32_t, achieves the former, using the packed attribute the later. Signed-off-by: Stefan Lengfeld <s.lengfeld@phytec.de> 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 state is not saved when string variable is changedStefan Lengfeld2016-11-031-1/+1
|/ | | | | | | The dirty flag was not set properly. Signed-off-by: Stefan Lengfeld <s.lengfeld@phytec.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: consistently pass one type as private data to dev_add_param_*Sascha Hauer2016-09-201-14/+15
| | | | | | | The different dev_add_param_* calls all use different types as private data. This is unnecessary, use struct state_variable * for all of them. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: make locally used function staticSascha Hauer2016-09-202-2/+1
| | | | | | state_set_dirty() is only used in one file, make it static. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: Add state to state_variableSascha Hauer2016-09-202-6/+8
| | | | | | | A state variable should know which state it belongs to. Add field for it to struct state_variable. 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-202-8/+13
| | | | | | | | | | 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: copy backend of_path stringMichael Olbrich2016-09-202-2/+3
| | | | | | | | | | Caching pointers to device tree nodes or names is not safe. The barebox internal device tree may be changed by loading a new device tree or through fixup handlers. As a result, the string may be deleted. Use local copies of the full path instead. Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/misc'Sascha Hauer2016-08-032-0/+16
|\
| * state: Save on shutdownSascha Hauer2016-07-222-0/+16
| | | | | | | | | | | | | | | | | | 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: only build circular backend if MTD is enabledLucas Stach2016-07-252-3/+5
|/ | | | | | | | The circular backend depends on MTD symbols and is only useful if MTD is present. Exclude it from the build if MTD is not enabled. Signed-off-by: Lucas Stach <l.stach@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: also append backend storage stridesizeMichael Grzeschik2016-07-083-0/+10
| | | | | Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: Refactor state frameworkMarkus Pargmann2016-07-0811-0/+3384
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>