1515import passport
1616from uasyncio import sleep_ms
1717from files import CardSlot , CardMissingError
18+ from foundation import flash
1819from errors import Error
1920
2021
2122TIMEOUT_MS = 1000
2223
2324
24- async def sleep_and_timeout (sleep_time_ms , timeout_ms , sf ):
25- while sf .is_busy ():
25+ async def sleep_and_timeout (sleep_time_ms , timeout_ms ):
26+ while flash .is_busy ():
2627 await sleep_ms (sleep_time_ms )
2728 timeout_ms -= sleep_time_ms
2829 assert timeout_ms > 0 , 'Firmware update timed out'
2930
3031
3132async def copy_firmware_to_spi_flash_task (file_path , size , on_progress , on_done ):
32- from common import system , sf
33+ from common import system
3334
3435 try :
3536 with CardSlot () as card :
@@ -74,8 +75,8 @@ async def copy_firmware_to_spi_flash_task(file_path, size, on_progress, on_done)
7475 update_hash = s .digest ()
7576
7677 # Erase first page
77- sf .sector_erase (0 )
78- await sleep_and_timeout (10 , TIMEOUT_MS , sf )
78+ flash .sector_erase (0 )
79+ await sleep_and_timeout (10 , TIMEOUT_MS )
7980
8081 buf = bytearray (256 ) # must be flash page size
8182
@@ -115,13 +116,13 @@ async def copy_firmware_to_spi_flash_task(file_path, size, on_progress, on_done)
115116 try :
116117 if pos % 4096 == 0 :
117118 # erase here
118- sf .sector_erase (pos )
119- await sleep_and_timeout (10 , TIMEOUT_MS , sf )
119+ flash .sector_erase (pos )
120+ await sleep_and_timeout (10 , TIMEOUT_MS )
120121
121- sf .write (pos , buf )
122+ flash .write (pos , buf )
122123
123124 # full page write: 0.6 to 3ms
124- await sleep_and_timeout (1 , TIMEOUT_MS , sf )
125+ await sleep_and_timeout (1 , TIMEOUT_MS )
125126
126127 pos += here
127128 if passport .IS_SIMULATOR :
@@ -138,7 +139,7 @@ async def copy_firmware_to_spi_flash_task(file_path, size, on_progress, on_done)
138139 # Do this at the end so we know the rest worked - prevent bootloader from installing bad firmware
139140 buf [0 :32 ] = update_hash # Copy into the buf we'll use to write to SPI flash
140141
141- sf .write (0 , buf ) # Need to write the entire page of 256 bytes
142+ flash .write (0 , buf ) # Need to write the entire page of 256 bytes
142143
143144 # Success
144145 except CardMissingError :
0 commit comments