Skip to content

nshlib: add relative image path support in boot command - #3668

Merged
acassis merged 1 commit into
apache:masterfrom
Junbo-Zheng:nshlib
Jul 27, 2026
Merged

nshlib: add relative image path support in boot command#3668
acassis merged 1 commit into
apache:masterfrom
Junbo-Zheng:nshlib

Conversation

@Junbo-Zheng

Copy link
Copy Markdown
Contributor

Summary

cmd_boot passed the image path straight to boardctl(), which resolves it in a context that does not inherit the NSH shell cwd, so relative paths failed, and only absolute paths worked. Use nsh_getfullpath() to resolve relative paths against the cwd before calling boardctl().

Impact

  • Users: boot <relative-path> now resolves against the NSH cwd;
    absolute-path behavior is unchanged.
  • Build: None -- uses the existing nsh_getfullpath/nsh_freefullpath
    helpers, no new dependency.
  • Hardware: None -- NSH command logic only, no board-specific code.
  • Documentation: None.
  • Security & Compatibility: None -- behavior extension; absolute
    paths behave exactly as before.

Testing

Local build on Cortex-M55 (enables CONFIG_BOARDCTL_BOOT_IMAGE); the boot ELF builds and the boot NSH command succeeds.

And the change follows the established nsh_getfullpath()/nsh_freefullpath() convention already used by the other NSH file-path commands. Representative upstream examples (the same pattern is also used by mv, ls, ln, mkdir, and every other NSH file-path command):

cmd_boot passed the image path straight to boardctl(), which resolves
it in a context that does not inherit the NSH shell cwd, so relative
paths failed and only absolute paths worked. Use nsh_getfullpath() to
resolve relative paths against the cwd before calling boardctl().

Signed-off-by: Junbo Zheng <zhengjunbo1@xiaomi.com>

@cederom cederom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @Junbo-Zheng :-)

@acassis acassis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Junbo-Zheng I think this feature needs Documentation

@cederom

cederom commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

I also wonder about impact on firmware size, have you compared that @Junbo-Zheng ? Maybe we want this as an option if the function is not part of the firmware by default? I understand that cp, rm, cat can use relative paths but these can be disabled by default. If no impact then no problem :-)

@Junbo-Zheng

Junbo-Zheng commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

@Junbo-Zheng I think this feature needs Documentation

@acassis Done, please review apache/nuttx#19553

@Junbo-Zheng

Copy link
Copy Markdown
Contributor Author

I also wonder about impact on firmware size, have you compared that @Junbo-Zheng ? Maybe we want this as an option if the function is not part of the firmware by default? I understand that cp, rm, cat can use relative paths but these can be disabled by default. If no impact then no problem :-)

@cederom

The boot nsh command is already optional — it is gated by CONFIG_BOARDCTL_BOOT_IMAGE (opt-in) together with CONFIG_NSH_DISABLE_BOOT (opt-out), see nsh_syscmds.c#L404. Platforms that don't need image boot simply leave CONFIG_BOARDCTL_BOOT_IMAGE unset, and cmd_boot (along with its nsh_getfullpath() call) is not compiled in at all.

Local build with Arm GNU Toolchain 13.2.rel1

/home/mi/xiaomi/trunk [26-07-27_13:53:56] arm-none-eabi-gcc --version
arm-none-eabi-gcc (Arm GNU Toolchain 13.2.rel1 (Build arm-13.7)) 13.2.1 20231009
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  • before
/home/mi/xiaomi/trunk/out [26-07-27_12:16:26] arm-none-eabi-size nuttx 
   text	   data	    bss	    dec	    hex	filename
 469784	  15352	49257896	49743032	2f704b8	nuttx
  • after
    • CONFIG_BOARDCTL_BOOT_IMAGE=y
    • CONFIG_NSH_DISABLE_BOOT not set
/home/mi/xiaomi/trunk/out [26-07-27_12:18:43] arm-none-eabi-size nuttx 
   text	   data	    bss	    dec	    hex	filename
 469792	  15352	49257896	49743040	2f704c0	nuttx

@Junbo-Zheng
Junbo-Zheng requested review from acassis and cederom July 27, 2026 06:13
@acassis
acassis merged commit fabafbc into apache:master Jul 27, 2026
75 of 79 checks passed
@Junbo-Zheng
Junbo-Zheng deleted the nshlib branch July 27, 2026 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants