From 39619e33bbceb7c3f116dfafb759a3a81523f720 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Pouiller?= Date: Tue, 22 Oct 2024 13:34:02 +0200 Subject: [PATCH 1/4] drivers: entropy: Introduce driver for SiWx917 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Support for random number generator is required for most of the cryptographic operations, including support for WiFi and TLS. This driver has been tested with tests/drivers/entropy: *** Booting Zephyr OS build v3.7.0-4339-g1ec5ce05f9f8 *** Running TESTSUITE entropy_api =================================================================== START - test_entropy_get_entropy random device is 0x8217298, name is rng@45090000 0x93 0x3e 0xf1 0x68 0xd4 0x22 0xbf 0x4d 0xad PASS - test_entropy_get_entropy in 0.012 seconds =================================================================== TESTSUITE entropy_api succeeded ------ TESTSUITE SUMMARY START ------ SUITE PASS - 100.00% [entropy_api]: pass = 1, fail = 0, skip = 0 ... - PASS - [entropy_api.test_entropy_get_entropy] duration = 0.01 ... ------ TESTSUITE SUMMARY END ------ =================================================================== RunID: d1547c805699201af769cb01331efcce PROJECT EXECUTION SUCCESSFUL Co-authored-by: Tibor Laczko Signed-off-by: Tibor Laczko Signed-off-by: Jérôme Pouiller --- drivers/CMakeLists.txt | 1 + drivers/entropy/CMakeLists.txt | 5 ++ drivers/entropy/Kconfig | 8 ++++ drivers/entropy/Kconfig.siwx917 | 11 +++++ drivers/entropy/entropy_silabs_siwx917.c | 61 ++++++++++++++++++++++++ dts/arm/silabs/siwg917.dtsi | 9 ++++ dts/bindings/rng/silabs,siwx917-rng.yaml | 12 +++++ west.yml | 2 +- 8 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 drivers/entropy/CMakeLists.txt create mode 100644 drivers/entropy/Kconfig create mode 100644 drivers/entropy/Kconfig.siwx917 create mode 100644 drivers/entropy/entropy_silabs_siwx917.c create mode 100644 dts/bindings/rng/silabs,siwx917-rng.yaml diff --git a/drivers/CMakeLists.txt b/drivers/CMakeLists.txt index 1e2076c..bd9e4f9 100644 --- a/drivers/CMakeLists.txt +++ b/drivers/CMakeLists.txt @@ -2,6 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 add_subdirectory(bluetooth) +add_subdirectory(entropy) add_subdirectory(gpio) add_subdirectory(pinctrl) add_subdirectory(wifi) diff --git a/drivers/entropy/CMakeLists.txt b/drivers/entropy/CMakeLists.txt new file mode 100644 index 0000000..48e46a0 --- /dev/null +++ b/drivers/entropy/CMakeLists.txt @@ -0,0 +1,5 @@ +# Copyright (c) 2024 Silicon Laboratories Inc. +# SPDX-License-Identifier: Apache-2.0 + +zephyr_library_amend() +zephyr_library_sources_ifdef(CONFIG_ENTROPY_SILABS_SIWX917 entropy_silabs_siwx917.c) diff --git a/drivers/entropy/Kconfig b/drivers/entropy/Kconfig new file mode 100644 index 0000000..af8fb97 --- /dev/null +++ b/drivers/entropy/Kconfig @@ -0,0 +1,8 @@ +# Copyright (c) 2024 Silicon Laboratories Inc. +# SPDX-License-Identifier: Apache-2.0 + +if ENTROPY_GENERATOR + +rsource "Kconfig.siwx917" + +endif diff --git a/drivers/entropy/Kconfig.siwx917 b/drivers/entropy/Kconfig.siwx917 new file mode 100644 index 0000000..fc694b8 --- /dev/null +++ b/drivers/entropy/Kconfig.siwx917 @@ -0,0 +1,11 @@ +# Copyright (c) 2024 Silicon Laboratories Inc. +# SPDX-License-Identifier: Apache-2.0 + +config ENTROPY_SILABS_SIWX917 + bool "SiWx917 RNG driver" + default y + depends on DT_HAS_SILABS_SIWX917_RNG_ENABLED + select ENTROPY_HAS_DRIVER + help + Enable hardware Random Number Generator embedded on Silicon Labs + SiWx917 chips. diff --git a/drivers/entropy/entropy_silabs_siwx917.c b/drivers/entropy/entropy_silabs_siwx917.c new file mode 100644 index 0000000..5487782 --- /dev/null +++ b/drivers/entropy/entropy_silabs_siwx917.c @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2024 Silicon Laboratories Inc. + * SPDX-License-Identifier: Apache-2.0 + */ +#define DT_DRV_COMPAT silabs_siwx917_rng + +#include + +#include "rsi_rom_rng.h" +#include "rsi_rom_clks.h" + +static int siwx917_get_entropy_isr(const struct device *dev, uint8_t *buffer, + uint16_t length, uint32_t flags) +{ + uint32_t u32_count = length / sizeof(uint32_t); + uint32_t u8_count = u32_count * sizeof(uint32_t); + uint32_t u8_remainder = length - u8_count; + uint32_t swap_space; + + if (!(flags & ENTROPY_BUSYWAIT)) { + return -ENOTSUP; + } + RSI_RNG_GetBytes((void *)dev->config, (uint32_t *)buffer, u32_count); + if (length % sizeof(uint32_t)) { + RSI_RNG_GetBytes((void *)dev->config, &swap_space, 1); + memcpy(buffer + u8_count, &swap_space, u8_remainder); + } + + return 0; +} + +static int siwx917_get_entropy(const struct device *dev, uint8_t *buffer, uint16_t length) +{ + return siwx917_get_entropy_isr(dev, buffer, length, ENTROPY_BUSYWAIT); +} + +static int siwx917_init(const struct device *dev) +{ + int ret; + + ret = RSI_CLK_PeripheralClkEnable1(M4CLK, HWRNG_PCLK_ENABLE); + if (ret) { + return -EIO; + } + ret = RSI_RNG_Start((void *)dev->config, RSI_RNG_TRUE_RANDOM); + if (ret) { + return -EIO; + } + return 0; +} + +static const struct entropy_driver_api siwx917_api = { + .get_entropy = siwx917_get_entropy, + .get_entropy_isr = siwx917_get_entropy_isr, +}; + +#define SIWX917_RNG_INIT(idx) \ + DEVICE_DT_INST_DEFINE(idx, siwx917_init, NULL, NULL, (void *)DT_INST_REG_ADDR(idx), \ + PRE_KERNEL_1, CONFIG_ENTROPY_INIT_PRIORITY, &siwx917_api); + +DT_INST_FOREACH_STATUS_OKAY(SIWX917_RNG_INIT) diff --git a/dts/arm/silabs/siwg917.dtsi b/dts/arm/silabs/siwg917.dtsi index 593adb1..388b1bd 100644 --- a/dts/arm/silabs/siwg917.dtsi +++ b/dts/arm/silabs/siwg917.dtsi @@ -9,6 +9,10 @@ #include / { + chosen { + zephyr,entropy = &rng0; + }; + cpus { #address-cells = <1>; #size-cells = <0>; @@ -202,6 +206,11 @@ interrupt-names = "i2c2"; status = "disabled"; }; + + rng0: rng@45090000 { + compatible = "silabs,siwx917-rng"; + reg = <0x45090000 0x8>; + }; }; }; diff --git a/dts/bindings/rng/silabs,siwx917-rng.yaml b/dts/bindings/rng/silabs,siwx917-rng.yaml new file mode 100644 index 0000000..8ef9141 --- /dev/null +++ b/dts/bindings/rng/silabs,siwx917-rng.yaml @@ -0,0 +1,12 @@ +# Copyright (c) 2024 Silicon Laboratories Inc. +# SPDX-License-Identifier: Apache-2.0 + +description: Hardware Random Number Generator embedded on Silabs SiWx917 chips + +compatible: "silabs,siwx917-rng" + +include: base.yaml + +properties: + reg: + required: true diff --git a/west.yml b/west.yml index c9b3ef8..a9196d1 100644 --- a/west.yml +++ b/west.yml @@ -11,7 +11,7 @@ manifest: projects: - name: hal_silabs remote: silabs - revision: 2eb82930b376900f1b6949e218199ab33ba6f34c + revision: ca720524a33c4bb55446ceb7e94502e37153d941 path: modules/hal/silabs - name: zephyr remote: zephyrproject-rtos From 9527bef43d82db3425142fdb328afa935c1ed14e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Pouiller?= Date: Thu, 10 Oct 2024 17:02:14 +0200 Subject: [PATCH 2/4] github: workflows: Use same level of indentation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change indentation level of build.yml to match upstream-build.yml. Signed-off-by: Jérôme Pouiller --- .github/workflows/build.yml | 62 ++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 40bc7a2..0e6becc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,10 +3,10 @@ name: Build on: pull_request: types: - - edited - - opened - - reopened - - synchronize + - edited + - opened + - reopened + - synchronize jobs: build: @@ -16,34 +16,34 @@ jobs: os: [ubuntu-22.04, macos-14, windows-2022] runs-on: ${{ matrix.os }} steps: - - name: Checkout - uses: actions/checkout@v4 - with: - path: zephyr-silabs + - name: Checkout + uses: actions/checkout@v4 + with: + path: zephyr-silabs - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: 3.11 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: 3.11 - - name: Setup Zephyr project - uses: zephyrproject-rtos/action-zephyr-setup@v1 - with: - app-path: zephyr-silabs - toolchains: arm-zephyr-eabi + - name: Setup Zephyr project + uses: zephyrproject-rtos/action-zephyr-setup@v1 + with: + app-path: zephyr-silabs + toolchains: arm-zephyr-eabi - - name: Fetch blobs - run: | - west blobs fetch hal_silabs + - name: Fetch blobs + run: | + west blobs fetch hal_silabs - - name: Build hello world - working-directory: zephyr-silabs - shell: bash - run: | - if [ "${{ runner.os }}" = "Windows" ]; then - EXTRA_TWISTER_FLAGS="--short-build-path -O/tmp/twister-out" - fi - west twister --test sample.basic.helloworld -p siwx917_rb4338a -v --inline-logs $EXTRA_TWISTER_FLAGS - west twister --test sample.net.wifi -p siwx917_rb4338a -v --inline-logs -K $EXTRA_TWISTER_FLAGS - west twister --test sample.bluetooth.peripheral_hr -p siwx917_rb4338a -v --inline-logs -K $EXTRA_TWISTER_FLAGS - west twister --test sample.rail.simple_txrx -T samples -v --inline-logs $EXTRA_TWISTER_FLAGS + - name: Build hello world + working-directory: zephyr-silabs + shell: bash + run: | + if [ "${{ runner.os }}" = "Windows" ]; then + EXTRA_TWISTER_FLAGS="--short-build-path -O/tmp/twister-out" + fi + west twister --test sample.basic.helloworld -p siwx917_rb4338a -v --inline-logs $EXTRA_TWISTER_FLAGS + west twister --test sample.net.wifi -p siwx917_rb4338a -v --inline-logs -K $EXTRA_TWISTER_FLAGS + west twister --test sample.bluetooth.peripheral_hr -p siwx917_rb4338a -v --inline-logs -K $EXTRA_TWISTER_FLAGS + west twister --test sample.rail.simple_txrx -T samples -v --inline-logs $EXTRA_TWISTER_FLAGS From 35dd707b5dd0a4022fbc37ebf06d49c00f37dc69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Pouiller?= Date: Thu, 10 Oct 2024 17:11:46 +0200 Subject: [PATCH 3/4] github: workflows: Align invocations of twister MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit upstream-build.yml and build.yml didn't invoke twister in the same nor with the same tests. Note $EXTRA_TWISTER_FLAGS was used in all the tests. Yet, CI still runs on Windows. So, this commit get rid of EXTRA_TWISTER_FLAGS in all the invocations. Signed-off-by: Jérôme Pouiller --- .github/workflows/build.yml | 27 +++++++++++++++++++-------- .github/workflows/upstream-build.yml | 28 ++++++++++++++++++---------- 2 files changed, 37 insertions(+), 18 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0e6becc..113873f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -33,17 +33,28 @@ jobs: toolchains: arm-zephyr-eabi - name: Fetch blobs + working-directory: zephyr-silabs + shell: bash run: | west blobs fetch hal_silabs - - name: Build hello world + - name: Build Bluetooth samples + continue-on-error: true + working-directory: zephyr-silabs + shell: bash + run: | + west twister -s sample.bluetooth.peripheral_hr -p siwx917_rb4338a -v --inline-logs -K + + - name: Build Rail samples + continue-on-error: true + working-directory: zephyr-silabs + shell: bash + run: | + west twister -s sample.rail.simple_txrx -T samples -v --inline-logs + + - name: Build Wifi samples + continue-on-error: true working-directory: zephyr-silabs shell: bash run: | - if [ "${{ runner.os }}" = "Windows" ]; then - EXTRA_TWISTER_FLAGS="--short-build-path -O/tmp/twister-out" - fi - west twister --test sample.basic.helloworld -p siwx917_rb4338a -v --inline-logs $EXTRA_TWISTER_FLAGS - west twister --test sample.net.wifi -p siwx917_rb4338a -v --inline-logs -K $EXTRA_TWISTER_FLAGS - west twister --test sample.bluetooth.peripheral_hr -p siwx917_rb4338a -v --inline-logs -K $EXTRA_TWISTER_FLAGS - west twister --test sample.rail.simple_txrx -T samples -v --inline-logs $EXTRA_TWISTER_FLAGS + west twister -s sample.net.wifi -p siwx917_rb4338a -v --inline-logs -K diff --git a/.github/workflows/upstream-build.yml b/.github/workflows/upstream-build.yml index 7d6aa96..8477a4e 100644 --- a/.github/workflows/upstream-build.yml +++ b/.github/workflows/upstream-build.yml @@ -36,23 +36,31 @@ jobs: sed s/$Z_REV/main/ west.yml > west.yml.new mv west.yml.new west.yml west update + + - name: Fetch blobs + working-directory: zephyr-silabs + shell: bash + run: | west blobs fetch hal_silabs - - name: Build Bluetooth sample for xG27 + - name: Build Bluetooth samples + continue-on-error: true + working-directory: zephyr-silabs + shell: bash + run: | + west twister -s sample.bluetooth.peripheral_hr -p xg27_dk2602a -v --inline-logs -K + west twister -s sample.bluetooth.peripheral_hr -p siwx917_rb4338a -v --inline-logs -K + + - name: Build Rail samples continue-on-error: true working-directory: zephyr-silabs shell: bash run: | - west twister -K -p xg27_dk2602a --test sample.bluetooth.peripheral_hr + west twister -s sample.rail.simple_txrx -T samples -v --inline-logs - - name: Build hello world for siwx917_rb4338a + - name: Build Wifi samples + continue-on-error: true working-directory: zephyr-silabs shell: bash run: | - if [ "${{ runner.os }}" = "Windows" ]; then - EXTRA_TWISTER_FLAGS="--short-build-path -O/tmp/twister-out" - fi - west twister -T ../zephyr/samples -s sample.basic.helloworld -p siwx917_rb4338a -v --inline-logs $EXTRA_TWISTER_FLAGS - west twister -T ../zephyr/samples -s sample.net.wifi -p siwx917_rb4338a -v --inline-logs -K $EXTRA_TWISTER_FLAGS - west twister -T ../zephyr/samples -s sample.bluetooth.peripheral_hr -p siwx917_rb4338a -v --inline-logs -K $EXTRA_TWISTER_FLAGS - west twister -T samples -s sample.rail.simple_txrx -v --inline-logs $EXTRA_TWISTER_FLAGS + west twister -s sample.net.wifi -p siwx917_rb4338a -v --inline-logs -K From 47e8a59bd07ec25b55cbd464f72b95deb4605c49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Pouiller?= Date: Tue, 22 Oct 2024 13:39:37 +0200 Subject: [PATCH 4/4] github: workflows: Add test for RNG driver MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It makes sense to check we don't break the entropy driver. Signed-off-by: Jérôme Pouiller --- .github/workflows/build.yml | 7 +++++++ .github/workflows/upstream-build.yml | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 113873f..d110124 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -38,6 +38,13 @@ jobs: run: | west blobs fetch hal_silabs + - name: Build Entropy test + continue-on-error: true + working-directory: zephyr-silabs + shell: bash + run: | + west twister -s drivers.entropy -p siwx917_rb4338a -v --inline-logs + - name: Build Bluetooth samples continue-on-error: true working-directory: zephyr-silabs diff --git a/.github/workflows/upstream-build.yml b/.github/workflows/upstream-build.yml index 8477a4e..407f8ea 100644 --- a/.github/workflows/upstream-build.yml +++ b/.github/workflows/upstream-build.yml @@ -43,6 +43,13 @@ jobs: run: | west blobs fetch hal_silabs + - name: Build Entropy test + continue-on-error: true + working-directory: zephyr-silabs + shell: bash + run: | + west twister -s drivers.entropy -p siwx917_rb4338a -v --inline-logs -K + - name: Build Bluetooth samples continue-on-error: true working-directory: zephyr-silabs