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