NetBSD Problem Report #54941

From www@netbsd.org  Thu Feb  6 07:49:28 2020
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 3713F1A9213
	for <gnats-bugs@gnats.NetBSD.org>; Thu,  6 Feb 2020 07:49:28 +0000 (UTC)
Message-Id: <20200206074927.6029E1A9251@mollari.NetBSD.org>
Date: Thu,  6 Feb 2020 07:49:27 +0000 (UTC)
From: rokuyama.rk@gmail.com
Reply-To: rokuyama.rk@gmail.com
To: gnats-bugs@NetBSD.org
Subject: Raspberry Pi Zero W serial console corrupted when CPU frequency changed
X-Send-Pr-Version: www-1.0

>Number:         54941
>Category:       port-evbarm
>Synopsis:       Raspberry Pi Zero W serial console corrupted when CPU frequency changed
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    port-evbarm-maintainer
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Feb 06 07:50:00 +0000 2020
>Last-Modified:  Thu Feb 20 03:00:02 +0000 2020
>Originator:     Rin Okuyama
>Release:        9.99.45 (netbsd-9 is also affected)
>Organization:
Department of Physics, Meiji University
>Environment:
NetBSD rpi0w 9.99.45 NetBSD 9.99.45 (RPI) #4: Wed Feb  5 09:59:26 JST 2020  rin@latipes:/build/src/sys/arch/evbarm/compile/RPI evbarm
>Description:
Serial console (mini UART; com0) on Raspberry Pi Zero W (RPI0W) gets
corrupted when CPU frequency (machdep.cpu.frequency.target) is changed
from 700 to 1000 by sysctl(8).

This is because the baud rate of mini UART is linked to CPU frequency:

  https://www.raspberrypi.org/documentation/configuration/uart.md
>How-To-Repeat:
sudo sysctl -w machdep.cpu.frequency.target=1000
>Fix:
A lazy workaround is to copy /boot/bcm2835-rpi-zero.dtb into
/boot/bcm2835-rpi-zero-w.dtb, which forces firmware to configure the
system as a RPI0. Then, PL011 (plcom0) is used as console, which is
free from the core frequency. However, this workaround kills all the
enhancements made to RPI0W from RPI0.

The real fix should be to adjust the baud rate when CPU frequency is
changed in vcmbox_cpufreq_sysctl_helper():

  https://nxr.netbsd.org/xref/src/sys/arch/evbarm/rpi/rpi_vcmbox.c#vcmbox_cpufreq_sysctl_helper

But I'm currently not sure whether this is possible, especially when
console is opened from userland.

>Audit-Trail:
From: mlelstv@serpens.de (Michael van Elst)
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: port-evbarm/54941: Raspberry Pi Zero W serial console corrupted when CPU frequency changed
Date: Fri, 7 Feb 2020 04:32:42 -0000 (UTC)

 rokuyama.rk@gmail.com writes:

 >Serial console (mini UART; com0) on Raspberry Pi Zero W (RPI0W) gets
 >corrupted when CPU frequency (machdep.cpu.frequency.target) is changed
 >from 700 to 1000 by sysctl(8).

 >This is because the baud rate of mini UART is linked to CPU frequency:
 >  https://www.raspberrypi.org/documentation/configuration/uart.md

 That's a limitation of the hardware. It also occurs when the CPU
 frequency is changed by the firmware (e.g. when temperature is too
 high or voltage too low).

 You can force firmware to keep frequency (which also stops users from
 selecting a frequency) with the force_turbo=1 firmware setting (also some
 other possibilities).

 You can switch console to the PL011 UART (and disable/restrict the Bluetooth
 interface by doing so) with a DTB overlay. Not sure if our DTB allows it,
 but that's the common method used with Linux.

 >The real fix should be to adjust the baud rate when CPU frequency is
 >changed in vcmbox_cpufreq_sysctl_helper():

 Adjusting the UART configuration in the com driver (not the sysctl helper)
 would be possible. However, it doesn't really fix the problem. At every
 frequency switch a concurrent send or receive operation on the console
 still gets corrupted.

 -- 
 -- 
                                 Michael van Elst
 Internet: mlelstv@serpens.de
                                 "A potential Snark may lurk in every tree."

From: Rin Okuyama <rokuyama.rk@gmail.com>
To: gnats-bugs@netbsd.org, Michael van Elst <mlelstv@serpens.de>
Cc: 
Subject: Re: port-evbarm/54941: Raspberry Pi Zero W serial console corrupted
 when CPU frequency changed
Date: Thu, 20 Feb 2020 11:56:28 +0900

 Thank you Michael for your comment, and sorry for the late reply.

 I see. The failure is due to the hardware limitation, and it is
 difficult, at least for now, to deal with it by kernel.

 For DTB overlay, RPI firmware requires /boot/overlays/*.dtbo files, that
 we do not currently distribute.

 Unfortunately, DTBO files compiled from DTS provided by github/raspberrypi:

    https://github.com/raspberrypi/linux/tree/rpi-4.19.y/arch/arm/boot/dts/overlays

 do not work. This is due to inconsistency in DTS files b/w Linux mainline
 (our upstream):

    https://github.com/torvalds/linux/tree/master/arch/arm/boot/dts

 v.s. github/raspberrypi:

    https://github.com/raspberrypi/linux/tree/rpi-4.19.y/arch/arm/boot/dts/

 # Note that firmware outputs diagnostic messages in console when dtdebug=1
 # in /boot/config.txt:
 #
 #   https://www.raspberrypi.org/documentation/configuration/device-tree.md
 #
 # and s/BOOT_UART=0/BOOT_UART=1/ in /boot/bootcode.bin:
 #
 #   https://www.raspberrypi.org/documentation/hardware/raspberrypi/bootmodes/

 Therefore, we need to (1) have our own DTBO files, or (2) switch to DTB
 files provided by github/raspberrypi.

 For (1), I cannot at the moment write working DTBO files equivalent to
 disable-bt nor miniuart-bt. I wonder whether it is possible to disable
 bluetooth node in uart0:

    https://nxr.netbsd.org/xref/src/sys/external/gpl2/dts/dist/arch/arm/boot/dts/bcm2835-rpi-zero-w.dts#139

 For (2), DTS files of github/raspberrypi cannot be compiled by our
 dtc(1), and kernel does not boot with DTB files taken from Raspbian.
 Also, changing upstream from Linux to github/raspberrypi may be not
 a good choice.

 Thanks,
 rin

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.