<?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>CryptoCell lazy initialization</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/127172/cryptocell-lazy-initialization</link><description>nrf5340 NCS 3.1.0 
 Hello, I am trying to improve boot time and here are some spikes and timings. What I have found out is that CryptoCell init (hw_cc3xx_init_internal) takes majority of PRE_KERNEL_1 time. As Crypto is not used early in the application</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 27 Feb 2026 15:10:26 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/127172/cryptocell-lazy-initialization" /><item><title>RE: CryptoCell lazy initialization</title><link>https://devzone.nordicsemi.com/thread/562238?ContentTypeID=1</link><pubDate>Fri, 27 Feb 2026 15:10:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fc88c181-9d1b-43f6-9f49-f1b69e5cba43</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Thank you for the update. I was actually just looking into this when you posted this. hw_cc3xx_init_internal() initializes the RNG by calling nrf_cc3xx_platform_init(). While&amp;nbsp;the zephyr,deferred-init property added to the cryptocell node correctly defers the entropy driver&amp;nbsp;initialisation, it&amp;nbsp;does not matter&amp;nbsp;because the RNG is already being initialised by hw_cc3xx_init_internal(), which is not gated by this&amp;nbsp;&lt;span&gt;zephyr,deferred-init&lt;/span&gt;&amp;nbsp;property that&amp;nbsp;only applies to device drivers.&lt;/p&gt;
&lt;p&gt;I did the following in my test:&lt;/p&gt;
&lt;p&gt;1. Patched the hw_cc3xx.c file with this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;diff --git a/drivers/hw_cc3xx/hw_cc3xx.c b/drivers/hw_cc3xx/hw_cc3xx.c
index b4218477e4..88d34b772d 100644
--- a/drivers/hw_cc3xx/hw_cc3xx.c
+++ b/drivers/hw_cc3xx/hw_cc3xx.c
@@ -25,13 +25,13 @@ static int hw_cc3xx_init_internal(void)
 	/* Initialize the cc3xx HW with or without RNG support */
 
 	/* Using same configurations as the users of entropy, see NCSDK-24914. */
-#if CONFIG_ENTROPY_CC3XX || defined(CONFIG_PSA_NEED_CC3XX_CTR_DRBG_DRIVER)
-	res = nrf_cc3xx_platform_init();
-#elif defined(CONFIG_PSA_NEED_CC3XX_HMAC_DRBG_DRIVER)
-	res = nrf_cc3xx_platform_init_hmac_drbg();
-#else
+//#if CONFIG_ENTROPY_CC3XX || defined(CONFIG_PSA_NEED_CC3XX_CTR_DRBG_DRIVER)
+//	res = nrf_cc3xx_platform_init();
+//#elif defined(CONFIG_PSA_NEED_CC3XX_HMAC_DRBG_DRIVER)
+//	res = nrf_cc3xx_platform_init_hmac_drbg();
+//#else
 	res = nrf_cc3xx_platform_init_no_rng();
-#endif
+//#endif
 
 	return res;
 }&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;2. Then made sure to initialise the device before enabling bluetooth:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;const struct device *c312 = DEVICE_DT_GET(DT_NODELABEL(cryptocell));

...

    err = device_init(c312);
	if (err) {
		printk(&amp;quot;Failed to initialize device: %s (err %s)&amp;quot;, c312-&amp;gt;name, err);
	}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t immediately see any problems with this approach but at a minimum you should check if there is anything else that tries to request entropy data on startup.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: CryptoCell lazy initialization</title><link>https://devzone.nordicsemi.com/thread/562228?ContentTypeID=1</link><pubDate>Fri, 27 Feb 2026 14:32:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e2e01976-48e1-4bd1-97a6-fe7fea6f3dc7</guid><dc:creator>Nemanja Jovicic</dc:creator><description>&lt;p&gt;HI &lt;a href="https://devzone.nordicsemi.com/members/vibe"&gt;Vidar Berg&lt;/a&gt;&amp;nbsp;&lt;br /&gt;&lt;br /&gt;It seems like I succeeded.&lt;br /&gt;&lt;br /&gt;What I&amp;#39;ve changed:&lt;br /&gt;&lt;br /&gt;nrf/drivers/hw_cc3xx/hw_cc3xx.c&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;
