summaryrefslogtreecommitdiffstats
path: root/common/globalvar.c
Commit message (Collapse)AuthorAgeFilesLines
* treewide: Rename remaining struct device_d -> deviceSascha Hauer2023-02-231-3/+3
| | | | | | | struct device_d was renamed to struct device. Rename the remaining occurences of device_d. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Rename struct device_d to deviceSascha Hauer2023-01-101-14/+18
| | | | | | | | | | | | | The '_d' suffix was originally introduced in case we want to import Linux struct device as a separate struct into barebox. Over time it became clear that this won't happen, instead barebox struct device_d is basically the same as Linux struct device. Rename the struct name accordingly to make porting Linux code easier. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Reviewed-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.barebox.org/20221214123512.189688-3-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* treewide: add SPDX-License-Identifier for files without explicit licenseAhmad Fatoum2022-01-051-0/+2
| | | | | | | | | Record GPL-2.0-only as license for all files lacking an explicit license statement. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20220103120539.1730644-12-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* RISC-V: S-Mode: propagate Hart IDAhmad Fatoum2021-06-241-0/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | Unlike other architectures we support, Linux must apparently be booted on all cores by the bootloader. To achieve this, the bootloaders running on the multiple cores synchronize via IPIs. We will get there eventually, but for now, let's restrict barebox to boot Linux on a single core. S-Mode firmware is passed hart (core) id in a0. This is propagated via the thread pointer register, which is unused by GCC and made available as: - cpuinfo output when running in S-Mode - $global.hartid - a0 when booting via bootm - /chosen/boot-hartid fixup: will come in handy when we gain EFI loading support - single /cpus/*/reg: All other CPU nodes are deleted via fixup For M-Mode, we can query hart id via CSR. It's unknown whether erizo supports it and we don't yet have exception support to handle it not being available, so changes are only done for S-Mode for now. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20210619045055.779-6-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* startup: introduce global.endianness variableAntony Pavlov2021-05-121-0/+13
| | | | | | | | | | The global.endianness variable makes it possible to determine current endian mode from command line or from script on bi-endian capable system. Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com> Link: https://lore.barebox.org/20210511083648.134890-1-antonynpavlov@gmail.com Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* nv: fix use-after-free when clearing from shellAhmad Fatoum2020-11-131-8/+4
| | | | | | | | | | | | | | | | | When we use hush to set the same nv.var twice to the empty string: $ nv.user= $ nv.user= nv_set is called twice with a NULL val argument leading to a double free and accompanied memory corruption. Reorder the code, so p->value is freed just once. Fixes: fa4c41ba60af ("nvvar: when setting a nvvar to NULL just free the content") Cc: Holger Assmann <has@pengutronix.de> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/magicvar-unique-id' into masterSascha Hauer2020-10-141-4/+3
|\
| * magicvar: Replace BAREBOX_MAGICVAR_NAMED with BAREBOX_MAGICVARSascha Hauer2020-10-021-1/+1
| | | | | | | | | | | | | | | | BAREBOX_MAGICVAR now generates a unique identifier automatically, so we can convert users of BAREBOX_MAGICVAR_NAMED to the simpler BAREBOX_MAGICVAR macro. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | Merge branch 'for-next/clang-analyzer' into masterSascha Hauer2020-10-141-1/+1
|\ \
| * | globalvar: fix uninitialized read of variable when no nvvars existAhmad Fatoum2020-10-021-1/+1
| |/ | | | | | | | | | | | | | | | | When there are no nvvars, the function returns an uninitialized ret, return 0 in this case instead. Reported-by: clang-analyzer-10 Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* / common: globalvar: add variable for buildsystem_version_stringSteffen Trumtrar2020-09-281-0/+6
|/ | | | | | | | | Now that the buildsystem version is available, make it accessible as a global variable for runtime usage. If the buildsystem version is not present (i.e. empty), don't add the variable at all. Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/net' into masterSascha Hauer2020-09-251-2/+52
|\
| * globalvar: Add helper for deprecated variable namesSascha Hauer2020-08-191-2/+52
| | | | | | | | | | | | | | | | | | | | When globalvars are renamed across releases it's not nice when variables in the persistent environment loose their meaning. This adds a helper function which adds an alias for the old names. When the persistent variables still use the old names then their values are automatically written to variables with the new names. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | Merge branch 'for-next/mmc' into masterSascha Hauer2020-09-251-0/+5
|\ \
| * | globalvar: add globalvar_set functionRouven Czerwinski2020-09-151-0/+5
| |/ | | | | | | | | | | | | | | Instead of overwriting the whole hierarchy beneath a globalvar, the globalvar_set function only sets the specific globalvar. Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* / globalvar: allow running actions on set with globalvar_add_bool()Ahmad Fatoum2020-09-181-3/+5
|/ | | | | | | | | | globalvar_add_simple_bool() and the other family of globalvars don't allow running a callback when the variable is set. This is a useful thing to have however for things like global.usbgadget.autostart=1. Provide a globalvar_add_bool() that accommodates this. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* treewide: make use of PTR_ERR_OR_ZEROUwe Kleine-König2020-06-261-4/+1
| | | | | | | | | | | PTR_ERR_OR_ZERO is designed to replace boiler plate like: if (IS_ERR(x)) return PTR_ERR(x); return 0; Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* globalvar: Allow NULL pointers to be returned by dev_add_param()Christian Eggers2020-01-271-8/+11
| | | | | | | | | | The following commit will change the return value of dev_add_param() from -ENOSYS to NULL if CONFIG_PARAMETER is disabled. After that, building without CONFIG_PARAMETER will return a NULL pointer to __nvvar_add() instead of an error. Signed-off-by: Christian Eggers <ceggers@arri.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Allow usage of default environment without environment file storageAlbert Schwarzkopf2019-12-111-5/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | Currently, the default environment is only used when the barebox environment on the persistent store is not valid or when ENVFS_FLAGS_FORCE_BUILT_IN is set in the super block. However, ENVFS_FLAGS_FORCE_BUILT_IN can be cleared and the environmnet variables in the persistent store will be used again. This may not be desirable. This patch allows building CONFIG_DEFAULT_ENVIRONMENT independent of CONFIG_ENV_HANDLING. This can be useful if you never want to load or write values from the persistent store and you only need to read environment variables from your default environment. If CONFIG_ENV_HANDLING is not set, a message will be printed to the user indicating that changes to non-volatile variables won't be persisted. Move envfs functions that are needed when CONFIG_DEFAULT_ENVIRONMENT and/or CONFIG_ENV_HANDLING is set to a new file common/envfs-core.c. Signed-off-by: Albert Schwarzkopf <a.schwarzkopf@phytec.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* globalvar: fix crash if CONFIG_NVVAR is not setAntony Pavlov2018-12-131-0/+9
| | | | | | | | | | | | | | | | | | | | | | | At the moment globalvar code tries to use nv_device even if nv_device is not registered. How to reproduce the problem: barebox$ make sandbox_defconfig ... barebox$ sed -i "s/\(CONFIG_NVVAR\)=y/# \1 is not set/" .config barebox$ sed -i "s/\(CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW\)=y/# \1 is not set\n# CONFIG_DEFAULT_ENVIRONMENT_GENERIC is not set/" .config barebox$ make oldconfig ... barebox$ make ... barebox$ ./barebox Segmentation fault This patch blocks nv_device use if CONFIG_NVVAR is not set. Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/net'Sascha Hauer2018-01-051-2/+4
|\
| * nvvar: when setting a nvvar to NULL just free the contentSascha Hauer2017-12-011-2/+4
| | | | | | | | | | | | | | | | | | | | When a nvvar is about to be removed then it is set to NULL by barebox. This means for the variable to free it's memory. In this case also do not pass the value to the corresponding globalvar, since that would set the globalvar to NULL aswell, but we want to keep its current value. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | Merge branch 'for-next/misc'Sascha Hauer2018-01-051-3/+42
|\ \
| * | nvvar: Initialze from underlying device parameterSascha Hauer2017-11-241-1/+8
| | | | | | | | | | | | | | | | | | | | | | | | When a nvvar is added with a NULL parameter then it's initialized with the value of the underlying global variable. Do this aswell when the nvvar is a device parameter. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | nv: add device parameter overwrites to completion listSascha Hauer2017-11-231-2/+31
| | | | | | | | | | | | | | | | | | | | | | | | nv variables in the form dev.<devname>.* can be used to make device parameters persistent. Add these to the completion list to make setting these variables more convenient. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | globalvar: When a globalvar is created with a NULL value, use empty stringSascha Hauer2017-11-231-0/+3
| | | | | | | | | | | | | | | | | | | | | As a convenience for users of globalvar_add_simple_string() create an empty value for the variable when passed a NULL pointer as value. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | | common: globalvar: fix removing multiple nvvars with wildcardsSascha Hauer2017-11-301-2/+3
|/ / | | | | | | | | | | | | | | | | | | | | nvvar_remove takes wildcards, so it can remove multiple variables. This means we cannot return after the first loop iteration, but instead must continue. Fixes: 609d3edc3ad9 (common: globvar: let nvvar_remove() report non-existing variable) Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Cc:
* / common: globvar: let nvvar_remove() report non-existing variableEnrico Jorns2017-11-031-1/+3
|/ | | | | | | | | | | The former implementation did not allow to detect whether the call to nvvar_remove() succeeded or failed and always returned 0. This changes the implementation to return 0 only if a variable with the given name was found and return ENOENT otherwise. Signed-off-by: Enrico Jorns <ejo@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Revert "nv: Do not create globalvars from nvvars"Sascha Hauer2017-06-131-21/+21
| | | | This reverts commit 35d8e858bea17ec4796069c9c27fd0b134125eaf.
* Revert "globalvar: remove code for unqualified globalvars"Sascha Hauer2017-06-131-1/+42
| | | | This reverts commit e4f81050e098074792730b61563538d9e394e3d6.
* Revert "globalvar: make globalvar functions more consistent"Sascha Hauer2017-06-131-7/+21
| | | | This reverts commit 1b4a05c9263ae26083526acfabdea1ef96531a1d.
* Revert "param: remove unnecessary device_d * argument"Sascha Hauer2017-06-131-7/+7
| | | | This reverts commit 0071bacb4c7cab21c9fab8540f5aa9922a270a85.
* Revert "globalvar: don't use nv_device if CONFIG_NVVAR is disabled"Sascha Hauer2017-06-131-11/+1
| | | | This reverts commit b378e8c9427b45d856d052a6df4a879a2cee670c.
* Revert "globalvar: make nv_device static"Sascha Hauer2017-06-131-1/+1
| | | | This reverts commit f655902cfad63b9ba5cea7d0c9fc9c3632143e02.
* Revert "nv: Fix setting of nv.dev.<devname>.<param> variables"Sascha Hauer2017-06-131-23/+42
| | | | This reverts commit eaf884ba55def055fd81ff3291a1a534fc8bd8f9.
* Revert "globalvar: Fix value of new globalvar when nvvar exists"Sascha Hauer2017-06-131-2/+2
| | | | This reverts commit f8a177478c1b79e369ecc65501d9d15ff573339f.
* globalvar: Fix value of new globalvar when nvvar existsSascha Hauer2017-05-081-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>
* nv: Fix setting of nv.dev.<devname>.<param> variablesSascha Hauer2017-05-081-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>
* Merge branch 'for-next/parameter-types'Sascha Hauer2017-05-051-28/+14
|\
| * param: remove unnecessary device_d * argumentSascha Hauer2017-04-111-7/+7
| | | | | | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * globalvar: make globalvar functions more consistentSascha Hauer2017-04-111-21/+7
| | | | | | | | | | | | | | | | | | Similar to the device parameter functions also make the globalvar functions more consistent. This also adds support for readonly globalvars and changes several existing globalvars which should really be readonly to readonly. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | Merge branch 'for-next/misc'Sascha Hauer2017-05-051-1/+1
|\ \
| * | globalvar: make nv_device staticAntony Pavlov2017-04-281-1/+1
| |/ | | | | | | | | | | | | | | nv_device isn't used outside of common/globalvar.c so make it static. Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com> 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>
* Merge branch 'for-next/misc'Sascha Hauer2017-04-071-78/+24
|\
| * globalvar: remove code for unqualified globalvarsSascha Hauer2017-04-071-42/+1
| | | | | | | | | | | | | | | | | | | | | | | | The globalvar_add_simple_* functions will fail when a globalvar of the name already exists. This happened when the globalvar was created previously because a corresponding nvvar existed. For this reason we removed the globalvars that have been previously created by nvvar creation (we called these unqualified globalvars). Since we no longer create the corresponding globalvars on nvvar creation this code is no longer needed. Remove it. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * nv: Do not create globalvars from nvvarsSascha Hauer2017-04-071-21/+21
| | | | | | | | | | | | | | | | | | | | When we create a new nvvar there's no need to create the corresponding globalvar, because whoever wants to use the corresponding globalvar will create it before usage anyway. Doing this means that we have to test for existence of a corresponding nvvar when we create a globalvar, and if it does, set the value of the globalvar from the nvvar. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * globalvar: remove unused globalvar_add()Sascha Hauer2017-04-071-16/+0
| | | | | | | | | | | | globalvar_add() is unused in the tree. Remove it. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * global command: print info about variablesSascha Hauer2017-04-041-1/+4
| | | | | | | | | | | | | | | | The info contains useful information at least for enums, for these the possible values are printed. This makes the output of the "global" command more useful and similar to "devinfo global" Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | nvvar: Fix creation without valueSascha Hauer2017-04-071-3/+9
|/ | | | | | | | | | When a new nvvar is added without a value we want to get the value from the corresponding globalvar. We do this by using nv_set which ends up freeing the exact string that we passed into nv_set as value. This results in a corrupt value. Fix this by assigning a value manually without calling nv_set. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>