diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 40bc7a2..d110124 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,52 @@ 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: 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: 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: Checkout + uses: actions/checkout@v4 + with: + path: zephyr-silabs + + - 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: Fetch blobs + working-directory: zephyr-silabs + shell: bash + 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 + 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: | + 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..407f8ea 100644 --- a/.github/workflows/upstream-build.yml +++ b/.github/workflows/upstream-build.yml @@ -36,23 +36,38 @@ 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 Entropy test 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 drivers.entropy -p siwx917_rb4338a -v --inline-logs -K - - name: Build hello world for siwx917_rb4338a + - 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 -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 -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 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