b.liu | d440f9f | 2025-04-18 10:44:31 +0800 | [diff] [blame] | 1 | #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 | |
| 11 | int ql_absys_get_cur_active_part(absystem_t *cur_system) |
| 12 | { |
b.liu | d440f9f | 2025-04-18 10:44:31 +0800 | [diff] [blame] | 13 | |
l.yang | 82a297c | 2025-05-13 01:12:41 -0700 | [diff] [blame] | 14 | FILE *file = NULL; |
| 15 | char cmdline[1024] = {0}; |
| 16 | |
| 17 | file = fopen("/proc/cmdline", "r"); |
| 18 | if(file == NULL) |
b.liu | d440f9f | 2025-04-18 10:44:31 +0800 | [diff] [blame] | 19 | { |
l.yang | 82a297c | 2025-05-13 01:12:41 -0700 | [diff] [blame] | 20 | LOGE("Failed to open /proc/cmdline"); |
| 21 | return -1; |
b.liu | d440f9f | 2025-04-18 10:44:31 +0800 | [diff] [blame] | 22 | } |
| 23 | |
l.yang | 82a297c | 2025-05-13 01:12:41 -0700 | [diff] [blame] | 24 | if(fgets(cmdline, sizeof(cmdline), file) != NULL) |
| 25 | { |
| 26 | if(strstr(cmdline, "system=a") != NULL) |
| 27 | { |
| 28 | *cur_system = SYSTEM_A; |
| 29 | } |
| 30 | else |
| 31 | { |
| 32 | *cur_system = SYSTEM_B; |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | fclose(file); |
b.liu | d440f9f | 2025-04-18 10:44:31 +0800 | [diff] [blame] | 37 | return 0; |
l.yang | 82a297c | 2025-05-13 01:12:41 -0700 | [diff] [blame] | 38 | |
b.liu | d440f9f | 2025-04-18 10:44:31 +0800 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | int ql_absys_switch(void) |
| 42 | { |
| 43 | int absys_t, active, tmp_active, reboot_cnt; |
| 44 | |
| 45 | active = mbtk_fota_get_active_absys_type(); |
| 46 | tmp_active = mbtk_fota_get_tmp_absys_type(); |
| 47 | absys_t = mbtk_fota_get_sync_absys_type(); |
| 48 | reboot_cnt = mbtk_fota_get_asr_reboot_cnt_flag(); |
| 49 | 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); |
| 50 | |
| 51 | if (reboot_cnt == 0 && (active == tmp_active)) |
| 52 | { |
| 53 | return 0; |
| 54 | } |
| 55 | |
| 56 | if ((active == tmp_active) && absys_t == 0) |
| 57 | { |
| 58 | return -2; |
| 59 | } |
| 60 | |
| 61 | if ((active != tmp_active) && absys_t == 0) |
| 62 | { |
| 63 | return -3; |
| 64 | } |
| 65 | |
| 66 | return -1; |
| 67 | } |
| 68 | |
| 69 | int ql_absys_getstatus(sysstatus_t *sys_state) |
| 70 | { |
| 71 | int active, tmp_active, mtd_check; |
| 72 | char tmp_ac, ac; |
| 73 | char out[8]={0}; |
| 74 | |
| 75 | active = mbtk_fota_get_active_absys_type(); |
| 76 | tmp_active = mbtk_fota_get_tmp_absys_type(); |
| 77 | mtd_check = mbtk_fota_get_mtd_check_type(); |
| 78 | LOGI("ql_absys_get_cur_active_part tmp_active=%d active=%d mtd_check=%d",tmp_active,active,mtd_check); |
| 79 | |
| 80 | if (mtd_check == 0) |
| 81 | { |
| 82 | sys_state->is_damaged = 0; |
| 83 | } |
| 84 | else |
| 85 | { |
| 86 | if (tmp_active == 0) |
| 87 | tmp_ac = 'A'; |
| 88 | else |
| 89 | tmp_ac = 'B'; |
| 90 | |
| 91 | if (active == 0) |
| 92 | ac = 'A'; |
| 93 | else |
| 94 | ac = 'B'; |
| 95 | |
| 96 | sys_state->is_damaged = 1; |
| 97 | sprintf(out, "%c to %c",tmp_ac, ac); |
| 98 | memcpy(sys_state->damaged_partname, out, strlen(out)); |
| 99 | } |
| 100 | |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | int ql_absys_sync(void) |
| 105 | { |
| 106 | mbtk_system("sync"); |
| 107 | |
| 108 | return 0; |
| 109 | } |
| 110 | |
| 111 | |