⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 download.c

📁 hifn ipsec固件下载工具
💻 C
📖 第 1 页 / 共 5 页
字号:
 * * @param unit          RO: Unit number of target being downloaded. * @param force         RO: When true indicates that we wish to force a *                          reset even if the processor type is *                          unrecognized. * @param sframe        WO: Pointer to buffer for frame to send. * * @par Externals: *    None. * * @return * * @par Errors: *    None. * * @par Assumptions: *    None. * *----------------------------------------------------------------------------*/staticHFTC_Status_t doSoftBootReset(HFTC_Unit_t          unit,                              HFTC_Boolean_t       force,                              HFTC_Buffer_t       *sframe){   HFTC_Status_t        status                  = HFTC_STATUS_OK;   uint32_t             sendFrameLen;   uint32_t             bytesSent;   if (DL_DEBUG)   {      printf("-->%s unit=%d, force=%s\n", __func__,             unit, HFTC_Boolean_t_text(force));   }   /*      Do softboot reset.   */   do   {      status = HFTC_CD_SoftBootReset(unit, force,                                       &sendFrameLen, sframe);      if (status == HFTC_STATUS_OK)      {         /* Send the frame. */         if (MIIAdjust == HFTC_TRUE)         {            HFTC_MII_LENGTH_ADJUST(sendFrameLen);         }         status = HFTC_socket_sendto(socket_fd_fs, sframe, sendFrameLen,                                     &socket_addr_fs, &bytesSent);         if (status != HFTC_STATUS_OK || bytesSent != sendFrameLen)         {            printf("Transmit failed!  Status = %s (%d).\n",                   HFTC_Status_t_text(status), status);            status = HFTC_SOCKET_ERROR;            break;         }      }   } while (status == HFTC_RESULT_UNKNOWN);   if (DL_DEBUG)   {      printf("<--%s status=%s\n", __func__,             HFTC_Status_t_text(status));   }   return status;} /* End doSoftBootReset *//*----------------------------------------------------------------------------* *   doInfoGathering *----------------------------------------------------------------------------* * @ingroup CD_API_UTIL * @brief Gather information to make sure the image is compatible with target. * * @param f             RO: File handle of cdl file * @param unit          RO: Unit number of target being downloaded. * @param processorType RO: DPU or eSC * @param codeBufferLen RO: * @param codeBuffer    WO: * * @par Externals: *    PCIDeviceID       File static variable to hold the PCI device id, used *                      to know if we need to apply the Viper Patch. * * @return * * @par Errors: *    None. * * @par Assumptions: *    None. * *----------------------------------------------------------------------------*/staticHFTC_Status_t doInfoGathering(FILE                *f,                              HFTC_Unit_t          unit,                              HFTC_Processor_t     processorType,                              uint32_t             codeBufferLen,                              HFTC_Buffer_t       *codeBuffer){   HFTC_Status_t        status                  = HFTC_STATUS_OK;   HFTC_HardwareVer_t   hardwareVer;   HFTC_SoftwareVer_t   softwareVer;   HFTC_Boolean_t       resetState;   int                  freadResult;   /*      Now we can gather some information and make sure the image will load.      We don't really care about what versions are running, but the call is      there to test the interface.  This also verifies that the header has a      compatible image.   */   do   {      /*         Gather information on the hardware.      */      status = HFTC_CD_GetHardwareVersion(unit, &hardwareVer);      if (status != HFTC_STATUS_OK)      {         printf("** ERROR: Get hardware version failed.  Status = %s (%d).\n",                HFTC_Status_t_text(status), status);         break;      }      /*         Save off the PCI Device ID so we know if we need to apply the Viper         patch.      */      PCIDeviceID = hardwareVer.PCIDeviceID;      /*         Gather information on the firmware image.      */      status = HFTC_CD_GetCodeVersion(unit, &softwareVer);      if (status != HFTC_STATUS_OK)      {         printf("** ERROR: Get code version failed.  Status = %s (%d).\n",                HFTC_Status_t_text(status), status);         break;      }      resetState = HFTC_TRUE;      do      {         /* Read some (more) data */         freadResult = fread(codeBuffer, codeBufferLen, 1, f);         if (freadResult != 1)         {            printf("** ERROR: Read of file failed.\n");            status = HFTC_UNEXPECTED_ERROR;            break;         }         status = HFTC_CD_GetImageVersion(resetState, processorType,                                          codeBufferLen, codeBuffer,                                          &softwareVer);         resetState = HFTC_FALSE;      } while (status == HFTC_CALL_AGAIN);      if (status != HFTC_STATUS_OK)      {         if (status == HFTC_INCONSISTENT)         {            printf("** ERROR: Compatible image (for specified processor %d) "                   "not found.  ",                     processorType);            printf("status = %s (%d).\n",                   HFTC_Status_t_text(status), status);         }         else         {            printf("** ERROR: Get image version failed.  Status = %s (%d).\n",                   HFTC_Status_t_text(status), status);         }         break;      }      /*         Check that this image is compatible with the hardware.      */      status = HFTC_CD_CheckCodeVersions(unit, &softwareVer);      switch (status)      {         case HFTC_STATUS_OK:            /* Print out the version of code in the file. */            printf("version %d.%d.%d.%d...  ",                   softwareVer.majorRevision, softwareVer.minorRevision,                   softwareVer.maintRevision, softwareVer.buildRevision);            break;         case HFTC_UNKNOWN_VERSION:            printf("** ERROR: "                   "Can't determine if the code file has a good image.\n");            break;         case HFTC_INVALID_VERSION:            printf("** ERROR: The image in this code file is not compatible "                   "with the hardware.\n");            break;         case HFTC_INVALID_DATA:            printf("** ERROR: The version information has a problem.\n");            break;         case HFTC_INVALID_USE:            printf("** ERROR: "                   "The program has a problem calling CheckCodeVersions.\n");            break;         default:            printf("** ERROR: I have no idea what a check with a status "                   "of %s (%d) means.\n",                   HFTC_Status_t_text(status), status);            break;      }   } while (HFTC_FALSE);   return status;} /* End doInfoGathering *//*----------------------------------------------------------------------------* *   doCodeDownload *----------------------------------------------------------------------------* * @ingroup CD_API_UTIL * @brief Do the actual code download in the non error path. * * Pseudo code for the function below is as follows: * * save file pos * *    do * *       do *          read next config block *          generate a frame to transmit *       while call again * *       exchange frames * *       if result unknown *          rewind *       else *          save new file pos *       end * *    while call again * * @param f             RO: File handle of cdl file * @param unit          RO: Unit number of target being downloaded. * @param codeBufferLen RO: The size of the codeBuffer buffer. * @param frameLen      RO: The maximum length of a frame, the size of the *                          sframe buffer and rframe buffer. * @param codeBuffer    WO: A buffer to hold pieces of code read out of the *                          cdl file. * @param sframe        WO: Pointer to buffer for frame to send. * @param rframe        WO: Pointer to buffer where frame is received. * * @par Externals: *    None. * * @return * * @par Errors: *    None. * * @par Assumptions: *    None. * *----------------------------------------------------------------------------*/staticHFTC_Status_t doCodeDownload(FILE                *f,                             HFTC_Unit_t          unit,                             uint32_t             codeBufferLen,                             uint32_t             frameLen,                             HFTC_Buffer_t       *codeBuffer,                             HFTC_Buffer_t       *sframe,                             HFTC_Buffer_t       *rframe){   HFTC_Status_t        status                  = HFTC_STATUS_OK;   uint32_t             sendFrameLen;   int                  fpos;   int                  freadResult;   /*      Start the download!   */   if (DL_DEBUG)   {      printf("-->%s\n", __func__);   }   /* Save off our file position in case we need to retransmit */   fpos = ftell(f);   do   {      do      {         /*            Read some (more) data.         */         freadResult = fread(codeBuffer, codeBufferLen, 1, f);         if (freadResult != 1)         {            printf("read of file during download failed.\n");            status = HFTC_UNEXPECTED_ERROR;            return status;         }         /*            Generate a frame to transmit         */         status = HFTC_CD_GenerateCodeFrame(unit, codeBufferLen, codeBuffer,                                          &sendFrameLen, sframe);      } while (status == HFTC_CALL_AGAIN);      if (status != HFTC_STATUS_OK)      {         /*            If the status is not OK, then something went wrong.  Abort            the download.         */         printf("Problem in generating Code Frame, status = %s (%d)\n",                HFTC_Status_t_text(status), status);         break;      }      /*         Exchange frames      */      status = exchangeFrames(unit, frameLen, sendFrameLen, CodeDownLoad,                              sframe, rframe);      if ((status == HFTC_RESULT_UNKNOWN) || (status == HFTC_RESEND))      {         /* We need to retransmit, go back to last good position */         fseek(f,fpos,SEEK_SET);         status = HFTC_CALL_AGAIN;  /* We need to try again */      }      else      {         /* Success, save our file position in case we need to retransmit */         fpos = ftell(f);      }   } while (status == HFTC_CALL_AGAIN);   if (DL_DEBUG)   {      printf("<--%s status = %s (%d)\n", __func__,             HFTC_Status_t_text(status), status);   }   return status;} /* End doCodeDownload *//*----------------------------------------------------------------------------* *   doCodeVerify *----------------------------------------------------------------------------* * @ingroup CD_API_UTIL * @brief Code verify in the non error path. * * The logic in this routine is similar to that in doCodeDownload.  One * notable difference is that since the call to HFTC_CD_VerifyCodeImage * can't go back and send old data, the logic internal to the API keeps track * of where the last verify was done, and it backs up on its own.  Thus, we * loop for not only a return value of HFTC_CALL_AGAIN, but also for a * return value of HFTC_RESULT_UNKNOWN, where the API will do its own * retransmit (by issuing us the same memory read to transmit again) * * @param unit          RO: Unit number of target being downloaded. * @param frameLen      RO: The maximum length of a frame, the size of the *                          sframe buffer and rframe buffer. * @param sframe        WO: Pointer to buffer for frame to send. * @param rframe        WO: Pointer to buffer where frame is received. * * @par Externals: *    None. * * @return * * @par Errors: *    None. * * @par Assumptions: * *----------------------------------------------------------------------------*/staticHFTC_Status_t doCodeVerify(HFTC_Unit_t          unit,                           uint32_t             frameLen,                           HFTC_Buffer_t       *sframe,                           HFTC_Buffer_t       *rframe){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -