blob: 5d0b25361b44b587e2a77e47d313fe77fd41c4bd [file] [log] [blame]
b.liud440f9f2025-04-18 10:44:31 +08001#include <string.h>
2#include <stdlib.h>
3#include <stdio.h>
4
5#include "ql_absys_api.h"
6#include "mbtk_type.h"
7#include "mbtk_fota.h"
8#include "mbtk_log.h"
9#include "mbtk_utils.h"
10
11int ql_absys_get_cur_active_part(absystem_t *cur_system)
12{
13 int active;
14
15 active = mbtk_fota_get_active_absys_type();
16 if (active == 0)
17 {
18 *cur_system = SYSTEM_A;
19 }
20 else if (active == 1)
21 {
22 *cur_system = SYSTEM_B;
23 }
24 else
25 {
26 LOGE("ql_absys_get_cur_active_part fail");
27 return -1;
28 }
29
30 return 0;
31}
32
33int ql_absys_switch(void)
34{
35 int absys_t, active, tmp_active, reboot_cnt;
36
37 active = mbtk_fota_get_active_absys_type();
38 tmp_active = mbtk_fota_get_tmp_absys_type();
39 absys_t = mbtk_fota_get_sync_absys_type();
40 reboot_cnt = mbtk_fota_get_asr_reboot_cnt_flag();
41 LOGI("ql_absys_get_cur_active_part active=%d,tmp_active=%d,absys_t=%d,reboot_cnt=%d",active,tmp_active,absys_t,reboot_cnt);
42
43 if (reboot_cnt == 0 && (active == tmp_active))
44 {
45 return 0;
46 }
47
48 if ((active == tmp_active) && absys_t == 0)
49 {
50 return -2;
51 }
52
53 if ((active != tmp_active) && absys_t == 0)
54 {
55 return -3;
56 }
57
58 return -1;
59}
60
61int ql_absys_getstatus(sysstatus_t *sys_state)
62{
63 int active, tmp_active, mtd_check;
64 char tmp_ac, ac;
65 char out[8]={0};
66
67 active = mbtk_fota_get_active_absys_type();
68 tmp_active = mbtk_fota_get_tmp_absys_type();
69 mtd_check = mbtk_fota_get_mtd_check_type();
70 LOGI("ql_absys_get_cur_active_part tmp_active=%d active=%d mtd_check=%d",tmp_active,active,mtd_check);
71
72 if (mtd_check == 0)
73 {
74 sys_state->is_damaged = 0;
75 }
76 else
77 {
78 if (tmp_active == 0)
79 tmp_ac = 'A';
80 else
81 tmp_ac = 'B';
82
83 if (active == 0)
84 ac = 'A';
85 else
86 ac = 'B';
87
88 sys_state->is_damaged = 1;
89 sprintf(out, "%c to %c",tmp_ac, ac);
90 memcpy(sys_state->damaged_partname, out, strlen(out));
91 }
92
93 return 0;
94}
95
96int ql_absys_sync(void)
97{
98 mbtk_system("sync");
99
100 return 0;
101}
102
103