[修改] 增加freeRTOS

1. 版本FreeRTOSv202212.01,命名为kernel;
This commit is contained in:
2023-05-06 16:43:01 +00:00
commit a345df017b
20944 changed files with 11094377 additions and 0 deletions

View File

@ -0,0 +1,47 @@
From e76d44bc8b4ee892fc15da7cfe094b345311ef95 Mon Sep 17 00:00:00 2001
From: Aditya Patwardhan <aditya.patwardhan@espressif.com>
Date: Tue, 26 Jul 2022 14:31:46 +0530
Subject: [PATCH] Fix missing prototype warning when
`MBEDTLS_DEPRECATED_REMOVED` is enabled
Added the changelog.d entry
Signed-off-by: Aditya Patwardhan <aditya.patwardhan@espressif.com>
(cherry picked from commit 3096f331ee17a37529f6cc12984d82fc077a4f4d)
---
ChangeLog.d/fix_build_error_for_mbedtls_deprecated_removed.txt | 3 +++
library/ssl_tls.c | 2 ++
2 files changed, 5 insertions(+)
create mode 100644 ChangeLog.d/fix_build_error_for_mbedtls_deprecated_removed.txt
diff --git a/ChangeLog.d/fix_build_error_for_mbedtls_deprecated_removed.txt b/ChangeLog.d/fix_build_error_for_mbedtls_deprecated_removed.txt
new file mode 100644
index 000000000..a70521a00
--- /dev/null
+++ b/ChangeLog.d/fix_build_error_for_mbedtls_deprecated_removed.txt
@@ -0,0 +1,3 @@
+Bugfix
+ * Fix build error due to missing prototype
+ warning when MBEDTLS_DEPRECATED_REMOVED is enabled
diff --git a/library/ssl_tls.c b/library/ssl_tls.c
index e60b82fa5..f594ab5cd 100644
--- a/library/ssl_tls.c
+++ b/library/ssl_tls.c
@@ -2309,6 +2309,7 @@ void mbedtls_ssl_get_dtls_srtp_negotiation_result( const mbedtls_ssl_context *ss
}
#endif /* MBEDTLS_SSL_DTLS_SRTP */
+#if !defined(MBEDTLS_DEPRECATED_REMOVED)
void mbedtls_ssl_conf_max_version( mbedtls_ssl_config *conf, int major, int minor )
{
conf->max_tls_version = (major << 8) | minor;
@@ -2318,6 +2319,7 @@ void mbedtls_ssl_conf_min_version( mbedtls_ssl_config *conf, int major, int mino
{
conf->min_tls_version = (major << 8) | minor;
}
+#endif /* MBEDTLS_DEPRECATED_REMOVED */
#if defined(MBEDTLS_SSL_SRV_C)
void mbedtls_ssl_conf_cert_req_ca_list( mbedtls_ssl_config *conf,
--
2.37.3

View File

@ -0,0 +1,116 @@
include(FetchContent)
# Ensure unity target has been added.
if(NOT TARGET unity)
include(${MODULE_ROOT_DIR}/tools/unity.cmake)
endif()
FetchContent_Declare(
cmock GIT_REPOSITORY https://github.com/ThrowTheSwitch/CMock.git
GIT_TAG afa294982e8a28bc06f341cc77fd4276641b42bd
)
FetchContent_GetProperties(
cmock
POPULATED cmock_POPULATED
)
if(NOT ${cmock_POPULATED})
FetchContent_Populate(cmock)
endif()
if(NOT TARGET cmock)
add_library(cmock STATIC)
target_sources(cmock PRIVATE ${cmock_SOURCE_DIR}/src/cmock.c)
set_target_properties(cmock PROPERTIES COMPILE_FLAGS "-Og")
target_include_directories(cmock PRIVATE ${cmock_SOURCE_DIR}/src)
target_include_directories(cmock PUBLIC ${cmock_SOURCE_DIR}/src)
target_link_libraries(cmock PRIVATE unity)
endif()
macro(
target_add_mock_pp
mock_target
cmock_config
mock_header
pp_args
)
get_filename_component(mock_basename ${mock_header} NAME_WE)
get_filename_component(cmock_config_absolute ${cmock_config} ABSOLUTE)
get_filename_component(mock_header_absolute ${mock_header} ABSOLUTE)
get_target_property(target_defs ${mock_target} COMPILE_DEFINITIONS)
set(target_flags "")
if(NOT "${target_defs}" STREQUAL "target_defs-NOTFOUND")
foreach(target_def ${target_defs})
set(target_flags ${target_flags} ${target_def})
endforeach()
endif()
get_target_property(target_include_dirs ${mock_target} INCLUDE_DIRECTORIES)
if(NOT "${target_include_dirs}" STREQUAL "target_include_dirs-NOTFOUND")
foreach(include_dir ${target_include_dirs})
set(target_flags ${target_flags} -I${include_dir})
endforeach()
endif()
add_custom_target(
mocks_pp_dir ALL
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/mocks_pp
)
# Preprocess header file before generating mock
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/mocks_pp/${mock_basename}.h
VERBATIM
COMMAND
${CMAKE_C_COMPILER} -E ${pp_args} ${target_flags} -nostdlib -nodefaultlibs
${mock_header_absolute} -o ${CMAKE_CURRENT_BINARY_DIR}/mocks_pp/${mock_basename}.h
DEPENDS mocks_pp_dir pkcs11_api
)
# Generate mock
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/mock_${mock_basename}.c
COMMAND
ruby ${cmock_SOURCE_DIR}/lib/cmock.rb -o${cmock_config_absolute}
${CMAKE_CURRENT_BINARY_DIR}/mocks_pp/${mock_basename}.h
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/mocks_pp/${mock_basename}.h
)
target_sources(${mock_target} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/mock_${mock_basename}.c)
target_include_directories(${mock_target} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
endmacro()
macro(target_add_mock mock_target cmock_config mock_header)
get_filename_component(mock_basename ${mock_header} NAME_WE)
get_filename_component(cmock_config_absolute ${cmock_config} ABSOLUTE)
get_filename_component(mock_header_absolute ${mock_header} ABSOLUTE)
get_target_property(target_defs ${mock_target} COMPILE_DEFINITIONS)
set(target_flags "")
if(NOT "${target_defs}" STREQUAL "target_defs-NOTFOUND")
foreach(target_def ${target_defs})
set(target_flags ${target_flags} -D${target_def})
endforeach()
endif()
# Generate mock
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/mock_${mock_basename}.c
COMMAND
ruby ${cmock_SOURCE_DIR}/lib/cmock.rb -o${cmock_config_absolute}
${mock_header_absolute}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
target_sources(${mock_target} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/mock_${mock_basename}.c)
target_include_directories(${mock_target} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
endmacro()

View File

@ -0,0 +1,85 @@
# Taken from amazon-freertos repository
cmake_minimum_required(VERSION 3.13)
# set(BINARY_DIR ${CMAKE_BINARY_DIR})
# reset coverage counters
execute_process(
COMMAND lcov --directory ${CMAKE_BINARY_DIR}
--base-directory ${CMAKE_BINARY_DIR}
--zerocounters
COMMAND mkdir -p ${CMAKE_BINARY_DIR}/coverage
)
# make the initial/baseline capture a zeroed out files
execute_process(
COMMAND lcov --directory ${CMAKE_BINARY_DIR}
--base-directory ${CMAKE_BINARY_DIR}
--initial
--capture
--rc lcov_branch_coverage=1
--rc genhtml_branch_coverage=1
--output-file=${CMAKE_BINARY_DIR}/base_coverage.info
)
file(GLOB files "${CMAKE_BINARY_DIR}/bin/*")
set(REPORT_FILE ${CMAKE_BINARY_DIR}/utest_report.txt)
file(WRITE ${REPORT_FILE} "")
# execute all files in bin directory, gathering the output to show it in CI
foreach(testname ${files})
get_filename_component(test ${testname} NAME_WLE)
message("Running ${testname}")
execute_process(COMMAND ${testname} OUTPUT_FILE ${CMAKE_BINARY_DIR}/${test}_out.txt)
file(READ ${CMAKE_BINARY_DIR}/${test}_out.txt CONTENTS)
file(APPEND ${REPORT_FILE} "${CONTENTS}")
endforeach()
# generate Junit style xml output
execute_process(
COMMAND ruby
${CMAKE_BINARY_DIR}/_deps/unity-src/auto/parse_output.rb
-xml ${REPORT_FILE}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
# capture data after running the tests
execute_process(
COMMAND lcov --capture
--rc lcov_branch_coverage=1
--rc genhtml_branch_coverage=1
--base-directory ${CMAKE_BINARY_DIR}
--directory ${CMAKE_BINARY_DIR}
--output-file ${CMAKE_BINARY_DIR}/second_coverage.info
--quiet
)
# combine baseline results (zeros) with the one after running the tests
execute_process(
COMMAND lcov --base-directory ${CMAKE_BINARY_DIR}
--directory ${CMAKE_BINARY_DIR}
--add-tracefile ${CMAKE_BINARY_DIR}/base_coverage.info
--add-tracefile ${CMAKE_BINARY_DIR}/second_coverage.info
--output-file ${CMAKE_BINARY_DIR}/coverage.info
--no-external
--rc lcov_branch_coverage=1
--quiet
)
execute_process(
COMMAND lcov
--remove ${CMAKE_BINARY_DIR}/coverage.info \*_deps\*
--output-file ${CMAKE_BINARY_DIR}/coverage.info
--rc lcov_branch_coverage=1
--quiet
)
execute_process(
COMMAND lcov --list ${CMAKE_BINARY_DIR}/coverage.info
--rc lcov_branch_coverage=1
)
execute_process(
COMMAND genhtml --rc lcov_branch_coverage=1
--branch-coverage
--output-directory ${CMAKE_BINARY_DIR}/coverage
${CMAKE_BINARY_DIR}/coverage.info
)

View File

@ -0,0 +1,79 @@
# Static code analysis for corePKCS11 library
This directory is made for the purpose of statically testing the MISRA C:2012 compliance of corePKCS11 using
[Synopsys Coverity](https://www.synopsys.com/software-integrity/security-testing/static-analysis-sast.html) static analysis tool.
To that end, this directory provides a [configuration file](https://github.com/FreeRTOS/corePKCS11/blob/main/tools/coverity/misra.config) to use when
building a binary for the tool to analyze.
> **Note**
For generating the report as outlined below, we have used Coverity version 2018.09.
For details regarding the suppressed violations in the report (which can be generated using the instructions described below), please
see the [MISRA.md](https://github.com/FreeRTOS/corePKCS11/blob/main/MISRA.md) file.
## Getting Started
### Prerequisites
You can run this on a platform supported by Coverity. The list and other details can be found [here](https://sig-docs.synopsys.com/polaris/topics/c_coverity-compatible-platforms.html).
To compile and run the Coverity target successfully, you must have the following:
1. CMake version > 3.13.0 (You can check whether you have this by typing `cmake --version`)
2. GCC compiler
- You can see the downloading and installation instructions [here](https://gcc.gnu.org/install/).
3. Download the repo and include the submodules using the following commands.
- `git clone --recurse-submodules git@github.com:FreeRTOS/corePKCS11.git ./corePKCS11`
- `cd ./corePKCS11`
- `git submodule update --checkout --init --recursive`
### To build and run coverity:
Go to the root directory of the library and run the following commands in terminal:
1. Update the compiler configuration in Coverity
~~~
cov-configure --force --compiler cc --comptype gcc
~~~
2. Create the build files using CMake in a `build` directory
~~~
cmake -B build -S test
~~~
3. Go to the build directory and copy the coverity configuration file
~~~
cd build/
~~~
4. Build the static analysis target
~~~
cov-build --emit-complementary-info --dir cov-out make coverity_analysis
~~~
5. Go to the Coverity output directory (`cov-out`) and begin Coverity static analysis
~~~
cd cov-out/
cov-analyze --dir . --coding-standard-config ../../tools/coverity/misra.config --tu-pattern "file('.*/source/.*')"
~~~
6. Format the errors in HTML format so that it is more readable while removing the test and build directory from the report
~~~
cov-format-errors --dir . --file "source" --exclude-files '(/build/|/test/|/dependency/|/portable/)' --html-output html-out;
~~~
7. Format the errors in JSON format to perform a jq query to get a simplified list of any exceptions.
NOTE: A blank output means there are no defects that aren't being suppressed by the config or inline comments.
~~~
cov-format-errors --dir . --file "source" --exclude-files '(/build/|/test/|/dependency/|/portable/)' --json-output-v2 defects.json;
echo -e "\n-------------------------Non-Suppresed Deviations, if any, Listed Below-------------------------\n";
jq '.issues[] | .events[] | .eventTag ' defects.json | sort | uniq -c | sort -nr;
echo -e "\n-------------------------Non-Suppresed Deviations, if any, Listed Above-------------------------\n";
~~~
For your convenience the commands above are below to be copy/pasted into a UNIX command friendly terminal.
~~~
cov-configure --force --compiler cc --comptype gcc;
cmake -B build -S test;
cd build/;
cov-build --emit-complementary-info --dir cov-out make coverity_analysis;
cd cov-out/
cov-analyze --dir . --coding-standard-config ../../tools/coverity/misra.config;
cov-format-errors --dir . --file "source" --exclude-files '(/build/|/test/|/dependency/|/portable/)' --html-output html-out;
cov-format-errors --dir . --file "source" --exclude-files '(/build/|/test/|/dependency/|/portable/)' --json-output-v2 defects.json;
echo -e "\n-------------------------Non-Suppresed Deviations, if any, Listed Below-------------------------\n";
jq '.issues[] | .events[] | .eventTag ' defects.json | sort | uniq -c | sort -nr;
echo -e "\n-------------------------Non-Suppresed Deviations, if any, Listed Above-------------------------\n";
cd ../../;
~~~
You should now have the HTML formatted violations list in a directory named `build/cov-out/html-output`.
With the current configuration and the provided project, you should not see any deviations.

View File

@ -0,0 +1,58 @@
// MISRA C-2012 Rules
{
version : "2.0",
standard : "c2012",
title: "Coverity MISRA Configuration",
deviations : [
// Disable the following rules.
{
deviation: "Directive 4.5",
reason: "Allow names that MISRA considers ambiguous (such as enum IOT_MQTT_CONNECT and function IotMqtt_Connect)."
},
{
deviation: "Directive 4.8",
reason: "Allow inclusion of unused types. Header files for a specific port, which are needed by all files, may define types that are not used by a specific file."
},
{
deviation: "Directive 4.9",
reason: "Allow inclusion of function like macros. Logging is done using function like macros."
},
{
deviation: "Directive 4.12",
reason: "Allow use of malloc. This library uses malloc to create cryptographic objects."
},
{
deviation: "Rule 2.3",
reason: "Allow unused types. Library headers may define types intended for the application's use, but not used within the library files."
},
{
deviation: "Rule 2.4",
reason: "Allow unused macros. Library headers may define macros intended for the application's use, but not used by a specific file."
},
{
deviation: "Rule 2.5",
reason: "Allow unused macros. Library headers may define macros intended for the application's use, but not used by a specific file."
},
{
deviation: "Rule 3.1",
reason: "Allow nested comments. Documentation blocks contain comments for example code."
},
{
deviation: "Rule 8.7",
reason: "API functions are not used by library. They must be externally visible in order to be used by the application."
},
{
deviation: "Rule 8.13",
reason: "The PKCS #11 API is defined by the PKCS #11 header files distributed by OASIS. There are some parameters that could be const qualified in this implementation, but since the API cannot be modified, are not const qualified."
},
{
deviation: "Rule 21.1",
reason: "Allow use of all macro names. For compatibility, some macros introduced in C99 are defined for use with C90 compilers."
},
{
deviation: "Rule 21.2",
reason: " Allow use of all macro and identifier names. For compatibility, some macros introduced in C99 are defined for use with C90 compilers."
}
]
}

View File

@ -0,0 +1,105 @@
include(FetchContent)
set(FETCHCONTENT_QUIET OFF)
set(MBEDTLS_2_VERSION 2.28.1)
FetchContent_Declare(
mbedtls_2
GIT_REPOSITORY "https://github.com/ARMmbed/mbedtls"
GIT_TAG v${MBEDTLS_2_VERSION}
PATCH_COMMAND ${MODULE_ROOT_DIR}/tools/mbedtls_configure.sh <SOURCE_DIR> config.h
)
FetchContent_GetProperties(
mbedtls_2
POPULATED mbedtls_2_POPULATED
)
if(NOT ${mbedtls_2_POPULATED})
FetchContent_Populate(mbedtls_2)
endif()
if(NOT TARGET MbedTLS2_mbedtls)
set(MBEDTLS_2_BIN_DIR ${CMAKE_CURRENT_BINARY_DIR}/lib/mbedtls_2)
set(MBEDTLS_TARGET_PREFIX "MbedTLS2_")
option(USE_STATIC_MBEDTLS_LIBRARY "" ON)
option(USE_SHARED_MBEDTLS_LIBRARY "" OFF)
option(ENABLE_PROGRAMS "" OFF)
option(ENABLE_TESTING "" OFF)
add_subdirectory(${mbedtls_2_SOURCE_DIR} ${mbedtls_2_BINARY_DIR})
add_library(MbedTLS2_interface INTERFACE)
get_target_property(mbedtls_includes MbedTLS2_mbedtls INCLUDE_DIRECTORIES)
target_include_directories(
MbedTLS2_interface
INTERFACE ${mbedtls_includes}
INTERFACE ${mbedtls_2_SOURCE_DIR}/library
INTERFACE ${mbedtls_2_SOURCE_DIR}/include/mbedtls
)
set_target_properties(
MbedTLS2_mbedcrypto MbedTLS2_mbedtls MbedTLS2_mbedx509
PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${MBEDTLS_2_BIN_DIR} LIBRARY_OUTPUT_DIRECTORY
${MBEDTLS_2_BIN_DIR}
)
add_library(MbedTLS2::mbedtls ALIAS MbedTLS2_mbedtls)
add_library(MbedTLS2::mbedcrypto ALIAS MbedTLS2_mbedcrypto)
add_library(MbedTLS2::mbedx509 ALIAS MbedTLS2_mbedx509)
add_library(MbedTLS2::interface ALIAS MbedTLS2_interface)
endif()
set(MBEDTLS_3_VERSION 3.2.1)
FetchContent_Declare(
mbedtls_3
GIT_REPOSITORY "https://github.com/ARMmbed/mbedtls"
GIT_TAG v${MBEDTLS_3_VERSION}
PATCH_COMMAND
${CMAKE_CURRENT_LIST_DIR}/mbedtls_configure.sh <SOURCE_DIR> mbedtls_config.h &&
${CMAKE_CURRENT_LIST_DIR}/mbedtls_patch.sh <SOURCE_DIR> ${CMAKE_CURRENT_LIST_DIR}/0001-Fix-missing-prototype-warning-when-MBEDTLS_DEPRECATE.patch
)
FetchContent_GetProperties(
mbedtls_3
POPULATED mbedtls_3_POPULATED
)
if(NOT ${mbedtls_3_POPULATED})
FetchContent_Populate(mbedtls_3)
endif()
if(NOT TARGET MbedTLS3_mbedtls)
set(MBEDTLS_3_BIN_DIR ${CMAKE_CURRENT_BINARY_DIR}/lib/mbedtls_3)
set(MBEDTLS_TARGET_PREFIX "MbedTLS3_")
option(USE_STATIC_MBEDTLS_LIBRARY "" ON)
option(USE_SHARED_MBEDTLS_LIBRARY "" OFF)
option(ENABLE_PROGRAMS "" OFF)
option(ENABLE_TESTING "" OFF)
add_subdirectory(${mbedtls_3_SOURCE_DIR} ${mbedtls_3_BINARY_DIR})
add_library(MbedTLS3_interface INTERFACE)
get_target_property(mbedtls_includes MbedTLS3_mbedtls INCLUDE_DIRECTORIES)
target_include_directories(
MbedTLS3_interface
INTERFACE ${mbedtls_includes}
INTERFACE ${mbedtls_3_SOURCE_DIR}/library
INTERFACE ${mbedtls_3_SOURCE_DIR}/include/mbedtls
)
set_target_properties(
MbedTLS3_mbedcrypto MbedTLS3_mbedtls MbedTLS3_mbedx509
PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${MBEDTLS_3_BIN_DIR} LIBRARY_OUTPUT_DIRECTORY
${MBEDTLS_3_BIN_DIR}
)
add_library(MbedTLS3::mbedtls ALIAS MbedTLS3_mbedtls)
add_library(MbedTLS3::mbedcrypto ALIAS MbedTLS3_mbedcrypto)
add_library(MbedTLS3::mbedx509 ALIAS MbedTLS3_mbedx509)
add_library(MbedTLS3::interface ALIAS MbedTLS3_interface)
endif()

View File

@ -0,0 +1,28 @@
#!/bin/sh
if [ $# -ne 2 ]; then
echo "Usage: mbedtls_configure.sh <MBEDTLS_SRC_DIR> <CONFIG_H_NAME>"
exit 1
fi
MBEDTLS_DIR="${1}"
CONFIG="${2}"
cp "${MBEDTLS_DIR}/include/mbedtls/${CONFIG}" mbedtls_config_patch.h
"${MBEDTLS_DIR}/scripts/config.py" --file mbedtls_config_patch.h full_no_deprecated
"${MBEDTLS_DIR}/scripts/config.py" --file mbedtls_config_patch.h unset MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
"${MBEDTLS_DIR}/scripts/config.py" --file mbedtls_config_patch.h unset MBEDTLS_ENTROPY_NV_SEED
"${MBEDTLS_DIR}/scripts/config.py" --file mbedtls_config_patch.h unset MBEDTLS_PLATFORM_NV_SEED_ALT
"${MBEDTLS_DIR}/scripts/config.py" --file mbedtls_config_patch.h unset MBEDTLS_PSA_CRYPTO_C
"${MBEDTLS_DIR}/scripts/config.py" --file mbedtls_config_patch.h unset MBEDTLS_PSA_CRYPTO_CLIENT
"${MBEDTLS_DIR}/scripts/config.py" --file mbedtls_config_patch.h unset MBEDTLS_PSA_CRYPTO_DRIVERS
"${MBEDTLS_DIR}/scripts/config.py" --file mbedtls_config_patch.h unset MBEDTLS_SSL_PROTO_TLS1_3
"${MBEDTLS_DIR}/scripts/config.py" --file mbedtls_config_patch.h unset MBEDTLS_USE_PSA_CRYPTO
"${MBEDTLS_DIR}/scripts/config.py" --file mbedtls_config_patch.h unset MBEDTLS_PSA_CRYPTO_C
"${MBEDTLS_DIR}/scripts/config.py" --file mbedtls_config_patch.h unset MBEDTLS_PSA_CRYPTO_STORAGE_C
"${MBEDTLS_DIR}/scripts/config.py" --file mbedtls_config_patch.h unset MBEDTLS_PSA_ITS_FILE_C
"${MBEDTLS_DIR}/scripts/config.py" --file mbedtls_config_patch.h unset MBEDTLS_PSA_CRYPTO_SE_C
cmp --quiet "${MBEDTLS_DIR}/include/mbedtls/config.h" mbedtls_config_patch.h || {
cp mbedtls_config_patch.h "${MBEDTLS_DIR}/include/mbedtls/${CONFIG}"
}

View File

@ -0,0 +1,28 @@
#!/bin/sh
if [ $# -lt 2 ]; then
echo "Usage: mbedtls_patch.sh <MBEDTLS_SRC_DIR> <PATCH_1> [<PATCH_2>].."
exit 1
fi
MBEDTLS_DIR="${1}"
shift
PATCHES="${1}"
shift
while [ $# -gt 0 ]; do
PATCHES="${PATCHES} ${1}"
shift
done
for patch in ${PATCHES}; do
if git -C "${MBEDTLS_DIR}" apply --check --quiet --reverse "${patch}"; then
echo "patch: $(basename "${patch}") already applied"
else
echo "patch: applying $(basename "${patch}")"
git -C "${MBEDTLS_DIR}" apply "${patch}"
fi
done

View File

@ -0,0 +1,22 @@
include(FetchContent)
FetchContent_Declare(
pkcs11_api GIT_REPOSITORY https://github.com/oasis-tcs/pkcs11.git GIT_TAG 2-40-errata-1
)
FetchContent_GetProperties(
pkcs11_api
POPULATED pkcs11_api_POPULATED
SOURCE_DIR pkcs11_api_SOURCE_DIR
)
if(NOT ${pkcs11_api_POPULATED})
FetchContent_Populate(pkcs11_api)
endif()
set(PKCS11_API_PATH ${pkcs11_api_SOURCE_DIR}/published/2-40-errata-1)
if(NOT TARGET pkcs11_api)
add_library(pkcs11_api INTERFACE)
target_include_directories(pkcs11_api INTERFACE ${PKCS11_API_PATH})
endif()

View File

@ -0,0 +1,160 @@
# Uncrustify-0.67
input_tab_size = 4 # unsigned number
output_tab_size = 4 # unsigned number
sp_arith = force # ignore/add/remove/force
sp_assign = force # ignore/add/remove/force
sp_assign_default = force # ignore/add/remove/force
sp_before_assign = force # ignore/add/remove/force
sp_after_assign = force # ignore/add/remove/force
sp_enum_assign = force # ignore/add/remove/force
sp_enum_before_assign = force # ignore/add/remove/force
sp_enum_after_assign = force # ignore/add/remove/force
sp_pp_stringify = add # ignore/add/remove/force
sp_bool = force # ignore/add/remove/force
sp_compare = force # ignore/add/remove/force
sp_inside_paren = force # ignore/add/remove/force
sp_paren_paren = force # ignore/add/remove/force
sp_paren_brace = force # ignore/add/remove/force
sp_before_ptr_star = force # ignore/add/remove/force
sp_before_unnamed_ptr_star = force # ignore/add/remove/force
sp_between_ptr_star = remove # ignore/add/remove/force
sp_after_ptr_star = force # ignore/add/remove/force
sp_before_byref = force # ignore/add/remove/force
sp_after_byref = remove # ignore/add/remove/force
sp_after_byref_func = remove # ignore/add/remove/force
sp_before_angle = remove # ignore/add/remove/force
sp_inside_angle = remove # ignore/add/remove/force
sp_after_angle = force # ignore/add/remove/force
sp_before_sparen = remove # ignore/add/remove/force
sp_inside_sparen = force # ignore/add/remove/force
sp_after_sparen = force # ignore/add/remove/force
sp_sparen_brace = force # ignore/add/remove/force
sp_before_semi_for = remove # ignore/add/remove/force
sp_before_semi_for_empty = add # ignore/add/remove/force
sp_after_semi_for_empty = force # ignore/add/remove/force
sp_before_square = remove # ignore/add/remove/force
sp_before_squares = remove # ignore/add/remove/force
sp_inside_square = force # ignore/add/remove/force
sp_after_comma = force # ignore/add/remove/force
sp_after_cast = force # ignore/add/remove/force
sp_inside_paren_cast = force # ignore/add/remove/force
sp_sizeof_paren = remove # ignore/add/remove/force
sp_inside_braces_enum = force # ignore/add/remove/force
sp_inside_braces_struct = force # ignore/add/remove/force
sp_inside_braces = force # ignore/add/remove/force
sp_inside_braces_empty = remove # ignore/add/remove/force
sp_type_func = force # ignore/add/remove/force
sp_func_proto_paren = remove # ignore/add/remove/force
sp_func_def_paren = remove # ignore/add/remove/force
sp_inside_fparens = remove # ignore/add/remove/force
sp_inside_fparen = force # ignore/add/remove/force
sp_fparen_brace = add # ignore/add/remove/force
sp_func_call_paren = remove # ignore/add/remove/force
sp_func_class_paren = remove # ignore/add/remove/force
sp_return_paren = remove # ignore/add/remove/force
sp_attribute_paren = remove # ignore/add/remove/force
sp_defined_paren = remove # ignore/add/remove/force
sp_macro = force # ignore/add/remove/force
sp_macro_func = force # ignore/add/remove/force
sp_brace_typedef = force # ignore/add/remove/force
sp_before_dc = remove # ignore/add/remove/force
sp_after_dc = remove # ignore/add/remove/force
sp_cond_colon = force # ignore/add/remove/force
sp_cond_question = force # ignore/add/remove/force
sp_case_label = force # ignore/add/remove/force
sp_endif_cmt = force # ignore/add/remove/force
sp_before_tr_emb_cmt = force # ignore/add/remove/force
sp_num_before_tr_emb_cmt = 1 # unsigned number
indent_columns = 4 # unsigned number
indent_with_tabs = 0 # unsigned number
indent_align_string = true # false/true
indent_class = true # false/true
indent_class_colon = true # false/true
indent_member = 3 # unsigned number
indent_switch_case = 4 # unsigned number
indent_case_brace = 3 # number
nl_assign_leave_one_liners = true # false/true
nl_class_leave_one_liners = true # false/true
nl_start_of_file = remove # ignore/add/remove/force
nl_end_of_file = force # ignore/add/remove/force
nl_end_of_file_min = 1 # unsigned number
nl_assign_brace = add # ignore/add/remove/force
nl_func_var_def_blk = 1 # unsigned number
nl_fcall_brace = add # ignore/add/remove/force
nl_enum_brace = force # ignore/add/remove/force
nl_struct_brace = force # ignore/add/remove/force
nl_union_brace = force # ignore/add/remove/force
nl_if_brace = add # ignore/add/remove/force
nl_brace_else = add # ignore/add/remove/force
nl_else_brace = add # ignore/add/remove/force
nl_getset_brace = force # ignore/add/remove/force
nl_for_brace = add # ignore/add/remove/force
nl_while_brace = add # ignore/add/remove/force
nl_do_brace = add # ignore/add/remove/force
nl_switch_brace = add # ignore/add/remove/force
nl_multi_line_define = true # false/true
nl_before_case = true # false/true
nl_after_case = true # false/true
nl_func_type_name = remove # ignore/add/remove/force
nl_func_proto_type_name = remove # ignore/add/remove/force
nl_func_paren = remove # ignore/add/remove/force
nl_func_def_paren = remove # ignore/add/remove/force
nl_func_decl_start = remove # ignore/add/remove/force
nl_func_def_start = remove # ignore/add/remove/force
nl_func_decl_args = add # ignore/add/remove/force
nl_func_def_args = add # ignore/add/remove/force
nl_func_decl_end = remove # ignore/add/remove/force
nl_func_def_end = remove # ignore/add/remove/force
nl_fdef_brace = add # ignore/add/remove/force
nl_after_semicolon = true # false/true
nl_after_brace_open = true # false/true
nl_after_brace_close = true # false/true
nl_squeeze_ifdef = true # false/true
nl_before_if = force # ignore/add/remove/force
nl_after_if = force # ignore/add/remove/force
nl_before_for = force # ignore/add/remove/force
nl_after_for = force # ignore/add/remove/force
nl_before_while = force # ignore/add/remove/force
nl_after_while = force # ignore/add/remove/force
nl_before_switch = force # ignore/add/remove/force
nl_after_switch = force # ignore/add/remove/force
nl_before_do = force # ignore/add/remove/force
nl_after_do = force # ignore/add/remove/force
nl_max = 4 # unsigned number
nl_after_func_proto_group = 1 # unsigned number
nl_after_func_body_class = 2 # unsigned number
nl_before_block_comment = 2 # unsigned number
eat_blanks_after_open_brace = true # false/true
eat_blanks_before_close_brace = true # false/true
nl_after_return = true # false/true
pos_bool = trail # ignore/join/lead/lead_break/lead_force/trail/trail_break/trail_force
align_var_def_amp_style = 1 # unsigned number
align_var_def_thresh = 16 # unsigned number
align_assign_thresh = 12 # unsigned number
align_struct_init_span = 3 # unsigned number
align_typedef_gap = 3 # unsigned number
align_typedef_span = 5 # unsigned number
align_typedef_star_style = 1 # unsigned number
align_typedef_amp_style = 1 # unsigned number
align_right_cmt_span = 3 # unsigned number
align_nl_cont = true # false/true
align_pp_define_gap = 4 # unsigned number
align_pp_define_span = 3 # unsigned number
cmt_cpp_to_c = true # false/true
cmt_star_cont = true # false/true
mod_full_brace_do = add # ignore/add/remove/force
mod_full_brace_for = add # ignore/add/remove/force
mod_full_brace_if = add # ignore/add/remove/force
mod_full_brace_while = add # ignore/add/remove/force
mod_full_paren_if_bool = true # false/true
mod_remove_extra_semicolon = true # false/true
mod_add_long_ifdef_endif_comment = 10 # unsigned number
mod_add_long_ifdef_else_comment = 10 # unsigned number
mod_case_brace = remove # ignore/add/remove/force
mod_remove_empty_return = true # false/true
pp_indent = force # ignore/add/remove/force
pp_indent_at_level = true # false/true
pp_indent_count = 4 # unsigned number
pp_space = remove # ignore/add/remove/force
pp_if_indent_code = true # false/true
# option(s) with 'not default' value: 158

View File

@ -0,0 +1,109 @@
include(FetchContent)
FetchContent_Declare(
unity GIT_REPOSITORY https://github.com/ThrowTheSwitch/unity.git GIT_TAG v2.5.1
)
FetchContent_GetProperties(
unity
POPULATED unity_POPULATED
)
if(NOT ${unity_POPULATED})
FetchContent_Populate(unity)
endif()
if(NOT TARGET unity)
add_library(unity STATIC)
target_sources(
unity
PRIVATE ${unity_SOURCE_DIR}/src/unity.c
PRIVATE ${unity_SOURCE_DIR}/extras/fixture/src/unity_fixture.c
PRIVATE ${unity_SOURCE_DIR}/extras/memory/src/unity_memory.c
)
target_include_directories(
unity
PRIVATE ${unity_SOURCE_DIR}/src
PRIVATE ${unity_SOURCE_DIR}/extras/memory/src
PRIVATE ${unity_SOURCE_DIR}/extras/fixture/src
)
target_include_directories(
unity
PUBLIC ${unity_SOURCE_DIR}/src
PUBLIC ${unity_SOURCE_DIR}/extras/memory/src
PUBLIC ${unity_SOURCE_DIR}/extras/fixture/src
)
endif()
macro(add_test_target target test_src)
add_executable(${target} ${test_src})
set_target_properties(
${target} PROPERTIES COMPILE_FLAG "-O0 -ggdb" RUNTIME_OUTPUT_DIRECTORY
"${CMAKE_BINARY_DIR}/bin"
)
include(CTest)
add_test(NAME ${target} COMMAND "${CMAKE_BINARY_DIR}/bin/${target}"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
endmacro()
macro(target_enable_gcov target flag)
get_target_property(target_type ${target} TYPE)
if(target_type STREQUAL "INTERFACE_LIBRARY")
set(c_flag INTERFACE)
set(l_flag INTERFACE)
else()
set(c_flag PRIVATE)
set(l_flag PUBLIC)
endif()
target_compile_options(
${target}
${c_flag}
"-Wextra"
${c_flag}
"-Wpedantic"
${c_flag}
"-fprofile-arcs"
${c_flag}
"-ftest-coverage"
${c_flag}
"-fprofile-generate"
)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_link_options(${target} ${l_flag} "-fprofile-instr-generate")
target_compile_options(${target} ${c_flag} "-Wno-unused-private-field")
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
target_link_libraries(${target} ${l_flag} -lgcov)
target_compile_options(${target} ${c_flag} "-Wno-unused-but-set-variable")
endif()
endmacro()
macro(target_add_test_runner target unity_config test_src)
get_filename_component(test_name ${test_src} NAME_WE)
get_target_property(target_type ${target} TYPE)
if(target_type STREQUAL "INTERFACE_LIBRARY")
set(s_flag INTERFACE)
else()
set(s_flag PRIVATE)
endif()
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${test_name}_runner.c
DEPENDS ${test_src} ${unity_config}
COMMAND
ruby ${unity_SOURCE_DIR}/auto/generate_test_runner.rb ${unity_config} ${test_src}
${CMAKE_CURRENT_BINARY_DIR}/${test_name}_runner.c
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
)
target_sources(${target} ${s_flag} ${CMAKE_CURRENT_BINARY_DIR}/${test_name}_runner.c)
target_link_libraries(${target} ${s_flag} unity)
endmacro()