arm trustzone - lauterbach · 2020. 2. 28. · trustzonebasics trustzonecortex-a trustzonecortex-m...

37
TrustZone Basics TrustZone Cortex-A TrustZone Cortex-M Usage Cortex-A Example Cortex-A Usage Cortex-M ARM TrustZone Alex Merkle November 26, 2019

Upload: others

Post on 05-Sep-2020

17 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ARM TrustZone - Lauterbach · 2020. 2. 28. · TrustZoneBasics TrustZoneCortex-A TrustZoneCortex-M UsageCortex-A ExampleCortex-A UsageCortex-M TrustZone Cortex-A Cortex-AcoresfeaturemultipleException

TrustZone Basics TrustZone Cortex-A TrustZone Cortex-M Usage Cortex-A Example Cortex-A Usage Cortex-M

ARM TrustZone

Alex Merkle

November 26, 2019

Page 2: ARM TrustZone - Lauterbach · 2020. 2. 28. · TrustZoneBasics TrustZoneCortex-A TrustZoneCortex-M UsageCortex-A ExampleCortex-A UsageCortex-M TrustZone Cortex-A Cortex-AcoresfeaturemultipleException

TrustZone Basics TrustZone Cortex-A TrustZone Cortex-M Usage Cortex-A Example Cortex-A Usage Cortex-M

Overview

1 TrustZone Basics

2 TrustZone Cortex-A

3 TrustZone Cortex-M

4 Usage Cortex-A

5 Example Cortex-A

6 Usage Cortex-M

Page 3: ARM TrustZone - Lauterbach · 2020. 2. 28. · TrustZoneBasics TrustZoneCortex-A TrustZoneCortex-M UsageCortex-A ExampleCortex-A UsageCortex-M TrustZone Cortex-A Cortex-AcoresfeaturemultipleException

TrustZone Basics TrustZone Cortex-A TrustZone Cortex-M Usage Cortex-A Example Cortex-A Usage Cortex-M

TrustZone Cortex-A

Cortex-A cores feature multiple Exception Level EL0/1/2/3EL0 = User, EL1 = Supervisor, EL2 = Hypervisor, EL3 = MonitorAdditionally there is a Security State Secure/NonSecureBoth Exception Level and Security State control the MMUSecurity State is also connected to the SoC interconnect

EL0 AppAArch64 or AArch32

EL1 Guest OSAArch64 or AArch32

EL3 SecuremonitorAArch64

EL0 Secure AppAArch64 or AArch32

EL1 Secure OSAArch64 or AArch32

Secure worldNon-secure world

EL2 HypervisorAArch64 or AArch32

EL2 SecureAArch64 Hypervisor

ArmV8.4-A

Cortex-Acore MMU Memory

BusNSM=EL0/1/2/3

NS=Sec/NSec

Page 4: ARM TrustZone - Lauterbach · 2020. 2. 28. · TrustZoneBasics TrustZoneCortex-A TrustZoneCortex-M UsageCortex-A ExampleCortex-A UsageCortex-M TrustZone Cortex-A Cortex-AcoresfeaturemultipleException

TrustZone Basics TrustZone Cortex-A TrustZone Cortex-M Usage Cortex-A Example Cortex-A Usage Cortex-M

TrustZone Cortex-M

Cortex-M cores feature Handler and Thread modeHandler = Supervisor , Thread = User/NonPrivilegedAdditionally there is a Security State Secure/NonSecureSecurity State controls the SAUSecurity State is also connected to the SoC interconnect

Cortex-Mcore MPU SAU Memory

BusS/U NS

NS=Sec/NSec

Page 5: ARM TrustZone - Lauterbach · 2020. 2. 28. · TrustZoneBasics TrustZoneCortex-A TrustZoneCortex-M UsageCortex-A ExampleCortex-A UsageCortex-M TrustZone Cortex-A Cortex-AcoresfeaturemultipleException

TrustZone Basics TrustZone Cortex-A TrustZone Cortex-M Usage Cortex-A Example Cortex-A Usage Cortex-M

Overview

1 TrustZone Basics

2 TrustZone Cortex-A

3 TrustZone Cortex-M

