From 72be2c7c209e52b41ddd0fb3e2b6c4f430310dc4 Mon Sep 17 00:00:00 2001 From: TOKITA Hiroshi Date: Sat, 7 Jun 2025 00:22:22 +0900 Subject: [PATCH 1/2] pico-sdk: adapt for the sha256 driver to Zephyr Comment out unused DMA-related code and add wrappers to expose internal functions. Signed-off-by: TOKITA Hiroshi --- .../pico_sha256/include/pico/sha256.h | 12 ++++++++++++ src/rp2_common/pico_sha256/sha256.c | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/rp2_common/pico_sha256/include/pico/sha256.h b/src/rp2_common/pico_sha256/include/pico/sha256.h index 80aa5af37..96d2284ca 100644 --- a/src/rp2_common/pico_sha256/include/pico/sha256.h +++ b/src/rp2_common/pico_sha256/include/pico/sha256.h @@ -7,8 +7,10 @@ #ifndef _PICO_SHA256_H #define _PICO_SHA256_H +#if !defined(__ZEPHYR__) #include "pico/time.h" #include "hardware/dma.h" +#endif #include "hardware/sha256.h" /** \file pico/sha256.h @@ -54,10 +56,13 @@ typedef struct pico_sha256_state { uint32_t word; uint8_t bytes[4]; } cache; +#if !defined(__ZEPHYR__) dma_channel_config config; +#endif size_t total_data_size; } pico_sha256_state_t; +#if !defined(__ZEPHYR__) /*! \brief Start a SHA-256 calculation returning immediately with an error if the SHA-256 hardware is not available * \ingroup pico_sha256 * @@ -99,6 +104,7 @@ int pico_sha256_start_blocking_until(pico_sha256_state_t *state, enum sha256_end static inline int pico_sha256_start_blocking(pico_sha256_state_t *state, enum sha256_endianness endianness, bool use_dma) { return pico_sha256_start_blocking_until(state, endianness, use_dma, at_the_end_of_time); } +#endif /*! \brief Add byte data to be SHA-256 calculation * \ingroup pico_sha256 @@ -117,6 +123,7 @@ static inline int pico_sha256_start_blocking(pico_sha256_state_t *state, enum sh */ void pico_sha256_update(pico_sha256_state_t *state, const uint8_t *data, size_t data_size_bytes); +#if !defined(__ZEPHYR__) /*! \brief Add byte data to be SHA-256 calculation * \ingroup pico_sha256 * @@ -142,6 +149,11 @@ void pico_sha256_update_blocking(pico_sha256_state_t *state, const uint8_t *data * @param out The SHA-256 checksum */ void pico_sha256_finish(pico_sha256_state_t *state, sha256_result_t *out); +#endif + +#if defined(__ZEPHYR__) +void pico_sha256_write_padding(pico_sha256_state_t *state); +#endif #ifdef __cplusplus } diff --git a/src/rp2_common/pico_sha256/sha256.c b/src/rp2_common/pico_sha256/sha256.c index e0cc73974..7f2591d8b 100644 --- a/src/rp2_common/pico_sha256/sha256.c +++ b/src/rp2_common/pico_sha256/sha256.c @@ -11,12 +11,15 @@ #include "hardware/sha256.h" #include "pico/bootrom/lock.h" #include "pico/sha256.h" +#if !defined(__ZEPHYR__) #include "pico/time.h" +#endif // We add one 0x80 byte, then 8 bytes for the size #define SHA256_PADDING_DATA_BYTES 9 #define SHA256_BLOCK_SIZE_BYTES 64 +#if !defined(__ZEPHYR__) bool __weak pico_sha256_lock(pico_sha256_state_t *state) { if (!bootrom_try_acquire_lock(BOOTROM_LOCK_SHA_256)) return false; @@ -68,8 +71,10 @@ int pico_sha256_start_blocking_until(pico_sha256_state_t *state, enum sha256_end } while (true); return rc; } +#endif static void write_to_hardware(pico_sha256_state_t *state, const uint8_t *data, size_t data_size_bytes) { +#if !defined(__ZEPHYR__) if (state->channel >= 0) { dma_channel_wait_for_finish_blocking(state->channel); assert(!sha256_err_not_ready()); @@ -83,6 +88,7 @@ static void write_to_hardware(pico_sha256_state_t *state, const uint8_t *data, s true ); } else { +#endif if (!state->cache_used && !(((uintptr_t)data)&3u)) { GCC_Like_Pragma("GCC diagnostic ignored \"-Wcast-align\"") const uint32_t *data32 = (const uint32_t *)data; @@ -103,7 +109,9 @@ static void write_to_hardware(pico_sha256_state_t *state, const uint8_t *data, s sha256_put_word(state->cache.word); } } +#if !defined(__ZEPHYR__) } +#endif } static void update_internal(pico_sha256_state_t *state, const uint8_t *data, size_t data_size_bytes) { @@ -138,12 +146,14 @@ void pico_sha256_update(pico_sha256_state_t *state, const uint8_t *data, size_t update_internal(state, data, data_size_bytes); } +#if !defined(__ZEPHYR__) void pico_sha256_update_blocking(pico_sha256_state_t *state, const uint8_t *data, size_t data_size_bytes) { update_internal(state, data, data_size_bytes); if (state->channel >= 0) { dma_channel_wait_for_finish_blocking(state->channel); } } +#endif // write the SHA-256 padding to hardware static void write_padding(pico_sha256_state_t *state) { @@ -164,6 +174,7 @@ static void write_padding(pico_sha256_state_t *state) { update_internal(state, (uint8_t*)&size, sizeof(uint64_t)); // last write } +#if !defined(__ZEPHYR__) void pico_sha256_finish(pico_sha256_state_t *state, sha256_result_t *out) { assert(state->locked); // pass NULL to abandon the current hash in case of an error @@ -183,3 +194,10 @@ void pico_sha256_finish(pico_sha256_state_t *state, sha256_result_t *out) { } pico_sha256_unlock(state); } +#endif + +#if defined(__ZEPHYR__) +void pico_sha256_write_padding(pico_sha256_state_t *state) { + write_padding(state); +} +#endif From 36cbc9f54382dabe511d7ce764b96478989cd5fe Mon Sep 17 00:00:00 2001 From: TOKITA Hiroshi Date: Sun, 15 Jun 2025 23:56:24 +0900 Subject: [PATCH 2/2] pico-sdk: Update a changelog file about the sha256 adaptation Add a note about the sha256 zephyr adaptation. Signed-off-by: TOKITA Hiroshi --- ChangeLog.zephyr.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ChangeLog.zephyr.md b/ChangeLog.zephyr.md index e15cfbe51..e46aac40f 100644 --- a/ChangeLog.zephyr.md +++ b/ChangeLog.zephyr.md @@ -3,6 +3,9 @@ Need to take care to not break these changes when updating pico-sdk. ## Patch List: + - [#10] pico-sdk: Disabling sanity check the IRQ status + - src/rp2_common/pico_sha256/include/pico/sha256.h + - src/rp2_common/pico_sha256/sha256.c - [#9] pico-sdk: Disabling sanity check the IRQ status - src/rp2_common/hardware_gpio/gpio.c - [#8] pico-sdk: pico_platform_compiler: Do not redefine `__weak`