From patchwork Wed Jun 20 07:15:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 139284 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp436306lji; Wed, 20 Jun 2018 00:16:30 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKfrRB/UDZCvIHl82BVpLgwxc4jJcxbj/MmKwpHyXTN11rANkJAkwjz2oJ5PrbD6i+PDdL6 X-Received: by 2002:a17:902:42c3:: with SMTP id h61-v6mr22366591pld.319.1529478990502; Wed, 20 Jun 2018 00:16:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529478990; cv=none; d=google.com; s=arc-20160816; b=aJtTgvGkMmG0qkkWx/3muObO1PowhZet0diRdXR5SLqfGzfRl4xaWZCdUAa0tJpcfi QpvndIcJyafpvp+mdczI/RgHFuj3/A1TJr20qA7WhSd4uY9N8tBzn23CqTL1LS/OSSVB 5qdmL/oedQPuIQBsfUiUmYkphVmsbyyevEnZTYp6yaO3cet1++od12ZOmj/NHZqgCD07 5z+GMtA9rmLKlkpAr79epo0GlIOfOR/4SATr07E1a604pyvWIvQ8XoZOiuQIWd+VpKuv oKN6Rfyokl1VM4wT7l8y9wqoF31YIsHkm1tZ2OPyHf65Q2ywnNM2+4I/PUQ1qePuPsCG eQWA== 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=cPSLjK9a5h7XHdw0eXlWTO9fuSCm3ynj7xD0q72CpIQ=; b=DsPgTaKV3ql+xQVNLY9F2dCdPSzxV8b6BvJJZ+RdgXjM/J89u9Q+VvmpVjcpfoVRDi LWgaTxQ0J8I1OAQ0ffBH3cGt5tVKy2ec4W4ryTXYkmT6/CPVDvwFh5//VJBluQWECo9a /BBzbfxyURSbhbqm0JhdU/18FRIxR7dACkAknskg645wsZHpacgGDAN3W9tCj1257GKk hiqLhWoBcbWWPsg+cNzRBrtsyOxUnCPF2ojVT/Cf7vneUn9vC3giYqI6b3Jc+a2aPsQj Y+V64tSsO10rC2iaPvE5KG8RPfzFqit9/PxkDVgFWbk6ZqQAacos4IKviFMMc/6GkVLy FFjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=fNhnm+qh; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 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. [198.145.21.10]) by mx.google.com with ESMTPS id o19-v6si1425672pgc.299.2018.06.20.00.16.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Jun 2018 00:16:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) client-ip=198.145.21.10; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=fNhnm+qh; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 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 B48EA210D1EE5; Wed, 20 Jun 2018 00:16:29 -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:c00::244; helo=mail-pf0-x244.google.com; envelope-from=masahisa.kojima@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-pf0-x244.google.com (mail-pf0-x244.google.com [IPv6:2607:f8b0:400e:c00::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 688EC2112546A for ; Wed, 20 Jun 2018 00:16:29 -0700 (PDT) Received: by mail-pf0-x244.google.com with SMTP id b74-v6so1138261pfl.5 for ; Wed, 20 Jun 2018 00:16:29 -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=lVehAalfXvirqdJfLa/7CsOXFbv1esiwZj0D+Hd9hfY=; b=fNhnm+qhsQMwg1Hg8bFhoXsKDCpaEBrlrVxPCUODHCunx6Fo8QiEtscRheZvLiZvRC sleQpAaY9g7aMimAB3Sp0DH6Wnq+YqHnmRWTao+0yhwch4PYxzhsd3+/jo7WfwebRrRR Xwg7qUuKgvxPVjnsKqeXe6QydAqP+kTlmc0NU= 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=lVehAalfXvirqdJfLa/7CsOXFbv1esiwZj0D+Hd9hfY=; b=HhEFH2sEkHuAv4GpeYizl9HF8SD6rBkylr/cgwg0mRD9kSI58++yznXUSSQEVmrkse DV/OmUkljYGdumKO4Rrnka9+yYtNvMtUdtbLbBENDyLGaxn+4PjzbqiQjwMP5zXhxI7N PCwYA7FoS1qb63jiHc8T0d41jMy2A8Qvjvy0uhj1kijUfkuug/mGLdS7z2bzoI5NpvnK /PapDct1Y2E3HQ0ifNf7Bo+FFqQ7mE7FIi15XjhexjPSsKvoTemVwUJ3W0eCZNa9Rvbc bBKUzmsqE2LMZ20MJJPOI47XbN0HAVk3CwcQDMjPK4MTKyLKe3kTIFY8xH+GmkvVcpGN SlAA== X-Gm-Message-State: APt69E1vbDfIDkQXYD/oZkY0TRtfy+qxf5rh/5cOc/OYJRjFn0A4iniL fe8K6zu6aI5WtIcuMdTl9gxK88JLZ70= X-Received: by 2002:a62:b612:: with SMTP id j18-v6mr21570296pff.199.1529478988818; Wed, 20 Jun 2018 00:16:28 -0700 (PDT) Received: from localhost ([121.95.100.191]) by smtp.gmail.com with ESMTPSA id g4-v6sm2601246pfg.38.2018.06.20.00.16.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Jun 2018 00:16:28 -0700 (PDT) From: masahisa.kojima@linaro.org To: edk2-devel@lists.01.org Date: Wed, 20 Jun 2018 16:15:49 +0900 Message-Id: <20180620071549.2295-1-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.14.2 Subject: [edk2] [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: , 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 | 28 +++++++++++++++------- 1 file changed, 19 insertions(+), 9 deletions(-) -- 2.14.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel Reviewed-by: Ard Biesheuvel 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) {