Hello! Welcome to the next lesson in your preparation for the embedded driver development role.
In our last session, we dove deep into the AUTOSAR MCAL layer, implementing a Can driver. We saw how a hardware-specific driver interfaces with the hardware-abstracted CanIf layer. Today, we're moving from a single peripheral to a core architectural feature of the processor itself: security.
Your learning goal for this lesson is to describe the ARM TrustZone architecture for separating Secure and Non-Secure worlds.
Understanding TrustZone is essential for modern embedded systems, especially in automotive, where protecting critical functions like ADAS, secure boot, and over-the-air updates from potential vulnerabilities in less-critical systems (like infotainment) is paramount. Given your background in ISO 26262 and complex system design, you'll see how this hardware feature provides a fundamental building block for both security and functional safety.
1. The Core Concept: Two Worlds, One Processor
At its heart, ARM TrustZone is a hardware security extension that partitions a single processor and the entire System-on-Chip (SoC) into two isolated environments:
- The Normal World: Also called the Rich Execution Environment (REE). This is where a complex, feature-rich OS like Linux or Android, along with its applications, typically runs. Due to its size and complexity, it has a larger "attack surface" and is considered less trusted.
- The Secure World: Also called the Trusted Execution Environment (TEE). This is a smaller, more secure environment designed to run a minimal, highly-vetted secure OS and trusted applications that handle sensitive data and operations.
The goal is to provide a hardware-enforced "firewall" so that even if the Normal World is compromised by malware, the assets within the Secure World remain protected.
Learn the architecture - TrustZone for AArch64
To start, let's read a short introduction from ARM's architectural documentation that formally defines these two worlds.
Please read the section '2. What is TrustZone?'. This will introduce you to the concepts of the Normal and Trusted worlds and the motivation behind them.
To see how this applies in practice, let's watch a brief video that gives concrete examples of what kind of tasks are allocated to each world.
#34 ARM Trustzone | Information Security 5 Secure Systems Engineering
This clip from NPTEL-NOC IITM explains the basic partitioning and provides examples of sensitive tasks handled by the Secure World.
Watch the segment from 02:24 to 04:54. Focus on the examples given, such as encryption, password handling, and how a system might switch between worlds to perform a sensitive operation.
2. The Foundation: Hardware-Enforced Isolation
The isolation between the Secure and Normal worlds is not just a software convention; it's enforced by the processor and SoC hardware at a fundamental level. This enforcement happens in three key areas: processor state, memory, and peripherals.
Processor State
The processor core itself is always aware of its current security state.
- In older ARM architectures (like ARMv7), this is managed by the
NS(Non-Secure) bit in the Secure Configuration Register (SCR). - In the ARMv8-A architecture, security state is integrated with the Exception Level model. EL3 is always Secure, and it controls whether EL2, EL1, and EL0 are in Secure or Non-secure state via the
SCR_EL3.NSbit.
When the processor is in the Non-secure state, its ability to access certain system resources and execute privileged instructions is restricted by the hardware.
Memory and Peripheral Isolation
This is the most critical aspect of the hardware enforcement. The system bus is extended with an additional signal, often conceptualized as a "33rd bit" on a 32-bit address bus, which indicates whether a memory access is Secure or Non-secure.
- Two Physical Address Spaces: TrustZone effectively creates two parallel physical address spaces: Secure and Non-secure. This means that physical address
0x8000_0000in the Secure space is a completely different location from physical address0x8000_0000in the Non-secure space. - Access Control Rules:
- When the processor is in Non-secure state, it can only generate Non-secure memory accesses. Any attempt to access an address marked as Secure will be blocked by the hardware and will trigger a fault exception.
- When the processor is in Secure state, it can access both Secure and Non-secure memory. The Memory Management Unit (MMU) uses a special
NSbit in its page table entries to determine which physical address space a given virtual address should map to.
This principle extends beyond the processor to the entire SoC. Peripherals on the bus (like DMA controllers, crypto accelerators, or specific GPIO banks) can be configured to be Secure or Non-secure, meaning they will only respond to transactions with the correct security attribute.
The following video provides a detailed look at how the MMU and even the CPU caches are made "TrustZone-aware" to enforce this isolation.
#34 ARM Trustzone | Information Security 5 Secure Systems Engineering
This section of the NPTEL video details the hardware mechanisms behind isolation, including the NS bit, and its effect on the MMU, Translation Lookaside Buffer (TLB), and cache.
Watch from 10:00 to 18:28. Pay close attention to how the NS bit is propagated through the system and how the MMU uses it to select the correct set of page tables for address translation.
Test your understanding!
A piece of code running in the Normal World (e.g., a Linux driver) attempts to directly read a register from a cryptographic accelerator peripheral that has been configured as a Secure peripheral. What will happen?
Show answer
The processor, running in Non-secure state, will place a Non-secure read request onto the system bus. The bus interconnect hardware or the peripheral itself will see that the target address belongs to a Secure-only resource. It will block the access and signal a bus fault back to the processor, which will then trigger an exception (e.g., a synchronous Data Abort). The read will fail, and the Normal World OS will have to handle the fault.
3. Crossing the Boundary: The Secure Monitor
Since the two worlds are strictly isolated, how does the Normal World ask the Secure World to perform a service, like encrypting data? Direct calls are forbidden.
The only way to transition between worlds is by triggering an exception that is routed to the highest privilege level in the Secure state:
- In ARMv8-A, this is Exception Level 3 (EL3).
- In older ARM architectures, this is a special mode called Monitor Mode.
The software running at this level is called the Secure Monitor. It acts as the sole gatekeeper between the two worlds.
A transition is typically initiated in one of two ways:
- Software Request: The Normal World executes a
SMC(Secure Monitor Call) instruction. This is a deliberate trap into the Secure Monitor to request a specific service. - Hardware Interrupt: An interrupt (IRQ or FIQ) can be configured to always be taken by the Secure Monitor first. The Monitor can then process the interrupt or decide to forward it to the Normal World for handling.
When a transition occurs, the Secure Monitor is responsible for:
- Saving the full context (registers) of the current world.
- Switching the processor's security state.
- Restoring the context of the world being switched to.
This context switching is crucial for maintaining the isolation.
Learn the architecture - TrustZone for AArch64
This ARM guide explains the role of EL3 and the Secure Monitor in managing the switch between security states.
Read the subsections 'Security States' and 'Switching between Security states' within section '3. TrustZone in the processor'. This will show you how EL3 is the root of trust and how it orchestrates the world switch.
4. Cortex-A vs. Cortex-M: Different Architectures, Same Goal
While you are likely familiar with Cortex-A series processors from ADAS platforms, you may also encounter Cortex-M microcontrollers which also feature TrustZone. The implementation, called TrustZone-M, is adapted for the simpler architecture of MCUs.

