summaryrefslogtreecommitdiffstats
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
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
..
-rw-r--r--memtestEDK/Memtest/ProtocolInformation/Logger.c155
-rw-r--r--test_code/hda-contents/Logger.efibin0 -> 11136 bytes
-rw-r--r--test_code/hda-contents/MemtestEfi.efibin22848 -> 32896 bytes
-rwxr-xr-xtest_code/run.sh3
4 files changed, 86 insertions, 72 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;
}
diff --git a/test_code/hda-contents/Logger.efi b/test_code/hda-contents/Logger.efi
new file mode 100644
index 0000000..d1c1756
--- /dev/null
+++ b/test_code/hda-contents/Logger.efi
Binary files differ
diff --git a/test_code/hda-contents/MemtestEfi.efi b/test_code/hda-contents/MemtestEfi.efi
index 587a742..27a715b 100644
--- a/test_code/hda-contents/MemtestEfi.efi
+++ b/test_code/hda-contents/MemtestEfi.efi
Binary files differ
diff --git a/test_code/run.sh b/test_code/run.sh
index 3f9820a..6779ae2 100755
--- a/test_code/run.sh
+++ b/test_code/run.sh
@@ -5,7 +5,8 @@ applications=( "ConfigurationTable.efi"\
"GetRootSystemDescriptionPointer.efi"\
"TextOutput.efi"\
"ProtocolInformation.efi"\
- "doTest1.efi"
+ "doTest1.efi"\
+ "Logger.efi"
)
for app in "${applications[@]}"