Skip to content

drivers/serial: make serial line break optional for DEFAULT_SMALL - #22149

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

GUIDINGLI merged 1 commit into
apache:masterfrom
Swatantra-66:fix/serial-break-default-small

Conversation

@Swatantra-66

Copy link
Copy Markdown
Contributor

Summary

Make serial line break support (tcsendbreak, TCSBRK, and TCSBRKP) optional via CONFIG_SERIAL_BREAK, defaulting to !DEFAULT_SMALL.

Many memory-constrained targets (DEFAULT_SMALL=y) do not require line break signaling over UART. Currently, uart_tcsendbreak() and its associated ioctl handling are unconditionally compiled into drivers/serial/serial.c. Furthermore, no ARM MCU lower-half serial driver implements a hardware line break routine—it is only forwarded via dev->ops->ioctl passthrough with BSD-compatible TIOCSBRK/TIOCCBRK.

When CONFIG_SERIAL_BREAK is disabled (n):

  • uart_tcsendbreak() is omitted from compilation.
  • The TCSBRK and TCSBRKP ioctl cases fall through to default, returning -ENOTTY.
  • In user space, tcsendbreak() receives -ENOTTY from ioctl(), returning -1 with errno set to ENOTTY.
  • Saves 634 bytes of Flash (text) and 160 bytes of RAM (data + bss) in drivers/serial.o.

Addresses Issue #20414.

Impact

  • Is new feature added? No (adds Kconfig gating option CONFIG_SERIAL_BREAK).
  • Is existing feature changed? Yes, TCSBRK and TCSBRKP return -ENOTTY when CONFIG_SERIAL_BREAK is disabled.
  • Impact on user: None when CONFIG_SERIAL_BREAK=y (default). For DEFAULT_SMALL=y configurations, tcsendbreak() will fail with ENOTTY, saving Flash and RAM.
  • Impact on build: None.
  • Impact on hardware: None.
  • Impact on documentation: Updated Documentation/os/drivers/character/serial.rst.

Size Difference (sim:nsh)

Configuration: sim:nsh (x86_64)

drivers/serial.o

Section CONFIG_SERIAL_BREAK=y CONFIG_SERIAL_BREAK=n Difference
text 21918 21284 -634 bytes (-2.9%)
data 1760 1712 -48 bytes
bss 3696 3584 -112 bytes
Total 27374 26580 -794 bytes (-2.9%)

Testing

Build Verification

  • Clean build with CONFIG_SERIAL_BREAK=y: Success.
  • Clean build with CONFIG_SERIAL_BREAK=n: Success.
  • nxstyle verification on drivers/serial/serial.c: 0 errors.

Runtime Test Log (sim:nsh, CONFIG_SERIAL_BREAK=n)

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 0x756942400400 0x756942400488
    2     0     0 224 FIFO     Kthread   - Waiting  Semaphore 0000000000000000 0067472 hpwork 0x4017cb00 0x4017cb88
    4     4     0 100 FIFO     Task      - Waiting  Semaphore 0000000000000000 0067504 init_main
    7     7     4 100 FIFO     Task      - Running            0000000000000000 0067504 sh
nsh> poweroff

Make TCSBRK and TCSBRKP ioctl handling and uart_tcsendbreak()
optional via CONFIG_SERIAL_BREAK, defaulting to !DEFAULT_SMALL.
When disabled, the break ioctls return -ENOTTY (causing tcsendbreak()
to return -1 with errno set to ENOTTY), saving 634 bytes of Flash
(text) and 160 bytes of data/bss on small targets.

Assisted-by: Claude:claude-opus-4.6
Signed-off-by: Swatantra Yadav <[email protected]>
@github-actions github-actions Bot added Area: Drivers Drivers issues Size: S The size of the change in this PR is small labels Nov 22, 2026
@github-actions

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

arduino-mega2560

  • flash: .text -286 B (-0.4%, 64,601 B / 262,144 B, total: 25% used)

hifive1-revb

  • flash: .text -300 B (-0.3%, 87,296 B / 4,194,304 B, total: 2% used)

mirtoo

  • kseg0_progmem: .text -352 B (-0.5%, 66,588 B / 131,072 B, total: 51% used)

stm32-nucleo-f103rb

  • flash: .text -132 B (-0.4%, 35,264 B / 131,072 B, total: 27% used)

No memory changes detected for:


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

@GUIDINGLI
GUIDINGLI merged commit 46b8efc into apache:master Nov 23, 2026
59 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.

3 participants