1 #include <stdio.h>
2 #include <unistd.h>
3 #include <stdlib.h>
4 #include "Upgrade.h"
5
6 enum { INSTALL_SUCCESS, INSTALL_ERROR, INSTALL_CORRUPT };
7
8 FILE *cmd_pipe = NULL;
9 int sdBootUpdate = 0;
10
11
handle_upgrade_callback(char * szPrompt)12 void handle_upgrade_callback(char *szPrompt)
13 {
14 if (cmd_pipe != NULL)
15 {
16 fprintf(cmd_pipe, "ui_print %s\n", szPrompt);
17 }
18 }
19
handle_upgrade_progress_callback(float portion,float seconds)20 void handle_upgrade_progress_callback(float portion, float seconds)
21 {
22 if (cmd_pipe != NULL)
23 {
24 if (seconds == 0)
25 {
26 fprintf(cmd_pipe, "set_progress %f\n", portion);
27 }
28 else
29 {
30 fprintf(cmd_pipe, "progress %f %d\n", portion, seconds);
31 }
32 }
33 }
34
main(int argc,char * argv[])35 int main(int argc, char *argv[])
36 {
37 int status;
38
39 setbuf(stdout, NULL);
40 setbuf(stderr, NULL);
41 if (argc != 5)
42 {
43 printf("unexpected number of arguments (%d)\n", argc);
44 fprintf(stderr, "unexpected number of arguments (%d)\n", argc);
45 return 1;
46 }
47 int fd = atoi(argv[2]);
48 cmd_pipe = fdopen(fd, "wb");
49 setlinebuf(cmd_pipe);
50
51 char *filepath = argv[3];
52 sdBootUpdate = atoi(argv[4]);
53
54 //call update
55 bool bRet = do_rk_firmware_upgrade(filepath, (void *)handle_upgrade_callback,
56 (void *)handle_upgrade_progress_callback);
57
58 if (!bRet)
59 {
60 status = INSTALL_ERROR;
61 }
62 else
63 {
64 status = INSTALL_SUCCESS;
65 }
66
67 sleep(5);
68 sync();
69 return status;
70 }
71