@@ -216,7 +216,8 @@ public void EraseSpiFlash(int chainIndex, CancellationToken cancellationToken)
216216 ThrowIfDisposed ( ) ;
217217 cancellationToken . ThrowIfCancellationRequested ( ) ;
218218
219- var spiProxy = ProgramSpiProxy ( chainIndex , cancellationToken ) ;
219+ var spiProxy = OpenSpiProxy ( chainIndex ) ;
220+
220221 var flashCapacityBytes = ReadFlashCapacityBytes ( spiProxy , cancellationToken ) ;
221222 logger . LogInformation ( $ "Detected SPI flash with capacity of { ( flashCapacityBytes * 8 ) / 1024 / 1024 } Mb") ;
222223 if ( flashCapacityBytes > 0x01_00_00_00 )
@@ -283,7 +284,8 @@ List<int> BuildPageProgramList(byte[] image, int usedLength, int pageSize)
283284 ThrowIfDisposed ( ) ;
284285 cancellationToken . ThrowIfCancellationRequested ( ) ;
285286
286- var spiProxy = ProgramSpiProxy ( chainIndex , cancellationToken ) ;
287+ var spiProxy = OpenSpiProxy ( chainIndex ) ;
288+
287289 var flashCapacityBytes = ReadFlashCapacityBytes ( spiProxy , cancellationToken ) ;
288290 logger . LogInformation ( $ "Detected SPI flash with capacity of { ( flashCapacityBytes * 8 ) / 1024 / 1024 } Mb") ;
289291 if ( image . Length > flashCapacityBytes )
@@ -349,7 +351,8 @@ public void ProgramSpiFlashSector(int chainIndex, int address, ReadOnlySpan<byte
349351 ThrowIfDisposed ( ) ;
350352 cancellationToken . ThrowIfCancellationRequested ( ) ;
351353
352- var spiProxy = ProgramSpiProxy ( chainIndex , cancellationToken ) ;
354+ var spiProxy = OpenSpiProxy ( chainIndex ) ;
355+
353356 var flashCapacityBytes = ReadFlashCapacityBytes ( spiProxy , cancellationToken ) ;
354357
355358 if ( ( long ) address + data . Length > flashCapacityBytes )
@@ -407,7 +410,8 @@ public void VerifySpiFlash(int chainIndex, string imagePath, CancellationToken c
407410 ThrowIfDisposed ( ) ;
408411 cancellationToken . ThrowIfCancellationRequested ( ) ;
409412
410- var spiProxy = ProgramSpiProxy ( chainIndex , cancellationToken ) ;
413+ var spiProxy = OpenSpiProxy ( chainIndex ) ;
414+
411415 var flashCapacityBytes = ReadFlashCapacityBytes ( spiProxy , cancellationToken ) ;
412416 logger . LogInformation ( $ "Detected SPI flash with capacity of { ( flashCapacityBytes * 8 ) / 1024 / 1024 } Mb") ;
413417 if ( image . Length > flashCapacityBytes )
@@ -493,7 +497,7 @@ private static ulong ReverseBits64(ulong value)
493497 return reversed ;
494498 }
495499
496- private JtagSpiProxy ProgramSpiProxy ( int chainIndex , CancellationToken cancellationToken )
500+ public void ProgramSpiProxy ( int chainIndex , CancellationToken cancellationToken )
497501 {
498502 static string ResolveProxyBitfilePath ( string model )
499503 {
@@ -522,36 +526,20 @@ static string ResolveProxyBitfilePath(string model)
522526 var devices = Scan ( ) ;
523527 ValidateChainIndex ( chainIndex , devices . Count ) ;
524528
525- tap . ShiftIrWriteTarget ( devices . Count , chainIndex , instructionSet . IrLength , instructionSet . JShutdownInstruction , Xc7BypassInstruction ) ;
526- tap . RunIdleCycles ( instructionSet . ProgramShutdownIdleClocks ) ;
527-
528- var existingProxy = OpenSpiProxy ( chainIndex ) ;
529- if ( TryReadFlashCapacityBytes ( existingProxy , cancellationToken , out _ ) )
530- {
531- logger . LogInformation ( "SPI proxy detected; SPI proxy programming skipped" ) ;
532- return existingProxy ;
533- }
534-
535- logger . LogInformation ( "SPI proxy not detected; programming SPI proxy" ) ;
536-
537529 var target = devices [ chainIndex ] ;
538530 var proxyPath = ResolveProxyBitfilePath ( target . Model ) ;
539531 Program ( chainIndex , proxyPath , cancellationToken ) ;
540532
541533 var spiProxy = OpenSpiProxy ( chainIndex ) ;
542534 ReadFlashCapacityBytes ( spiProxy , cancellationToken ) ;
543535 logger . LogInformation ( "SPI proxy programmed and verified" ) ;
544-
545- return spiProxy ;
546536 }
547537
548538 private JtagSpiProxy OpenSpiProxy ( int chainIndex )
549539 {
550540 var idCodes = tap . ReadChainIdCodes ( instructionSet . IrLength , instructionSet . IdCodeInstruction , MaxScanDevices ) ;
551541 ValidateChainIndex ( chainIndex , idCodes . Count ) ;
552-
553542 tap . ShiftIrWriteTarget ( idCodes . Count , chainIndex , instructionSet . IrLength , instructionSet . User1Instruction , Xc7BypassInstruction ) ;
554-
555543 return new JtagSpiProxy ( tap , idCodes . Count , chainIndex ) ;
556544 }
557545
@@ -571,7 +559,7 @@ private static void ResetSpiFlash(JtagSpiProxy jtagSpiProxy, CancellationToken c
571559
572560 private static void DelayWithCancellation ( int milliseconds , CancellationToken cancellationToken )
573561 {
574- if ( cancellationToken . WaitHandle . WaitOne ( milliseconds ) )
562+ if ( cancellationToken . WaitHandle . WaitOne ( milliseconds * 10 ) )
575563 {
576564 cancellationToken . ThrowIfCancellationRequested ( ) ;
577565 }
@@ -605,37 +593,6 @@ private int ReadFlashCapacityBytes(JtagSpiProxy jtagSpiProxy, CancellationToken
605593 return capacityBytes ;
606594 }
607595
608- private bool TryReadFlashCapacityBytes ( JtagSpiProxy jtagSpiProxy , CancellationToken cancellationToken , out int capacityBytes )
609- {
610- capacityBytes = 0 ;
611-
612- ResetSpiFlash ( jtagSpiProxy , cancellationToken ) ;
613-
614- var id = jtagSpiProxy . Read ( SpiFlashOpcodes . ReadId , [ ] , 3 ) ;
615- if ( id . Length < 3 )
616- {
617- return false ;
618- }
619-
620- if ( id [ 0 ] != SupportedFlashManufacturerId )
621- {
622- return false ;
623- }
624-
625- if ( id [ 1 ] != SupportedFlashMemoryTypeId )
626- {
627- return false ;
628- }
629-
630- if ( ! TryDecodeCapacityBytes ( id [ 2 ] , out capacityBytes ) || capacityBytes < 64 * 1024 )
631- {
632- capacityBytes = 0 ;
633- return false ;
634- }
635-
636- return true ;
637- }
638-
639596 private static bool TryDecodeCapacityBytes ( byte capacityCode , out int capacityBytes )
640597 {
641598 capacityBytes = 0 ;
0 commit comments