From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:4001:c0b::243; helo=mail-it0-x243.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-it0-x243.google.com (mail-it0-x243.google.com [IPv6:2607:f8b0:4001:c0b::243]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 4E486210D1F0D for ; Wed, 20 Jun 2018 03:51:19 -0700 (PDT) Received: by mail-it0-x243.google.com with SMTP id n7-v6so4755000itn.1 for ; Wed, 20 Jun 2018 03:51:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=OMpX+wszMoeXgNk+2yNfgwrwQ3TSVEsixAI0xdtVhfM=; b=ZQIaBH2MIdUzIAyXHl+3RDzG8MY6qO8W0XChrm+mldE4gJV0zxNBTAi+L25OZkGJMW DH9ojhu+4xxSak+zu+o0yNFeRxE9xx/KLfpkarWO0JSb5Ru4bWCRsMpIL7EuNxK0LeX3 +MptfCGub28vXZjy3oKR+fLmMjT480sNbtpH8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=OMpX+wszMoeXgNk+2yNfgwrwQ3TSVEsixAI0xdtVhfM=; b=EvxIx26WvsEERW+akJRYc4V3t+LqQJGJHmdKFB4Gl+SJzIeKsztH73RO7pWknH5Tlt fHq6fKYtjlkZumZ27fAJvDOmQgp2YvXQnW4BmNkfTM3j5MPxZCvJ0pH2BbxO2XdimirM cB4V4xtgHRHsIm1xLqhyqdbJaPSNkEi9Q83bnawbPgoQZ0UI8EQ+zWh+vcRYV0NNL9h7 wUavFhg0LMqw6MtNs9Whl9BMbnuwmd1+MVz4Mi5i7clvqaBbUe0Rmfw8YoucZm0lo9wm fT6jR5NqKupov8C/8PA6fz5/Ed2r4lqYrZpY7w/0vEQlTVxg2j4UhdKpSoranqxCaqdI aJuw== X-Gm-Message-State: APt69E3yltwlpevyxUZpMtRu2S95R95CO9cxrQsXGajTGXsaYaFBMs4u A95trN1vYcT8ITLHbnfFSRTxAr9E1Ha/AZoX9RuNtg== X-Google-Smtp-Source: ADUXVKIVomD+21KHC5NebW/VzmgP+BvKYc3Z/8KlWqRQw5L8qO0Y9zZ8a9nMY2qpqntOpNiTODgdeUukt2M1bwMNVXk= X-Received: by 2002:a02:2422:: with SMTP id f34-v6mr16870098jaa.2.1529491878842; Wed, 20 Jun 2018 03:51:18 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a6b:bbc7:0:0:0:0:0 with HTTP; Wed, 20 Jun 2018 03:51:18 -0700 (PDT) In-Reply-To: <20180620071549.2295-1-masahisa.kojima@linaro.org> References: <20180620071549.2295-1-masahisa.kojima@linaro.org> From: Ard Biesheuvel Date: Wed, 20 Jun 2018 12:51:18 +0200 Message-ID: To: Masahisa Kojima Cc: "edk2-devel@lists.01.org" , Leif Lindholm , Yoshitoyo Osaki Subject: Re: [PATCH v3] Silicon/NXP/Pcf8563RealTimeClockLib: add Voltage-low handling X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 20 Jun 2018 10:51:20 -0000 Content-Type: text/plain; charset="UTF-8" On 20 June 2018 at 09:15, wrote: > From: Masahisa Kojima > > BcdToDecimal8() in LibGetTime() asserts with the > following condition. > 1) RTC device has not been initialized yet, RTC device > returns indeterminate value with VL bit(1) > 2) DEBUG build > > UEFI boot fails with assertion when it satisfies above conditions. > > Aside form boot failure, UEFI shell commands "date/time" expect > that getting time from RTC should success when user sets the time. > ShellCommandRunTime() performs GetTime()->update time->SetTime(), > if the first GetTime() fails, user can not set time. > With that, simply returning EFI_DEVICE_ERROR in LibGetTime() > is not applicable to VL bit handling. > > To avoid this situation, even if it only occurs in DEBUG build, > RTC driver should check the VL bit in the VL_seconds register. > This VL bit is voltage-low detector, it means integrity of the > clock information is not guaranteed if it sets to 1. In this > case, driver return dummy date/time(01/01/2000 00:00:00) to > proceed succeeding process. > > linux driver also checks this bit when driver gets the time > from RTC. If VL bit is 1, linux driver discard the retreived > time data. > > Note that if VL bit is 1, GetTime() returns always > 01/01/2000 00:00:00 until user sets date/time. > > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Masahisa Kojima > Signed-off-by: Yoshitoyo Osaki Thanks Reviewed-by: Ard Biesheuvel Pushed as 070938aa96aa91d822de57897e39c747c56eb4de > --- > .../Pcf8563RealTimeClockLib.c | 28 +++++++++++++++------- > 1 file changed, 19 insertions(+), 9 deletions(-) > > diff --git a/Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.c b/Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.c > index fb58e1feb4..77d8998cfd 100644 > --- a/Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.c > +++ b/Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.c > @@ -24,6 +24,7 @@ > #define SLAVE_ADDRESS (FixedPcdGet8 (PcdI2cSlaveAddress)) > #define PCF8563_DATA_REG_OFFSET 0x2 > > +#define PCF8563_CLOCK_INVALID 0x80 > #define PCF8563_SECONDS_MASK 0x7f > #define PCF8563_MINUTES_MASK 0x7f > #define PCF8563_HOURS_MASK 0x3f > @@ -122,15 +123,24 @@ LibGetTime ( > return EFI_DEVICE_ERROR; > } > > - Time->Second = BcdToDecimal8 (DateTime.VL_seconds & PCF8563_SECONDS_MASK); > - Time->Minute = BcdToDecimal8 (DateTime.Minutes & PCF8563_MINUTES_MASK); > - Time->Hour = BcdToDecimal8 (DateTime.Hours & PCF8563_HOURS_MASK); > - Time->Day = BcdToDecimal8 (DateTime.Days & PCF8563_DAYS_MASK); > - Time->Month = BcdToDecimal8 (DateTime.Century_months & PCF8563_MONTHS_MASK); > - Time->Year = BcdToDecimal8 (DateTime.Years) + EPOCH_BASE; > - > - if (DateTime.Century_months & PCF8563_CENTURY_MASK) { > - Time->Year += 100; > + if ((DateTime.VL_seconds & PCF8563_CLOCK_INVALID) != 0) { > + Time->Second = 0; > + Time->Minute = 0; > + Time->Hour = 0; > + Time->Day = 1; > + Time->Month = 1; > + Time->Year = EPOCH_BASE; > + } else { > + Time->Second = BcdToDecimal8 (DateTime.VL_seconds & PCF8563_SECONDS_MASK); > + Time->Minute = BcdToDecimal8 (DateTime.Minutes & PCF8563_MINUTES_MASK); > + Time->Hour = BcdToDecimal8 (DateTime.Hours & PCF8563_HOURS_MASK); > + Time->Day = BcdToDecimal8 (DateTime.Days & PCF8563_DAYS_MASK); > + Time->Month = BcdToDecimal8 (DateTime.Century_months & PCF8563_MONTHS_MASK); > + Time->Year = BcdToDecimal8 (DateTime.Years) + EPOCH_BASE; > + > + if (DateTime.Century_months & PCF8563_CENTURY_MASK) { > + Time->Year += 100; > + } > } > > if (Capabilities != NULL) { > -- > 2.14.2 >