9
0
Fork 0
barebox/common
Markus Pargmann c999b507da 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>
2016-07-08 08:59:31 +02:00
..
partitions partitions: dos: add partuuid string for logical partitions 2016-05-10 08:13:33 +02:00
state state: Refactor state framework 2016-07-08 08:59:31 +02:00
.gitignore update .gitignore files for linker scripts 2009-01-21 23:28:14 +01:00
Kconfig defaultenv-2: select BOOTM 2016-06-24 08:23:33 +02:00
Makefile state: Refactor state framework 2016-07-08 08:59:31 +02:00
bbu.c Merge branch 'for-next/imx-bbu-nand-fcb' 2016-04-08 13:37:28 +02:00
binfmt.c command: Let builtin command take precedence 2013-09-24 09:03:18 +02:00
block.c block: Add flush callback 2014-07-14 08:01:11 +02:00
blspec.c Merge branch 'for-next/include-cleanup' 2016-05-09 08:49:42 +02:00
bootargs.c string: Fix (v)asprintf prototypes 2016-04-15 12:21:45 +02:00
bootm.c bootm: make verbosity controllable via global variable 2016-05-11 08:16:31 +02:00
bootsource.c bootsource: Add NET bootsource 2015-05-27 08:56:07 +02:00
clock.c common: clock: introduce mdelay_non_interruptible() 2015-10-02 07:50:51 +02:00
command.c common/command.c: Replace magic number with appropriate constant 2015-10-15 08:56:21 +02:00
complete.c completion: fix device parameter completion 2015-08-07 09:20:39 +02:00
console.c console: Fix initial value of baudrate parameter 2016-05-26 09:13:09 +02:00
console_common.c stdio: Replace FILE functions with filedescriptor functions 2016-04-15 12:21:46 +02:00
console_countdown.c stdio: rename getc to getchar 2016-04-15 12:21:46 +02:00
console_simple.c stdio: rename getc to getchar 2016-04-15 12:21:46 +02:00
date.c hwclock command: use format like the Linux tool does 2016-01-07 08:45:12 +01:00
ddr_spd.c ddr_spd: add routine for printing DDR2 SPD contents in human-readable format 2015-07-14 07:09:19 +02:00
dlmalloc.c dlmalloc: remove unused functions 2014-07-09 07:38:12 +02:00
dummy_malloc.c dummy malloc: Add licence header 2013-03-08 08:47:51 +01:00
efi-devicepath.c efi: add helper to get the GPT partition UUID for a device 2015-07-27 07:23:17 +02:00
efi-guid.c efi: use an EFI variable to save the environment 2015-07-27 07:23:20 +02:00
env.c Merge branch 'for-next/include-cleanup' 2016-05-09 08:49:42 +02:00
environment.c Merge branch 'for-next/include-cleanup' 2016-05-09 08:49:42 +02:00
file-list.c Add function to parse a string in dfu format 2014-07-22 08:11:08 +02:00
filetype.c filetype: Fix booting ARM Linux Kernels with CONFIG_EFI enabled 2016-04-19 10:56:16 +02:00
firmware.c string: Fix (v)asprintf prototypes 2016-04-15 12:21:45 +02:00
globalvar.c Merge branch 'for-next/misc' 2016-05-09 08:49:43 +02:00
hush.c hush: fix indentation 2016-01-11 13:31:57 +01:00
image-fit.c bootm: Add verify mode "available" 2016-05-10 16:02:13 +02:00
image.c bootm: Move bootm options to common/Kconfig 2016-05-10 14:51:58 +02:00
imd-barebox.c Add support for metadata in barebox images 2014-08-07 06:13:52 +02:00
imd.c imd: make it work on big-endian machines 2016-05-23 09:33:21 +02:00
imx-bbu-nand-fcb.c imx-bbu-nand-fcb: avoid double free of dbbt_entries 2016-07-07 09:36:31 +02:00
kallsyms.c treewide: fix 'new blank line at EOF' formatting error 2015-07-02 09:39:58 +02:00
meminfo.c Merge branch 'for-next/pr_print' 2013-04-04 14:20:33 +02:00
memory.c malloc: Add a function to detect if malloc pool is already initialized 2015-01-05 11:30:59 +01:00
memory_display.c memory_display: Add 64bit support 2015-05-28 12:29:49 +02:00
memsize.c Add warning above get_ram_size 2013-02-13 18:14:38 +01:00
memtest.c Revert "memtest: move error handling to end of function" 2015-12-04 08:01:59 +01:00
menu.c menu: add vi like key support 2016-04-19 08:12:46 +02:00
menutree.c string: Fix (v)asprintf prototypes 2016-04-15 12:21:45 +02:00
misc.c common: Add EPROBE_DEFER to strerror 2016-03-17 08:23:05 +01:00
module.c whole tree: remove trailing whitespaces 2016-04-21 15:17:52 +02:00
module.lds.S Treewide: remove address of the Free Software Foundation 2012-09-17 10:57:41 +02:00
oftree.c common: oftree: Add function to register set status fixup 2016-03-01 08:25:42 +01:00
parser.c common/parser.c: Do not treat zero return code as error 2015-10-15 08:56:21 +02:00
partitions.c string: Fix (v)asprintf prototypes 2016-04-15 12:21:45 +02:00
password.c stdio: rename getc to getchar 2016-04-15 12:21:46 +02:00
poller.c poller: Fix async poller 2016-01-13 15:55:23 +01:00
ratp.c ratp: use proper defines for BAREBOX_CMD 2016-03-04 07:54:58 +01:00
reset_source.c reset_source: export reset_source_set_priority 2016-05-13 12:02:09 +02:00
resource.c resource: Let request_ioport_region return an error pointer 2014-09-16 08:32:10 +02:00
restart.c restart: replace reset_cpu with registered restart handlers 2015-08-27 21:37:03 +02:00
s_record.c Treewide: remove address of the Free Software Foundation 2012-09-17 10:57:41 +02:00
startup.c include: move shell prototypes to shell.h 2016-04-15 12:21:44 +02:00
tlsf.c whole tree: remove trailing whitespaces 2016-04-21 15:17:52 +02:00
tlsf_malloc.c meminfo: purely cosmetical changes 2014-06-02 09:07:12 +02:00
tlsfbits.h tlsf malloc: enable 64bit support on 64bit architectures 2015-05-22 09:40:31 +02:00
ubiformat.c ubiformat: use default values for ubi_ver and image_seq 2016-04-26 09:24:57 +02:00
uimage.c bootm: Move bootm options to common/Kconfig 2016-05-10 14:51:58 +02:00
version.c startup: Don't print multiple lines with pr_info 2014-09-30 10:44:16 +02:00