[Skiboot] [PATCH] hdata/i2c: Workaround broken i2c devices

Oliver O'Halloran oohall at gmail.com
Wed Apr 12 17:14:10 AEST 2017


Some older revisions of hostboot populate the host i2c device fields
with all zero entires. Detect and ignore these so we don't crash on
boot.

Signed-off-by: Oliver O'Halloran <oohall at gmail.com>
---
 hdata/i2c.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/hdata/i2c.c b/hdata/i2c.c
index 127068fafdeb..17f9ff1f8edf 100644
--- a/hdata/i2c.c
+++ b/hdata/i2c.c
@@ -132,6 +132,18 @@ static const char *map_label(uint32_t type)
 	return NULL;
 }
 
+static bool is_zeros(const void *p, size_t size)
+{
+	const char *c = p;
+	size_t i;
+
+	for (i = 0; i < size; i++)
+		if (c[i] != 0)
+			break;
+
+	return i == size;
+}
+
 int parse_i2c_devs(const struct HDIF_common_hdr *hdr, int idata_index,
 	struct dt_node *xscom)
 {
@@ -140,6 +152,7 @@ int parse_i2c_devs(const struct HDIF_common_hdr *hdr, int idata_index,
 	const struct i2c_dev *dev;
 	const char *label, *name, *compat;
 	uint32_t i2c_addr;
+	uint32_t size;
 	int i, count;
 
 	/*
@@ -150,7 +163,16 @@ int parse_i2c_devs(const struct HDIF_common_hdr *hdr, int idata_index,
 
 	count = HDIF_get_iarray_size(hdr, idata_index);
 	for (i = 0; i < count; i++) {
-		dev = HDIF_get_iarray_item(hdr, idata_index, i, NULL);
+		dev = HDIF_get_iarray_item(hdr, idata_index, i, &size);
+
+		/*
+		 * XXX: Some broken hostboots populate i2c devs with zeros.
+		 * Workaround them for now.
+		 */
+		if (is_zeros(dev, size)) {
+			prerror("I2C: Ignoring broken i2c dev %d\n", i);
+			continue;
+		}
 
 		i2cm = get_i2cm_node(xscom, dev->i2cm_engine);
 		bus = get_bus_node(i2cm, dev->i2cm_port,
-- 
2.9.3



More information about the Skiboot mailing list