int CUSB30Device::InitFirmware() { int ret = FRC_FAILED; { // 如果被识别为2.0设备,需要重新下载固件 if (m_pUSBDevice->Open(0)) { ret = DownloadFirmware(FXFirmwareFilePath, RAM); //if (ret == FRC_SUCCESS) { ::Sleep(200); //Refresh(); } } } return ret; }
Int32 OnRequestACK(Int8* buffer, UInt32 len) { if ( len != sizeof(pTRequestACK) ) { return -1; } pTRequestACK p = (pTRequestACK)buffer; if ( p->nStartByte == REQUEST_START_BYTE ) { if ( p->szDownloadPath[0] != 0 ) { //Will Download DownloadFirmware(p->szDownloadServer, p->nDownloadPort, p->szDownloadPath); } } return 0; }
//////////////////////////// // SET SERIAL NUMBER void AltaUsbIo::SetSerialNumber(const std::string & num) { //download firmware into the cypress chip's RAM //because of hw architecture we have to run the //chip out of RAM to access the EEPROMS DownloadFirmware(); //write the serial number into the EEPROM std::vector<uint8_t> numVect( Eeprom::MAX_SERIAL_NUM_BYTES, 0); std::copy(num.begin(), num.end(), numVect.begin() ); PromFx2Io pf( m_Usb, ALTA_EEPROM_MAX_BLOCKS, ALTA_EEPROM_MAX_BANKS ); pf.BufferWriteEeprom(ALTA_SN_EEPROM_BANK, ALTA_SN_EEPROM_BLOCK, ALTA_SN_EEPROM_ADDR, numVect); }
/************************************************* * Loads the image with the given name into RAM. * * @param p_device (in) The kernel device. * @param p_name (in) The image name. This image file must be located * in /vendor/firmware. * @param addr (in) The RAM address to load the image into. * @param expectedSize (in) The expected size of the image file, or 0 * if the size is to be calculated. * *****************************************************/ static int32_t LoadFirmware(struct device *p_device, const char *p_name, int addr, int expectedSize) { const struct firmware *fw; int32_t err; int imgSize; IPC_DEBUG(DBG_INFO, "calling request_firmware for %s, device=%p\n", p_name, p_device); /** call kernel to start firmware load **/ /* request_firmware(const struct firmware **fw, * const char *name, * struct device *device); */ err = request_firmware(&fw, p_name, p_device); if (err) { IPC_DEBUG(DBG_ERROR, "firmware request failed (%d)\n", err); return err; } if (fw) IPC_DEBUG(DBG_INFO, "fw->size=%d\n", fw->size); else { /*Coverity Complaint: FORWARD_NULL */ IPC_DEBUG(DBG_INFO, "fw = NULL!\n"); return err; } imgSize = fw->size; if (expectedSize == 0) { UInt8 *ptr; /* This is the main CP image */ if (IsCommsImageValid(fw->data)) IPC_DEBUG(DBG_INFO, "verified CP image\n"); else IPC_DEBUG(DBG_ERROR, "failed to verify main image\n"); ptr = ((UInt8 *)fw->data) + CP_IMAGE_SIZE_OFFSET; imgSize = (ptr[3] << 24) | (ptr[2] << 16) | (ptr[1] << 8) | ptr[0]; IPC_DEBUG(DBG_INFO, "calculated CP image size = 0x%x\n", imgSize); } else if (expectedSize != imgSize) { if (imgSize > expectedSize) { IPC_DEBUG(DBG_ERROR, "ERROR: fw->size > expected (0x%x > 0x%x)\n", fw->size, expectedSize); imgSize = expectedSize; } else IPC_DEBUG(DBG_ERROR, "ERROR: fw->size < expected (0x%x < 0x%x)\n", fw->size, expectedSize); } /** download to chip **/ err = DownloadFirmware(imgSize, fw->data, addr); /* Verify CP image @ RAM addr */ if (expectedSize == 0) { void __iomem *virtAddr; virtAddr = ioremap_nocache(addr, fw->size); if (virtAddr) { int retval; /* This is the main CP image */ if (IsCommsImageValid(virtAddr)) IPC_DEBUG(DBG_INFO, "verified CP image @ %p\n", (void *)addr); else IPC_DEBUG(DBG_ERROR, "failed to verify main image @ %p\n", (void *)addr); retval = memcmp(fw->data, virtAddr, imgSize); IPC_DEBUG(DBG_INFO, "memcmp(%p, %p, 0x%x) = %d\n", (void *)fw->data, virtAddr, imgSize, retval); iounmap(virtAddr); } else { IPC_DEBUG(DBG_ERROR, "*** ERROR: ioremap_nocache FAILED for addr %p\n", (void *)addr); } } /** free kernel structure */ release_firmware(fw); return err; }
/////////////////////////// // PROGRAM CAMERA void AltaUsbIo::Program(const std::string & FilenameCamCon, const std::string & FilenameBufCon, const std::string & FilenameFx2, const std::string & FilenameGpifCamCon,const std::string & FilenameGpifBufCon, const std::string & FilenameGpifFifo, bool Print2StdOut ) { m_Print2StdOut = Print2StdOut; //STEP 1 //get the current product and device identifier uint16_t Vid = 0; uint16_t Pid = 0; uint16_t Did = 0; GetUsbVendorInfo( Vid, Pid, Did ); //if this programmed with apogee fx2 code //grab the custom serial number now, so we //can write it back at the end of the firmware //programming std::string serialNum; if ( ( UsbFrmwr::ALTA_USB_PID == Pid ) && (UsbFrmwr::ALTA_USB_DID <= Did) ) { serialNum = GetSerialNumber(); } Progress2StdOut( 8 ); //STEP 2 //download the alta firmware DownloadFirmware(); Progress2StdOut( 16 ); //STEP 3 // initialize prom header information Eeprom::Header hdr; memset(&hdr, 0, sizeof( hdr ) ); hdr.Size = sizeof( hdr ); hdr.Version = Eeprom::HEADER_VERSION; Progress2StdOut( 24 ); //STEP 4 //download bufcon PromFx2Io pf( m_Usb, ALTA_EEPROM_MAX_BLOCKS, ALTA_EEPROM_MAX_BANKS ); uint32_t DownloadSize = 0; pf.WriteFile2Eeprom( FilenameBufCon, BUFCON_PROM_BANK, BUFCON_PROM_BLOCK , BUFCON_PROM_ADDR, DownloadSize ); hdr.BufConSize = DownloadSize; hdr.Fields |= Eeprom::HEADER_BUFCON_VALID_BIT; Progress2StdOut( 32 ); //STEP 5 //download camcon pf.WriteFile2Eeprom( FilenameCamCon, CAMCON_PROM_BANK, CAMCON_PROM_BLOCK , CAMCON_PROM_ADDR, DownloadSize ); hdr.CamConSize = DownloadSize; hdr.Fields |= Eeprom::HEADER_CAMCON_VALID_BIT; Progress2StdOut( 40 ); //STEP 6 //download the fx2 pf.WriteFile2Eeprom( FilenameFx2, FX2_PROM_BANK, FX2_PROM_BLOCK, FX2_PROM_ADDR, DownloadSize ); hdr.Fields |= Eeprom::HEADER_BOOTROM_VALID_BIT; Progress2StdOut( 48 ); //STEP 7 //download the bufcon gpif waveform pf.WriteFile2Eeprom( FilenameGpifBufCon, GPIF_WAVEFORM_BUFCON_PROM_BANK, GPIF_WAVEFORM_BUFCON_PROM_BLOCK, GPIF_WAVEFORM_BUFCON_PROM_ADDR, DownloadSize ); Progress2StdOut( 56 ); //STEP 8 //download the camcon gpif waveform pf.WriteFile2Eeprom( FilenameGpifCamCon, GPIF_WAVEFORM_CAMCON_PROM_BANK, GPIF_WAVEFORM_CAMCON_PROM_BLOCK, GPIF_WAVEFORM_CAMCON_PROM_ADDR, DownloadSize ); Progress2StdOut( 64 ); //STEP 9 //download the FIFO gpif waveform pf.WriteFile2Eeprom( FilenameGpifFifo, GPIF_WAVEFORM_FIFO_PROM_BANK, GPIF_WAVEFORM_FIFO_PROM_BLOCK, GPIF_WAVEFORM_FIFO_PROM_ADDR, DownloadSize ); hdr.Fields |= Eeprom::HEADER_GPIF_VALID_BIT; Progress2StdOut( 72 ); //STEP 10 //set the vid, pid, and did hdr.VendorId = UsbFrmwr::APOGEE_VID; hdr.Fields |= Eeprom::HEADER_VID_VALID; hdr.ProductId = UsbFrmwr::ALTA_USB_PID; hdr.Fields |= Eeprom::HEADER_PID_VALID ; hdr.DeviceId = UsbFrmwr::ALTA_USB_DID; hdr.Fields |= Eeprom::HEADER_DID_VALID; Progress2StdOut( 80 ); //STEP 11 //write the header hdr.CheckSum = Eeprom::CalcHdrCheckSum( hdr ); pf.WriteEepromHdr( hdr, HEADER_PROM_BANK, HEADER_PROM_BLOCK, HEADER_PROM_ADDR); Progress2StdOut( 88 ); //STEP 12 //write the stored serial number to the camera SetSerialNumber( serialNum ); Progress2StdOut( 100 ); //turn this off on exit m_Print2StdOut = false; }
A_BOOL RunAR6kTest(A_UINT32 Channel, A_CHAR *pSSID, MTE_WIFI_TEST_STATUS *pTestStatus) { AR6K_FIRMWARE_INFO firmware; A_STATUS status = A_OK; A_MEMZERO(&firmware,sizeof(firmware)); InitializeMTE(); if (!GetFirmwareInfo(&firmware)) { DBG_LOG_PRINT(DBG_ZONE_ERR, ("Target Firmware missing!! Aborting.. \r\n")); return FALSE; } g_WifiMTE.SSIDLength = strlen(pSSID); A_ASSERT(g_WifiMTE.SSIDLength <= 32); A_MEMCPY(g_WifiMTE.SSID,pSSID,g_WifiMTE.SSIDLength); A_ASSERT(Channel <= MAX_WIFI_CHANNELS); A_ASSERT(Channel > 0); /* look up the channel hint (in Mhz) */ g_WifiMTE.WiFiChannel = g_ChannelLookUp[Channel]; DBG_LOG_PRINT(DBG_ZONE_INIT, ("Ar6k WiFi MTE Test Start..(SSID: %s , channel:%d) \r\n", g_WifiMTE.SSID, g_WifiMTE.WiFiChannel)); do { /* init test status */ g_WifiMTE.MteStatus = MTE_WIFI_STATUS_SDIO_INIT_FAILED; if (A_FAILED(HIFInit())) { DBG_LOG_PRINT(DBG_ZONE_ERR, ("** HIFInit Failed!!! \r\n")); break; } BMIInit(); /* all failures are setup failures this point forward */ g_WifiMTE.MteStatus = MTE_WIFI_STATUS_SETUP_FAILED; g_WifiMTE.HifDevice = HIFGetDevice(); DBG_LOG_PRINT(DBG_ZONE_ERR, ("Getting Target ID... \r\n")); status = BMIGetTargetInfo(g_WifiMTE.HifDevice, &g_WifiMTE.TargetInfo); if (A_FAILED(status)) { DBG_LOG_PRINT(DBG_ZONE_ERR, ("** Failed to Get Target Information \r\n")); break; } DBG_LOG_PRINT(DBG_ZONE_INIT, ("TARGET_TYPE:0x%X TARGET_VER : 0x%X \r\n", g_WifiMTE.TargetInfo.target_type, g_WifiMTE.TargetInfo.target_ver)); status = ar6000_prepare_target(g_WifiMTE.HifDevice, g_WifiMTE.TargetInfo.target_type, g_WifiMTE.TargetInfo.target_ver); if (A_FAILED(status)) { DBG_LOG_PRINT(DBG_ZONE_ERR, ("** Failed to prepare target \r\n")); break; } status = ar6000_configure_clock (g_WifiMTE.HifDevice, g_WifiMTE.TargetInfo.target_type, g_WifiMTE.TargetInfo.target_ver, BOARD_XTAL_FREQ); if (A_FAILED(status)) { DBG_LOG_PRINT(DBG_ZONE_ERR, ("** Failed to configure target XTAL \r\n")); break; } DBG_LOG_PRINT(DBG_ZONE_INIT, ("Download Firmware ... (firmware length: %d, %s) (datapatch len: %d) \r\n", firmware.AthwlanLength, firmware.AthwlanCompressed ? "COMPRESSED" : "UNCOMPRESSED", firmware.DataPatchLength)); status = DownloadFirmware(g_WifiMTE.HifDevice, g_WifiMTE.TargetInfo.target_type, g_WifiMTE.TargetInfo.target_ver, firmware.pAthwlan, firmware.AthwlanLength, firmware.AthwlanCompressed, firmware.pDataPatch, firmware.DataPatchLength); if (A_FAILED(status)) { DBG_LOG_PRINT(DBG_ZONE_ERR, ("** Failed to download firmware \r\n")); break; } DBG_LOG_PRINT(DBG_ZONE_INIT, ("Firmware Download Complete.. \r\n")); ar6000_enable_target_console(g_WifiMTE.HifDevice,g_WifiMTE.TargetInfo.target_type); status = ar6000_set_htc_params(g_WifiMTE.HifDevice, g_WifiMTE.TargetInfo.target_type, 0, 0); if (A_FAILED(status)) { DBG_LOG_PRINT(DBG_ZONE_ERR, ("** Failed to set HTC Params \r\n")); break; } DBG_LOG_PRINT(DBG_ZONE_INIT, ("Transferring EEPROM settings .. \r\n")); status = eeprom_ar6000_transfer(g_WifiMTE.HifDevice, g_WifiMTE.TargetInfo.target_type); if (A_FAILED(status)) { DBG_LOG_PRINT(DBG_ZONE_ERR, ("** Failed to transfer EEPROM settings \r\n")); break; } DBG_LOG_PRINT(DBG_ZONE_INIT, ("Starting Target .. \r\n")); status = BMIDone(g_WifiMTE.HifDevice); if (A_FAILED(status)) { DBG_LOG_PRINT(DBG_ZONE_ERR, ("** Target failed to start \r\n")); break; } /* from here on out, all mte failures are boot failures */ g_WifiMTE.MteStatus = MTE_WIFI_STATUS_BOOT_FAILED; DBG_LOG_PRINT(DBG_ZONE_INIT, ("Connecting HTC .. \r\n")); /* connect HTC layer */ g_WifiMTE.htcHandle = HTCConnect(g_WifiMTE.HifDevice); if (g_WifiMTE.htcHandle == NULL) { DBG_LOG_PRINT(DBG_ZONE_ERR, ("** HTC connection failed \r\n")); break; } status = HTCConnectService(g_WifiMTE.htcHandle, WMI_CONTROL_SVC, &g_WifiMTE.ControlEp); if (A_FAILED(status)) { DBG_LOG_PRINT(DBG_ZONE_ERR, ("** Failed to connect to WMI control service \r\n")); break; } status = HTCConnectService(g_WifiMTE.htcHandle, WMI_DATA_BE_SVC, &g_WifiMTE.DataEp); if (A_FAILED(status)) { DBG_LOG_PRINT(DBG_ZONE_ERR, ("** Failed to connect to WMI best effort data service \r\n")); break; } DBG_LOG_PRINT(DBG_ZONE_INIT, ("HTC is connected (wmi_ctrl:%d, data:%d) ... \r\n", g_WifiMTE.ControlEp, g_WifiMTE.DataEp)); status = HTCStart(g_WifiMTE.htcHandle); if (A_FAILED(status)) { DBG_LOG_PRINT(DBG_ZONE_ERR, ("** failed to start HTC \r\n")); break; } status = WMIInit(g_WifiMTE.htcHandle,g_WifiMTE.ControlEp,g_WifiMTE.DataEp); if (A_FAILED(status)) { DBG_LOG_PRINT(DBG_ZONE_ERR, ("** failed to init WMI \r\n")); break; } status = RunConnectionTest(); } while (FALSE); pTestStatus->StatusCode = g_WifiMTE.MteStatus; pTestStatus->RSSI = g_WifiMTE.RSSI; return (A_SUCCESS(status)); }
//////////////////////////// // PROGRAM void AscentBasedUsbIo::Program(const std::string & FilenameFpga, const std::string & FilenameFx2, const std::string & FilenameDescriptor, bool Print2StdOut) { m_Print2StdOut = Print2StdOut; //STEP 1 //download usb firmware if we have to uint16_t Vid = 0; uint16_t Pid = 0; uint16_t Did = 0; GetUsbVendorInfo( Vid, Pid, Did ); if ( UsbFrmwr::CYPRESS_VID == Vid ) { DownloadFirmware(); } Progress2StdOut( 16 ); //STEP 2 // initialize prom header information Eeprom::Header hdr; memset(&hdr, 0, sizeof( hdr ) ); hdr.Size = sizeof( hdr ); hdr.Version = Eeprom::HEADER_VERSION; Progress2StdOut( 32 ); //STEP 3 //program fpga bits PromFx2Io pf( m_Usb, ASCENT_EEPROM_MAX_BLOCKS, ASCENT_EEPROM_MAX_BANKS ); uint32_t fgpaDownloadSize = 0; pf.WriteFile2Eeprom( FilenameFpga, FPGA_PROM_BANK, FPGA_PROM_BLOCK, FPGA_PROM_ADDR, fgpaDownloadSize ); //xlinix firmware bits programmed set the "buf con" size and //valid bits. for the ascent and the gee the buf con prom header is overloaded //to mean all xlinix firmware, since buf and cam con are in one package //now hdr.BufConSize = fgpaDownloadSize; hdr.Fields |= Eeprom::HEADER_BUFCON_VALID_BIT; Progress2StdOut( 48 ); //STEP 4 //download the fx2 uint32_t DownloadSize = 0; pf.WriteFile2Eeprom( FilenameFx2, FX2_PROM_BANK, FX2_PROM_BLOCK, FX2_PROM_ADDR, DownloadSize ); hdr.Fields |= Eeprom::HEADER_BOOTROM_VALID_BIT; Progress2StdOut( 64 ); //STEP 5 //download usb descriptors pf.WriteFile2Eeprom( FilenameDescriptor, DSCR_PROM_BANK, DSCR_PROM_BLOCK, DSCR_PROM_ADDR, DownloadSize ); hdr.Fields |= Eeprom::HEADER_DESCRIPTOR_VALID_BIT; Progress2StdOut( 80 ); //STEP 6 //write the header hdr.CheckSum = Eeprom::CalcHdrCheckSum( hdr ); pf.WriteEepromHdr( hdr, HEADER_PROM_BANK, HEADER_PROM_BLOCK, HEADER_PROM_ADDR); Progress2StdOut( 100 ); //turn this off on exit m_Print2StdOut = false; }