AN5365 SAM L11 Security Reference Guide Introduction This document is intended to help the developer to use SAM L11 security features for building secure embedded applications. The following application development aspects are covered in this document: • Single and dual developer approach •...
Introduction to SAM L11 Security Features TrustZone for ARMv8-M The central security element for the Microchip SAM L11 microcontroller (MCU) is the implementation of the TrustZone for an ARMv8-M device. The TrustZone technology is a System-on-Chip (SoC) and MCU system-wide approach to security that enables Secure and Non-Secure application code to run on a single MCU.
Page 4
AN5365 Introduction to SAM L11 Security Features Figure 1-2. IDAU Interface and Memory Accesses Core/Debugger access Address IDAU IDAU Responder Interface S / NS / NCS Combine Non- Secure Secure Access to memory Cortex-M23 SAM L11 Thanks to this implementation, a simple function call or an interrupt processing results in a branch to a specific security state as illustrated in the figure below.
Page 5
1.1.1 Memory Security Attribution To differentiate and isolate the Secure code from the Non-Secure code, the SAM L11 memory is divided into ten memory regions as shown in the figure below. Each region size can be configured using dedicated NVM fuses, such as BS, BNSC, BOOTPROT, AS, ANSC, DS, and RS.
Page 6
AN5365 Introduction to SAM L11 Security Features At the software architecture level, specific Secure and Non-Secure function call mechanisms must be used to ensure security, which are described in the following sections: 1.1.2.1 Non-Secure Callable APIs When working with TrustZone for ARMv8-M, the application developer can define a set of Non-Secure callable APIs which can be used to access the Secure code from the Non-Secure world.
Page 7
AN5365 Introduction to SAM L11 Security Features Secure_function.c (linked in the secure memory region of the device): int secure_func1(int x) return x + 3; 1.1.2.2 Non-Secure Software Callbacks The Secure code can define and use software callbacks to execute functions from the Non-Secure world.
Page 8
AN5365 Introduction to SAM L11 Security Features Figure 1-7. Non-Secure Software Callback Mechanism Note: The definition of Non-Secure software callback is done through pointer to Non-Secure code location . If not correctly checked in the Secure application, a wrong use of pointers can lead to security weakness that enables execution of any Secure functions by the Non-Secure code.
Figure 1-9. Cortex-M 23 Interrupt Mechanism Secure and Non-Secure Peripherals The SAM L11 extends the concept of TrustZone to its integrated peripherals and offers the possibility to allocate specific peripheral to Secure and Non-Secure world. the management of each peripheral security attribution is done through the Peripheral Access Controller (PAC).
Important: The peripherals security attribution cannot be changed by accessing the PAC.NONSECx registers during application run-time. Any changes must be done using the User Row fuses and require a reset of the SAM L11 device. The application can read the PAC.NONSECx register to get the current attribution of integrated peripherals.
Page 11
AN5365 Introduction to SAM L11 Security Features • Event System (EVSYS): Supports individual assignment of each event channel to the Secure or Non- Secure applications. The capability for a Mix-Secure peripheral to share its internal resources depends on the security attribution of that peripheral in the PAC peripheral (PAC Secured or PAC Non-Secured).
Page 12
AN5365 Introduction to SAM L11 Security Features Figure 1-12. NONSEC Register The NONSEC register content can only be modified by the Secure world through the peripheral register Secure alias (PERIPH_SEC.NONSEC). Setting a specific internal feature bit field in the NONSEC register, enables the access to the different bit fields associated to this feature in the peripheral Non-Secure alias.
Non-Secure peripheral. Debug Access Level (DAL) and Chip Erase SAM L11 has the following configurable debug access levels (DAL), which restrict programming and debug access to Secure and Non-Secure resources in the system. • DAL2: Debug access with no restrictions in terms of memory and peripheral accesses.
Page 14
AN5365 Introduction to SAM L11 Security Features Figure 1-14. ChipErase Commands Secure Flash (BOOT Region) Non‐Secure Callable Flash (BOOT Region) Non‐Secure Flash (BOOT Region) Secure Flash (APPLICATION Region) Non‐Secure Callable Flash (APPLICATION Region) Non‐Secure Flash (APPLICATION Region) CMD CEx : NS S All Secure Data Flash Non‐Secure Data Flash CMD CEx : NS S All The configuration of the ChipErase command protection Key is done through the BOCOR bit field configuration, as shown in the following figure.
Page 15
AN5365 Introduction to SAM L11 Security Features Figure 1-15. SAM L11 Configurable ChipErase Key Fuses The different ChipErase commands are used to increase the DAL level without compromising the code security. Therefore, erase the code before changing to a higher DAL level, as illustrated in the figure below.
Figure 1-18. ChipErase Key Fuses Setting Under AS7 Device Programming Secure Boot The SAM L11 Boot ROM is always executed at product startup. This software is ROM coded into the device and cannot be bypassed by the user. Depending on the Boot Configuration Row (BOCOR) fuse setting, the Boot ROM knows if a Secure Boot region is defined in the system.
Page 18
AN5365 Introduction to SAM L11 Security Features Figure 1-19. Secure Boot Process with BS+BNSC Verification Boot ROM ‐ Verify Secure Boot Region (optional) 0x0000 0000 ‐ Jump at address Secure Flash 0x00000000 (BOOT Region) BS x 0x100 – BNSC x 0x20 Non‐Secure Callable Flash (BOOT Region) BS x 0x100 Non‐Secure Flash (BOOT Region) Secure Flash (APPLICATION Region) Non‐Secure Callable Flash (APPLICATION Region) Non‐Secure Flash ...
Page 19
AN5365 Introduction to SAM L11 Security Features Figure 1-20. Boot Secure Reference Hash Location If the verification result is equal to the reference hashes, the Boot ROM starts the Secure Bootloader execution. Any mismatch in the value puts the device in an endless reset loop preventing Flash code execution.
Atmel Studio 7 integrated development platform provides a full set of advanced features to accelerate the development of a SAM L11 application. The following sections illustrate the approaches to be followed by Customer A and Customer B to create and customize their application.
Customer A and Customer B. Develop a Secure Solution (Customer A) To help Customer A to start with SAM L11 (regardless of single or dual developer approaches), Atmel Studio 7 provides a pre-configured Secure Solution template that illustrates the basic Secure and Non- Secure application execution as shown in the figure below.
Page 23
Function call TrustZone for Cortex‐M 2.3.1 Creating SAM L11 Secure Solution from Atmel Studio Secure Solution Template Creating a Secure Solution from the pre-configured template available in Atmel Studio 7 can be done by following these steps : Open Atmel Studio 7.
Page 26
2.3.2.1 Secure Project Description The goal of the Secure project included in the SAM L11 Secure Solution template is to provide a preconfigured development base for Secure code development on SAM L11. The Secure project is preconfigured to illustrate the following applicative aspects of a standard Secure application on SAM L11: •...
Page 27
2.3.2.2 Non-Secure Project Description The Non-Secure project provided within the SAM L11 Secure Solution Template is a standard application that runs in a Non-Secure world. This application can use all system resources allocated to the Non- Secure world. It uses pre-programmed Non-Secure Callable (NSC) functions using the veneer.h file provided by the Secure application.
Page 29
(including Customer A) until the next boot. Note: The description of the SAM L11 Boot ROM can be found in the “Boot ROM “ chapter of the “ SAM L10/L11 Data Sheet” (DS60001513).
Page 31
AN5365 SAM L11 Application Development (Customer A ... 2.3.2.4 Secure and Non-Secure Projects Linker Files Secure and Non-Secure projects have their own pre-configured linker files which are available in their Device_Startup directory. The content of these files is aligned to the memory mapping defined by the saml11_urow.h and saml11_bocor.h as shown in the figure below.
Page 32
Ensure that the debugger is connected to a computer and SAM L11. Click (Alt+F5) to start debugging and automatically break on the Secure main function.
Page 34
AN5365 SAM L11 Application Development (Customer A ... Add a breakpoint on the return line of func1 in the Secure project Secure_Functions/secure.c file. Figure 2-16. Breakpoint on func1 Call (Secure Project) When debugging the Secure application veneers, only hardware breakpoints must be CAUTION used to stop code execution on an SG instruction.
Page 36
Close the debug session (if running). Open the Device Programming tool by selecting Tools > Device Programming. Send the DAL1 command to the target SAM L11 device as shown in the following figure: 3.1. Select the EDBG Device Programming tool, and then click Apply.
Page 38
AN5365 SAM L11 Application Development (Customer A ... As a result, setting DAL1 prevents any future debug access to the Secure memory region of the device, as shown in the figure below. Figure 2-20. DAL Protected Device Memory Region 0x0000 0000 Not accessible BS x 0x100 –...
Page 39
AN5365 SAM L11 Application Development (Customer A ... Any future debug access to the Secure memory region will be refused by the device and reported as follows by Atmel Studio 7, as shown in the following figure. Figure 2-21. Launch Failed error on DAL Protected Area Important: ...
Ideally, the approach should be for Customer A to provide a Non-Secure project template to Customer B. The following sections describe how to create and configure a Non-Secure project for a SAM L11 device embedding a pre-programmed DAL1 protected Secure application.
Page 41
Select the ATSAML11E16A device in the Device Selection window, and then click OK. Figure 2-24. SAM L11 Product Selection for New SAM L11 Standalone Non-Secure Project The Non-Secure project appears in Atmel Studio 7 IDE, as shown in the following figure.
Page 42
AN5365 SAM L11 Application Development (Customer A ... Figure 2-25. Standalone SAM L11 Non-Secure Project 2.4.2 Project Configuration After creating a Non-Secure project, follow these steps to configure it according to the pre-programed Secure project mapping and Secure gateway APIs: • Configure the project by aligning its linker file to the Secure and Non-Secure memories attribution predefined by Customer A.
Page 43
SAM L11 Application Development (Customer A ... 2.4.2.1 Align Project Linker File to the SAM L11 Non-Secure Memories Attribution Follow these steps to modify the Non-Secure solution project linker file according to the Secure and Non- Secure memory space allocation as illustrated in the following figure.
Page 44
SAM L11 Application Development (Customer A ... Open the project linker file: Device Startup/saml11e16a_flash.ld. Figure 2-27. Non-Secure Project Linker File Location Update the linker file memory space definitions according to the SAM L11 Non-Secure memory attribution. /* Memory Spaces Definitions */...
Page 45
AN5365 SAM L11 Application Development (Customer A ... Figure 2-28. Non-Secure Memory Address and Size Definition 2.4.2.2 Adding and Linking Secure Gateway Library to Non-Secure Project Follow these steps to add and link the Secure gateway library that is generated during Secure application development provided by Customer A: Copy the Secure project implib to the Non-Secure project.
Page 47
AN5365 SAM L11 Application Development (Customer A ... To add the Secure Project library, from Toolchain > ARM/GNU Linker > Libraries, and then click Add Item. Figure 2-31. Add New Library to the Link Option Under Libraries section, enter library name.
Page 48
AN5365 SAM L11 Application Development (Customer A ... Add the Secure Project library path, from Toolchain > ARM/GNU Linker > Libraries. Click Add Item. Figure 2-33. Add New Library Search Path Under Library search path, browse and select the location of the Secure project implib.
Page 49
AN5365 SAM L11 Application Development (Customer A ... The Linker Library properties must be displayed as shown in the following figure: Figure 2-35. Non-Secure Project Linker Libraries Configuration 10. Click (Save button) to save the project settings. 2.4.2.3 Adding and Including Secure Gateway Header File To add and include a secure gateway header file, perform these actions: Copy the Secure gateway header file from the Secure project to the Non-Secure project.
Page 52
AN5365 SAM L11 Application Development (Customer A ... In the Non-Secure project property window, select Toolchain > ARM/GNU C Compiler > Directories, and then click Add Item. Figure 2-40. Adding New Compiler Directory to Non-secure Project Under Include Paths, select the location of the veneer.h file.
Page 54
13. Verify that no error is reported by the build process. 14. Launch debug session and confirm it is working. Important: Prior to loading the project on the target SAM L11 device, it is important to check Project Properties> Tools> Programing settings and ensure that the programming process does not execute a ChipErase_All command prior to loading the application.
Page 55
AN5365 SAM L11 Application Development (Customer A ... Figure 2-44. Project Program Settings Figure 2-45. Non-Secure Project Successful Build 15. Launch the debug session and verify whether the project is working or not. Important: Debugging the Non-Secure project requires a compatible preprogrammed Secure application that configures and starts the Non-Secure execution.
SAM L11 Application Development (Customer A ... Developing Solution with Secure Boot Program (Customer A) The SAM L11 device offers two configurable memory sections for storing the Secure and Non-Secure boot programs. These two sections are protected against ChipErase_S and ChipErase_NS offering possibilities to store Secure and Non-Secure Bootloader code as shown in the following figure.
Page 57
AN5365 SAM L11 Application Development (Customer A ... Figure 2-47. Secure Solution Template Content Non secure Project Secure Boot Project Start System Start Secure boot function Function call Secure boot function Function call User application Secure Project Start System Start Secure function 1 Function call Secure function 2 Function call TrustZone for Cortex‐M Follow these steps to create a Secure solution with a Boot program using Atmel Studio 7.
Page 60
Secure Solution Template with Boot Description The SAM L11 Secure solution template with boot code provided within Atmel Studio 7 is similar to the SAM L11 Secure solution template as described in previous chapters, but it embeds a Secure Boot program (stored in BS+BNSC memory region of the device).
Page 61
AN5365 SAM L11 Application Development (Customer A ... 2.5.2.2 Template NVM Fuses Configuration The default USERROW and BOCOR template settings and associated memory mapping are described in the following figure. Figure 2-51. Default Secure Solution with Boot Code Mapping 0x0000 0000 Secure Flash ...
Page 62
AN5365 SAM L11 Application Development (Customer A ....continued Fuses values Configuration BOOTPROT 0x10 Boot Protection size = BOOTPROT*0x100 = 0x1000 BCWEN 0x01 Boot Configuration Write Enabled BCREN 0x01 Boot Configuration Read Enabled CEKEY0 All 1s CE0 key = All 1s...
Page 63
AN5365 SAM L11 Application Development (Customer A ....continued Fuses values Configuration 0x08 Data Flash Secure Size = DS*0x100 = 0x800 0x40 RAM Secure Size = RS*0x80 = 0x2000 URWEN User Row Write Enabled NONSECA 0x0000 0000 Peripherals are secured...
Page 64
AN5365 SAM L11 Application Development (Customer A ... 2.5.2.3 Enabling Secure Boot Process with BS+BNSC Verification Follow these steps to enable Secure Boot process verification when working with Atmel Studio 7: Perform a ChipErase_ALL command using device programming. Build the Boot application using Atmel Studio IDE.
Page 65
AN5365 SAM L11 Application Development (Customer A ... The reference hash will be computed and written in memory automatically by the device programming tool when the step, shown in the figure below, is executed. Figure 2-54. Secure Boot Application Reference Hash Ref. Hash...
Software Use Case Examples Non-Secure Peripheral (TC0) This Use Case example describes how to configure a SAM L11 integrated peripheral (TC0) as a Non- Secure peripheral. In this example, the Secure project is in charge of allocating PORT and TC peripherals to the Non-Secure world, setting system clocks, and then jumping to the Non-Secure application.
NOP(); Secure Peripheral (TC0) This use case example demonstrates how to configure a SAM L11 integrated peripheral (TC0) as a Secure peripheral. In this use case, the Secure project is in charge of configuring system resources and managing the TC peripheral.
Figure 3-5. Secure TC Handler Flow Chart Mix-Secure Peripheral (EIC) This use case example describes how to configure and use a SAM L11 Mix-Secure peripheral (EIC). Using this example, the user can configure two interrupt lines, EXTIN 1 and EXTIN2, and then allocate them to the Non-Secure and Secure world.
AN5365 Software Use Case Examples TrustRAM The TrustRAM (TRAM) embedded in the SAM L11 offers these advanced security features for Secure information storage: • Address and data scrambling • Silent access • Data remanence • Active shielding and tamper detection •...
AN5365 Software Use Case Examples Cryptographic Accelerator (CRYA) SAM L11 embeds a hardware Cryptographic Accelerator (CRYA) with associated software functions stored in Boot ROM, which provide the hardware acceleration for the following: • Advanced Encryption Standard (AES-128) encryption and decryption •...
AN5365 Software Use Case Examples Data Flash The Data Flash embedded in SAM L11 offers the following advanced security features for the secure information storage: • Data scrambling • Silent access to selected row (TEROW) • Tamper erase of selected row (TEROW) on tamper detection...
• The topic Application Deployment with Secure and Non-Secure Bootloaders was removed and the content incorporated into Introduction to SAM L11 Security Features • The topic How to Define and Use Secure and Non-Secure Peripherals was removed and the content...
SQTP is a service mark of Microchip Technology Incorporated in the U.S.A. Silicon Storage Technology is a registered trademark of Microchip Technology Inc. in other countries. GestIC is a registered trademark of Microchip Technology Germany II GmbH & Co. KG, a subsidiary of Microchip Technology Inc., in other countries.
Need help?
Do you have a question about the SAM L11 and is the answer not in the manual?
Questions and answers