lin
2025-04-14 e0c033f30287744d392a8d700693b1c0b78afc7c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
/*
 * (C) Copyright 2017-2018
 * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
 * wangwei <wangwei@allwinnertech.com>
 *
 * Configuration settings for the Allwinner sunxi series of boards.
 *
 * SPDX-License-Identifier:    GPL-2.0+
 */
 
#include <common.h>
#include <smc.h>
#include <sunxi_board.h>
#include "teesmc_v2.h"
#include <securestorage.h>
#include <efuse_map.h>
#include <memalign.h>
 
DECLARE_GLOBAL_DATA_PTR;
 
#define ARM_SVC_CALL_COUNT          0x8000ff00
#define ARM_SVC_UID                 0x8000ff01
/* 0x8000ff02 reserved */
#define ARM_SVC_VERSION             0x8000ff03
#define ARM_SVC_RUNNSOS             0x8000ff04
 
#ifdef CONFIG_SUNXI_ARM64
#define ARM_SVC_READ_SEC_REG        0x8000ff05
#define ARM_SVC_WRITE_SEC_REG       0x8000ff06
#else
#define ARM_SVC_READ_SEC_REG        OPTEE_SMC_READ_REG
#define ARM_SVC_WRITE_SEC_REG       OPTEE_SMC_WRITE_REG
#endif
 
#define PSCI_CPU_OFF                0x84000002
#define PSCI_CPU_ON_AARCH32         0x84000003
 
#define SUNXI_CPU_ON_AARCH32        0x84000010
#define SUNXI_CPU_OFF_AARCH32       0x84000011
#define SUNXI_CPU_WFI_AARCH32       0x84000012
/* arisc */
#define ARM_SVC_ARISC_STARTUP                   0x8000ff10
#define ARM_SVC_ARISC_WAIT_READY                0x8000ff11
#define ARM_SVC_ARISC_READ_PMU                  0x8000ff12
#define ARM_SVC_ARISC_WRITE_PMU                 0x8000ff13
#define ARM_SVC_ARISC_FAKE_POWER_OFF_REQ_ARCH32 0x83000019
 
/* efuse */
#define ARM_SVC_EFUSE_READ         (0x8000fe00)
#define ARM_SVC_EFUSE_WRITE        (0x8000fe01)
#define ARM_SVC_EFUSE_PROBE_SECURE_ENABLE_AARCH32    (0x8000fe03)
#define ARM_SVC_EFUSE_CUSTOMER_RESERVED_HANDLE        (0x8000fe05)
 
/*
*note pResult is will
*/
u32 sunxi_smc_call_optee(ulong arg0, ulong arg1, ulong arg2,
       ulong arg3, ulong pResult)
{
   struct arm_smccc_res param = { 0 };
   arm_smccc_smc(arg0, arg1, arg2, arg3, 0, 0, 0, 0, &param);
   return param.a0;
}
 
/*
*note pResult is will
*/
u32 sunxi_smc_call_atf(ulong arg0, ulong arg1, ulong arg2, ulong arg3,
   ulong pResult)
{
   return __sunxi_smc_call(arg0, arg1, arg2, arg3);
}
 
u32 sunxi_smc_call(ulong arg0, ulong arg1, ulong arg2,
       ulong arg3, ulong pResult)
{
#ifdef CONFIG_SUNXI_ARM64
   return sunxi_smc_call_atf(arg0, arg1, arg2, arg3, pResult);
#else
   return sunxi_smc_call_optee(arg0, arg1, arg2, arg3, pResult);
#endif
}
 
int arm_svc_set_cpu_on(int cpu, uint entry)
{
   return sunxi_smc_call(PSCI_CPU_ON_AARCH32, cpu, entry, 0, 0);
}
 
int arm_svc_set_cpu_off(int cpu)
{
   return sunxi_smc_call(PSCI_CPU_OFF, cpu, 0, 0, 0);
}
 
/*for multi cluster*/
int sunxi_smc_set_cpu_entry(u32 entry, int cpu)
{
   struct arm_smccc_res res;
   arm_smccc_smc(OPTEE_SMC_PLATFORM_CMD,
       TEE_SET_CPU_ENTRY, entry, cpu, 0, 0, 0, 0, &res);
   return res.a0;
}
 
/*for multi cluster*/
int sunxi_smc_set_cpu_off(void)
{
   struct arm_smccc_res res;
   arm_smccc_smc(OPTEE_SMC_PLATFORM_CMD,
       TEE_SET_CPU_OFF, 0, 0, 0, 0, 0, 0, &res);
   return res.a0;
}
 
 
int arm_svc_version(u32 *major, u32 *minor)
{
   u32 *pResult = NULL;
   int ret = 0;
   ret = sunxi_smc_call_atf(ARM_SVC_VERSION, 0, 0, 0, (ulong)&pResult);
   if (ret < 0)
       return ret;
 
   *major = pResult[0];
   *minor = pResult[1];
   return ret;
}
 
int arm_svc_call_count(void)
{
   return sunxi_smc_call_atf(ARM_SVC_CALL_COUNT, 0, 0, 0, 0);
}
 
int arm_svc_uuid(u32 *uuid)
{
   return sunxi_smc_call_atf(ARM_SVC_UID, 0, 0, 0, (ulong)uuid);
}
 
int arm_svc_run_os(ulong kernel, ulong fdt, ulong arg2)
{
   return sunxi_smc_call_atf(ARM_SVC_RUNNSOS, kernel, fdt, arg2, 0);
}
 
u32 arm_svc_read_sec_reg(ulong reg)
{
   return sunxi_smc_call(ARM_SVC_READ_SEC_REG, reg, 0, 0, 0);
}
 
int arm_svc_write_sec_reg(u32 val, ulong reg)
{
   sunxi_smc_call(ARM_SVC_WRITE_SEC_REG, reg, val, 0, 0);
   return 0;
}
 
int arm_svc_arisc_startup(ulong cfg_base)
{
   return sunxi_smc_call_atf(ARM_SVC_ARISC_STARTUP, cfg_base, 0, 0, 0);
}
 
int arm_svc_arisc_wait_ready(void)
{
   return sunxi_smc_call_atf(ARM_SVC_ARISC_WAIT_READY, 0, 0, 0, 0);
}
 
int arm_svc_arisc_fake_poweroff(void)
{
   return sunxi_smc_call(ARM_SVC_ARISC_FAKE_POWER_OFF_REQ_ARCH32, 0, 0, 0, 0);
}
 
u32 arm_svc_arisc_read_pmu(ulong addr)
{
   return sunxi_smc_call_atf(ARM_SVC_ARISC_READ_PMU, addr, 0, 0, 0);
}
 
int arm_svc_arisc_write_pmu(ulong addr, u32 value)
{
   return sunxi_smc_call_atf(ARM_SVC_ARISC_WRITE_PMU, addr, value, 0, 0);
}
 
int arm_svc_efuse_read(void *key_buf, void *read_buf)
{
#if defined(CONFIG_SUNXI_ARM64)
   return sunxi_smc_call(ARM_SVC_EFUSE_READ,
       (ulong)key_buf, (ulong)read_buf, 0, 0);
#else
   struct arm_smccc_res res;
   efuse_key_info_t *efuse_info;
   int offset, len;
   memset(&res, 0, sizeof(res));
       /*probe share memory*/
   arm_smccc_smc(OPTEE_SMC_CRYPT, TEESMC_PROBE_SHM_BASE,
   0, 0, 0, 0, 0, 0, &res);
   if (res.a0 != 0) {
       printf("smc tee probe share memory base failed\n ");
       return -1;
   }
 
   efuse_info = (efuse_key_info_t *)res.a1;
   if (!efuse_info)
       return -1;
 
   memcpy(efuse_info, key_buf, sizeof(efuse_key_info_t));
 
   memset(&res, 0, sizeof(res));
 
   sunxi_smc_call(OPTEE_SMC_EFUSE_OP, EFUSE_OP_RD,
       (ulong)efuse_info, 0, 0);
 
   offset = ROUND(sizeof(efuse_key_info_t), 8);
   len = *(int *)((u32)efuse_info + SUNXI_KEY_NAME_LEN);
   memcpy(read_buf, (void *)((u32)efuse_info + offset), len);
   return len;
#endif
}
 
