Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 2 Jan 2018 15:37:37 +0100
From:      Matthias Apitz <guru@unixarea.de>
To:        Ian Lepore <ian@freebsd.org>, freebsd-current@freebsd.org, cem@freebsd.org
Subject:   Re: panic: invalid bcd 194
Message-ID:  <20180102143737.GA2286@c720-r314251>
In-Reply-To: <20180102130020.GA2236@c720-r314251>
References:  <20171230210711.GA75976@c720-r314251> <20171230211154.GT1684@kib.kiev.ua> <20171230214819.GA2191@c720-r314251> <20171231083624.GA2175@c720-r314251> <1514740790.12000.20.camel@freebsd.org> <20180101085425.GA2301@c720-r314251> <1514851362.1759.8.camel@freebsd.org> <20180102130020.GA2236@c720-r314251>

next in thread | previous in thread | raw e-mail | index | archive | help

--2oS5YaxWCcQjTEyO
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

El d=C3=ADa martes, enero 02, 2018 a las 02:00:20p. m. +0100, Matthias Apit=
z escribi=C3=B3:

> # cp /usr/obj/usr/src/sys/GENERIC/kernel /boot/kernel/kernel
>=20
> The kernel boots fine as:
>=20
> FreeBSD c720-r314251 12.0-CURRENT FreeBSD 12.0-CURRENT #2 r314251M: Tue J=
an  2 12:53:31 CET 2018     guru@c720-r314251:/usr/obj/usr/src/sys/GENERIC =
 amd64
>=20
> but: while the current date is read with the correct time, the year is 19=
70:
>=20
> # date
> Tue Jan  2 1970, 13:45:24 CET
>=20
> One can set the date/time with the date(1) command or ntpdate.
>=20
> The debug messages are (the first line is from boot, the others from the
> date or ntpdate):
>=20
> # grep DEBUG /var/log/messages
> Jan  2 13:43:02 c720-r314251 kernel: BCD DEBUG: atrtc_gettime() entry
> Jan  2 13:43:02 c720-r314251 kernel: BCD DEBUG: atrtc_gettime() entry
> Jan  2 13:44:00 c720-r314251 kernel: BCD DEBUG: atrtc_set() entry


I've added one more printf to see what is coming as year from BCD. The code
is attached below and bcd.year comes out as 24 (decimal) which is 0x18. I.e=
=2E it
seems that the year from 2018 is stored in hex as 0x18, or?


Jan  2 15:08:02 c720-r314251 kernel: BCD DEBUG: atrtc_gettime() entry witho=
ut USE_RTC_CENTURY
Jan  2 15:08:02 c720-r314251 kernel: BCD DEBUG: atrtc_gettime() bct.year=3D=
24
Jan  2 15:13:00 c720-r314251 kernel: BCD DEBUG: atrtc_set() entry without U=
SE_RTC_CENTURY
Jan  2 15:14:34 c720-r314251 kernel: BCD DEBUG: atrtc_set() entry without U=
SE_RTC_CENTURY

static int
atrtc_gettime(device_t dev, struct timespec *ts)
{
	struct bcd_clocktime bct;
#ifdef USE_RTC_CENTURY
	printf("BCD DEBUG: atrtc_gettime() entry with USE_RTC_CENTURY\n");
#else
	printf("BCD DEBUG: atrtc_gettime() entry without USE_RTC_CENTURY\n");
#endif

	/* Look if we have a RTC present and the time is valid */
	if (!(rtcin(RTC_STATUSD) & RTCSD_PWR)) {
		device_printf(dev, "WARNING: Battery failure indication\n");
		return (EINVAL);
	}

	/*
	 * wait for time update to complete
	 * If RTCSA_TUP is zero, we have at least 244us before next update.
	 * This is fast enough on most hardware, but a refinement would be
	 * to make sure that no more than 240us pass after we start reading,
	 * and try again if so.
	 */
	while (rtcin(RTC_STATUSA) & RTCSA_TUP)
		continue;
	critical_enter();
	bct.sec  =3D rtcin(RTC_SEC);
	bct.min  =3D rtcin(RTC_MIN);
	bct.hour =3D rtcin(RTC_HRS);
	bct.day  =3D rtcin(RTC_DAY);
	bct.mon  =3D rtcin(RTC_MONTH);
	bct.year =3D rtcin(RTC_YEAR);
#ifdef USE_RTC_CENTURY
	bct.year |=3D rtcin(RTC_CENTURY) << 8;
#endif
	critical_exit();
	/* dow is unused in timespec conversion and we have no nsec info. */
	bct.dow  =3D 0;
	bct.nsec =3D 0;
	printf("BCD DEBUG: atrtc_gettime() bct.year=3D%d\n", bct.year);
	return (clock_bcd_to_ts(&bct, ts));
}

--=20
Matthias Apitz, =E2=9C=89 guru@unixarea.de, =E2=8C=82 http://www.unixarea.d=
e/  =F0=9F=93=B1 +49-176-38902045
Public GnuPG key: http://www.unixarea.de/key.pub

--2oS5YaxWCcQjTEyO
Content-Type: application/pgp-signature; name="signature.asc"

-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEEXmn7rBYYViyzy/vBR8z35Hb+nREFAlpLmS8ACgkQR8z35Hb+
nRHuMhAAl0DON2T2bsrKNS1uoGweMKFhvZFinw1azVgfOM/1CEcWZRLMAxctuO2A
R279bkJzbHaL2+c+uYF9Y1EXK0F5uNcb4hilJxaKTlg8Wgs3vIBnUGUDVsJZAudM
wkKgn62Rf/7s5MaxoKLJgT36o9KSmnFdoRYdi5WOBJO8eb2p34HZGtISGwWrYMNw
DJAg1wS9gclW+G4a2OnTyPb4Y4NAiMzxt6fA1QE2cjhZCjeSXqaE8WSw5i4BzI9b
Md+pUkKOQBXBjPIthCrlHCzfZhGQzLJdrIyTF5yB+i6xgb+5aMfO6vCYKdd2PwtD
ah+eU0V9jQIFM3xFLrm/x3uJhv9TX2eIyt6pkHPVCP7jmn+2wuaYZ5XoBTNWrsLX
IqjnuMqETUbjNIWbsHypFHL+SDMdNjdfcl5XdQTKrxfK76Z/INzQaaHyuofyEYLz
FioQfVBPxSDoOJo6fcg33AEugNVyLxhF/LrTkWoUpew8sc0Bpn1t2qVLxKm7Z41b
yuS7DqdsF8Nv6AB0Ue8hUxMvKhgrE9VQ2sFSklNRMBV2mROzGNdjXy9OrrsgXnoJ
YQtgHyM2gvlUQb/fpjLUv3txYVugQGNMTfu6AbuJWRnkro12VHpkRlVlp8hLLeDc
NNu4WX/ip2iUvCQZQh2QFaEOreTUX+xcqMxic0ou71W9Sxfaem4=
=IcwO
-----END PGP SIGNATURE-----

--2oS5YaxWCcQjTEyO--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20180102143737.GA2286>