Skip to content

Commit d189e7e

Browse files
committed
Merge pull request #2367 from pguyot/w29/stm32-optional-mbedtls
stm32: allow excluding mbedTLS to fit flash-constrained stm32g474ret6 These changes are made under both the "Apache 2.0" and the "GNU Lesser General Public License 2.1 or later" license terms (dual license). SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
2 parents 1d7fb2e + 838be84 commit d189e7e

3 files changed

Lines changed: 17 additions & 1 deletion

File tree

.github/workflows/stm32-build.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ jobs:
9898
tests: "boot gpio i2c spi crypto uart"
9999
- device: stm32g474ret6
100100
max_size: 393216
101+
# 384 KB flash: exclude mbedTLS/crypto (~38 KB) to fit the whole
102+
# firmware. G474 has an RNG, so crypto is opt-out via the flag.
103+
disable-crypto: "ON"
101104
- device: stm32l476rgt6
102105
max_size: 524288
103106
- device: stm32l562qei6
@@ -166,7 +169,7 @@ jobs:
166169
set -euo pipefail
167170
mkdir build
168171
cd build
169-
cmake .. -G Ninja -DCMAKE_TOOLCHAIN_FILE=cmake/arm-toolchain.cmake -DDEVICE=${{ matrix.device }} ${{ matrix.usb-cdc == 'ON' && '-DAVM_USB_CDC_PORT_DRIVER_ENABLED=ON' || '' }}
172+
cmake .. -G Ninja -DCMAKE_TOOLCHAIN_FILE=cmake/arm-toolchain.cmake -DDEVICE=${{ matrix.device }} ${{ matrix.usb-cdc == 'ON' && '-DAVM_USB_CDC_PORT_DRIVER_ENABLED=ON' || '' }} ${{ matrix.disable-crypto == 'ON' && '-DAVM_DISABLE_MBEDTLS=ON' || '' }}
170173
cmake --build .
171174
172175
- name: "Perform CodeQL Analysis"

src/platforms/stm32/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ option(AVM_ENABLE_LOG_LINES "Include source and line info for all enabled levels
3535
option(AVM_CONFIG_REBOOT_ON_NOT_OK "Reboot when application exits with non 'ok' return" OFF)
3636
option(AVM_DISABLE_GPIO_NIFS "Disable GPIO nifs (input and output)" OFF)
3737
option(AVM_DISABLE_GPIO_PORT_DRIVER "Disable GPIO 'port' driver (input, output, and interrupts)" OFF)
38+
option(AVM_DISABLE_MBEDTLS "Exclude mbedTLS/crypto NIFs even on devices with an RNG (saves ~38 KB flash)" OFF)
3839
option(AVM_PRINT_PROCESS_CRASH_DUMPS "Print crash reports when processes die with non-standard reasons" ON)
3940

4041
set(AVM_HSE_VALUE "" CACHE STRING "HSE crystal frequency in Hz (e.g. 25000000). Overrides family default.")

src/platforms/stm32/cmake/stm32_device.cmake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,22 @@ else()
155155
set(STM32_HAS_RNG FALSE)
156156
endif()
157157

158+
# Flash-constrained devices that do have an RNG (e.g. stm32g474ret6, 384 KB
159+
# flash) can opt out of mbedTLS/crypto to save ~38 KB. STM32_HAS_RNG is the
160+
# sole gate for crypto (mbedTLS fetch/link + otp_crypto.c), so forcing it FALSE
161+
# takes the same no-crypto path already exercised by RNG-less devices (g0b1).
162+
if (STM32_HAS_RNG AND AVM_DISABLE_MBEDTLS)
163+
set(STM32_HAS_RNG FALSE)
164+
set(STM32_CRYPTO_DISABLED_BY_OPTION TRUE)
165+
endif()
166+
158167
message("-----------Device Info-----------")
159168
message(STATUS "Device : ${DEVICE}")
160169
message(STATUS "Family : ${STM32_FAMILY}")
161170
message(STATUS "CPU : ${STM32_CPU}")
162171
message(STATUS "FPU : ${STM32_FPU}")
163172
message(STATUS "Arch Flags : ${_arch_flags_str}")
164173
message(STATUS "Has RNG : ${STM32_HAS_RNG}")
174+
if (STM32_CRYPTO_DISABLED_BY_OPTION)
175+
message(STATUS "Crypto : disabled via AVM_DISABLE_MBEDTLS (RNG present)")
176+
endif()

0 commit comments

Comments
 (0)