// Removed this SYS_INIT calls and made hw_cc3xx_init global function
/* Driver initalization done when mutex is not usable (pre kernel) */
SYS_INIT(hw_cc3xx_init_internal, PRE_KERNEL_1,
	 CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);

/* Driver initialization when mutex is usable (post kernel) */
SYS_INIT(hw_cc3xx_init, POST_KERNEL,
	 CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;nrf/drivers/entropy/entropy_cc3xx.c&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;// Changed this:
DEVICE_DT_DEFINE(CRYPTOCELL_NODE_ID, entropy_cc3xx_rng_init,
		 NULL, NULL, NULL, PRE_KERNEL_1,
		 CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &amp;amp;entropy_cc3xx_rng_api);

// To this:
DEVICE_DT_DEFINE(CRYPTOCELL_NODE_ID, NULL,
		 NULL, NULL, NULL, PRE_KERNEL_1,
		 CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &amp;amp;entropy_cc3xx_rng_api);
		 
// Made entropy_cc3xx_rng_init global function&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;nrf/subsys/nrf_security/src/zephyr/psa_crypto_init.c&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;// Removed this SYS_INIT call
SYS_INIT(_psa_crypto_init, POST_KERNEL,
	 CONFIG_KERNEL_INIT_PRIORITY_DEVICE);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;nrf/subsys/nrf_security/src/zephyr/mbedtls_heap.c&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;// Removed this SYS_INIT call and made mbedtls_heap_init global function
SYS_INIT(mbedtls_heap_init, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This is my work in progress lazy init piece of code that I can run from main or from work_q...&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;extern int hw_cc3xx_init(void);
extern int entropy_cc3xx_rng_init(const struct device *dev);
extern int mbedtls_heap_init(void);

static int lazy_crypto_init(void)
{
	static bool lazy_crypto_done = false;

	if (lazy_crypto_done) {
		return 0;
	}

	LOG_INF(&amp;quot;lazy start!!!!&amp;quot;);
	int res = hw_cc3xx_init();
	LOG_INF(&amp;quot;hw_cc3xx_init returned: %d&amp;quot;, res);

	if (res != 0) {
		LOG_ERR(&amp;quot;CC3XX init failed: %d&amp;quot;, res);
		return res;
	}

	const struct device *entropy_dev = DEVICE_DT_GET(DT_NODELABEL(cryptocell));
	if (entropy_dev == NULL) {
		LOG_ERR(&amp;quot;ERROR: Entropy device is NULL!&amp;quot;);
		return -ENODEV;
	}

	res = entropy_cc3xx_rng_init(entropy_dev);
	LOG_INF(&amp;quot;entropy_cc3xx_rng_init returned: %d&amp;quot;, res);

	psa_status_t err = psa_crypto_init();

	LOG_INF(&amp;quot;psa_crypto_init returned: %d&amp;quot;, err);
	if (err != PSA_SUCCESS) {

		LOG_ERR(&amp;quot;psa_crypto_init failed: %d&amp;quot;, err);
	}

	LOG_INF(&amp;quot;mbedtls_heap_init&amp;quot;);
	mbedtls_heap_init();

	lazy_crypto_done = true;
	return res;
}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;After this crypto lazy init I can setup BLE and run advertising. I&amp;#39;ve used PSA functions, I&amp;#39;ve did DFU over BLE.&lt;br /&gt;&lt;br /&gt;Do you see any possible downside here?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: CryptoCell lazy initialization</title><link>https://devzone.nordicsemi.com/thread/562136?ContentTypeID=1</link><pubDate>Thu, 26 Feb 2026 12:01:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:edb88eac-3198-4b8b-a8de-039e3cbce856</guid><dc:creator>Nemanja Jovicic</dc:creator><description>&lt;p&gt;Hello Vidar,&lt;br /&gt;Bluetooth is used, but also al later stage of the application.&lt;br /&gt;&lt;br /&gt;Basically Crypto and Bluetooth are used only to establish secure connection and transfer Firmware image for update.&lt;br /&gt;&lt;br /&gt;Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: CryptoCell lazy initialization</title><link>https://devzone.nordicsemi.com/thread/562133?ContentTypeID=1</link><pubDate>Thu, 26 Feb 2026 11:48:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bed303a2-be92-409d-8491-bd1d497a21d3</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t think it is possible with the current implementation, but I will investigate. Is your app using bluetooth? Reason for asking is that the stack requires the rng during init.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Vidar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>