STM32N6: improvements to XSPI driver, add support for userspace storage driver#418
Conversation
Fix incorrect offset for register access. JIRA: RTOS-1084
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the STM32N6 XSPI driver by laying the groundwork for userspace Flash storage driver implementation. It achieves this by introducing a mechanism to export detailed XSPI chip configuration into a syspage blob, allowing userspace applications to seamlessly interact with the Flash memory. This approach bypasses the complexities of re-initialization and synchronization between kernel and userspace. Additionally, the changes incorporate DMA-driven memory copy capabilities for more efficient Flash write operations and refine D-Cache management for better performance and control. Highlights
Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces several valuable improvements to the STM32N6 XSPI driver, including DMA support for memory-mapped writes, exporting flash configuration to userspace via syspage, and refactoring cache management functions. A medium-severity vulnerability was identified in the cache maintenance code, which could lead to undefined behavior, data corruption, or denial of service. Furthermore, a potential issue in the new DMA functionality could also lead to undefined behavior, and it is suggested to replace a hardcoded device-specific timeout with a configurable value for improved robustness, aligning with repository guidelines for device-specific parameters.
Refactor cache operations to unify common code. Use line size from CCSIDR register instead of hardcoded size. JIRA: RTOS-1084
Change Flash writing procedure from using indirect mode to using memory-mapped mode in preparation for memory encryption using MCE. Add simple driver for GPDMA peripheral to perform memory-to-memory copying. JIRA: RTOS-1084
6390981 to
a1482c4
Compare
Allow userspace driver to access Flash configuration parameters easily through a blob in syspage. JIRA: RTOS-1216
a1482c4 to
690f5ae
Compare
Description
This PR contains some commits from #417 - I wanted to separate the ones required for the userspace storage driver (needed ASAP) from the ones required for secure boot and encryption (can wait longer for approval). This includes infrastructure for writing to Flash in memory-mapped mode.
In order to support the userspace XSPI storage driver, the PLO driver now exports its configuration to a blob in syspage which can then be read by the userspace driver. The userspace driver then doesn't need to reset or re-initialize the chip and can issue read/write/erase operations right away. After considering multiple options I decided this is the best way.
Alternatives would be:
The userspace driver could reset and re-initialize the chip from scratch.
This would be problematic, especially on
nucleoboard which doesn't have a GPIO pin tied to Flash reset.We cannot reset Flash as we exit PLO, as this would prevent kernel from accessing it during boot.
In order to issue a soft-reset command in userspace driver, the PLO driver would need to pass information how to do it - causing the same problem again.
It would also require more copy-pasting of code between the PLO driver and userspace driver (which I wanted to avoid). The userspace code would need to contain chip identification and SFDP parser code which would need to be kept in sync with the PLO version, which would be a huge pain.
The PLO driver could pass data through
hal_syspage_tThis would be the more conventional method. It would require changes that would need to be kept in sync between PLO, kernel and userspace, as well as creation of dedicated
platformctloperation - I wanted to avoid this.The method of passing the blob has another advantage - the blob can be overridden by one supplied by user script. This means that potentially support of a chip could be upgraded without having to upgrade PLO.
Comments on what could be added to the
xspi_chipSetup_v1structure are welcome. The data it includes is sufficient for now, but it would be nice to make it more future-proof.Depends-On: phoenix-rtos-kernel:jmaksymowicz/stm32-flashcs
Motivation and Context
Allow userspace Flash storage driver to be implemented.
Types of changes
How Has This Been Tested?
Checklist:
Special treatment