* [PATCH] efi: loader: fix year and month reported by GetTime
@ 2026-08-25 8:52 Ahmad Fatoum
2026-08-28 13:03 ` Sascha Hauer
0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2026-08-25 8:52 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
struct rtc_time follows the Linux convention: tm_year counts from 1900
and tm_mon is zero based. EFI_TIME on the other hand carries the full
year and a one based month.
efi_get_time_boottime() copied both fields over unchanged, so GetTime()
reported year 126 and month 6 for July 2026.
efi_set_time_boottime() has the mirrored problem. rtc_valid_tm() accepts
the result, since it only rejects tm_year below 70 and tm_mon of 12 or
more, so rtc_tm_to_time() goes on to compute
mktime(time->year + 1900, time->month + 1, ...) and the RTC is set
roughly 1900 years and one month ahead.
Convert in both directions.
Assisted-by: Codex:gpt-5.5
Fixes: 06947fd4664c ("efi: loader: add support for runtime services before ExitBootServices")
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
efi/loader/runtime.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/efi/loader/runtime.c b/efi/loader/runtime.c
index f0fbd263fe55..024d402b3915 100644
--- a/efi/loader/runtime.c
+++ b/efi/loader/runtime.c
@@ -173,8 +173,8 @@ static efi_status_t EFIAPI efi_get_time_boottime(
}
memset(time, 0, sizeof(*time));
- time->year = tm.tm_year;
- time->month = tm.tm_mon;
+ time->year = tm.tm_year + 1900;
+ time->month = tm.tm_mon + 1;
time->day = tm.tm_mday;
time->hour = tm.tm_hour;
time->minute = tm.tm_min;
@@ -257,8 +257,8 @@ static efi_status_t EFIAPI efi_set_time_boottime(struct efi_time *time)
}
memset(&tm, 0, sizeof(tm));
- tm.tm_year = time->year;
- tm.tm_mon = time->month;
+ tm.tm_year = time->year - 1900;
+ tm.tm_mon = time->month - 1;
tm.tm_mday = time->day;
tm.tm_hour = time->hour;
tm.tm_min = time->minute;
--
2.47.3
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-08-28 13:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-25 8:52 [PATCH] efi: loader: fix year and month reported by GetTime Ahmad Fatoum
2026-08-28 13:03 ` Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox