Skip to content

Commit 893bd45

Browse files
committed
feature: add support for parsing boards, defconfigs and archs
Provides Python API for dev use and CLI list option.
1 parent 74863a4 commit 893bd45

File tree

8 files changed

+471
-0
lines changed

8 files changed

+471
-0
lines changed

docs/source/api_examples.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,36 @@ for path in copied_paths:
100100
# Clean up when done
101101
cleanup_tmp_copies(copied_paths)
102102
```
103+
104+
## List available boards and defconfigs with Board Explorer
105+
106+
The NuttxBoardExplorer allows the user to retrieve a list of boards, which
107+
can be filtered by arch, soc or individual board. Each returned board has
108+
a list of all defconfigs, which can be iterated and its content can be retrieved.
109+
110+
This example demonstrates how to discover boards and defconfigs available
111+
in an existing NuttX repository using the lightweight helpers in
112+
`ntxbuild.nuttx`.
113+
114+
```python
115+
from pathlib import Path
116+
from ntxbuild.nuttx import NuttxBoardExplorer
117+
118+
# Path to the nuttx repository inside your nuttxspace
119+
nuttx_repo = Path.cwd() / "nuttx"
120+
121+
# Create a filter and list all boards for a specific architecture
122+
nbf = NuttxBoardExplorer(nuttx_repo)
123+
boards = nbf.set_arch("arm").boards
124+
125+
for board in boards:
126+
print(f"Board: {board.name} (arch={board.arch} soc={board.soc})")
127+
for cfg in board.defconfigs:
128+
print(f" - defconfig: {d.name}")
129+
# optionally read the defconfig content
130+
# print(d.content)
131+
132+
# You can also find boards by soc or by exact board name
133+
boards_by_soc = nbf.set_soc("stm32").boards
134+
boards_by_name = nbf.set_board("nuttx-stm32").boards
135+
```

docs/source/features.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,19 @@ See usage examples on {doc}`api_examples`.
3939
- Configurable target directory
4040
- Automatic cleanup
4141

42+
## Board Explorer
43+
44+
The Board Explorer feature provides a simple way to discover and inspect
45+
the boards and available defconfigs inside a NuttX repository. It is available
46+
both through the CLI (commands that list boards) and the Python API
47+
(see `ntxbuild.nuttx` helpers).
48+
49+
- Quickly find which boards support a particular architecture or SoC.
50+
- Programmatically build a list of candidate boards for automated testing or
51+
CI matrix generation.
52+
- Provide a lightweight UI (or CLI output) that helps users choose a board
53+
and defconfig before running `start` or `build` commands.
54+
4255
## Curses Support
4356
Menuconfig works just as usual through this tool.
4457

docs/source/ntxbuild.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,17 @@ Utilities Module
7373
:show-inheritance:
7474
:undoc-members:
7575

76+
NuttX Module
77+
---------------------
78+
79+
Utilities for discovering and representing NuttX boards and defconfigs. This
80+
module provides small data classes to represent boards under `<nuttxspace>/nuttx/boards`.
81+
82+
.. automodule:: ntxbuild.nuttx
83+
:members:
84+
:show-inheritance:
85+
:undoc-members:
86+
7687
Module contents
7788
---------------
7889

docs/source/quick_start.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,68 @@ builder.build(parallel=10)
7979
builder.distclean()
8080
```
8181

82+
## View Available Boards and Configs
83+
It is possible to quickly see a table of available boards for a SoC or defconfigs for a board.
84+
85+
For the board list, provide the SoC name as in `boards/<arch>/<soc>`.
86+
```bash
87+
$ ntxbuild list boards qemu
88+
╒═════════════╕
89+
│ Boards │
90+
╞═════════════╡
91+
│ qemu-armv7a │
92+
├─────────────┤
93+
│ qemu-armv7r │
94+
├─────────────┤
95+
│ qemu-armv8a │
96+
├─────────────┤
97+
│ qemu-i486 │
98+
╘═════════════╛
99+
Total boards: 4
100+
101+
$ ntxbuild list boards esp32c6
102+
╒═════════════════╕
103+
│ Boards │
104+
╞═════════════════╡
105+
│ esp32c6-devkitc │
106+
├─────────────────┤
107+
│ esp32c6-devkitm │
108+
├─────────────────┤
109+
│ esp32c6-xiao │
110+
╘═════════════════╛
111+
Total boards: 3
112+
```
113+
114+
To view defconfigs, use the board name under `boards/<arch>/<soc>/<board>`.
115+
116+
```
117+
$ ntxbuild list defconfigs esp32c6-devkitc
118+
╒══════════════════════╤════════════════════╕
119+
│ Defconfigs │ Defconfigs │
120+
╞══════════════════════╪════════════════════╡
121+
│ adc │ bmp180 │
122+
├──────────────────────┼────────────────────┤
123+
│ buttons │ capture │
124+
├──────────────────────┼────────────────────┤
125+
│ crypto │ efuse │
126+
├──────────────────────┼────────────────────┤
127+
│ gpio │ i2c │
128+
|──────────────────────┼────────────────────┤
129+
[...]
130+
|──────────────────────┼────────────────────┤
131+
│ twai │ ulp │
132+
├──────────────────────┼────────────────────┤
133+
│ usbconsole │ watchdog │
134+
├──────────────────────┼────────────────────┤
135+
│ wifi │ │
136+
╘══════════════════════╧════════════════════╛
137+
╒═════════╤═════════════════╤════════╤═════════╤════════════════════════════════╕
138+
│ Total │ Board │ Arch │ Soc │ Path (nuttx/boards/) │
139+
╞═════════╪═════════════════╪════════╪═════════╪════════════════════════════════╡
140+
│ 37 │ esp32c6-devkitc │ risc-v │ esp32c6 │ risc-v/esp32c6/esp32c6-devkitc │
141+
╘═════════╧═════════════════╧════════╧═════════╧════════════════════════════════╛
142+
```
143+
82144
## Downloading Toolchains
83145
To visualize currently available toolchains, execute the `toolchain list` command:
84146

