diff options
Diffstat (limited to 'meta-oe/recipes-test/linux-serial-test/files/0001-Fix-serial-setup-handling-to-respect-user-intent.patch')
| -rw-r--r-- | meta-oe/recipes-test/linux-serial-test/files/0001-Fix-serial-setup-handling-to-respect-user-intent.patch | 133 |
1 files changed, 133 insertions, 0 deletions
diff --git a/meta-oe/recipes-test/linux-serial-test/files/0001-Fix-serial-setup-handling-to-respect-user-intent.patch b/meta-oe/recipes-test/linux-serial-test/files/0001-Fix-serial-setup-handling-to-respect-user-intent.patch new file mode 100644 index 0000000000..2360d1ee0c --- /dev/null +++ b/meta-oe/recipes-test/linux-serial-test/files/0001-Fix-serial-setup-handling-to-respect-user-intent.patch | |||
| @@ -0,0 +1,133 @@ | |||
| 1 | From 8d4f9a1a77f59eb3ed79267f58fac949835aebfc Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Vitor Soares <vitor.soares@toradex.com> | ||
| 3 | Date: Thu, 30 Oct 2025 14:52:57 +0000 | ||
| 4 | Subject: [PATCH] Fix serial setup handling to respect user intent | ||
| 5 | |||
| 6 | Commit 77320571e63c ("Check if rs485 is already configured on the port") | ||
| 7 | attempted to respect RS485 settings already configured on the port (e.g. | ||
| 8 | via Device Tree). However, it unintentionally ignored user input, | ||
| 9 | causing issues such as: | ||
| 10 | - Inability to change delay settings | ||
| 11 | - Failure to explicitly disable RS485 | ||
| 12 | - Broken UART loopback and RTS/CTS flow-control tests when RS485 was | ||
| 13 | pre-enabled | ||
| 14 | |||
| 15 | The original intent was valid for existing configurations (bare -q), but | ||
| 16 | the tool should prioritize user intent, especially in testing scenarios. | ||
| 17 | |||
| 18 | This update restores predictable, user-driven behavior: | ||
| 19 | - RS485 can be explicitly enabled, disabled, or reconfigured | ||
| 20 | - Current configurations are respected when appropriate | ||
| 21 | |||
| 22 | Upstream-Status: Submitted [https://github.com/cbrake/linux-serial-test/pull/68] | ||
| 23 | Fixes: 77320571e63c ("Check if rs485 is already configured on the port") | ||
| 24 | Signed-off-by: Vitor Soares <vitor.soares@toradex.com> | ||
| 25 | --- | ||
| 26 | linux-serial-test.c | 48 ++++++++++++++++++++++++++++----------------- | ||
| 27 | 1 file changed, 30 insertions(+), 18 deletions(-) | ||
| 28 | |||
| 29 | diff --git a/linux-serial-test.c b/linux-serial-test.c | ||
| 30 | index 294f53882570..119bf58e663d 100644 | ||
| 31 | --- a/linux-serial-test.c | ||
| 32 | +++ b/linux-serial-test.c | ||
| 33 | @@ -60,6 +60,7 @@ int _cl_no_tx_param = 0; | ||
| 34 | int _cl_rx_delay = 0; | ||
| 35 | int _cl_tx_delay = 0; | ||
| 36 | int _cl_tx_bytes = 0; | ||
| 37 | +int _cl_rs485 = 0; | ||
| 38 | int _cl_rs485_after_delay = -1; | ||
| 39 | int _cl_rs485_before_delay = 0; | ||
| 40 | int _cl_rs485_rts_after_send = 0; | ||
| 41 | @@ -315,7 +316,9 @@ static void display_help(void) | ||
| 42 | " -q, --rs485 Enable RS485 direction control on port, and set delay from when TX is\n" | ||
| 43 | " finished and RS485 driver enable is de-asserted. Delay is specified in\n" | ||
| 44 | " bit times. To optionally specify a delay from when the driver is enabled\n" | ||
| 45 | - " to start of TX use 'after_delay.before_delay' (-q 1.1)\n" | ||
| 46 | + " to start of TX use 'after_delay.before_delay' (-q 1.1). If no value is\n" | ||
| 47 | + " given, delay defaults to 0. Existing RS485 configuration is respected if\n" | ||
| 48 | + " already enabled.\n" | ||
| 49 | " -Q, --rs485_rts Deassert RTS on send, assert after send. Omitting -Q inverts this logic.\n" | ||
| 50 | " -m, --no-modem Do not clobber against any modem lines.\n" | ||
| 51 | " -o, --tx-time Number of seconds to transmit for (defaults to 0, meaning no limit)\n" | ||
| 52 | @@ -335,7 +338,7 @@ static void process_options(int argc, char * argv[]) | ||
| 53 | { | ||
| 54 | for (;;) { | ||
| 55 | int option_index = 0; | ||
| 56 | - static const char *short_options = "hb:p:d:D:TRsSy:z:cBertq:Qml:a:w:o:i:P:kKAI:O:W:Znf"; | ||
| 57 | + static const char *short_options = "hb:p:d:D:TRsSy:z:cBertq::Qml:a:w:o:i:P:kKAI:O:W:Znf"; | ||
| 58 | static const struct option long_options[] = { | ||
| 59 | {"help", no_argument, 0, 0}, | ||
| 60 | {"baud", required_argument, 0, 'b'}, | ||
| 61 | @@ -359,7 +362,7 @@ static void process_options(int argc, char * argv[]) | ||
| 62 | {"rx-delay", required_argument, 0, 'l'}, | ||
| 63 | {"tx-delay", required_argument, 0, 'a'}, | ||
| 64 | {"tx-bytes", required_argument, 0, 'w'}, | ||
| 65 | - {"rs485", required_argument, 0, 'q'}, | ||
| 66 | + {"rs485", optional_argument, 0, 'q'}, | ||
| 67 | {"rs485_rts", no_argument, 0, 'Q'}, | ||
| 68 | {"no-modem", no_argument, 0, 'm'}, | ||
| 69 | {"tx-time", required_argument, 0, 'o'}, | ||
| 70 | @@ -467,8 +470,12 @@ static void process_options(int argc, char * argv[]) | ||
| 71 | } | ||
| 72 | case 'q': { | ||
| 73 | char *endptr; | ||
| 74 | - _cl_rs485_after_delay = strtol(optarg, &endptr, 0); | ||
| 75 | - _cl_rs485_before_delay = strtol(endptr+1, &endptr, 0); | ||
| 76 | + _cl_rs485 = 1; | ||
| 77 | + | ||
| 78 | + if (optarg) { | ||
| 79 | + _cl_rs485_after_delay = strtol(optarg, &endptr, 0); | ||
| 80 | + _cl_rs485_before_delay = strtol(endptr+1, &endptr, 0); | ||
| 81 | + } | ||
| 82 | break; | ||
| 83 | } | ||
| 84 | case 'Q': | ||
| 85 | @@ -707,15 +714,20 @@ static void setup_serial_port(int baud) | ||
| 86 | |||
| 87 | /* enable/disable rs485 direction control, first check if RS485 is supported */ | ||
| 88 | if(ioctl(_fd, TIOCGRS485, &rs485) < 0) { | ||
| 89 | - if (_cl_rs485_after_delay >= 0) { | ||
| 90 | + if (_cl_rs485) { | ||
| 91 | /* error could be because hardware is missing rs485 support so only print when actually trying to activate it */ | ||
| 92 | perror("Error getting RS-485 mode"); | ||
| 93 | } | ||
| 94 | } else { | ||
| 95 | - if (rs485.flags & SER_RS485_ENABLED) { | ||
| 96 | - printf("RS485 already enabled on port, ignoring delays if set\n"); | ||
| 97 | - } else { | ||
| 98 | - if (_cl_rs485_after_delay >= 0) { | ||
| 99 | + if (_cl_rs485) { | ||
| 100 | + /* Skip reconfiguration if already enabled with default delays */ | ||
| 101 | + if ((_cl_rs485_after_delay < 0) && (rs485.flags & SER_RS485_ENABLED)) { | ||
| 102 | + printf("RS485 already enabled on port with default settings\n"); | ||
| 103 | + } else { | ||
| 104 | + /* Default to 0 if not specified */ | ||
| 105 | + if (_cl_rs485_after_delay < 0) { | ||
| 106 | + _cl_rs485_after_delay = 0; | ||
| 107 | + } | ||
| 108 | /* enable RS485 */ | ||
| 109 | rs485.flags |= SER_RS485_ENABLED | SER_RS485_RX_DURING_TX | | ||
| 110 | (_cl_rs485_rts_after_send ? SER_RS485_RTS_AFTER_SEND : SER_RS485_RTS_ON_SEND); | ||
| 111 | @@ -725,14 +737,14 @@ static void setup_serial_port(int baud) | ||
| 112 | if(ioctl(_fd, TIOCSRS485, &rs485) < 0) { | ||
| 113 | perror("Error setting RS-485 mode"); | ||
| 114 | } | ||
| 115 | - } else { | ||
| 116 | - /* disable RS485 */ | ||
| 117 | - rs485.flags &= ~(SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND | SER_RS485_RTS_AFTER_SEND); | ||
| 118 | - rs485.delay_rts_after_send = 0; | ||
| 119 | - rs485.delay_rts_before_send = 0; | ||
| 120 | - if(ioctl(_fd, TIOCSRS485, &rs485) < 0) { | ||
| 121 | - perror("Error setting RS-232 mode"); | ||
| 122 | - } | ||
| 123 | + } | ||
| 124 | + } else { | ||
| 125 | + /* disable RS485 */ | ||
| 126 | + rs485.flags &= ~(SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND | SER_RS485_RTS_AFTER_SEND); | ||
| 127 | + rs485.delay_rts_after_send = 0; | ||
| 128 | + rs485.delay_rts_before_send = 0; | ||
| 129 | + if(ioctl(_fd, TIOCSRS485, &rs485) < 0) { | ||
| 130 | + perror("Error setting RS-232 mode"); | ||
| 131 | } | ||
| 132 | } | ||
| 133 | } | ||
