Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2021-02-06 update breaks negative temperatures for 1-wire sensors (reports 7000 degrees instead of -10) #4124

Closed
johnterickson opened this issue Feb 6, 2021 · 13 comments

Comments

@johnterickson
Copy link

Is this the right place for my bug report?
This repository contains the Linux kernel used on the Raspberry Pi. If you believe that the issue you are seeing is kernel-related, this is the right place. If not, we have other repositories for the GPU firmware at github.com/raspberrypi/firmware and Raspberry Pi userland applications at github.com/raspberrypi/userland. If you have problems with the Raspbian distribution packages, report them in the github.com/RPi-Distro/repo. If you simply have a question, then the Raspberry Pi forums are the best place to ask it.

Describe the bug
I have a temperature sensor in Rasp Pi 2 in my garage. It's been running great for over a year. I have it set to update nightly. Last night, as soon as the update rebooted, I got a notification that my freezer was at 7000 degrees F. Fridge temp was nominal. I hard-powered off and on the device. No change.

Looking at the data sheet I realized that the 7000 deg F temp was way beyond what the sensor could even represent in binary. I double checked the direct output from the sensor (see below) to make sure it wasn't my code that messed it up.

To reproduce
Attach DS18B20, enable 1-wire, put sensor below 0 degrees celcius.

Expected behaviour
Negative temperatures from 1-wire sensors are correct.

Actual behaviour
Negative temperatures are incorrectly sign extended.

System
Copy and paste the results of the raspinfo command in to this section. Alternatively, copy and paste a pastebin link, or add answers to the following questions:

  • Which model of Raspberry Pi? e.g. Pi3B+, PiZeroW
    Raspberry Pi 2
  • Which OS and version (cat /etc/rpi-issue)?
pi@raspberrypi:/sys/devices/w1_bus_master1 $ cat /etc/rpi-issue
Raspberry Pi reference 2020-02-13
Generated using pi-gen, https://github.com/RPi-Distro/pi-gen, 5f884374b6ac6e155330c58caa1fb7249b8badf1, stage4
  • Which firmware version (vcgencmd version)?
pi@raspberrypi:/sys/devices/w1_bus_master1 $ vcgencmd version
Jan 27 2021 22:26:53
Copyright (c) 2012 Broadcom
version 99d9a48302e4553cff3688692bb7e9ac760a03fa (clean) (release) (start)
  • Which kernel version (uname -a)?
pi@raspberrypi:/sys/devices/w1_bus_master1 $ uname -a
Linux raspberrypi 5.10.11-v7+ #1399 SMP Thu Jan 28 12:06:05 GMT 2021 armv7l GNU/Linux

Logs

Start-Date: 2021-02-06  00:01:52
Commandline: apt-get upgrade -y
Requested-By: pi (1000)
Upgrade: libraspberrypi-bin:armhf (1.20210108-1, 1.20210201-1), libraspberrypi-dev:armhf (1.20210108-1, 1.20210201-1), libraspberrypi-doc:armhf (1.20210108-1, 1.20210201-1), libldap-2.4-2:armhf (2.4.47+dfsg-3+rpi1+deb10u4, 2.4.47+dfsg-3+rpi1+deb10u5), raspberrypi-kernel:armhf (1.20210108-1, 1.20210201-1), raspberrypi-bootloader:armhf (1.20210108-1, 1.20210201-1), libldap-common:armhf (2.4.47+dfsg-3+rpi1+deb10u4, 2.4.47+dfsg-3+rpi1+deb10u5), libraspberrypi0:armhf (1.20210108-1, 1.20210201-1), ca-certificates:armhf (20200601~deb10u1, 20200601~deb10u2), tzdata:armhf (2020e-0+deb10u1, 2021a-0+deb10u1)
# fridge
pi@raspberrypi:/sys/devices/w1_bus_master1 $ cat 28-03119779ae01/temperature
5187
pi@raspberrypi:/sys/devices/w1_bus_master1 $ cat 28-03119779ae01/w1_slave
52 00 55 05 7f a5 a5 66 d4 : crc=d4 YES
52 00 55 05 7f a5 a5 66 d4 t=5125

