From 453acba7dc4b34fa3814755671755e2601a9059d Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Sat, 19 Apr 2025 13:35:23 +0100 Subject: [PATCH] [time] Use currticks() to provide the null system time For platforms with no real-time clock (such as RISC-V SBI) we use the null time source, which currently just returns a constant zero. Switch to using currticks() to provide a clock that does not represent the real current time, but does at least advance at approximately the correct rate. In conjunction with the "ntp" command, this allows these platforms to use time-dependent features such as X.509 certificate verification for HTTPS connections. Signed-off-by: Michael Brown --- src/core/null_time.c | 14 +++++++++++++- src/include/ipxe/null_time.h | 5 ----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/core/null_time.c b/src/core/null_time.c index 90041a456..15d8a57a5 100644 --- a/src/core/null_time.c +++ b/src/core/null_time.c @@ -30,5 +30,17 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); */ #include +#include -PROVIDE_TIME_INLINE ( null, time_now ); +/** + * Get current time in seconds + * + * @ret time Time, in seconds + */ +static time_t null_now ( void ) { + + /* Provide a non-absolute timer bassed on currticks() */ + return ( currticks() / TICKS_PER_SEC ); +} + +PROVIDE_TIME ( null, time_now, null_now ); diff --git a/src/include/ipxe/null_time.h b/src/include/ipxe/null_time.h index d2b15194b..c670a5fce 100644 --- a/src/include/ipxe/null_time.h +++ b/src/include/ipxe/null_time.h @@ -15,9 +15,4 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #define TIME_PREFIX_null __null_ #endif -static inline __always_inline time_t -TIME_INLINE ( null, time_now ) ( void ) { - return 0; -} - #endif /* _IPXE_NULL_TIME_H */