From patchwork Wed Dec 30 17:07:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1421426 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmx.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.a=rsa-sha256 header.s=badeba3b8450 header.b=R89yEIpQ; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4D5d5w3b49z9sTK for ; Thu, 31 Dec 2020 04:08:10 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 31F3B82540; Wed, 30 Dec 2020 18:08:00 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.b="R89yEIpQ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 847FE824DE; Wed, 30 Dec 2020 18:07:58 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id E0386824DE for ; Wed, 30 Dec 2020 18:07:55 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1609348073; bh=PXl47xYy3NaZcXKZN/js6ffjaTGH9waIe05eUjZY8As=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date; b=R89yEIpQ9BfpvqJZaQBTGqnKHWK/okpVByA60i/PVm/3BBn3gzczJnktGDbeEi/MU PKiPbND/9LBkdkwTFW30ZWCSwNbFrOgWk7aoP28NlzUCxL69GDSAeP+W0aNExXLz+w q6x0KhOvjgXLbT0hKndK8K/BDZUMzxNUW3BqZ/ls= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from mcbin.fritz.box ([62.143.246.89]) by mail.gmx.com (mrgmx105 [212.227.17.174]) with ESMTPSA (Nemesis) id 1M3UZG-1kvCup1b62-000Z22; Wed, 30 Dec 2020 18:07:53 +0100 From: Heinrich Schuchardt To: Simon Glass Cc: Rasmus Villemoes , Heiko Schocher , u-boot@lists.denx.de, Heinrich Schuchardt Subject: [PATCH 1/1] sandbox: keep time offset when resetting Date: Wed, 30 Dec 2020 18:07:48 +0100 Message-Id: <20201230170748.108499-1-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 X-Provags-ID: V03:K1:T2E1LcrA9DvUnXJg3VxIl9DUjS422c6Vv99nSYK1UdM0Q28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F4sWAExlnAF/S7H3eyC1cwUSALpC32cY Q9FZUEtgp4sxxgur1oLg== X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean The UEFI Self Certification Test (SCT) checks the SetTime() service with the following steps: * set date * reset * check date matches To be compliant the sandbox should keep the offset to the host RTC during resets. The implementation uses the environment variable UBOOT_SB_TIME_OFFSET to persist the offset. Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass Reviewed-by: Simon Glass --- arch/sandbox/cpu/os.c | 25 +++++++++++++++++++++++++ doc/arch/sandbox.rst | 7 +++++++ drivers/rtc/i2c_rtc_emul.c | 4 +++- include/os.h | 18 ++++++++++++++++++ 4 files changed, 53 insertions(+), 1 deletion(-) -- 2.29.2 diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c index b56fa04a34..87fce57a36 100644 --- a/arch/sandbox/cpu/os.c +++ b/arch/sandbox/cpu/os.c @@ -32,6 +32,9 @@ #include #include +/* Environment variable for time offset */ +#define ENV_TIME_OFFSET "UBOOT_SB_TIME_OFFSET" + /* Operating System Interface */ struct os_mem_hdr { @@ -793,6 +796,28 @@ int os_spl_to_uboot(const char *fname) return os_jump_to_file(fname); } +long os_get_time_offset(void) +{ + const char *offset; + + offset = getenv(ENV_TIME_OFFSET); + if (offset) + return strtol(offset, NULL, 0); + return 0; +} + +void os_set_time_offset(long offset) +{ + char buf[21]; + int ret; + + snprintf(buf, sizeof(buf), "%ld", offset); + ret = setenv(ENV_TIME_OFFSET, buf, true); + if (ret) + printf("Could not set environment variable %s\n", + ENV_TIME_OFFSET); +} + void os_localtime(struct rtc_time *rt) { time_t t = time(NULL); diff --git a/doc/arch/sandbox.rst b/doc/arch/sandbox.rst index 4674c420ac..ee720c5a09 100644 --- a/doc/arch/sandbox.rst +++ b/doc/arch/sandbox.rst @@ -131,6 +131,13 @@ available options. Some of these are described below: * -i - Go to interactive mode after executing the commands specified by -c. +Environment Variables +--------------------- + +UBOOT_SB_TIME_OFFSET + This environment variable stores the offset of the emulated real time clock + to the host's real time clock in seconds. The offset defaults to zero. + Memory Emulation ---------------- diff --git a/drivers/rtc/i2c_rtc_emul.c b/drivers/rtc/i2c_rtc_emul.c index 7f78ff83cb..ef6f6a8e1d 100644 --- a/drivers/rtc/i2c_rtc_emul.c +++ b/drivers/rtc/i2c_rtc_emul.c @@ -57,6 +57,7 @@ long sandbox_i2c_rtc_set_offset(struct udevice *dev, bool use_system_time, plat->use_system_time = use_system_time; if (offset != -1) plat->offset = offset; + os_set_time_offset(plat->offset); return old_offset; } @@ -80,7 +81,7 @@ static void reset_time(struct udevice *dev) os_localtime(&now); plat->base_time = rtc_mktime(&now); - plat->offset = 0; + plat->offset = os_get_time_offset(); plat->use_system_time = true; } @@ -115,6 +116,7 @@ static int sandbox_i2c_rtc_set(struct udevice *dev, const struct rtc_time *time) now = plat->base_time; } plat->offset = rtc_mktime(time) - now; + os_set_time_offset(plat->offset); return 0; } diff --git a/include/os.h b/include/os.h index 0913b47b3a..e192e32d59 100644 --- a/include/os.h +++ b/include/os.h @@ -424,4 +424,22 @@ int os_setup_signal_handlers(void); */ void os_signal_action(int sig, unsigned long pc); +/** + * os_get_time_offset() - get time offset + * + * Get the time offset from environment variable UBOOT_SB_TIME_OFFSET. + * + * Return: offset in seconds + */ +long os_get_time_offset(void); + +/** + * os_set_time_offset() - set time offset + * + * Save the time offset in environment variable UBOOT_SB_TIME_OFFSET. + * + * @offset: offset in seconds + */ +void os_set_time_offset(long offset); + #endif