spd: trusty: memmap trusty's code memory before peeking
authorVarun Wadekar <vwadekar@nvidia.com>
Thu, 3 Jan 2019 18:44:22 +0000 (10:44 -0800)
committerVarun Wadekar <vwadekar@nvidia.com>
Tue, 5 Feb 2019 16:27:43 +0000 (08:27 -0800)
This patch dynamically maps the first page of trusty's code memory,
before accessing it to find out if we are running a 32-bit or 64-bit
image.

On Tegra platforms, this means we have to increase the mappings to
accomodate the new memmap entry.

Change-Id: If370d1e6cfcccd69b260134c1b462d8d17bee03d
Signed-off-by: Varun Wadekar <vwadekar@nvidia.com>
plat/nvidia/tegra/soc/t186/platform_t186.mk
plat/nvidia/tegra/soc/t210/platform_t210.mk
services/spd/trusty/trusty.c

index fdeb886cda3015f16674a6e506e9a4152957f600..5d94d8e5f223da757c9b33859892447c660a74de 100644 (file)
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2015-2017, ARM Limited and Contributors. All rights reserved.
+# Copyright (c) 2015-2019, ARM Limited and Contributors. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -33,7 +33,7 @@ $(eval $(call add_define,PLATFORM_MAX_CPUS_PER_CLUSTER))
 MAX_XLAT_TABLES                                := 24
 $(eval $(call add_define,MAX_XLAT_TABLES))
 
-MAX_MMAP_REGIONS                       := 24
+MAX_MMAP_REGIONS                       := 25
 $(eval $(call add_define,MAX_MMAP_REGIONS))
 
 # platform files
index d9371ed6b6da4eb93094a3b2cd2dad29c78ba305..a11aef4dd2017b566fe19733456aca97fae6448f 100644 (file)
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
+# Copyright (c) 2015-2019, ARM Limited and Contributors. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -19,7 +19,7 @@ $(eval $(call add_define,PLATFORM_MAX_CPUS_PER_CLUSTER))
 MAX_XLAT_TABLES                                := 10
 $(eval $(call add_define,MAX_XLAT_TABLES))
 
-MAX_MMAP_REGIONS                       := 15
+MAX_MMAP_REGIONS                       := 16
 $(eval $(call add_define,MAX_MMAP_REGIONS))
 
 ENABLE_WDT_LEGACY_FIQ_HANDLING         := 1
index ce942dd2c743ca8267fffa7f1c4bf66019a75609..b059a4352a20ac07cbdf0ae1d8545650967fe1f2 100644 (file)
@@ -7,6 +7,7 @@
 #include <assert.h>
 #include <stdbool.h>
 #include <string.h>
+#include <xlat_tables_v2.h>
 
 #include <arch_helpers.h>
 #include <bl31/bl31.h>
@@ -412,6 +413,14 @@ static int32_t trusty_setup(void)
                return -1;
        }
 
+       /* memmap first page of trusty's code memory before peeking */
+       ret = mmap_add_dynamic_region(ep_info->pc, /* PA */
+                       ep_info->pc, /* VA */
+                       PAGE_SIZE, /* size */
+                       MT_SECURE | MT_RW_DATA); /* attrs */
+       assert(ret == 0);
+
+       /* peek into trusty's code to see if we have a 32-bit or 64-bit image */
        instr = *(uint32_t *)ep_info->pc;
 
        if (instr >> 24 == 0xeaU) {
@@ -424,6 +433,9 @@ static int32_t trusty_setup(void)
                return -1;
        }
 
+       /* unmap trusty's memory page */
+       (void)mmap_remove_dynamic_region(ep_info->pc, PAGE_SIZE);
+
        SET_PARAM_HEAD(ep_info, PARAM_EP, VERSION_1, SECURE | EP_ST_ENABLE);
        if (!aarch32)
                ep_info->spsr = SPSR_64(MODE_EL1, MODE_SP_ELX,