carloscn / blog

My blog
Apache License 2.0
87 stars 20 forks source link

[S32K344] HSE Overview #217

Open carloscn opened 1 week ago

carloscn commented 1 week ago

1. SECURITY ARCHITECTURE

Architecture:

Functional Blocks:

2. Memory Architecture For HSE

3. HSE Boot Artifacts (IVT/HSE FW)

The secure boot flow involves multiple software bootloaders – this gives a great deal of scope for customisation to ensure that boot process is optimal for specific use cases.

3.1 Boot Flow

From a high level, the flow is as follows:

Depending on configuration inputs, the HSE can handle:

Note, The Application Secure Boot is managed by HSE FW through:

3.2 Boot Image

The layout of the Boot Image binary in the flash of the chip is shown in following figure:

IVT + Core0 image + Core1 image + LC config + Secure Boot image + HSE FW.

3.2.1 Image Vector Table (IVT)

IVT used by HSE to Boot application in non-secure way, for configuration and installation, while it is defined by the Application and it signed by the HSE, (only if security is enabled.

3.2.2 HSE Firmware

There are two types of the HSE firmware, which are the pink image and blue image.

Note, the HSE will be signing the Application. As the result, there is a private key in the HSE firmware. While the HSE also can encrypt the App image by a NXP FW Delivery key (FDK).

Note, the HSE has considered some attacks to enhance the security, such as:

4. HSE Interfaces

4.1 HSE Message Unit (MU)

AP -> HSE:

The features:

4.2 HSE Service Interface

4.2.1 Host Side

HSE Channel

HSE Mailbox (service descriptor)

4.2.2 HSE Side

HSE Channel

HSE Mailbox (service descriptor)

4.2 HSE Service Request/Response

4.2.1 HSE Service Request

HSE Service Response (hseSrvResponse_t); is provided by the HSE firmware, to indicate the end of a service request. It indicates whether the requested service has successfully completed or ended with an error.

4.2.2 HSE STATUS & NOTIFICATION ERRORS

HSE Status is provided by FSR register:

Asynchronous notification errors (at MU level) signaled by HSE to HOST through interrupts (GSR register). Each time a bit is set (an error is triggered) an interrupt occurs. E.g. FATAL ERROR: HSE FW will shutdown the MU communication (APP should perform a system reset).

5. HSE Installation on Virgin Device

5.1 Full Memory

After POR:

  1. The programming entity programs the images IVT in application flash block.
  2. The programming entity programs HSE FW Image in application flash block.
  3. The programming entity program app boot loader in application flash block.
  4. Programming entity programs XRDC image in application flash block & issues a reset
  5. Upon next boot HSE will decrypt, authenticate and program the HSE FW image in secure code area. It will boot the application and HSE FW.

The memory changes are shown in the following figure:

5.2 A/B Swap

After POR:

  1. The programming entity programs the images IVT in application flash block
  2. The programming entity programs A/B swap HSE FW Image in application flash block.
  3. The programming entity program app boot loader in application flash block
  4. Programming entity programs XRDC image in application flash block & issues a reset
  5. Upon next boot HSE will decrypt, authenticate and program the HSE FW image in secure code area. It will program A/B swap enable configuration, parameters and issue reset.

6. HSE config

The HSE firmware configuration is controlled and handled by the application through the different services available, under certain conditions, once the HSE firmware has been successfully installed:

6.1 Default config

6.2 Config

6.3 HSE ATTRIBUTE CONFIGURATION

6.4 Boot Sequence After Config

7. Data Sync

7.1 Data synchronization with the HSE core

Data can be seen from the Figure 2 that the HSE service structure is passed between S32K3xx and HSE through MU, and HSE will execute the service according to the service ID and parameters (which can be values or addresses) in the structure.

D-Cache problem: For the data transferred between the dual cores, will be modified by at least one of the cores, when D-cache is enabled, the data synchronization issue will occur.

There are two solutions for the data synchronization:

7.1.1 How to use global variables and temporary variables.

For the global value:

There are two types with initial value and without initial value:

Obviously, disabling the global D-Cache configuration is a worse method due to lose the global performance of the chip. As a result, we have to consider a method to control the data having synchronization issues populated into non-cacheable areas.

The S32K344 has defined a type of MemMap file to guide the compiler in formatting the memory. Through the precompiled directives(#prama section) defined in the MemMap file, assign the two type global variables to the non-cacheable data segment or non-cacheable bss segment as following figure.

For the temporary value:

Refer to https://github.com/carloscn/blog/issues/5 , the temporary value, being defined in one function, is placed into the .data or .text section after being compiled, deciding whether to with an initial value.

In the ARM Cortex-M7 design, as they are temporarily allocated on the stack, the M7 stack can only be placed in the non-cachable area.

Unless by modifying the cache policy by the MPU module of the stack area to solve this problem.

If there is a memory management program, the user can also use a non-cacheble memory pool to allocate the space for the temporary variables.