AES encryption on NRF52833 and NRF52840 with memory report problem on different NCS

Hi, 
We are currently migrating our project, originally developed with NCS version 1.8.0, to the latest NCS 2.7.0, while incorporating MCUboot for both of them. During this process, I encountered an unusual issue related to memory size after compilation on the NRF52840 and NRF52833 MCUs, both with and without AES ECB encryption enabled for our specific data. Below, I have included screenshots of the memory reports and compiler outputs for the same codebase, compiled with NCS 1.8.0 and NCS 2.7.0 for both MCUs. Note that the base code remains identical across both NCS versions and both MCUs.

For NCS 1.8.0 for crypto I enabled this flags in prj.conf for both MCU's (NRF52833 and NRF52840) - as in examples for this tag on NCS crypto examples: 

CONFIG_MBEDTLS_LIBRARY_NRF_SECURITY=y
CONFIG_NORDIC_SECURITY_BACKEND=y
CONFIG_MBEDTLS_PSA_CRYPTO_C=y
CONFIG_MBEDTLS_PSA_CRYPTO_STORAGE_C=y
CONFIG_PSA_NATIVE_ITS=y
CONFIG_MBEDTLS_ENABLE_HEAP=y
CONFIG_MBEDTLS_HEAP_SIZE=8192
CONFIG_FLASH=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_FLASH_MAP=y
CONFIG_NVS=y
CONFIG_SETTINGS=y


For NCS 2.7.0 for crypto this flags are enabled in prj.conf for both MCU's (NRF52833 and NRF52840):

CONFIG_MBEDTLS_LIBRARY_NRF_SECURITY=y
CONFIG_NORDIC_SECURITY_BACKEND=y
CONFIG_MBEDTLS_PSA_CRYPTO_C=y
CONFIG_PSA_WANT_GENERATE_RANDOM=y
CONFIG_PSA_WANT_KEY_TYPE_AES=y
CONFIG_PSA_WANT_ALG_CBC_NO_PADDING=y
CONFIG_PSA_WANT_ALG_ECB_NO_PADDING=y
CONFIG_MBEDTLS_ENABLE_HEAP=y
CONFIG_MBEDTLS_HEAP_SIZE=8192
CONFIG_PSA_CRYPTO_DRIVER_OBERON=n
CONFIG_PSA_CRYPTO_DRIVER_CC3XX=y
CONFIG_FLASH=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_FLASH_MAP=y
CONFIG_NVS=y
CONFIG_SETTINGS=y
CONFIG_SETTINGS_NVS=y
CONFIG_TRUSTED_STORAGE=y


- Memory usage NCS 1.8.0 with NRF52833 without crypto:

- Memory usage NCS 1.8.0 with NRF52833 with crypto:

- Memory usage NCS 1.8.0 with NRF52840 without crypto:

- Memory usage NCS 1.8.0 with NRF52840 with crypto:

- Memory usage NCS 2.7.0 with NRF52833 without crypto:

- Memory usage NCS 2.7.0 with NRF52833 with crypto:

- Memory usage NCS 2.7.0 with NRF52840 without crypto:

- Memory usage NCS 2.7.0 with NRF52840 with crypto:

So for this memory usage I have few questions:

1) Why for older NCS 1.8.0 there is such difference in code size with and without crypto: about 73k for NRF52833 and 112k for NRF52840 ?

2) Why there is difference in size of code with crypto for NRF52833 and NRF52840 - I mean why adding crypto for NRF52833 adds about 73k and 112k for NRF5840 for NCS 1.8.0 and about 5k for NRF52833 and 15k for NRF52840 on NCS 2.7.0 ? 

3) Almost the same question as above but why code without crypto is different for both MCU's also on both NCS versions ? 

4) Why on old NCS 1.8.0 there is such big difference in code size with crypto (73k for NRF52833 and 112k for NRF52840) in compare to NCS 2.7.0 ? 

5) What this memory report means and why total size is so different than size showed after compilation on NCS 2.7.0 ? For example code for NRF52840 without crypto after compilation shows 102516B in terminal and memory report shows 147.45kB - what it means ? 

Related