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

📄 doc2exb.c

📁 DOC文件系统驱动源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
   /* Initialize the volumes EXB fields */

   firmwareHeader = (FirmwareHeader FAR1*)flAddLongToFarPointer(buf,
                     (sizeof(ExbGlobalHeader) + (i * sizeof(FirmwareHeader))));
   i = &vol - vols;

   /* Save firmware files statstics recieved from the files header */
   exbs[i].firmwareStart = LE4(firmwareHeader->startOffset);
   exbs[i].firmwareEnd   = LE4(firmwareHeader->endOffset);
   exbs[i].splStart      = LE4(firmwareHeader->splStartOffset);
   exbs[i].splEnd        = LE4(firmwareHeader->splEndOffset);
   exbs[i].exbFileEnd    = LE4(globalHeader->fileSize);

   /* Calculate the binary partition size (good bytes) used to
      hold the EXB file.                                       */

   exbs[i].iplMod512 = (word)((exbs[i].splStart - exbs[i].firmwareStart)
                              >> SECTOR_SIZE_BITS);

   switch (vol.flash->mediaType)
   {
      /* NFTL formated device - IPL is placed on the binary partition */

      case DOC_TYPE:

         /* Size of EXB minus IPL which is placed in ROM */
         vol.binaryLength = exbs[i].firmwareEnd - exbs[i].splStart + 0x4000;
         break;

     case MDOC_TYPE:        /* Millennium 8, write data as is */

         /* Size of entire EXB */
         vol.binaryLength = exbs[i].firmwareEnd - exbs[i].firmwareStart;
         break;

      /* INFTL formated device - IPL is not placed on the binary
         partition, but on a dedicated flash area */

     case DOC2000TSOP_TYPE: /* DOC2000 TSOP   */
     case MDOCP_TYPE:       /* MDOC PLUS 32MB */
     case MDOCP_16_TYPE:    /* MDOC PLUS 16MB */

        vol.binaryLength  = exbs[i].firmwareEnd - exbs[i].splStart;
        break;

     default :
        DFORMAT_PRINT(("ERROR - Firmware formater reports A None DiskOnChip media.\r\n"));
        return flBadParameter;
   }
   return flOK;
}

/*------------------------------------------------------------------------*/
/*                    w a i t F o r H a l f B u f f e r                   */
/*                                                                        */
/* Increament the EXB file pointers and store the files data unit a       */
/* full sector of data is read.                                           */
/*                                                                        */
/* Parameters:                                                            */
/*  exbs[i].bufferOffset  : size of the buffer already filled with data   */
/*  exbs[i].exbFileOffset : offset from the beginning of the file         */
/*  exbs[i].buffer.data   : internal volume buffer accumulation file data */
/*  buf                   : buffer containing the files data              */
/*  bufLen                : Length of the buffer containing the file data */
/*  length                : Length of the buffer not yet used             */
/*  half                  : Wait for full 512 bytes of only 256           */
/* Returns:                                                               */
/*      boolean         : TRUE on full buffer otherwise FALSE.            */
/*      length          : Updated length of unused buffer                 */
/*------------------------------------------------------------------------*/

FLBoolean waitForFullBuffer(Volume vol , byte FAR1 * buf ,
                dword bufLen , Sdword * length,FLBoolean half)
{
  word bufferEnd;
  word tmp;
  byte i = &vol - vols;

  if (half == TRUE)
  {
     bufferEnd = (SECTOR_SIZE >> 1);
  }
  else
  {
     bufferEnd = SECTOR_SIZE;
  }

  tmp = (word)TFFSMIN(*length , bufferEnd - exbs[i].bufferOffset);

  tffscpy(exbs[i].buffer->flData + exbs[i].bufferOffset ,
          flAddLongToFarPointer(buf,(bufLen-(*length))), tmp);
  exbs[i].bufferOffset  += tmp;
  exbs[i].exbFileOffset += tmp;
  *length           -= tmp;
  if (*length+tmp < bufferEnd)
     return FALSE;

  exbs[i].bufferOffset = 0;
  return TRUE;
}

