Skip to content

Commit 2daa935

Browse files
authored
Merge pull request #2716 from andresag01/mbedtls_entropy_config
Add a new top level config.h for mbedtls
2 parents b67e1f7 + 21a7b1d commit 2daa935

File tree

4 files changed

+61
-10
lines changed

4 files changed

+61
-10
lines changed

features/mbedtls/importer/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ deploy: rsync
6666
#
6767
# Adjusting the default mbed TLS config file to mbed purposes
6868
./adjust-config.sh $(MBED_TLS_DIR)/scripts/config.pl $(TARGET_INC)/mbedtls/config.h
69+
#
70+
# Copy the trimmed config that does not require entropy source
71+
cp $(MBED_TLS_DIR)/configs/config-no-entropy.h $(TARGET_INC)/mbedtls/.
6972

7073
update: $(MBED_TLS_GIT_CFG) $(MBED_TLS_HA_GIT_CFG)
7174
#

features/mbedtls/importer/adjust-config.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,36 @@ conf() {
2525
$SCRIPT -f $FILE $@
2626
}
2727

28+
add_code() {
29+
MATCH_PATTERN="$1"
30+
shift
31+
CODE=$(IFS=""; printf "%s" "$*")
32+
33+
perl -i -pe \
34+
"s/$MATCH_PATTERN/$MATCH_PATTERN$CODE/igs" \
35+
"$FILE"
36+
}
37+
38+
# add an #ifndef to include config-no-entropy.h when the target does not have
39+
# an entropy source we can use.
40+
add_code \
41+
"#ifndef MBEDTLS_CONFIG_H\n" \
42+
"\n" \
43+
"#include \"platform\/inc\/platform_mbed.h\"\n" \
44+
"\n" \
45+
"\/*\n" \
46+
" * Only use features that do not require an entropy source when\n" \
47+
" * DEVICE_ENTROPY_SOURCE is not defined in mbed OS.\n" \
48+
" *\/\n" \
49+
"#if !defined(MBEDTLS_ENTROPY_HARDWARE_ALT)\n" \
50+
"#include \"mbedtls\/config-no-entropy.h\"\n" \
51+
"#else\n"
52+
53+
add_code \
54+
"#include \"check_config.h\"\n" \
55+
"\n" \
56+
"#endif \/* !MBEDTLS_ENTROPY_HARDWARE_ALT *\/"
57+
2858
# not supported on mbed OS, nor used by mbed Client
2959
conf unset MBEDTLS_NET_C
3060
conf unset MBEDTLS_TIMING_C
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Copyright (C) 2006-2016, ARM Limited, All Rights Reserved
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
* not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
* This file is part of mbed TLS (https://tls.mbed.org)
18+
*/
19+
20+
#if defined(DEVICE_TRNG)
21+
#define MBEDTLS_ENTROPY_HARDWARE_ALT
22+
#endif

hal/targets.json

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@
561561
"supported_toolchains": ["ARM", "GCC_ARM", "IAR"],
562562
"extra_labels": ["Freescale", "KSDK2_MCUS", "FRDM", "KPSDK_MCUS", "KPSDK_CODE", "MCU_K64F"],
563563
"is_disk_virtual": true,
564-
"macros": ["CPU_MK64FN1M0VMD12", "FSL_RTOS_MBED", "MBEDTLS_ENTROPY_HARDWARE_ALT"],
564+
"macros": ["CPU_MK64FN1M0VMD12", "FSL_RTOS_MBED"],
565565
"inherits": ["Target"],
566566
"progen": {"target": "frdm-k64f"},
567567
"detect_code": ["0240"],
@@ -599,7 +599,7 @@
599599
"supported_toolchains": ["ARM", "GCC_ARM", "IAR"],
600600
"extra_labels": ["Freescale", "KSDK2_MCUS", "FRDM"],
601601
"is_disk_virtual": true,
602-
"macros": ["CPU_MK66FN2M0VMD18", "FSL_RTOS_MBED", "MBEDTLS_ENTROPY_HARDWARE_ALT"],
602+
"macros": ["CPU_MK66FN2M0VMD18", "FSL_RTOS_MBED"],
603603
"inherits": ["Target"],
604604
"progen": {"target": "frdm-k66f"},
605605
"detect_code": ["0311"],
@@ -793,7 +793,7 @@
793793
"supported_toolchains": ["ARM", "uARM", "GCC_ARM", "IAR"],
794794
"inherits": ["Target"],
795795
"progen": {"target": "nucleo-f410rb"},
796-
"macros": ["MBEDTLS_ENTROPY_HARDWARE_ALT", "TRANSACTION_QUEUE_SIZE_SPI=2"],
796+
"macros": ["TRANSACTION_QUEUE_SIZE_SPI=2"],
797797
"detect_code": ["0740"],
798798
"device_has": ["ANALOGIN", "ANALOGOUT", "ERROR_RED", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES", "TRNG"],
799799
"release_versions": ["2", "5"]
@@ -832,7 +832,7 @@
832832
"extra_labels": ["STM", "STM32F4", "STM32F429", "STM32F429ZI", "STM32F429xx"],
833833
"supported_toolchains": ["ARM", "uARM", "GCC_ARM", "IAR"],
834834
"progen": {"target": "nucleo-f429zi"},
835-
"macros": ["MBEDTLS_ENTROPY_HARDWARE_ALT", "DEVICE_RTC_LSI=1", "TRANSACTION_QUEUE_SIZE_SPI=2"],
835+
"macros": ["DEVICE_RTC_LSI=1", "TRANSACTION_QUEUE_SIZE_SPI=2"],
836836
"device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "ERROR_RED", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "RTC_LSI", "SERIAL", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES", "TRNG"],
837837
"detect_code": ["0796"],
838838
"features": ["IPV4"],
@@ -883,7 +883,6 @@
883883
"extra_labels": ["STM", "STM32F7", "STM32F746", "STM32F746ZG"],
884884
"supported_toolchains": ["ARM", "uARM", "GCC_ARM", "IAR"],
885885
"default_toolchain": "ARM",
886-
"macros": ["MBEDTLS_ENTROPY_HARDWARE_ALT"],
887886
"progen": {
888887
"target": "nucleo-f746zg",
889888
"iar": {
@@ -902,7 +901,6 @@
902901
"extra_labels": ["STM", "STM32F7", "STM32F767", "STM32F767ZI"],
903902
"supported_toolchains": ["ARM", "uARM", "GCC_ARM", "IAR"],
904903
"default_toolchain": "ARM",
905-
"macros": ["MBEDTLS_ENTROPY_HARDWARE_ALT"],
906904
"progen": {"target": "nucleo-f767zi"},
907905
"detect_code": ["0818"],
908906
"device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "I2C", "I2CSLAVE", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES", "TRNG"],
@@ -1074,7 +1072,7 @@
10741072
"core": "Cortex-M4F",
10751073
"default_toolchain": "ARM",
10761074
"extra_labels": ["STM", "STM32F4", "STM32F429", "STM32F429ZI", "STM32F429xx"],
1077-
"macros": ["MBEDTLS_ENTROPY_HARDWARE_ALT","DEVICE_RTC_LSI=1","TRANSACTION_QUEUE_SIZE_SPI=2"],
1075+
"macros": ["DEVICE_RTC_LSI=1","TRANSACTION_QUEUE_SIZE_SPI=2"],
10781076
"supported_toolchains": ["ARM", "uARM", "GCC_ARM", "IAR"],
10791077
"progen": {"target": "disco-f429zi"},
10801078
"device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "ERROR_RED", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES", "TRNG"],
@@ -1087,7 +1085,7 @@
10871085
"extra_labels": ["STM", "STM32F4", "STM32F469", "STM32F469NI", "STM32F469xx"],
10881086
"supported_toolchains": ["ARM", "uARM", "IAR", "GCC_ARM"],
10891087
"inherits": ["Target"],
1090-
"macros": ["MBEDTLS_ENTROPY_HARDWARE_ALT","TRANSACTION_QUEUE_SIZE_SPI=2"],
1088+
"macros": ["TRANSACTION_QUEUE_SIZE_SPI=2"],
10911089
"progen": {"target": "disco-f469ni"},
10921090
"detect_code": ["0788"],
10931091
"device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "ERROR_RED", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES", "TRNG"],
@@ -1110,7 +1108,6 @@
11101108
"extra_labels": ["STM", "STM32F7", "STM32F746", "STM32F746NG"],
11111109
"supported_toolchains": ["ARM", "uARM", "GCC_ARM", "IAR"],
11121110
"default_toolchain": "ARM",
1113-
"macros": ["MBEDTLS_ENTROPY_HARDWARE_ALT"],
11141111
"progen": {"target": "disco-f746ng"},
11151112
"detect_code": ["0815"],
11161113
"device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "I2C", "I2CSLAVE", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES", "TRNG"],
@@ -2083,7 +2080,6 @@
20832080
"core": "Cortex-M4F",
20842081
"default_toolchain": "ARM",
20852082
"extra_labels": ["NUVOTON", "NUC472", "NUMAKER_PFM_NUC472"],
2086-
"macros": ["MBEDTLS_ENTROPY_HARDWARE_ALT"],
20872083
"is_disk_virtual": true,
20882084
"supported_toolchains": ["ARM", "uARM", "GCC_ARM", "IAR"],
20892085
"inherits": ["Target"],

0 commit comments

Comments
 (0)