#!/usr/bin/env python3 """ device_probe.py discovery class for finding out what is on the other end of the SE-UART """ import sys import struct from isp_core import isp_start from isp_core import isp_stop from isp_core import isp_build_packet from isp_util import close_isp_and_exit from isp_protocol import ISP_COMMAND_DATA_RESPONSE from isp_protocol import ISP_COMMAND_ENQUIRY from isp_protocol import ISP_COMMAND_GET from isp_protocol import ISP_PACKET_DATA_FIELD from isp_protocol import ISP_PACKET_COMMAND_FIELD from isp_protocol import ISP_SOURCE_SEROM from isp_protocol import ISP_SOURCE_SERAM from isp_protocol import ISP_GET_REVISION # Part# & Rev definitions PART_UNKNOWN = 0 REVISIONS = { '0 0 0 0' : 'UNKNOWN', '0 161 0 0' : 'A1', '0 165 0 0' : 'A5', # E1C '0 176 0 0' : 'B0', '0 178 0 0' : 'B2', '0 179 0 0' : 'B3', '0 180 0 0' : 'B4', '1 160 0 0' : 'A0', '1 165 0 0' : 'A5', '160 2 0 0' : 'EG' # super hack... } # bootloader stages STAGE_UNKOWN = 0 STAGE_SEROM = 1 STAGE_SERAM = 2 STAGE_TEXT = ['UNKNOWN','SEROM','SERAM'] EXPECTED_PACKET_LENGTH = 136 class device_get_attributes: """ device_get_attributes """ # attributes from the device part_number = 'PART_UNKNOWN' revision = 'UNKNOWN' stage = STAGE_UNKOWN env = 'UNKNOWN' # DEV or PROD environment def __init__(self, isp): """ ctor """ self.isp = isp # retrieve device Part# # retrieve device revision self.revision, self.part_number, self.env = self.__get_device_info(isp) # probe and set device bootloader stage self.stage = self.__get_device_stage(isp) def __get_device_info(self, isp): """ obtain the SoC Device information """ isp_start(isp) rev = 'ERROR' message = isp_build_packet(isp, ISP_COMMAND_GET, [ISP_GET_REVISION]) if len(message) == 0: close_isp_and_exit(isp, "[ERROR] Target did not respond") if len(message) != EXPECTED_PACKET_LENGTH or message[0] != EXPECTED_PACKET_LENGTH: close_isp_and_exit(isp, "[ERROR] Malformed packet received from target") cmd = message[ISP_PACKET_COMMAND_FIELD] if cmd == ISP_COMMAND_DATA_RESPONSE: # silicon revision lst = message[2:6] rev1 = ' '.join(map(str,lst)) (version,) = struct.unpack("