summaryrefslogtreecommitdiffstats
path: root/drivers/misc
diff options
context:
space:
mode:
authorMarkus Pargmann <mpa@pengutronix.de>2016-07-06 10:19:43 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2016-07-08 08:59:31 +0200
commitc999b507da9891f22cf2a60105bffa0774eea082 (patch)
treedbc1a712b3ab6919758c1cffc6f979ba8c98d59f /drivers/misc
parent3d33f178ccd7b0602b20c8fb37d7e57beed22e89 (diff)
downloadbarebox-c999b507da9891f22cf2a60105bffa0774eea082.tar.gz
barebox-c999b507da9891f22cf2a60105bffa0774eea082.tar.xz
state: Refactor state framework
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>
Diffstat (limited to 'drivers/misc')
-rw-r--r--drivers/misc/state.c65
1 files changed, 2 insertions, 63 deletions
diff --git a/drivers/misc/state.c b/drivers/misc/state.c
index 73356b45a0..b9eb1b7bb2 100644
--- a/drivers/misc/state.c
+++ b/drivers/misc/state.c
@@ -24,75 +24,14 @@
static int state_probe(struct device_d *dev)
{
struct device_node *np = dev->device_node;
- struct device_node *partition_node;
struct state *state;
- const char *alias;
- const char *backend_type = NULL;
- int len, ret;
- const char *of_path;
- char *path;
+ bool readonly = false;
- if (!np)
- return -EINVAL;
-
- alias = of_alias_get(np);
- if (!alias)
- alias = np->name;
-
- state = state_new_from_node(alias, np);
+ state = state_new_from_node(np, NULL, 0, 0, readonly);
if (IS_ERR(state))
return PTR_ERR(state);
- of_path = of_get_property(np, "backend", &len);
- if (!of_path) {
- ret = -ENODEV;
- goto out_release;
- }
-
- /* guess if of_path is a path, not a phandle */
- if (of_path[0] == '/' && len > 1) {
- ret = of_find_path(np, "backend", &path, 0);
- } else {
-
- partition_node = of_parse_phandle(np, "backend", 0);
- if (!partition_node)
- return -EINVAL;
-
- of_path = partition_node->full_name;
- ret = of_find_path_by_node(partition_node, &path, 0);
- }
-
- if (ret == -ENODEV)
- ret = -EPROBE_DEFER;
- if (ret)
- goto out_release;
-
- ret = of_property_read_string(np, "backend-type", &backend_type);
- if (ret) {
- goto out_free;
- } else if (!strcmp(backend_type, "raw")) {
- ret = state_backend_raw_file(state, of_path, path, 0, 0);
- } else if (!strcmp(backend_type, "dtb")) {
- ret = state_backend_dtb_file(state, of_path, path);
- } else {
- dev_warn(dev, "invalid backend type: %s\n", backend_type);
- ret = -ENODEV;
- goto out_free;
- }
-
- if (ret)
- goto out_free;
-
- dev_info(dev, "backend: %s, path: %s, of_path: %s\n", backend_type, path, of_path);
- free(path);
-
return 0;
-
- out_free:
- free(path);
- out_release:
- state_release(state);
- return ret;
}
static __maybe_unused struct of_device_id state_ids[] = {