diff mbox

[U-Boot,11/20] dm: sandbox: Add os_localtime() to obtain the system time

Message ID 1429555051-22335-12-git-send-email-sjg@chromium.org
State Accepted
Delegated to: Simon Glass
Headers show

Commit Message

Simon Glass April 20, 2015, 6:37 p.m. UTC
Add a function to read the system time into U-Boot.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 arch/sandbox/cpu/os.c | 18 ++++++++++++++++++
 include/os.h          | 11 +++++++++++
 2 files changed, 29 insertions(+)

Comments

Simon Glass May 4, 2015, 2:20 p.m. UTC | #1
On 20 April 2015 at 12:37, Simon Glass <sjg@chromium.org> wrote:
> Add a function to read the system time into U-Boot.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>  arch/sandbox/cpu/os.c | 18 ++++++++++++++++++
>  include/os.h          | 11 +++++++++++
>  2 files changed, 29 insertions(+)

Applied to u-boot-dm.
diff mbox

Patch

diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
index 4d5f805..e6dd17e 100644
--- a/arch/sandbox/cpu/os.c
+++ b/arch/sandbox/cpu/os.c
@@ -24,6 +24,7 @@ 
 #include <asm/sections.h>
 #include <asm/state.h>
 #include <os.h>
+#include <rtc_def.h>
 
 /* Operating System Interface */
 
@@ -537,3 +538,20 @@  int os_jump_to_image(const void *dest, int size)
 
 	return unlink(fname);
 }
+
+void os_localtime(struct rtc_time *rt)
+{
+	time_t t = time(NULL);
+	struct tm *tm;
+
+	tm = localtime(&t);
+	rt->tm_sec = tm->tm_sec;
+	rt->tm_min = tm->tm_min;
+	rt->tm_hour = tm->tm_hour;
+	rt->tm_mday = tm->tm_mday;
+	rt->tm_mon = tm->tm_mon + 1;
+	rt->tm_year = tm->tm_year + 1900;
+	rt->tm_wday = tm->tm_wday;
+	rt->tm_yday = tm->tm_yday;
+	rt->tm_isdst = tm->tm_isdst;
+}
diff --git a/include/os.h b/include/os.h
index a758f09..ffbdce8 100644
--- a/include/os.h
+++ b/include/os.h
@@ -13,6 +13,7 @@ 
 
 #include <linux/types.h>
 
+struct rtc_time;
 struct sandbox_state;
 
 /**
@@ -277,4 +278,14 @@  int os_read_ram_buf(const char *fname);
  */
 int os_jump_to_image(const void *dest, int size);
 
+/**
+ * Read the current system time
+ *
+ * This reads the current Local Time and places it into the provided
+ * structure.
+ *
+ * @param rt		Place to put system time
+ */
+void os_localtime(struct rtc_time *rt);
+
 #endif