NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
port-evbarm/61133: BMC2835 + BME280: Kernel hang due to unbounded loop in bsciic_exec()
>Number: 61133
>Category: port-evbarm
>Synopsis: BMC2835 + BME280: Kernel hang due to unbounded loop in bsciic_exec()
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: port-evbarm-maintainer
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sat Dec 05 20:00:01 +0000 2026
>Originator: Matteo Cicuttin
>Release: 11.1
>Organization:
>Environment:
NetBSD rpi 11.1 NetBSD 11.1 (RPI_MC) #34: Sat Dec 5 18:35:21 CET 2026 matteo@sdrbox:/home/matteo/netbsdbuild/usr/src/sys/arch/evbarm/compile/obj/RPI_MC evbarm
>Description:
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).
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:
rpi# envstat
Current CritMax WarnMax WarnMin CritMin Unit
[bmx280thp0]
temperature: N/A
pressure: 998.800 hPa
humidity: 58.679 %rH
[vcmbox0]
temperature: 42.236 85.000 degC
rpi#
Notice the N/A in the temperature. On the console, the device_printf() above produces the following:
[ 66.368695] bsciic2: I2C timeout: iters=100000 op=1 addr=0x76 cmdlen=0 datalen=1 state=5 status=0xf00000a1
Subsequent `envstat`s do work without issues and also the temperature is reported correctly:
rpi# envstat
Current CritMax WarnMax WarnMin CritMin Unit
[bmx280thp0]
temperature: 20.450 degC
pressure: 998.840 hPa
humidity: 58.667 %rH
[vcmbox0]
temperature: 40.084 85.000 degC
rpi#
In addition, no more messages are printed on the console, indicating that the loop exits before reaching the iteration limit. Also i2cscan works fine (before the patch it triggered the hang):
rpi# i2cscan -r /dev/iic2
/dev/iic2: found device at 0x76
/dev/iic2: 1 devices found
rpi#
>How-To-Repeat:
Option 1:
1) Take a Raspberry Pi 1 rev. B
2) Connect a BME280 THP sensor to the Raspberry I2C
3) Run `i2cscan -r /dev/iic2` --> system hangs
Option 2:
1) Take a Raspberry Pi 1 rev. B
2) Connect a BME280 THP sensor to the Raspberry I2C
3) Add the bmx280thp driver to the kernel and the corresponding DTB entry, plus patch the kernel with the patch above
4) Make sure that the sensor is correctly recognized by looking for something like the following in the dmesg:
[ 1.000000] bmx280thp0: Bosch Sensortec BME280, Chip ID: 0x60
5) Run `envstat` ---> system hangs
>Fix:
Not sufficiently familiar with the NetBSD stack and the BMC2835 I2C controller to propose a proper fix, sorry.
Home |
Main Index |
Thread Index |
Old Index