blob: 023f5ac63fb95c218a9b0986665f77a3f30b3e5d [file] [log] [blame]
julhal0137e1aea2021-02-09 15:22:20 +00001/*
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 Hall7048d302021-06-03 16:07:28 +01007#include <config/interface/config_store.h>
8#include <config/interface/config_blob.h>
9#include <platform/interface/device_region.h>
julhal0137e1aea2021-02-09 15:22:20 +000010#include <stdint.h>
11
12/**
13 * Secure Partition configuration tests for checking configuartion
Julian Hall7048d302021-06-03 16:07:28 +010014 * data passed to an SP at initialisation. These tests rely on
15 * the SP manifest for deployments/env_test.
julhal0137e1aea2021-02-09 15:22:20 +000016 */
17
18/*
19 * Check that the loaded configuration includes one or more
20 * device regions.
21 */
22static bool check_device_region_loaded(struct test_failure *failure)
23{
Julian Hall7048d302021-06-03 16:07:28 +010024 return config_store_count(CONFIG_CLASSIFIER_DEVICE_REGION) > 0;
julhal0137e1aea2021-02-09 15:22:20 +000025}
26
27/*
28 * Check that a device region for a 'trng' device has been loaded
29 * and that values are as expected.
30 */
31static bool check_trng_device_region_loaded(struct test_failure *failure)
32{
Julian Hall7048d302021-06-03 16:07:28 +010033 struct device_region dev_region;
julhal0137e1aea2021-02-09 15:22:20 +000034
Julian Hall7048d302021-06-03 16:07:28 +010035 bool passed = config_store_query(CONFIG_CLASSIFIER_DEVICE_REGION,
36 "trng", 0,
37 &dev_region, sizeof(dev_region));
julhal0137e1aea2021-02-09 15:22:20 +000038
Julian Hall7048d302021-06-03 16:07:28 +010039 if (passed) {
julhal0137e1aea2021-02-09 15:22:20 +000040
Julian Hall7048d302021-06-03 16:07:28 +010041 passed = (dev_region.dev_instance == 0);
42 failure->line_num = __LINE__;
43 failure->info = dev_region.dev_instance;
julhal0137e1aea2021-02-09 15:22:20 +000044
Julian Hall7048d302021-06-03 16:07:28 +010045 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;
julhal0137e1aea2021-02-09 15:22:20 +000057}
58
59/*
60 * Check access to some trng registers
61 */
62static bool check_trng_register_access(struct test_failure *failure)
63{
Julian Hall7048d302021-06-03 16:07:28 +010064 struct device_region dev_region;
julhal0137e1aea2021-02-09 15:22:20 +000065
Julian Hall7048d302021-06-03 16:07:28 +010066 bool passed = config_store_query(CONFIG_CLASSIFIER_DEVICE_REGION,
67 "trng", 0,
68 &dev_region, sizeof(dev_region));
julhal0137e1aea2021-02-09 15:22:20 +000069
Julian Hall7048d302021-06-03 16:07:28 +010070 if (passed) {
julhal0137e1aea2021-02-09 15:22:20 +000071
Julian Hall7048d302021-06-03 16:07:28 +010072 /* Expect reset values to be read from a selection of TRNG registers */
73 uint32_t reg_val;
julhal0137e1aea2021-02-09 15:22:20 +000074
Julian Hall7048d302021-06-03 16:07:28 +010075 /* 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;
julhal0137e1aea2021-02-09 15:22:20 +000080
Julian Hall7048d302021-06-03 16:07:28 +010081 /* 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 {
julhal0137e1aea2021-02-09 15:22:20 +000090
Julian Hall7048d302021-06-03 16:07:28 +010091 failure->line_num = __LINE__;
92 }
93
94 return passed;
julhal0137e1aea2021-02-09 15:22:20 +000095}
96
Julian Hall7048d302021-06-03 16:07:28 +010097/*
98 * Check that the loaded configuration includes one or more
99 * configuration blobs. One is expected for teh TPM event log.
100 */
101static 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 */
109static 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 */
123static 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}
julhal0137e1aea2021-02-09 15:22:20 +0000148
149/**
150 * Define an register test group
151 */
152void sp_config_tests_register(void)
153{
Julian Hall7048d302021-06-03 16:07:28 +0100154 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 };
julhal0137e1aea2021-02-09 15:22:20 +0000162
Julian Hall7048d302021-06-03 16:07:28 +0100163 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 };
julhal0137e1aea2021-02-09 15:22:20 +0000169
Julian Hall7048d302021-06-03 16:07:28 +0100170 simple_c_test_runner_register_group(&sp_config_test_group);
171}