int arm_svc_efuse_write(void *key_buf)
{
 
#if defined(CONFIG_SUNXI_ARM64)
   return sunxi_smc_call(ARM_SVC_EFUSE_WRITE,
               (ulong)key_buf, 0, 0, 0);
#else
   struct arm_smccc_res res;
   efuse_key_info_t *efuse_info;
   efuse_key_info_t *wd = (efuse_key_info_t *)key_buf;
   int offset;
   memset(&res, 0, sizeof(res));
   /*probe share memory*/
   arm_smccc_smc(OPTEE_SMC_CRYPT, TEESMC_PROBE_SHM_BASE,
   0, 0, 0, 0, 0, 0, &res);
   if (res.a0 != 0) {
       printf("smc tee probe share memory base failed\n ");
       return -1;
   }
 
   efuse_info = (efuse_key_info_t *)res.a1;
   if (!efuse_info)
       return -1;
 
   memcpy(efuse_info, key_buf, sizeof(efuse_key_info_t));
   offset = ROUND(sizeof(efuse_key_info_t), 8);
   memcpy((void *)((u32)efuse_info + offset), wd->key_data,
           wd->len);
   efuse_info->key_data = (u8 *)((u32)efuse_info + offset);
   memset(&res, 0, sizeof(res));
 
   /*For efuse, we can makesure 0x200 is enough*/
   flush_cache((ulong)efuse_info, 0x200);
   return sunxi_smc_call(OPTEE_SMC_EFUSE_OP, EFUSE_OP_WR,
       (ulong)efuse_info, 0, 0);
#endif
}
 
int arm_svc_probe_secure_mode(void)
{
   return sunxi_smc_call_atf(ARM_SVC_EFUSE_PROBE_SECURE_ENABLE_AARCH32,
       0, 0, 0, 0);
}
 
int arm_svc_customer_encrypt(u32 customer_reserved_id)
{
   return sunxi_smc_call(ARM_SVC_EFUSE_CUSTOMER_RESERVED_HANDLE,
       customer_reserved_id, 0, 0, 0);
}
 
static  u32 smc_readl_normal(ulong addr)
{
   return readl(addr);
}
static  int smc_writel_normal(u32 value, ulong addr)
{
   writel(value, addr);
   return 0;
}
 
u32 (*smc_readl_pt)(ulong addr) = smc_readl_normal;
int (*smc_writel_pt)(u32 value, ulong addr) = smc_writel_normal;
 
u32 smc_readl(ulong addr)
{
   return smc_readl_pt(addr);
}
 
void smc_writel(u32 val, ulong addr)
{
   smc_writel_pt(val, addr);
}
 
int smc_efuse_readl(void *key_buf, void *read_buf)
{
   printf("smc_efuse_readl is just a interface,you must override it\n");
   return 0;
}
 
int smc_efuse_writel(void *key_buf)
{
   printf("smc_efuse_writel is just a interface,you must override it\n");
   return 0;
}
 
 
int smc_init(void)
{
   if (sunxi_get_securemode()) {
       smc_readl_pt = arm_svc_read_sec_reg;
       smc_writel_pt = arm_svc_write_sec_reg;
   }
 
   return 0;
}
 
typedef struct _aes_function_info {
   uint32_t  decrypt;
   uint32_t  key_addr;
   uint32_t  key_len;
   uint32_t  iv_map;
   uint32_t  key_mode;
} aes_function_info;
 
struct smc_tee_ssk_addr_group {
   uint32_t out_tee;
   uint32_t in_tee;
   uint32_t private;
};
 
int smc_tee_ssk_encrypt(char *out_buf, char *in_buf, int len, int *out_len)
{
   struct arm_smccc_res param = { 0 };
   struct smc_tee_ssk_addr_group *tee_addr;
   int align_len = 0;
 
   align_len = ALIGN(len, CACHE_LINE_SIZE);
   arm_smccc_smc(OPTEE_SMC_CRYPT, TEESMC_PROBE_SHM_BASE,
       0, 0, 0, 0, 0, 0, &param);
   if (param.a0 != 0) {
       printf("smc tee probe share memory base failed\n ");
       return -1;
   }
 
   tee_addr = (struct smc_tee_ssk_addr_group *)param.a1;
   tee_addr->in_tee = param.a1 + 0x100;
   tee_addr->out_tee = tee_addr->in_tee + 4096;
   memset((void *)tee_addr->in_tee, 0x0, align_len);
   memcpy((void *)tee_addr->in_tee, in_buf, len);
   flush_cache(tee_addr->in_tee, align_len);
   flush_cache(tee_addr->out_tee, align_len);
   flush_cache((uint32_t)tee_addr,
           ALIGN(sizeof(struct smc_tee_ssk_addr_group),
             CACHE_LINE_SIZE));
 
   memset(&param, 0, sizeof(param));
   arm_smccc_smc(OPTEE_SMC_CRYPT, TEESMC_SSK_ENCRYPT,
       (uint32_t)tee_addr, align_len, 0, 0, 0, 0, &param);
   if (param.a0 != 0) {
       printf("smc tee encrypt with ssk failed with: %ld", param.a0);
 
       return -1;
   }
   memcpy(out_buf, (void *)tee_addr->out_tee, align_len);
   *out_len = align_len;
   return 0;
}
 
int smc_tee_ssk_decrypt(char *out_buf, char *in_buf, int len)
{
   struct arm_smccc_res param = { 0 };
   struct smc_tee_ssk_addr_group *tee_addr;
 
   arm_smccc_smc(OPTEE_SMC_CRYPT, TEESMC_PROBE_SHM_BASE,
       0, 0, 0, 0, 0, 0, &param);
   if (param.a0 != 0) {
       printf("smc tee probe share memory base failed\n ");
       return -1;
   }
 
   tee_addr = (struct smc_tee_ssk_addr_group *)param.a1;
   tee_addr->in_tee = param.a1 + 0x100;
   tee_addr->out_tee = tee_addr->in_tee + 4096;
   memcpy((void *)tee_addr->in_tee, in_buf, len);
   memset(&param, 0, sizeof(param));
   flush_cache(tee_addr->in_tee, len);
   flush_cache(tee_addr->out_tee, len);
   flush_cache((uint32_t)tee_addr,
           ALIGN(sizeof(struct smc_tee_ssk_addr_group),
             CACHE_LINE_SIZE));
 
   arm_smccc_smc(OPTEE_SMC_CRYPT, TEESMC_SSK_DECRYPT,
       (uint32_t)tee_addr, len, 0, 0, 0, 0, &param);
   if (param.a0 != 0) {
       printf("smc tee decrypt with ssk failed with: %ld", param.a0);
 
       return param.a0;
   }
   memcpy(out_buf, (void *)tee_addr->out_tee, len);
 
   return 0;
}
 
int smc_tee_rssk_encrypt(char *out_buf, char *in_buf, int len, int *out_len)
{
   struct smc_tee_ssk_addr_group *tee_addr;
   int align_len = 0;
   struct arm_smccc_res param = { 0 };
 
   align_len = ALIGN(len, CACHE_LINE_SIZE);
 
   arm_smccc_smc(OPTEE_SMC_CRYPT, TEESMC_PROBE_SHM_BASE,
       0, 0, 0, 0, 0, 0, &param);
   if (param.a0 != 0) {
       printf("smc tee probe share memory base failed\n ");
       return -1;
   }
 
   tee_addr = (struct smc_tee_ssk_addr_group *)param.a1;
   tee_addr->in_tee = param.a1 + 0x100;
   tee_addr->out_tee = tee_addr->in_tee + 4096;
   memset((void *)tee_addr->in_tee, 0x0, align_len);
   memcpy((void *)tee_addr->in_tee, in_buf, len);
   flush_cache(tee_addr->in_tee, align_len);
   flush_cache(tee_addr->out_tee, align_len);
   flush_cache((uint32_t)tee_addr,
           ALIGN(sizeof(struct smc_tee_ssk_addr_group),
             CACHE_LINE_SIZE));
 
   memset(&param, 0, sizeof(param));
   arm_smccc_smc(OPTEE_SMC_CRYPT, TEESMC_RSSK_ENCRYPT,
       (uint32_t)tee_addr, align_len, 0, 0, 0, 0, &param);
   if (param.a0 != 0) {
       printf("smc tee encrypt with ssk failed with: %ld", param.a0);
 
       return param.a0;
   }
   memcpy(out_buf, (void *)tee_addr->out_tee, align_len);
   *out_len = align_len;
   return 0;
}
 
int smc_aes_rssk_decrypt_to_keysram(void)
{
   struct smc_tee_ssk_addr_group *tee_addr;
   struct arm_smccc_res param = { 0 };
 
   arm_smccc_smc(OPTEE_SMC_CRYPT, TEESMC_PROBE_SHM_BASE,
       0, 0, 0, 0, 0, 0, &param);
   if (param.a0 != 0) {
       printf("smc tee probe share memory base failed\n ");
       return -1;
   }
 
   tee_addr = (struct smc_tee_ssk_addr_group *)param.a1;
   tee_addr->in_tee = param.a1 + 0x100;
   tee_addr->out_tee = tee_addr->in_tee + 4096;
   memset(&param, 0, sizeof(param));
   flush_cache((uint32_t)tee_addr,
           ALIGN(sizeof(struct smc_tee_ssk_addr_group),
             CACHE_LINE_SIZE));
   arm_smccc_smc(OPTEE_SMC_CRYPT, TEESMC_RSSK_DECRYPT,
       0, SUNXI_HDCP_KEY_LEN, 0, 0, 0, 0, &param);
 
   if (param.a0 != 0) {
       printf("smc tee decrypt with ssk failed with: %ld", param.a0);
       return param.a0;
   }
   return 0;
 
}
 
int smc_aes_algorithm(char *out_buf, char *in_buf, int data_len,
   char *pkey, int key_mode, int decrypt)
{
   struct smc_tee_ssk_addr_group *tee_addr;
   aes_function_info *p_aes_info = NULL;
   int len = data_len;
   uint8_t *aes_key = NULL;
   struct arm_smccc_res param = { 0 };
 
   arm_smccc_smc(OPTEE_SMC_CRYPT, TEESMC_PROBE_SHM_BASE,
       0, 0, 0, 0, 0, 0, &param);
   if (param.a0 != 0) {
       printf("smc tee probe share memory base failed\n ");
       return -1;
   }
 
   tee_addr = (struct smc_tee_ssk_addr_group *)param.a1;
   tee_addr->in_tee = param.a1 + 0x100;
   tee_addr->out_tee = tee_addr->in_tee + 4096;
   tee_addr->private = tee_addr->out_tee + 4096;
   aes_key = (uint8_t *)(tee_addr->private + 256);
 
   p_aes_info = (aes_function_info *)tee_addr->private;
   p_aes_info->decrypt = decrypt;
   p_aes_info->key_len = 128/8; /* key len is 128 bit */
   p_aes_info->key_addr = (uint32_t)aes_key;
   memcpy((void *)p_aes_info->key_addr, pkey, p_aes_info->key_len);
 
   memcpy((void *)tee_addr->in_tee, in_buf, len);
   memset(&param, 0, sizeof(param));
   flush_cache(tee_addr->in_tee, ALIGN(len, CACHE_LINE_SIZE));
   flush_cache(tee_addr->out_tee, ALIGN(len, CACHE_LINE_SIZE));
   flush_cache(tee_addr->private,
           ALIGN(sizeof(aes_function_info), CACHE_LINE_SIZE));
   flush_cache(p_aes_info->key_addr,
           ALIGN(p_aes_info->key_len, CACHE_LINE_SIZE));
   flush_cache((uint32_t)tee_addr,
           ALIGN(sizeof(struct smc_tee_ssk_addr_group),
             CACHE_LINE_SIZE));
   arm_smccc_smc(OPTEE_SMC_CRYPT, TEESMC_AES_CBC,
       (uint32_t)tee_addr, len, 0, 0, 0, 0, &param);
 
   if (param.a0 != 0) {
       printf("smc tee decrypt with ssk failed with: %ld", param.a0);
       return param.a0;
   }
   memcpy(out_buf, (void *)tee_addr->out_tee, len);
   return 0;
}
 
 
int smc_tee_keybox_store(const char *name, char *in_buf, int len)
{
   sunxi_secure_storage_info_t *key_box;
   struct arm_smccc_res param = { 0 };
 
   arm_smccc_smc(OPTEE_SMC_CRYPT, TEESMC_PROBE_SHM_BASE,
       0, 0, 0, 0, 0, 0, &param);
   if (param.a0 != 0) {
       printf("smc tee probe share memory base failed\n ");
       return -1;
   }
 
   key_box = (sunxi_secure_storage_info_t *)param.a1;
   memcpy(key_box, in_buf, len);
#if 0 /*debug info*/
   printf("len=%d\n", len);
   printf("name=%s\n", key_box->name);
   printf("len=%d\n",  key_box->len);
   printf("encrypt=%d\n", key_box->encrypted);
   printf("write_protect=%d\n", key_box->write_protect);
   printf("******************\n");
#endif
   if (strcmp(name, key_box->name)) {
       pr_err("name of key %s not match, key data corrupted\n", name);
       return -1;
   }
 
   flush_cache((ulong)key_box, sizeof(sunxi_secure_storage_info_t));
 
   memset(&param, 0, sizeof(param));
   arm_smccc_smc(OPTEE_SMC_CRYPT, TEESMC_KEYBOX_STORE,
       (uint32_t)key_box, 0, 0, 0, 0, 0, &param);
 
   if (param.a0 != 0) {
       printf("smc tee keybox store failed with: %ld", param.a0);
 
       return param.a0;
   }
 
   return 0;
}
 
int smc_tee_probe_drm_configure(ulong *drm_base, ulong *drm_size)
{
   struct arm_smccc_res param = { 0 };
   arm_smccc_smc(OPTEE_SMC_GET_DRM_INFO, 0, 0, 0, 0, 0, 0, 0, &param);
 
   if (param.a0 != 0) {
       printf("drm config service not available: %X", (uint)param.a0);
       return param.a0;
   }
 
   *drm_base = param.a1;
   *drm_size = param.a2;
 
   return 0;
}
 
int smc_tee_check_hash(const char *name, u8 *hash)
{
#define NAME_MAX_SIZE 16
   struct arm_smccc_res res;
   char *smc_name, *smc_hash;
 
   memset(&res, 0, sizeof(res));
   /*probe share memory*/
   arm_smccc_smc(OPTEE_SMC_CRYPT, TEESMC_PROBE_SHM_BASE, 0, 0, 0, 0, 0, 0,
             &res);
   if (res.a0 != 0) {
       printf("smc tee probe share memory base failed\n ");
       return -1;
   }
   if (!res.a1)
       return -1;
   smc_name = (char *)res.a1;
   strncpy(smc_name, name, NAME_MAX_SIZE);
   smc_name[NAME_MAX_SIZE - 1] = 0;
   smc_hash            = (char *)((u32)smc_name + NAME_MAX_SIZE);
   memcpy(smc_hash, hash, 32);
 
   flush_cache((ulong)smc_name,
           ALIGN(NAME_MAX_SIZE + 32, CACHE_LINE_SIZE));
   return sunxi_smc_call(OPTEE_SMC_SUNXI_HASH_OP, (ulong)smc_name,
                 (ulong)smc_hash, 0, 0);
}