Skip to content

Add support for Raspberry Pi Pico 2 flash controller. #89182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

hanan619
Copy link

The original Pico uses an SSI flash controller, which already has support
in Zephyr. The Pico 2 uses a different QMI flash controller. This PR adds
QMI controller support to Zephyr:

  • Added QMI controller implementation in flash_rpi_pico.c
  • Enabled the flash controller node in rp2350.dtsi

@ajf58
Copy link
Collaborator

ajf58 commented Apr 28, 2025

@hanan619 it looks like you've copied code directly from the Pico SDK. This is not permitted: the Pico SDK is under the BSD 3-Clause, and Zephyr is Apache 2.0

Copy link
Collaborator

@ajf58 ajf58 left a comment

Choose a reason for hiding this comment

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

I'd like to have some clarification about the provenance of the changes before reviewing further.

@hanan619
Copy link
Author

I'd like to have some clarification about the provenance of the changes before reviewing further.

I’d like to point out that the existing RP2040 (Pico1) flash implementation in Zephyr also follows the Pico SDK and includes direct references to its source. My implementation for RP2350 (Pico2) continues this approach for consistency across Raspberry Pi platforms.
Regarding licensing: the Pico SDK is under the BSD-3-Clause license, which is permissive and compatible with Apache 2.0, provided proper attribution is given. Since Zephyr already contains BSD-licensed contributions (such as the RP2040 code), I believe this implementation does not introduce a new licensing concern.
To make this even clearer, I updated the attribution comment in the code to explicitly cite the relevant sources used for RP2350, including:
• pico-bootrom for generic flash logic
• pico-bootrom-rp2350 for RP2350-specific logic
• and the pico-sdk flash code
Given that the RP2040 driver follows this same pattern and was accepted, I believe the same should apply to RP2350.
Please let me know if you would prefer the attribution comment be adjusted further to meet Zephyr’s contribution guidelines more explicitly.

@hanan619 hanan619 force-pushed the rpi_pico2_flash_support branch 8 times, most recently from ad66107 to 8cc9df8 Compare April 29, 2025 06:10
@ajf58
Copy link
Collaborator

ajf58 commented Apr 29, 2025

I’d like to point out that the existing RP2040 (Pico1) flash implementation in Zephyr also follows the Pico SDK and includes direct references to its source.

This https://github.com/zephyrproject-rtos/zephyr/pull/89182/files#diff-5b63ca534e31287da5b9512b307ebf0a52703e12edb4bece40956c0c2bef0b48R2-R3 certainly is a little concerning: Raspberry Pi haven't offered up anything under Apache 2.0 . Re-labelling Raspberry Pi's BSD 3-Clause as Apache 2.0 is not permitted. I'll raise this concern in an issue, and edit this message with a link to it here.

My implementation for RP2350 (Pico2) continues this approach for consistency across Raspberry Pi platforms.

I don't ascribe to a mindset of "everyone else is misbehaving, so I'll misbehave too." I wasn't a reviewer of the previous code, so my focus is brought to this here.

Regarding licensing: the Pico SDK is under the BSD-3-Clause license, which is permissive and compatible with Apache 2.0, provided proper attribution is given.

  1. Proper attribution hasn't been given: clause 1 of the BSD 3 Clause (emphasis mine):

Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