# freezer
pi@raspberrypi:/sys/devices/w1_bus_master1 $ cat 28-030997791dbd/temperature
4085000
pi@raspberrypi:/sys/devices/w1_bus_master1 $ cat 28-030997791dbd/w1_slave
3d ff 55 05 7f a5 a5 66 c9 : crc=c9 YES
3d ff 55 05 7f a5 a5 66 c9 t=4083812

Additional context
You can find my mitigation to properly sign-extend here: johnterickson/MiPi-1wire-rs@2b852cb

@johnterickson
Copy link
Author

My guess is this is a regression from 9ace0b4

@johnterickson
Copy link
Author

Yup in w1_DS18B20_convert_temp, it used to have a correctly sized integer s16 but now it transits as an int and I think the le16_to_cpup returned value is not sign-extended in conversion to int.

@danieltroger
Copy link

I did not know where to report this so I "reported" it on stack overflow instead and got guided here.

I also opened a question on the pi forums but either the site is buggy or it's still in moderation.

Idk who to tell but it would be great to get this fixed ASAP.

@johnterickson do you have some binary for me that I can use to get my thermometers working? Or anything else I can do while avoiding to compile the entire linux kernel on my pi which I imagine takes like 5 weeks.

@danieltroger
Copy link

Thanks to Jarosław Komar there is a workaround!

The thermometers always overreport by 4096°C and by subtracting 4096 if the temperature is over 100°C correct readings can be obtained.

@johnterickson
Copy link
Author

johnterickson commented Feb 7, 2021

@danieltroger Glad you found a workaround - I think the "subtract 4096" is equivalent, but you can see how I worked around this in my app here as another reference point: johnterickson/MiPi-1wire-rs@2b852cb

pelwell pushed a commit that referenced this issue Feb 8, 2021
commit 2f6055c upstream.

DS18B20 device driver returns an incorrect value for negative temperatures
due to a missing sign-extension in w1_DS18B20_convert_temp().

Fix by using s16 temperature value when converting to int.

See: #4124

Fixes: 9ace0b4 (w1: w1_therm: Add support for GXCAS GX20MH01 device.)
Cc: stable <stable@vger.kernel.org>
Reported-by: Paweł Marciniak <sunwire@gmail.com>
Signed-off-by: Ivan Zaentsev <ivan.zaentsev@wirenboard.ru>
Link: https://lore.kernel.org/r/20210121093021.224764-1-ivan.zaentsev@wirenboard.ru
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
pelwell pushed a commit that referenced this issue Feb 8, 2021
commit 2f6055c upstream.

DS18B20 device driver returns an incorrect value for negative temperatures
due to a missing sign-extension in w1_DS18B20_convert_temp().

Fix by using s16 temperature value when converting to int.

See: #4124

Fixes: 9ace0b4 (w1: w1_therm: Add support for GXCAS GX20MH01 device.)
Cc: stable <stable@vger.kernel.org>
Reported-by: Paweł Marciniak <sunwire@gmail.com>
Signed-off-by: Ivan Zaentsev <ivan.zaentsev@wirenboard.ru>
Link: https://lore.kernel.org/r/20210121093021.224764-1-ivan.zaentsev@wirenboard.ru
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
@pelwell
Copy link
Contributor

pelwell commented Feb 8, 2021

The upstream fix is now in rpi-5.10.y and rpi-5.11.y.

popcornmix added a commit to raspberrypi/firmware that referenced this issue Feb 8, 2021
kernel: media: i2c: imx290: Support V4L2_CID_ANALOGUE_GAIN as well as V4L2_CID_GAIN
See: raspberrypi/linux#4119

kernel: i2c: bcm2835: Handle untimely DONE signal
See: raspberrypi/linux#3064

kernel: 5.10 hdmi cec rework
See: raspberrypi/linux#3999

kernel: w1: w1_therm: Fix conversion result for negative temperatures
See: raspberrypi/linux#4124

kernel: staging:bcm2835-camera: Fix the cherry-pick of AWB Greyworld
See: raspberrypi/linux#4131
popcornmix added a commit to Hexxeh/rpi-firmware that referenced this issue Feb 8, 2021
kernel: media: i2c: imx290: Support V4L2_CID_ANALOGUE_GAIN as well as V4L2_CID_GAIN
See: raspberrypi/linux#4119

kernel: i2c: bcm2835: Handle untimely DONE signal
See: raspberrypi/linux#3064

