utils: Add function to get the latest version
This repo does not know which PSU version is the latest, and it lets the
vendor tool to decide which one is the latest.
This commit defines PSU_VERSION_COMPARE_UTIL which is expected to be a
tool that accepts arguments of a list of versions, and returns the
latest version string.
Tested: Put and configure to use the example get_latest_version on
Witherspoon, verify the versionId with a larger version string
is returned.
Signed-off-by: Lei YU <mine260309@gmail.com>
Change-Id: Ic5a10d3724cf6a98b3979486c72d54f8deac7038
diff --git a/vendor-example/get_latest_version.cpp b/vendor-example/get_latest_version.cpp
new file mode 100644
index 0000000..38dea2c
--- /dev/null
+++ b/vendor-example/get_latest_version.cpp
@@ -0,0 +1,29 @@
+#include <cstdio>
+#include <string>
+#include <vector>
+
+// Get the version string for a PSU and output to stdout
+// In this example, it just returns the last 8 bytes as the version
+constexpr int NUM_OF_BYTES = 8;
+
+int main(int argc, char** argv)
+{
+ if (argc < 2)
+ {
+ printf("Usage: %s versions...\n", argv[0]);
+ return 1;
+ }
+
+ std::vector<std::string> versions(argv + 1, argv + argc);
+ std::string latest;
+ for (const auto& s : versions)
+ {
+ if (latest < s)
+ {
+ latest = s;
+ }
+ }
+
+ printf("%s", latest.c_str());
+ return 0;
+}