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

📄 doc2exb.c

📁 M-System DOC(Disk on a Chip) Flash芯片的诊断工具, 可以从Flash芯片中获取特定的数据信息, 用于判断芯片当前的状态.
💻 C
📖 第 1 页 / 共 3 页
字号:
/*                                                                        */
/* Returns:                                                               */
/*      flOK              : On success.                                   */
/*      flNoSpaceInVolume : Not enough space on the binary area.          */
/*------------------------------------------------------------------------*/

FLStatus firstTimeInit(Volume vol , exbStruct* exb, FLByte FAR1 * buf ,
               FLDword bufLen , IOreq* ioreq , BDKStruct* bdk ,
               FLWord exbFlags)
{
	FLWord wNumOfLogicalUnits ;
    FLDword dwLowMemFileSize ; 
	
   if (vol.moduleNo == INVALID_MODULE_NO)
   {
      FLStatus status;
      TLInfo info;

      /* Use the sockets buffer */

      exb->buffer = flBufferOf((unsigned)(exbs-exb));

      /* Find the number of blocks used needed for the EXB file */

      checkStatus(getExbInfo(&vol,buf,bufLen,exbFlags,&dwLowMemFileSize));

      /* Find TFFS heap size */

      if (!(vol.flags & VOLUME_ABS_MOUNTED))
	  {
         /* checkStatus(absMountVolume(&vol)); */
		  FLStatus status;
		 ioreq->irHandle = 0;
		 status = flAbsMountVolume(ioreq);
		 if (status != flOK)
			return status;
	  }
      ioreq->irData     = &info;
      checkStatus(vol.tl.getTLInfo(vol.tl.rec,&info));

      /* andrayk: compilation error; there is no 'chipSize' in FLFlash */
      wNumOfLogicalUnits  = (FLWord)(vol.flash->mediaSize / vol.flash->erasableBlockSize) ;
     /* Add heap for dynamic allocation not related to convertion tables */
     //exb->tffsFarHeapSize = (FLWord)(((exb->tffsHeapSize * 20) >> SECTOR_SIZE_BITS) + 1);

	 exb->tffsFarHeapSize = (FLWord)(6*1024+5*wNumOfLogicalUnits +
	 ((MTDVarsStruct *) vol.flash->mtdVars)->dwSectorsInLogicalUnit*(8+2*64))>>FL_SECTOR_SIZE_BITS+1 ;

     exb->tffsFarHeapSize = (FLWord)(1.2 *  exb->tffsFarHeapSize)  ; /* Take 20% spare */
	 //exb->tffsFarHeapSize = 3*1024+5*wNumOfLogicalUnits +
	 //((MTDVarsStruct *) vol.flash->mtdVars)->dwSectorsInLogicalUnit*(8+2*64) ;

     exb->tffsHeapSize    = INFTL_NEAR_HEAP_SIZE;

#if 0 /* Was true for INFTL only */
      if((exbFlags & FIRMWARE_NO_MASK) >> FIRMWARE_NO_SHIFT == 0)
      {
         /* virutal TABLE + physical table */
         exb->tffsFarHeapSize = (FLWord)(((exb->tffsHeapSize * 3) >> SECTOR_SIZE_BITS) + 1);
         exb->tffsHeapSize    = INFTL_NEAR_HEAP_SIZE;
      }
      else /* Old TrueFFS source */
      {
         exb->tffsFarHeapSize = 0;
         exb->tffsHeapSize = exb->tffsHeapSize * 3 + DEFAULT_DOC_STACK;
      }      
#endif

#if 0
      /*** Create russian DIMA sub partition                    ***/
      ioreq->irData     = bdk;
	  ioreq->irHandle   = 0 ;  
      bdk->length = (vol.binaryLength/vol.flash->erasableBlockSize) + 1 ;
      tffsRAMcpy (bdk->oldSign,"HIGH",BDK_SIGNATURE_NAME) ;
      tffsRAMcpy (bdk->newSign,SIGN_SPL,BDK_SIGNATURE_NAME) ;
      bdk->startingBlock=0 ;
      status = bdCall (FL_BINARY_CREATE,ioreq) ; 
#endif
      /* Check if binary partition is formated for EXB */
      ioreq->irData      = bdk;
	  ioreq->irHandle    = 0 ;  
      tffsRAMcpy (bdk->oldSign,SIGN_SPL,BDK_SIGNATURE_NAME) ;
      bdk->startingBlock = 0;
      bdk->signOffset    = EXB_SIGN_OFFSET;
      status = (bdkCall(FL_BINARY_PARTITION_INFO,ioreq,vol.flash)) ;

      if ((bdk->startingBlock < vol.binaryLength) || (status != flOK))
      {
         ExPrint("ERROR - Not enough binary area marked for EXB.\r\n");
         return flNoSpaceInVolume;
      }

      /* initialize binary area for writting the EXB file */

      bdk->length        = ((vol.binaryLength-1) >> vol.flash->erasableBlockSizeBits) +1;
      bdk->startingBlock = 0;
      bdk->signOffset    = EXB_SIGN_OFFSET;

      checkStatus(bdkCall(FL_BINARY_ERASE,ioreq,vol.flash)); /* ERASE */
      if ((exbFlags & LEAVE_EMPTY) == 0)
      {
         /* If actualy need to place firmware initialize Binary write */
         bdk->length        = vol.binaryLength;
         bdk->flags         = BDK_COMPLETE_IMAGE_UPDATE | EDC;
         flBdkVol->bdkGlobalStatus |= BDK_S_INFO_FOUND; /* do not research */
         checkStatus(bdkCall(FL_BINARY_WRITE_INIT,ioreq,vol.flash));
         tffsRAMset(BUFFER,0xff,FL_SECTOR_SIZE);
      }
      exb->exbFileOffset = 0;        /* start of exb file          */
      exb->bufferOffset  = 0;        /* start of internal buffer   */
      exb->moduleLength  = 0;        /* size of the current module */
      exb->exbFlags      = exbFlags; /* see list in doc2exb.h      */
      vol.moduleNo       = 0;        /* module IPL                 */
   }
   return flOK;
}

