Пример #1
0
static int myWrite(char *inBuf, int inBufLen)
{
   static SINT32 allocSize = 0;
//<< [CTFN-SYS-024-4] Lucien.Huang : Kill more processes to avoid out of memory condition when CPE upgrade firmware for NOR flash, 2013/08/09
#ifdef BRCM_CMS_BUILD
   int pid = 0;
#endif
//>> [CTFN-SYS-024-4] End
   
   if (glbCurPtr == NULL) 
   {
      if (inBufLen < TFTP_BLKSIZE_DEFAULT)   // not enough data for a valid first packet and exit
         return -1;   

      // Allocate maximum flash image size + possible broadcom header TAG.
      // (Don't bother getting the length from the broadcom TAG, we don't
      // get a TAG if it is a whole image anyways.)
      // The Linux kernel will not assign physical pages to the buffer
      // until we write to it, so it is OK if we allocate a little more
      // than we really need.
      allocSize = cmsImg_getImageFlashSize() + cmsImg_getBroadcomImageTagSize();
      bb_error_msg("Allocating %d bytes for flash image.\n", allocSize);

//<< [CTFN-SYS-024-4] Lucien.Huang : Kill more processes to avoid out of memory condition when CPE upgrade firmware for NOR flash, 2013/08/09
#ifdef BRCM_CMS_BUILD
#ifdef DMP_STORAGESERVICE_1
      if ((pid = prctl_getPidByName("nmbd")) > 0) {
         kill(pid, SIGTERM);
         //bb_error_msg("Kill nmbd process! pid:%d\n", pid);
      }
      if ((pid = prctl_getPidByName("smbd")) > 0) {
         kill(pid, SIGTERM);
         //bb_error_msg("Kill smbd process! pid:%d\n", pid);
      }
#endif
#ifdef SUPPORT_SNTP
      if ((pid = prctl_getPidByName("sntp")) > 0) {
         kill(pid, SIGTERM);
         //bb_error_msg("Kill sntp process! pid:%d\n", pid);
      }
#endif
#ifdef CTCONFIG_3G_FEATURE
      if ((pid = prctl_getPidByName("ct_3gbackup")) > 0) {
         kill(pid, SIGTERM);
         //bb_error_msg("Kill ct_3gbackup process! pid:%d\n", pid);
      }
#endif
#ifdef DMP_X_BROADCOM_COM_DLNA_1
      system("killall bcmmserver 2>/dev/null");
      //bb_error_msg("Kill bcmmserver process!\n");
#endif
#ifdef SUPPORT_UPNP
      if ((pid = prctl_getPidByName("upnp")) > 0) {
         kill(pid, SIGTERM);
         //bb_error_msg("Kill upnp process! pid:%d\n", pid);
      }
#endif
#ifdef DMP_X_BROADCOM_COM_IPPRINTING_1
      if ((pid = prctl_getPidByName("ippd")) > 0) {
         kill(pid, SIGTERM);
         //bb_error_msg("Kill ippd process! pid:%d\n", pid);
      }
#endif
#ifdef DMP_X_BROADCOM_COM_MLD_1
      if ((pid = prctl_getPidByName("mcpd")) > 0) {
         kill(pid, SIGTERM);
         //bb_error_msg("Kill mcpd process! pid:%d\n", pid);
      }
#endif
#ifdef DMP_X_BROADCOM_COM_TR64_1
      if ((pid = prctl_getPidByName("tr64c")) > 0) {
         kill(pid, SIGTERM);
         //bb_error_msg("Kill tr64c process! pid:%d\n", pid);
      }
#endif
#ifdef DMP_X_BROADCOM_COM_WIFILAN_1
      system("killall lld2d 2>/dev/null");
      //bb_error_msg("Kill lld2d process!\n");
      system("killall wps_monitor 2>/dev/null");
      //bb_error_msg("Kill wps_monitor process!\n");
      system("killall nas 2>/dev/null");
      //bb_error_msg("Kill nas process!\n");;
      system("killall eapd 2>/dev/null");
      //bb_error_msg("Kill eapd process!\n");
      system("killall acsd 2>/dev/null");
      //bb_error_msg("Kill acsd process!\n");
      system("killall hspotap 2>/dev/null");
      //bb_error_msg("Kill hspotap process!\n");
#endif
#endif
//>> [CTFN-SYS-024-4] End

      if ((glbCurPtr = (char *) malloc(allocSize)) == NULL)
      {
         bb_error_msg("Not enough memory error.  Could not allocate %u bytes.", allocSize);   
         return -1;
      }
      bb_error_msg("Memory allocated\n");
      glbImagePtr = glbCurPtr;
   }

   // copy the data from the current packet into our buffer
   if (glbUploadSize + inBufLen < allocSize)
   {
      memcpy(glbCurPtr, inBuf, inBufLen);
      glbCurPtr += inBufLen;
      glbUploadSize += inBufLen;
   }
   else
   {
       bb_error_msg("Image could not fit into %u byte buffer.\n", allocSize);
       return -1;
   }

   return inBufLen;
}
Пример #2
0
void do_fwUpdate(void)
{
    int byteRd = 0;
    char *curPtr = NULL;
    unsigned int totalAllocatedSize = 0;
    char *buffer;
    int max;
    fd_set rfds;
    struct timeval tv;
    UBOOL8 isConfigFile;

   /* reset all of our globals before starting another download */    
    imageFormat = CMS_IMAGE_FORMAT_INVALID;
    if (imagePtr)
       free(imagePtr);
    imagePtr = NULL;
    uploadSize = 0;

	if (dataconn())
	    return;
    alarm(0);

    if ((buffer = malloc(xfer_bufsize)) == NULL)
    {
        displayMessage(UPLOAD_FAIL_NO_MEM);
        return;
    }

    max = (sock > fileno(stdin) ? sock : fileno(stdin)) + 1;
    for (;;) {
        FD_ZERO(&rfds);
        FD_SET(sock, &rfds);
        FD_SET(fileno(stdin), &rfds);
        
        tv.tv_sec = data_timeout;
        tv.tv_usec = 0;
        if (!select(max, &rfds, NULL, NULL, &tv)) {
            close(sock);
            control_printf(SL_FAILURE, "426 Kicked due to data transmission timeout.");
            if (imagePtr)
                free(imagePtr);
            free(buffer);
            displayMessage(UPLOAD_FAIL_FTP);
            return;     // exit ?
        }

		  if (!((byteRd = recv(sock, buffer, xfer_bufsize, 0))))
            break;

        if (curPtr == NULL)
        {
            // Also look in tftpd.c, which does about the same thing

            isConfigFile = cmsImg_isConfigFileLikely(buffer);
            cmsLog_debug("isConfigFile = %d", isConfigFile);
            
            if (isConfigFile)
            {
               totalAllocatedSize = cmsImg_getConfigFlashSize();
            }
            else
            {
               totalAllocatedSize = cmsImg_getImageFlashSize() + cmsImg_getBroadcomImageTagSize();
               // let smd know that we are about to start a big download
               cmsImg_sendLoadStartingMsg(msgHandle, connIfName);
            }

            if ((curPtr = (char *) malloc(totalAllocatedSize)) == NULL)
            {
               cmsLog_error("Not enough memory (%d bytes needed)", totalAllocatedSize);
               free(buffer);
               cmsImg_sendLoadDoneMsg(msgHandle);
               return;
            }
            printf("%d bytes allocated for image\n", totalAllocatedSize);
            imagePtr = curPtr;   
        }

        if (uploadSize + byteRd < totalAllocatedSize)
        {
            memcpy(curPtr, buffer, byteRd);     
            curPtr += byteRd;
            uploadSize += byteRd;
        }
        else
        {
            printf("Image could not fit into %d byte buffer.\n", totalAllocatedSize);
            free(buffer);
            free(imagePtr);
            imagePtr = NULL;
            cmsImg_sendLoadDoneMsg(msgHandle);
            return;
        }
        
	}  // end for loop to read in complete image


   free(buffer);

   
   /*
    * Now we have the entire image.  Validate it.
    */
   if ((imageFormat = cmsImg_validateImage(imagePtr, uploadSize, msgHandle)) == CMS_IMAGE_FORMAT_INVALID)
   {
      displayMessage(UPLOAD_FAIL_ILLEGAL_IMAGE);
      free(imagePtr);
      imagePtr = NULL;
      cmsImg_sendLoadDoneMsg(msgHandle);
   }
   else
   {
      printf("Image validated, size=%u format=%d, waiting for quit before flashing.\n", uploadSize, imageFormat);
      displayMessage(UPLOAD_OK);  // flash image will be done when user types bye or OK
   }

   close(sock);   // this tells the ftp client that the transfer is complete
   alarm(control_timeout);

}