linuxdriver: support dump tee log [1/1]
authorPengguang Zhu <pengguang.zhu@amlogic.com>
Wed, 24 Jun 2020 03:06:38 +0000 (11:06 +0800)
committerPengguang Zhu <pengguang.zhu@amlogic.com>
Wed, 24 Jun 2020 03:09:10 +0000 (11:09 +0800)
PD#TV-20362

Problem:
Save the key information like fatal error
to buffer when OPTEE process crash

Solution:
add sysfs node to dump the log buffer

Verify:
Android Q + franklin

Change-Id: I4b292a07034ee424911a14f86a885890d21e7be4
Signed-off-by: Pengguang Zhu <pengguang.zhu@amlogic.com>
optee/log.c

index bac6ae084f5ceb99394b77366ecc03b982c6c1ff..5f348e36b301f3c021cf038e8eeae88794fb8fc6 100644 (file)
@@ -54,6 +54,7 @@ static unsigned char *optee_log_buff;
 static uint32_t optee_log_mode = 1;
 static struct timer_list optee_log_timer;
 static uint8_t line_buff[OPTEE_LOG_LINE_MAX];
+static uint32_t looped = 0;
 static void *g_shm_va;
 
 static bool init_shm(phys_addr_t shm_pa, uint32_t shm_size)
@@ -128,8 +129,10 @@ static ssize_t log_buff_get_read_buff(char **buf, int len)
                read_size = 0;
        else if (reader < writer)
                read_size = writer - reader;
-       else
+       else {
+               looped = 1;
                read_size = ctl->total_size - reader;
+       }
 
        if (read_size > len)
                read_size = len;
@@ -149,6 +152,9 @@ static size_t log_print_text(char *buf, size_t size)
        size_t len = 0;
        char *line = line_buff;
 
+       if (size == 0)
+               return 0;
+
        do {
                const char *next = memchr(text, '\n', text_size);
                size_t line_size;
@@ -175,27 +181,31 @@ static size_t log_print_text(char *buf, size_t size)
        return len;
 }
 
-static ssize_t log_buff_dump(char *buf, size_t size)
+static ssize_t log_buff_dump(void)
 {
        ssize_t len;
        char *ptr = NULL;
+       unsigned int writer = 0;
        struct optee_log_ctl_s *ctl = optee_log_ctl;
 
        if (!ctl)
                return 0;
 
-       len = ctl->reader;
-       if (len == 0)
-               return 0;
+       writer = ctl->writer;
 
-       ptr = optee_log_buff;
-       if (len > size) {
-               ptr += len - size;
-               len = size;
+       if (looped) {
+               ptr = optee_log_buff + writer;
+               len = ctl->total_size - writer;
+
+               log_print_text(ptr, len);
        }
-       memcpy(buf, ptr, len);
 
-       return len;
+       ptr = optee_log_buff;
+       len = writer;
+
+       log_print_text(ptr, len);
+
+       return 0;
 }
 
 static void log_buff_reset(void)
@@ -249,7 +259,9 @@ static ssize_t log_buff_store(struct class *cla, struct class_attribute *attr,
 static ssize_t log_buff_show(struct class *cla,
                struct class_attribute *attr, char *buf)
 {
-       return log_buff_dump(buf, OPTEE_LOG_READ_MAX);
+       log_buff_dump();
+
+       return 0;
 }
 
 static struct class_attribute log_class_attrs[] = {