Forum Discussion
Mailbox Client HAL API: Erroneous behavior in flash erase boundary checks (Agilex 3 / Nios V)
Hi,
I am currently working on an Agilex 3 platform using the Nios V in Quartus Prime Pro 25.3. I discovered unexpected behavior in the Mailbox Client HAL API when trying to erase 32K blocks of flash.
In the file intel_mailbox_client_flash.c in function mailbox_client_flash_erase_block:
The function receives a dynamic block_size as an argument but ignores it during the boundary check, relying instead on the global dev_info->region_info.block_size.
Because it checks against the maximum hardware block_size (i.e., 64K) instead of the actual block_size parameter passed to the function, it mistakenly blocks legitimate erase commands at the final sectors of the region. Below is the code snippet:
int mailbox_client_flash_erase_block(intel_mailbox_client* fd, int block_offset, int block_size)
{
if(block_offset < 0 ||
block_offset > dev_info->region_info.region_size - dev_info->region_info.block_size ||
(block_offset & (SZ_4K - 1)) != 0)
{
return -EINVAL;
}
}
I suggest changing the boundary check to use the local block_size parameter that was explicitly passed to the function:
if(block_offset < 0 ||
block_offset > dev_info->region_info.region_size - block_size ||
(block_offset & (SZ_4K - 1)) != 0)
{
return -EINVAL;
}
A similar logic flaw exists in the caller function mailbox_client_flash_erase.
The input validation check uses the static hardware block size (dev_info->region_info.block_size) instead of taking the requested length into account.
I suppose this check should prevent out-of-bounds erases in the first place, so checking if there is one 64K block left in the flash is actually pointless.
int mailbox_client_flash_erase(intel_mailbox_client* fd, int offset, int length)
{
if(offset < 0 || offset > dev_info->region_info.region_size - dev_info->region_info.block_size)
{
return -EINVAL;
}
}I suggest using:
if(offset < 0 || offset > dev_info->region_info.region_size - length)
{
return -EINVAL;
}
Any feedback on this behavior would be appreciated.
Thanks!
Thanks for reporting this issue.
We have reviewed the behavior and confirmed it is a software defect in the Mailbox Client HAL flash erase implementation. Under certain conditions, valid erase operations may be incorrectly rejected near the end of a flash region.A fix has been identified and is planned for a future Quartus release.
We appreciate the detailed report and feedback.
4 Replies
- BoonBengT_Altera
Moderator
Dear Customer,
Since clarification has been provided and no further follow‑up questions have been raised, we will assume the issue has been resolved.
This thread will now be transitioned to community support, where other users can continue to assist with any additional inquiries.
For new questions, please feel free to open a fresh thread — we’ll be happy to support you there.
Thank you for being part of the community!
Best regards,
Altera Technical Support
- TienFong_Altera
Occasional Contributor
Thanks for reporting this issue.
We have reviewed the behavior and confirmed it is a software defect in the Mailbox Client HAL flash erase implementation. Under certain conditions, valid erase operations may be incorrectly rejected near the end of a flash region.A fix has been identified and is planned for a future Quartus release.
We appreciate the detailed report and feedback.
- TienFong_Altera
Occasional Contributor
Hi,
Thanks for the detailed analysis and code examples. We are currently reviewing this with the Mailbox Client HAL owners and will update this thread once we have more information.
Regards,
Tien Fong - ai_responder
Community Manager
Thank you for your inquiry. To ensure an accurate response, your request has been routed to an Altera application engineer for further review and assistance.
Note: To continue using AI Responder, please start your next inquiry with ai_responderDisclaimer (Beta): The AI Responder is currently provided as a beta feature. AI-generated responses may contain errors or omissions. Please verify technical guidance with official Altera documentation before implementation.
Thank you very much.