1 /** @file 2 A shell application that triggers capsule update process. 3 4 Copyright (c) 2019, Intel Corporation. All rights reserved.<BR> 5 SPDX-License-Identifier: BSD-2-Clause-Patent 6 7 **/ 8 9 10 #ifndef _CAPSULE_APP_H_ 11 #define _CAPSULE_APP_H_ 12 13 #include <Uefi.h> 14 #include <Library/BaseLib.h> 15 #include <Library/DebugLib.h> 16 #include <Library/BaseMemoryLib.h> 17 #include <Library/MemoryAllocationLib.h> 18 #include <Library/UefiBootServicesTableLib.h> 19 #include <Library/UefiRuntimeServicesTableLib.h> 20 #include <Library/UefiLib.h> 21 #include <Library/PrintLib.h> 22 #include <Library/BmpSupportLib.h> 23 #include <Library/FileHandleLib.h> 24 #include <Library/SortLib.h> 25 #include <Library/UefiBootManagerLib.h> 26 #include <Library/DevicePathLib.h> 27 #include <Protocol/GraphicsOutput.h> 28 #include <Protocol/SimpleFileSystem.h> 29 #include <Protocol/ShellParameters.h> 30 #include <Protocol/Shell.h> 31 #include <Protocol/FirmwareManagement.h> 32 #include <Guid/GlobalVariable.h> 33 #include <Guid/CapsuleReport.h> 34 #include <Guid/SystemResourceTable.h> 35 #include <Guid/FmpCapsule.h> 36 #include <Guid/FileInfo.h> 37 #include <Guid/ImageAuthentication.h> 38 #include <Guid/CapsuleVendor.h> 39 #include <Guid/Gpt.h> 40 #include <IndustryStandard/WindowsUxCapsule.h> 41 42 #define CAPSULE_HEADER_SIZE 0x20 43 44 #define NESTED_CAPSULE_HEADER_SIZE SIZE_4KB 45 #define SYSTEM_FIRMWARE_FLAG 0x50000 46 #define DEVICE_FIRMWARE_FLAG 0x78010 47 48 #define MAJOR_VERSION 1 49 #define MINOR_VERSION 0 50 51 #define MAX_CAPSULE_NUM 10 52 53 // 54 // (20 * (6+5+2))+1) unicode characters from EFI FAT spec (doubled for bytes) 55 // 56 #define MAX_FILE_NAME_SIZE 522 57 #define MAX_FILE_NAME_LEN (MAX_FILE_NAME_SIZE / sizeof(CHAR16)) 58 59 extern UINTN Argc; 60 extern CHAR16 **Argv; 61 62 /** 63 64 This function parse application ARG. 65 66 @return Status 67 **/ 68 EFI_STATUS 69 GetArg ( 70 VOID 71 ); 72 73 /** 74 Get shell protocol. 75 76 @return Pointer to shell protocol. 77 78 **/ 79 EFI_SHELL_PROTOCOL * 80 GetShellProtocol ( 81 VOID 82 ); 83 84 85 /** 86 Read a file. 87 88 @param[in] FileName The file to be read. 89 @param[out] BufferSize The file buffer size 90 @param[out] Buffer The file buffer 91 92 @retval EFI_SUCCESS Read file successfully 93 @retval EFI_NOT_FOUND Shell protocol or file not found 94 @retval others Read file failed 95 **/ 96 EFI_STATUS 97 ReadFileToBuffer ( 98 IN CHAR16 *FileName, 99 OUT UINTN *BufferSize, 100 OUT VOID **Buffer 101 ); 102 103 /** 104 Write a file. 105 106 @param[in] FileName The file to be written. 107 @param[in] BufferSize The file buffer size 108 @param[in] Buffer The file buffer 109 110 @retval EFI_SUCCESS Write file successfully 111 @retval EFI_NOT_FOUND Shell protocol not found 112 @retval others Write file failed 113 **/ 114 EFI_STATUS 115 WriteFileFromBuffer ( 116 IN CHAR16 *FileName, 117 IN UINTN BufferSize, 118 IN VOID *Buffer 119 ); 120 121 122 /** 123 Dump capsule information 124 125 @param[in] CapsuleName The name of the capsule image. 126 127 @retval EFI_SUCCESS The capsule information is dumped. 128 @retval EFI_UNSUPPORTED Input parameter is not valid. 129 **/ 130 EFI_STATUS 131 DumpCapsule ( 132 IN CHAR16 *CapsuleName 133 ); 134 135 /** 136 Dump capsule status variable. 137 138 @retval EFI_SUCCESS The capsule status variable is dumped. 139 @retval EFI_UNSUPPORTED Input parameter is not valid. 140 **/ 141 EFI_STATUS 142 DumpCapsuleStatusVariable ( 143 VOID 144 ); 145 146 /** 147 Dump FMP protocol info. 148 **/ 149 VOID 150 DumpFmpData ( 151 VOID 152 ); 153 154 /** 155 Dump FMP image data. 156 157 @param[in] ImageTypeId The ImageTypeId of the FMP image. 158 It is used to identify the FMP protocol. 159 @param[in] ImageIndex The ImageIndex of the FMP image. 160 It is the input parameter for FMP->GetImage(). 161 @param[in] ImageName The file name to hold the output FMP image. 162 **/ 163 VOID 164 DumpFmpImage ( 165 IN EFI_GUID *ImageTypeId, 166 IN UINTN ImageIndex, 167 IN CHAR16 *ImageName 168 ); 169 170 /** 171 Dump ESRT info. 172 **/ 173 VOID 174 DumpEsrtData ( 175 VOID 176 ); 177 178 /** 179 Dump Provisioned Capsule. 180 181 @param[in] DumpCapsuleInfo The flag to indicate whether to dump the capsule inforomation. 182 **/ 183 VOID 184 DumpProvisionedCapsule ( 185 IN BOOLEAN DumpCapsuleInfo 186 ); 187 188 /** 189 Dump all EFI System Partition. 190 **/ 191 VOID 192 DumpAllEfiSysPartition ( 193 VOID 194 ); 195 196 197 /** 198 Get SimpleFileSystem from boot option file path. 199 200 @param[in] DevicePath The file path of boot option 201 @param[out] FullPath The full device path of boot device 202 @param[out] Fs The file system within EfiSysPartition 203 204 @retval EFI_SUCCESS Get file system successfully 205 @retval EFI_NOT_FOUND No valid file system found 206 @retval others Get file system failed 207 208 **/ 209 EFI_STATUS 210 GetEfiSysPartitionFromBootOptionFilePath ( 211 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, 212 OUT EFI_DEVICE_PATH_PROTOCOL **FullPath, 213 OUT EFI_SIMPLE_FILE_SYSTEM_PROTOCOL **Fs 214 ); 215 216 217 /** 218 Process Capsule On Disk. 219 220 @param[in] CapsuleBuffer An array of pointer to capsule images 221 @param[in] CapsuleBufferSize An array of UINTN to capsule images size 222 @param[in] FilePath An array of capsule images file path 223 @param[in] Map File system mapping string 224 @param[in] CapsuleNum The count of capsule images 225 226 @retval EFI_SUCCESS Capsule on disk success. 227 @retval others Capsule on disk fail. 228 229 **/ 230 EFI_STATUS 231 ProcessCapsuleOnDisk ( 232 IN VOID **CapsuleBuffer, 233 IN UINTN *CapsuleBufferSize, 234 IN CHAR16 **FilePath, 235 IN CHAR16 *Map, 236 IN UINTN CapsuleNum 237 ); 238 239 #endif 240 241