blob: f1dfc8c88a36c35a7a3d33a3caecd8e1c25a8aaf [file] [log] [blame]
yq.wang6c876f52025-05-17 16:56:50 +08001/*-----------------------------------------------------------------------------------------------*/
2/**
3 @file reboot_reason.c
4 @brief set reboot reason
5*/
6/*-----------------------------------------------------------------------------------------------*/
7
8/*-------------------------------------------------------------------------------------------------
9 Copyright (c) 2024 mobiletek Wireless Solution, Co., Ltd. All Rights Reserved.
10 mobiletek Wireless Solution Proprietary and Confidential.
11-------------------------------------------------------------------------------------------------*/
12
13/*-------------------------------------------------------------------------------------------------
14 EDIT HISTORY
15 This section contains comments describing changes made to the file.
16 Notice that changes are listed in reverse chronological order.
17 $Header: $
18 when who what, where, why
19 -------- --------- -----------------------------------------------------------------
20 20250515 yq.wang Created .
21-------------------------------------------------------------------------------------------------*/
22#include <stdio.h>
23#include <stdint.h>
24#include <stdlib.h>
25#include <unistd.h>
26#include <errno.h>
27#include <fcntl.h>
28#include <cutils/properties.h>
29
30#include "mbtk_type.h"
31#include "reboot_reason.h"
32#include "mbtk_log.h"
33#include "mbtk_device.h"
34
35int reboot_reason_init(void)
36{
37 int ret = 0;
38 char buff[32] = {0};
39 mbtk_device_info_reboot_flag_enum reboot_reason = MBTK_REBOOT_FLAG_NORMAL;
40 mbtk_device_info_basic_t info_basic = {0};
41 memset(&info_basic, 0, sizeof(mbtk_device_info_basic_t));
b.liub7530d22025-06-16 19:49:05 +080042
43
yq.wang6c876f52025-05-17 16:56:50 +080044 ret = mbtk_dev_info_read(MBTK_DEVICE_INFO_ITEM_BASIC, &(info_basic), sizeof(mbtk_device_info_basic_t));
45 if(ret != 0)
46 {
47 LOGE("[%s] mbtk_dev_info_read(BASIC) fail.", __func__);
48 reboot_reason = MBTK_REBOOT_FLAG_UNKNOWN;
49 }
50 else
51 {
b.liub7530d22025-06-16 19:49:05 +080052 if(info_basic.version == DEV_INFO_VERSION_V1) {
53 reboot_reason = info_basic.basic.v1.reboot_flag;
54 if(reboot_reason != MBTK_REBOOT_FLAG_NORMAL)
55 {
56 info_basic.basic.v1.reboot_flag = MBTK_REBOOT_FLAG_NORMAL;
57 ret = mbtk_dev_info_write(MBTK_DEVICE_INFO_ITEM_BASIC, &info_basic, sizeof(mbtk_device_info_basic_t));
58 if(ret != 0) {
59 LOGE("[%s] mbtk_dev_info_write(BASIC) fail.", __func__);
60 }
yq.wang6c876f52025-05-17 16:56:50 +080061 }
b.liub7530d22025-06-16 19:49:05 +080062 } else {
63 reboot_reason = info_basic.basic.v2.reboot_flag;
64 if(reboot_reason != MBTK_REBOOT_FLAG_NORMAL)
65 {
66 info_basic.basic.v2.reboot_flag = MBTK_REBOOT_FLAG_NORMAL;
67 ret = mbtk_dev_info_write(MBTK_DEVICE_INFO_ITEM_BASIC, &info_basic, sizeof(mbtk_device_info_basic_t));
68 if(ret != 0) {
69 LOGE("[%s] mbtk_dev_info_write(BASIC) fail.", __func__);
70 }
71 }
72
yq.wang6c876f52025-05-17 16:56:50 +080073 }
74 }
75
76 LOGD("[%s] reboot reason [%d].", __func__, reboot_reason);
77 memset(buff, 0x0, 32);
78 sprintf(buff, "%d", reboot_reason);
79 property_set("persist.mbtk.reboot_reason", buff);
b.liub7530d22025-06-16 19:49:05 +080080
yq.wang6c876f52025-05-17 16:56:50 +080081 LOGD("[%s] reboot reason exit.", __func__);
82
83 return 0;
84}
85