mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-25 23:01:02 +00:00
39 lines
1.1 KiB
Python
Executable File
39 lines
1.1 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
import sys
|
|
import struct
|
|
|
|
# bootloader header specification: https://github.com/trezor/trezor-core/blob/master/docs/bootloader.md#bootloader-header
|
|
|
|
def check_bootloader(filename):
|
|
data = open(filename, 'rb').read()
|
|
hdr = struct.unpack('<4sIIIBBBBB64s171s', data[:256])
|
|
code = data[256:]
|
|
magic, hdrlen, expiry, codelen, vmajor, vminor, vpatch, vbuild, sigidx, sig, reserved = hdr
|
|
sigidx = tuple([ i + 1 for i in range(8) if sigidx & (1 << i) ])
|
|
print('magic :', magic)
|
|
assert magic == b'TRZB'
|
|
print('hdrlen :', hdrlen)
|
|
assert hdrlen == 256
|
|
print('expiry :', expiry)
|
|
print('codelen :', codelen)
|
|
print('vmajor :', vmajor)
|
|
print('vminor :', vminor)
|
|
print('vpatch :', vpatch)
|
|
print('vbuild :', vbuild)
|
|
print('sigidx :', sigidx)
|
|
print('sig :', sig)
|
|
assert reserved == 171 * b'\x00'
|
|
assert codelen == 64*1024
|
|
assert codelen == len(code)
|
|
|
|
|
|
def main():
|
|
if len(sys.argv) < 2:
|
|
print('Usage: check_bootloader bootloader.bin')
|
|
return 1
|
|
fn = sys.argv[1]
|
|
check_bootloader(fn)
|
|
|
|
|
|
main()
|