10.2 Linker Macros Controlling Memory Regions for TrustZone®

Linking either the secure or non-secure application requires that the linker know the address and length of secure, non-secure, and non-secure callable memory regions. The following are the preprocessor definitions that are used to set and control memory zones for TrustZone when linking TrustZone applications. They are passed as -Wl,-DNAME[=value].

When building a non-secure application, the following preprocessor definitions affect the linker script.

  • BOOTPROT=size (optional): Defines the boot protections size in bytes. The default value is 0 if not provided.
  • AS=size (recommended): Defines the flash secure application size, in bytes. Defaults to 50% of ROM if not provided.
  • RS=size (recommended): Defines the size of secure RAM, in bytes. Defaults to 50% of RAM if not provided.

When building a secure application, the following preprocessor definitions affect the linker script.

  • SECURE (required): Use the memory layout for a secure application.
  • BOOTPROT=size (optional): Defines the boot protections size in bytes. The default value is 0 if not provided.
  • AS=size (recommended): Defines the flash application secure size, in bytes. Defaults to 50% of ROM is not provided.
  • ANSC=size (recommended): Defines the flash application non-secure callable size, in bytes. Defaults to 0 if not provided.
  • RS=size (recommended): Defines the size of secure RAM, in bytes. Defaults to 50% of RAM if not provided.

In all cases, if a recommended value is not provided it will result in a warning message from the linker preprocessor.

Important: The memory region sizes must match those programmed in the device configuration bits in NVM User Row (UROW) and NVM Boot Configuration Row (BOCOR). These can be set as configuration bits via #pragma config in the source code. If that is done, the values in the config bits must match up with the values in the linker scripts dictating the memory regions to facilitate proper operation. See the normal config pragma documentation for the names of the fields and values.