kernel: 5.10 hdmi cec rework
See: raspberrypi/linux#3999

kernel: w1: w1_therm: Fix conversion result for negative temperatures
See: raspberrypi/linux#4124

kernel: staging:bcm2835-camera: Fix the cherry-pick of AWB Greyworld
See: raspberrypi/linux#4131
@popcornmix
Copy link
Collaborator

rpi-update contains the potential fix for this. Please test and report.

@Jaszczur666
Copy link

Just updated and tested - it works for me, thank you.

@johnterickson
Copy link
Author

Confirmed here as well - thanks @pelwell and @popcornmix for the quick turnaround!

@tracerrx
Copy link

tracerrx commented Feb 8, 2021

Can confirm that this patch fixes reading negatives on a Raspberry Pi Model B Rev 2, kernel 5.10.14. Thanks for the quick fix!

@danieltroger
Copy link

Can confirm here too it is now working again, thanks a lot!

it-is-a-robot pushed a commit to openeuler-mirror/raspberrypi-kernel that referenced this issue Feb 11, 2021
commit 2f6055c upstream.

DS18B20 device driver returns an incorrect value for negative temperatures
due to a missing sign-extension in w1_DS18B20_convert_temp().

Fix by using s16 temperature value when converting to int.

See: raspberrypi/linux#4124

Fixes: 9ace0b4 (w1: w1_therm: Add support for GXCAS GX20MH01 device.)
Cc: stable <stable@vger.kernel.org>
Reported-by: Paweł Marciniak <sunwire@gmail.com>
Signed-off-by: Ivan Zaentsev <ivan.zaentsev@wirenboard.ru>
Link: https://lore.kernel.org/r/20210121093021.224764-1-ivan.zaentsev@wirenboard.ru
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
@awarburt
Copy link

Tested the fix by way of raspi-config, and negative centigrade temperatures appear to be getting decoded correctly again. Thank you for the rapid fix.

gajdipajti added a commit to gajdipajti/munin-rpi-temp that referenced this issue Feb 15, 2021
The w1 driver has been updated in newer kernels, so I added this simplification to the code and also removed  the error checking (this issue should not be handled in software, build better onewire networks, please).
*NOTE:* There is also a kernel bug when negative temperatures are read, but it will be corrected in the near future. raspberrypi/linux#4124
popcornmix pushed a commit that referenced this issue Feb 16, 2021
commit 2f6055c upstream.

DS18B20 device driver returns an incorrect value for negative temperatures
due to a missing sign-extension in w1_DS18B20_convert_temp().

Fix by using s16 temperature value when converting to int.

See: #4124

Fixes: 9ace0b4 (w1: w1_therm: Add support for GXCAS GX20MH01 device.)
Cc: stable <stable@vger.kernel.org>
Reported-by: Paweł Marciniak <sunwire@gmail.com>
Signed-off-by: Ivan Zaentsev <ivan.zaentsev@wirenboard.ru>
Link: https://lore.kernel.org/r/20210121093021.224764-1-ivan.zaentsev@wirenboard.ru
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
it-is-a-robot pushed a commit to openeuler-mirror/raspberrypi-kernel that referenced this issue Feb 24, 2021
commit 2f6055c upstream.

DS18B20 device driver returns an incorrect value for negative temperatures
due to a missing sign-extension in w1_DS18B20_convert_temp().

Fix by using s16 temperature value when converting to int.

See: raspberrypi/linux#4124

Fixes: 9ace0b4 (w1: w1_therm: Add support for GXCAS GX20MH01 device.)
Cc: stable <stable@vger.kernel.org>
Reported-by: Paweł Marciniak <sunwire@gmail.com>
Signed-off-by: Ivan Zaentsev <ivan.zaentsev@wirenboard.ru>
Link: https://lore.kernel.org/r/20210121093021.224764-1-ivan.zaentsev@wirenboard.ru
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Fang Yafen <yafen@iscas.ac.cn>
it-is-a-robot pushed a commit to openeuler-mirror/raspberrypi-kernel that referenced this issue Feb 25, 2021
commit 2f6055c upstream.

DS18B20 device driver returns an incorrect value for negative temperatures
due to a missing sign-extension in w1_DS18B20_convert_temp().

Fix by using s16 temperature value when converting to int.

See: raspberrypi/linux#4124

