Skip to content

devices: add flash-nandfctrl2 driver#421

Draft
lukileczo wants to merge 1 commit intomasterfrom
lukileczo/csat-158
Draft

devices: add flash-nandfctrl2 driver#421
lukileczo wants to merge 1 commit intomasterfrom
lukileczo/csat-158

Conversation

@lukileczo
Copy link
Member

YT: CSAT-158

Description

Motivation and Context

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (refactoring, style fixes, git/CI config, submodule management, no code logic changes)

How Has This Been Tested?

  • Already covered by automatic testing.
  • New test added: (add PR link here).
  • Tested by hand on: riscv64-gr765-vcu118

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing linter checks and tests passed.
  • My changes generate no new compilation warnings for any of the targets.

Special treatment

  • This PR needs additional PRs to work (list the PRs, preferably in merge-order).
  • I will merge this PR by myself when appropriate.

@gemini-code-assist
Copy link

Summary of Changes

Hello, 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 delivers a crucial new component: a GRLIB NAND Flash Controller 2 driver. This driver significantly expands the system's storage capabilities by enabling robust and compliant interaction with NAND flash devices. It handles low-level flash operations, bad block management, and adapts to various flash configurations through ONFI 4.0 parameter parsing, ensuring reliable data storage and retrieval for embedded systems.

Highlights

  • New NAND Flash Controller Driver: Introduced a new driver for the GRLIB NAND Flash Controller 2 (NANDFCTRL2), enabling interaction with NAND flash memory.
  • ONFI 4.0 Support: Implemented support for ONFI 4.0 specifications, allowing the driver to dynamically detect and configure flash parameters and timings.
  • Data and Metadata Interfaces: Provided separate interfaces for data (read, write, erase) and metadata (spare area) operations, including block caching and bad block management.
  • Build System and Linker Script Updates: Integrated the new driver into the build system and adjusted linker scripts to accommodate the increased memory footprint.
Changelog
  • devices/flash-nandfctrl2/Makefile
    • Added Makefile for the new flash-nandfctrl2 driver.
  • devices/flash-nandfctrl2/data.c
    • Implemented the data interface for NAND flash, including read, write, erase, and sync operations.
    • Incorporated block caching and bad block handling logic.
  • devices/flash-nandfctrl2/data.h
    • Defined the data interface for the NAND flash controller.
  • devices/flash-nandfctrl2/meta.c
    • Implemented the metadata interface for NAND flash, providing read and write access to spare areas.
  • devices/flash-nandfctrl2/nandfctrl2.c
    • Implemented the core GRLIB NANDFCTRL2 flash driver, managing register access and command execution.
    • Integrated ONFI parameter parsing and timing configuration.
    • Added bad block scanning and marking functionalities.
  • devices/flash-nandfctrl2/nandfctrl2.h
    • Defined structures and public API for the NANDFCTRL2 driver.
  • devices/flash-nandfctrl2/onfi-4.c
    • Implemented ONFI 4.0 parameter page deserialization and timing mode retrieval functions.
  • devices/flash-nandfctrl2/onfi-4.h
    • Defined ONFI 4.0 data structures and related constants.
  • hal/riscv64/gaisler/gr765/Makefile
    • Updated the Makefile to include the new flash-nandfctrl2 device in PLO_ALLDEVICES.
  • ld/riscv64-gr765.ldt
    • Increased SIZE_PLO from 0x40000 to 0x1000000 to accommodate the new driver.
  • riscv-sbi/ld/gr765.ldt
    • Increased SIZE_PAYLOAD from 0x40000 to 0x1000000 to accommodate the new driver.
Activity
  • The pull request introduces a new feature.
  • The changes have been manually tested on riscv64-gr765-vcu118.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@lukileczo lukileczo force-pushed the lukileczo/csat-158 branch from efc4cc0 to 2923ac3 Compare March 17, 2026 12:29
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new GRLIB NANDFCTRL2 flash driver, including data and metadata interfaces, and integrates it into the build system and linker scripts. The changes enable support for NAND flash memory, providing functionalities for reading, writing, erasing, and managing bad blocks. The implementation includes ONFI 4.0 parameter page parsing and timing configuration. Several areas require attention regarding clarity, hardware register documentation, and adherence to configuration best practices for device-specific parameters. Additionally, a critical compilation error was identified in the header file for an undefined struct, and significant memory allocation changes in linker scripts require justification.


totalSparesz = (nand->info.size / nand->info.writesz) * nand->info.spareavail;

if ((offs >= nand->info.size) || (len > totalSparesz) || ((offs % nand->info.writesz) != 0U)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The validation (offs % nand->info.writesz) != 0U implies that offs must be page-aligned. However, the meta_read and meta_write functions are intended to operate on the spare area (metadata). If offs represents an offset within the logical address space of the metadata device, it should be aligned to nand->info.spareavail or some other metadata-specific unit, not nand->info.writesz (which is the data page size). This logic is ambiguous and could lead to incorrect behavior or unexpected validation failures. Please clarify the intended meaning of offs for the metadata device and adjust the validation accordingly.


#define ADDR_DDR 0x10000
#define SIZE_PLO 0x40000
#define SIZE_PLO 0x1000000

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The SIZE_PLO has been significantly increased from 0x40000 to 0x1000000. This is a substantial change in memory allocation for the loader. While it might be necessary for the new NAND driver, such a large increase should be explicitly justified in the pull request description to ensure efficient memory usage and avoid unnecessary resource consumption.


#define ADDR_DDR 0x00000
#define SIZE_SBI 0x10000
#define SIZE_PAYLOAD 0x1000000

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The SIZE_PAYLOAD has been significantly increased from 0x40000 to 0x1000000. Similar to SIZE_PLO, this is a substantial change in memory allocation for the payload. Please provide justification for this large increase to ensure it's necessary and optimized.

@lukileczo lukileczo force-pushed the lukileczo/csat-158 branch from 2923ac3 to 07024fb Compare March 17, 2026 12:57
@github-actions
Copy link

Unit Test Results

9 553 tests   8 961 ✅  53m 27s ⏱️
  591 suites    592 💤
    1 files        0 ❌

Results for commit 07024fb.

@lukileczo lukileczo force-pushed the lukileczo/csat-158 branch from 07024fb to ba9395d Compare March 17, 2026 15:48
@lukileczo lukileczo marked this pull request as draft March 20, 2026 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant