OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
RtcRw.c
Go to the documentation of this file.
1
15#include <Uefi.h>
16#include <Library/BaseMemoryLib.h>
18#include <Library/MemoryAllocationLib.h>
20#include <Library/OcMiscLib.h>
21#include <Library/OcRtcLib.h>
22#include <Library/OcStringLib.h>
23#include <Library/UefiApplicationEntryPoint.h>
24#include <Library/UefiBootServicesTableLib.h>
25#include <Library/UefiLib.h>
26
27EFI_STATUS
28EFIAPI
30 IN EFI_HANDLE ImageHandle,
31 IN EFI_SYSTEM_TABLE *SystemTable
32 )
33{
34 EFI_STATUS Status;
35 UINTN Argc;
36 CHAR16 **Argv;
37 UINTN Addr;
38 UINTN Value;
39 UINTN Index;
40 UINT8 Rtc[256];
41
42 gBS->SetWatchdogTimer (0, 0, 0, NULL);
43
44 OcProvideConsoleGop (FALSE);
45
47
48 OcSetConsoleResolution (0, 0, 0, FALSE);
49
50 Status = GetArguments (&Argc, &Argv);
51 if (!EFI_ERROR (Status) && (Argc >= 2)) {
52 if ((OcStriCmp (Argv[1], L"dump") == 0) && (Argc == 2)) {
53 for (Index = 0; Index < ARRAY_SIZE (Rtc); ++Index) {
54 Rtc[Index] = OcRtcRead ((UINT8)Index);
55 }
56
57 for (Index = 0; Index < ARRAY_SIZE (Rtc); Index += 16) {
58 Print (
59 L"%02Xh: %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\n",
60 Index,
61 Rtc[Index+0],
62 Rtc[Index+1],
63 Rtc[Index+2],
64 Rtc[Index+3],
65 Rtc[Index+4],
66 Rtc[Index+5],
67 Rtc[Index+6],
68 Rtc[Index+7],
69 Rtc[Index+8],
70 Rtc[Index+9],
71 Rtc[Index+10],
72 Rtc[Index+11],
73 Rtc[Index+12],
74 Rtc[Index+13],
75 Rtc[Index+14],
76 Rtc[Index+15]
77 );
78 }
79
80 return EFI_SUCCESS;
81 }
82
83 if ((OcStriCmp (Argv[1], L"read") == 0) && (Argc == 3)) {
84 Status = StrHexToUintnS (Argv[2], NULL, &Addr);
85 if (EFI_ERROR (Status) || (Addr > 0xFF)) {
86 Print (L"Invalid addr %LX - %r\n", (UINT64)Addr, Status);
87 return EFI_SUCCESS;
88 }
89
90 Print (L"Rtc[0x%Xh] = 0x%02X\n", (UINT32)Addr, OcRtcRead ((UINT8)Addr));
91 return EFI_SUCCESS;
92 }
93
94 if ((OcStriCmp (Argv[1], L"write") == 0) && (Argc == 4)) {
95 Status = StrHexToUintnS (Argv[2], NULL, &Addr);
96 if (EFI_ERROR (Status) || (Addr > 0xFF)) {
97 Print (L"Invalid addr %LX - %r\n", (UINT64)Addr, Status);
98 return EFI_SUCCESS;
99 }
100
101 Status = StrHexToUintnS (Argv[3], NULL, &Value);
102 if (EFI_ERROR (Status) || (Value > 0xFF)) {
103 Print (L"Invalid value %LX - %r\n", (UINT64)Value, Status);
104 return EFI_SUCCESS;
105 }
106
107 Print (
108 L"Rtc[0x%X] = 0x%02X -> 0x%02X\n",
109 (UINT32)Addr,
110 OcRtcRead ((UINT8)Addr),
111 (UINT8)Value
112 );
113 OcRtcWrite ((UINT8)Addr, (UINT8)Value);
114 return EFI_SUCCESS;
115 }
116 }
117
118 Print (L"Usage: RtcRw <dump|read|write> <addr> <value>\n");
119 return EFI_SUCCESS;
120}
#define ARRAY_SIZE(Array)
Definition AppleMacEfi.h:34
@ EfiConsoleControlScreenText
EFI_BOOT_SERVICES * gBS
EFI_CONSOLE_CONTROL_SCREEN_MODE OcConsoleControlSetMode(IN EFI_CONSOLE_CONTROL_SCREEN_MODE Mode)
EFI_STATUS OcSetConsoleResolution(IN UINT32 Width OPTIONAL, IN UINT32 Height OPTIONAL, IN UINT32 Bpp OPTIONAL, IN BOOLEAN Force)
EFI_STATUS OcProvideConsoleGop(IN BOOLEAN Route)
Definition ConsoleGop.c:81
EFI_STATUS GetArguments(OUT UINTN *Argc, OUT CHAR16 ***Argv)
UINT8 OcRtcRead(IN UINT8 Offset)
Definition OcRtcLib.c:25
VOID OcRtcWrite(IN UINT8 Offset, IN UINT8 Value)
Definition OcRtcLib.c:47
INTN EFIAPI OcStriCmp(IN CONST CHAR16 *FirstString, IN CONST CHAR16 *SecondString)
EFI_STATUS EFIAPI UefiMain(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition RtcRw.c:29