fix(dfu): Use original HackRF DFU tools

This commit is contained in:
schneider
2017-01-29 22:54:44 +01:00
parent 642feac51e
commit 07f800d57a
3 changed files with 12 additions and 75 deletions

View File

@ -27,10 +27,12 @@ To build and install a standard firmware image for HackRF One:
$ cd hackrf_usb
$ mkdir build
$ cd build
$ cmake .. -DBOARD=RAD1O
$ cmake .. -DBOARD=HACKRF_ONE
$ make
$ hackrf_spiflash -w hackrf_usb.bin
If you have a Jawbreaker, use -DBOARD=JAWBREAKER instead.
If you have a rad1o, use -DBOARD=RAD1O instead.
For loading firmware into RAM with DFU you will also need:
@ -43,4 +45,4 @@ after the 3V3 LED illuminates.
A .dfu file is built by default when building firmware. Alternatively you can
load a known good .dfu file from a release package with:
$ dfu-util --device 1fc9:000c --alt 0 --download hackrf_usb_ram.dfu
$ dfu-util --device 1fc9:000c --alt 0 --download hackrf_usb.dfu

View File

@ -196,9 +196,14 @@ macro(DeclareTargets)
)
add_custom_target(
${PROJECT_NAME}.dfu ALL
DEPENDS ${PROJECT_NAME}.bin
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../tools/make-dfu.py ${PROJECT_NAME}.bin ${PROJECT_NAME}.dfu
${PROJECT_NAME}.dfu ${DFU_ALL}
DEPENDS ${PROJECT_NAME}_dfu.bin
COMMAND rm -f _tmp.dfu _header.bin
COMMAND cp ${PROJECT_NAME}_dfu.bin _tmp.dfu
COMMAND ${DFU_COMMAND}
COMMAND python ../../dfu.py ${PROJECT_NAME}
COMMAND cat _header.bin _tmp.dfu >${PROJECT_NAME}.dfu
COMMAND rm -f _tmp.dfu _header.bin
)
add_custom_target(

View File

@ -1,70 +0,0 @@
#!/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