ntxbuild/cli.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from .build import BuildTool, nuttx_builder
1313
from .config import ConfigManager
1414
from .env_data import clear_ntx_env, create_base_env_file, load_ntx_env
15+
from .nuttx import NuttxBoardExplorer
1516
from .setup import download_nuttx_apps_repo, download_nuttx_repo
1617
from .toolchains import ManagePath, ToolchainInstaller
1718
from .utils import NUTTX_APPS_DEFAULT_DIR_NAME, NUTTX_DEFAULT_DIR_NAME, find_nuttx_root
@@ -512,5 +513,77 @@ def menuconfig(menuconfig):
512513
sys.exit(1)
513514

514515

516+
@main.group()
517+
def list(): # noqa: F811
518+
"""List available boards and defconfigs.
519+
520+
Provides commands to list boards and defconfigs in the NuttX repository.
521+
"""
522+
pass
523+
524+
525+
@list.command()
526+
@click.argument("soc")
527+
@click.option("--nuttx-dir", help="NuttX directory", default=NUTTX_DEFAULT_DIR_NAME)
528+
@click.option("--apps-dir", help="Apps directory", default=NUTTX_APPS_DEFAULT_DIR_NAME)
529+
def boards(soc, nuttx_dir, apps_dir):
530+
"""List available boards for a specific SoC/chip.
531+
532+
Example usage:
533+
ntxbuild list boards <soc>
534+
"""
535+
current_dir = Path.cwd()
536+
logger.debug(f"Search for nuttx directory in: {current_dir}")
537+
538+
# This validates the directory structure. We don't use prepare_env
539+
# because we don't need to load the environment just to check
540+
# available boards.
541+
nuttxspace = find_nuttx_root(current_dir, nuttx_dir, apps_dir)
542+
543+
try:
544+
nuttx_path = nuttxspace / nuttx_dir
545+
explorer = NuttxBoardExplorer(nuttx_path)
546+
boards_list = explorer.set_soc(soc).boards
547+
if not boards_list:
548+
click.echo(f"No boards found for SoC: {soc}")
549+
sys.exit(0)
550+
explorer.print_board_summary()
551+
sys.exit(0)
552+
except Exception as e:
553+
click.echo(f"❌ {e}")
554+
sys.exit(1)
555+
556+
557+
@list.command()
558+
@click.argument("board")
559+
@click.option("--nuttx-dir", help="NuttX directory", default=NUTTX_DEFAULT_DIR_NAME)
560+
@click.option("--apps-dir", help="Apps directory", default=NUTTX_APPS_DEFAULT_DIR_NAME)
561+
def defconfigs(board, nuttx_dir, apps_dir):
562+
"""List available defconfigs for a specific board.
563+
564+
Example usage:
565+
ntxbuild list defconfigs <board>
566+
"""
567+
current_dir = Path.cwd()
568+
logger.debug(f"Search for nuttx directory in: {current_dir}")
569+
570+
# This validates the directory structure. We don't use prepare_env
571+
# because we don't need to load the environment just to check
572+
# available defconfigs.
573+
nuttxspace = find_nuttx_root(current_dir, nuttx_dir, apps_dir)
574+
try:
575+
nuttx_path = nuttxspace / nuttx_dir
576+
explorer = NuttxBoardExplorer(nuttx_path)
577+
boards_list = explorer.set_board(board).boards
578+
if not boards_list:
579+
click.echo(f"Board not found: {board}")
580+
sys.exit(0)
581+
boards_list[0].print_defconfig_summary()
582+
sys.exit(0)
583+
except Exception as e:
584+
click.echo(f"❌ {e}")
585+
sys.exit(1)
586+
587+
515588
if __name__ == "__main__":
516589
main()

0 commit comments

Comments
 (0)