Skip to content

Commit 1b58435

Browse files
authored
Merge pull request #377 from fdcavalcanti/feature/nuttx-efuse
feat: add support for virtual efuse on NuttX (RDT-1502)
2 parents 30e18cb + 5e946a0 commit 1b58435

File tree

9 files changed

+65
-6
lines changed

9 files changed

+65
-6
lines changed

all_local_packages.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
-e ./pytest-embedded-jtag/
66
-e ./pytest-embedded-qemu/
77
-e ./pytest-embedded-arduino/
8+
-e ./pytest-embedded-nuttx/

pytest-embedded-nuttx/pytest_embedded_nuttx/app.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ def __init__(
2222
super().__init__(**kwargs)
2323

2424
self.file_extension = file_extension
25-
self.app_file, self.bootloader_file, self.merge_file = self._get_bin_files()
25+
self.app_file, self.bootloader_file, self.merge_file, self.vefuse_file = self._get_bin_files()
2626

27-
def _get_bin_files(self) -> tuple[Path | None, Path | None, Path | None]:
27+
def _get_bin_files(self) -> tuple[Path | None, Path | None, Path | None, Path | None]:
2828
"""
2929
Get path to binary files available in the app_path.
3030
If either the application image or bootloader is not found,
@@ -37,13 +37,17 @@ def _get_bin_files(self) -> tuple[Path | None, Path | None, Path | None]:
3737
search_pattern = '*' + self.file_extension
3838
bin_files = list(search_path.rglob(search_pattern))
3939
app_file, bootloader_file, merge_file = None, None, None
40+
vefuse_file = None
4041

4142
logging.info('Searching %s', str(search_path))
4243
if not bin_files:
4344
logging.warning('No binary files found with pattern: %s', search_pattern)
4445

4546
for file_path in bin_files:
4647
file_name = str(file_path.stem)
48+
if 'vefuse' in file_name:
49+
vefuse_file = file_path
50+
logging.info('Virtual E-Fuse file: %s', vefuse_file.as_posix())
4751
if 'nuttx' in file_name:
4852
if 'merged' in file_name:
4953
merge_file = file_path
@@ -59,4 +63,4 @@ def _get_bin_files(self) -> tuple[Path | None, Path | None, Path | None]:
5963
logging.error('App file not found: %s', app_file)
6064
print(bin_files)
6165

62-
return app_file, bootloader_file, merge_file
66+
return app_file, bootloader_file, merge_file, vefuse_file

pytest-embedded-nuttx/pytest_embedded_nuttx/serial.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ class NuttxSerial(EspSerial):
1515

1616
# Default offset for the primary MCUBoot slot across
1717
# all Espressif devices on NuttX
18-
MCUBOOT_PRIMARY_SLOT_OFFSET = 0x10000
18+
MCUBOOT_PRIMARY_SLOT_OFFSET = 0x20000
19+
VIRTUAL_EFUSE_OFFSET = 0x10000
1920
SERIAL_BAUDRATE = 115200
2021

2122
binary_offsets: ClassVar[dict[str, int]] = {
@@ -82,13 +83,19 @@ def get_key_from_value(dictionary, val):
8283
self.flash_mode = 'dio'
8384

8485
@EspSerial.use_esptool()
85-
def flash(self) -> None:
86+
def flash(
87+
self,
88+
virtual_efuse_offset: int = VIRTUAL_EFUSE_OFFSET,
89+
mcuboot_primary_slot_offset: int = MCUBOOT_PRIMARY_SLOT_OFFSET,
90+
) -> None:
8691
"""Flash the binary files to the board."""
8792

8893
flash_files = []
8994
if self.app.bootloader_file:
95+
if self.app.vefuse_file:
96+
flash_files.extend((str(virtual_efuse_offset), self.app.vefuse_file.as_posix()))
9097
flash_files.extend((str(self.binary_offsets[self.target]), self.app.bootloader_file.as_posix()))
91-
flash_files.extend((str(self.MCUBOOT_PRIMARY_SLOT_OFFSET), self.app.app_file.as_posix()))
98+
flash_files.extend((str(mcuboot_primary_slot_offset), self.app.app_file.as_posix()))
9299
else:
93100
flash_files.extend((str(self.binary_offsets[self.target]), self.app.app_file.as_posix()))
94101

@@ -101,6 +108,11 @@ def flash(self) -> None:
101108
self.flash_freq,
102109
]
103110

111+
print(f'Flash files: {flash_files}')
112+
print(f'Flash settings: {flash_settings}')
113+
print(f'Virtual E-Fuse offset: {hex(virtual_efuse_offset)}')
114+
print(f'MCUBoot primary slot offset: {hex(mcuboot_primary_slot_offset)}')
115+
104116
esptool.main(
105117
[
106118
'--chip',

pytest-embedded-nuttx/tests/test_nuttx.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def test_nuttx_app_mcuboot(dut, app, target):
4848
assert '4MB' == dut.serial.flash_size
4949
assert 'dio' == dut.serial.flash_mode
5050
assert None != app.bootloader_file
51+
assert None == app.vefuse_file
5152
5253
def test_nuttx_app_mcuboot_flash(serial, dut):
5354
serial.erase_flash()
@@ -73,6 +74,47 @@ def test_hello_mcuboot(dut):
7374
result.assert_outcomes(passed=3)
7475

7576

77+
def test_nuttx_app_mcuboot_with_virtual_efuse(testdir):
78+
"""This test takes vefuse.bin in consideration. This is a scenario
79+
where the bootloader is flashed with virtual efuse enabled, which
80+
changes the location in flash for MCUBoot and application.
81+
This was added to NuttX on september 2025.
82+
"""
83+
testdir.makepyfile("""
84+
import pytest
85+
86+
def test_nuttx_app_mcuboot(dut, app, target):
87+
assert 'esp32' == target
88+
assert '40m' == dut.serial.flash_freq
89+
assert '4MB' == dut.serial.flash_size
90+
assert 'dio' == dut.serial.flash_mode
91+
assert None != app.bootloader_file
92+
assert None != app.vefuse_file
93+
94+
def test_nuttx_app_mcuboot_flash(serial, dut):
95+
serial.erase_flash()
96+
serial.flash()
97+
dut.reset_to_nsh()
98+
99+
def test_hello_mcuboot(dut):
100+
dut.reset_to_nsh()
101+
dut.write("ls /dev")
102+
dut.expect("console")
103+
""")
104+
105+
result = testdir.runpytest(
106+
'-s',
107+
'--embedded-services',
108+
'nuttx,esp',
109+
'--target',
110+
'esp32',
111+
'--app-path',
112+
os.path.join(testdir.tmpdir, 'hello_world_nuttx_virtual_efuse'),
113+
)
114+
115+
result.assert_outcomes(passed=3)
116+
117+
76118
qemu_bin_required = pytest.mark.skipif(
77119
shutil.which('qemu-system-xtensa') is None,
78120
reason='Please make sure that `qemu-system-xtensa` is in your PATH env var. Build QEMU for ESP32 locally and then '
1.28 KB
Binary file not shown.
0 Bytes
Binary file not shown.
28.1 KB
Binary file not shown.
1 MB
Binary file not shown.

tests/fixtures/hello_world_nuttx_virtual_efuse/vefuse.bin

Whitespace-only changes.

0 commit comments

Comments
 (0)