4 Usage Cortex-A

5 Example Cortex-A

6 Usage Cortex-M

Page 6: ARM TrustZone - Lauterbach · 2020. 2. 28. · TrustZoneBasics TrustZoneCortex-A TrustZoneCortex-M UsageCortex-A ExampleCortex-A UsageCortex-M TrustZone Cortex-A Cortex-AcoresfeaturemultipleException

TrustZone Basics TrustZone Cortex-A TrustZone Cortex-M Usage Cortex-A Example Cortex-A Usage Cortex-M

Address Ambiguity

As the Exception Level & SecurityState are input signal for theMMU there exists for everycombination a own virtual addressmapEvery Exception Level & SecurityState combination has a ownAccess-Class within TRACE32Reason: Address-Values areambiguous!

EL0EL1

0x0

0xffff.ffff

EL2

0x0

0xffff.ffff

EL3EL3

0x0

0xffff.ffff

EL3EL2

EL0EL1

0x0

0xffff.ffff

Page 7: ARM TrustZone - Lauterbach · 2020. 2. 28. · TrustZoneBasics TrustZoneCortex-A TrustZoneCortex-M UsageCortex-A ExampleCortex-A UsageCortex-M TrustZone Cortex-A Cortex-AcoresfeaturemultipleException

TrustZone Basics TrustZone Cortex-A TrustZone Cortex-M Usage Cortex-A Example Cortex-A Usage Cortex-M

TRACE32 Access Classes

TRACE32 Access Classes allow to access virtual memory of a specific modeTRACE32 combines the specified access class with the current CPU-Mode if theaddress is not fully qualified

TrustZone (NS)Mode (M) NonSecure SecureEL0/User NU:<addr> ZU:<addr>

EL1/Supervisor NS:<addr> ZS:<addr>EL2/Hypervisor H:<addr>1 ZH:<addr>2

EL3/Monitor M:<addr>

1H: is a an alias for NH:2starting from ARMv8.4

Page 8: ARM TrustZone - Lauterbach · 2020. 2. 28. · TrustZoneBasics TrustZoneCortex-A TrustZoneCortex-M UsageCortex-A ExampleCortex-A UsageCortex-M TrustZone Cortex-A Cortex-AcoresfeaturemultipleException

TrustZone Basics TrustZone Cortex-A TrustZone Cortex-M Usage Cortex-A Example Cortex-A Usage Cortex-M

Onchip Breakpoints

Onchip Breakpoints can trigger on Security State Secure/NonSecureOnchip Breakpoints can trigger on Exception Level EL0+1/EL2/EL3No Onchip Breakpoints to physical memory

Cortex-ACore

= =

MMU

P: D:

DataBPs

InstrBPs

A: (AZ:/AN:)

NS

M

Page 9: ARM TrustZone - Lauterbach · 2020. 2. 28. · TrustZoneBasics TrustZoneCortex-A TrustZoneCortex-M UsageCortex-A ExampleCortex-A UsageCortex-M TrustZone Cortex-A Cortex-AcoresfeaturemultipleException

TrustZone Basics TrustZone Cortex-A TrustZone Cortex-M Usage Cortex-A Example Cortex-A Usage Cortex-M

Physical Memory

Access Class A: can becombined with Security Stateas it’s connected to the SoCinterconnectAZ: <-> AN:

Cortex-ACore

= =

MMU

P: D:

DataBPs

InstrBPs

A: (AZ:/AN:)

NS

M

CPU CacheMMU MemoryNC

A

ANC

Page 10: ARM TrustZone - Lauterbach · 2020. 2. 28. · TrustZoneBasics TrustZoneCortex-A TrustZoneCortex-M UsageCortex-A ExampleCortex-A UsageCortex-M TrustZone Cortex-A Cortex-AcoresfeaturemultipleException

TrustZone Basics TrustZone Cortex-A TrustZone Cortex-M Usage Cortex-A Example Cortex-A Usage Cortex-M

TRACE32 behavior

Security State & Exception Level combination is called ZONE in TRACE32Default - SYStem.Option ZONESPACES OFF

sYmbol Database is not strictly separated/symbol addresses may be ambiguousSYStem.Option ZONESPACES ON