That list of conditions (and/or the reference to the code being released under BSD 3 Clause.

  1. The Zephyr project has its own rules/policies regarding mixing in code released under different licences.

Please let me know if you would prefer the attribution comment be adjusted further to meet Zephyr’s contribution guidelines more explicitly.

Thanks, I think it's best for some of the more experienced reviewers to comment on this. @henrikbrixandersen , I think you've contirbuted feedback on similar licencing terms, would you be able to comment?

Copy link
Collaborator

@kartben kartben left a comment

Choose a reason for hiding this comment

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

From https://docs.zephyrproject.org/latest/contribute/guidelines.html#licensing:
Importing code into the Zephyr OS from other projects that use a license other than the Apache 2.0 license needs to be fully understood in context and approved by the Zephyr governing board.

Can't your contribution just be (your) Zephyr glue code around code being pulled from the pico-sdk zephyr module?

@hanan619
Copy link
Author

hanan619 commented May 6, 2025

Partial writes are not supported in pico-sdk. Therefore someone has added partial_write implementation in zephyr flash for rp2040.
I think we can remove the partial write support for both rp2040 and rp2350 and let the pico-sdk team add proper support in bootrom repo.
There is already an issue raised and work in progress for this task
raspberrypi/pico-sdk#1169

@soburi
Copy link
Member

soburi commented May 14, 2025

@hanan619

It seems that the check was missed in the original code, so we need to consider how to deal with it.

Here, the request is to move the HAL-derived sources to https://github.com/zephyrproject-rtos/hal_rpi_pico rather than https://github.com/raspberrypi/pico-sdk

so there is no problem with putting the zephyr-specific modification, and no required upstreaming.

I think it is possible to move the HAL-derived sources and their modifications from here to

https://github.com/zephyrproject-rtos/hal_rpi_pico/tree/zephyr/src/rp2_common/hardware_flash.

@hanan619 hanan619 force-pushed the rpi_pico2_flash_support branch from 8cc9df8 to 840defa Compare May 19, 2025 09:38
@hanan619
Copy link
Author

the zephyr-specific modification, and n

I have created a PR in hal_rpi_pico for the desired changes.
zephyrproject-rtos/hal_rpi_pico#11

The Raspberry Pi Pico 2 uses a QMI flash controller, which differs from the
SSI controller used in the original Pico. Zephyr already has support for
the SSI controller, but lacked support for QMI.

This change adds the QMI flash controller implementation in the
flash_rpi_pico.c driver file. Additionally, the RP2350 SoC devicetree file
(rp2350.dtsi) has been updated to enable and describe the flash controller
for Pico 2.

Signed-off-by: Hanan Arshad <[email protected]>
@hanan619 hanan619 force-pushed the rpi_pico2_flash_support branch from 840defa to 58c17d3 Compare May 19, 2025 12:05
hanan619 added 2 commits May 19, 2025 17:08
…iables

Cleaned up the flash_rpi_pico driver to improve code readability and
compliance with Zephyr coding standards. Fixed inconsistent indentation
across the file and removed variables that were declared but not used.

A few improvements are credited to Manu3l0us.

Signed-off-by: Hanan Arshad <[email protected]>
…_pico

This commit links the hal_rpi_pico PR required for the flash driver.
west.yml is updated

Signed-off-by: Hanan Arshad <[email protected]>
Copy link

The following west manifest projects have changed revision in this Pull Request:

Name Old Revision New Revision Diff
hal_rpi_pico zephyrproject-rtos/hal_rpi_pico@7b57b24 (zephyr) zephyrproject-rtos/hal_rpi_pico#11 zephyrproject-rtos/hal_rpi_pico#11/files

DNM label due to: 1 project with PR revision

Note: This message is automatically posted and updated by the Manifest GitHub Action.

@hanan619
Copy link
Author

From https://docs.zephyrproject.org/latest/contribute/guidelines.html#licensing: Importing code into the Zephyr OS from other projects that use a license other than the Apache 2.0 license needs to be fully understood in context and approved by the Zephyr governing board.

Can't your contribution just be (your) Zephyr glue code around code being pulled from the pico-sdk zephyr module?

I have updated the PR.
Moved partial write changes to hal_rpi_pico and linked them to zephyr

@github-actions github-actions bot added manifest manifest-hal_rpi_pico DNM (manifest) This PR should not be merged (controlled by action-manifest) labels May 19, 2025
@hanan619 hanan619 requested review from ajf58 and kartben May 19, 2025 12:13
@hanan619
Copy link
Author

Please assign someone to PR zephyrproject-rtos/hal_rpi_pico#11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Flash DNM (manifest) This PR should not be merged (controlled by action-manifest) manifest manifest-hal_rpi_pico platform: Raspberry Pi Pico Raspberry Pi Pico (RPi Pico)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants