hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
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
// SPDX-License-Identifier: BSD-2-Clause
/*
 * Copyright (c) 2021 Rockchip Electronics Co. Ltd.
 */
#include <tee_internal_api.h>
#include "rktest_handle.h"
#include "../rk_public_api/rk_oem_otp_api.h"
 
 
TEE_Result handle_otp_read(void)
{
   TEE_Result res = TEE_SUCCESS;
   /*
    * RK356x platform require the address and length of OTP must be
    * an integral multiple of 2 integer(half word).
    */
   uint32_t read_len = 2;
   uint32_t read_offset = 0;
   uint8_t *read_data;
 
   //The memory used to invoke internal TA MUST BE secure memory, instead of CA memory.
   read_data = TEE_Malloc(read_len, 0);
   if (!read_data) {
       EMSG("Malloc context memory FAILED!");
       return TEE_ERROR_OUT_OF_MEMORY;
   }
   res = rk_otp_read(read_offset, read_data, read_len);
   if (res != TEE_SUCCESS)
       EMSG("rk_otp_read failed with code 0x%x", res);
   else
       IMSG("rk_otp_read succes with data: 0x%x, 0x%x", *read_data,
            *(read_data + 1));
 
   TEE_Free(read_data);
   return res;
}
 
TEE_Result handle_otp_write(void)
{
   TEE_Result res = TEE_SUCCESS;
   /*
    * RK356x platform require the address and length of OTP must be
    * an integral multiple of 2 integer(half word).
    */
   uint32_t write_len = 2;
   uint8_t write_data[2] = {0xaa, 0xaa};
   uint32_t write_offset = 0;
 
   res = rk_otp_write(write_offset, write_data, write_len);
   if (res != TEE_SUCCESS) {
       EMSG("rk_otp_write failed with code 0x%x", res);
       return res;
   }
   IMSG("rk_otp_write succes with data: 0x%x, 0x%x", write_data[0], write_data[1]);
   return res;
}
 
TEE_Result handle_otp_size(void)
{
   TEE_Result res = TEE_SUCCESS;
   uint32_t otp_size = 0;
 
   res = rk_otp_size(&otp_size);
   if (res != TEE_SUCCESS) {
       EMSG("rk_otp_size failed with code 0x%x", res);
       return res;
   }
   IMSG("The oem otp size is %d byte.", otp_size);
   return res;
}