Skip to content

tools/cxd56/mkspk: proper resources free on error. - #19841

Open
cederom wants to merge 1 commit into
apache:masterfrom
cederom:cederom-20260813-tools_cxd56_mkspk_free_resources_fix
Open

tools/cxd56/mkspk: proper resources free on error.#19841
cederom wants to merge 1 commit into
apache:masterfrom
cederom:cederom-20260813-tools_cxd56_mkspk_free_resources_fix

Conversation

@cederom

@cederom cederom commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Poroperly free up resources (allocated memory, file descriptors) on error.

Reported-by: xjDeng.

Impact

nuttx/tools/cxd56/mkspk.c is a host tool that builds Spresense firmware images, and now have fixed resources free on error which should satisfy memory leak code scanners.

Testing

Build host:

% uname -a
FreeBSD hexagon 14.4-RELEASE-p8 FreeBSD 14.4-RELEASE-p8 cederom-releng-14.4.8-igc_test_20260810-n273771-e99dffa6c4c8 GENERIC amd64

Checkpatch:

% ./tools/checkpatch.sh -c -u -m -g HEAD~...HEAD
Used config files:
    1: .codespellrc
  All checks pass.

Before:

% git branch
* master

% git log --oneline -5
e64b28974bf (HEAD -> master, origin/master, origin/HEAD) boards/nrf5340-dk: configure HFXO capacitance
45657b976b2 arch/nrf53: fix HFXO trim field extraction
3ac88f0f976 drivers/lcd: honour the LCD_APA102_* settings in the apa102 LCD driver

% ./tools/configure.sh -B spresense:nsh
  Copy files
  Select CONFIG_HOST_BSD=y
  Refreshing...
(..)
#
# configuration written to .config
#

% gmake -j
(..)
Memory region         Used Size  Region Size  %age Used
             ram:      116548 B      1536 KB      7.41%
         gnssram:           0 B       640 KB      0.00%
Generating: nuttx.spk
tools/cxd56/mkspk -c2 nuttx nuttx nuttx.spk;
File nuttx.spk is successfully created.
Done.

% ./tools/flash_writer.py -s -a -c /dev/cuaU0 -b 115200 nuttx.spk
/XXX/nuttx.git/./tools/flash_writer.py:27: DeprecationWarning: 'telnetlib' is deprecated and slated for removal in Python 3.13
  import telnetlib
/bin/sh: ./reset_board.sh: not found
Please press RESET button on target board
>>> Install files ...
install -b 115200
Install nuttx.spk
|0%-----------------------------50%------------------------------100%|
######################################################################

116672 bytes loaded.
Package validation is OK.
Saving package to "nuttx"
updater# >>> Save Configuration to FlashROM ...
set bootable M0P
M0P is not valid bootable. config not changed.
updater# sync
updater# Restarting the board ...
reboot


% cu -l /dev/cuaU0 -s 115200
Connected
cxd56_farapiinitialize: Mismatched version: loader(20591) != Self(20596)
cxd56_farapiinitialize: Please update loader and gnssfw firmwares!!

