Swatantra-66 opened a new pull request, #22133:
URL: https://github.com/apache/nuttx/pull/22133
## Summary
Addresses #20414
Make terminal window size support (`TIOCGWINSZ` and `TIOCSWINSZ`) optional
via `CONFIG_SERIAL_WINSIZE` (defaulting to `!DEFAULT_SMALL`):
1. **New Kconfig Option (`CONFIG_SERIAL_WINSIZE`)**:
- Added `config SERIAL_WINSIZE` under `drivers/serial/Kconfig`.
- Defaults to `!DEFAULT_SMALL`.
- Documents prerequisite signals: window size changes send `SIGWINCH` if
`CONFIG_TTY_SIGINT` or `CONFIG_TTY_SIGTSTP` is enabled.
2. **Conditional Compilation in Drivers**:
- `include/nuttx/serial/serial.h`: `winsize` field in `struct uart_dev_s`
is gated under `#ifdef CONFIG_SERIAL_WINSIZE`.
- `drivers/serial/serial.c`: `TIOCGWINSZ` and `TIOCSWINSZ` cases in
`uart_ioctl()` are gated under `#ifdef CONFIG_SERIAL_WINSIZE`. When disabled,
they fall through to default returning `-ENOTTY`.
- `drivers/serial/pty.c`: `pp_winsize` in `struct pty_devpair_s`,
`TIOCGWINSZ`/`TIOCSWINSZ` handling, and deferred `SIGWINCH` delivery in
`pty_ioctl()` are gated under `#ifdef CONFIG_SERIAL_WINSIZE`.
3. **Documentation**:
- `Documentation/os/drivers/character/serial.rst`: Documented
`CONFIG_SERIAL_WINSIZE`, noted that disabled ioctl calls fail with `ENOTTY`
(returning -1 and setting `errno` to `ENOTTY`), and described the
`DEFAULT_SMALL` default.
---
## Impact
- **Is new feature added?**: No (code bloat reduction / optional
configuration)
- **Is existing feature changed?**: Yes (terminal window size ioctls can be
omitted for small footprints)
- **Impact on user**: On memory-constrained devices with `DEFAULT_SMALL=y`,
terminal window size handling and storage are omitted to save Flash and SRAM.
On normal targets (`DEFAULT_SMALL=n`), default behavior is unchanged.
- **Impact on build**: None.
- **Impact on hardware**: None.
- **Impact on documentation**: Updated
`Documentation/os/drivers/character/serial.rst`.
---
## Size Difference
### Real Size Figures (`drivers/serial.o` on `sim:nsh` x86_64)
```
# CONFIG_SERIAL_WINSIZE=y
$ size drivers/serial.o
text data bss dec hex filename
21854 1760 3688 27302 6aa6 drivers/serial.o
# CONFIG_SERIAL_WINSIZE=n
$ size drivers/serial.o
text data bss dec hex filename
21566 1760 3648 26974 695e drivers/serial.o
```
| Configuration | text (bytes) | data (bytes) | bss (bytes) | Total (bytes) |
| :--- | :--- | :--- | :--- | :--- |
| `CONFIG_SERIAL_WINSIZE=y` | 21854 | 1760 | 3688 | 27302 |
| `CONFIG_SERIAL_WINSIZE=n` | 21566 | 1760 | 3648 | 26974 |
| **Savings** | **-288** | **0** | **-40** | **-328** |
In addition, each UART device instance saves 8 bytes (`struct winsize`) of
runtime SRAM.
---
## Testing
### Build Verification Log
- **Target**: `sim:nsh` (`x86_64`)
- Both `CONFIG_SERIAL_WINSIZE=y` and `CONFIG_SERIAL_WINSIZE=n` build cleanly:
```
CC: drivers/serial/serial.c
CC: drivers/serial/pty.c
AR: libdrivers.a
LD: nuttx
Pac SIM with dynamic libs..
SIM elf with dynamic libs archive in nuttx.tgz
```
### Runtime Test Execution Log
Boot and session verification on `sim:nsh` simulator:
```
nsh> help
help usage: help [-v] [<cmd>]
. dirname free mount set umount
[ date help mv kill unset
? df hexdump pidof pkill uptime
alias dmesg losetup poweroff sleep watch
unalias echo ln quit usleep xd
basename env ls printf source wait
break exec du ps test
cat exit mkdir pwd time
cd expr mkfatfs readlink true
cp false mkfifo rm truncate
cmp fdinfo mkrd rmdir uname
Builtin Apps:
dd gcov hello nsh sh
dumpstack gpio init ostest
nsh> ps
TID PID PPID PRI POLICY TYPE NPX STATE EVENT SIGMASK
STACK COMMAND
0 0 0 0 FIFO Kthread - Ready
0000000000000000 0069584 Idle_Task
1 0 0 224 FIFO Kthread - Waiting Semaphore
0000000000000000 0067456 sim_loop_wq 0x79125d800400 0x79125d800488
2 0 0 224 FIFO Kthread - Waiting Semaphore
0000000000000000 0067472 hpwork 0x40172ae0 0x40172b68
4 4 0 100 FIFO Task - Waiting Semaphore
0000000000000000 0067504 init_main
7 7 4 100 FIFO Task - Running
0000000000000000 0067504 sh
nsh> poweroff
```
### Code Style Verification
Checked with `tools/nxstyle`:
```
$ ./tools/nxstyle drivers/serial/pty.c
$ ./tools/nxstyle drivers/serial/serial.c
$ ./tools/nxstyle include/nuttx/serial/serial.h
# 0 errors, 0 warnings across all files (exit code 0)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]