meta-ampere: support software revision using Ampere format

OpenBMC uses os-release.bbappend to control the FW version, which is
the output of 'git describe --dirty --long'. The format of this command's
output is: {annotated-tag-name}-{num-commits-to-tag}-{current-commit-hash}.
'-dirty' will be appended to the output if the working space is not clean.

In addition, git describe --dirty --long only find an annotated tag, not
lightweight tag which will miss internal release.

This commit updates the rule to extract the right revision from Ampere
build and release tag.

Tested: tag with v1.02.100-ampere and check WebUI display revision
1.02.100.

Signed-off-by: Thu Cao <thcao@os.amperecomputing.com>
Signed-off-by: Chau Ly <chaul@amperecomputing.com>
Change-Id: I6d5e6d2dcdb4988809f71d48a5b0e2710e7810d2
diff --git a/meta-ampere/meta-common/recipes-core/os-release/os-release.bbappend b/meta-ampere/meta-common/recipes-core/os-release/os-release.bbappend
new file mode 100644
index 0000000..1e9e253
--- /dev/null
+++ b/meta-ampere/meta-common/recipes-core/os-release/os-release.bbappend
@@ -0,0 +1,17 @@
+def run_git(d, cmd):
+    try:
+        oeroot = d.getVar('COREBASE', True)
+        return bb.process.run("git --work-tree %s --git-dir %s/.git %s"
+            % (oeroot, oeroot, cmd))[0].strip('\n')
+    except:
+        pass
+
+python() {
+    version_id = run_git(d, 'describe --dirty --long --tags')
+    if version_id:
+        versionList = version_id.split('-')
+
+        # Override with tag name only, if built at tag.
+        if 'dirty' not in version_id and versionList[1] == 'ampere':
+            d.setVar('VERSION_ID', versionList[0].split('v')[-1])
+}