Fix Mbed TLS adjust-config.sh script

The Mbed TLS import script is quite fragile, and depends on certain lines to be
present in the files it adjusts to be able to do the modifications it needs to
to allow Mbed TLS to build within Mbed OS.

Thsi commit changes the `adjust-config.sh` script to look for a the end of the
config.h file, defined as "#endif /* MBEDTLS_CONFIG_H */" rather than the
include line for "check_config.h".

That's because the inclusion of "check_config.h" is being removed upstream in
Mbed TLS to fix another issue.
pull/12998/head
Simon Butcher 2020-05-19 23:17:49 +01:00
parent 9a8c9e2c29
commit 5b0316832d
1 changed files with 18 additions and 5 deletions

View File

@ -25,7 +25,19 @@ conf() {
$SCRIPT -f $FILE --force $@
}
add_code() {
# Add code before the matching line
prepend_code() {
MATCH_PATTERN="$1"
shift
CODE=$(IFS=""; printf "%s" "$*")
perl -i -pe \
"s/$MATCH_PATTERN/$CODE$MATCH_PATTERN/igs" \
"$FILE"
}
# Add code after the matching line
append_code() {
MATCH_PATTERN="$1"
shift
CODE=$(IFS=""; printf "%s" "$*")
@ -37,7 +49,7 @@ add_code() {
# add an #ifndef to include config-no-entropy.h when the target does not have
# an entropy source we can use.
add_code \
append_code \
"#ifndef MBEDTLS_CONFIG_H\n" \
"\n" \
"#include \"platform\/inc\/platform_mbed.h\"\n" \
@ -56,8 +68,8 @@ add_code
"\n" \
"#else\n"
add_code \
"#include \"mbedtls\/check_config.h\"\n" \
prepend_code \
"#endif \/\* MBEDTLS_CONFIG_H \*\/" \
"\n" \
"#endif \/* !MBEDTLS_ENTROPY_HARDWARE_ALT && !MBEDTLS_TEST_NULL_ENTROPY && !MBEDTLS_ENTROPY_NV_SEED *\/\n" \
"\n" \
@ -70,7 +82,8 @@ add_code
" !defined(MBEDTLS_ENTROPY_HARDWARE_ALT) && !defined(MBEDTLS_ENTROPY_NV_SEED)\n" \
"#error \"No entropy source was found at build time, so TLS \" \\\\\n" \
" \"functionality is not available\"\n" \
"#endif\n"
"#endif\n" \
"\n"
# not supported on mbed OS, nor used by mbed Client
conf unset MBEDTLS_NET_C