generate-tar: Add machine name

The openbmc image manager expects "MachineName" in MANIFEST that matches
the BMC's OPENBMC_TARGET_MACHINE in /etc/os-release.
* If there is no MachineName in MANIFEST, it logs a warning for now;
* If they do not match, an error is reported and the version is deleted.

Add -m, --machine argument for generate-tar to make it support the
"MachineName".

Tested: Verify that when a correct machine name is given, the tarball is
        processed by image manager correctly;
        And if an invalid machine name is given, the tarball uploaded
        will get "Machine name doesn't match" error and is deleted.

Signed-off-by: Lei YU <mine260309@gmail.com>
Change-Id: I8fbb5060cb1be348c39e0688fe7306426cc4ed77
diff --git a/generate-tar b/generate-tar
index d948f33..313b015 100755
--- a/generate-tar
+++ b/generate-tar
@@ -25,6 +25,8 @@
                           the private key file. Defaults to the bash variable
                           PRIVATE_KEY_PATH if available, or else uses the
                           open-source private key in this script.
+   -m, --machine <name>   Optionally specify the target machine name of this
+                          image.
    -h, --help             Display this help text and exit.
 '
 
@@ -57,6 +59,7 @@
 outfile=""
 declare -a partitions=()
 tocfile="pnor.toc"
+machine_name=""
 
 while [[ $# -gt 0 ]]; do
   key="$1"
@@ -78,6 +81,10 @@
         shift 1
       fi
       ;;
+    -m|--machine)
+      machine_name="$2"
+      shift 2
+      ;;
     -h|--help)
       echo "$help"
       exit
@@ -231,6 +238,10 @@
 echo -e "purpose=xyz.openbmc_project.Software.Version.VersionPurpose.Host\nversion=$version\n\
 extended_version=$extended_version" >> $manifest_location
 
+if [[ ! -z "${machine_name}" ]]; then
+    echo -e "MachineName=${machine_name}" >> $manifest_location
+fi
+
 if [[ "${do_sign}" == true ]]; then
   private_key_name=$(basename "${private_key_path}")
   key_type="${private_key_name%.*}"