cortex-m icon indicating copy to clipboard operation
cortex-m copied to clipboard

Support Secure Mode for Armv8-m (e.g. Secture Interrupt Vector Table)

Open thejpster opened this issue 6 years ago • 8 comments

TrustZone in Armv8-m processors like the Cortex-M23 and Cortex-M33 supports a second 'secure' copy of registers like SysTick and VTOR. It also supports a second interrupt vector table.

I'd like to add support, but it should be behind a feature flag as not all Cortex-M23/33 implementations support Secure Mode.

References:

  • https://community.arm.com/cfs-file/__key/telligent-evolution-components-attachments/01-2057-00-00-00-01-28-35/Cortex_2D00_M-for-Beginners-2D00-2017_5F00_EN_5F00_v2.pdf
  • http://infocenter.arm.com/help/topic/com.arm.doc.ddi0550c/Cihjajhi.html

thejpster avatar Nov 10 '18 09:11 thejpster

Any news on this topic? We try to integrate the TZ features for Rust on the nRF9160 sip.

tothero avatar Apr 14 '20 18:04 tothero

Hi @tothero ! I am currently working (on the side) on enabling more and more TrustZone-M features in the Rust Embedded ecosystem. The two big ones right now are:

There is more to come and it's all slowly coming together 😃

hug-dev avatar Apr 14 '20 20:04 hug-dev

Hi, good to know that there is some progress :-)

Beside your topics these would also be from interest:

  • Automatic Import lib with veneer function entries creation during building the secure image.
  • Special output linker section support for the veneers to be defined as NSC.

Some times ago i wrote an overview article how the needed things are handled in the gcc @ https://www.lobaro.com/using-the-armv8-m-trustzone-with-gcc/

tothero avatar Apr 14 '20 21:04 tothero

Quick question - I see SAU support has been added for Cortex-M23/33 but I cant figure out a way to link non-secure and secure projects in Rust. My program flow is as follows -

  1. Upon boot, the processor defaults to its secure state.
  2. We configure SAU to split the entire memory map into one of NS, S, NSC memory regions.
  3. Add the compiler attribute (for now I'm only testing cmse_nonsecure_entry ) to a test secure function.
  4. Build the secure project.

But after this, how do I tell my non-secure project where to find the veneer function that acts a gateway to the actual secure function.

nihalpasham avatar Aug 01 '20 06:08 nihalpasham

I've done this by getting the address from an objdump, and casting a literal integer to a function reference type and calling that function.

thejpster avatar Aug 03 '20 08:08 thejpster

But after this, how do I tell my non-secure project where to find the veneer function that acts a gateway to the actual secure function.

This step would normally be done by the linker. It would name the veneer with the same name as the secure function so that Non-Secure code can just call it normally. Internally, the actual Secure Function is renamed and called by the veneer after doing the necessary prerequisites.

I say "normally" here because the cmse_nonsecure_entry is not yet supported 😢 But I am working on this actively now and will try to have at least something started by the end of the month.

hug-dev avatar Aug 03 '20 08:08 hug-dev

The cmse_nonsecure_entry attribute is now in and see rust-embedded/cortex-m-rt#297 as well!

hug-dev avatar Oct 01 '20 10:10 hug-dev

I wrote an example to use Rust to write Secure and Non-Secure World applications with TrustZone: https://github.com/luojia65/trustzone-m-rs

luojia65 avatar Mar 08 '22 06:03 luojia65