The key differences are:
- Memory Partitioning: Cortex-M processors lack an MMU. Instead, they use a Security Attribution Unit (SAU) (and optionally a vendor-specific IDAU) to define regions of the flat memory map as Secure, Non-secure, or Non-secure Callable (NSC).
- World Transitions: Instead of a full-blown Secure Monitor, transitions from the Non-secure to the Secure world are made through special functions located in the NSC memory region. These functions use a
SG(Secure Gateway) instruction, which acts as a controlled entry point into the Secure world. This is a much more lightweight mechanism suitable for MCUs.
36C3 - TrustZone-M(eh): Breaking ARMv8-M's security
This video, though focused on security vulnerabilities, provides an excellent introduction to the specific mechanics of TrustZone-M.
Watch the two segments. The first (06:44 - 08:54) explains the concept of Non-Secure Callable (NSC) memory and the Secure Gateway (SG) instruction. The second (08:43 - 10:40) introduces the Security Attribution Unit (SAU) and how it's used to define secure memory regions.
Understanding both implementations is valuable, as you may encounter SoCs that use Cortex-A for the main application processing and an embedded Cortex-M as a dedicated secure enclave or safety island.
5. Interview Corner
Q1: What is ARM TrustZone and what fundamental problem does it solve in an embedded system?
A: ARM TrustZone is a system-wide security architecture that partitions the processor and SoC into two isolated environments: a Secure World and a Normal World. It solves the problem of protecting critical assets (like keys, cryptographic operations, and secure firmware) from a large and potentially vulnerable software stack (like a rich OS and third-party apps). By using hardware enforcement, it ensures that even if the Normal World is compromised, the Secure World remains intact.
Q2: How does TrustZone enforce isolation between the Secure and Non-Secure worlds? Describe the key hardware mechanisms.
A: The isolation is hardware-enforced. First, the processor has a distinct Security State (Secure or Non-secure). Second, the memory system is partitioned into two physical address spaces. An extra bus signal indicates the security of each transaction. The hardware enforces a strict rule: code running in the Non-secure state can only make Non-secure accesses. An attempt to access a Secure memory location or peripheral results in a hardware fault. Code in the Secure state can access both, with the target address space determined by the MMU/SAU configuration. This extends to caches, MMUs, and peripherals across the SoC, which are all "TrustZone-aware".
Q3: A developer wants the infotainment system (running in the Normal World) to get a unique device ID that is stored in a protected fuse box (a Secure peripheral). How can this be achieved using TrustZone?
A: Direct access is not possible or allowed. The correct architectural approach is for the infotainment application to make a system call to its OS, which then executes an SMC (Secure Monitor Call) instruction. This traps execution into the Secure Monitor (at EL3). The SMC call would have parameters indicating a request for the device ID. The Secure Monitor would then switch context to a trusted application in the Secure World. This trusted application would read the device ID from the Secure fuse box peripheral and then return the value back to the Secure Monitor. The Monitor would then switch context back to the Normal World, delivering the device ID as the return value from the original SMC call. This ensures the Normal World never directly accesses the secure hardware.
Conclusion
In this lesson, we explored the ARM TrustZone architecture, a cornerstone of modern embedded system security. You learned how it creates a hardware-enforced separation between a trusted, secure environment and a less-trusted, normal environment.
Key Takeaways:
- TrustZone divides a system into an isolated Secure World (for trusted code/data) and a Normal World (for rich OS/apps).
- Isolation is enforced by hardware: the processor's security state, separate physical address spaces, and access control logic in the memory system and peripherals that check the
NS(Non-secure) attribute of every transaction. - Transitions between worlds are arbitrated exclusively by a highly privileged Secure Monitor (running in Monitor Mode or EL3).
- The Normal World deliberately requests services from the Secure World using the
SMCinstruction. - The architecture is adapted for different processor profiles, with TrustZone-M for Cortex-M MCUs using an SAU and Secure Gateways instead of an MMU and a full monitor.
Next Lesson Preview:
Now that we understand the architecture of TrustZone, our next step is to see how these worlds communicate in practice. In the next lesson, we will focus on implementing a Secure Monitor Call (SMC) to transition from the Non-Secure world to the Secure world to execute a protected function.