-
Notifications
You must be signed in to change notification settings - Fork 7.6k
drivers: crypto: Add initial support for rpi_pico sha256 accelerator #85036
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
base: main
Are you sure you want to change the base?
Conversation
0d6e6b8
to
a2b3bb7
Compare
a2b3bb7
to
19c04b7
Compare
@ceolin @valeriosetti @ThreeEights Could you take a look if you have a bit of a while? |
There was a problem hiding this 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorting - good idea!
There was a problem hiding this comment.
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.
There was a problem hiding this 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
a6aeaeb
to
f2ca146
Compare
Could you take a look at it? |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
To be clear here. Changing an existing license declaration on a file can only be done by permission of all of the contributing authors. Changing license declarations is much worse than bringing in the files with the licenses on them (and figuring out what needs to happen to use the code under the license the authors released the code under). The license lines in the file are an indication, from the author, of the terms that they allow their code to be used under them. Removing those declarations is in bad-faith, and is something we have to be very careful never happens to code in this project. |
This was discussed in the TSC and it was agreed that we will not accept non original, Apache licensed code for this type of driver. Please use another method of integration. |
Agreed. There have been a few PRs recently where we need them to stay Apache 2.0. I think the best way to do this is in the HAL, which is where several of them originate from. I don't think there's much of a convention across the different vendor HALs here, but I'll take a look. |
Add `zephyr-keep-sorted` and reorder file entries alphabetically. Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
Update hal_rpi_pico to introduce the Zephyr adaptation for the sha256 driver. Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
Add include paths and source files for the sha256 driver when enabled `CONFIG_PICOSDK_USE_SHA256` config. Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
The following west manifest projects have changed revision in this Pull Request:
⛔ DNM label due to: 1 project with PR revision Note: This message is automatically posted and updated by the Manifest GitHub Action. |
Add a public interface to the hal side and change the policy to use it. |
{ | ||
struct rpi_pico_sha256_data *data = dev->data; | ||
|
||
assert(!data->state.locked); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't assert()
a bit too strong here? I suggest adding a mutex in struct rpi_pico_sha256_data
and use it here:
- lock the mutex
- check
data->state.locked
and return if already set (releasing the mutex, of course before returning) - set
data->state.locked
(not on line 79 as it is done now) - unlock the mutex
- remember to unset
data->state.locked
inrpi_pico_sha256_hash_session_free()
In this way you can have 2 threads willing to use the hash driver at the same time and then the one that comes later will just wait for the resource to be free.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The response has become slower.
It's true that assert is quite powerful, so I have modified it.
Your suggestion was to use a mutex, but the exclusive section completes in an extremely short time, so I implemented it using a spinlock.
ed7b1d2
to
43bbff2
Compare
Add basic support for RaspberryPi Pico's SHA256 hardware accelerator. Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
Added sha256 accelerator to rpi_pico. Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
Add rpi_pico2 to the crypto_hash test target. Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
|
Add basic support for RaspberryPi Pico's SHA256 hardware accelerator.