sYmbol Database is strictly separatedDefault - Break.CONFIG.MatchZONE OFF

Onchip Breakpoints ignore Security State as well as Exception LevelBreak.CONFIG.MatchZONE ON

Onchip Breakpoints respect Security State as well as Exception Level

Page 11: ARM TrustZone - Lauterbach · 2020. 2. 28. · TrustZoneBasics TrustZoneCortex-A TrustZoneCortex-M UsageCortex-A ExampleCortex-A UsageCortex-M TrustZone Cortex-A Cortex-AcoresfeaturemultipleException

TrustZone Basics TrustZone Cortex-A TrustZone Cortex-M Usage Cortex-A Example Cortex-A Usage Cortex-M

TRACE32 behavior

ConfigurationSYStem.Option ZONESPACES ONBreak.CONFIG.MatchZone ON

<Zone>:<Address>

<Zone>:<Address>

Break.Set

Break.Set

/Onchip

/Onchip

ONMatchZone

OFF

IGNORE

Page 12: ARM TrustZone - Lauterbach · 2020. 2. 28. · TrustZoneBasics TrustZoneCortex-A TrustZoneCortex-M UsageCortex-A ExampleCortex-A UsageCortex-M TrustZone Cortex-A Cortex-AcoresfeaturemultipleException

TrustZone Basics TrustZone Cortex-A TrustZone Cortex-M Usage Cortex-A Example Cortex-A Usage Cortex-M

Overview

1 TrustZone Basics

2 TrustZone Cortex-A

3 TrustZone Cortex-M

4 Usage Cortex-A

5 Example Cortex-A

6 Usage Cortex-M

Page 13: ARM TrustZone - Lauterbach · 2020. 2. 28. · TrustZoneBasics TrustZoneCortex-A TrustZoneCortex-M UsageCortex-A ExampleCortex-A UsageCortex-M TrustZone Cortex-A Cortex-AcoresfeaturemultipleException

TrustZone Basics TrustZone Cortex-A TrustZone Cortex-M Usage Cortex-A Example Cortex-A Usage Cortex-M

Memory Map

For Cortex-M addresses arenon-ambiguousThe Security State is a inputsignal for the SAUThe SAU is software configurableand allows to restrict accessesinto memory when the core is inNonSecure stateSecure Gateable region containssg instructions that allowsNonSecure code to call Secureroutines

Secure Flash

Secure Gateable Flash

NonSecure Flash

Secure RAM

Secure Gateable RAM

NonSecure RAM

0x20000000

Peripherals0x40000000

System Control0xe0000000

0x0

0xffffffff

Page 14: ARM TrustZone - Lauterbach · 2020. 2. 28. · TrustZoneBasics TrustZoneCortex-A TrustZoneCortex-M UsageCortex-A ExampleCortex-A UsageCortex-M TrustZone Cortex-A Cortex-AcoresfeaturemultipleException

TrustZone Basics TrustZone Cortex-A TrustZone Cortex-M Usage Cortex-A Example Cortex-A Usage Cortex-M

Memory Map

The SAU works like a blinker/blinder for NonSecure

Secure Flash

Secure Gateable Flash

NonSecure Flash

Secure RAM

Secure Gateable RAM

NonSecure RAM

0x20000000

Peripherals0x40000000

System Control0xe0000000

0x0

0xffffffff

Secure

Secure Gateable Flash

NonSecure Flash

Secure Gateable RAM

NonSecure RAM

0x20000000

Peripherals0x40000000

System Control0xe0000000

0x0

0xffffffff

NonSecure

Page 15: ARM TrustZone - Lauterbach · 2020. 2. 28. · TrustZoneBasics TrustZoneCortex-A TrustZoneCortex-M UsageCortex-A ExampleCortex-A UsageCortex-M TrustZone Cortex-A Cortex-AcoresfeaturemultipleException

TrustZone Basics TrustZone Cortex-A TrustZone Cortex-M Usage Cortex-A Example Cortex-A Usage Cortex-M

NonSecure to Secure switch

Secure Gateable Region is used as a veneer

Secure Flash

Secure Gateable Flash

NonSecure Flash

Secure RAM

Secure Gateable RAM

NonSecure RAM

0x20000000

Peripherals0x40000000

System Control0xe0000000

0x0

0xffffffff

Secure

Secure Gateable Flash

NonSecure Flash

Secure Gateable RAM

NonSecure RAM

0x20000000

Peripherals0x40000000

System Control0xe0000000

0x0

0xffffffff

NonSecure

1

23

Page 16: ARM TrustZone - Lauterbach · 2020. 2. 28. · TrustZoneBasics TrustZoneCortex-A TrustZoneCortex-M UsageCortex-A ExampleCortex-A UsageCortex-M TrustZone Cortex-A Cortex-AcoresfeaturemultipleException

TrustZone Basics TrustZone Cortex-A TrustZone Cortex-M Usage Cortex-A Example Cortex-A Usage Cortex-M

TRACE32 Access Classes

TRACE32 Access Classes allow to access memory of a specific Security StateTRACE32 combines the specified access class with the current CPU-Mode if theaddress is not fully qualified

TrustZone (NS)Mode (M) NonSecure SecureEL0/User NU:<addr>1 ZU:<addr>1

EL1/Supervisor NS:<addr> ZS:<addr>

1Cortex-M debugger accesses bypass MPU => U: is ignored

Page 17: ARM TrustZone - Lauterbach · 2020. 2. 28. · TrustZoneBasics TrustZoneCortex-A TrustZoneCortex-M UsageCortex-A ExampleCortex-A UsageCortex-M TrustZone Cortex-A Cortex-AcoresfeaturemultipleException

TrustZone Basics TrustZone Cortex-A TrustZone Cortex-M Usage Cortex-A Example Cortex-A Usage Cortex-M

Physical Memory

Access Class A: can be combined with Security State as it’s connected to the SoCinterconnectAZ: <-> AN:Addresses for Cortex-M are always physical

CPU CacheMPU

Memory

DAP

NC

A

ANC

Page 18: ARM TrustZone - Lauterbach · 2020. 2. 28. · TrustZoneBasics TrustZoneCortex-A TrustZoneCortex-M UsageCortex-A ExampleCortex-A UsageCortex-M TrustZone Cortex-A Cortex-AcoresfeaturemultipleException

TrustZone Basics TrustZone Cortex-A TrustZone Cortex-M Usage Cortex-A Example Cortex-A Usage Cortex-M

Overview

1 TrustZone Basics

2 TrustZone Cortex-A

3 TrustZone Cortex-M

4 Usage Cortex-A

5 Example Cortex-A

6 Usage Cortex-M

Page 19: ARM TrustZone - Lauterbach · 2020. 2. 28. · TrustZoneBasics TrustZoneCortex-A TrustZoneCortex-M UsageCortex-A ExampleCortex-A UsageCortex-M TrustZone Cortex-A Cortex-AcoresfeaturemultipleException

TrustZone Basics TrustZone Cortex-A TrustZone Cortex-M Usage Cortex-A Example Cortex-A Usage Cortex-M

SymbolsSYStem.Option ZONESPACES ONBreak.CONFIG.MatchZone ON; ----------------------------------------------------; load sYmbolsData.LOAD.Elf <code_on_el3.elf> M: /NoCODEData.LOAD.Elf <code_on_el2.elf> NH: /NoCODEData.LOAD.Elf <code_on_el1_ns.elf> NS: /NoCODEData.LOAD.Elf <code_on_el1_s.elf> ZS: /NoCODE

Different code and different sourcecode & memory for each zone

Page 20: ARM TrustZone - Lauterbach · 2020. 2. 28. · TrustZoneBasics TrustZoneCortex-A TrustZoneCortex-M UsageCortex-A ExampleCortex-A UsageCortex-M TrustZone Cortex-A Cortex-AcoresfeaturemultipleException

TrustZone Basics TrustZone Cortex-A TrustZone Cortex-M Usage Cortex-A Example Cortex-A Usage Cortex-M

sYmbols

Functions & Variables are automatically accessed with the correct zone

Page 21: ARM TrustZone - Lauterbach · 2020. 2. 28. · TrustZoneBasics TrustZoneCortex-A TrustZoneCortex-M UsageCortex-A ExampleCortex-A UsageCortex-M TrustZone Cortex-A Cortex-AcoresfeaturemultipleException

TrustZone Basics TrustZone Cortex-A TrustZone Cortex-M Usage Cortex-A Example Cortex-A Usage Cortex-M

Breakpoints

Break.CONFIG.MatchZone ON; ----------------------------------------------------; set BPsBreak.Set M:<addr> [/Onchip] </Program|/ReadWrite|/Read|/Write>Break.Set H:<addr> [/Onchip] </Program|/ReadWrite|/Read|/Write>Break.Set NS:<addr> [/Onchip] </Program|/ReadWrite|/Read|/Write>Break.Set ZS:<addr> [/Onchip] </Program|/ReadWrite|/Read|/Write>

Break.Set <symbol_name> [/Onchip]

Page 22: ARM TrustZone - Lauterbach · 2020. 2. 28. · TrustZoneBasics TrustZoneCortex-A TrustZoneCortex-M UsageCortex-A ExampleCortex-A UsageCortex-M TrustZone Cortex-A Cortex-AcoresfeaturemultipleException

TrustZone Basics TrustZone Cortex-A TrustZone Cortex-M Usage Cortex-A Example Cortex-A Usage Cortex-M

Access Memory

; ----------------------------------------------------; access memoryData.Set M:<addr> <value>Data.Set H:<addr> <value>Data.Set NS:<addr> <value>Data.Set ZS:<addr> <value>Data.dump M:<addr>Data.dump H:<addr>Data.dump NS:<addr>Data.dump ZS:<addr>; ----------------------------------------------------; access physical memoryData.Set A:<addr> <value>Data.Set AZ:<addr> <value>Data.Set AN:<addr> <value>Data.dump A:<addr>Data.dump AZ:<addr>Data.dump AN:<addr>

Page 23: ARM TrustZone - Lauterbach · 2020. 2. 28. · TrustZoneBasics TrustZoneCortex-A TrustZoneCortex-M UsageCortex-A ExampleCortex-A UsageCortex-M TrustZone Cortex-A Cortex-AcoresfeaturemultipleException

TrustZone Basics TrustZone Cortex-A TrustZone Cortex-M Usage Cortex-A Example Cortex-A Usage Cortex-M

Peripherals; ----------------------------------------------------; access physical memoryData.Set <A|AZ|AN>:<addr> <value>Data.dump <A|AZ|AN>:<addr>; ----------------------------------------------------; peripheral viewPERPER , /NonSecurePER , /Secure

Page 24: ARM TrustZone - Lauterbach · 2020. 2. 28. · TrustZoneBasics TrustZoneCortex-A TrustZoneCortex-M UsageCortex-A ExampleCortex-A UsageCortex-M TrustZone Cortex-A Cortex-AcoresfeaturemultipleException

TrustZone Basics TrustZone Cortex-A TrustZone Cortex-M Usage Cortex-A Example Cortex-A Usage Cortex-M

Overview

1 TrustZone Basics

2 TrustZone Cortex-A

3 TrustZone Cortex-M

4 Usage Cortex-A

5 Example Cortex-A

6 Usage Cortex-M

Page 25: ARM TrustZone - Lauterbach · 2020. 2. 28. · TrustZoneBasics TrustZoneCortex-A TrustZoneCortex-M UsageCortex-A ExampleCortex-A UsageCortex-M TrustZone Cortex-A Cortex-AcoresfeaturemultipleException

TrustZone Basics TrustZone Cortex-A TrustZone Cortex-M Usage Cortex-A Example Cortex-A Usage Cortex-M

Debugging ATF; ----------------------------------------------------; connectSYStem.CPU 88F3720-A0SYStem.Option ZONESPACES ONBreak.CONFIG.MatchZone ONCORE.ASSIGN 1.SYStem.Up

; ----------------------------------------------------; load Symbols; Bootloader 1: bl1 running in Monitor/EL3Data.LOAD.Elf ~~~~/atf/build/a3700/debug/bl1/bl1.elf M: /NoCODE; Bootloader 2: bl2 running in Secure Supervisor/EL2Data.LOAD.Elf ~~~~/atf/build/a3700/debug/bl2/bl2.elf Z: /NoCODE /NoCLEAR; Bootloader 3: bl31 running in Monitor/EL3Data.LOAD.Elf ~~~~/atf/build/a3700/debug/bl31/bl31.elf M: /NoCODE /NoCLEAR; Bootloader 4: u-boot running in Hypervisor/EL2Data.LOAD.Elf ~~~~/u-boot/u-boot H: /NoCODE /NoCLEAR

Go bl1_entrypoint /Onchip /PROGRAMWAIT !STATE.RUN()

Go bl2_entrypoint /Onchip /PROGRAMWAIT !STATE.RUN()

Go bl31_entrypoint /Onchip /PROGRAMWAIT !STATE.RUN()

Go __image_copy_start /Onchip /PROGRAMWAIT !STATE.RUN() 10s

Page 26: ARM TrustZone - Lauterbach · 2020. 2. 28. · TrustZoneBasics TrustZoneCortex-A TrustZoneCortex-M UsageCortex-A ExampleCortex-A UsageCortex-M TrustZone Cortex-A Cortex-AcoresfeaturemultipleException

TrustZone Basics TrustZone Cortex-A TrustZone Cortex-M Usage Cortex-A Example Cortex-A Usage Cortex-M

Debugging ATF - Hints

Keep the complete code in the bootsource (e.g. Flash / SD-Card)⇒ Boot sequence is automatizedUse /Onchip Breakpoints to trigger at every bootstage entry⇒ Possibility to patch the codeUse

TRANSlation.TableWalk ONTRANSlation.ON

to enable TRACE32 automatic MMU-TableWalk⇒ Software Breakpoints within every zone even though the .text segment isread-only (via MMU)

Page 27: ARM TrustZone - Lauterbach · 2020. 2. 28. · TrustZoneBasics TrustZoneCortex-A TrustZoneCortex-M UsageCortex-A ExampleCortex-A UsageCortex-M TrustZone Cortex-A Cortex-AcoresfeaturemultipleException

TrustZone Basics TrustZone Cortex-A TrustZone Cortex-M Usage Cortex-A Example Cortex-A Usage Cortex-M

Debugging ATF - Pitfalls

Bootflow is SoC specific - check BSPTo debug into the bootloaders requires to connect the debugger early after resetHighly SoC & Board specific!Not every SoC supports that!⇒patch a endless loop into the bootimage (last resort)TRACE32 is preconfigured for SMP debugging after SYStem.CPU⇒ use CORE.ASSIGN <x> to select the bootcore(s) only⇒ example scripts ˜˜/demo/<arch>/hardware/<chip|board>

[email protected]

Page 28: ARM TrustZone - Lauterbach · 2020. 2. 28. · TrustZoneBasics TrustZoneCortex-A TrustZoneCortex-M UsageCortex-A ExampleCortex-A UsageCortex-M TrustZone Cortex-A Cortex-AcoresfeaturemultipleException

TrustZone Basics TrustZone Cortex-A TrustZone Cortex-M Usage Cortex-A Example Cortex-A Usage Cortex-M

Debugging Linux + bl31; ----------------------------------------------------; connectSYStem.CPU 88F3720-A0SYStem.Option ZONESPACES ONSYStem.Option MMUSPACES ONBreak.CONFIG.MatchZone ONSYStem.Mode AttachBreak

; ----------------------------------------------------; load Symbols; bl31 running in Monitor/EL3Data.LOAD.Elf ~~~~/atf/build/a3700/debug/bl31/bl31.elf M: /NoCODE; linux running in NonSecure Supervisor/EL1Data.LOAD.Elf ~~~~/linux/vmlinux NS: /NoCODE /NoCLEAR

; ----------------------------------------------------; configure debugger address translationMMU.FORMAT LINUXSWAP3 \\vmlinux\\swapper_pg_dir NS:<virtual range> <physical>TRANSlation.COMMON NS:0xf000000000000000--0xffffffffffffffffTRANSlation.TableWalk ONTRANSlation.ON