/*----------------------------------------------------------------------*/
/*                    p l a c e E x b B y B u f f e r                   */
/*                                                                      */
/* Place M-systems firmware file on the media.                          */
/* This routine analizes the exb file calclating the media space needed */
/* for it taking only the device specific code.                         */
/*                                                                      */
/* Note : The media must be already formated with enough binary area    */
/* already marked with the SPL signature. This routine is best used     */
/* with the format routine where the format routine is givven the first */
/* 512 bytes while the rest of the file is given with this routine      */
/*                                                                      */
/* Parameters:                                                          */
/*      vol          : Pointer identifying drive                        */
/*      buf          : Buffer containing EXB file data                  */
/*      bufLen       : Size of the current buffer                       */
/*      windowBase   : Optional set window base address                 */
/*      exbFlags     : INSTALL_FIRST - Install device as drive C:        */
/*                     FLOPPY        - Install device as drive A:        */
/*                     QUIET          - Do not show TFFS titles         */
/*                     INT15_DISABLE - Do not hook int 15               */
/*                     SIS5598       - Support for SIS5598 platforms    */
/*                     NO_PNP_HEADER - Do not place the PNP bios header */
/*                     LEAVE_EMPTY   - Leave space for firmware         */
/*                                                                      */
/* Returns:                                                             */
/*        FLStatus        : 0 on success, otherwise failed              */
/*----------------------------------------------------------------------*/

FLStatus placeExbByBuffer(Volume vol, FLByte FAR1 * buf, FLDword bufLen,
              FLWord docWinBase ,FLWord exbFlags)
{
   IOreq       ioreq;
   BDKStruct   bdk;
   FLWord      tmpWord;
   FLSDword    length = bufLen;
   exbStruct  *exb = &exbs[(FLByte)(&vol-vols)];
   BIOSHeader *hdr;
   IplHeader   *ipl;
   SplHeader   *spl;
   TffsHeader  *tffs;

   /*** Initialize binary partition call packet              ***/
   ioreq.irData   = &bdk;
   ioreq.irHandle = 0;
   bdk.signOffset = EXB_SIGN_OFFSET;
   tffsRAMcpy(bdk.oldSign,SIGN_SPL,BINARY_SIGNATURE_NAME);  

   /*** First time initialization                            ***/
   checkStatus(firstTimeInit(&vol,exb,buf,bufLen,&ioreq, &bdk, exbFlags));

   tffsRAMcpy(bdk.oldSign,SIGN_SPL,BINARY_SIGNATURE_NAME);  
   /* Initialize the rest of the binary partition call packet */
   bdk.bdkBuffer  = BUFFER;         /* internal bufer  */
   bdk.length     = sizeof(BUFFER); /* buffer size     */
   bdk.flags     |= ERASE_BEFORE_WRITE; /* Erase each unit before writing */

   /* Make sure this is a relevant part of the file */
   /* exb->exbFileOffset starts with 0              */   
   if (exb->exbFileOffset + length < exb->firmwareStart)
   {  /* We do not need to write it (cause its header & not real firmware) */
      /* => Update only exb->exbFileOffset (Offset in file)              */
      /* Before this specific device firmware */
      exb->exbFileOffset += length;
      return flOK;
   }

   /* If we got until firmware end => Preform download & Exit */
   if (exb->exbFileOffset >= exb->firmwareEnd)
   {
      /* After this specific device firmware */
      exb->exbFileOffset += length;
      if (exb->exbFileOffset >= exb->exbFileEnd)
      {
         vol.moduleNo = INVALID_MODULE_NO;
         if (vol.flash->download != NULL)
            return vol.flash->download(vol.flash); /* download IPL */
      }
      return flOK;
   }

   /* In that case we need to write only some of the bytes    */
   if (exb->exbFileOffset < exb->firmwareStart)
   {
      /* The length is calculated only from start of firmware */
      length -= exb->firmwareStart - exb->exbFileOffset;
	  /* The offset is from start of firmware                 */
      exb->exbFileOffset = exb->firmwareStart;
   }

   /* Start writting the file modules */

   while ((exb->firmwareEnd > exb->exbFileOffset) && (length >0))
   {
      /* Read next page into internal buffer */

      /* DOC2000 IPL is ROM and it assumed small pages therefore
         read only the first 256 bytes of each page.             */

      if ((vol.moduleNo == 1) && (vol.flash->mediaType == DOC_TYPE))
      {
         if (waitForFullBuffer(&vol , buf , bufLen , &length,
                               TRUE) == FALSE)  /* 256 BYTES */
         return flOK;
      }
      else
      {  /*** Wait for a full buffer ***/
         if ((waitForFullBuffer(&vol , buf , bufLen , &length,
                                FALSE) == FALSE) && /* 512 BYTES */
             (exb->exbFileOffset != exb->exbFileEnd)) /* Not last buffer */
            return flOK;
      }

      if (exb->moduleLength == 0)
      {
         /* Calculte exb->moduleLength:  
		    All modules except for the SPL start with biosHdr record
            SPL has a 2 bytes opCode preciding the biosHdr and an
            incorrect module length                                   */
      
         switch (vol.moduleNo)
         {   
             case 1: 
                /* SPL */
                hdr = &((SplHeader *)BUFFER)->biosHdr;
                /* calculate the number of buffers to use for the SPL */
                exb->moduleLength = (FLWord)((exb->splEnd-exb->splStart) >> FL_SECTOR_SIZE_BITS);
                /* Doc 2000 writes in chunks of 256 bytes therfore need to
                   double the amount of write operations */
                if (vol.flash->mediaType == DOC_TYPE)
                   exb->moduleLength = (FLWord)(exb->moduleLength << 1);
                break;

             default : /* Get size from header */
                /* Other Module - all others has BIOSHeader */
                hdr = (BIOSHeader *) BUFFER;
                exb->moduleLength = hdr->lenMod512;
				//printf ("Module Length=%d \r\n\r\n",exb->moduleLength) ;
         }
         /* Check validy of bios header */

         if ((hdr->signature[0] != 0x55) || (hdr->signature[1] != 0xAA))
         {
            ExPrint("ERROR - EXB file is missing one of the BIOS driver modules.\r\n");
            return flBadLength;
         }

         /* Update neccesary fields in the modules headers */
         switch (vol.moduleNo)
         {
            case 0:   /* IPL */
               
			   ExPrint("Writing IPL                                         \r\n");
               ExPrint("-----------                                         \r\n");
               ExPrint("- Size=1KB \r\n");

               /* The IPL length is actualy the window size in order to */
               /* supply the BIOS the expantion range. The real size    */
               /* if calculated according to the exb file header.       */
               if (vol.moduleNo==0)
                  exb->moduleLength = exb->iplMod512;

               ipl = (IplHeader *)BUFFER;

               /* Set 0000 pointer of ISA P&P Header */
               if(exb->exbFlags & NO_PNP_HEADER)
               {
                  ipl->dummy    += ((FLByte)(ipl->pnpHeader >> 8) +
                                    (FLByte)ipl->pnpHeader);
                  ipl->pnpHeader = 0;
               }

               /* Set DOC Window base explicitely */
               if( docWinBase > 0 )
               {
                  toLE2(ipl->windowBase , docWinBase);
                  ipl->dummy     -= (FLByte)( docWinBase );
                  ipl->dummy     -= (FLByte)( docWinBase >> 8 );
               }
               if (exbFlags & TWO_SPL_COPIES)
			   {
                 ipl->NoOfCopies = 2 ;
				 ipl->dummy     -= 2 ;
			   }
			   else
			   {
                 ipl->NoOfCopies = 1 ;
				 ipl->dummy     -= 1 ;
			   }
               break;

            case 1:   /* SPL */
               ExPrint("Writing SPL                                         \r\n");
               ExPrint("-----------                                         \r\n");
               ExPrint("- Size=%dKB \r\n",(exb->splEnd-exb->splStart)/1024 );
               spl = (SplHeader *)BUFFER;

⌨️ 快捷键说明

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