- // We must have some bytes to write\r
- if (*NumBytes == 0) {\r
- DEBUG ((EFI_D_ERROR, "FvbWrite: ERROR - EFI_BAD_BUFFER_SIZE: (Offset=0x%x + NumBytes=0x%x) > BlockSize=0x%x\n", Offset, *NumBytes, BlockSize ));\r
- return EFI_BAD_BUFFER_SIZE;\r
- }\r
-\r
- // Allocate runtime memory to read in the NOR Flash data.\r
- // Since the intention is to use this with Variable Services and since these are runtime,\r
- // allocate the memory from the runtime pool.\r
- BlockBuffer = AllocateRuntimePool (BlockSize);\r
-\r
- // Check we did get some memory\r
- if( BlockBuffer == NULL ) {\r
- DEBUG ((EFI_D_ERROR, "FvbWrite: ERROR - Can not allocate BlockBuffer @ 0x%08x.\n", BlockBuffer));\r
- return EFI_DEVICE_ERROR;\r
- }\r
-\r
- // Read NOR Flash data into shadow buffer\r
- TempStatus = NorFlashReadBlocks (Instance, Instance->StartLba + Lba, BlockSize, BlockBuffer);\r
- if (EFI_ERROR (TempStatus)) {\r
- // Return one of the pre-approved error statuses\r
- Status = EFI_DEVICE_ERROR;\r
- goto FREE_MEMORY;\r
- }\r
-\r
- // Put the data at the appropriate location inside the buffer area\r
- CopyMem((BlockBuffer + Offset), Buffer, *NumBytes);\r
-\r
- // Write the modified buffer back to the NorFlash\r
- TempStatus = NorFlashWriteBlocks (Instance, Instance->StartLba + Lba, BlockSize, BlockBuffer);\r
- if (EFI_ERROR (TempStatus)) {\r
- // Return one of the pre-approved error statuses\r
- Status = EFI_DEVICE_ERROR;\r
- goto FREE_MEMORY;\r
- }\r
-\r
-FREE_MEMORY:\r
- FreePool(BlockBuffer);\r
- return Status;\r