Merge "[feature][T8TSK][MISC]add lynq_get_reboot_reason to sdk"
diff --git a/IC_src/mtk/lib/liblynq-misc/include/lynq_misc.h b/IC_src/mtk/lib/liblynq-misc/include/lynq_misc.h
index 4207191..3bf0202 100755
--- a/IC_src/mtk/lib/liblynq-misc/include/lynq_misc.h
+++ b/IC_src/mtk/lib/liblynq-misc/include/lynq_misc.h
@@ -21,7 +21,7 @@
* @return 0 success, -1 some error occur
*/
int lynq_get_security_boot_flag(int * enabled_flag);
-
+int lynq_get_reboot_reason(void);
#ifdef __cplusplus
}
#endif
diff --git a/IC_src/mtk/lib/liblynq-misc/lynq_misc.cpp b/IC_src/mtk/lib/liblynq-misc/lynq_misc.cpp
index 6e6fe8d..ee28293 100755
--- a/IC_src/mtk/lib/liblynq-misc/lynq_misc.cpp
+++ b/IC_src/mtk/lib/liblynq-misc/lynq_misc.cpp
@@ -1,4 +1,6 @@
#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
#include "lynq_misc.h"
#include "log/log.h"
@@ -40,3 +42,62 @@
*enabled_flag = (value & 0x8) == 0 ? 0 : 1;
return 0;
}
+
+
+
+int lynq_get_reboot_reason(void)
+{
+ FILE *fp;
+ int ret;
+ char buffer[8];
+ int flag[3];
+ char *token;
+ int i = 1;
+ fp = popen("cat /proc/aed/reboot-reason|sed -n '1p'|awk '{print $3, $6,$9}'","r");
+ fgets(buffer, sizeof(buffer), fp);
+ pclose(fp);
+ RLOGE("buffer is %s, size is %d\n", buffer, sizeof(buffer));
+ token = strtok(buffer, " ");
+ flag[0] = atoi(token);
+ while(i < 3)
+ {
+ token = strtok(NULL, " ");
+ flag[i] = atoi(token);
+ i++;
+ }
+ if(flag[0] == 0)
+ {
+ ret = system("cat /sys/fs/pstore/console-ramoops-0 > /dev/null");
+ if(ret == 0)
+ {
+ RLOGE("reboot reason is sysrst pin\n");
+ return 1;
+ }
+ else
+ {
+ RLOGE("reboot reason is power off\n");
+ return 0;
+ }
+ }
+ else if(flag[0] == 2)
+ {
+ if(flag[2] == 0)
+ {
+ RLOGE("reboot reason is soft nomal reboot\n");
+ return 2;
+ }
+ else
+ {
+ RLOGE("reboot reason is panic\n");
+ return 3;
+ }
+ }
+ else
+ {
+ RLOGE("reboot reason is other\n");
+ return 4;
+ }
+
+ return 0;
+
+}