utzig commented on a change in pull request #2144: OTP Tool: Support BLE Addr
and HWID
URL: https://github.com/apache/mynewt-core/pull/2144#discussion_r363934099
##########
File path: hw/bsp/dialog_da1469x-dk-pro/otp_tool.py
##########
@@ -605,6 +615,141 @@ def test_alive_target(uart):
SystemExit("Successfully communicated with target")
[email protected]('-u', '--uart', required=True, help='uart port')
[email protected](help='Read the BLE Address of the device')
+def otp_read_ble_addr(uart):
+ try:
+ ser = serial.Serial(port=uart, baudrate=1000000, timeout=1,
+ bytesize=8, stopbits=serial.STOPBITS_ONE)
+ except serial.SerialException:
+ raise SystemExit("Failed to open serial port")
+
+ cmd = cmd_no_payload(0xaa55aa55, Cmd.READ_BLEADDR)
+ msg = struct.pack('II', *cmd)
+
+ try:
+ ser.write(msg)
+ except serial.SerialException:
+ raise SystemExit("Failed to write to %s" % uart)
+
+ data = read_exact(ser, 16)
+ response = cmd_response._make(struct.unpack_from('IIII', data))
+ if response.status == 0:
+ # BLE Addr is 48 bits long, read as 2 uint32_t values
+ ble_words = struct.unpack_from('II', ser.read(8))
+ print("BLE Addr - Low Word:" + hex(ble_words[0])
+ + " High Word:" + hex(ble_words[1]))
+ else:
+ raise SystemExit("Error reading BLE Addr with status %s" %
+ hex(response.status))
+
+
[email protected]('-u', '--uart', required=True, help='uart port')
[email protected](help='Generate and program the BLE Address of the device')
+def otp_write_ble_addr(uart):
+ try:
+ ser = serial.Serial(port=uart, baudrate=1000000, timeout=1,
+ bytesize=8, stopbits=serial.STOPBITS_ONE)
+ except serial.SerialException:
+ raise SystemExit("Failed to open serial port")
+
+ cmd = cmd_no_payload(0xaa55aa55, Cmd.GEN_BLEADDR)
+ msg = struct.pack('II', *cmd)
+
+ try:
+ ser.write(msg)
+ except serial.SerialException:
+ raise SystemExit("Failed to write %s" % uart)
+
+ data = read_exact(ser, 16)
+ response = cmd_response._make(struct.unpack_from('IIII', data))
+ if (response.status == 0 or response.status == 1):
+ ble_words = struct.unpack_from('II', ser.read(8))
+ if response.status == 0:
+ print("Newly programmed BLE Address")
+ elif response.status == 1:
+ print("Previously programmed")
+ print("BLE Addr - Low Word:" + hex(ble_words[0])
+ + " High Word:" + hex(ble_words[1]))
+ else:
+ raise SystemExit("Error generating/programming BLE Address")
+
+
[email protected]('-u', '--uart', required=True, help='uart port')
[email protected](help='Read the HWID of the device')
+def otp_read_hwid(uart):
+ try:
+ ser = serial.Serial(port=uart, baudrate=1000000, timeout=1,
+ bytesize=8, stopbits=serial.STOPBITS_ONE)
+ except serial.SerialException:
+ raise SystemExit("Failed to open serial port")
+
+ cmd = cmd_no_payload(0xaa55aa55, Cmd.READ_HWID)
+ msg = struct.pack('II', *cmd)
+
+ try:
+ ser.write(msg)
+ except serial.SerialException:
+ raise SystemExit("Failed to write to %s" % uart)
+
+ data = read_exact(ser, 16)
+ response = cmd_response._make(struct.unpack_from('IIII', data))
+
+ if response.status == 0:
+ ble_addr = ser.read(16)
+ print("HWID:" + ble_addr.hex())
+ else:
+ raise SystemExit("Error reading HWID with status %s" %
+ hex(response.status))
+
+
[email protected]('infile')
[email protected]('-u', '--uart', required=True, help='uart port')
[email protected](help='Write hardware ID into OTP')
+def otp_write_hwid(infile, uart):
+ hwid = bytearray()
+ hwid_len = 10
+ try:
+ with open(infile, "rb") as f:
+ # read hwid file
+ buf = f.read()
+
+ # Expect 10 byte HWID
+ if len(buf) != 10:
+ raise SystemExit("HWID has incorrect length")
Review comment:
You don't need to wrap the context manager inside a `try` block, just use
"Failed to read key from file" here and remove the `except` below.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services