1 /** @file 2 3 Copyright (c) 1999 - 2014, Intel Corporation. All rights reserved.<BR> 4 5 This program and the accompanying materials are licensed and made available under 7 the terms and conditions of the BSD License that accompanies this distribution. 9 The full text of the license may be found at 11 http://opensource.org/licenses/bsd-license.php. 13 15 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 17 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 19 21 23 **/ 24 25 #ifndef _FIRMWARE_UPDATE_H_ 26 #define _FIRMWARE_UPDATE_H_ 27 28 #include <Uefi.h> 29 30 #include <PiDxe.h> 31 32 #include <Guid/FileInfo.h> 33 34 #include <Protocol/FirmwareVolumeBlock.h> 35 #include <Protocol/LoadedImage.h> 36 #include <Protocol/SimpleFileSystem.h> 37 #include <Protocol/Spi.h> 38 39 #include <Library/BaseLib.h> 40 #include <Library/BaseMemoryLib.h> 41 #include <Library/CacheMaintenanceLib.h> 42 #include <Library/DebugLib.h> 43 #include <Library/FileHandleLib.h> 44 #include <Library/HiiLib.h> 45 #include <Library/MemoryAllocationLib.h> 46 #include <Library/PcdLib.h> 47 #include <Library/PrintLib.h> 48 #include <Library/ShellLib.h> 49 #include <Library/UefiApplicationEntryPoint.h> 50 #include <Library/UefiBootServicesTableLib.h> 51 #include <Library/UefiLib.h> 52 #include <Library/UefiRuntimeServicesTableLib.h> 53 54 // 55 // Function Prototypes. 56 // 57 STATIC 58 EFI_STATUS 59 ReadFileData ( 60 IN CHAR16 *FileName, 61 OUT UINT8 **Buffer, 62 OUT UINT32 *BufferSize 63 ); 64 65 STATIC 66 EFI_STATUS 67 InternalEraseBlock ( 68 IN EFI_PHYSICAL_ADDRESS BaseAddress 69 ); 70 71 #if 0 72 STATIC 73 EFI_STATUS 74 InternalReadBlock ( 75 IN EFI_PHYSICAL_ADDRESS BaseAddress, 76 OUT VOID *ReadBuffer 77 ); 78 #endif 79 80 STATIC 81 EFI_STATUS 82 InternalCompareBlock ( 83 IN EFI_PHYSICAL_ADDRESS BaseAddress, 84 IN UINT8 *Buffer 85 ); 86 87 STATIC 88 EFI_STATUS 89 InternalWriteBlock ( 90 IN EFI_PHYSICAL_ADDRESS BaseAddress, 91 IN UINT8 *Buffer, 92 IN UINT32 BufferSize 93 ); 94 95 STATIC 96 VOID 97 PrintHelpInfo ( 98 VOID 99 ); 100 101 STATIC 102 EFI_STATUS 103 EFIAPI 104 SpiFlashRead ( 105 IN UINTN Address, 106 IN OUT UINT32 *NumBytes, 107 OUT UINT8 *Buffer 108 ); 109 110 STATIC 111 EFI_STATUS 112 EFIAPI 113 SpiFlashWrite ( 114 IN UINTN Address, 115 IN OUT UINT32 *NumBytes, 116 IN UINT8 *Buffer 117 ); 118 119 STATIC 120 EFI_STATUS 121 EFIAPI 122 SpiFlashBlockErase ( 123 IN UINTN Address, 124 IN UINTN *NumBytes 125 ); 126 127 STATIC 128 EFI_STATUS 129 EFIAPI 130 ConvertMac ( 131 CHAR16 *Str 132 ); 133 134 EFI_STATUS 135 InitializeFVUPDATE ( 136 IN EFI_HANDLE ImageHandle, 137 IN EFI_SYSTEM_TABLE *SystemTable 138 ); 139 140 // 141 // Flash specific definitions. 142 // - Should we use a PCD for this information? 143 // 144 #define BLOCK_SIZE SIZE_4KB 145 146 // 147 // Flash region layout and update information. 148 // 149 typedef struct { 150 EFI_PHYSICAL_ADDRESS Base; 151 UINTN Size; 152 BOOLEAN Update; 153 } FV_REGION_INFO; 154 155 // 156 // MAC Address information. 157 // 158 #define MAC_ADD_STR_LEN 12 159 #define MAC_ADD_STR_SIZE (MAC_ADD_STR_LEN + 1) 160 #define MAC_ADD_BYTE_COUNT 6 161 #define MAC_ADD_TMP_STR_LEN 2 162 #define MAC_ADD_TMP_STR_SIZE (MAC_ADD_TMP_STR_LEN + 1) 163 164 // 165 // Command Line Data. 166 // 167 #define INPUT_STRING_LEN 255 168 #define INPUT_STRING_SIZE (INPUT_STRING_LEN + 1) 169 typedef struct { 170 BOOLEAN UpdateFromFile; 171 CHAR16 FileName[INPUT_STRING_SIZE]; 172 BOOLEAN UpdateMac; 173 UINT8 MacValue[MAC_ADD_BYTE_COUNT]; 174 BOOLEAN FullFlashUpdate; 175 } FV_INPUT_DATA; 176 177 // 178 // Prefix Opcode Index on the host SPI controller. 179 // 180 typedef enum { 181 SPI_WREN, // Prefix Opcode 0: Write Enable. 182 SPI_EWSR, // Prefix Opcode 1: Enable Write Status Register. 183 } PREFIX_OPCODE_INDEX; 184 185 // 186 // Opcode Menu Index on the host SPI controller. 187 // 188 typedef enum { 189 SPI_READ_ID, // Opcode 0: READ ID, Read cycle with address. 190 SPI_READ, // Opcode 1: READ, Read cycle with address. 191 SPI_RDSR, // Opcode 2: Read Status Register, No address. 192 SPI_WRDI_SFDP, // Opcode 3: Write Disable or Discovery Parameters, No address. 193 SPI_SERASE, // Opcode 4: Sector Erase (4KB), Write cycle with address. 194 SPI_BERASE, // Opcode 5: Block Erase (32KB), Write cycle with address. 195 SPI_PROG, // Opcode 6: Byte Program, Write cycle with address. 196 SPI_WRSR, // Opcode 7: Write Status Register, No address. 197 } SPI_OPCODE_INDEX; 198 199 #endif 200