blob: efdf5d5c746be856d9986b1c9e6d7a599be3a8b8 [file] [log] [blame]
b.liud440f9f2025-04-18 10:44:31 +08001#include <stdlib.h>
2#include <stdio.h>
3#include <string.h>
4#include <sys/types.h>
5#include <unistd.h>
6#include <dlfcn.h>
7#include <stdint.h>
8#include <pthread.h>
9
10int (*lynq_get_upgrade_status)(void);
11int (*lynq_fota_set_addr_value)(char *value,int size);
12int (*lynq_fota_nrestart)(void);
13int (*lynq_rock_main)(int first_run);
14int (*lynq_read_process)(void);
15void *dlHandle_fota = NULL;
16
17void *thread_function_noreboot(void *arg)
18{
19
20 lynq_fota_nrestart();
21 return NULL;
22}
23
24void *thread_function_reboot(void *arg)
25{
26
27 lynq_rock_main(1);
28 return NULL;
29}
30
31
32int main(int argc,char *argv[])
33{
34 int ret = 0;
35 int reboot_flag;
36 char *value = argv[1];
37 printf("Enter main function\n");
38
39 const char *lynqLibPath_fota = "/lib/liblynq-fota.so";
40 dlHandle_fota = dlopen(lynqLibPath_fota, RTLD_NOW);
41 if (dlHandle_fota == NULL)
42 {
43 printf("dlopen dlHandle_fota failed: %s\n", dlerror());
44 return -1;
45 }
46
47 lynq_fota_set_addr_value = (int (*)(char *value,int size))dlsym(dlHandle_fota, "lynq_fota_set_addr_value");
48 if(lynq_fota_set_addr_value == NULL)
49 {
50 printf("lynq fota ser addr value is null\n");
51 return -1;
52 }
53
54 lynq_get_upgrade_status = (int (*)(void))dlsym(dlHandle_fota,"lynq_get_upgrade_status");
55 if(lynq_get_upgrade_status == NULL)
56 {
57 printf("lynq_get_upgrade_status is null\n");
58 return -1;
59 }
60 lynq_fota_nrestart = (int (*)())dlsym(dlHandle_fota,"lynq_fota_nrestart");
61 if(lynq_fota_nrestart == NULL)
62 {
63 printf("lynq_fota_nrestart is null\n");
64 return -1;
65 }
66 lynq_rock_main = (int (*)(int first_run))dlsym(dlHandle_fota,"lynq_rock_main");
67 if(lynq_rock_main == NULL)
68 {
69 printf("lynq_rock_main is null\n");
70 return -1;
71 }
72
73 lynq_read_process = (int (*)(void))dlsym(dlHandle_fota,"lynq_read_process");
74 if(lynq_read_process == NULL)
75 {
76 printf("lynq_read_process is null\n");
77 return -1;
78 }
79
80 ret = lynq_fota_set_addr_value(value,(int )strlen(value));
81 if(ret != 0)
82 {
83 printf("set upgrade package addr failed\n");
84 return -1;
85 }
86 while(1)
87 {
88 printf("Please chose action 0: upgrade done ,not reboot 1: upgrade done ,reboot 2:get upgrade status 3:read fota process \n");
89 if(1 != scanf("%d",&reboot_flag))
90 break;
91
92 switch(reboot_flag)
93 {
94 case 0:
95 {
96 pthread_t thread_id_noreboot;
97 int result = pthread_create(&thread_id_noreboot, NULL, thread_function_noreboot, NULL);
98 if (result != 0)
99 {
100 printf("pthread_create failed \n");
101 return -1;;
102 }
103 }
104 break;
105
106 case 1:
107 {
108 pthread_t thread_id_reboot;
109 int result = pthread_create(&thread_id_reboot, NULL, thread_function_reboot, NULL);
110 if (result != 0)
111 {
112 printf("pthread_create failed \n");
113 return -1;;
114 }
115 }
116 break;
117 case 2:
118 printf("Get fota upgrade status \n");
119 ret = lynq_get_upgrade_status();
120 printf("lynq_get_upgrade_status ret is %d\n",ret);
121 break;
122 case 3:
123 printf("get fota upgrade process\n");
124 ret = lynq_read_process();
125 printf("Now upgrade process is %d\n",ret);
126 break;
127 default:
128 printf("please input right flag 0 or 1 or 2 or 3\n");
129 break;
130
131 }
132
133 }
134 return 0;
135
136}
137