NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: port-evbarm/61133: BMC2835 + BME280: Kernel hang due to unbounded loop in bsciic_exec()



The following reply was made to PR port-evbarm/61133; it has been noted by GNATS.

From: Brad Spencer <brad%anduin.eldar.org@localhost>
To: gnats-bugs%netbsd.org@localhost
Cc: port-evbarm-maintainer%netbsd.org@localhost, gnats-admin%netbsd.org@localhost,
        netbsd-bugs%netbsd.org@localhost
Subject: Re: port-evbarm/61133: BMC2835 + BME280: Kernel hang due to
 unbounded loop in bsciic_exec()
Date: Sat, 05 Dec 2026 19:40:03 -0500

 "matteo%matteocicuttin.it@localhost via gnats" <gnats-admin%NetBSD.org@localhost> writes:
 
 [snip]
 
 I am only going to comment a little on this PR.
 
 > I wanted to use a BME280 temperature/humidity/pressure sensor on a Raspberry Pi 1 rev. B, so I added "bmx280thp* at iic? addr 0x76" to the kernel config plus the appropriate entry to the DTB:
 >
 > 	bme280@76 {
 >         	compatible = "bosch,bme280";
 >    		reg = <0x76>;
 >     	};
 >
 > Recompiled and noticed that the sensor did not attach, therefore patched sys/dev/i2c/bmx280thpi2c.c as follows:
 >
 > --- bmx280thpi2c.c.orig	2026-12-05 20:07:23.979853245 +0100
 > +++ bmx280thpi2c.c	2026-12-05 17:31:53.161355130 +0100
 > @@ -41,6 +41,7 @@
 >  #include <dev/spi/spivar.h>
 >  #include <dev/ic/bmx280reg.h>
 >  #include <dev/ic/bmx280var.h>
 > +#include <dev/fdt/fdtvar.h>
 >  
 >  extern void	bmx280_attach(struct bmx280_sc *);
 >  
 > @@ -60,6 +61,12 @@
 >  #define DPRINTF(s, l, x)
 >  #endif
 >  
 > +static const struct device_compatible_entry bmx280thpi2c_compat[] = {
 > +    { .compat = "bosch,bme280" },
 > +    { .compat = "bosch,bmp280" },
 > +    DEVICE_COMPAT_EOL
 > +};
 > +
 >  CFATTACH_DECL_NEW(bmx280thpi2c, sizeof(struct bmx280_sc),
 >      bmx280thpi2c_match, bmx280thpi2c_attach, bmx280thpi2c_detach, NULL);
 >  
 > @@ -154,7 +161,7 @@
 >  	int error, match_result;
 >  	const bool matchdebug = false;
 >  
 > -	if (iic_use_direct_match(ia, match, NULL, &match_result))
 > +	if (iic_use_direct_match(ia, match, bmx280thpi2c_compat, &match_result))
 >  		return match_result;
 >  
 >  	/* indirect config - check for configured address */
 >
 > After the patch the sensor attaches correctly, however when I run `envstat` the system hangs and becomes totally unresponsive. Same result triggered by `i2cscan -r /dev/iic2`. In addition, i2cscan triggers the hang also without the bmx280thpi2c driver configured into the kernel (if the BME280 is connected).
 
 The driver for the BMx280 chip family was updated in -current post the
 11.x branch to include the above and a whole bunch of other changes.
 Even for 11.x, the above really isn't needed in most cases.  You can use
 indirect config of the device and just load the module, no kernel config
 changes and no DTB changes.  Just put bmx280thpi2c in /etc/modules.conf
 and put modules=YES in /etc/rc.conf.  The I2C buses will be probed and
 if your BMx280 device is at all normal, it will be found.  So, in
 general, I don't consider that part to be a bug.  It is certainly the
 case that direct config, like you were doing, will work better in
 -current.  However, back porting the driver into 11.x, offically, may
 not be in the cards.
 
 > Traced back the hang to a potentially unbounded loop in bsciic_exec() in sys/arch/arm/broadcom/bcm2835_bsc.c:
 >
 > 	uint32_t s;
 > 	do {
 > 		s = bus_space_read_4(sc->sc_iot, sc->sc_ioh, BSC_S);
 > 	} while ((s & BSC_S_TA) != 0);
 >
 > Replaced the code above with a bounded loop:
 >
 > 	uint32_t s;
 > 	int i;
 >
 > 	for (i = 0; i < 100000; i++) {
 > 		s = bus_space_read_4(sc->sc_iot, sc->sc_ioh, BSC_S);
 > 		if ((s & BSC_S_TA) == 0)
 > 			break;
 > 		DELAY(1);
 > 	}
 >
 > 	if (s & BSC_S_TA) {
 > 		device_printf(sc->sc_dev,
 >     		"I2C timeout: iters=%d op=%d addr=0x%x cmdlen=%zu datalen=%zu "
 >     		"state=%d status=0x%08x\n", i, sc->sc_exec.op, sc->sc_exec.addr,
 >     		sc->sc_exec.cmdlen,	sc->sc_exec.datalen,
 >     		sc->sc_exec_state, s);
 > 		error = ETIMEDOUT;
 > 	}
 >
 > After installing the patched kernel, I ran `envstat` that this time did not hang the machine:
 
 This part I am unfamilar with.  My use of RPI devices and I2C is
 extensive and constant, including the bmx280 driver and I have
 personally never seen this hang on the devices I have.  For RPI devices
 I use RPI0 and RPI3b devices, typically, but I can imagine a difference
 with the RPI1A.
 
 [snip]
 
 
 
 -- 
 Brad Spencer - brad%anduin.eldar.org@localhost
 



Home | Main Index | Thread Index | Old Index