From patchwork Wed Jun 20 03:02:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 139276 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp242921lji; Tue, 19 Jun 2018 20:03:52 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLO7+0ID6vFX0fXN9x8w0iKiAZ3vR41NicP1h+qGSaL7xL0TVaZRZ1XNIJSpczujHQettDR X-Received: by 2002:a63:b004:: with SMTP id h4-v6mr318362pgf.340.1529463832755; Tue, 19 Jun 2018 20:03:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529463832; cv=none; d=google.com; s=arc-20160816; b=lFsz2uW6x1QWKE2cw9EIpEnDekpPwjexhIC8Jl0f+p4PXz8161hNolR4TBN1HSkaa5 C+uRtb+53fbHWT6QIqQt35rXLIgfYv97/VjDaeUDJMJVMgO1T6F4NON1ZUcKm2OwKzsw Ucez8XtgalqLtdofbT1rUN12y0SVNsYVVqNJq8hiZX3nXLOkxCfxmzkI96jbC+0H/uxZ YUWfIlICXw6ZXew3XOELOoRclqz2TJTyviGQ82EzouI348+pFE3cKwi6L2YpcQD9C3Tp tXIuWJb8QI0xUaq6xgfVYJia0p2iZQ/anLCmWs9Y3qEIsKGnDdunn+y4Wo9U8hWnFRov oeQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=pt+CE80Kmz8xZAF1MZFZIDDGZwAl0CdP9riZYYfmEWI=; b=xPw50M2QMNjqMnr9bZl6wf10kfI5G6HSsz6f44pU+XypZHUYc8CG/vWFwuKu82uCgf CZErf2GixGG54sBJwkJjowfLjbfna3EoYtF5BT42qTmmU8rwUXsQPKBCusS0ikx6d+zG svdKRdE1LGI58bJIjBEh/iEhytN/2GzppFKM3hLPGJwcUkjnUxZJZIqzqDwBbEFZVKiT Xj9jYvEAfPTj0RTwkfOTnfnWApitdM631phxnQSKXCnofYFGLIXJ1h7WTUc9JgRfhu0k O4IYt3ln4zcf/sTEqPVFXtCf71nN+Bpoi35Vz3cOE/N1Wsc8y145SG/mkBp/l1aV3H9H v4Xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=LqWmixfI; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id a16-v6si1193315pff.43.2018.06.19.20.03.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Jun 2018 20:03:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=LqWmixfI; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id A75A021193780; Tue, 19 Jun 2018 20:03:51 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:400e:c05::244; helo=mail-pg0-x244.google.com; envelope-from=masahisa.kojima@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-pg0-x244.google.com (mail-pg0-x244.google.com [IPv6:2607:f8b0:400e:c05::244]) (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 2720F2118A59B for ; Tue, 19 Jun 2018 20:03:49 -0700 (PDT) Received: by mail-pg0-x244.google.com with SMTP id d2-v6so764727pga.13 for ; Tue, 19 Jun 2018 20:03:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=Q+WmnE74+DjdGyn/XlnDAAt1DmzWA5wgAk27U7yM64I=; b=LqWmixfILurl7q9KPzuG3qMMreS8BTZr07WNqgnFmaQaTdjQmbY/bezxb16ATi17Wg yiIU8n6RRt6ATv3x9v2a7VsC6Z+o02cxJ8L359FB2ux9qaFt6brAW3XatulfRSDh7JD5 myzBMxt9d2TGN/pesZ+f0BcomAZ9P+s7NKHz0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Q+WmnE74+DjdGyn/XlnDAAt1DmzWA5wgAk27U7yM64I=; b=cMFuypl3AwFr/DHJfIoWjKJtIZhda1vn2iTbm+vqK2AZmikhBpXfwMwlr2ChGC1DmB 8v75pAbDLneNPPWDHMSfl663JH803K0despy6YGxcgxtjg+/5mpcsSEuwCZDFXtWBbWU mJYebuLlgMMi6BJUbYE0/UEOilDnf0H8razUx3jJ1GAMbC37sHQS9VGn0WuYdXaTsaR/ 2PxK1XtEDlS6VyVffhM7+xNU6fS5+p1R36nlrnh+wwOs+Bd6FjAPycvg9JVPWIRUSY2n /5uwD9cZ2A2SkJLV67zfq4KpaOf5OOoRno43+GE77b80oX3dKEgIgVtIbekO8X3qs+34 ey6Q== X-Gm-Message-State: APt69E2wUVyT9TZ5u7ATmXJtxg40wxmARhIGSajtfxAjgqZrhjY3G/aE A4/uUzqNG8eyf7urY6Jdt990qJ7CMs8= X-Received: by 2002:a65:4dc3:: with SMTP id q3-v6mr17005648pgt.331.1529463829124; Tue, 19 Jun 2018 20:03:49 -0700 (PDT) Received: from localhost ([121.95.100.191]) by smtp.gmail.com with ESMTPSA id u90-v6sm1513812pfa.101.2018.06.19.20.03.48 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 19 Jun 2018 20:03:48 -0700 (PDT) From: masahisa.kojima@linaro.org To: edk2-devel@lists.01.org Date: Wed, 20 Jun 2018 12:02:40 +0900 Message-Id: <20180620030240.2409-1-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.14.2 Subject: [edk2] [PATCH v2] 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: , Cc: Yoshitoyo Osaki , leif.lindholm@linaro.org, ard.biesheuvel@linaro.org MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" 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 --- .../Pcf8563RealTimeClockLib.c | 31 +++++++++++++++------- 1 file changed, 22 insertions(+), 9 deletions(-) -- 2.14.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.c b/Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.c index fb58e1feb4..9f49ae91de 100644 --- a/Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.c +++ b/Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.c @@ -19,11 +19,13 @@ #include #include #include +#include #include #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 @@ -95,6 +97,7 @@ LibGetTime ( RTC_DATETIME DateTime; EFI_STATUS Status; UINT8 Reg; + EFI_TIME InitTime; if (Time == NULL) { return EFI_INVALID_PARAMETER; @@ -122,15 +125,25 @@ 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) { + InitTime.Second = 0; + InitTime.Minute = 0; + InitTime.Hour = 0; + InitTime.Day = 1; + InitTime.Month = 1; + InitTime.Year = EPOCH_BASE; + (VOID)CopyMem (Time, &InitTime, sizeof(EFI_TIME)); + } 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) {