diff --git a/UnifiedFlashingPlatformTransport.WPI.cs b/UnifiedFlashingPlatformTransport.WPI.cs index c6449cb..6952bbd 100644 --- a/UnifiedFlashingPlatformTransport.WPI.cs +++ b/UnifiedFlashingPlatformTransport.WPI.cs @@ -219,7 +219,7 @@ namespace UnifiedFlashingPlatform const string Header = "NOKXFS"; Buffer.BlockCopy(System.Text.Encoding.ASCII.GetBytes(Header), 0, Request, 0, Header.Length); - Buffer.BlockCopy(BigEndian.GetBytes((int)FfuProtocol.ProtocolSyncV2, 2), 0, Request, 0x06, 2); // Protocol version = 0x0001 + Buffer.BlockCopy(BigEndian.GetBytes((int)FfuProtocol.ProtocolAsyncV1, 2), 0, Request, 0x06, 2); // Protocol version = 0x0001 Request[0x08] = 0; // Progress = 0% Request[0x0B] = 1; // Subblock count = 1 @@ -440,10 +440,6 @@ namespace UnifiedFlashingPlatform FfuFile.Seek(position, SeekOrigin.Begin); - byte[] FfuHeader = new byte[CombinedFFUHeaderSize]; - FfuFile.Read(FfuHeader, 0, (int)CombinedFFUHeaderSize); - SendFfuHeaderV1(FfuHeader, Options); - ulong Position = CombinedFFUHeaderSize; byte[] Payload; int ChunkCount = 0; @@ -451,6 +447,10 @@ namespace UnifiedFlashingPlatform if ((Info.SecureFfuSupportedProtocolMask & (ushort)FfuProtocol.ProtocolSyncV2) == 0) { // Protocol v1 + byte[] FfuHeader = new byte[CombinedFFUHeaderSize]; + FfuFile.Read(FfuHeader, 0, (int)CombinedFFUHeaderSize); + SendFfuHeaderV1(FfuHeader, Options); + Payload = new byte[chunkSize]; while (Position < (ulong)FfuFile.Length) @@ -466,6 +466,23 @@ namespace UnifiedFlashingPlatform else { // Protocol v2 + byte[] FfuHeader = new byte[Info.WriteBufferSize]; + + uint HeaderPosition = 0; + while (HeaderPosition < CombinedFFUHeaderSize) + { + uint PayloadSize = Info.WriteBufferSize; + if ((CombinedFFUHeaderSize - Position) < PayloadSize) + { + PayloadSize = (uint)(CombinedFFUHeaderSize - Position); + FfuHeader = new byte[PayloadSize]; + } + + FfuFile.Read(FfuHeader, 0, (int)PayloadSize); + SendFfuHeaderV2((uint)CombinedFFUHeaderSize, HeaderPosition, FfuHeader, Options); + HeaderPosition += PayloadSize; + } + Payload = new byte[Info.WriteBufferSize]; while (Position < (ulong)FfuFile.Length)