You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
there are such macro definitions in lx_api.h:
...
#define LX_UTILITY_SHORT_SET(address, value) ((USHORT)(address)) = (USHORT)(value)
#define LX_UTILITY_LONG_SET(address, value) ((ULONG)(address)) = (ULONG)(value)
#define LX_UTILITY_SHORT_GET(address) (((USHORT)(address)))
#define LX_UTILITY_LONG_GET(address) (((ULONG)(address)))
in case address is not 4 bytes aligned on LONG_GET/SET, neither 2 bytes aligned on SHORT_GET/SET, you will get wrong value on many platforms such as the ARM platform.
for the universality, we should use SET/GET just as what fx_utility***_read/write did to replace these macros.
btw:
although there are '16' in _fx_utility_16_unsigned_write/read, it's confused that UINT type but not USHORT parameters are used.
the default nand defition is 128MB in lx_nand_flash_simulator.c, however, it's a simulated nand based on RAM, and I guess most systems running LX has less than 128MB RAM, so it's not a friendly settings to the newbies.
Hey @fdesbiens, I was about to open a an issue similar to this but for the RISC-V64 architecture. While OP gets wrong values, on the RISCV, you end up in the trap handler until the board is rebooted, so no recovery in that case. As this issue is still ongoing, I would like to clarify our case.
Looking at the _lx_nand_flash_memory_initialize function, we can see that the variable memory_offset is correctly aligned from the very start as long as lx_nand_flash_bytes_per_page is a common page size as described in the rtos-docs
The sizeof always returns 2 and nand_flash -> lx_nand_flash_total_blocks can have any value based on the size of the partition we give to levelx. In our case it was 127. Then later, the actual lx_nand_flash_page_buffer pointer will have an unaligned address
The current workaround for use as of now is to make sure the lx_nand_flash_bytes_per_page variable is a multiple of 4 in order to get a correctly aligned lx_nand_flash_page_buffer
Hi @jie-ss and @cpdpls. I’m sorry this took so long. I confirmed both alignment faults: the metadata macros access byte buffers through potentially misaligned word pointers, and a 127-block layout can misalign the NAND page buffer. I opened PR #96 to make metadata access safe for unaligned addresses and align the page buffer. The focused regression passed on 32-bit and 64-bit GCC 14 builds; I have not run it on RISC-V64 hardware. I’ll keep this issue open until the PR merges.
On the side questions, FileX’s _fx_utility_16_unsigned_read/write use UINT for the value but access exactly two bytes. The NAND simulator’s default geometry reserves 128 MiB for page data plus spare and bookkeeping storage; lowering TOTAL_BLOCKS reduces that test allocation. A configurable simulator size could be considered separately.
Activity
fdesbiens commentedon Apr 15, 2025
Hi @jie-ss. Thank you for raising this issue. We will discuss it during our weekly meeting later today.
@eclipse-threadx/iot-threadx-committers and @eclipse-threadx/iot-threadx-contributors: Please provide feedback.
cpdpls commentedon Apr 16, 2026
Hey @fdesbiens, I was about to open a an issue similar to this but for the RISC-V64 architecture. While OP gets wrong values, on the RISCV, you end up in the trap handler until the board is rebooted, so no recovery in that case. As this issue is still ongoing, I would like to clarify our case.
Looking at the _lx_nand_flash_memory_initialize function, we can see that the variable
memory_offsetis correctly aligned from the very start as long aslx_nand_flash_bytes_per_pageis a common page size as described in the rtos-docslevelx/common/src/lx_nand_flash_memory_initialize.c
Lines 72 to 110 in a46b74f
The real issue happens right after were
memory_offsetbecomes unaligned.levelx/common/src/lx_nand_flash_memory_initialize.c
Line 141 in a46b74f
The sizeof always returns 2 and
nand_flash -> lx_nand_flash_total_blockscan have any value based on the size of the partition we give to levelx. In our case it was 127. Then later, the actual lx_nand_flash_page_buffer pointer will have an unaligned addresslevelx/common/src/lx_nand_flash_memory_initialize.c
Line 185 in a46b74f
This causes issue because this pointer is used later as an ULONG which causes a trap as I talked about. More specifically here
levelx/common/src/lx_nand_flash_open_extended.c
Lines 157 to 158 in a46b74f
levelx/common/src/lx_nand_flash_open_extended.c
Line 218 in a46b74f
The current workaround for use as of now is to make sure the lx_nand_flash_bytes_per_page variable is a multiple of 4 in order to get a correctly aligned lx_nand_flash_page_buffer
Fixed NAND faults from unaligned metadata and page buffers
fdesbiens commentedon Sep 28, 2026
Hi @jie-ss and @cpdpls. I’m sorry this took so long. I confirmed both alignment faults: the metadata macros access byte buffers through potentially misaligned word pointers, and a 127-block layout can misalign the NAND page buffer. I opened PR #96 to make metadata access safe for unaligned addresses and align the page buffer. The focused regression passed on 32-bit and 64-bit GCC 14 builds; I have not run it on RISC-V64 hardware. I’ll keep this issue open until the PR merges.
On the side questions, FileX’s
_fx_utility_16_unsigned_read/writeuseUINTfor the value but access exactly two bytes. The NAND simulator’s default geometry reserves 128 MiB for page data plus spare and bookkeeping storage; loweringTOTAL_BLOCKSreduces that test allocation. A configurable simulator size could be considered separately.