#!/usr/bin/env python3 """ device_probe.py discovery class for finding out what is on the other end of the SE-UART """ import struct from isp_core import isp_start from isp_core import isp_stop from isp_core import isp_build_packet 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 176 0 0' : 'B0', '0 178 0 0' : 'B2', '0 179 0 0' : 'B3', '0 180 0 0' : 'B4', '1 160 0 0' : 'A0', '2 160 0 0' : 'EG' # super hack... } # bootloader stages STAGE_UNKOWN = 0 STAGE_SEROM = 1 STAGE_SERAM = 2 STAGE_TEXT = ['UNKNOWN','SEROM','SERAM'] 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]) cmd = message[ISP_PACKET_COMMAND_FIELD] if len(message) == 0: print("[ERROR] Target did not respond") return rev if cmd == ISP_COMMAND_DATA_RESPONSE: # silicon revision lst = message[2:6] rev1 = ' '.join(map(str,lst)) (version,) = struct.unpack("