Support uploading same image for multiple times

The code was unable to upload the same image for multiple times because
it has the same version ID.

Add a salt when generating the version ID so that we could get different
version IDs for the same image, and thus it is possible to upload the
images for multiple times. Use a random generator with the time as seed
to ensure uniqueness.

When the image updater starts up, use the mount directory name or
functional suffix as seeds to make the version ids unique.

The version ID is then necessary in the version object because the Delete
interface needs it when the version object is to be deleted.

With this change, it is possible to upload and update the same image for
multiple times, and systems with dual BMC chips could have the same image
as well.

Tested: Upload a same image for multiple times and verify all the
        uploads are OK and getting different DBus objects;
        Verify it is OK to delete the uploaded images by deleting the
        DBus objects.
        Verify the code update works on all layouts and that the flash
        id (Path property) was set.

- static
root@romulus:~# busctl --no-pager introspect \
xyz.openbmc_project.Software.BMC.Updater \
/xyz/openbmc_project/software/79139bc0
...
.Path   property  s "9e3b868e"

root@romulus:~# ls -l /run/media/rofs-9e3b868e-functional/etc/
lrwxrwxrwx    1 root     root            15 Jan 22 20:11 os-release ->
/etc/os-release

- ubi
root@witherspoon:~# busctl --no-pager introspect \
xyz.openbmc_project.Software.BMC.Updater \
/xyz/openbmc_project/software/151bc3d8
...
.Path   property  s "cfb85943"

root@witherspoon:~# df
/dev/ubiblock0_0         18816     18816         0 100% /media/rofs-cfb85943-functional
/dev/ubiblock4_0         18816     18816         0 100% /media/rofs-26085328

root@witherspoon:~# cat /var/lib/phosphor-bmc-code-mgmt/cfb85943/priority
{
    "priority": 0
}

- mmc
root@p10bmc:~# busctl --no-pager introspect \
xyz.openbmc_project.Software.BMC.Updater \
/xyz/openbmc_project/software/cb5f99e2
...
.Path   property  s         "b"

root@p10bmc:~# df
/dev/mmcblk0p5          202095    153782     33107  82% /media/rofs-b-functional

root@p10bmc:~# cat /var/lib/phosphor-bmc-code-mgmt/b/priority
{
    "priority": 0
}

Signed-off-by: Lei YU <yulei.sh@bytedance.com>
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
Change-Id: I76842de4d5b7c5175acc43ed7c57e0deb4057be5
diff --git a/version.hpp b/version.hpp
index 73cc137..b6269e0 100644
--- a/version.hpp
+++ b/version.hpp
@@ -79,9 +79,9 @@
     Version(sdbusplus::bus::bus& bus, const std::string& objPath,
             const std::string& versionString, VersionPurpose versionPurpose,
             const std::string& extVersion, const std::string& filePath,
-            eraseFunc callback) :
+            eraseFunc callback, const std::string& id) :
         VersionInherit(bus, (objPath).c_str(), true),
-        eraseCallback(callback), versionStr(versionString)
+        eraseCallback(callback), id(id), versionStr(versionString)
     {
         // Set properties.
         extendedVersion(extVersion);
@@ -106,11 +106,13 @@
      * @details The version id is a unique 8 hexadecimal digit id
      *          calculated from the version string.
      *
-     * @param[in] version - The image's version string (e.g. v1.99.10-19).
+     * @param[in] versionWithSalt - The image's version string
+     *                              (e.g. v1.99.10-19) plus an optional salt
+     *                              string.
      *
      * @return The id.
      */
-    static std::string getId(const std::string& version);
+    static std::string getId(const std::string& versionWithSalt);
 
     /**
      * @brief Get the active BMC machine name string.
@@ -166,6 +168,9 @@
     /** @brief The parent's erase callback. */
     eraseFunc eraseCallback;
 
+    /** @brief The version ID of the object */
+    const std::string id;
+
   private:
     /** @brief This Version's version string */
     const std::string versionStr;