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
71
72
73
74
75
76
77
78
79
80
|
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <getopt.h>
#include "hiddevice.h"
#include "rmi4update.h"
#define RMI4UPDATE_GETOPTS "hf"
void printHelp(const char *prog_name)
{
fprintf(stdout, "Usage: %s [OPTIONS] DEVICEFILE FIRMWAREFILE\n", prog_name);
fprintf(stdout, "\t-h, --help\tPrint this message\n");
fprintf(stdout, "\t-f, --force\tForce updating firmware even it the image provided is older\n\t\t\tthen the current firmware on the device.\n");
}
int main(int argc, char **argv)
{
int rc;
HIDDevice rmidevice;
FirmwareImage image;
int opt;
int index;
const char *deviceName = NULL;
const char *firmwareName = NULL;
bool force = false;
static struct option long_options[] = {
{"help", 0, NULL, 'h'},
{"force", 0, NULL, 'f'},
{0, 0, 0, 0},
};
while ((opt = getopt_long(argc, argv, RMI4UPDATE_GETOPTS, long_options, &index)) != -1) {
switch (opt) {
case 'h':
printHelp(argv[0]);
return 0;
case 'f':
force = true;
break;
default:
break;
}
}
if (optind < argc)
deviceName = argv[optind++];
else
return -1;
if (optind < argc)
firmwareName = argv[optind];
else
return -1;
rc = rmidevice.Open(deviceName);
if (rc) {
fprintf(stderr, "Failed to open rmi device: %s\n", strerror(errno));
return rc;
}
rc = image.Initialize(firmwareName);
if (rc != UPDATE_SUCCESS) {
fprintf(stderr, "Failed to initialize the firmware image: %s\n", update_err_to_string(rc));
return 1;
}
RMI4Update update(rmidevice, image);
rc = update.UpdateFirmware(force);
if (rc != UPDATE_SUCCESS) {
fprintf(stderr, "Firmware update failed because: %s\n", update_err_to_string(rc));
return 1;
}
return 0;
}
|