/*------------------------------------------------------------------------*/
/*                    f i r s t T i m e I n i t                           */
/*                                                                        */
/* Initialize data structures for placing exb file.                       */
/* full sector of data is read.                                           */
/*                                                                        */
/* Actions:                                                               */
/*   1) Analize exb file buffer.                                          */
/*   2) Calculate TFFS heap size.                                         */
/*   3) Check if binary area with SPL signature is big enough.            */
/*   4) Calculate SPL start media address                                 */
/*   5) Calculate binary area used for the firmware.                      */
/*   6) Initialize the volumes EXB record.                                */
/*                                                                        */
/* Parameters:                                                            */
/*    vol    : Pointer to volume record describing the volume.            */
/*    exb    : Pointer to exb record describing the volume.               */
/*    buf    : Exb file buffer.                                           */
/*    bufLen : Length of exb file buffer.                                 */
/*    ioreq  : Internal ioreq record for binary operaions.                */
/*    bdk    : Bdk record which is a part of the ioreq packet.            */
/*                                                                        */
/* Affected Variables.                                                    */
/*                                                                        */
/* Returns:                                                               */
/*      flOK              : On success.                                   */
/*      flNoSpaceInVolume : Not enough space on the binary area.          */
/*------------------------------------------------------------------------*/

FLStatus firstTimeInit(Volume vol , exbStruct* exb, byte FAR1 * buf ,
               dword bufLen , IOreq* ioreq , BDKStruct* bdk ,
               word exbFlags)
{
   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));

      /* Find TFFS heap size */

      if (!(vol.flags & VOLUME_ABS_MOUNTED))
         checkStatus(absMountVolume(&vol));
      ioreq->irData     = &info;
      checkStatus(vol.tl.getTLInfo(vol.tl.rec,&info));
      exb->tffsHeapSize = (dword)(vol.flash->chipSize * vol.flash->noOfChips) >> info.tlUnitBits;

      /* Add heap for dynamic allocation not related to convertion tables */

      if((exbFlags & FIRMWARE_NO_MASK) >> FIRMWARE_NO_SHIFT == 0)
      {
         /* virutal TABLE + physical table */
         exb->tffsFarHeapSize = (word)(((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;
      }      

      /* Check if binary partition is formated for EXB */

      bdk->startingBlock = 0;
      ioreq->irData      = bdk;
      status = bdkCall(FL_BINARY_PARTITION_INFO,ioreq,vol.flash);

      if ((bdk->startingBlock < vol.binaryLength) || (status != flOK))
      {
         DFORMAT_PRINT(("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;
         bdkVol->bdkGlobalStatus |= BDK_S_INFO_FOUND; /* do not research */
         checkStatus(bdkCall(FL_BINARY_WRITE_INIT,ioreq,vol.flash));
         tffsset(BUFFER,0xff,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, byte FAR1 * buf, dword bufLen,
              word docWinBase ,word exbFlags)
{
   IOreq       ioreq;
   BDKStruct   bdk;
   word        tmpWord;
   Sdword      length       = bufLen;
   byte        anandMark[2] = {0x55,0x55};
   exbStruct*  exb          = &exbs[(byte)(&vol-vols)];
   BIOSHeader* hdr;
   IplHeader   *ipl;
   SplHeader   *spl;
   TffsHeader  *tffs;

   /* Initialize binary partition call packet */

   tffscpy(bdk.oldSign,SIGN_SPL,BINARY_SIGNATURE_NAME);  /* firmware signature */
   ioreq.irData   = &bdk;
   bdk.signOffset = EXB_SIGN_OFFSET;
   ioreq.irHandle = 0;

   /* First time initialization */

   checkStatus(firstTimeInit(&vol,exb,buf,bufLen,&ioreq, &bdk, exbFlags));

   /* Initialize the rest of the binary partition call packet */

⌨️ 快捷键说明

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