summaryrefslogtreecommitdiffstats
path: root/common/misc.c
Commit message (Collapse)AuthorAgeFilesLines
* common: add option to poweroff system on failureAhmad Fatoum2024-03-051-4/+8
| | | | | | | | | | | | | When developing using Qemu and KASAN/Hardening options enabled, it can be useful to just terminate Qemu on an error, because a stack trace is already printed to console and restarting barebox or hanging just results in the developer having to kill the process. For this use case, add shutdown as third option besides hang and reset. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-6-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* ARM: Do not print exception stacktrace in panicSascha Hauer2023-03-101-6/+23
| | | | | | | | | | panic() prints a stacktrace by default. When being called in a an exception this will print the stacktrace of the exception stack which is not useful, so drop it. We are printing the desired stacktrace anyway before calling panic(). Link: https://lore.barebox.org/20230309142631.338244-1-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: misc: remove now unused errno_strAhmad Fatoum2022-10-111-6/+0
| | | | | | | | | | | | | | | | | With all errno_str() instanced removed in a previous commit, we can drop the now unused definition. New code should use printf("message: %m\n"); instead of printf("message: %s\n", errno_str()); or just use strerror(...) directly. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20221010061122.2084009-4-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* treewide: replace errno_str() with %m printf format specifierAhmad Fatoum2022-10-111-1/+1
| | | | | | | | | | | Both errno_str() and printf("%m" end up calling strerror(). %m is more convenient to use, so switch over all instances to it. No functional change. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20221010061122.2084009-3-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: don't fixup empty serial/machine_compatible stringsAhmad Fatoum2022-08-081-0/+4
| | | | | | | | | | | | | | | | | | There is no point in fixing up an empty string into the kernel device tree, yet this can happen when globalvar_add_simple_string() is called for the variable at least once as the function replaces NULL with an allocated empty string. globalvar_add_simple_string() was called unconditionally for of.kernel.add_machine_compatible, which in turn led to always fixing up an empty string as the top-most compatible. Resolve this by having barebox_get_(of_machine_compatible|serial_number) return NULL for the empty string as well. Fixes: 81dd24a0946c ("of: add generic of_prepend_machine_compatible()") Fixes: f6756e9ce6f2 ("common: add $global.serial_number with device tree fixup") Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20220718114824.2632364-2-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* of: add generic of_prepend_machine_compatible()Oleksij Rempel2022-05-051-0/+23
| | | | | | | | Add generic function to extend/fixup machine compatible. Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de> Link: https://lore.barebox.org/20220503091220.3871612-4-o.rempel@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: add $global.serial_number with device tree fixupAhmad Fatoum2022-05-051-0/+16
| | | | | | | | | | | This new variable can be set by boards from C code or from the environment to change the serial number fixed up into the kernel device tree. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de> Link: https://lore.barebox.org/20220503091220.3871612-2-o.rempel@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: replace license statements with SPDX-License-IdentifiersAhmad Fatoum2020-11-271-10/+1
| | | | | | | | | | | | | For all files in common/ that already have a license text: - Replace with appropriate SPDX-License-Identifier - Remove empty comment lines around replacement - remove comment completely if only thing remaining is name of file without description Reviewed-by: Roland Hieber <rhi@pengutronix.de> Reviewed-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/misc' into masterSascha Hauer2020-10-141-1/+2
|\
| * common: misc: support strerror(err) for all err <= MAX_ERRNOAhmad Fatoum2020-09-281-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | We have a _LAST_ERRNO of 3 decimal digits. strerror(_LAST_ERRNO) is ok, but it's still possible that some code passes a non-error code int, which will overflow the static buffer. Play it safe and bump up the buffer size to at least 11 characters. This is enough to represent all integers, with only 7 characters more static storage. This way strerror(some_int_passed_by_mistake) will not invoke UB. Signed-off-by: Ahmad Fatoum <ahmad@a3f.at> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | magicvar: Replace BAREBOX_MAGICVAR_NAMED with BAREBOX_MAGICVARSascha Hauer2020-10-021-2/+2
|/ | | | | | | | 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>
* treewide: remove references to CREDITSUwe Kleine-König2020-04-271-3/+0
| | | | | | | | The CREDITS file was removed from barebox in 2015 by commit 6570288f2d97 ("Remove the CREDITS file"). Remove references to it from several files. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: return "none" when board unsetSascha Hauer2019-08-191-1/+4
| | | | | | Instead of returning NULL when board is not set return "none". Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* imd: fix missing error messageThorsten K. Scherer2018-11-291-1/+1
| | | | | | | | imd -t just returns 'imd: error 61', if there is not tag for <type> reference: common/imd.c:357 if (!imd) { ... Signed-off-by: Thorsten K. Scherer <t.scherer@eckelmann.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Use globalvar_add_simple_string for model and hostnameSascha Hauer2018-02-261-18/+8
| | | | | | | Simplify the code by using globalvar_add_simple_string(), no functional change intended. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* of: base: use root_node compatible as suggestion for a hostnameOleksij Rempel2018-01-171-0/+7
| | | | | | | | | | | | | | | | on some SoCs we can use generic PLL and RAM initialization. In this cases we create board file only to provide a host name. With this patch host name will be created from device tree compatible. For example: compatible = "board_vendor,board", "chip_vendor,soc" the host name will be: "board" This function will not overwrite a host name which is already set by board or machine code. Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* errno: Include string for ELOOPSascha Hauer2017-05-111-0/+1
| | | | | | | Needed for printing a correct error message when symbolic link loops are encountered. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: Add EPROBE_DEFER to strerrorAndrey Smirnov2016-03-171-0/+1
| | | | | Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* ARM: Remove do_execute and thumb2_executeTrent Piepho2015-12-071-3/+0
| | | | | | | | | | | | | | | | | | | | In commit 104a6a7ccfb7928ca5dc28c8cbe0ea231ffc45ee support was added for Thumb2. It added do_execute() as a way to provide arch dependent calling veneers for use in "go" and thumb2_execute() as the thumb2 to arm veneer. But thumb2_execute() isn't necessary as gcc generates a proper calling sequence from a standard function pointer call. Thumb2 barebox is compiled with the AAPCS ABI which requires this. It also had a bug and didn't pass the arguments properly, but code execute via "go" rarely uses arguments so this wasn't very noticeable. Since thumb2 was always the only user of do_execute(), go ahead and delete that too. Signed-off-by: Trent Piepho <tpiepho@kymetacorp.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* restart: replace reset_cpu with registered restart handlersSascha Hauer2015-08-271-1/+2
| | | | | | | | | | | | | | | | | | | | | | This replaces the reset_cpu() function which every SoC or board must provide with registered handlers. This makes it possible to have multiple reset functions for boards which have multiple ways to reset the machine. Also boards which have no way at all to reset the machine no longer have to provide a dummy reset_cpu() function. The problem this solves is that some machines have external PMICs or similar to reset the system which have to be preferred over the internal SoC reset, because the PMIC can reset not only the SoC but also the external devices. To pick the right way to reset a machine each handler has a priority. The default priority is 100 and all currently existing restart handlers are registered with this priority. of_get_restart_priority() allows to retrieve the priority from the device tree which makes it possible for boards to give certain restart handlers a higher priority in order to use this one instead of the default one. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* printf: move panic() to common/misc.cSascha Hauer2015-01-051-0/+22
| | | | | | | | panic() is not really a printf like function, so move it to common/misc.c. This is done because we want to have printf support in the PBL, but PBL has it's own panic() implementation. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* treewide: Add missing includesSascha Hauer2013-11-081-0/+1
| | | | | | | | A lot of files rely on include/driver.h including include/of.h (and this including include/errno.h. include the files explicitly so we can eventually get rid of including of.h from driver.h Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* export model as globalvarSascha Hauer2013-08-161-2/+9
| | | | | | | The model string is valuable information. Make it available to scripts with a globalvar. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Set model and hostname at boardlevelSascha Hauer2013-08-161-4/+1
| | | | | | | | | | | | With multiboard support the compiletime generated BOARDINFO string gets more and more meaningless. This removes it from Kconfig and replaces it with a variable that can be set at boardlevel. Also many boards have a standard setting for the hostname in the environment. This patch also moves the standard to C code by calling barebox_set_hostname(). Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Make hostname available to C CodeSascha Hauer2013-08-161-0/+34
| | | | | | | The boards often have a sane default for the hostname. Provide a C function for setting/getting it. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* introduce barebox_set_modelSascha Hauer2013-08-161-8/+15
| | | | | | | | Instead of calling of_get_model() in barebox_get_model() add a barebox_set_model() and use it to set the boardinfo once it's available from the devicetree. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* remove remaining references of CONFIG_BOARDINFOSascha Hauer2013-08-161-10/+10
| | | | | | | | | | | With this all code uses barebox_get_model() and no longer a compile time generated string. Also this renames barebox_boardinfo() to barebox_get_model() since we are going to add the corresponding _set_ function and 'model' corresponds to the devicetree notion. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* add function to get boardinfo stringSascha Hauer2013-06-241-0/+17
| | | | | | | | When using devicetrees the boardinfo (or model) can be obtained from the devicetree. Add a function to get the boardinfo so that we have a chance to add information from the devicetree. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Treewide: remove address of the Free Software FoundationSascha Hauer2012-09-171-3/+0
| | | | | | | The FSF address has changed in the past. Instead of updating it each time the address changes, just drop it completely treewide. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Make errno a positive valueSascha Hauer2012-05-141-1/+1
| | | | | | | | | Normally errno contains a positive error value. A certain unnamed developer mixed this up while implementing U-Boot-v2. Also, normally errno is never set to zero by any library function. This patch fixes this. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* ARM: Allow to compile in thumb-2 modeSascha Hauer2012-03-061-0/+3
| | | | | | | | | This shrinks the resulting binary size by ~25%. Exceptions are still handled in arm mode, so we have to explicitely put .arm directives into the exception code. Thumb-2 mode has been tested on i.MX51 Babbage board. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* add string for -ETIMEDOUTSascha Hauer2012-02-191-1/+1
| | | | | | | -ETIMEDOUT is a common error value, so print the string rather than just the number. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* errno: add strings for network related error messagesSascha Hauer2010-06-171-3/+4
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Combine memory initialization with the main memory functions.Juergen Beisert2009-12-101-49/+0
| | | | | | | | | Memory allocation is very simple in u-boot-v2. So, it makes also sense to add the "operating system" emulation layer into the main memory management source file, to keep them at one place and simple. Signed-off-by: Juergen Beisert <jbe@pengutronix.de>
* add strerror functionSascha Hauer2009-05-251-4/+11
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fix errno_str without text error messagesSascha Hauer2009-04-061-0/+2
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Print error numberSascha Hauer2008-11-101-6/+5
| | | | | | | When we do not have the appropriate error string compiled in, print at least the number Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* [general] Fixed crash in memory allocatorCarsten Schlote2008-02-201-1/+3
| | | | | | | | | | | | Fixed a bug in sbrk(). When the new mem_brk value returned by sbrk_no_zero() returns NULL to indicate 'out of memory', sbrk() still memset()s innocent memory at address NULL. For some architectures this memory might be empty, so this never causes a problem. Anyway on Coldfire I still have my vector table there. Nuking them isn't really a good idea :-) Signed-off-by: Carsten Schlote <c.schlote@konzeptpark.de>
* export symbolsSascha Hauer2007-10-071-0/+1
|
* export functionsSascha Hauer2007-10-041-0/+2
|
* display malloc space on startupSascha Hauer2007-09-261-9/+19
|
* svn_rev_706Sascha Hauer2007-07-051-0/+21
| | | | add file headers
* svn_rev_653Sascha Hauer2007-07-051-3/+3
| | | | restructure tree, add reginfo command
* svn_rev_603Sascha Hauer2007-07-051-5/+3
|
* svn_rev_532Sascha Hauer2007-07-051-4/+12
| | | | | | | | | - Do not zero memory in mem_malloc_init because it takes a long time with big memory. Instead zero it when we actually need the memory. - Add sbrk_no_zero() function to allocate memory without zeroing it. This is usefull for scratch mem devices which occupy large chunks of memory
* svn_rev_457Sascha Hauer2007-07-051-0/+3
|
* svn_rev_441Sascha Hauer2007-07-051-6/+16
| | | | add errno_str()
* svn_rev_370Sascha Hauer2007-07-051-1/+1
| | | | fixups for last commit
* svn_rev_369Sascha Hauer2007-07-051-1/+1
| | | | include asm-generic in errno.h instead of all other files
* svn_rev_332Sascha Hauer2007-07-051-3/+7
| | | | make errno messages optional