Skip to content

storage: implement driver for grlib nandfctrl2#643

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

storage: implement driver for grlib nandfctrl2#643
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.

@lukileczo lukileczo requested review from agkaminski and kber-ps March 26, 2026 12:37
@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 introduces a new driver for the GRLIB NANDFCTRL2, significantly expanding the system's storage capabilities by enabling support for NAND flash devices. The implementation provides a robust MTD interface for interacting with the flash, including low-level DMA operations, ECC handling, and bad block management. A comprehensive test suite is also included to ensure the driver's reliability and correctness.

Highlights

  • New Driver Implementation: Implemented a new driver for the GRLIB NANDFCTRL2, enabling support for NAND flash storage devices.
  • MTD Integration: Integrated the NAND flash controller with the existing storage subsystem via the Memory Technology Device (MTD) interface, providing standard flash operations.
  • Comprehensive Test Suite: Included a dedicated test program to thoroughly validate the functionality of the GRLIB NANDFCTRL2 driver, covering various flash operations and error handling.
  • ONFI 4.0 Support: Added support for ONFI 4.0 compliant NAND flash devices, including parameter page parsing and timing configuration.
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.

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.

@gemini-code-assist
Copy link

Warning

Gemini encountered an error creating the review. You can try again by commenting /gemini review.

@lukileczo
Copy link
Member Author

/gemini review

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 controller driver, device interface, and server, along with a dedicated test program. The review highlights several areas for improvement, including a critical bug in flashsrv.c where partition paths are hardcoded to mtd0, which will cause issues with multiple dies. Additionally, there are suggestions to refactor duplicated error handling and resource cleanup code in flashdev.c and flashdrv.c using goto statements for improved readability and maintainability. The review also points out the use of a magic number for interrupt enabling in flashdrv.c that should be replaced with a more descriptive constant, and a type correctness issue in flashsrv.c where strtol is used instead of strtoul for parsing an unsigned integer.

}


int flashdev_init(storage_t *strg, unsigned int target)

Choose a reason for hiding this comment

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

medium

The error handling in this function has a lot of duplicated code for cleaning up allocated resources. This can be made much cleaner and less error-prone by using goto statements for a centralized cleanup path. This is a common and accepted pattern in C for resource management.

For example:

int flashdev_init(storage_t *strg, unsigned int target)
{
	int err = -ENOMEM;

	strg->dev = malloc(sizeof(storage_dev_t));
	if (strg->dev == NULL) {
		return err;
	}

	strg->dev->ctx = malloc(sizeof(storage_devCtx_t));
	if (strg->dev->ctx == NULL) {
		goto err_dev;
	}

	/* ... other allocations ... */

	return 0;

	/* ... cleanup labels ... */
err_ctx:
	free(strg->dev->ctx);
err_dev:
	free(strg->dev);
	strg->dev = NULL;

	return err;
}

}


int flashdrv_init(void)

Choose a reason for hiding this comment

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

medium

This function has a lot of repetitive code in its error handling paths for resource cleanup. This could be refactored using goto for a single cleanup point, which would improve readability and maintainability. This is a common pattern in C for handling resource allocation and deallocation.

@lukileczo lukileczo force-pushed the lukileczo/csat-158 branch from 5da07a1 to 18745d2 Compare March 26, 2026 15:01
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