]>
Commit | Line | Data |
---|---|---|
ced216f8 HL |
1 | /** @file\r |
2 | *\r | |
3 | * Copyright (c) 2014, ARM Ltd. All rights reserved.\r | |
4 | *\r | |
5 | * This program and the accompanying materials are licensed and made available\r | |
6 | * under the terms and conditions of the BSD License which accompanies this\r | |
7 | * distribution. The full text of the license may be found at\r | |
8 | * http://opensource.org/licenses/bsd-license.php\r | |
9 | *\r | |
10 | * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT\r | |
11 | * WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | *\r | |
13 | **/\r | |
14 | \r | |
15 | #include <Library/BaseLib.h>\r | |
16 | #include <Library/BaseMemoryLib.h>\r | |
17 | #include <Library/MemoryAllocationLib.h>\r | |
18 | #include <Library/DebugLib.h>\r | |
19 | #include <Library/UefiLib.h>\r | |
20 | \r | |
21 | #include <Guid/BootMonFsFileInfo.h>\r | |
22 | #include <Protocol/SimpleFileSystem.h> // EFI_FILE_HANDLE\r | |
23 | \r | |
24 | #include "ArmShellCmdRunAxf.h"\r | |
25 | #include "BootMonFsLoader.h"\r | |
26 | \r | |
27 | /**\r | |
28 | Check that loading the file is supported.\r | |
29 | \r | |
30 | Not all information is checked, only the properties that matters to us in\r | |
31 | our simplified loader.\r | |
32 | \r | |
33 | BootMonFS file properties is not in a file header but in the file-system\r | |
34 | metadata, so we need to pass a handle to the file to allow access to the\r | |
35 | information.\r | |
36 | \r | |
37 | @param[in] FileHandle Handle of the file to check.\r | |
38 | \r | |
39 | @retval EFI_SUCCESS on success.\r | |
40 | @retval EFI_INVALID_PARAMETER if the header is invalid.\r | |
41 | @retval EFI_UNSUPPORTED if the file type/platform is not supported.\r | |
42 | **/\r | |
43 | EFI_STATUS\r | |
44 | BootMonFsCheckFile (\r | |
45 | IN CONST EFI_FILE_HANDLE FileHandle\r | |
46 | )\r | |
47 | {\r | |
48 | EFI_STATUS Status;\r | |
49 | BOOTMON_FS_FILE_INFO Info;\r | |
50 | UINTN InfoSize;\r | |
51 | UINTN Index;\r | |
52 | \r | |
53 | ASSERT (FileHandle != NULL);\r | |
54 | \r | |
55 | // Try to load the file information as BootMonFS executable.\r | |
56 | InfoSize = sizeof (Info);\r | |
57 | // Get BootMon File info and see if it gives us what we need to load the file.\r | |
58 | Status = FileHandle->GetInfo (FileHandle, &gArmBootMonFsFileInfoGuid,\r | |
59 | &InfoSize, &Info);\r | |
60 | \r | |
61 | if (!EFI_ERROR (Status)) {\r | |
62 | // Check the values return to see if they look reasonable.\r | |
63 | // Do we have a good entrypoint and at least one good load region?\r | |
64 | // We assume here that we cannot load to address 0x0.\r | |
65 | if ((Info.Size == 0) || (Info.EntryPoint == 0) || (Info.RegionCount == 0) ||\r | |
66 | (Info.RegionCount > BOOTMONFS_IMAGE_DESCRIPTION_REGION_MAX)) {\r | |
67 | // The file does not seem to be of the right type.\r | |
68 | Status = EFI_UNSUPPORTED;\r | |
69 | } else {\r | |
70 | // Check load regions. We just check for valid numbers, we dont do the\r | |
71 | // checksums. Info.Offset can be zero if it loads from the start of the\r | |
72 | // file.\r | |
73 | for (Index = 0; Index < Info.RegionCount; Index++) {\r | |
74 | if ((Info.Region[Index].LoadAddress == 0) || (Info.Region[Index].Size == 0)) {\r | |
75 | Status = EFI_UNSUPPORTED;\r | |
76 | break;\r | |
77 | }\r | |
78 | }\r | |
79 | }\r | |
80 | }\r | |
81 | \r | |
82 | return Status;\r | |
83 | }\r | |
84 | \r | |
85 | /**\r | |
86 | Load a binary file from BootMonFS.\r | |
87 | \r | |
88 | @param[in] FileHandle Handle of the file to load.\r | |
89 | \r | |
90 | @param[in] FileData Address of the file data in memory.\r | |
91 | \r | |
92 | @param[out] EntryPoint Will be filled with the ELF entry point address.\r | |
93 | \r | |
94 | @param[out] ImageSize Will be filled with the file size in memory. This\r | |
95 | will effectively be equal to the sum of the load\r | |
96 | region sizes.\r | |
97 | \r | |
98 | This function assumes the file is valid and supported as checked with\r | |
99 | BootMonFsCheckFile().\r | |
100 | \r | |
101 | @retval EFI_SUCCESS on success.\r | |
102 | @retval EFI_INVALID_PARAMETER if the file is invalid.\r | |
103 | **/\r | |
104 | EFI_STATUS\r | |
105 | BootMonFsLoadFile (\r | |
106 | IN CONST EFI_FILE_HANDLE FileHandle,\r | |
107 | IN CONST VOID *FileData,\r | |
108 | OUT VOID **EntryPoint,\r | |
109 | OUT LIST_ENTRY *LoadList\r | |
110 | )\r | |
111 | {\r | |
112 | EFI_STATUS Status;\r | |
113 | BOOTMON_FS_FILE_INFO Info;\r | |
114 | UINTN InfoSize;\r | |
115 | UINTN Index;\r | |
116 | UINTN ImageSize;\r | |
117 | RUNAXF_LOAD_LIST *LoadNode;\r | |
118 | \r | |
119 | ASSERT (FileHandle != NULL);\r | |
120 | ASSERT (FileData != NULL);\r | |
121 | ASSERT (EntryPoint != NULL);\r | |
122 | ASSERT (LoadList != NULL);\r | |
123 | \r | |
124 | ImageSize = 0;\r | |
125 | \r | |
126 | InfoSize = sizeof (Info);\r | |
127 | Status = FileHandle->GetInfo (FileHandle, &gArmBootMonFsFileInfoGuid,\r | |
128 | &InfoSize, &Info);\r | |
129 | \r | |
130 | if (!EFI_ERROR (Status)) {\r | |
131 | *EntryPoint = (VOID*)((UINTN)Info.EntryPoint);\r | |
132 | // Load all the regions to run-time memory\r | |
133 | for (Index = 0; Index < Info.RegionCount; Index++) {\r | |
134 | LoadNode = AllocateRuntimeZeroPool (sizeof (RUNAXF_LOAD_LIST));\r | |
135 | if (LoadNode == NULL) {\r | |
136 | Status = EFI_OUT_OF_RESOURCES;\r | |
137 | break;\r | |
138 | }\r | |
139 | \r | |
140 | LoadNode->MemOffset = (UINTN)Info.Region[Index].LoadAddress;\r | |
141 | LoadNode->FileOffset = (UINTN)FileData + Info.Region[Index].Offset;\r | |
142 | LoadNode->Length = (UINTN)Info.Region[Index].Size;\r | |
143 | InsertTailList (LoadList, &LoadNode->Link);\r | |
144 | \r | |
145 | ImageSize += LoadNode->Length;\r | |
146 | }\r | |
147 | }\r | |
148 | \r | |
149 | if ((!EFI_ERROR (Status)) && (ImageSize == 0)) {\r | |
150 | Status = EFI_INVALID_PARAMETER;\r | |
151 | }\r | |
152 | \r | |
153 | return Status;\r | |
154 | }\r |