julhal01 | 37e1aea | 2021-02-09 15:22:20 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | #include <service/test_runner/provider/backend/simple_c/simple_c_test_runner.h> |
Julian Hall | 7048d30 | 2021-06-03 16:07:28 +0100 | [diff] [blame^] | 7 | #include <config/interface/config_store.h> |
| 8 | #include <config/interface/config_blob.h> |
| 9 | #include <platform/interface/device_region.h> |
julhal01 | 37e1aea | 2021-02-09 15:22:20 +0000 | [diff] [blame] | 10 | #include <stdint.h> |
| 11 | |
| 12 | /** |
| 13 | * Secure Partition configuration tests for checking configuartion |
Julian Hall | 7048d30 | 2021-06-03 16:07:28 +0100 | [diff] [blame^] | 14 | * data passed to an SP at initialisation. These tests rely on |
| 15 | * the SP manifest for deployments/env_test. |
julhal01 | 37e1aea | 2021-02-09 15:22:20 +0000 | [diff] [blame] | 16 | */ |
| 17 | |
| 18 | /* |
| 19 | * Check that the loaded configuration includes one or more |
| 20 | * device regions. |
| 21 | */ |
| 22 | static bool check_device_region_loaded(struct test_failure *failure) |
| 23 | { |
Julian Hall | 7048d30 | 2021-06-03 16:07:28 +0100 | [diff] [blame^] | 24 | return config_store_count(CONFIG_CLASSIFIER_DEVICE_REGION) > 0; |
julhal01 | 37e1aea | 2021-02-09 15:22:20 +0000 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | /* |
| 28 | * Check that a device region for a 'trng' device has been loaded |
| 29 | * and that values are as expected. |
| 30 | */ |
| 31 | static bool check_trng_device_region_loaded(struct test_failure *failure) |
| 32 | { |
Julian Hall | 7048d30 | 2021-06-03 16:07:28 +0100 | [diff] [blame^] | 33 | struct device_region dev_region; |
julhal01 | 37e1aea | 2021-02-09 15:22:20 +0000 | [diff] [blame] | 34 | |
Julian Hall | 7048d30 | 2021-06-03 16:07:28 +0100 | [diff] [blame^] | 35 | bool passed = config_store_query(CONFIG_CLASSIFIER_DEVICE_REGION, |
| 36 | "trng", 0, |
| 37 | &dev_region, sizeof(dev_region)); |
julhal01 | 37e1aea | 2021-02-09 15:22:20 +0000 | [diff] [blame] | 38 | |
Julian Hall | 7048d30 | 2021-06-03 16:07:28 +0100 | [diff] [blame^] | 39 | if (passed) { |
julhal01 | 37e1aea | 2021-02-09 15:22:20 +0000 | [diff] [blame] | 40 | |
Julian Hall | 7048d30 | 2021-06-03 16:07:28 +0100 | [diff] [blame^] | 41 | passed = (dev_region.dev_instance == 0); |
| 42 | failure->line_num = __LINE__; |
| 43 | failure->info = dev_region.dev_instance; |
julhal01 | 37e1aea | 2021-02-09 15:22:20 +0000 | [diff] [blame] | 44 | |
Julian Hall | 7048d30 | 2021-06-03 16:07:28 +0100 | [diff] [blame^] | 45 | if (passed) { |
| 46 | passed = (dev_region.io_region_size == 0x1000); |
| 47 | failure->line_num = __LINE__; |
| 48 | failure->info = dev_region.io_region_size; |
| 49 | } |
| 50 | } |
| 51 | else { |
| 52 | |
| 53 | failure->line_num = __LINE__; |
| 54 | } |
| 55 | |
| 56 | return passed; |
julhal01 | 37e1aea | 2021-02-09 15:22:20 +0000 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | /* |
| 60 | * Check access to some trng registers |
| 61 | */ |
| 62 | static bool check_trng_register_access(struct test_failure *failure) |
| 63 | { |
Julian Hall | 7048d30 | 2021-06-03 16:07:28 +0100 | [diff] [blame^] | 64 | struct device_region dev_region; |
julhal01 | 37e1aea | 2021-02-09 15:22:20 +0000 | [diff] [blame] | 65 | |
Julian Hall | 7048d30 | 2021-06-03 16:07:28 +0100 | [diff] [blame^] | 66 | bool passed = config_store_query(CONFIG_CLASSIFIER_DEVICE_REGION, |
| 67 | "trng", 0, |
| 68 | &dev_region, sizeof(dev_region)); |
julhal01 | 37e1aea | 2021-02-09 15:22:20 +0000 | [diff] [blame] | 69 | |
Julian Hall | 7048d30 | 2021-06-03 16:07:28 +0100 | [diff] [blame^] | 70 | if (passed) { |
julhal01 | 37e1aea | 2021-02-09 15:22:20 +0000 | [diff] [blame] | 71 | |
Julian Hall | 7048d30 | 2021-06-03 16:07:28 +0100 | [diff] [blame^] | 72 | /* Expect reset values to be read from a selection of TRNG registers */ |
| 73 | uint32_t reg_val; |
julhal01 | 37e1aea | 2021-02-09 15:22:20 +0000 | [diff] [blame] | 74 | |
Julian Hall | 7048d30 | 2021-06-03 16:07:28 +0100 | [diff] [blame^] | 75 | /* PID4 */ |
| 76 | reg_val = *((volatile uint32_t*)((uint8_t*)dev_region.base_addr + 0xfd0)); |
| 77 | passed = (reg_val == 0x00000004); |
| 78 | failure->line_num = __LINE__; |
| 79 | failure->info = reg_val; |
julhal01 | 37e1aea | 2021-02-09 15:22:20 +0000 | [diff] [blame] | 80 | |
Julian Hall | 7048d30 | 2021-06-03 16:07:28 +0100 | [diff] [blame^] | 81 | /* PID0 */ |
| 82 | if (passed) { |
| 83 | reg_val = *((volatile uint32_t*)((uint8_t*)dev_region.base_addr + 0xfe0)); |
| 84 | passed = (reg_val == 0x000000aa); |
| 85 | failure->line_num = __LINE__; |
| 86 | failure->info = reg_val; |
| 87 | } |
| 88 | } |
| 89 | else { |
julhal01 | 37e1aea | 2021-02-09 15:22:20 +0000 | [diff] [blame] | 90 | |
Julian Hall | 7048d30 | 2021-06-03 16:07:28 +0100 | [diff] [blame^] | 91 | failure->line_num = __LINE__; |
| 92 | } |
| 93 | |
| 94 | return passed; |
julhal01 | 37e1aea | 2021-02-09 15:22:20 +0000 | [diff] [blame] | 95 | } |
| 96 | |
Julian Hall | 7048d30 | 2021-06-03 16:07:28 +0100 | [diff] [blame^] | 97 | /* |
| 98 | * Check that the loaded configuration includes one or more |
| 99 | * configuration blobs. One is expected for teh TPM event log. |
| 100 | */ |
| 101 | static bool check_config_blob_loaded(struct test_failure *failure) |
| 102 | { |
| 103 | return config_store_count(CONFIG_CLASSIFIER_BLOB) > 0; |
| 104 | } |
| 105 | |
| 106 | /* |
| 107 | * Check that the event log has been loaded. |
| 108 | */ |
| 109 | static bool check_event_log_loaded(struct test_failure *failure) |
| 110 | { |
| 111 | struct config_blob config_blob; |
| 112 | |
| 113 | bool passed = config_store_query(CONFIG_CLASSIFIER_BLOB, |
| 114 | "EVENT_LOG", 0, |
| 115 | &config_blob, sizeof(config_blob)); |
| 116 | |
| 117 | return passed; |
| 118 | } |
| 119 | |
| 120 | /* |
| 121 | * Check that the event log can be accessed |
| 122 | */ |
| 123 | static bool check_event_log_access(struct test_failure *failure) |
| 124 | { |
| 125 | struct config_blob config_blob; |
| 126 | |
| 127 | bool passed = config_store_query(CONFIG_CLASSIFIER_BLOB, |
| 128 | "EVENT_LOG", 0, |
| 129 | &config_blob, sizeof(config_blob)); |
| 130 | |
| 131 | if (passed) { |
| 132 | |
| 133 | passed = (config_blob.data_len > 0); |
| 134 | failure->line_num = __LINE__; |
| 135 | |
| 136 | if (passed) { |
| 137 | passed = (config_blob.data); |
| 138 | failure->line_num = __LINE__; |
| 139 | } |
| 140 | } |
| 141 | else { |
| 142 | |
| 143 | failure->line_num = __LINE__; |
| 144 | } |
| 145 | |
| 146 | return passed; |
| 147 | } |
julhal01 | 37e1aea | 2021-02-09 15:22:20 +0000 | [diff] [blame] | 148 | |
| 149 | /** |
| 150 | * Define an register test group |
| 151 | */ |
| 152 | void sp_config_tests_register(void) |
| 153 | { |
Julian Hall | 7048d30 | 2021-06-03 16:07:28 +0100 | [diff] [blame^] | 154 | static const struct simple_c_test_case sp_config_tests[] = { |
| 155 | {.name = "DevRegionLoaded", .test_func = check_device_region_loaded}, |
| 156 | {.name = "TrngDevRegionLoaded", .test_func = check_trng_device_region_loaded}, |
| 157 | {.name = "TrngRegAccess", .test_func = check_trng_register_access}, |
| 158 | {.name = "ConfigBlobLoaded", .test_func = check_config_blob_loaded}, |
| 159 | {.name = "EventLogLoaded", .test_func = check_event_log_loaded}, |
| 160 | {.name = "EventLogAccess", .test_func = check_event_log_access} |
| 161 | }; |
julhal01 | 37e1aea | 2021-02-09 15:22:20 +0000 | [diff] [blame] | 162 | |
Julian Hall | 7048d30 | 2021-06-03 16:07:28 +0100 | [diff] [blame^] | 163 | static const struct simple_c_test_group sp_config_test_group = |
| 164 | { |
| 165 | .group = "SpConfigTests", |
| 166 | .num_test_cases = sizeof(sp_config_tests)/sizeof(struct simple_c_test_case), |
| 167 | .test_cases = sp_config_tests |
| 168 | }; |
julhal01 | 37e1aea | 2021-02-09 15:22:20 +0000 | [diff] [blame] | 169 | |
Julian Hall | 7048d30 | 2021-06-03 16:07:28 +0100 | [diff] [blame^] | 170 | simple_c_test_runner_register_group(&sp_config_test_group); |
| 171 | } |