Support a Semi Host file system over a debuggers JTAG\r
\r
Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
- \r
+ Portions copyright (c) 2011, 2012, ARM Ltd. All rights reserved.<BR>\r
+\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
EFI_FILE File;\r
CHAR8 *FileName;\r
UINT32 Position;\r
- UINT32 SemihostHandle;\r
+ UINTN SemihostHandle;\r
BOOLEAN IsRoot;\r
} SEMIHOST_FCB;\r
\r
{\r
SEMIHOST_FCB *FileFcb = NULL;\r
EFI_STATUS Status = EFI_SUCCESS;\r
- UINT32 SemihostHandle;\r
+ UINTN SemihostHandle;\r
CHAR8 *AsciiFileName;\r
- CHAR8 *AsciiPtr;\r
- UINTN Length;\r
UINT32 SemihostMode;\r
BOOLEAN IsRoot;\r
\r
return EFI_INVALID_PARAMETER;\r
}\r
\r
- // Semihost interface requires ASCII filesnames\r
- Length = StrSize (FileName);\r
-\r
- AsciiFileName = AllocatePool (Length);\r
+ // Semihost interface requires ASCII filenames\r
+ AsciiFileName = AllocatePool ((StrLen (FileName) + 1) * sizeof (CHAR8));\r
if (AsciiFileName == NULL) {\r
return EFI_OUT_OF_RESOURCES;\r
}\r
+ UnicodeStrToAsciiStr (FileName, AsciiFileName);\r
\r
- AsciiPtr = AsciiFileName;\r
-\r
- while (Length--) {\r
- *AsciiPtr++ = *FileName++ & 0xFF;\r
- }\r
-\r
- if ((AsciiStrCmp (AsciiFileName, "\\") == 0) || (AsciiStrCmp (AsciiFileName, "/") == 0) || (AsciiStrCmp (AsciiFileName, "") == 0)) {\r
- // Opening '/', '\', or the NULL pathname is trying to open the root directory\r
+ if ((AsciiStrCmp (AsciiFileName, "\\") == 0) ||\r
+ (AsciiStrCmp (AsciiFileName, "/") == 0) ||\r
+ (AsciiStrCmp (AsciiFileName, "") == 0) ||\r
+ (AsciiStrCmp (AsciiFileName, ".") == 0)) {\r
+ // Opening '/', '\', '.', or the NULL pathname is trying to open the root directory\r
IsRoot = TRUE;\r
\r
// Root directory node doesn't have a name.\r
\r
Fcb = SEMIHOST_FCB_FROM_THIS(File);\r
\r
- // Get the filename from the Fcb\r
- NameSize = AsciiStrLen (Fcb->FileName);\r
- FileName = AllocatePool (NameSize + 1);\r
+ if (!Fcb->IsRoot) {\r
+ // Get the filename from the Fcb\r
+ NameSize = AsciiStrLen (Fcb->FileName);\r
+ FileName = AllocatePool (NameSize + 1);\r
\r
- AsciiStrCpy (FileName, Fcb->FileName);\r
+ AsciiStrCpy (FileName, Fcb->FileName);\r
\r
- // Close the file if it's open. Disregard return status,\r
- // since it might give an error if the file isn't open.\r
- File->Close (File);\r
- \r
- // Call the semihost interface to delete the file.\r
- Status = SemihostFileRemove (FileName);\r
+ // Close the file if it's open. Disregard return status,\r
+ // since it might give an error if the file isn't open.\r
+ File->Close (File);\r
+\r
+ // Call the semihost interface to delete the file.\r
+ Status = SemihostFileRemove (FileName);\r
+ } else {\r
+ Status = EFI_UNSUPPORTED;\r
+ }\r
\r
return Status;\r
}\r
)\r
{\r
SEMIHOST_FCB *Fcb = NULL;\r
- UINT32 Length;\r
+ UINTN Length;\r
EFI_STATUS Status;\r
\r
Fcb = SEMIHOST_FCB_FROM_THIS(File);\r
\r
- Status = SemihostFileLength (Fcb->SemihostHandle, &Length);\r
- if (!EFI_ERROR(Status) && (Length < Position)) {\r
- Position = Length;\r
- }\r
+ if (!Fcb->IsRoot) {\r
+ Status = SemihostFileLength (Fcb->SemihostHandle, &Length);\r
+ if (!EFI_ERROR(Status) && (Length < Position)) {\r
+ Position = Length;\r
+ }\r
\r
- Status = SemihostFileSeek (Fcb->SemihostHandle, (UINT32)Position);\r
- if (!EFI_ERROR(Status)) {\r
+ Status = SemihostFileSeek (Fcb->SemihostHandle, (UINT32)Position);\r
+ if (!EFI_ERROR(Status)) {\r
+ Fcb->Position = Position;\r
+ }\r
+ } else {\r
Fcb->Position = Position;\r
+ Status = EFI_SUCCESS;\r
}\r
\r
return Status;\r
UINTN NameSize = 0;\r
UINTN ResultSize;\r
UINTN Index;\r
- UINT32 Length;\r
+ UINTN Length;\r
EFI_STATUS Status;\r
\r
if (Fcb->IsRoot == TRUE) {\r