summaryrefslogtreecommitdiff
path: root/common/cmd_tee_log_level.c
blob: 1bccb62a7c861e33351785e2f58c96e4db4b43a6 (plain)
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
#include <common.h>

#define FUNCID_UPDATE_TEE_TRACE_LEVEL        0xb2000016

#define __asmeq(x, y) ".ifnc " x "," y " ; .err ; .endif\n\t"

static int atoi(const char* str)
{
	int ret = 0;

	if (!str)
		return ret;

	while ( *str != '\0') {
		if (('0' <= *str) && (*str <= '9')) {
			ret = ret * 10 + (*str++ - '0');
		} else {
			ret = 0;
			break;
		}
	}

	return ret;
}

static uint32_t update_log_level(uint32_t log_level)
{
	register uint32_t x0 asm("x0") = FUNCID_UPDATE_TEE_TRACE_LEVEL;
	register uint32_t x1 asm("x1") = log_level;
	do {
			asm volatile(
				__asmeq("%0", "x0")
				__asmeq("%1", "x0")
				__asmeq("%2", "x1")
				"smc    #0\n"
				: "=r"(x0)
				: "r"(x0), "r"(x1));
	} while (0);

	return x0;
}

int exec(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
	uint32_t log_level = 0;
	uint32_t updated_log_level = 0;

	if (argc != 2) {
		printf("BL33: parameter error,\n"
				"Usage:\ntee_log_level [log_level],\n"
				"the min log level is 1, and the max log level is related to"
				" Secure OS version\n");
		return 0;
	}

	log_level = atoi(argv[1]);
	updated_log_level = update_log_level(log_level);
	if (log_level < updated_log_level) {
		printf("BL33: the min log level is %d\n", updated_log_level);
	} else if (log_level > updated_log_level) {
		printf("BL33: the max log level is %d\n", updated_log_level);
	}
	printf("BL33: the updated log level is %d\n", updated_log_level);

	return 0;
}

/* -------------------------------------------------------------------- */
U_BOOT_CMD(
		tee_log_level, CONFIG_SYS_MAXARGS, 0, exec,
		"update tee log level",
		"[log_level],\nthe min log level is 1, and the max log level is"
		" related to Secure OS version"
);