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

Michael Neuling mikey at neuling.org
Thu Apr 13 13:35:58 AEST 2017


On Wed, 2017-04-12 at 17:27 +1000, Oliver O'Halloran wrote:
> 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.

This has been pushed upstream as bcfa5f2160.

> 
> Signed-off-by: Oliver O'Halloran <oohall at gmail.com>
> ---
> v1 -> v2: Optimised is_zero() for mikey, because that's an important thing to
> do.
>           Added backtrace when printing the error.
> ---
>  hdata/i2c.c | 25 ++++++++++++++++++++++++-
>  1 file changed, 24 insertions(+), 1 deletion(-)
> 
> diff --git a/hdata/i2c.c b/hdata/i2c.c
> index 127068fafdeb..0555ead6e9dc 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)
> +			return false;
> +
> +	return true;
> +}
> +
>  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,17 @@ 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);
> +			backtrace();
> +			continue;
> +		}
>  
>  		i2cm = get_i2cm_node(xscom, dev->i2cm_engine);
>  		bus = get_bus_node(i2cm, dev->i2cm_port,


More information about the Skiboot mailing list