summaryrefslogtreecommitdiffstats
path: root/memtestEDK
diff options
context:
space:
mode:
authorRegina König2020-08-21 14:34:53 +0200
committerRegina König2020-08-21 14:34:53 +0200
commitdf7830bcecedf481f76f2f63fc6020e7bc7ae3c7 (patch)
treee33470b9180c30c80110895f6eb6c1a888fad971 /memtestEDK
parentcreated Logger.c. It's structure should be the final version for use in memtest (diff)
downloadmemtest86-df7830bcecedf481f76f2f63fc6020e7bc7ae3c7.tar.gz
memtest86-df7830bcecedf481f76f2f63fc6020e7bc7ae3c7.tar.xz
memtest86-df7830bcecedf481f76f2f63fc6020e7bc7ae3c7.zip
..
Diffstat (limited to 'memtestEDK')
-rw-r--r--memtestEDK/Memtest/ProtocolInformation/Logger.c155
1 files changed, 84 insertions, 71 deletions
diff --git a/memtestEDK/Memtest/ProtocolInformation/Logger.c b/memtestEDK/Memtest/ProtocolInformation/Logger.c
index 8f448c5..d41f7e5 100644
--- a/memtestEDK/Memtest/ProtocolInformation/Logger.c
+++ b/memtestEDK/Memtest/ProtocolInformation/Logger.c
@@ -32,6 +32,9 @@ EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfo;
UINTN OpenInfoIndex;
UINTN OpenInfoCount;
+EFI_FILE_PROTOCOL* root = NULL;
+EFI_FILE_SYSTEM_INFO* fileSystemInfo = NULL;
+
void printFileSystemInfo(EFI_FILE_SYSTEM_INFO* fileSystemInfo) {
Print(L"fileSystemInfo pointer %p\n", fileSystemInfo);
@@ -75,6 +78,79 @@ BOOLEAN compareGuids(EFI_GUID* sfspGuid, EFI_GUID* guid) {
return FALSE;
}
+EFI_STATUS writeToFile() {
+
+ EFI_FILE_PROTOCOL* token = NULL;
+ efiStatus = root->Open(
+ root,
+ &token,
+ L"memtest_log",
+ EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE,
+ 0);
+ checkStatus(efiStatus, "Open");
+
+ UINT64 currPos;
+ efiStatus = token->GetPosition(token, &currPos);
+ checkStatus(efiStatus, "GetPosition");
+ Print(L"Current File Position: %d\n", currPos);
+
+ UINTN fileSize; // TODO get the actual size
+ CHAR16* fileBuffer = NULL;
+
+ efiStatus = token->Read(token, &fileSize, fileBuffer);
+ checkStatus(efiStatus, "Read");
+
+ Print(L"FILE SIZE: %d\n", fileSize);
+
+ fileSize += 80;
+ efiStatus = bs->AllocatePool(EfiLoaderData, (UINTN) (fileSize) , (void **)&fileBuffer);
+ checkStatus(efiStatus, "AllocatePool for file");
+
+ Print(L"FILE SIZE2: %d\n", fileSize);
+
+ efiStatus = token->Read(token, &fileSize, fileBuffer);
+ checkStatus(efiStatus, "Read");
+ printFileContent(fileSize, fileBuffer);
+
+ efiStatus = token->GetPosition(token, &currPos);
+ checkStatus(efiStatus, "GetPosition");
+ Print(L"Current File Position: %d\n", currPos);
+
+ char message[] = "\nAdding a new line";
+ UINTN length = 19;
+ UINTN sizeBytes = sizeof(message);
+ Print(L"size in bytes: %d\n", sizeBytes);
+ Print(L"Lengh: %d\n", length);
+
+ if (fileSize >=1) {
+ token->SetPosition(token, fileSize);
+ }
+
+ efiStatus = token->Write(token, &length, message);
+ checkStatus(efiStatus, "Write");
+
+ fileSize += length;
+
+ token->SetPosition(token, 0);
+
+ efiStatus = token->Read(token, &fileSize, fileBuffer);
+ printFileContent(fileSize, fileBuffer);
+
+ if (fileBuffer != NULL) {
+ bs->FreePool(fileBuffer);
+ }
+
+ if (fileSystemInfo != NULL) {
+ bs->FreePool(fileSystemInfo);
+ }
+
+ efiStatus = token->Close(token);
+ checkStatus(efiStatus, "Close");
+
+ return efiStatus;
+}
+
+
EFI_STATUS
EFIAPI
UefiMain (
@@ -86,14 +162,13 @@ UefiMain (
Console = SystemTable->ConOut;
//
- // Get all Handles
+ // Get all Handles containing the EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID
//
- efiStatus = bs->LocateHandleBuffer (
- AllHandles,
- NULL,
- NULL,
- &handleCount,
- &handleBuffer
+ efiStatus = bs->LocateHandleBuffer(ByProtocol,
+ &sfspGuid,
+ NULL,
+ &handleCount,
+ &handleBuffer
);
checkStatus(efiStatus, "LocateHandleBuffer");
@@ -150,13 +225,11 @@ UefiMain (
);
checkStatus(efiStatus, "HandleProtocol");
- EFI_FILE_PROTOCOL* root = NULL;
efiStatus = fs->OpenVolume(fs, &root);
checkStatus(efiStatus, "OpenVolume");
EFI_GUID fsiGuid = EFI_FILE_SYSTEM_INFO_ID;
UINTN bufSize = 0;
- EFI_FILE_SYSTEM_INFO* fileSystemInfo = NULL;
// First time it is expected to fail
efiStatus = root->GetInfo(
root,
@@ -176,73 +249,13 @@ UefiMain (
//printFileSystemInfo(fileSystemInfo);
// TODO first check if it is the right filesystem. If yes, leave the for loop
-
- EFI_FILE_PROTOCOL* token = NULL;
- efiStatus = root->Open(
- root,
- &token,
- L"memtest_log",
- EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE,
- 0);
- checkStatus(efiStatus, "Open");
-
- UINT64 currPos;
- efiStatus = token->GetPosition(token, &currPos);
- checkStatus(efiStatus, "GetPosition");
- Print(L"Current File Position: %d\n", currPos);
-
- UINTN fileSize = 500; // TODO get the actual size
- CHAR16* fileBuffer = NULL;
- efiStatus = bs->AllocatePool(EfiLoaderData, (UINTN) (fileSize) , (void **)&fileBuffer);
- checkStatus(efiStatus, "AllocatePool for file");
-
- efiStatus = token->Read(token, &fileSize, fileBuffer);
- checkStatus(efiStatus, "Read");
- printFileContent(fileSize, fileBuffer);
-
- efiStatus = token->GetPosition(token, &currPos);
- checkStatus(efiStatus, "GetPosition");
- Print(L"Current File Position: %d\n", currPos);
-
- char *message = "\nAdding a new line";
- UINTN length = 19;
- Print(L"Lengh: %d\n", length);
-
- if (fileSize >=1) {
- token->SetPosition(token, fileSize - 1);
- }
-
- efiStatus = token->Write(token, &length, message);
- checkStatus(efiStatus, "Write");
-
- fileSize += length;
-
- token->SetPosition(token, 0);
-
- efiStatus = token->Read(token, &fileSize, fileBuffer);
- printFileContent(fileSize, fileBuffer);
-
- if (fileBuffer != NULL) {
- bs->FreePool(fileBuffer);
- }
-
- if (fileSystemInfo != NULL) {
- bs->FreePool(fileSystemInfo);
- }
+ break;
} // end if (compareGuids(&sfspGuid, guid))
} // end for (ProtocolIndex = 0; ProtocolIndex < ArrayCount; ProtocolIndex++)
} // end "for (handleIndex = 0; handleIndex < handleCount; handleIndex++)"
-
- efiStatus = bs->LocateHandleBuffer(ByProtocol,
- &sfspGuid,
- NULL,
- &handleCount2,
- &handleBuffer2);
-
- Print(L"Handle count2: %d\n", handleCount2);
-
+ efiStatus = writeToFile();
return EFI_SUCCESS;
}