Skip to content

drivers/serial: make terminal window size optional for DEFAULT_SMALL - #22133

Merged
xiaoxiang781216 merged 1 commit into
apache:masterfrom
Swatantra-66:fix/serial-winsize-default-small
Nov 23, 2026
Merged

xiaoxiang781216 merged 1 commit into
apache:masterfrom
Swatantra-66:fix/serial-winsize-default-small

Conversation

@Swatantra-66

Copy link
Copy Markdown
Contributor

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)

@github-actions github-actions Bot added Area: Drivers Drivers issues Size: S The size of the change in this PR is small labels Nov 20, 2026
@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

arduino-mega2560

  • flash: .data -8 B, .text -70 B (-0.1%, 64,463 B / 262,144 B, total: 25% used)
  • sram: .data -8 B (-0.3%, 2,768 B / 8,192 B, total: 34% used)

hifive1-revb

  • flash: .data -8 B, .text -256 B (-0.3%, 87,240 B / 4,194,304 B, total: 2% used)
  • sram: .data -8 B (-0.2%, 4,020 B / 16,384 B, total: 25% used)

mirtoo

  • kseg0_progmem: .data -8 B, .text -264 B (-0.4%, 66,272 B / 131,072 B, total: 51% used)
  • kseg1_datamem: .data -8 B, .sbss -8 B (-0.6%, 2,620 B / 32,256 B, total: 8% used)

stm32-nucleo-f103rb

  • flash: .data -8 B, .text -124 B (-0.4%, 35,168 B / 131,072 B, total: 27% used)
  • sram: .data -8 B (-0.3%, 2,500 B / 20,480 B, total: 12% used)

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

@GUIDINGLI

Copy link
Copy Markdown
Contributor

@Swatantra-66 Thanks for your help for code size, please fix the conflict

Add CONFIG_SERIAL_WINSIZE (default !DEFAULT_SMALL) to gate TIOCGWINSZ
and TIOCSWINSZ ioctl support in the serial and pseudo-terminal drivers.
When disabled, the struct winsize member is omitted from uart_dev_s and
pty_devpair_s, and the ioctl cases fall through to the default handler
returning -ENOTTY.

Saves 288 bytes of Flash and 40 bytes of bss per serial device on
sim:nsh (x86_64).  On DEFAULT_SMALL ARM targets the struct winsize
(8 bytes SRAM per UART) is also eliminated.

Assisted-by: Antigravity:claude-opus-4.6
Signed-off-by: Swatantra Yadav <[email protected]>
@Swatantra-66

Copy link
Copy Markdown
Contributor Author

@Swatantra-66 Thanks for your help for code size, please fix the conflict

conflict resolved

@xiaoxiang781216
xiaoxiang781216 merged commit 93a85cd into apache:master Nov 23, 2026
58 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Drivers Drivers issues Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants