1---
2permalink: /trustzone-sdk-docs/expanding-ta-secure-memory-on-qemuv8.md
3---
4
5# Expanding TA Secure Memory on QEMUv8
6
7Since some Rust examples such as `tls_server-rs` and `tls_client-rs`  require
8larger TA memory (about 18M heap), we've expanded TA secure memory on OP-TEE
9QEMUv8 platform. On QEMUv8 platform it supports 7M TA memory originally, after
10expanding it supports 27M TA memory at most.
11
12We modified the firmware and configuration of QEMU, ATF and OPTEE. You can
13download the pre-built image from
14https://nightlies.apache.org/teaclave/teaclave-trustzone-sdk/ or patch the code
15and build the images by yourself.
16
17The modifications are:
18
191. QEMU patch in `optee-repo/qemu`:
20
21```
22diff --git a/hw/arm/virt.c b/hw/arm/virt.c
23index d2e5ecd..e1070a0 100644
24--- a/hw/arm/virt.c
25+++ b/hw/arm/virt.c
26@@ -157,7 +157,7 @@ static const MemMapEntry base_memmap[] = {
27     [VIRT_MMIO] =               { 0x0a000000, 0x00000200 },
28     /* ...repeating for a total of NUM_VIRTIO_TRANSPORTS, each of that size */
29     [VIRT_PLATFORM_BUS] =       { 0x0c000000, 0x02000000 },
30-    [VIRT_SECURE_MEM] =         { 0x0e000000, 0x01000000 },
31+    [VIRT_SECURE_MEM] =         { 0x0e000000, 0x02000000 },
32     [VIRT_PCIE_MMIO] =          { 0x10000000, 0x2eff0000 },
33     [VIRT_PCIE_PIO] =           { 0x3eff0000, 0x00010000 },
34     [VIRT_PCIE_ECAM] =          { 0x3f000000, 0x01000000 },
35```
36
372. ATF patch in `optee-repo/trusted-firmware-a`:
38
39```
40diff --git a/plat/qemu/qemu/include/platform_def.h b/plat/qemu/qemu/include/platform_def.h
41index c02eff9..ded0660 100644
42--- a/plat/qemu/qemu/include/platform_def.h
43+++ b/plat/qemu/qemu/include/platform_def.h
44@@ -87,7 +87,7 @@
45 #define SEC_SRAM_SIZE                  0x00060000
46
47 #define SEC_DRAM_BASE                  0x0e100000
48-#define SEC_DRAM_SIZE                  0x00f00000
49+#define SEC_DRAM_SIZE                  0x01f00000
50
51 #define SECURE_GPIO_BASE               0x090b0000
52 #define SECURE_GPIO_SIZE               0x00001000
53```
54
553. Add configurations in `optee-repo/optee_os`:
56
57```
58diff --git a/mk/config.mk b/mk/config.mk
59index f2822df..8148cc5 100644
60--- a/mk/config.mk
61+++ b/mk/config.mk
62@@ -904,3 +904,7 @@ CFG_DRIVERS_TPM2_MMIO ?= n
63 ifeq ($(CFG_CORE_TPM_EVENT_LOG),y)
64 CFG_CORE_TCG_PROVIDER ?= $(CFG_DRIVERS_TPM2)
65 endif
66+
67+# expand TA secure memory
68+CFG_TZDRAM_START = 0x0e100000
69+CFG_TZDRAM_SIZE = 0x01f00000
70```
71
724. Patch for OP-TEE core pagetable:
73
74```
75diff --git a/core/include/mm/pgt_cache.h b/core/include/mm/pgt_cache.h
76index 0e72e17..28c58ad 100644
77--- a/core/include/mm/pgt_cache.h
78+++ b/core/include/mm/pgt_cache.h
79@@ -45,9 +45,9 @@ struct pgt {
80 #if CFG_NUM_THREADS < 2
81 #define PGT_CACHE_SIZE 4
82 #elif (CFG_NUM_THREADS == 2 && !defined(CFG_WITH_LPAE))
83-#define PGT_CACHE_SIZE 8
84+#define PGT_CACHE_SIZE 32
85 #else
86-#define PGT_CACHE_SIZE ROUNDUP(CFG_NUM_THREADS * 2, PGT_NUM_PGT_PER_PAGE)
87+#define PGT_CACHE_SIZE 32
88 #endif
89```
90
91Finally, build images:
92
93```
94$ cd optee-repo/build
95$ make
96```
97