#include <stdio.h> | |
#include <string.h> | |
#include <stdlib.h> | |
#include "lynq_misc.h" | |
#include "log/log.h" | |
#undef LOG_TAG | |
#define LOG_TAG "MISC" | |
int lynq_get_security_boot_flag(int * enabled_flag) | |
{ | |
int value, ret; | |
if (enabled_flag == NULL) | |
{ | |
RLOGE("input param is null ptr"); | |
return -1; | |
} | |
*enabled_flag = 0; | |
FILE *pfile=fopen("/proc/device-tree/chosen/atag,devinfo", "r"); | |
if (pfile == NULL) | |
{ | |
RLOGE("open devinfo fail"); | |
return -1; | |
} | |
ret = fseek(pfile, 0x428, 0); | |
if (ret != 0) | |
{ | |
RLOGE("seek file fail"); | |
fclose(pfile); | |
return -1; | |
} | |
ret = fread(&value, sizeof (value), 1, pfile); | |
if (ret != 1) | |
{ | |
RLOGE("read file fail"); | |
fclose(pfile); | |
return -1; | |
} | |
fclose(pfile); | |
// the third bit of 32bits at 0x428 (index start with 0?), 1 for enabled, 0 not enabled | |
*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; | |
} |