aboutsummaryrefslogtreecommitdiff
path: root/Tools/px_uploader.py
diff options
context:
space:
mode:
authorLorenz Meier <lm@inf.ethz.ch>2014-02-05 14:23:48 +0100
committerLorenz Meier <lm@inf.ethz.ch>2014-02-05 14:24:01 +0100
commit080b2da214e014933e9062aca9a0be5bd1a2340a (patch)
tree7d84815d830c55b7c459ca403c2fb68f0c4c3534 /Tools/px_uploader.py
parenta7218770b3cb6c45927d5c791aa863ffccba6b89 (diff)
downloadpx4-firmware-080b2da214e014933e9062aca9a0be5bd1a2340a.tar.gz
px4-firmware-080b2da214e014933e9062aca9a0be5bd1a2340a.tar.bz2
px4-firmware-080b2da214e014933e9062aca9a0be5bd1a2340a.zip
Updated uploader from Bootloader repo
Diffstat (limited to 'Tools/px_uploader.py')
-rwxr-xr-xTools/px_uploader.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/Tools/px_uploader.py b/Tools/px_uploader.py
index cce5e5e54..23dc48450 100755
--- a/Tools/px_uploader.py
+++ b/Tools/px_uploader.py
@@ -50,6 +50,9 @@
# Currently only used for informational purposes.
#
+# for python2.7 compatibility
+from __future__ import print_function
+
import sys
import argparse
import binascii
@@ -154,6 +157,8 @@ class uploader(object):
PROG_MULTI = b'\x27'
READ_MULTI = b'\x28' # rev2 only
GET_CRC = b'\x29' # rev3+
+ GET_OTP = b'\x2a' # rev4+ , get a word from OTP area
+ GET_SN = b'\x2b' # rev4+ , get a word from SN area
REBOOT = b'\x30'
INFO_BL_REV = b'\x01' # bootloader protocol revision
@@ -175,6 +180,8 @@ class uploader(object):
def __init__(self, portname, baudrate):
# open the port, keep the default timeout short so we can poll quickly
self.port = serial.Serial(portname, baudrate, timeout=0.5)
+ self.otp = b''
+ self.sn = b''
def close(self):
if self.port is not None:
@@ -237,6 +244,22 @@ class uploader(object):
self.__getSync()
return value
+ # send the GET_OTP command and wait for an info parameter
+ def __getOTP(self, param):
+ t = struct.pack("I", param) # int param as 32bit ( 4 byte ) char array.
+ self.__send(uploader.GET_OTP + t + uploader.EOC)
+ value = self.__recv(4)
+ self.__getSync()
+ return value
+
+ # send the GET_OTP command and wait for an info parameter
+ def __getSN(self, param):
+ t = struct.pack("I", param) # int param as 32bit ( 4 byte ) char array.
+ self.__send(uploader.GET_SN + t + uploader.EOC)
+ value = self.__recv(4)
+ self.__getSync()
+ return value
+
# send the CHIP_ERASE command and wait for the bootloader to become ready
def __erase(self):
self.__send(uploader.CHIP_ERASE
@@ -353,6 +376,31 @@ class uploader(object):
if self.fw_maxsize < fw.property('image_size'):
raise RuntimeError("Firmware image is too large for this board")
+ # OTP added in v4:
+ if self.bl_rev > 3:
+ for byte in range(0,32*6,4):
+ x = self.__getOTP(byte)
+ self.otp = self.otp + x
+ print(binascii.hexlify(x).decode('utf-8') + ' ', end='')
+ # see src/modules/systemlib/otp.h in px4 code:
+ self.otp_id = self.otp[0:4]
+ self.otp_idtype = self.otp[4:5]
+ self.otp_vid = self.otp[8:4:-1]
+ self.otp_pid = self.otp[12:8:-1]
+ self.otp_coa = self.otp[32:160]
+ # show user:
+ print("type: " + self.otp_id.decode('utf-8'))
+ print("idtype: " + binascii.b2a_qp(self.otp_idtype).decode('utf-8'))
+ print("vid: " + binascii.hexlify(self.otp_vid).decode('utf-8'))
+ print("pid: "+ binascii.hexlify(self.otp_pid).decode('utf-8'))
+ print("coa: "+ binascii.b2a_base64(self.otp_coa).decode('utf-8'))
+ print("sn: ", end='')
+ for byte in range(0,12,4):
+ x = self.__getSN(byte)
+ x = x[::-1] # reverse the bytes
+ self.sn = self.sn + x
+ print(binascii.hexlify(x).decode('utf-8'), end='') # show user
+ print('')
print("erase...")
self.__erase()