-
Notifications
You must be signed in to change notification settings - Fork 0
/
all_bytes_are.py
39 lines (30 loc) · 1.21 KB
/
all_bytes_are.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
def all_bytes_are(byte, begin, length, block_size=2**12, verbose=False):
'''
returns True if all bytes in QSPI Flash, between begin and begin+length,
are the same as byte, otherwise False.
assumes that utils.flash_read() behaves as if imported from Maix,
ie: `from Maix import utils`
'''
from binascii import hexlify
answer = True
if verbose:
print("Checking if %s bytes of flash at %s are all 0x%s..." % (
length, hex(begin), hexlify(byte).decode()), end='')
bytes_read = 0
while bytes_read < length:
if bytes_read + block_size < length:
if utils.flash_read(begin+bytes_read, block_size) != byte * block_size:
answer = False
break
bytes_read += block_size
else:
if utils.flash_read(begin+bytes_read, length-bytes_read) != byte * (length - bytes_read):
answer = False
break
bytes_read += length - bytes_read
if verbose:
print('.', end='')
if verbose:
print("\nthe %s bytes at %s are %s 0x%s." % (
length, hex(begin), 'ALL' if answer else 'NOT all', hexlify(byte).decode()))
return answer