-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtee-load-vid-fw.c
69 lines (59 loc) · 1.72 KB
/
tee-load-vid-fw.c
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
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (c) 2023 Freebox SA
* Author: Pierre-Hugues Husson <phhusson@freebox.fr>
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <tee_client_api.h>
#define TA_VIDEO_FW \
{ 0x526fc4fc, 0x7ee6, 0x4a12, {0x96, 0xe3, 0x83, 0xda, 0x95, 0x65, 0xbc, 0xe8} }
int main(void) {
TEEC_Result res;
TEEC_Context ctx;
TEEC_Session sess;
TEEC_UUID uuid = TA_VIDEO_FW;
uint32_t err_origin;
/* Initialize a context connecting us to the TEE */
res = TEEC_InitializeContext(NULL, &ctx);
if (res != TEEC_SUCCESS) {
fprintf(stderr, "TEEC_InitializeContext failed with code 0x%x", res);
return -1;
}
res = TEEC_OpenSession(&ctx, &sess, &uuid,
TEEC_LOGIN_PUBLIC, NULL, NULL, &err_origin);
if (res != TEEC_SUCCESS) {
fprintf(stderr, "TEEC_Opensession failed with code 0x%x origin 0x%x\n",
res, err_origin);
return -2;
}
TEEC_Operation op;
memset(&op, 0, sizeof(op));
op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, TEEC_MEMREF_TEMP_INPUT,
TEEC_VALUE_INPUT, TEEC_NONE);
int fd = open("video_ucode.bin", O_RDONLY);
off_t fdSize = lseek(fd, 0, SEEK_END);
lseek(fd, 0, SEEK_SET);
char *buf = malloc(fdSize);
read(fd, buf, fdSize);
close(fd);
op.params[0].tmpref.buffer = (void*)(buf + 0x100);
op.params[0].tmpref.size = fdSize - 0x100;
op.params[1].tmpref.buffer = (void*)buf;
op.params[1].tmpref.size = 0x100;
op.params[2].value.a = 0;
op.params[2].value.b = 0;
res = TEEC_InvokeCommand(&sess, 0, &op,
&err_origin);
if (res != TEEC_SUCCESS) {
fprintf(stderr, "TEEC_InvokeCommand failed with code 0x%x origin 0x%x\n",
res, err_origin);
return 1;
}
return 0;
}