<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Reading writing CAAM MCFGR, DECORR from Linux when TrustZone is enabled in i.MX Processors</title>
    <link>https://community.nxp.com/t5/i-MX-Processors/Reading-writing-CAAM-MCFGR-DECORR-from-Linux-when-TrustZone-is/m-p/736860#M114692</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So this text in the NXP document describes the behaviour I'm seeing exactly&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;NOTE&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;The CAAM address space is divided into 16 4 KB pages to&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;match the access granularity of the MMU. Registers that are&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;intended to be accessed by a specific processor or process are&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;grouped into one of these 16 pages so that access to these&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;registers can be restricted via CAAM's own MID-based access&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;control mechanism, or via the CPU's MMU. For instance, the&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;general configuration and status registers are located within&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;page 0 and are intended to be accessed only by privileged&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;software. The registers that control each job ring are located in&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;a separate address block so that access to each job ring can be&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;restricted to a particular process. Some registers, such as the&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;version ID registers, are intended to be shared among processes.&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;Rather than require each CAAM driver process to have two&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;MMU page entries, one page for its private registers and one&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;for the shared registers, CAAM "aliases" these shared registers&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;into the upper section of each of the 16 address blocks. Reading&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;any one of the address aliases for the same register returns the&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;same information. Some of these aliased registers are writable,&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;so access to these registers may require that software implement&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;a concurrency control construct, as would be the case with any&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;register that is read/write accessible by multiple processes.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-weight: normal;"&gt;The only question is - how do we tell the MMU (or is it the CAAM MID ) to assign control of page 0 over to Linux instead of TEE/TrustZone....&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 22 Dec 2017 00:27:53 GMT</pubDate>
    <dc:creator>bryan_odonoghue</dc:creator>
    <dc:date>2017-12-22T00:27:53Z</dc:date>
    <item>
      <title>Reading writing CAAM MCFGR, DECORR from Linux when TrustZone is enabled</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/Reading-writing-CAAM-MCFGR-DECORR-from-Linux-when-TrustZone-is/m-p/736859#M114691</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;On an i.MX7Solo I find that when TrustZone is enabled MCFGR, DECORR return zeros instead of valid data when read/written from the upstream Linux CAAM driver.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The problem is described here :&amp;nbsp;&lt;A class="link-titled" href="https://github.com/OP-TEE/optee_os/issues/1408" title="https://github.com/OP-TEE/optee_os/issues/1408"&gt;Kernel panic with CAAM on IMX6UL EVK? · Issue #1408 · OP-TEE/optee_os · GitHub&lt;/A&gt;&amp;nbsp;&amp;nbsp;and you can see I've added my own input.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The only description of this behaviour I can find similar in "Security Reference Manual for i.MX 7Dual and 7Solo Applications Processors, Rev. 0, 03/2017" is at&amp;nbsp;9.9 SNVS Register Descriptions which states&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"Privileged read/write accessible registers can only be accessed for read/write by&lt;BR /&gt;privileged software. Unauthorized write accesses are ignored, and unauthorized read&lt;BR /&gt;accesses return zero"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I can confirm however that the SNVS Command Register has the "Non-Privileged Software Access Enable" bit set to 1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HPCOMPR =&amp;nbsp;0x80002100&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It is possible to read valid data from the alias registers later on in the memory map. For example CAAM Status (CSTA) @ 0xFD4 returns valid and expected data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Could NXP provide some guidance on how and why the MCFGR and DECORR registers are returning zero to Linux when TrustZone is enabled and how to correctly map those registers into a non-TrustZone context ?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Dec 2017 01:28:16 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/Reading-writing-CAAM-MCFGR-DECORR-from-Linux-when-TrustZone-is/m-p/736859#M114691</guid>
      <dc:creator>bryan_odonoghue</dc:creator>
      <dc:date>2017-12-21T01:28:16Z</dc:date>
    </item>
    <item>
      <title>Re: Reading writing CAAM MCFGR, DECORR from Linux when TrustZone is enabled</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/Reading-writing-CAAM-MCFGR-DECORR-from-Linux-when-TrustZone-is/m-p/736860#M114692</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So this text in the NXP document describes the behaviour I'm seeing exactly&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;NOTE&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;The CAAM address space is divided into 16 4 KB pages to&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;match the access granularity of the MMU. Registers that are&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;intended to be accessed by a specific processor or process are&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;grouped into one of these 16 pages so that access to these&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;registers can be restricted via CAAM's own MID-based access&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;control mechanism, or via the CPU's MMU. For instance, the&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;general configuration and status registers are located within&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;page 0 and are intended to be accessed only by privileged&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;software. The registers that control each job ring are located in&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;a separate address block so that access to each job ring can be&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;restricted to a particular process. Some registers, such as the&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;version ID registers, are intended to be shared among processes.&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;Rather than require each CAAM driver process to have two&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;MMU page entries, one page for its private registers and one&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;for the shared registers, CAAM "aliases" these shared registers&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;into the upper section of each of the 16 address blocks. Reading&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;any one of the address aliases for the same register returns the&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;same information. Some of these aliased registers are writable,&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;so access to these registers may require that software implement&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;a concurrency control construct, as would be the case with any&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;register that is read/write accessible by multiple processes.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-weight: normal;"&gt;The only question is - how do we tell the MMU (or is it the CAAM MID ) to assign control of page 0 over to Linux instead of TEE/TrustZone....&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 Dec 2017 00:27:53 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/Reading-writing-CAAM-MCFGR-DECORR-from-Linux-when-TrustZone-is/m-p/736860#M114692</guid>
      <dc:creator>bryan_odonoghue</dc:creator>
      <dc:date>2017-12-22T00:27:53Z</dc:date>
    </item>
    <item>
      <title>Re: Reading writing CAAM MCFGR, DECORR from Linux when TrustZone is enabled</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/Reading-writing-CAAM-MCFGR-DECORR-from-Linux-when-TrustZone-is/m-p/736861#M114693</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Bryan,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;We are discussing your issue internally, but since this are holidays, the answer can be a little delay.&amp;nbsp; I apologize for the inconvenience.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Happy New Year 2018&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Dec 2017 18:49:22 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/Reading-writing-CAAM-MCFGR-DECORR-from-Linux-when-TrustZone-is/m-p/736861#M114693</guid>
      <dc:creator>jamesbone</dc:creator>
      <dc:date>2017-12-29T18:49:22Z</dc:date>
    </item>
    <item>
      <title>Re: Reading writing CAAM MCFGR, DECORR from Linux when TrustZone is enabled</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/Reading-writing-CAAM-MCFGR-DECORR-from-Linux-when-TrustZone-is/m-p/736862#M114694</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Poking about about I've managed to get this working.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There are two things that need to happen on MX7 at least for me&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#1 Assign ownership of the job-ring registers to non-secure mode - prior to enabling trust zone&lt;/P&gt;&lt;P&gt;In u-boot I do this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;diff --git a/drivers/crypto/fsl/jr.c b/drivers/crypto/fsl/jr.c&lt;BR /&gt;index 986eabf..ad2bd43 100644&lt;BR /&gt;--- a/drivers/crypto/fsl/jr.c&lt;BR /&gt;+++ b/drivers/crypto/fsl/jr.c&lt;BR /&gt;@@ -573,6 +573,15 @@ int sec_init_idx(uint8_t sec_idx)&lt;BR /&gt; uint32_t liodn_ns;&lt;BR /&gt; uint32_t liodn_s;&lt;BR /&gt; #endif&lt;BR /&gt;+ uint32_t ns_toggle;&lt;BR /&gt;+&lt;BR /&gt;+ printf("JR0 ms=0x%08x ls=0x%08x\n",&lt;BR /&gt;+ sec-&amp;gt;jrliodnr[0].ms,&lt;BR /&gt;+ sec-&amp;gt;jrliodnr[0].ls);&lt;BR /&gt;+&lt;BR /&gt;+ printf("JR1 ms=0x%08x ls=0x%08x\n",&lt;BR /&gt;+ sec-&amp;gt;jrliodnr[1].ms,&lt;BR /&gt;+ sec-&amp;gt;jrliodnr[1].ls);&lt;BR /&gt; &lt;BR /&gt; if (!(sec_idx &amp;lt; CONFIG_SYS_FSL_MAX_NUM_OF_SEC)) {&lt;BR /&gt; printf("SEC initialization failed\n");&lt;BR /&gt;@@ -621,6 +630,22 @@ int sec_init_idx(uint8_t sec_idx)&lt;BR /&gt; #endif&lt;BR /&gt; #endif&lt;BR /&gt; &lt;BR /&gt;+ ns_toggle = sec_in32(&amp;amp;sec-&amp;gt;jrliodnr[0].ms);&lt;BR /&gt;+ ns_toggle |= 0x08;&lt;BR /&gt;+ sec_out32(&amp;amp;sec-&amp;gt;jrliodnr[0].ms, ns_toggle);&lt;BR /&gt;+&lt;BR /&gt;+ ns_toggle = sec_in32(&amp;amp;sec-&amp;gt;jrliodnr[1].ms);&lt;BR /&gt;+ ns_toggle |= 0x08;&lt;BR /&gt;+ sec_out32(&amp;amp;sec-&amp;gt;jrliodnr[1].ms, ns_toggle);&lt;BR /&gt;+&lt;BR /&gt;+ printf("JR0 ms=0x%08x ls=0x%08x\n",&lt;BR /&gt;+ sec-&amp;gt;jrliodnr[0].ms,&lt;BR /&gt;+ sec-&amp;gt;jrliodnr[0].ls);&lt;BR /&gt;+&lt;BR /&gt;+ printf("JR1 ms=0x%08x ls=0x%08x\n",&lt;BR /&gt;+ sec-&amp;gt;jrliodnr[1].ms,&lt;BR /&gt;+ sec-&amp;gt;jrliodnr[1].ls);&lt;BR /&gt;+&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#2 Skip RNG initialisation in Linux (thanks to Peng Fan) in NXP for this suggestion&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c&lt;BR /&gt;index 98468b9..a79e11e 100644&lt;BR /&gt;--- a/drivers/crypto/caam/ctrl.c&lt;BR /&gt;+++ b/drivers/crypto/caam/ctrl.c&lt;BR /&gt;@@ -693,6 +693,7 @@ static int caam_probe(struct platform_device *pdev)&lt;BR /&gt; kick_trng(pdev, ent_delay);&lt;BR /&gt; ent_delay += 400;&lt;BR /&gt; }&lt;BR /&gt;+ #if 0&lt;BR /&gt; /*&lt;BR /&gt; * if instantiate_rng(...) fails, the loop will rerun&lt;BR /&gt; * and the kick_trng(...) function will modfiy the&lt;BR /&gt;@@ -708,6 +709,9 @@ static int caam_probe(struct platform_device *pdev)&lt;BR /&gt; * so don't hog the CPU&lt;BR /&gt; */&lt;BR /&gt; cpu_relax();&lt;BR /&gt;+ #else&lt;BR /&gt;+ dev_info(dev, "Relying on bootloader CAAM RNG init\n");&lt;BR /&gt;+ #endif&lt;BR /&gt; } while ((ret == -EAGAIN) &amp;amp;&amp;amp; (ent_delay &amp;lt; RTSDCTL_ENT_DLY_MAX));&lt;BR /&gt; if (ret) {&lt;BR /&gt; dev_err(dev, "failed to instantiate RNG");&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Jan 2018 10:54:31 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/Reading-writing-CAAM-MCFGR-DECORR-from-Linux-when-TrustZone-is/m-p/736862#M114694</guid>
      <dc:creator>bryan_odonoghue</dc:creator>
      <dc:date>2018-01-11T10:54:31Z</dc:date>
    </item>
  </channel>
</rss>

