1
0
mirror of https://xff.cz/git/u-boot/ synced 2025-10-22 10:31:56 +02:00

tools: kwboot: Allow any baudrate on Linux

The A38x platform supports more baudrates than just those defined by the
Bn constants, and some of them are higher than the highest Bn baudrate
(the highest is 4 MBd while A38x support 5.15 MBd).

On Linux, add support for arbitrary baudrates. (Since there is no
standard POSIX API to specify arbitrary baudrate for a tty device, this
change is Linux-specific.)

We need to use raw TCGETS2/TCSETS2 or TCGETS/TCSETS ioctls with the
BOTHER flag in struct termios2/termios, defined in Linux headers
<asm/ioctls.h> (included by <sys/ioctl.h>) and <asm/termbits.h>. Since
these headers conflict with glibc's header file <termios.h>, it is not
possible to use libc's termios functions and we need to reimplement them
via ioctl() calls.

Note that the Bnnn constants from <termios.h> need not be compatible
with Bnnn constants from <asm/termbits.h>.

Signed-off-by: Pali Rohár <pali@kernel.org>
[ termios macros rewritten to static inline functions (for type control)
  and moved to tools/termios_linux.h ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
This commit is contained in:
Pali Rohár
2021-09-24 23:07:06 +02:00
committed by Stefan Roese
parent ca272041c0
commit 93b55636b0
2 changed files with 204 additions and 1 deletions

View File

@@ -23,10 +23,15 @@
#include <errno.h>
#include <unistd.h>
#include <stdint.h>
#include <termios.h>
#include <time.h>
#include <sys/stat.h>
#ifdef __linux__
#include "termios_linux.h"
#else
#include <termios.h>
#endif
/*
* Marvell BootROM UART Sensing
*/
@@ -554,7 +559,11 @@ kwboot_tty_baudrate_to_speed(int baudrate)
return B50;
#endif
default:
#ifdef BOTHER
return BOTHER;
#else
return B0;
#endif
}
}
@@ -575,6 +584,11 @@ kwboot_tty_change_baudrate(int fd, int baudrate)
return -1;
}
#ifdef BOTHER
if (speed == BOTHER)
tio.c_ospeed = tio.c_ispeed = baudrate;
#endif
rc = cfsetospeed(&tio, speed);
if (rc)
return rc;