Skip to content

Conversation

soburi
Copy link
Member

@soburi soburi commented Feb 3, 2025

Add basic support for RaspberryPi Pico's SHA256 hardware accelerator.

@soburi soburi marked this pull request as draft February 3, 2025 01:49
@soburi soburi added the DNM This PR should not be merged (Do Not Merge) label Feb 3, 2025
@soburi soburi marked this pull request as ready for review February 3, 2025 04:02
@valeriosetti valeriosetti self-requested a review February 10, 2025 08:31
@soburi soburi removed the DNM This PR should not be merged (Do Not Merge) label Feb 11, 2025
@soburi
Copy link
Member Author

soburi commented Feb 14, 2025

@ceolin @valeriosetti @ThreeEights

Could you take a look if you have a bit of a while?

Copy link
Contributor

@valeriosetti valeriosetti left a comment

Choose a reason for hiding this comment

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

The PR looks OK to me. I cannot test it locally because I don't have a board at hand, but at least the test that was extended builds correctly. I only left one minor non-blocking question/comment.

zephyr_library_sources_ifdef(CONFIG_CRYPTO_SMARTBOND crypto_smartbond.c)
zephyr_library_sources_ifdef(CONFIG_CRYPTO_STM32 crypto_stm32.c)
zephyr_library_sources_ifdef(CONFIG_CRYPTO_TINYCRYPT_SHIM crypto_tc_shim.c)
# zephyr-keep-sorted-stop
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorting - good idea!

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I'd prefer it if the sorting is one commit, and the addition is a separate commit. The end result is the same, but it's easier to to see the two orthogonal things going on.

Copy link
Contributor

@valeriosetti valeriosetti left a comment

Choose a reason for hiding this comment

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

Thanks for addressing previous comment. However reviewing the PR again I found a couple of new ones that I missed before. Sorry

@soburi soburi force-pushed the rpi_pico_sha256 branch 2 times, most recently from a6aeaeb to f2ca146 Compare March 10, 2025 22:42
@soburi soburi requested a review from valeriosetti March 11, 2025 05:36
valeriosetti
valeriosetti previously approved these changes Mar 14, 2025
@soburi
Copy link
Member Author

soburi commented Mar 17, 2025

@ceolin @ThreeEights @ajf58

Could you take a look at it?

Copy link
Contributor

@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.

The change looks functionally good, but I am concerned about the outright copy and paste of BSD code, then relabeling it as Apache 2.

I feel like someone else needs to comment on this.

zephyr_library_sources_ifdef(CONFIG_CRYPTO_SMARTBOND crypto_smartbond.c)
zephyr_library_sources_ifdef(CONFIG_CRYPTO_STM32 crypto_stm32.c)
zephyr_library_sources_ifdef(CONFIG_CRYPTO_TINYCRYPT_SHIM crypto_tc_shim.c)
# zephyr-keep-sorted-stop
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I'd prefer it if the sorting is one commit, and the addition is a separate commit. The end result is the same, but it's easier to to see the two orthogonal things going on.

LOG_MODULE_REGISTER(sha_rpi_pico_sha256, CONFIG_CRYPTO_LOG_LEVEL);

/*
* This is based on the pico_sha256 implementation in the Pico-SDK.
Copy link
Contributor

Choose a reason for hiding this comment

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

Original code is a https://github.com/raspberrypi/pico-sdk/blob/2.1.0/src/rp2_common/pico_sha256/sha256.c , it's 3-Clause BSD (BSD-3-Clause).

I feel like this file has lifted-and-shifted too much for someone to ignore (many lines of code are the same, just formatted to meet the Zephyr Project's coding style).

I'd be happy if this file had a BSD-3-Clause on it. Zephyr must be compatible with this, we link against BSD-3-Clause all over the place. It's not easy t osee examples of that, however.

Alternatively, we could modify the version of the source code in the hal_rpi_pico. This is something I prefer to avoid, but that feels better at ensuring the software licence is upheld.

Copy link
Member Author

Choose a reason for hiding this comment

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

The codes derived from pico-sdk were separated into crypto_rpi_pico_sha256.h, and the license changed to BSD-3.

Copy link
Member Author

Choose a reason for hiding this comment

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

nit: I'd prefer it if the sorting is one commit, and the addition is a separate commit. The end result is the same, but it's easier to to see the two orthogonal things going on.

Addressed.

@soburi soburi force-pushed the rpi_pico_sha256 branch 4 times, most recently from 6b6de83 to e568f8c Compare September 21, 2025 10:37
zephyr_library_sources_ifdef(CONFIG_CRYPTO_ATAES132A crypto_ataes132a.c)
zephyr_library_sources_ifdef(CONFIG_CRYPTO_CC23X0 crypto_cc23x0.c)
zephyr_library_sources_ifdef(CONFIG_CRYPTO_INTEL_SHA crypto_intel_sha.c)
zephyr_library_sources_ifdef(CONFIG_CRYPTO_IT51XXX_SHA crypto_it51xxx_sha.c)
Copy link
Member

Choose a reason for hiding this comment

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

Despite all other entries being transitioned to uniform space indentation, this remains tabs

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

zephyr_library_sources_ifdef(CONFIG_CRYPTO_SI32 crypto_si32.c)
zephyr_library_sources_ifdef(CONFIG_CRYPTO_SMARTBOND crypto_smartbond.c)
zephyr_library_sources_ifdef(CONFIG_CRYPTO_STM32 crypto_stm32.c)
zephyr_library_sources_ifdef(CONFIG_CRYPTO_STM32_HASH crypto_stm32_hash.c)
Copy link
Member

Choose a reason for hiding this comment

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

Could this also be converted to spaces for alignment?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

# SPDX-License-Identifier: Apache-2.0

config CRYPTO_RPI_PICO_SHA256
bool "RasberryPi Pico SHA256 Accelerator driver"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
bool "RasberryPi Pico SHA256 Accelerator driver"
bool "Raspberry Pi Pico SHA256 Accelerator driver"

or maybe even like this, as Pico is a board and the driver is for SoC. It's opinionated though, feel free to reject:

Suggested change
bool "RasberryPi Pico SHA256 Accelerator driver"
bool "Raspberry Pi microcontrollers SHA256 Accelerator driver"

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

depends on DT_HAS_RASPBERRYPI_PICO_SHA256_ENABLED
select PICOSDK_USE_SHA256
help
RaspberryPi Pico SHA256 accelarator driver.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
RaspberryPi Pico SHA256 accelarator driver.
Raspberry Pi Pico SHA256 accelarator driver.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.


static int crypto_rpi_pico_sha256_query_hw_caps(const struct device *dev)
{
return (CAP_SEPARATE_IO_BUFS | CAP_SYNC_OPS);
Copy link
Member

Choose a reason for hiding this comment

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

personal opinion: readability would be better without parentheses:

Suggested change
return (CAP_SEPARATE_IO_BUFS | CAP_SYNC_OPS);
return CAP_SEPARATE_IO_BUFS | CAP_SYNC_OPS;

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

@zephyrbot zephyrbot added area: Devicetree Bindings area: Tests Issues related to a particular existing or missing test area: Boards/SoCs labels Oct 13, 2025
@zephyrbot zephyrbot requested a review from nashif October 13, 2025 06:40
@zephyrbot zephyrbot added the area: Samples Samples label Oct 13, 2025
@soburi soburi force-pushed the rpi_pico_sha256 branch 2 times, most recently from 19ad0c7 to a577c96 Compare October 14, 2025 20:42
By the recent SDK update, compilation will fail if
`pico_platform_common` is not added to the include path,
so that we fix this.

Signed-off-by: TOKITA Hiroshi <[email protected]>
Update hal_rpi_pico to commit 09e9575 to introduce hardware sha256.

Signed-off-by: TOKITA Hiroshi <[email protected]>
Add `zephyr-keep-sorted` and reorder file entries alphabetically.

Signed-off-by: TOKITA Hiroshi <[email protected]>
Add `hardware_sha256/include` to `zephyr_include_directories`.
Use the header only.

Signed-off-by: TOKITA Hiroshi <[email protected]>
Add basic support for RaspberryPi Pico's SHA256 hardware accelerator.

Signed-off-by: TOKITA Hiroshi <[email protected]>
Added sha256 accelerator to rpi_pico.

Signed-off-by: TOKITA Hiroshi <[email protected]>
Add rpi_pico2 to the crypto_hash test target.

Signed-off-by: TOKITA Hiroshi <[email protected]>
Copy link

@soburi
Copy link
Member Author

soburi commented Oct 14, 2025

@valeriosetti @dsseng @ajf58

Could you revisit? I would like to include this in v4.3.0 if we can meet the deadline.

sha256_set_bswap(true);
sha256_start();

pico_sha256_update(&data->state, pkt->in_buf, pkt->in_len);
Copy link
Member

Choose a reason for hiding this comment

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

Are there limits on the input size by the HAL? If so, please test for them to return EINVAL

Copy link
Member

Choose a reason for hiding this comment

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

Does this also work on Hazard3 as it's merged now? Cannot test right now, sorry, but interested whether or not bootrom call works fine, as those are somewhat interesting on RISC-V mode due to emulation being involved and may require application/RTOS to allocate a stack for BootROM emulator in some cases

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

9 participants