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

📄 download.c

📁 hifn ipsec固件下载工具
💻 C
📖 第 1 页 / 共 5 页
字号:
                                 sframe_p,                                 rframe_p);         if (status == HFTC_RESULT_UNKNOWN)         {            /* We need to retransmit, go back to last good position */            fseek(f,fpos,SEEK_SET);            blockNumber = savedBlock;            status = HFTC_CALL_AGAIN;         }         else         {            /* Success, save our file position in case we need to retransmit */            fpos = ftell(f);            dataRecord++;            savedBlock = blockNumber;         }      } while (status == HFTC_CALL_AGAIN);   } while (HFTC_FALSE);   return status;} /* End doDownloadConfig *//*----------------------------------------------------------------------------* *   download_file *----------------------------------------------------------------------------* * @ingroup CD_API_UTIL * @brief Download a code image. * * This uses the code download API to download one code image out of code * file. * * @param filename      RO: File to download. * @param param_p       RO: Parameters pointer * * @par Externals: *    PCIDeviceID       File static variable to hold the PCI device id, used *                      to know if we need to apply the Viper Patch. *    imagesLoaded      File static variable counting the number of images *                      loaded.  Used to prevent resets from occuring after *                      the first image has been loaded. * * @return *    HFTC_STATUS_OK    Download success * * @par Errors: *    HFTC_NO_MORE_RESOURCE     Resource exhausted. *    HFTC_FILE_ERROR           Couldn't open file, or no file. * * @par Assumptions: *    Assumes a single thread doing a download.  This is because of the *    file static socket data, and MII length pad workaround file static *    data. * *----------------------------------------------------------------------------*/HFTC_Status_t download_file(char               *filename,                            download_param_t   *param_p){   HFTC_Status_t           status       = HFTC_STATUS_OK;   HFTC_Status_t           closeStatus  = HFTC_STATUS_OK;   HFTC_Unit_t             unit         = 0;   HFTC_Status_t           istatus;   /*      Pointers to allocated data.   */   HFTC_Buffer_t       *codeBuffer              = NULL;   HFTC_Buffer_t       *sframe                  = NULL;   HFTC_Buffer_t       *rframe                  = NULL;   /*      Program Download Config Variables   */   uint32_t             frameLen                = FRAMELEN;   HFTC_Boolean_t       resetState              = HFTC_TRUE; /* On First Call */   HFTC_Boolean_t       force                   = HFTC_FALSE;   /* Download options passed to HFTC_CD_SetCodeDownloadOptions */   HFTC_DownloadOptions_t downloadOptions;   /* Program Argument Data Variables */   FILE                *f                       = NULL;   HFTC_Boolean_t       fileOpened              = HFTC_FALSE;   if (DL_DEBUG)   {      printf("-->%s (%s)\n", __func__, filename);   }   do   {      /*         Set frameLen based on the buffer length plus the overhead bytes         needed.  We will need this value set properly when we call         HFTC_CD_InitCodeDownload.      */      frameLen = param_p->codeBufferLen + HFTC_CODE_FRAME_OVERHEAD_BYTE_SIZE;      /*         Allocate code buffer and frame.      */      codeBuffer = HFTC_malloc(param_p->codeBufferLen);      if (codeBuffer == NULL)      {         printf("** ERROR: Allocation of buffer size = %d failed.\n",                param_p->codeBufferLen);         status = HFTC_NO_MORE_RESOURCE;         break;      }      sframe = HFTC_malloc(frameLen);      if (sframe == NULL)      {         printf("** ERROR: Allocation of framelen for transmit = %d failed.\n",                frameLen);         status = HFTC_NO_MORE_RESOURCE;         break;      }      rframe = HFTC_malloc(frameLen);      if (rframe == NULL)      {         printf("** ERROR: Allocation of framelen for receive = %d failed.\n",                frameLen);         status = HFTC_NO_MORE_RESOURCE;         break;      }      /*         Open the input file.      */      if (strlen(filename) == 0)      {         /* Print help. */         printf("** ERROR: No file name given.\n");         printUsage();         status = HFTC_FILE_ERROR;         break;      }      f = fopen(filename,"r");      if (f == NULL)      {         printf("** ERROR: Can't open file '%s'.\n", filename);         status = HFTC_FILE_ERROR;         break;      }      fileOpened = HFTC_TRUE;      if (DL_DEBUG)      {         printf("   %s opened %s\n", __func__, filename);      }      printf("  Downloading %s...%s",             filename,             strlen(filename) > 25 ? "\n    " : " ");      fflush(stdout);      /*         Open up a socket for send/receive of download data.       */      socket_fd_fs = HFTC_socket_open(param_p->interface, &socket_addr_fs,                                      HFTC_TRUE,                                      HFTC_PPCI_DEFAULT_TIMEOUT_MILLISECONDS);      if (socket_fd_fs == HFTC_INVALID_SOCKET_FD)      {         printf("** ERROR: socket open on interface '%s' failed!\n",                param_p->interface);         status = HFTC_SOCKET_ERROR;         break;      }      /*         Set any download options that we need.      */      if (param_p->mii133MHzDownload == HFTC_TRUE)      {         downloadOptions.version = HFTC_DOWNLOAD_OPTIONS_VERSION_1;         downloadOptions.mii133MHzDownload = HFTC_TRUE;         status = HFTC_CD_SetCodeDownloadOptions(unit, &downloadOptions);      }      if (status != HFTC_STATUS_OK)      {         printf("Set code download options failed; status = %s (%d).\n",                HFTC_Status_t_text(status), status);         break;      }      /*         Do the initCodeDownload call.      */      if (DL_DEBUG)      {         printf("   %s first init code download.  resetState=%s\n", __func__,                HFTC_Boolean_t_text(resetState));      }      status = doInitCodeDownload(unit,                                  resetState,                                  param_p,                                  frameLen,                                  sframe,                                  rframe);      resetState = HFTC_FALSE;      switch (status)      {         case HFTC_STATUS_OK:            if (DL_DEBUG)            {               printf("Successful init.\n");            }            break;         case HFTC_NOT_INITIALIZED:            if (DL_DEBUG)            {               printf("Boot ROM or DIAG code not running; %s",                (param_p->noSoftBootReset == HFTC_FALSE)                  ? "attempt soft boot reset.\n"                  : "continuing.\n");            }            force = HFTC_FALSE;            break;         default:            printf("** ERROR: Init code download failed.  Status = %s (%d).\n",                   HFTC_Status_t_text(status), status);            force = HFTC_TRUE;            break;      }      /*         Now we can gather some information and make sure the image will load.         We use a separate status here because we may want to still be able to         try doing a soft boot reset even if we couldn't get information.      */      istatus = doInfoGathering(f,                                unit,                                param_p->processorType,                                param_p->codeBufferLen,                                codeBuffer);      if (istatus != HFTC_STATUS_OK)      {         printf("Information-gathering failure.  Status = %s (%d).\n",                HFTC_Status_t_text(istatus), istatus);         status = istatus;         break;      }      /*         Softboot reset.         A soft boot reset may change the PPCI Address on the hardware.         Note that if a registration call was being done above, we would         need to do a registration call again before using the UT-API.         However, we have not done a registration call in this example, so         we don't need to register again.  Also, the code here is still         within the Download API realm, which knows that a soft boot reset         may change the PPCI address.  The call found a little lower to         doInitCodeDownload will eventually call HFTC_CD_InitCodeDownload,         which will reset the Download APIs concept of the PPCI address.      */      if ((param_p->forceSoftBootReset == HFTC_TRUE) ||          ((status != HFTC_STATUS_OK) &&           (param_p->noSoftBootReset == HFTC_FALSE)))      {         if (imagesLoaded > 0)         {            printf("\n\n"                   "Reset needed, yet this is not the first image loaded.\n"                   "This indicates a problem which will require a reset\n"                   "before loading.  Use the --force-reset flag to accomplish\n"                   "the reset.\n\n");            fflush(stdout);            break;         }         printf("reset...");         fflush(stdout);         status = doSoftBootReset(unit, force, sframe);         if (status != HFTC_STATUS_OK)         {            printf("Soft boot reset failed.  status = %s (%d).\n",                   HFTC_Status_t_text(status), status);            break;         }         /* Sleep a bit after the reset */         status = HFTC_nanosleep(250000000);         if (status != HFTC_STATUS_OK)         {            printf("\nHFTC_nanosleep failed, status = %s (%d)\n",                  HFTC_Status_t_text(status), status);            break;         }         /*            After a soft boot reset, the targets PPCI Address gets reset.            So, we reset the addresses here.         */         param_p->destPPCIAddrDpu = DEST_PPCIADDR_DPU;         param_p->destPPCIAddrEsc = DEST_PPCIADDR_ESC;         resetState = HFTC_TRUE;         /*            Since we just reset, apply the Viper reset patch if this is a            Viper.  Also, since we know this is a viper, we know we don't            need the MII length adjust, so set that parameter to false.  If            it is not a Viper, check if the load is over the MII.         */         if (is_viper())         {            status = viper_reset_patch(param_p);            MIIAdjust = HFTC_FALSE;         }         else if (param_p->miiDownload == HFTC_FALSE)         {            MIIAdjust = HFTC_FALSE;         }         /*            Do the initCodeDownload call again.  We are doing this again            because we called softbootreset.         */         if (DL_DEBUG)         {            printf("   %s init post soft reset.  resetState=%s\n", __func__,                   (resetState == HFTC_TRUE) ? "TRUE" : "FALSE");         }         status = doInitCodeDownload(unit,                                     resetState,                                     param_p,                                     frameLen,                                     sframe,                                     rframe);         if (status != HFTC_STATUS_OK)         {            printf("Init code download failed.  status = %s (%d).\n",                   HFTC_Status_t_text(status), status);            break;         }         resetState = HFTC_FALSE;      }      /*         Get back to the start of the file.      */      rewind(f);      /*         Now that we know we have a good image, start the download!      */      status = doCodeDownload(f,                              unit,                              param_p->codeBufferLen,                              frameLen,                              codeBuffer,                              sframe,                              rframe);      if (status != HFTC_STATUS_OK)      {         printf("Download failed!  status = %s (%d)\n",                HFTC_Status_t_text(status), status);         break;      }      /*         Verify that the code image was properly downloaded.      */      if (param_p->noVerify == HFTC_FALSE)      {         status = doCodeVerify(unit, frameLen, sframe, rframe);         if (status != HFTC_STATUS_OK)         {            printf("Verify failed!  status = %s (%d)\n",                   HFTC_Status_t_text(status), status);            break;         }      }      /*         Set to do long SDRAM test if requested      */      if (param_p->longSdramTest == HFTC_TRUE)      {         printf("Set to run long SDRAM test.  This runs as part of POST.\n");         status = setLongSdramTest(unit, frameLen, sframe, rframe);         if (status != HFTC_STATUS_OK)         {            printf("Set of Long SDRAM Test failed.  status = %s (%d)\n",                   HFTC_Status_t_text(status), status);            if (status == HFTC_INVALID_ENUM)            {               printf("Option not available for this firmware type,\n");               printf("thus the option is being ignored for this .cdl.\n");               status = HFTC_STATUS_OK;            }            else            {               break;            }         }         printf("Note: The SDRAM test may take up to %d seconds to run.\n",                RETRANSMIT_RETRY_SECONDS_LONG_POST);      }

⌨️ 快捷键说明

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