[haiku-commits] haiku: hrev54806 - src/system/boot/platform/openfirmware

  • From: Adrien Destugues <pulkomandy@xxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 22 Dec 2020 13:40:14 -0500 (EST)

hrev54806 adds 1 changeset to branch 'master'
old head: acd5d4fddfa301317ea8114db4bce9fc3983790c
new head: e050005a07d239ebc4e1a9a73ac27215349b7d8c
overview: 
https://git.haiku-os.org/haiku/log/?qt=range&q=e050005a07d2+%5Eacd5d4fddfa3

----------------------------------------------------------------------------

e050005a07d2: Revert "openfirmware: remove real_time_clock."
  
  This reverts commit 4e134b546a253168f986914ae9c08344d1a75d1a.
  
  It breaks bootloader build on powerpc.

                             [ Adrien Destugues <pulkomandy@xxxxxxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev54806
Commit:      e050005a07d239ebc4e1a9a73ac27215349b7d8c
URL:         https://git.haiku-os.org/haiku/commit/?id=e050005a07d2
Author:      Adrien Destugues <pulkomandy@xxxxxxxxxxxxx>
Date:        Tue Dec 22 18:37:43 2020 UTC

----------------------------------------------------------------------------

4 files changed, 86 insertions(+)
src/system/boot/platform/openfirmware/Jamfile    |  1 +
.../platform/openfirmware/real_time_clock.cpp    | 57 ++++++++++++++++++++
.../boot/platform/openfirmware/real_time_clock.h | 24 +++++++++
src/system/boot/platform/openfirmware/start.cpp  |  4 ++

----------------------------------------------------------------------------

diff --git a/src/system/boot/platform/openfirmware/Jamfile 
b/src/system/boot/platform/openfirmware/Jamfile
index 3a740de1b8..33d8e1439e 100644
--- a/src/system/boot/platform/openfirmware/Jamfile
+++ b/src/system/boot/platform/openfirmware/Jamfile
@@ -21,6 +21,7 @@ local platform_src =
        menu.cpp
        mmu.cpp
        network.cpp
+       real_time_clock.cpp
        start.cpp
        support.cpp
        video.cpp
diff --git a/src/system/boot/platform/openfirmware/real_time_clock.cpp 
b/src/system/boot/platform/openfirmware/real_time_clock.cpp
new file mode 100644
index 0000000000..fb91a6686b
--- /dev/null
+++ b/src/system/boot/platform/openfirmware/real_time_clock.cpp
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2006, Ingo Weinhold <bonefish@xxxxxxxxxxxxxxx>.
+ * Copyright 2010, Andreas Färber <andreas.faerber@xxxxxx>
+ * All rights reserved. Distributed under the terms of the MIT License.
+ */
+
+
+#include "real_time_clock.h"
+
+#include <stdio.h>
+
+#include <boot/kernel_args.h>
+#include <boot/stage2.h>
+#include <platform/openfirmware/devices.h>
+#include <platform/openfirmware/openfirmware.h>
+
+
+static int sHandle = OF_FAILED;
+
+
+status_t
+init_real_time_clock(void)
+{
+       // find RTC
+       intptr_t rtcCookie = 0;
+       if (of_get_next_device(&rtcCookie, 0, "rtc",
+                       gKernelArgs.platform_args.rtc_path,
+                       sizeof(gKernelArgs.platform_args.rtc_path)) != B_OK) {
+               printf("init_real_time_clock(): Found no RTC device!");
+               return B_ERROR;
+       }
+
+       sHandle = of_open(gKernelArgs.platform_args.rtc_path);
+       if (sHandle == OF_FAILED) {
+               printf("%s(): Could not open RTC device!\n", __func__);
+               return B_ERROR;
+       }
+
+       return B_OK;
+}
+
+
+bigtime_t
+real_time_clock_usecs(void)
+{
+       if (sHandle == OF_FAILED)
+               return OF_FAILED;
+       int second, minute, hour, day, month, year;
+       if (of_call_method(sHandle, "get-time", 0, 6, &year, &month, &day,
+                       &hour, &minute, &second) == OF_FAILED)
+               return OF_FAILED;
+       int days = day;
+               // TODO: Apply algorithm from kernel
+               // to assure monotonically increasing date.
+       return (((days * 24 + hour) * 60ULL + minute) * 60ULL + second)
+               * 1000000ULL;
+}
diff --git a/src/system/boot/platform/openfirmware/real_time_clock.h 
b/src/system/boot/platform/openfirmware/real_time_clock.h
new file mode 100644
index 0000000000..8262be4234
--- /dev/null
+++ b/src/system/boot/platform/openfirmware/real_time_clock.h
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2006, Ingo Weinhold <bonefish@xxxxxxxxxxxxxxx>.
+ * Copyright 2010, Andreas Färber <andreas.faerber@xxxxxx>
+ * All rights reserved. Distributed under the terms of the MIT License.
+ */
+#ifndef OPENFIRMWARE_REAL_TIME_CLOCK_H
+#define OPENFIRMWARE_REAL_TIME_CLOCK_H
+
+
+#include <SupportDefs.h>
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+status_t init_real_time_clock(void);
+bigtime_t real_time_clock_usecs(void);
+
+#ifdef __cplusplus
+}   // extern "C"
+#endif
+
+#endif /* OPENFIRMWARE_REAL_TIME_CLOCK_H */
diff --git a/src/system/boot/platform/openfirmware/start.cpp 
b/src/system/boot/platform/openfirmware/start.cpp
index fb267eff0c..e49398efdd 100644
--- a/src/system/boot/platform/openfirmware/start.cpp
+++ b/src/system/boot/platform/openfirmware/start.cpp
@@ -20,6 +20,7 @@
 
 #include "console.h"
 #include "machine.h"
+#include "real_time_clock.h"
 
 
 #define HEAP_SIZE 65536
@@ -125,6 +126,9 @@ start(void *openFirmwareEntry)
        if (boot_arch_cpu_init() != B_OK)
                of_exit();
 
+       if (init_real_time_clock() != B_OK)
+               of_exit();
+
        // check for key presses once
        sBootOptions = 0;
        int key = console_check_for_key();


Other related posts:

  • » [haiku-commits] haiku: hrev54806 - src/system/boot/platform/openfirmware - Adrien Destugues