<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Using a failed malloc inside my secure partition (TF-M) reboots the board instead of returning an error</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/92866/using-a-failed-malloc-inside-my-secure-partition-tf-m-reboots-the-board-instead-of-returning-an-error</link><description>Hi, 
 I&amp;#39;m using the following function in my project, in order to get an idea of how much memory can be reserved with malloc : 
 
 This function should return the last value of i that was tested. 
 When I use it from the main.c of my application (from</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 20 Oct 2022 12:13:00 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/92866/using-a-failed-malloc-inside-my-secure-partition-tf-m-reboots-the-board-instead-of-returning-an-error" /><item><title>RE: Using a failed malloc inside my secure partition (TF-M) reboots the board instead of returning an error</title><link>https://devzone.nordicsemi.com/thread/391650?ContentTypeID=1</link><pubDate>Thu, 20 Oct 2022 12:13:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:11251670-5451-46c6-886b-9b8f7e547d1f</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Pablo,&amp;nbsp;&lt;br /&gt;You can add the following:&amp;nbsp;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;pre class="ui-code" data-mode="text"&gt;Add this CMake code at the bottom of the app&amp;#39;s CMakeLists.txt.

set_property(
TARGET zephyr_property_target
APPEND PROPERTY TFM_CMAKE_OPTIONS

# Use -O0. So GDB reports correct line numbers.
-DCMAKE_BUILD_TYPE=Debug

# Halt instead of rebooting on internal TF-M faults.
-DTFM_HALT_ON_CORE_PANIC=ON

# NB: Probably not enough MPU regions on nrf53 in Isolation level 2
-DNULL_POINTER_EXCEPTION_DETECTION=ON

# Add a debug function that logs the memory protection config, and
# then invoke it from the SPE with log_memory_protection() to see
# the memory protection configuration.
-DLOG_MEMORY_PROTECTION=ON

# WDT will force tests to continue for certain types of TF-M
# tests. This can be inconvenient when debugging. But the WDT can
# also be a necessary part of the test execution.
# -DWATCHDOG_AVAILABLE=0
)

Add these Kconfig&amp;#39;s to your non-secure Zephyr application&amp;#39;s prj.conf:

CONFIG_TFM_PARTITION_LOG_LEVEL_DEBUG=y
CONFIG_TFM_SPM_LOG_LEVEL_DEBUG=y

# Dump exception info. Must be combined with enabling log output.
CONFIG_TFM_EXCEPTION_INFO_DUMP=y

# Don&amp;#39;t use the minimal TF-M configuration as that doesn&amp;#39;t support logging
CONFIG_TFM_PROFILE_TYPE_NOT_SET=y&lt;/pre&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;After that I can see FATAL ERROR: BusFault in the log.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;But we still troubling to find why we have a BusFault here.&amp;nbsp;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using a failed malloc inside my secure partition (TF-M) reboots the board instead of returning an error</title><link>https://devzone.nordicsemi.com/thread/391350?ContentTypeID=1</link><pubDate>Wed, 19 Oct 2022 08:21:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5c469e1f-c42c-4dc9-a0a9-325f8f956ea3</guid><dc:creator>Pablosanserr</dc:creator><description>&lt;p&gt;Hi Hung,&lt;/p&gt;
&lt;p&gt;Thank you for testing the code. I will try to post the question to &lt;a href="https://www.trustedfirmware.org/contact/"&gt;TF-M&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;However, to try to get more information about the error, shouldn&amp;#39;t some message be displayed when a hardfault occurs? Is there a configuration to enable that?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Pablo&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using a failed malloc inside my secure partition (TF-M) reboots the board instead of returning an error</title><link>https://devzone.nordicsemi.com/thread/391206?ContentTypeID=1</link><pubDate>Tue, 18 Oct 2022 13:23:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f1902974-638e-4a0d-8114-377df3f1cc97</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Thanks Pablo for the code. As you call the function directly inside&amp;nbsp;tfm_dp_secret_digest_req() I guess it has nothing to do with the IPC or TF-M library.&amp;nbsp;&lt;br /&gt;I have reproduced the same issue here and also checked internally with our team but we don&amp;#39;t know what caused the fault.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This issue is a little bit outside of our knowledge. I would suggest to post the question to &lt;a href="https://www.trustedfirmware.org/contact/"&gt;TF-M&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using a failed malloc inside my secure partition (TF-M) reboots the board instead of returning an error</title><link>https://devzone.nordicsemi.com/thread/391127?ContentTypeID=1</link><pubDate>Tue, 18 Oct 2022 09:01:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:53c82b40-a29e-4144-8122-28cdf0152a38</guid><dc:creator>Pablosanserr</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I am using TFM library. It would be desirable to use IPC API?&lt;/p&gt;
&lt;p&gt;I have reproduced the same problem in the tfm_secure_partition example, in order to separate it from other possible problems in my project. I builded the application for ncs 2.0.0.&lt;/p&gt;
&lt;p&gt;I attach the tfm_secure_partition project with the GetFreeMemorySize function so you can reproduce the problem. You will be able to see that it runs first on the main (non-secure partition) and then fails when it runs on the secure partition.&lt;/p&gt;
&lt;p&gt;Project:&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/tfm_5F00_secure_5F00_partition.zip"&gt;devzone.nordicsemi.com/.../tfm_5F00_secure_5F00_partition.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I have added the CONFIG_RESET_ON_FATAL_ERROR=n option and this is what is shown in the outputs:&lt;/p&gt;
&lt;p&gt;&lt;span style="text-decoration:underline;"&gt;&lt;em&gt;&lt;strong&gt;Application output&lt;/strong&gt;&lt;/em&gt;&lt;/span&gt;:&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1666083053927v1.png" /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="text-decoration:underline;"&gt;&lt;em&gt;TF-M output&lt;/em&gt;&lt;/span&gt;&lt;/strong&gt;:&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1666083257908v2.png" /&gt;&lt;/p&gt;
&lt;p&gt;What I want to do is that the function ends and returns a value, as it does from the non-secure partition. I would like to know how to prevent malloc from causing that error, or know if there is another alternative to malloc.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Pablo&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using a failed malloc inside my secure partition (TF-M) reboots the board instead of returning an error</title><link>https://devzone.nordicsemi.com/thread/390965?ContentTypeID=1</link><pubDate>Mon, 17 Oct 2022 11:12:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:14c8b09f-ae55-4bf7-b89e-c865d9086631</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Pablo,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Could you provide the project and files you used for the TF-M setup ? Did you use IPC API or use the TFM library ?&amp;nbsp;&lt;br /&gt;From my understanding it might be the feature of TF-M that it doesn&amp;#39;t allow you to malloc out size of the secure area and will trigger a hardfault. This explain the board reset you observed.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;I will check with the team here. Would be nice to have&amp;nbsp;your project source to test.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Have you tried to configure&amp;nbsp;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_RESET_ON_FATAL_ERROR&lt;/span&gt;&lt;span&gt;=n&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;And check if you have any log ?&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>