TASK.CONFIG ~~/demo/arm64/kernel/linux/awareness/linux.t32 /ACCESS NS:MENU.ReProgram ~~/demo/arm64/kernel/linux/awareness/linux.men

Use ~~/demo/<arm|arm64>/kernel/linux/boards/generic-template/detect_translation.cmm

Use ~~/demo/<arm|arm64>/kernel/linux/boards/generic-template/linux-attach.cmm

Page 29: ARM TrustZone - Lauterbach · 2020. 2. 28. · TrustZoneBasics TrustZoneCortex-A TrustZoneCortex-M UsageCortex-A ExampleCortex-A UsageCortex-M TrustZone Cortex-A Cortex-AcoresfeaturemultipleException

TrustZone Basics TrustZone Cortex-A TrustZone Cortex-M Usage Cortex-A Example Cortex-A Usage Cortex-M

detect_translation.cmm

First official release DVD2019.02Supports KAISER/MELTDOWN patchSteps

Linux must be up and runningDebugger is connected ⇒ SYStem.Mode AttachDebug symbols must be loaded ⇒ Data.LOAD.Elf ...DO ~~/demo/<arm|arm64>/kernel/linux/boards/generic-template/detect_translation.cmm

See also: ~~/demo/<arm|arm64>/kernel/linux/boards/generic-template/linux-attach.cmm

Page 30: ARM TrustZone - Lauterbach · 2020. 2. 28. · TrustZoneBasics TrustZoneCortex-A TrustZoneCortex-M UsageCortex-A ExampleCortex-A UsageCortex-M TrustZone Cortex-A Cortex-AcoresfeaturemultipleException

TrustZone Basics TrustZone Cortex-A TrustZone Cortex-M Usage Cortex-A Example Cortex-A Usage Cortex-M

Debugging OP-TEE

; ----------------------------------------------------; connectSYStem.CPU ZYNQ-ULTRASCALE+-APUSYStem.Option ZONESPACES ONSYStem.Option MMUSPACES ONBreak.CONFIG.MatchZone ONSYStem.Mode AttachBreak

; ----------------------------------------------------; load Symbols; op-tee running in Secure Supervisor/EL1Data.LOAD.Elf out/arm-plat-zynqmp/core/tee.elf ZS: /NoCODE

; ----------------------------------------------------; configure debugger address translationTRANSlation.Create ZS:<optee virtual range> AZ:<optee physical>TRANSlation.COMMON ZS:<optee virtual range>TRANSlation.TableWalk ONTRANSlation.ON

TASK.CONFIG ~~/demo/arm64/kernel/op-tee/optee.t32 /ACCESS ZS:MENU.ReProgram ~~/demo/arm64/kernel/op-tee/optee.men

Page 31: ARM TrustZone - Lauterbach · 2020. 2. 28. · TrustZoneBasics TrustZoneCortex-A TrustZoneCortex-M UsageCortex-A ExampleCortex-A UsageCortex-M TrustZone Cortex-A Cortex-AcoresfeaturemultipleException

TrustZone Basics TrustZone Cortex-A TrustZone Cortex-M Usage Cortex-A Example Cortex-A Usage Cortex-M

Debugging OP-TEE - Hints

Op-Tee uses a paging approach with ambiguous TA address space⇒ SYStem.Option MMUSPACES ON

The Op-Tee default translation needs to be configured manually, by Nov 2019 wedo not support MMU.FORMAT⇒ TRANSlation.Create

UseTRANSlation.TableWalk ONTRANSlation.ON

to enable TRACE32 automatic MMU-TableWalk⇒ Software Breakpoints are available for TAs despite the .text segment isread-only (via MMU)

Page 32: ARM TrustZone - Lauterbach · 2020. 2. 28. · TrustZoneBasics TrustZoneCortex-A TrustZoneCortex-M UsageCortex-A ExampleCortex-A UsageCortex-M TrustZone Cortex-A Cortex-AcoresfeaturemultipleException

TrustZone Basics TrustZone Cortex-A TrustZone Cortex-M Usage Cortex-A Example Cortex-A Usage Cortex-M

Debugging OP-TEE - Limitations

Status November 2019The standard workflow foresees that a TA is

loaded - TEEC_OpenSessiondebugged - TEEC_InvokeCommandunloaded - TEEC_CloseSession

triggered by the optee menu Debug Trusted Application from Entry.For TAs that are loaded persistently (no TEEC_CloseSession), possiblyambiguous Onchip-Breakpoints need to be used

Page 33: ARM TrustZone - Lauterbach · 2020. 2. 28. · TrustZoneBasics TrustZoneCortex-A TrustZoneCortex-M UsageCortex-A ExampleCortex-A UsageCortex-M TrustZone Cortex-A Cortex-AcoresfeaturemultipleException

TrustZone Basics TrustZone Cortex-A TrustZone Cortex-M Usage Cortex-A Example Cortex-A Usage Cortex-M

Overview

1 TrustZone Basics

2 TrustZone Cortex-A

3 TrustZone Cortex-M

4 Usage Cortex-A

5 Example Cortex-A

6 Usage Cortex-M

Page 34: ARM TrustZone - Lauterbach · 2020. 2. 28. · TrustZoneBasics TrustZoneCortex-A TrustZoneCortex-M UsageCortex-A ExampleCortex-A UsageCortex-M TrustZone Cortex-A Cortex-AcoresfeaturemultipleException

TrustZone Basics TrustZone Cortex-A TrustZone Cortex-M Usage Cortex-A Example Cortex-A Usage Cortex-M

Symbols; ----------------------------------------------------; load sYmbolsData.LOAD.Elf <secure.elf> Z: /NoCODEData.LOAD.Elf <non_secure.elf> N: /NoCODE /NoCLEAR

Functions & Variables are automatically accessed with the correct zone

Page 35: ARM TrustZone - Lauterbach · 2020. 2. 28. · TrustZoneBasics TrustZoneCortex-A TrustZoneCortex-M UsageCortex-A ExampleCortex-A UsageCortex-M TrustZone Cortex-A Cortex-AcoresfeaturemultipleException

TrustZone Basics TrustZone Cortex-A TrustZone Cortex-M Usage Cortex-A Example Cortex-A Usage Cortex-M

Access Memory; ----------------------------------------------------; access memoryData.Set <N|Z>:<addr> <value>Data.Set <addr> <value>Data.dump <N|Z>:<addr>Data.dump <addr>

Page 36: ARM TrustZone - Lauterbach · 2020. 2. 28. · TrustZoneBasics TrustZoneCortex-A TrustZoneCortex-M UsageCortex-A ExampleCortex-A UsageCortex-M TrustZone Cortex-A Cortex-AcoresfeaturemultipleException

TrustZone Basics TrustZone Cortex-A TrustZone Cortex-M Usage Cortex-A Example Cortex-A Usage Cortex-M

Peripherals; ----------------------------------------------------; access physical memoryData.Set <A|AZ|AN>:<addr> <value>Data.dump <A|AZ|AN>:<addr>; ----------------------------------------------------; peripheral viewPERPER , /NonSecurePER , /Secure

Page 37: ARM TrustZone - Lauterbach · 2020. 2. 28. · TrustZoneBasics TrustZoneCortex-A TrustZoneCortex-M UsageCortex-A ExampleCortex-A UsageCortex-M TrustZone Cortex-A Cortex-AcoresfeaturemultipleException

TrustZone Basics TrustZone Cortex-A TrustZone Cortex-M Usage Cortex-A Example Cortex-A Usage Cortex-M

Flash programming

SYStem.CPU <cpu>SYStem.Up

; --------------------------------------------------------------------------------; Flash programming; prepare flash programming (declarations)DO ~~/demo/arm/flash/<driver>.cmm PREPAREONLY; ReProgram FlashFLASH.ReProgram ALLData.LOAD.Elf <secure.elf> /NosYmbolData.LOAD.Elf <non_secure.elf> /NosYmbolFLASH.ReProgram OFF

; ----------------------------------------------------; load sYmbolsData.LOAD.Elf <secure.elf> Z: /NoCODEData.LOAD.Elf <non_secure.elf> N: /NoCODE /NoCLEAR