summaryrefslogtreecommitdiffstats
path: root/common/state
Commit message (Collapse)AuthorAgeFilesLines
* state: Fix lseek error check in state_mtd_peb_write()Andrey Smirnov2019-03-111-4/+3
| | | | | | | | | Don't use 'int' to store lseek()'s return value to avoid problems with large seek offsets. While at it, make sure to populate return error code from 'errno'. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: Fix lseek error check in state_mtd_peb_read()Andrey Smirnov2019-03-111-4/+3
| | | | | | | | | Don't use 'int' to store lseek()'s return value to avoid problems with large seek offsets. While at it, make sure to populate return error code from 'errno'. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: Fix lseek error check in state_backend_bucket_direct_write()Andrey Smirnov2019-03-111-4/+3
| | | | | | | | | Don't use 'int' to store lseek()'s return value to avoid problems with large seek offsets. While at it, make sure to populate return error code from 'errno'. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: Fix lseek error check in state_backend_bucket_direct_read()Andrey Smirnov2019-03-111-8/+8
| | | | | | | | | Don't use 'int' to store lseek()'s return value to avoid problems with large seek offsets. While at it, make sure to populate return error code from 'errno'. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: state: harmonize code with dt-utilsUlrich Ölmann2019-02-111-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Insert a helpful size check that is an outcome of the following dt-utils commits: | commit a6eb5350be0f7a5673162d20f2dd72569d5a4d0c | Author: Markus Pargmann <mpa@pengutronix.de> | Date: Fri May 27 13:53:40 2016 +0200 | | barebox-state: Import updated state code | | Signed-off-by: Markus Pargmann <mpa@pengutronix.de> | commit 583acea6669550ffa7ffb465301ddb3529206afc | Author: Sascha Hauer <s.hauer@pengutronix.de> | Date: Thu Mar 23 11:29:50 2017 +0100 | | state: backend-direct: Fix max_size | | The max_size in the direct backend includes the meta data, so | substract its size when determing the max data size we can store. | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> | commit dcf781f1b3d15aff5f5ff0b604bff447dee2040c | Author: Sascha Hauer <s.hauer@pengutronix.de> | Date: Thu Mar 23 12:59:48 2017 +0100 | | state: backend_bucket_direct: max_size is always given | | max_size is always != 0, so if(direct->max_size) can be skipped. | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Signed-off-by: Ulrich Ölmann <u.oelmann@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: state: harmonize code with dt-utilsUlrich Ölmann2019-02-111-1/+1
| | | | | | | | | | | | | | Linux userspace with recent glibc versions lets barebox-state suffer from linux/stat.h redefining 'struct statx' and because of that switched to the inclusion of sys/stat.h instead, see dt-utils commit 1c80e31872ae ("src: fix compilation for glibc version 2.27.9000-36.fc29 and newer"). We can follow this switch in barebox without any problems, too, as in barebox sys/stat.h includes linux/stat.h (and adds some more definitions on top that don't hurt us here). Signed-off-by: Ulrich Ölmann <u.oelmann@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: state: harmonize code with dt-utilsUlrich Ölmann2019-02-111-0/+4
| | | | | | | Linux userspace needs sys/param.h to have the definition of roundup(). Signed-off-by: Ulrich Ölmann <u.oelmann@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 formatting of "uint32_t" variablesUlrich Ölmann2019-02-111-3/+3
| | | | | | | | | | | | | | | | | | | To harmonize the common codebase this ports the following dt-utils commit: | commit 5588a6c32d54bc4a1ef0b9f72807c46dd00bc20e | Author: Ulrich Ölmann <u.oelmann@pengutronix.de> | Date: Sun Feb 3 22:48:07 2019 +0100 | | state: fix formatting of "uint32_t" variables | | The format specifier "%zd" is for "size_t" typed variables and produces a | warning with gcc, so use "%u" instead. | | Signed-off-by: Ulrich Ölmann <u.oelmann@pengutronix.de> | Signed-off-by: Roland Hieber <rhi@pengutronix.de> Signed-off-by: Ulrich Ölmann <u.oelmann@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: state: fix formatting of "off_t" variablesUlrich Ölmann2019-02-112-26/+26
| | | | | | | | | | | | | | | | | | | | To harmonize the common codebase this ports the following dt-utils commit: | commit 89d033284cb69f834c1f2195c9e99a3d7f585cf1 | Author: Ulrich Ölmann <u.oelmann@pengutronix.de> | Date: Sun Feb 3 22:48:06 2019 +0100 | | state: fix formatting of "off_t" variables | | Explicitely casting an "off_t" variable to "long long" and formatting it via | "%lld" or "%llx" respectively makes 32- as well as 64-bit compilers | happy (tested with gcc-8.2.1 and clang-7.0.1). | | Signed-off-by: Ulrich Ölmann <u.oelmann@pengutronix.de> | Signed-off-by: Roland Hieber <rhi@pengutronix.de> Signed-off-by: Ulrich Ölmann <u.oelmann@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: state: fix compiler warnings about wrong type conversion in messagesUlrich Ölmann2019-02-111-7/+7
| | | | | | | | | | | | | | | | | | | | | To harmonize the common codebase this ports the remaining hunks of the following dt-utils commit, as the residual hunks have independently already been done before in barebox commit 1afbf6b5680e ("state: fix compile warnings for dev_err expansion"): | commit 9f1db73234b40f4ea071421e8179065df16211ec | Author: Philipp Rosenberger <p.rosenberger@linutronix.de> | Date: Thu Oct 18 09:17:23 2018 +0200 | | Fix compiler warnings about wrong type conversion in messages. | | These warning were observed with gcc-6.3 on x86-64. | | Signed-off-by: Philipp Rosenberger <p.rosenberger@linutronix.de> | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Signed-off-by: Ulrich Ölmann <u.oelmann@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: state: fix typoUlrich Ölmann2019-02-073-4/+4
| | | | | Signed-off-by: Ulrich Ölmann <u.oelmann@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: state: fix another alignmentRoland Hieber2019-01-081-1/+1
| | | | | | | Fixes: 7126dffd0be ("common: state: Add variable_type to state_variable") Fixes: 6096a0cfa4a ("common: state: fix alignment") Signed-off-by: Roland Hieber <rhi@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: state: fix alignmentRoland Hieber2019-01-071-4/+4
| | | | | | Fixes: 7126dffd0be ("common: state: Add variable_type to state_variable") Signed-off-by: Roland Hieber <rhi@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: remove unused functionSascha Hauer2018-11-191-13/+0
| | | | | | state_find_type() is unused and doesn't have a prototype. Remove it. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/state'Sascha Hauer2018-11-092-7/+8
|\
| * state: backend_bucket_circular: remove unused variablesUlrich Ölmann2018-10-121-2/+0
| | | | | | | | | | | | | | | | This has been forgotten in commit 9d6d91931afb ("state: Remove -EUCLEAN check from userspace tool"). Signed-off-by: Ulrich Ölmann <u.oelmann@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * 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>
| * state: backend_bucket_circular: fix memory leakUlrich Ölmann2018-10-101-4/+7
| | | | | | | | | | 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: use of_property_write_string() where appropriateUlrich Ölmann2018-10-121-4/+2
|/ | | | | | | | See commit b6089182316d ("treewide: Use of_property_write_string() where appropriate"). Signed-off-by: Ulrich Ölmann <u.oelmann@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: backend_bucket_circular: fix for non power of 2 writesizeLadislav Michl2018-09-261-2/+2
| | | | | | | | | backend_bucket_circular currently assumes writesize is power of 2, which makes it fail on dataflash devices, where this assumption is false. Signed-off-by: Ladislav Michl <ladis@linux-mips.org> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: state: Add property to protect existing dataDaniel Schultz2018-04-164-4/+27
| | | | | | | | | | | 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-222-1/+6
| | | | | | | | | | | | 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-062-0/+9
| | | | | | | 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 as enumDaniel Schultz2017-11-072-0/+27
| | | | | | | | | | | The variable_type struct holds a name of its type. Checking the type of a variable with this string needs much resources. This patch introduce a enum of the variable type for better type checking. 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-073-9/+21
| | | | | | | | 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>
* remove checks for xzalloc() returning NULLUwe Kleine-König2017-09-263-8/+0
| | | | | | | xzalloc() either returns memory or panics, so checking for NULL is useless. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: don't use uninitialized variableJuergen Borleis2017-09-061-1/+1
| | | | | | | Printing 'ret' makes no sense. Signed-off-by: Juergen Borleis <jbe@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: use the given backend storage type nameJuergen Borleis2017-09-061-4/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | Change 119f92b27e131a0cb506fe8d8bffe8010fb14a3d already tried to fix it, but forgets the 'direct' usecase. The 'backend-storage-type' node is optional. Its default depends on the capability of the used backend memory, which means "circular" or NULL. The latter defaults to 'direct' in the routines. If it is NULL, the devicetree fixup routine skips exporting a 'backend-storage-type' node to the kernel's devicetree. But currently if the 'backend-storage-type' node is explicitly given as 'direct', it will be skipped silently and set to NULL instead. In this case the user of the 'barebox-state' tool then ends up with the warning: "No backend-storage-type found, using default" which is annoying, because it was given. Storing the given value will still use a NULL if the 'backend-storage-type' node isn't defined, but stores everything else if it is defined. Then the 'backend-storage-type' node is present in the kernel's devicetree as well. Signed-off-by: Juergen Borleis <jbe@pengutronix.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-062-1/+8
| | | | | | | | | 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: keep backward compatibilityJuergen Borleis2017-09-061-9/+19
| | | | | | | | | | | | | Previous 'state' variable set variants do not know and use metadata. The 'direct' storage backend's read function honors this, but not its counterpart the write function. This makes an update of the 'state' variable set impossible. This change makes backward compatibility explicit, else it complains in the read function as well. With some more debug output it helps the developer to do things right. Signed-off-by: Juergen Borleis <jbe@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/state'Lucas Stach2017-07-312-3/+1
|\
| * state: backend_storage: remove unreachable error messagePhilipp Zabel2017-07-201-2/+0
| | | | | | | | | | | | | | This looks like a leftover. Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de> Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
| * state: backend_bucket_circular: promote old state debug message to infoPhilipp Zabel2017-07-201-1/+1
| | | | | | | | | | | | | | | | A report about the changed on-storage state format might be interesting to the user. Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de> Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
* | Merge branch 'for-next/efi'Lucas Stach2017-07-313-3/+3
|\ \
| * | state: fix compile warnings for dev_err expansionSteffen Trumtrar2017-07-103-3/+3
| |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fix the following warnings: CC common/state/backend_format_dtb.o In file included from include/common.h:33:0, from common/state/backend_format_dtb.c:18: common/state/backend_format_dtb.c: In function ‘state_backend_format_dtb_verify’: include/printk.h:52:52: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘size_t {aka long unsigned int}’ [-Wformat=] (level) <= LOGLEVEL ? dev_printf((level), (dev), (format), ##args) : 0; \ ^ include/printk.h:63:2: note: in expansion of macro ‘__dev_printf’ __dev_printf(3, (dev) , format , ## arg) ^~~~~~~~~~~~ common/state/backend_format_dtb.c:52:3: note: in expansion of macro ‘dev_err’ dev_err(fdtb->dev, "Error, stored DTB length (%d) longer than read buffer (%d)\n", ^~~~~~~ include/printk.h:52:52: warning: format ‘%d’ expects argument of type ‘int’, but argument 5 has type ‘size_t {aka long unsigned int}’ [-Wformat=] (level) <= LOGLEVEL ? dev_printf((level), (dev), (format), ##args) : 0; \ ^ include/printk.h:63:2: note: in expansion of macro ‘__dev_printf’ __dev_printf(3, (dev) , format , ## arg) ^~~~~~~~~~~~ common/state/backend_format_dtb.c:52:3: note: in expansion of macro ‘dev_err’ dev_err(fdtb->dev, "Error, stored DTB length (%d) longer than read buffer (%d)\n", ^~~~~~~ CC common/state/backend_format_raw.o In file included from include/common.h:33:0, from common/state/backend_format_raw.c:18: common/state/backend_format_raw.c: In function ‘backend_format_raw_verify’: include/printk.h:52:52: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘ssize_t {aka long int}’ [-Wformat=] (level) <= LOGLEVEL ? dev_printf((level), (dev), (format), ##args) : 0; \ ^ include/printk.h:63:2: note: in expansion of macro ‘__dev_printf’ __dev_printf(3, (dev) , format , ## arg) ^~~~~~~~~~~~ common/state/backend_format_raw.c:111:3: note: in expansion of macro ‘dev_err’ dev_err(backend_raw->dev, "Error, buffer length (%d) is shorter than the minimum required header length\n", ^~~~~~~ CC common/state/backend_storage.o In file included from common/state/backend_storage.c:24:0: common/state/backend_storage.c: In function ‘state_storage_mtd_buckets_init’: include/printk.h:52:52: warning: format ‘%zu’ expects argument of type ‘size_t’, but argument 5 has type ‘uint32_t {aka unsigned int}’ [-Wformat=] (level) <= LOGLEVEL ? dev_printf((level), (dev), (format), ##args) : 0; \ ^ include/printk.h:63:2: note: in expansion of macro ‘__dev_printf’ __dev_printf(3, (dev) , format , ## arg) ^~~~~~~~~~~~ common/state/backend_storage.c:250:3: note: in expansion of macro ‘dev_err’ dev_err(storage->dev, "Offset within the device is not aligned to eraseblocks. Offset is %ld, erasesize %zu\n", ^~~~~~~ Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de> Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
* / state: backend_bucket_circular: fix old state readsPhilipp Zabel2017-07-201-1/+4
|/ | | | | | | | | | | | | When the circular bucket meta magic was not found, it is assumed that the whole written state is in the old on-storage format. In that case, the size of the circular bucket meta must not be subtracted from the read length, or the (complete_len > len) check in the raw backend's verify function will fail: state: Error, invalid data_len 16 in header, have data of len 24 Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de> Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
* state: backend: always pass backend type to Linux dtbSascha Hauer2017-06-231-1/+2
| | | | | | | | | | When the "backend-storage-type" property is unset in the barebox dtb then barebox will use the default. Instead of leaving the property unset in the Linux dtb, set it to the value we used as default. By making the default explicit to Linux we force Linux to the same backend type, even when the defaults may differ. 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>
* Merge branch 'for-next/state'Sascha Hauer2017-05-051-3/+25
|\
| * 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>