summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlec Berg <alecaberg@chromium.org>2014-08-27 09:09:53 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-08-28 20:12:52 +0000
commitb7f1d5261917c88e734d0e788de74b2bc419c431 (patch)
tree5d238902410b955e3b58e6217392f6013d75fe35
parent9d0bb00192d460ef0a445040bf245a4840d38fbb (diff)
downloadchrome-ec-b7f1d5261917c88e734d0e788de74b2bc419c431.tar.gz
zinger: samus_pd: change zinger SW ver to report commit count
Change the zinger software version returned by VDO_CMD_READ_INFO to report the commit count portion of the version string to make the software version automatically change. This software version is important for debugging and is printed to PD console every time a zinger is attached. BUG=none BRANCH=none TEST=load onto zinger and samus, plug in zinger and see: Dev:1 SW:2147 RW:0 compare to the version string in zinger binary and we see: zinger_v1.1.2147-... Change-Id: Ieafe89b4b16cee076be17bcbc6774bbd7fc24f8e Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/214428 Reviewed-by: Todd Broch <tbroch@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r--board/zinger/board.h1
-rw-r--r--board/zinger/usb_pd_policy.c2
-rw-r--r--common/version.c31
-rw-r--r--include/usb_pd.h8
-rw-r--r--include/version.h4
5 files changed, 41 insertions, 5 deletions
diff --git a/board/zinger/board.h b/board/zinger/board.h
index f3a0d3dc5f..e26d5a5e96 100644
--- a/board/zinger/board.h
+++ b/board/zinger/board.h
@@ -44,7 +44,6 @@
/* USB PD ChromeOS VDM information */
#define USB_PD_HARDWARE_DEVICE_ID 1
-#define USB_PD_DBG_SW_VERSION 255
#ifndef __ASSEMBLER__
diff --git a/board/zinger/usb_pd_policy.c b/board/zinger/usb_pd_policy.c
index 591021bb56..6ef6fee461 100644
--- a/board/zinger/usb_pd_policy.c
+++ b/board/zinger/usb_pd_policy.c
@@ -376,7 +376,7 @@ int pd_custom_vdm(int port, int cnt, uint32_t *payload, uint32_t **rpayload)
/* copy other info into response */
payload[SHA1_DIGEST_SIZE/4 + 1] = VDO_INFO(
USB_PD_HARDWARE_DEVICE_ID,
- USB_PD_DBG_SW_VERSION,
+ ver_get_numcommits(),
!is_ro_mode());
rsize = 7;
break;
diff --git a/common/version.c b/common/version.c
index a2f554e58d..766b4ad56b 100644
--- a/common/version.c
+++ b/common/version.c
@@ -18,3 +18,34 @@ const struct version_struct version_data
const char build_info[] __attribute__((section(".rodata.buildinfo"))) =
CROS_EC_VERSION " " DATE " " BUILDER;
+
+uint32_t ver_get_numcommits(void)
+{
+ int i;
+ int numperiods = 0;
+ uint32_t ret = 0;
+
+ /*
+ * Version string is formatted like:
+ * name_major.branch.numcommits-hash[dirty]
+ * we want to return the numcommits as an int.
+ */
+ for (i = 0; i < 32; i++) {
+ if (version_data.version[i] == '.') {
+ numperiods++;
+ if (numperiods == 2)
+ break;
+ }
+ }
+
+ i++;
+ for (; i < 32; i++) {
+ if (version_data.version[i] == '-')
+ break;
+ ret *= 10;
+ ret += version_data.version[i] - '0';
+ }
+
+ return (i == 32 ? 0 : ret);
+}
+
diff --git a/include/usb_pd.h b/include/usb_pd.h
index 4a9376a369..507a81fe7f 100644
--- a/include/usb_pd.h
+++ b/include/usb_pd.h
@@ -137,12 +137,14 @@ enum pd_errors {
* ChromeOS specific VDO_CMD_READ_INFO responds with device info including:
* RW Hash: sha1 of RW hash (20 bytes)
* HW Device ID: unique descriptor for each ChromeOS model (2 bytes)
- * SW Debug Version: Software version useful for debugging (1 byte)
+ * SW Debug Version: Software version useful for debugging (15 bits)
* IS RW: True if currently in RW, False otherwise (1 bit)
*/
-#define VDO_INFO(id, ver, is_rw) ((id) << 16 | (ver) << 8 | (is_rw))
+#define VDO_INFO(id, ver, is_rw) ((id) << 16 \
+ | ((ver) & 0x7fff) << 1 \
+ | ((is_rw) & 1))
#define VDO_INFO_HW_DEV_ID(x) ((x) >> 16)
-#define VDO_INFO_SW_DBG_VER(x) (((x) >> 8) & 0xff)
+#define VDO_INFO_SW_DBG_VER(x) (((x) >> 1) & 0x7fff)
#define VDO_INFO_IS_RW(x) ((x) & 1)
/* USB Vendor ID assigned to Google Inc. */
diff --git a/include/version.h b/include/version.h
index 42d176916f..8853d76561 100644
--- a/include/version.h
+++ b/include/version.h
@@ -23,4 +23,8 @@ extern const struct version_struct version_data;
extern const char build_info[];
extern const char __version_struct_offset[];
+/**
+ * Get the number of commits field from version string.
+ */
+uint32_t ver_get_numcommits(void);
#endif /* __CROS_EC_VERSION_H */