Enabling logs in Mbed TLS

Hello! I am trying to monitor mbedtls heap usage in the azure_iot_hub sample (v2.8.0), building for nrf7002dk/nrf5340/cpuapp/ns. I can see in modules/crypto/mbedtls/library/memory_buffer_alloc.c that there is already some code that keeps track how many bytes are allocated, so the only question is how to enable it.


I would expect that adding below options to the prj.conf would work, however I get a linker error related to the memory allocator.

CONFIG_MBEDTLS_DEBUG=y 
CONFIG_MBEDTLS_MEMORY_DEBUG=y CONFIG_MBEDTLS_LOG_LEVEL_DBG=y
/home/user/ncs/toolchains/b81a7cd864/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld: /home/user/ncs/toolchains/b81a7cd864/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/lib/thumb/v8-m.main/nofp/libnosys.a(sbrk.o): in function `_sbrk':
sbrk.c:(.text._sbrk+0x1c): undefined reference to `end'
Memory region         Used Size  Region Size  %age Used
           FLASH:      129980 B     130560 B     99.56%
             RAM:       39072 B        48 KB     79.49%

The above error happens in the tf-m build.

After seeing the above error I limited my effort to just get mbedtls logs working. In nrf/applications/serial_lte_modem/overlay-native_tls.conf I have found the following commented block:

# Enable Mbed TLS logs
#CONFIG_MBEDTLS_DEBUG=y
#CONFIG_MBEDTLS_DEBUG_C=y
#CONFIG_MBEDTLS_DEBUG_LEVEL=3

I uncommented the lines and build the mentioned application with west build -b nrf9160dk/nrf9160/ns -- -DEXTRA_CONF_FILE=overlay-native_tls.conf

In that case I got the following error:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
-- west build: generating a build system
Loading Zephyr module(s) (Zephyr base): sysbuild_default
-- Found Python3: /home/user/ncs/toolchains/b81a7cd864/usr/local/bin/python3.12 (found suitable version "3.12.4", minimum required is "3.8") found components: Interpreter
-- Cache files will be written to: /home/user/.cache/zephyr
-- Found west (found suitable version "1.2.0", minimum required is "0.14.0")
-- Board: nrf9160dk, Revision: 0.14.0, qualifiers: nrf9160/ns
Parsing /home/user/workdir/zephyr/share/sysbuild/Kconfig
Loaded configuration '/home/user/workdir/nrf/applications/serial_lte_modem/build/_sysbuild/empty.conf'
Merged configuration '/home/user/workdir/nrf/applications/serial_lte_modem/build/_sysbuild/empty.conf'
Merged configuration '/home/user/workdir/nrf/applications/serial_lte_modem/sysbuild.conf'
Configuration saved to '/home/user/workdir/nrf/applications/serial_lte_modem/build/zephyr/.config'
Kconfig header saved to '/home/user/workdir/nrf/applications/serial_lte_modem/build/_sysbuild/autoconf.h'
--
*****************************
* Running CMake for mcuboot *
*****************************
Loading Zephyr default modules (Zephyr base).
-- Application: /home/user/workdir/bootloader/mcuboot/boot/zephyr
-- CMake version: 3.21.0
-- Found Python3: /home/user/ncs/toolchains/b81a7cd864/usr/local/bin/python (found suitable version "3.12.4", minimum required is "3.8") found components: Interpreter
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

It seems to me that there might be some misconfiguration with the build system. Any help would be much appreciated.