Fixes: 9ace0b4 (w1: w1_therm: Add support for GXCAS GX20MH01 device.)
Cc: stable <stable@vger.kernel.org>
Reported-by: Paweł Marciniak <sunwire@gmail.com>
Signed-off-by: Ivan Zaentsev <ivan.zaentsev@wirenboard.ru>
Link: https://lore.kernel.org/r/20210121093021.224764-1-ivan.zaentsev@wirenboard.ru
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Fang Yafen <yafen@iscas.ac.cn>
it-is-a-robot pushed a commit to openeuler-mirror/raspberrypi-kernel that referenced this issue Feb 25, 2021
commit 2f6055c upstream.

DS18B20 device driver returns an incorrect value for negative temperatures
due to a missing sign-extension in w1_DS18B20_convert_temp().

Fix by using s16 temperature value when converting to int.

See: raspberrypi/linux#4124

Fixes: 9ace0b4 (w1: w1_therm: Add support for GXCAS GX20MH01 device.)
Cc: stable <stable@vger.kernel.org>
Reported-by: Paweł Marciniak <sunwire@gmail.com>
Signed-off-by: Ivan Zaentsev <ivan.zaentsev@wirenboard.ru>
Link: https://lore.kernel.org/r/20210121093021.224764-1-ivan.zaentsev@wirenboard.ru
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Fang Yafen <yafen@iscas.ac.cn>
it-is-a-robot pushed a commit to openeuler-mirror/raspberrypi-kernel that referenced this issue Feb 27, 2021
commit 2f6055c upstream.

DS18B20 device driver returns an incorrect value for negative temperatures
due to a missing sign-extension in w1_DS18B20_convert_temp().

Fix by using s16 temperature value when converting to int.

See: raspberrypi/linux#4124

Fixes: 9ace0b4 (w1: w1_therm: Add support for GXCAS GX20MH01 device.)
Cc: stable <stable@vger.kernel.org>
Reported-by: Paweł Marciniak <sunwire@gmail.com>
Signed-off-by: Ivan Zaentsev <ivan.zaentsev@wirenboard.ru>
Link: https://lore.kernel.org/r/20210121093021.224764-1-ivan.zaentsev@wirenboard.ru
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Fang Yafen <yafen@iscas.ac.cn>
it-is-a-robot pushed a commit to openeuler-mirror/raspberrypi-kernel that referenced this issue Feb 27, 2021
commit 2f6055c upstream.

DS18B20 device driver returns an incorrect value for negative temperatures
due to a missing sign-extension in w1_DS18B20_convert_temp().

Fix by using s16 temperature value when converting to int.

See: raspberrypi/linux#4124

Fixes: 9ace0b4 (w1: w1_therm: Add support for GXCAS GX20MH01 device.)
Cc: stable <stable@vger.kernel.org>
Reported-by: Paweł Marciniak <sunwire@gmail.com>
Signed-off-by: Ivan Zaentsev <ivan.zaentsev@wirenboard.ru>
Link: https://lore.kernel.org/r/20210121093021.224764-1-ivan.zaentsev@wirenboard.ru
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Fang Yafen <yafen@iscas.ac.cn>
it-is-a-robot pushed a commit to openeuler-mirror/kernel that referenced this issue Mar 6, 2021
raspberrypi inclusion
category: feature
bugzilla: 50432

--------------------------------

commit 2f6055c upstream.

DS18B20 device driver returns an incorrect value for negative temperatures
due to a missing sign-extension in w1_DS18B20_convert_temp().

Fix by using s16 temperature value when converting to int.

See: raspberrypi/linux#4124

Fixes: 9ace0b4 (w1: w1_therm: Add support for GXCAS GX20MH01 device.)
Cc: stable <stable@vger.kernel.org>
Reported-by: Paweł Marciniak <sunwire@gmail.com>
Signed-off-by: Ivan Zaentsev <ivan.zaentsev@wirenboard.ru>
Link: https://lore.kernel.org/r/20210121093021.224764-1-ivan.zaentsev@wirenboard.ru
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Fang Yafen <yafen@iscas.ac.cn>
Signed-off-by: Zheng Zengkai <zhengzengkai@huawei.com>
johnterickson referenced this issue in johnterickson/MiPi-1wire-rs Mar 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants