Remove dependency on old dfu-suffix
This commit is contained in:
@ -168,12 +168,7 @@ macro(DeclareTargets)
|
|||||||
add_custom_target(
|
add_custom_target(
|
||||||
${PROJECT_NAME}.dfu ALL
|
${PROJECT_NAME}.dfu ALL
|
||||||
DEPENDS ${PROJECT_NAME}.bin
|
DEPENDS ${PROJECT_NAME}.bin
|
||||||
COMMAND rm -f _tmp.dfu _header.bin
|
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../tools/make-dfu.py ${PROJECT_NAME}.bin ${PROJECT_NAME}.dfu
|
||||||
COMMAND cp ${PROJECT_NAME}.bin _tmp.dfu
|
|
||||||
COMMAND dfu-suffix --vid=0x1fc9 --pid=0x000c --did=0x0 -s 0 -a _tmp.dfu
|
|
||||||
COMMAND python -c \"import os.path\; import struct\; print\('0000000: da ff ' + ' '.join\(map\(lambda s: '%02x' % ord\(s\), struct.pack\('<H', os.path.getsize\('${PROJECT_NAME}.bin'\) / 512 + 1\)\)\) + ' ff ff ff ff'\)\" | xxd -g1 -r > _header.bin
|
|
||||||
COMMAND cat _header.bin _tmp.dfu >${PROJECT_NAME}.dfu
|
|
||||||
COMMAND rm -f _tmp.dfu _header.bin
|
|
||||||
)
|
)
|
||||||
|
|
||||||
add_custom_target(
|
add_custom_target(
|
||||||
|
70
firmware/tools/make-dfu.py
Executable file
70
firmware/tools/make-dfu.py
Executable file
@ -0,0 +1,70 @@
|
|||||||
|
#!/usr/bin/env python2
|
||||||
|
# vim: set ts=4 sw=4 tw=0 et pm=:
|
||||||
|
import struct
|
||||||
|
import sys
|
||||||
|
import os.path
|
||||||
|
import getopt
|
||||||
|
import zlib
|
||||||
|
|
||||||
|
options, remainder = getopt.getopt(sys.argv[1:], 'p:v:d:S:v', ['pid=',
|
||||||
|
'vid=',
|
||||||
|
'did=',
|
||||||
|
'spec=',
|
||||||
|
'verbose',
|
||||||
|
])
|
||||||
|
|
||||||
|
pid = 0x000c
|
||||||
|
vid = 0x1fc9
|
||||||
|
did = 0
|
||||||
|
spec = 0x0100
|
||||||
|
verbose = False
|
||||||
|
|
||||||
|
for opt, arg in options:
|
||||||
|
if opt in ('-p', '--pid'):
|
||||||
|
pid = int(arg)
|
||||||
|
if opt in ('-v', '--vid'):
|
||||||
|
vid = int(arg)
|
||||||
|
if opt in ('-d', '--did'):
|
||||||
|
did = int(arg)
|
||||||
|
if opt in ('-S', '--spec'):
|
||||||
|
spec = int(arg)
|
||||||
|
elif opt in ('-v', '--verbose'):
|
||||||
|
verbose = True
|
||||||
|
|
||||||
|
if len(remainder)<1:
|
||||||
|
in_file = "/dev/stdin"
|
||||||
|
else:
|
||||||
|
in_file = remainder[0]
|
||||||
|
|
||||||
|
if len(remainder)<2:
|
||||||
|
out = open("/dev/stdout","wb")
|
||||||
|
else:
|
||||||
|
out = open(remainder[1],"wb")
|
||||||
|
|
||||||
|
# ref. NXP UM10503 Table 24 (Boot image header description)
|
||||||
|
header = ""
|
||||||
|
header += struct.pack ('<B',int("11"+"011010",2)) # AES enc not active + No hash active
|
||||||
|
header += struct.pack ('<B',int("11"+"111111",2)) # RESERVED + AES_CONTROL
|
||||||
|
size=os.path.getsize(in_file)
|
||||||
|
size=(size+511)/512 # 512 byte blocks, rounded up
|
||||||
|
header += struct.pack('<H',size) # (badly named) HASH_SIZE
|
||||||
|
header += struct.pack('8B',*[0xff] *8) # HASH_VALUE (unused)
|
||||||
|
header += struct.pack('4B',*[0xff] *4) # RESERVED
|
||||||
|
|
||||||
|
out.write( header )
|
||||||
|
|
||||||
|
infile=open(in_file,"rb").read()
|
||||||
|
out.write( infile )
|
||||||
|
|
||||||
|
suffix= ""
|
||||||
|
suffix+= struct.pack('<H', did) # bcdDevice
|
||||||
|
suffix+= struct.pack('<H', pid) # idProduct
|
||||||
|
suffix+= struct.pack('<H', vid) # idVendor
|
||||||
|
suffix+= struct.pack('<H', spec) # bcdDFU
|
||||||
|
suffix+= b'DFU'[::-1] # (reverse DFU)
|
||||||
|
suffix+= struct.pack('<B', 16) # suffix length
|
||||||
|
|
||||||
|
out.write( suffix )
|
||||||
|
|
||||||
|
checksum=zlib.crc32(header+infile+suffix) & 0xffffffff ^ 0xffffffff
|
||||||
|
out.write( struct.pack('I', checksum) ) # crc32
|
Reference in New Issue
Block a user