summaryrefslogtreecommitdiffstats
path: root/common/console.c
Commit message (Collapse)AuthorAgeFilesLines
* console: forbid ctrlc during startupSascha Hauer2019-04-241-0/+24
| | | | | | | | | | | | | | | When global.autoboot_abort_key is set to ctrl-c then the user is expected to press ctrl-c to get to the prompt. The user might press ctrl-c before the init script runs the "timeout" command. In this case the init script is aborted at arbitrary places which leads to inconsistent results depending on the place it is aborted. This patch introduces the global.console.ctrlc_allowed variable. When this variable is set to false ctrl-c is ignored entirely. The variable is set to false by default and changed to true in the init script. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Shell: Handle aborting loops betterSascha Hauer2019-04-241-5/+23
| | | | | | | | | | | | | | | | | | It's easy to get stuck in an infinite loop in the hush shell: while true; do sleep 1; done The 'sleep' command will check for ctrl-c with the ctrlc() function. This will abort the sleep command. Hush then checks for ctrl-c again in the loop. The ctrl-c in the buffer has already been eaten by the sleep command, so the loop will continue. With this patch we remember the presence of a ctrl-c character in a variable instead of checking for a new character each time. The variable must be resetted explicitly by calling ctrlc_handled() which will be called by the shell in the outer loop. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* drivers: Introduce dev_set_name()Andrey Smirnov2018-10-181-2/+2
| | | | | | | | 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>
* Merge branch 'for-next/dts-warnings'Sascha Hauer2018-07-091-1/+1
|\
| * console: Update description for global.linux.bootargs.consoleSascha Hauer2018-06-191-1/+1
| | | | | | | | | | | | Replace linux,stdout-path with stdout-path as the former is deprecated. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | console: remove duplicate newline conversionSascha Hauer2018-06-191-3/+2
| | | | | | | | | | | | | | | | When the console is not yet fully initialized then console_puts falls back to print characters using console_putc. console_putc already does newline conversion, so do not repeat it in console_puts. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | console: add missing newline conversion for putc_llSascha Hauer2018-06-191-0/+2
|/ | | | | | | | | putc_ll doesn't do newline conversion (and it shouldn't do, as it's a static inline function for early debugging, adding more code there is not nice), so add newline conversion to the console code when it uses putc_ll for printing early messages. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* console: Add simplified 'serdev' framework from Linux kernelAndrey Smirnov2018-04-171-3/+21
| | | | | | | | | Port 'serdev' UART-slave deivce framework found in recent Linux kernels (post 4.13) in order to be able to port 'serdev' slave drivers from Linux. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* param: make parameter functions more consistentSascha Hauer2017-04-111-1/+1
| | | | | | | | | | | | | | | | | | | | | | This patch creates a consitent set of device parameter functions. With this we have: dev_add_param_<type><access> "type" is one of: int32, uint32, int64, uint64, string, mac, ipv4, enum, bitmask The improvement here is that we now can exactly specify the width of the int type parameters and also correctly distinguish between signed and unsigned variables which means that a variable no longer ends up with INT_MAX when it's assigned -1. "access" can be empty for regular read/write parameter, "_ro" for readonly parameters which get their value from a variable pointer in the background or "_fixed" for parameters which are set to a fixed value (without a pointer in the background). Some more exotic types are not (yet) implemented, like dev_add_param_ip_ro. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* console: Use dev_add_param_stringSascha Hauer2017-04-111-26/+24
| | | | | | | dev_add_param_string allows to pass a priv * so that the device_d * argument is not needed and can be removed later. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* console: fix usbserial re-connectAlexander Kurz2017-03-291-1/+3
| | | | | | | | | | | | | | | | With commit b4f55fcf355a ("console: expose consoles in devfs") consoles got inserted, but never removed from devfs. When dealing with USB consoles, barebox should be prepared for devices spontaneously appering and disappering again (user disconnects and re- connects the cable). If the devfs entry is not removed upon disconnect, barebox will raise an error "device creation failed with File exists" when the cable is connected again. Remove devfs entries when consoles are de-registered. Also change the error message, it's the devfs entry. Signed-off-by: Alexander Kurz <akurz@blala.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fix: console: expose consoles in devfsJean-Christophe PLAGNIOL-VILLARD2017-03-131-1/+1
| | | | | | | | | | | | | | | | on 64bit ssize_t is not an int but a long so use the protype for fops_write ssize_t common/console.c: In function ‘console_register’: common/console.c:373:22: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types] newcdev->fops.write = fops_write; in commit b4f55fcf355a4d0ac456445a5f42f259f2812b57 By Bastian Stender <bst@pengutronix.de> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* console: expose consoles in devfsBastian Stender2017-02-281-0/+53
| | | | | | | | | This enables displaying text on e.g. a framebuffer console by issueing echo -o /dev/fbconsole0 abc123 Signed-off-by: Bastian Stender <bst@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* console: replace set_active by open/closeBastian Stender2017-02-281-2/+44
| | | | | | | | | Opening and closing consoles should be independent from setting them active. This way it is possible to open e.g. a framebuffer console and display text on it without showing stdout/stderr. Signed-off-by: Bastian Stender <bst@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* console: Fix initial value of baudrate parameterSascha Hauer2016-05-261-1/+1
| | | | | | | | The 'baudrate' parameter has the wrong value initially, it has to be set to CONFIG_BAUDRATE. Otherwise a devinfo shows a baudrate of 0 until actively changed. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* stdio: Replace FILE functions with filedescriptor functionsSascha Hauer2016-04-151-10/+0
| | | | | | | | | | | | 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>
* stdio: rename getc to getcharSascha Hauer2016-04-151-5/+5
| | | | | | | The function we have implemented as getc has the semantics of the standard function getchar, so rename it accorgingly. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* string: Fix (v)asprintf prototypesSascha Hauer2016-04-151-2/+2
| | | | | | | | | | Our asprintf and vasprintf have different prototypes than the glibc functions. This causes trouble when we want to share barebox code with userspace code. Change the prototypes for (v)asprintf to match the glibc prototypes. Since the current (v)asprintf are convenient to use change the existing functions to b(v)asprintf. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* barebox remote controlSascha Hauer2016-01-181-3/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This adds the ability to control barebox over serial lines. The regular console is designed for human input and is unsuitable for controlling barebox from scripts since characters can be lost on both ends, the data stream contains escape sequences and the prompt cannot be easily matched upon. This approach is based on the RATP protocol. RATP packages start with a binary 0x01 which does not occur in normal console data. Whenever a 0x01 character is detected in the console barebox goes into RATP mode. The RATP packets contain a simple structure with a command/respone type and data for that type. Currently defined types are: BB_RATP_TYPE_COMMAND (host->barebox): Execute a command in the shell BB_RATP_TYPE_COMMAND_RETURN (barebox->host) Sends return value of the command back to the host, also means barebox is ready for the next command BB_RATP_TYPE_CONSOLEMSG (barebox->host) Console message from barebox Planned but not yet implemented are: BB_RATP_TYPE_PING (host->barebox) BB_RATP_TYPE_PONG (barebox->host) For testing purposes BB_RATP_TYPE_GETENV (host->barebox) BB_RATP_TYPE_GETENV_RETURN (barebox->host) Get values of environment variables Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Tested-by: Andrey Smirnov <andrew.smirnov@gmail.com>
* console: Set baudrate during registrationSascha Hauer2015-11-171-7/+4
| | | | | | | This makes sure that the cdev->baudrate field is always consistent with the hardware state. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* login: rework login mechanismSascha Hauer2015-08-281-6/+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>
* console: When deactivating a console, flush it firstSascha Hauer2015-07-231-0/+3
| | | | | | | Otherwise the last characters may not be sent before deactivating a console. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* console: When switching baudrate print console nameSascha Hauer2015-06-091-2/+2
| | | | | | | Since there may be multiple consoles print the name of the console whose baudrate shall be switched. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* console: Add functions to get/set baudrateSascha Hauer2015-06-091-5/+32
| | | | | | So C code can call a function rather than fiddling with device parameters. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* console: Add functions to get/set active state of consoleSascha Hauer2015-06-091-34/+53
| | | | | | | | Currently code needs to fiddle with the active parameter of a console device directly to enable/disable consoles. Add console_set_active() to set the status and console_get_active() to get the current status. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* console: allow to specify the device idJean-Christophe PLAGNIOL-VILLARD2015-01-131-1/+1
| | | | | | | so we can use dynamic number id with specific devname Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* console: Add set_active callbackSascha Hauer2014-12-171-0/+7
| | | | | | | | The netconsole needs to be able to deny activation when the network has not been enabled. Add an optional callback to the console for this. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/efi'Sascha Hauer2014-08-071-0/+29
|\ | | | | | | | | | | | | Conflicts: .gitignore Makefile drivers/serial/Makefile
| * console: Add puts callback to console devicesSascha Hauer2014-07-111-0/+29
| | | | | | | | | | | | | | | | Some devices may have a much more efficient way to output strings rather than single characters. Let console devices implement a callback for this. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | console: Allow persistent device namesSascha Hauer2014-07-111-2/+8
|/ | | | | | | | Add a devname field to struct console_device so that the device name can be set by the driver. This makes it possible to have persistent device names. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* console: Set Linux console parameter automaticallySascha Hauer2014-01-221-1/+28
| | | | | | | | | | | | | | | | | | | | | Linux specifies the linux,stdout-path property in the /chosen node in the devicetree. Unfortunately this is ignored in most cases. For cases in which barebox uses this property for its own use we translate this into a Linux boot arg with: - the console name provided by the serial driver - the the instance from the 'serial' alias - the baudrate from the actual baudrate. So with this it's for devicetee enabled boards no longer necessary to manually assign a console= parameter. Should a user not want to use the automatically assigned parameter it should do: global.linux.bootargs.console= in the environment. 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>
* Merge branch 'for-next/login'Sascha Hauer2013-10-071-0/+6
|\ | | | | | | | | Conflicts: include/console.h
| * login: disable input console if password wrongJean-Christophe PLAGNIOL-VILLARD2013-09-191-0/+6
| | | | | | | | | | | | | | 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: drop f_caps and check the function pointer getc/putc insteadJean-Christophe PLAGNIOL-VILLARD2013-09-211-8/+10
|/ | | | | | | | | | None of the driver make the difference between STDOUT and STDERR. So we just need to check if putc or getc are filled in the console_device save 32 bytes on versatilepb Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/omap'Sascha Hauer2013-09-051-4/+4
|\ | | | | | | | | Conflicts: arch/arm/boards/pcm051/env/config
| * rework debug_llSascha Hauer2013-09-051-4/+4
| | | | | | | | | | | | | | | | | | | | Convert to static inline functions and use lower case letters for function names. Also, include mach/debug_ll.h when an architecture provides support for debug_ll, not only when it's actually enabled. This allows architecures to put some UART initialization code into mach/debug_ll.h which is compiled out when debug_ll is disabled. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | console: fix console without CONFIG_PARAMETERJan Luebbe2013-08-261-2/+6
|/ | | | | | | If CONFIG_PARAMETER is not set, dev_set_param() does not call the setter function. Call it directly instead in this case. Signed-off-by: Jan Luebbe <jlu@pengutronix.de>
* Force set console baudrate at enable timeAlexey Galakhov2013-07-101-2/+11
| | | | | Signed-off-by: Alexey Galakhov <agalakhov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: console: Fix possible null pointer dereferenceAlexander Shiyan2013-07-091-14/+13
| | | | | | | | doing a 'cs0.active=' on the command line crashed barebox. Fix this by not dereferencing val when it's NULL. Signed-off-by: Alexander Shiyan <shc_work@mail.ru> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* console: Use dev_add_param_int for baudrate parameterSascha Hauer2013-04-111-18/+8
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* console: consolidate common console codeSascha Hauer2013-02-131-85/+0
| | | | | | | 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>
* drivers/base: fix corrupt device treeSascha Hauer2012-12-121-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | dev_add_child is a very unsafe function. If called multiple times it allows setting the same device to different parents thus corrupting the siblings list. This happens regularly since: | commit c2e568d19c5c34a05a1002d25280bf113b72b752 | Author: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> | Date: Sat Nov 3 16:11:05 2012 +0100 | | bus: add bus device | | automatically add it as parent of any bus device if none already specified | | we have now a nice output per bus If for example a FATfs is mounted this nice output per bus often ends with: > `---- fat0 > `---- 0 > `---- 0x86f0000087020031-0x86f000410df27124: /dev/<NULL> > `---- sram00 > `---- 0x00000000-0xffffffffffffffff: /dev/<NULL> > `---- 0x00000000-0xffffffffffffffff: /dev/<NULL> > unable to handle NULL pointer dereference at address 0x0000000c > pc : [<87f08a20>] lr : [<87f08a04>] > sp : 86eff8c0 ip : 87f3fbde fp : ffffffff > r10: ffffffff r9 : 00000000 r8 : 00000003 > r7 : 86f075b8 r6 : 00000002 r5 : ffffffec r4 : 86f07544 > r3 : 00000000 r2 : 43f900b4 r1 : 00000020 r0 : 00000005 > Flags: Nzcv IRQs off FIQs off Mode SVC_32 > [<87f08a20>] (do_devinfo_subtree+0x90/0x130) from [<87f08a90>] (do_devinfo_subtree+0x100/0x130) > > [<87f3e070>] (unwind_backtrace+0x0/0x90) from [<87f28514>] (panic+0x28/0x3c) > [<87f28514>] (panic+0x28/0x3c) from [<87f3e4b8>] (do_exception+0x10/0x14) > [<87f3e4b8>] (do_exception+0x10/0x14) from [<87f3e544>] (do_data_abort+0x2c/0x38) > [<87f3e544>] (do_data_abort+0x2c/0x38) from [<87f3e268>] (data_abort+0x48/0x60) This patch fixes this by adding a device to its parents children list in register_device so that dev_add_child is no longer needed. This function is removed from the tree. Now callers of register_device have to clearly set the parent *before* registering a device. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Reported-by: Jan Lübbe <jlu@pengutronix.de>
* console: display Switch to console [csxx] when switching from debug_ll to ↵Jean-Christophe PLAGNIOL-VILLARD2012-10-301-0/+3
| | | | | | | real console Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* console: use debug_ll before the console is availableJean-Christophe PLAGNIOL-VILLARD2012-10-301-0/+2
| | | | | | | This will allow to have the same feature as earlyprintk in the kernel Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* console/of: evaluate linux,stdout-path propertySascha Hauer2012-10-091-0/+3
| | | | | | | When a linux,stdout-path property is given in the devicetree activate the corresponding console. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* console: Cleanup console activationSascha Hauer2012-10-091-25/+26
| | | | | | | | | | | | | | | | | When CONFIG_CONSOLE_ACTIVATE_ALL is set, the banner will never be printed. Also, the console buffer is emptied when the first console is registered, even when it's not enabled. This patch cleans it up in a way that: - the console buffer is emptied once the first console is activated, not when it's registered. - Make sure that the banner is printed first, so that we can output things to the buffer before the banner is printed without ending up in having the banner in the middle of the other boot messages. - Use IS_ENABLED rather than ifdefs Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* switch all platform_bus device/driver registering to ↵Jean-Christophe PLAGNIOL-VILLARD2012-10-041-1/+1
| | | | | | | | platform_driver/device_register now register_driver and register_device are for bus only usage. Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
* Treewide: remove address of the Free Software FoundationSascha Hauer2012-09-171-4/+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>
* Use DEVICE_ID_DYNAMIC where applicableSascha Hauer2012-04-161-1/+1
| | | | | | | We now have DEVICE_ID_DYNAMIC for dynamic allocation of device ids, Use it where applicable. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>