aboutsummaryrefslogtreecommitdiff
path: root/Tools
diff options
context:
space:
mode:
authorLorenz Meier <lm@inf.ethz.ch>2014-02-11 08:24:18 +0100
committerLorenz Meier <lm@inf.ethz.ch>2014-02-11 08:24:18 +0100
commit1b978293d9cce0ddd49299ac893864fea27ae491 (patch)
tree78e6e03a233a5addc6be6fd7703438076e3a2682 /Tools
parent268f3d757f264fcd1c2217a41d5fa480e0c91a8f (diff)
parent0388d9adefb33c98f1e4350e3f2ed59a7fdd5359 (diff)
downloadpx4-firmware-1b978293d9cce0ddd49299ac893864fea27ae491.tar.gz
px4-firmware-1b978293d9cce0ddd49299ac893864fea27ae491.tar.bz2
px4-firmware-1b978293d9cce0ddd49299ac893864fea27ae491.zip
Merged master into beta
Diffstat (limited to 'Tools')
-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..e4a8b3c05 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('Latin-1') + ' ', 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('Latin-1'))
+ print("idtype: " + binascii.b2a_qp(self.otp_idtype).decode('Latin-1'))
+ print("vid: " + binascii.hexlify(self.otp_vid).decode('Latin-1'))
+ print("pid: "+ binascii.hexlify(self.otp_pid).decode('Latin-1'))
+ print("coa: "+ binascii.b2a_base64(self.otp_coa).decode('Latin-1'))
+ 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('Latin-1'), end='') # show user
+ print('')
print("erase...")
self.__erase()