diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-05-09 20:35:08 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-05-09 20:35:08 +0000 |
commit | 9b8dcb5c9a441f938fa51dd42246f2e3cce702ac (patch) | |
tree | e97f7a96918abacfcbe222c19f57fa95ee813569 /rmi4update/main.cpp | |
parent | 9c4b019e28fa67eba1ca0f3b55ee2b729a6b037b (diff) | |
parent | 300225f3e9561e02d6abe8050fb341ee8b4891a3 (diff) | |
download | rmi4utils-aml_med_331410000.tar.gz |
Snap for 8562061 from 300225f3e9561e02d6abe8050fb341ee8b4891a3 to mainline-media-releaseaml_med_331911000aml_med_331712010aml_med_331612000aml_med_331511000aml_med_331410000aml_med_331318000aml_med_331115000aml_med_331012020android13-mainline-media-release
Change-Id: I2230e585daeaf6421cb6f2458e75de6dbd155a20
Diffstat (limited to 'rmi4update/main.cpp')
-rwxr-xr-x[-rw-r--r--] | rmi4update/main.cpp | 116 |
1 files changed, 54 insertions, 62 deletions
diff --git a/rmi4update/main.cpp b/rmi4update/main.cpp index 11146e1..a710764 100644..100755 --- a/rmi4update/main.cpp +++ b/rmi4update/main.cpp @@ -32,20 +32,22 @@ #include "rmi4update.h" #define VERSION_MAJOR 1 -#define VERSION_MINOR 2 -#define VERSION_SUBMINOR 0 +#define VERSION_MINOR 3 +#define VERSION_SUBMINOR 5 -#define RMI4UPDATE_GETOPTS "hfd:plv" +#define RMI4UPDATE_GETOPTS "hfd:t:pclv" void printHelp(const char *prog_name) { fprintf(stdout, "Usage: %s [OPTIONS] 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"); - fprintf(stdout, "\t-d, --device\thidraw device file associated with the device being updated.\n"); - fprintf(stdout, "\t-p, --fw-props\tPrint the firmware properties.\n"); - fprintf(stdout, "\t-l, --lockdown\tPerform lockdown.\n"); - fprintf(stdout, "\t-v, --version\tPrint version number.\n"); + fprintf(stdout, "\t-h, --help\t\tPrint this message\n"); + fprintf(stdout, "\t-f, --force\t\tForce updating firmware even it the image provided is older\n\t\t\t\tthen the current firmware on the device.\n"); + fprintf(stdout, "\t-d, --device\t\thidraw device file associated with the device being updated.\n"); + fprintf(stdout, "\t-p, --fw-props\t\tPrint the firmware properties.\n"); + fprintf(stdout, "\t-c, --config-id\t\tPrint the config id.\n"); + fprintf(stdout, "\t-l, --lockdown\t\tPerform lockdown.\n"); + fprintf(stdout, "\t-v, --version\t\tPrint version number.\n"); + fprintf(stdout, "\t-t, --device-type\tFilter by device type [touchpad or touchscreen].\n"); } void printVersion() @@ -54,24 +56,7 @@ void printVersion() VERSION_MAJOR, VERSION_MINOR, VERSION_SUBMINOR); } -int UpdateDevice(FirmwareImage & image, bool force, bool performLockdown, const char * deviceFile) -{ - HIDDevice rmidevice; - int rc; - - rc = rmidevice.Open(deviceFile); - if (rc) - return rc; - - RMI4Update update(rmidevice, image); - rc = update.UpdateFirmware(force, performLockdown); - if (rc != UPDATE_SUCCESS) - return rc; - - return rc; -} - -int GetFirmwareProps(const char * deviceFile, std::string &props) +int GetFirmwareProps(const char * deviceFile, std::string &props, bool configid) { HIDDevice rmidevice; int rc = UPDATE_SUCCESS; @@ -84,12 +69,16 @@ int GetFirmwareProps(const char * deviceFile, std::string &props) rmidevice.ScanPDT(0x1); rmidevice.QueryBasicProperties(); - ss << rmidevice.GetFirmwareVersionMajor() << "." - << rmidevice.GetFirmwareVersionMinor() << "." - << std::hex << rmidevice.GetFirmwareID(); + if (configid) { + ss << std::hex << rmidevice.GetConfigID(); + } else { + ss << rmidevice.GetFirmwareVersionMajor() << "." + << rmidevice.GetFirmwareVersionMinor() << "." + << rmidevice.GetFirmwareID(); - if (rmidevice.InBootloader()) - ss << " bootloader"; + if (rmidevice.InBootloader()) + ss << " bootloader"; + } props = ss.str(); @@ -110,14 +99,17 @@ int main(int argc, char **argv) {"force", 0, NULL, 'f'}, {"device", 1, NULL, 'd'}, {"fw-props", 0, NULL, 'p'}, + {"config-id", 0, NULL, 'c'}, {"lockdown", 0, NULL, 'l'}, {"version", 0, NULL, 'v'}, + {"device-type", 1, NULL, 't'}, {0, 0, 0, 0}, }; - struct dirent * devDirEntry; - DIR * devDir; bool printFirmwareProps = false; + bool printConfigid = false; bool performLockdown = false; + HIDDevice device; + enum RMIDeviceType deviceType = RMI_DEVICE_TYPE_ANY; while ((opt = getopt_long(argc, argv, RMI4UPDATE_GETOPTS, long_options, &index)) != -1) { switch (opt) { @@ -133,9 +125,19 @@ int main(int argc, char **argv) case 'p': printFirmwareProps = true; break; + case 'c': + printFirmwareProps = true; + printConfigid = true; + break; case 'l': performLockdown = true; break; + case 't': + if (!strcasecmp((const char *)optarg, "touchpad")) + deviceType = RMI_DEVICE_TYPE_TOUCHPAD; + else if (!strcasecmp((const char *)optarg, "touchscreen")) + deviceType = RMI_DEVICE_TYPE_TOUCHSCREEN; + break; case 'v': printVersion(); return 0; @@ -152,7 +154,7 @@ int main(int argc, char **argv) fprintf(stderr, "Specifiy which device to query\n"); return 1; } - rc = GetFirmwareProps(deviceName, props); + rc = GetFirmwareProps(deviceName, props, printConfigid); if (rc) { fprintf(stderr, "Failed to read properties from device: %s\n", update_err_to_string(rc)); return 1; @@ -175,35 +177,25 @@ int main(int argc, char **argv) } if (deviceName) { - rc = UpdateDevice(image, force, performLockdown, deviceName); - - return rc; - } else { - char deviceFile[PATH_MAX]; - bool found = false; - - devDir = opendir("/dev"); - if (!devDir) - return -1; - - while ((devDirEntry = readdir(devDir)) != NULL) { - if (strstr(devDirEntry->d_name, "hidraw")) { - char rawDevice[PATH_MAX]; - strncpy(rawDevice, devDirEntry->d_name, PATH_MAX); - snprintf(deviceFile, PATH_MAX, "/dev/%s", devDirEntry->d_name); - rc = UpdateDevice(image, force, performLockdown, deviceFile); - if (rc != 0) { - continue; - } else { - found = true; - break; - } - } + rc = device.Open(deviceName); + if (rc) { + fprintf(stderr, "%s: failed to initialize rmi device (%d): %s\n", argv[0], errno, + strerror(errno)); + return 1; } - closedir(devDir); + } else { + if (!device.FindDevice(deviceType)) + return 1; + } + - if (!found) - return rc; + RMI4Update update(device, image); + rc = update.UpdateFirmware(force, performLockdown); + + if (rc != UPDATE_SUCCESS) + { + device.Reset(); + return 1; } return 0; |