Platform: Add hardware version

Hardware version is a globally unique number in EAN-13+5
format identifying the GDSII that went to fabrication,
HW and ROM.

Change-Id: I6619f1f28f7b7a4c926c54248de10d1e3e739e4a
Signed-off-by: Tamas Ban <tamas.ban@arm.com>
diff --git a/platform/ext/target/mps2/an519/dummy_device_id.c b/platform/ext/target/mps2/an519/dummy_device_id.c
index be428f0..d282385 100644
--- a/platform/ext/target/mps2/an519/dummy_device_id.c
+++ b/platform/ext/target/mps2/an519/dummy_device_id.c
@@ -30,6 +30,7 @@
     0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD,
 };
 
+static const uint8_t example_ean_13[] = "060456527282910010";
 /**
  * \brief Copy the device specific ID to the destination buffer
  *
@@ -90,3 +91,18 @@
 
     return TFM_PLAT_ERR_SUCCESS;
 }
+
+enum tfm_plat_err_t tfm_plat_get_hw_version(uint32_t *size, uint8_t *buf)
+{
+    const uint8_t *p_hw_version = example_ean_13;
+    uint32_t hw_version_size = sizeof(example_ean_13) - 1;
+
+    if (*size < hw_version_size) {
+        return TFM_PLAT_ERR_SYSTEM_ERR;
+    }
+
+    copy_id(buf, p_hw_version, hw_version_size);
+    *size = hw_version_size;
+
+    return TFM_PLAT_ERR_SUCCESS;
+}
diff --git a/platform/ext/target/mps2/an521/dummy_device_id.c b/platform/ext/target/mps2/an521/dummy_device_id.c
index be428f0..d282385 100644
--- a/platform/ext/target/mps2/an521/dummy_device_id.c
+++ b/platform/ext/target/mps2/an521/dummy_device_id.c
@@ -30,6 +30,7 @@
     0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD,
 };
 
+static const uint8_t example_ean_13[] = "060456527282910010";
 /**
  * \brief Copy the device specific ID to the destination buffer
  *
@@ -90,3 +91,18 @@
 
     return TFM_PLAT_ERR_SUCCESS;
 }
+
+enum tfm_plat_err_t tfm_plat_get_hw_version(uint32_t *size, uint8_t *buf)
+{
+    const uint8_t *p_hw_version = example_ean_13;
+    uint32_t hw_version_size = sizeof(example_ean_13) - 1;
+
+    if (*size < hw_version_size) {
+        return TFM_PLAT_ERR_SYSTEM_ERR;
+    }
+
+    copy_id(buf, p_hw_version, hw_version_size);
+    *size = hw_version_size;
+
+    return TFM_PLAT_ERR_SUCCESS;
+}
diff --git a/platform/ext/target/musca_a/dummy_device_id.c b/platform/ext/target/musca_a/dummy_device_id.c
index be428f0..d282385 100644
--- a/platform/ext/target/musca_a/dummy_device_id.c
+++ b/platform/ext/target/musca_a/dummy_device_id.c
@@ -30,6 +30,7 @@
     0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD,
 };
 
+static const uint8_t example_ean_13[] = "060456527282910010";
 /**
  * \brief Copy the device specific ID to the destination buffer
  *
@@ -90,3 +91,18 @@
 
     return TFM_PLAT_ERR_SUCCESS;
 }
+
+enum tfm_plat_err_t tfm_plat_get_hw_version(uint32_t *size, uint8_t *buf)
+{
+    const uint8_t *p_hw_version = example_ean_13;
+    uint32_t hw_version_size = sizeof(example_ean_13) - 1;
+
+    if (*size < hw_version_size) {
+        return TFM_PLAT_ERR_SYSTEM_ERR;
+    }
+
+    copy_id(buf, p_hw_version, hw_version_size);
+    *size = hw_version_size;
+
+    return TFM_PLAT_ERR_SUCCESS;
+}
diff --git a/platform/ext/target/musca_b1/dummy_device_id.c b/platform/ext/target/musca_b1/dummy_device_id.c
index be428f0..d282385 100644
--- a/platform/ext/target/musca_b1/dummy_device_id.c
+++ b/platform/ext/target/musca_b1/dummy_device_id.c
@@ -30,6 +30,7 @@
     0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD,
 };
 
+static const uint8_t example_ean_13[] = "060456527282910010";
 /**
  * \brief Copy the device specific ID to the destination buffer
  *
@@ -90,3 +91,18 @@
 
     return TFM_PLAT_ERR_SUCCESS;
 }
+
+enum tfm_plat_err_t tfm_plat_get_hw_version(uint32_t *size, uint8_t *buf)
+{
+    const uint8_t *p_hw_version = example_ean_13;
+    uint32_t hw_version_size = sizeof(example_ean_13) - 1;
+
+    if (*size < hw_version_size) {
+        return TFM_PLAT_ERR_SYSTEM_ERR;
+    }
+
+    copy_id(buf, p_hw_version, hw_version_size);
+    *size = hw_version_size;
+
+    return TFM_PLAT_ERR_SUCCESS;
+}
diff --git a/platform/include/tfm_plat_device_id.h b/platform/include/tfm_plat_device_id.h
index 350505c..dcce837 100644
--- a/platform/include/tfm_plat_device_id.h
+++ b/platform/include/tfm_plat_device_id.h
@@ -14,6 +14,7 @@
  * attributes of the device:
  *  - Instance ID:       Unique identifier of the device.
  *  - Implementation ID: Original implementation signer of the attestation key.
+ *  - Hardware version:  Identify the GDSII that went to fabrication.
  */
 
 /**
@@ -43,6 +44,15 @@
 #define IMPLEMENTATION_ID_MAX_SIZE (32u)
 
 /**
+ * \def HW_VERSION_MAX_SIZE
+ *
+ * \brief Maximum size of hardware version in bytes
+ *
+ * Recommended to use the European Article Number format: EAN-13+5
+ */
+#define HW_VERSION_MAX_SIZE (18u)
+
+/**
  * \brief Get the UEID of the device.
  *
  * This mandatory claim represents the unique identifier of the instance.
@@ -82,6 +92,24 @@
 enum tfm_plat_err_t tfm_plat_get_implementation_id(uint32_t *size,
                                                    uint8_t  *buf);
 
+/**
+ * \brief Get the hardware version of the device.
+ *
+ * This optional claim provides metadata linking the token to the GDSII that
+ * went to fabrication for this instance. It is represented as CBOR text string.
+ * It is recommended to use for identification the format of the European
+ * Article Number: EAN-13+5.
+ *
+ * \param[in/out] size  As an input value it indicates the size of the caller
+ *                      allocated buffer (in bytes) to store the HW version. At
+ *                      return its value is updated with the exact size of the
+ *                      HW version.
+ * \param[out]    buf   Pointer to the buffer to store the HW version
+ *
+ * \return  Returns error code specified in \ref tfm_plat_err_t
+ */
+enum tfm_plat_err_t tfm_plat_get_hw_version(uint32_t *size, uint8_t *buf);
+
 #ifdef __cplusplus
 }
 #endif