mirror of
https://source.denx.de/u-boot/u-boot.git
synced 2025-11-29 22:51:49 +01:00
sandbox: keep time offset when resetting
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 <xypron.glpk@gmx.de> Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
5e6c9029cd
commit
43db07507a
@ -32,6 +32,9 @@
|
|||||||
#include <os.h>
|
#include <os.h>
|
||||||
#include <rtc_def.h>
|
#include <rtc_def.h>
|
||||||
|
|
||||||
|
/* Environment variable for time offset */
|
||||||
|
#define ENV_TIME_OFFSET "UBOOT_SB_TIME_OFFSET"
|
||||||
|
|
||||||
/* Operating System Interface */
|
/* Operating System Interface */
|
||||||
|
|
||||||
struct os_mem_hdr {
|
struct os_mem_hdr {
|
||||||
@ -798,6 +801,28 @@ int os_spl_to_uboot(const char *fname)
|
|||||||
return os_jump_to_file(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)
|
void os_localtime(struct rtc_time *rt)
|
||||||
{
|
{
|
||||||
time_t t = time(NULL);
|
time_t t = time(NULL);
|
||||||
|
|||||||
@ -131,6 +131,13 @@ available options. Some of these are described below:
|
|||||||
-i
|
-i
|
||||||
Go to interactive mode after executing the commands specified by -c.
|
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
|
Memory Emulation
|
||||||
----------------
|
----------------
|
||||||
|
|
||||||
|
|||||||
@ -57,6 +57,7 @@ long sandbox_i2c_rtc_set_offset(struct udevice *dev, bool use_system_time,
|
|||||||
plat->use_system_time = use_system_time;
|
plat->use_system_time = use_system_time;
|
||||||
if (offset != -1)
|
if (offset != -1)
|
||||||
plat->offset = offset;
|
plat->offset = offset;
|
||||||
|
os_set_time_offset(plat->offset);
|
||||||
|
|
||||||
return old_offset;
|
return old_offset;
|
||||||
}
|
}
|
||||||
@ -80,7 +81,7 @@ static void reset_time(struct udevice *dev)
|
|||||||
|
|
||||||
os_localtime(&now);
|
os_localtime(&now);
|
||||||
plat->base_time = rtc_mktime(&now);
|
plat->base_time = rtc_mktime(&now);
|
||||||
plat->offset = 0;
|
plat->offset = os_get_time_offset();
|
||||||
plat->use_system_time = true;
|
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;
|
now = plat->base_time;
|
||||||
}
|
}
|
||||||
plat->offset = rtc_mktime(time) - now;
|
plat->offset = rtc_mktime(time) - now;
|
||||||
|
os_set_time_offset(plat->offset);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
18
include/os.h
18
include/os.h
@ -424,4 +424,22 @@ int os_setup_signal_handlers(void);
|
|||||||
*/
|
*/
|
||||||
void os_signal_action(int sig, unsigned long pc);
|
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
|
#endif
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user