NuttShell (NSH) NuttX-10.4.0
nsh>
nsh> uname -a
NuttX 10.4.0 e64b28974bf Aug 14 2026 01:48:41 arm spresense
nsh> ?
help usage:  help [-v] [<cmd>]

    .           cp          exit        mkdir       rmdir       true
    [           cmp         expr        mkrd        set         truncate
    ?           dirname     false       mount       kill        uname
    alias       date        fdinfo      mv          pkill       umount
    unalias     df          free        pidof       sleep       unset
    basename    dmesg       help        printf      usleep      uptime
    break       echo        hexdump     ps          source      watch
    cat         env         ls          pwd         test        xd
    cd          exec        du          rm          time        wait

Builtin Apps:
    dd     nsh    sh
nsh> ~

After:

% git branch
* cederom-20260813-tools_cxd56_mkspk_free_resources_fix

% git log --oneline -3
b37b800a94 (HEAD -> cederom-20260813-tools_cxd56_mkspk_free_resources_fix, cederom/cederom-20260813-tools_cxd56_mkspk_free_resources_fix) tools/cxd56/mkspk: proper resources free on error.
e64b28974b (origin/master, origin/HEAD, master) boards/nrf5340-dk: configure HFXO capacitance
45657b976b arch/nrf53: fix HFXO trim field extraction

% ./tools/configure.sh -B spresense:nsh
  Copy files
  Select CONFIG_HOST_BSD=y
  Refreshing...
(..)
#
# configuration written to .config
#

% gmake -j
(..)
Memory region         Used Size  Region Size  %age Used
             ram:      116552 B      1536 KB      7.41%
         gnssram:           0 B       640 KB      0.00%
Generating: nuttx.spk
tools/cxd56/mkspk -c2 nuttx nuttx nuttx.spk;
File nuttx.spk is successfully created.
Done.

% ./tools/flash_writer.py -s -a -c /dev/cuaU0 -b 115200 nuttx.spk
/XXX/nuttx.git/./tools/flash_writer.py:27: DeprecationWarning: 'telnetlib' is deprecated and slated for removal in Python 3.13
  import telnetlib
/bin/sh: ./reset_board.sh: not found
Please press RESET button on target board
>>> Install files ...
install -b 115200
Install nuttx.spk
|0%-----------------------------50%------------------------------100%|
######################################################################

116672 bytes loaded.
Package validation is OK.
Saving package to "nuttx"
updater# >>> Save Configuration to FlashROM ...
set bootable M0P
M0P is not valid bootable. config not changed.
updater# sync
updater# Restarting the board ...
reboot


% cu -l /dev/cuaU0 -s 115200
Connected
cxd56_farapiinitialize: Mismatched version: loader(20591) != Self(20596)
cxd56_farapiinitialize: Please update loader and gnssfw firmwares!!

NuttShell (NSH) NuttX-13.0.0
nsh>
nsh> uname -a
NuttX 13.0.0 3e14158cee-dirty Aug 14 2026 01:57:34 arm spresense
nsh> ?
help usage:  help [-v] [<cmd>]

    .           cp          exit        mkdir       rmdir       true
    [           cmp         expr        mkrd        set         truncate
    ?           dirname     false       mount       kill        uname
    alias       date        fdinfo      mv          pkill       umount
    unalias     df          free        pidof       sleep       unset
    basename    dmesg       help        printf      usleep      uptime
    break       echo        hexdump     ps          source      watch
    cat         env         ls          pwd         test        xd
    cd          exec        du          rm          time        wait

Builtin Apps:
    dd     nsh    sh
nsh> ~
[EOT]
hexagon% ls -al nuttx.spk
-rw-r--r--  1 cederom wheel 116672 14 sie 01:57 nuttx.spk

@cederom
cederom requested a review from jerpelea as a code owner August 14, 2026 00:15
@github-actions github-actions Bot added Area: Tooling Size: S The size of the change in this PR is small labels Aug 14, 2026
@github-actions

github-actions Bot commented Aug 14, 2026

Copy link
Copy Markdown

MemBrowse Memory Report

No memory changes detected for:

@cederom
cederom requested review from acassis and linguini1 August 14, 2026 01:12
jerpelea
jerpelea previously approved these changes Aug 14, 2026
Poroperly free up resources (allocated memory, file descriptors) on error.

Reported-by: xjDeng.

Signed-off-by: Tomasz 'CeDeROM' CEDRO <tomek@cedro.info>
@jerpelea
jerpelea dismissed stale reviews from xiaoxiang781216 and themself via 27d5344 August 14, 2026 06:25
@jerpelea
jerpelea force-pushed the cederom-20260813-tools_cxd56_mkspk_free_resources_fix branch from b37b800 to 27d5344 Compare August 14, 2026 06:25
@jerpelea

Copy link
Copy Markdown
Contributor

DO NOT MERGE!

@jerpelea

Copy link
Copy Markdown
Contributor

@acassis @xiaoxiang781216

@jerpelea

jerpelea commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

CI depends on apache/nuttx-apps#3722

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Tooling 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