summaryrefslogtreecommitdiffstats
path: root/common/console_common.c
Commit message (Collapse)AuthorAgeFilesLines
* Merge branch 'for-next/misc'Sascha Hauer2024-03-151-4/+13
|\
| * commands: dmesg: support aborting dmesg output with ctrl-cAhmad Fatoum2024-03-081-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | dmesg output can get very long, especially if debug messages are compiled in and the maximum number of retained log messages is increased. Therefore, follow what we do for other potentially long-running commands and allow the user to abort it with ctrl+c. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240306184519.626594-2-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * console: scale number of log messages with available RAMAhmad Fatoum2024-03-081-3/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The default value of 1000 messages is too small with CONFIG_COMPILE_LOGLEVEL=7, because the many driver debug messages will evict any earlier error or warning messages that have been in the log. Assuming a log record size of 128 bytes, 1000 messages translates to 128kB, which has quite a bit of breathing room. Let's instead scale the maximum with the available memory: one message per 32KiB of malloc area. This gives us: - 64M total memory -> ~32M malloc area -> 1K messages (128K bytes) - 256M total memory -> ~128M malloc area -> 4K messages (512K bytes) - 1G total memory -> ~512M malloc area -> 16K messages ( 2M bytes) Users for which this is too excessive can still configure this via the environment. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240306184519.626594-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | common: console_common: handle NULL dev gracefully in dev_printfAhmad Fatoum2024-03-131-1/+1
|/ | | | | | | | | | | | | | dev_name(NULL) returns NULL, which snprintf can handle, but dev->driver used beforehand would derference the NULL pointer without checking. Fix this by checking that dev is !NULL before dereferencing. This still leads to an ugly <NULL>: prefix, when a NULL dev is used, so it can be fixed, but without the crash, which might be difficult to pinpoint if the print happens early. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240313092633.3339320-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* console: allocate only once instead of twice per log messageAhmad Fatoum2023-08-041-7/+7
| | | | | | | | | | | | | | We do two allocations for each log message, one for the log message string itself and another for the struct log_entry referencing it. We could just make the log message directly follow the log entry and save the space for the pointer and the time to do a second allocation. No functional change. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230804081147.559379-2-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Rename struct device_d to deviceSascha Hauer2023-01-101-3/+3
| | | | | | | | | | | | | 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>
* common: console_common: output log messages to CONSOLE_STDERRAhmad Fatoum2022-10-051-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | Like U-Boot, barebox has two standard output streams: CONSOLE_STDOUT and CONSOLE_STDERR in addition to the input stream CONSOLE_STDIN. >From a consumer view, the console.active device parameter allows restricting which of these streams interact with a given console. >From a provider view, only CONSOLE_STDOUT is ever used. dputs dputc allow passing in CONSOLE_STDERR instead, but nothing in-tree does so. Change this by having all log messages (e.g. pr_debug or dev_err) go to CONSOLE_STDERR. For nearly all systems that just use the default of console.active="ioe" or "oe", there is no difference. But now systems that use either "o" or "e" can use different console devices for barebox log messages and for standard output by commands. This is especially useful to debug interactive applications like edit or for monitoring barebox debug messages during execution of payloads when barebox acts as EFI loader. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20220930154145.754181-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* console: Fix message coloursSascha Hauer2021-12-131-6/+6
| | | | | | | The correct code to change colours is "\033[1;31m", not "\033[31m". Fix that. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/usb-gadget'Sascha Hauer2021-05-171-0/+20
|\
| * common: console: add log_writefile to write log into new fileAhmad Fatoum2021-05-031-0/+20
| | | | | | | | | | | | | | | | | | | | It can be useful to dump the log into the file, e.g. when doing an update from a USB flash drive with no serial peer attached. Add a function to facilitate this. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20210503114901.13095-3-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | common: console_common: Replace vsprintf with vsnprintfJules Maselbas2021-05-121-7/+8
|/ | | | | | | | | | Replace the *sprintf to their *snprintf version when printing to the fixed size printbuffer. Reported-by: Neeraj Pal <neerajpal09@gmail.com> Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu> Link: https://lore.barebox.org/20210417211144.26466-1-jmaselbas@kalray.eu Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: common_console: Rework log_printJules Maselbas2021-03-261-10/+8
| | | | | | | | | | Since time_beginning has been removed there is no reason to use a variables called `diff` or `diff_ul`, there are respectively renamed to `time_ns` and `time`. Also remove the test for null timestamp. Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* clock: Remove time_beginningJules Maselbas2021-03-261-1/+1
| | | | | | | | | | | | The output of the `demsg -t` command will have broken timestamps for every log entries written (in the log) before switching clock. The function get_time_ns() is monotonic, thus setting time_beginning with get_time_ns() when switching clocksource will always result in time_beginning being greater than every timestamp set before. Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* treewide: include <linux/math64.h> wrapper instead of <asm-generic/div64.h>Ahmad Fatoum2021-02-191-1/+1
| | | | | | | | | | | <asm-generic/div64.h> isn't meant for direct usage as <asm/div64.h> may override this on a per-architecture basis. We don't do that currently, but in the future we might. Include the <linux/math64.h> instead. No functional change. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: replace license statements with SPDX-License-IdentifiersAhmad Fatoum2020-11-271-11/+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>
* common: console_common: add of_console_get_by_alias() helperOleksij Rempel2020-08-241-0/+18
| | | | | | | Add helper function to get console device by devicetree alias Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de> 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: fix typos found with codespellYegor Yefremov2020-03-231-1/+1
| | | | | Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* pstore: Only capture log messagesSascha Hauer2019-07-091-0/+4
| | | | | | | | | | | | | With this pstore only captures barebox log messages printed with pr_* and dev_*, but no longer anything printed with printf and friends. When capturing the barebox output with pstore only the log messages are of interest, but not the ones printed with printf and certainly not the things typed interactively on the command line. These are logged currently because we register pstore as a barebox console. Instead, hook into pr_puts which only outputs the barebox log messages. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: console_common: do not store color additions to the log bufferOleksij Rempel2019-02-271-17/+18
| | | | | | | it is needed for raw dmesg output Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* commands: dmesg: add -l option to restrict output levelOleksij Rempel2019-02-271-1/+4
| | | | | | | | | Same as linux dmesg, barebox dmesg will be able to restrict output level by using -l option. For example "dmesg -l err,warn" This functionality can be used for test automation. Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* commands: dmesg: add print raw parameterOleksij Rempel2019-02-271-0/+3
| | | | | | | | | | | | | | | | | Add -r option to mimic functionality of linux dmesg. It will prefix log level and timestamp to each buffer: <6>[ 460us] barebox 2019.02.0-00266-g6aea757067-dirty #355 Thu Feb 21 11:51:43 CET 2019 <6>[ 6279us] Board: DPTechnics DPT-Module <6>[ 209281us] mdio_bus: miibus0: probed <6>[ 210184us] ag71xx-gmac 18070000.mac@19000000.of: network device registered <6>[ 216051us] m25p80 w25q128@00: w25q128 (16384 Kbytes) <6>[ 219913us] netconsole: registered as netconsole-1 <6>[ 223312us] malloc space: 0x80c00000 -> 0x80ffffff (size 4 MiB) <6>[ 228255us] eth0: got preset MAC address: c4:93:00:00:ae:89 <6>[ 246363us] running /env/bin/init... Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* console: Fix console_get_first_active()Andrey Smirnov2018-06-191-1/+2
| | | | | | | | Fix if condition in console_get_first_active() to actually check that both bit are set. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* console: added colored print out of log levelsEugen Wiens2018-02-221-0/+25
| | | | | | | When the system is booting the warnings and errors are not be quickly discovered. With this improvement the errors are colored red, the warnings yellow and the notices blue. Signed-off-by: Eugen Wiens <eugen.wiens@jumo.net> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* console: move global.allow_color handling to C codeSascha Hauer2018-02-221-2/+15
| | | | | | | | | We have global.allow_color, but this is limited to the environment only. Move creation and handling of this variable to C code so that we can add support for colored output to commands/console controlled by the same variable. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Revert "globalvar: make globalvar functions more consistent"Sascha Hauer2017-06-131-3/+3
| | | | This reverts commit 1b4a05c9263ae26083526acfabdea1ef96531a1d.
* globalvar: make globalvar functions more consistentSascha Hauer2017-04-111-3/+3
| | | | | | | | | 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>
* console: console_get_by_name: do not strcmp NULLAlexander Kurz2017-03-291-1/+1
| | | | | | | | | | | | | console_get_by_name iterates through the console_list using strcmp to mach a given console by name. console_list may contain entries with devname = NULL, inserted there e.g. by KEYBOARD_GPIO. In worst case loady -t usbserial will crash barebox when strcmp hits 0 NULL devname: > unable to handle NULL pointer dereference at address 0x00000000 Let console_get_by_name just ignore the anonymous consoles. Signed-off-by: Alexander Kurz <akurz@blala.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* stdio: Replace FILE functions with filedescriptor functionsSascha Hauer2016-04-151-9/+9
| | | | | | | | | | | | We have defined stdin, stdout and stderr as integer file descriptors, but normally they should be FILE *. Also fprintf, fputc and fputs take file descriptors instead of FILE *. As FILE * are inconvenient in the barebox environment replace the f* functions with the corresponding d* functions. dprintf is POSIX conform whereas dputc and dputs are barebox specific, but do not conflict with any stdc function. fgetc is unused and can be removed without replacing it. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* console: use int rather than uint in printf() and friendsMasahiro Yamada2015-09-071-3/+3
| | | | | | | | These functions and vsprintf() return int type. No reason to use uint type. Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* login: rework login mechanismSascha Hauer2015-08-281-27/+0
| | | | | | | | | | | | | | We used to have the login functionality in the /env/bin/init script. This is hard to review and it's too easy to break the login functionality with changes to this script. Move the places to ask for a password to C code where we have only a few places where we have to ask for a password. Mainly these are run_shell() and the menutree command. This patch introduces a login() function which will only return if the correct password has been entered. Following calls will return immediately without asking for a password again. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/misc'Sascha Hauer2015-06-091-3/+11
|\
| * console: use regular malloc for log messagesSascha Hauer2015-05-151-3/+11
| | | | | | | | | | | | | | | | Using xfunctions to allocate log messages is not a good idea. Should we be out of memory the xfunctions will panic which will cause another allocation, so we deadlock the system with no message going out. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | console: Add console_get_by_nameSascha Hauer2015-06-091-0/+13
|/ | | | | | | Commands like loadx/loady wish to find a console device by its name. Add a function for this. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* console: Make locally used function staticSascha Hauer2015-03-041-1/+1
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: console_console: put functions under correct ifdefLucas Stach2015-01-191-35/+35
| | | | | | | | | | So they aren't build when no console support is selected. Fixes: In function `console_get_by_dev': undefined reference to `console_list' Signed-off-by: Lucas Stach <dev@lynxeye.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* console: Make sure xzalloc is only used when it's availableSascha Hauer2015-01-051-1/+1
| | | | | | | | To make it possible to call the pr_* functions very early before malloc is initialized test if malloc is available before using it. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Introduce message logging supportSascha Hauer2014-09-301-3/+126
| | | | | | | | | | This adds a buffer for log messages and a 'dmesg' command to print the messages. The log buffer is implemented as log objects rather than a string buffer. This makes it easy to implement limiting the messages, cleaning the buffer and timestamping the messages. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/rs485'Sascha Hauer2013-10-071-0/+13
|\ | | | | | | | | Conflicts: common/console_common.c
| * console: introduce console_get_by_devJean-Christophe PLAGNIOL-VILLARD2013-09-241-0/+13
| | | | | | | | | | | | | | so we can get console by it's device Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | Merge branch 'for-next/login'Sascha Hauer2013-10-071-0/+60
|\ \ | | | | | | | | | | | | Conflicts: include/console.h
| * | introduce runtime loglevelSascha Hauer2013-09-291-0/+27
| | | | | | | | | | | | | | | | | | | | | With this the verbosity of barebox can be controlled during runtime using the 'loglevel' globalvar. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | login: disable input console if password wrongJean-Christophe PLAGNIOL-VILLARD2013-09-191-0/+33
| |/ | | | | | | | | | | | | so we guarantee that barebox is secured again user interaction Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* / console: factorise function to get the first enabled consoleJean-Christophe PLAGNIOL-VILLARD2013-10-061-0/+22
|/ | | | | | | rename it to console_get_first_active Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* console: consolidate common console codeSascha Hauer2013-02-131-0/+110
The different console implementations share a good amount of code, share this in console_common.c. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>