summaryrefslogtreecommitdiffstats
path: root/common
Commit message (Collapse)AuthorAgeFilesLines
* nv: Fix setting of nv.dev.<devname>.<param> variablesSascha Hauer2017-05-301-42/+23
| | | | | | | | | | | | | | | | | | nv variables with the form nv.dev.<devname>.<param> shall be mirrored to the device parameter <param> of the device named <devname>. This is broken since: | commit 35d8e858bea17ec4796069c9c27fd0b134125eaf | Author: Sascha Hauer <s.hauer@pengutronix.de> | Date: Thu Apr 6 15:23:56 2017 +0200 | | nv: Do not create globalvars from nvvars Fix this by attaching the setting of the mirror device parameter directly to the nv device rather than to the global device. Reported-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* globalvar: Fix value of new globalvar when nvvar existsSascha Hauer2017-05-241-2/+2
| | | | | | | | | | | | | When a new globalvar with a value is created and the corresponding nvvar exists, then the globalvar gets the value of the nvvar, not from the newly assigned value as expected. nv quux=foo; global quux=bar; echo ${global.quux} Should give "bar", not "foo". Fix this. Reported-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* clock: initialize dummy clocksource staticallySascha Hauer2017-05-241-6/+1
| | | | | | | | | | | | | | | | | | | | Assigning the dummy clocksource in a initcall has the problem that get_time_ns() crashes before that initcall is executed. This happens when dmesg support is enabled in conjunction with CONFIG_DEBUG_INITCALLS. In this case the dmesg code wants to have the timestamp of a log message. Solve this by setting the current clocksource to the dummy clock statically and not at runtime. This way we always have a dummy clock available. Fixes: commit 8972eb7ff17ad058a6c6018305bb912138ab0ca2 Author: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Date: Fri Mar 3 13:34:02 2017 +0100 clocksource: move dummy clock source to init_clock Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: BLSPEC needs boot infrastructure and at least simple command supportLucas Stach2017-04-261-0/+3
| | | | | Signed-off-by: Lucas Stach <l.stach@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* globalvar: don't use nv_device if CONFIG_NVVAR is disabledAntony Pavlov2017-04-251-1/+11
| | | | | | | | | | | | | | | | | | | At the moment barebox crashes if CONFIG_NVVAR is disabled because of access to unregistered nv_device in get_param_by_name(&nv_device, "version"). How to reproduce the crash: barebox$ unset ARCH barebox$ unset CROSS_COMPILE barebox$ make sandbox_defconfig barebox$ sed -i "s/CONFIG_ENV_HANDLING=y/# CONFIG_ENV_HANDLING is not set/" .config barebox$ make oldconfig barebox$ ./barebox Segmentation fault Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: backend_raw: init digest earlierSascha Hauer2017-04-241-4/+6
| | | | | | | | | In backend_format_raw_pack() digest_length is used before it's initialized in backend_raw_digest_init() which results in a too small memory allocation for the raw backend. Fix this and prevent a memory corruption. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: Fix "pack" returning freed data for DTB backendIan Abbott2017-04-211-2/+0
| | | | | | | | | | | | | | | | `state_backend_format_dtb_pack()` passes a buffer containing state packed in flattened DTB format back to its caller via its `buf` parameter. It then frees the buffer before returning. This means the caller (`state_save()`) will be working on freed buffer contents before freeing the buffer a second time itself. Fix it by removing the spurious call to `free()`. This should fix a bug reported by Norbert Wiedmann in <http://lists.infradead.org/pipermail/barebox/2017-April/029980.html>. Cc: Norbert Wiedmann <info@n-wiedmann.de> Signed-off-by: Ian Abbott <abbotti@mev.co.uk> 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: backend_storage: Set needs_refresh back to 0 after refreshingSascha Hauer2017-04-191-2/+4
| | | | | | | | | | Set needs_refresh back to 0 after refreshing so that we do not refresh it again without need. This would only happen when we read the state from the storage multiple times, which normally is not the case. However, it's more consistent like this. Reported-by: Sam Ravnborg <sam@ravnborg.org> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* state: backend_bucket_circular: Do not leak memorySascha Hauer2017-04-191-2/+4
| | | | | | | buf was just allocated, free it before returning an error. Reported-by: Sam Ravnborg <sam@ravnborg.org> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: bootchooser: add dependenciesLucas Stach2017-04-191-0/+3
| | | | | | | | Bootchooser isn't worth much without the boot infrastructure, also it needs at least the simple shell variant to be enabled. Signed-off-by: Lucas Stach <l.stach@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/state'Sascha Hauer2017-04-0711-847/+487
|\
| * state: remove unused variable typeSascha Hauer2017-04-043-17/+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-312-6/+6
| | | | | | | | | | | | | | | | | | 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: Remove -EUCLEAN check from userspace toolSascha Hauer2017-03-311-21/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The state code is used for the userspace tool aswell, kept in sync manually. This patch only introduces a change for the userspace tool, not for barebox. In Linux userspace there is no direct possibility to check for -EUCLEAN. To indirectly check for -EUCLEAN the state tool reads the number of corrected bits before and after reading a block. Unfortunately it does not take the number of acceptable bitflips into account, but instead returns -EUCLEAN even when only a single bitflip occurred on a whole page. To be correct the algorithm must be more complicated: We would have to read the bitflip_threshold from sysfs. This value is per ECC step (often 512 byte), not per page. We would have to read the page in ECC step size chunks, testing for bitflips lower than the threshold for each chunk. Even if we would do that, there's still another issue. The eccstats ioctl delivers the eccstats for the whole device, so a concurrent reader would falsify the result. Let's decide that this is not worth the hassle and assume that no device has enough uptime that a cleanup in barebox is not sufficient. 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-315-11/+28
| | | | | | | | | | | | | | 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: backend bucket circular: Explain metadataSascha Hauer2017-03-311-0/+5
| | | | | | | | | | | | Explain why we have metadata and where it is used. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * state: backend_circular: Set minumum writesize to 8Sascha Hauer2017-03-311-0/+3
| | | | | | | | | | | | | | | | NOR flashes have a write size of 1. With this the metadata may end up on non-4-byte-aligned offsets. Force the minimum writesize to 8 so that the metadata is always at aligned offsets. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * state: backend_raw: alloc digest only when neededSascha Hauer2017-03-311-53/+59
| | | | | | | | | | | | | | | | Instead of deferring probe just allocate the digest when it's needed. This way the credentials can be added later, possibly on the commandline. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * state: backend_storage: rename more variablesSascha Hauer2017-03-311-6/+6
| | | | | | | | | | | | Use "buckets" rather than "copies" in variable names. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * state: backend_storage: make locally used variable staticSascha Hauer2017-03-311-1/+1
| | | | | | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * state: backend_storage: rewrite function docSascha Hauer2017-03-311-2/+2
| | | | | | | | | | | | | | The function documentation for state_storage_file_buckets_init() is not very accurate. Rewrite it. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * state: backend_storage: Rename variable desired_copies to desired_bucketsSascha Hauer2017-03-311-9/+9
| | | | | | | | | | | | | | | | | | We defined what a bucket is, so rename the variable that holds the number of desired buckets from desired_copies to desired_buckets. While at it, make locally used variable static. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * state: backend_storage: Rename variable nr_copies to n_bucketsSascha Hauer2017-03-311-12/+12
| | | | | | | | | | | | | | We defined what a bucket is, so use n_buckets when counting buckets, and not nr_copies. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * state: backend_circular: rewrite function docSascha Hauer2017-03-311-5/+3
| | | | | | | | | | | | | | The commment talks about copies where buckets are meant and also claims we start at offset 0, which may not be true. Rewrite comment. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * state: backend_circular: default to circular storageSascha Hauer2017-03-311-6/+8
| | | | | | | | | | | | | | | | Default to the new circular storage format which saves erase cycles. The old format can still be selected with backend-storage-type = "noncircular". Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * state: backend: Add some documentationSascha Hauer2017-03-312-1/+37
| | | | | | | | | | | | Write some sentences to make the concepts clearer. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * state: storage: direct: do not close file that is not openedSascha Hauer2017-03-311-1/+0
| | | | | | | | | | | | When open failed to not try to close the invalid fd afterwards. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * state: backend_circular: remove unnecessary warningSascha Hauer2017-03-311-4/+1
| | | | | | | | | | | | | | It's expected that NAND flashes contain bad blocks, do not warn about them. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * state: backend: Add more fields to struct state_backend_storageSascha Hauer2017-03-312-28/+26
| | | | | | | | | | | | To save a few function arguments. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * state: backend_bucket_direct: max_size is always givenSascha Hauer2017-03-311-1/+1
| | | | | | | | | | | | max_size is always != 0, so if(direct->max_size) can be skipped. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * state: bucket: Make output more informativeSascha Hauer2017-03-312-10/+18
| | | | | | | | | | | | | | | | | | | | | | Print offset and number of the bucket along with the bucket specific messages to give a hint which bucket a message is for. Also it's pretty much expected that buckets sometimes have no data or need cleanup, so instead of complaining loudly, only write which bucket is used and which buckets are cleaned up. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * state: backend-direct: Fix max_sizeSascha Hauer2017-03-311-1/+1
| | | | | | | | | | | | | | 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>
| * state: Drop cache bucketSascha Hauer2017-03-314-190/+71
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The cache bucket sits between the storage functions and the backend storage. We only read from the storage once, so there is no need to cache anything. The real purpose of the cache bucket is to keep the -EUCLEAN information when a NAND block needs to be rewritten and to keep the read buffers as long as the backend iterates over all buckets trying to find the one we want to use. This can be coded easier and more obvious in the backend code, so drop the cache bucket. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * state: Convert all bufs to void *Sascha Hauer2017-03-318-35/+35
| | | | | | | | | | | | | | | | 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: replace len_hint logicSascha Hauer2017-03-316-17/+21
| | | | | | | | | | | | | | | | The len_hint mechanism is rather hard to understand as it's not clear from where to where the hint is passed and also it's not clear what happens if the hint is empty or wrong. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * state: simplify direct backendSascha Hauer2017-03-311-131/+14
| | | | | | | | | | | | | | | | | | - drop support for regular files. This, if at all, is only useful for debugging. For the debugging case still a file of sufficient size can be created manually. - make stridesize mandatory. Makes the code simpler. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * state: drop lazy_initSascha Hauer2017-03-314-60/+6
| | | | | | | | | | | | | | | | | | lazy_init is an optimization that makes it possible to read only up to the first valid bucket when starting. However, when restoring consistency, immediately afterwards we have we have to initialize all buckets anyway, so being lazy doesn't give us any gain. Remove it to simplify the code. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * state: backend_circular: Read whole PEBSascha Hauer2017-03-311-10/+8
| | | | | | | | | | | | | | | | | | | | | | When the circular backend searches for the last page written in the eraseblock, it iterates backwards pagewise from the end of the block. This is ok for NAND flash, but on NOR flash, which does not have pages, the code ends up iterating bytewise backwards, calling into mtd each time. This is very time consuming, so optimize this by reading the whole eraseblock once and just iterate over the buffer in memory. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * state: storage: initialize variable once outside loopSascha Hauer2017-03-311-4/+6
| | | | | | | | | | | | | | writesize is initialized with the same value in each loop iteration, Instead, initialize it once outside the loop. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * state: pass struct state * to storage functionsSascha Hauer2017-03-313-7/+5
| | | | | | | | | | | | | | 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-314-190/+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-313-59/+46
| | | | | | | | | | | | | | 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: backend: remove len_hint argument from state_storage_readSascha Hauer2017-03-313-7/+4
| | | | | | | | | | | | The argument is 0 in the only caller, so remove the argument. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * state: backend: remove .get_packed_lenSascha Hauer2017-03-312-5/+0
| | | | | | | | | | | | | | .get_packed_len isn't implemented by any backend, so remove the hook and its potential caller. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * state: Use positive logicSascha Hauer2017-03-311-7/+7
| | | | | | | | | | | | | | bools with "non" in the names are rather confusing. Switch to positive logic. 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>