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

📄 doc2exb.c

📁 DOC文件系统驱动源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
   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 */

   if (exb->exbFileOffset + length < exb->firmwareStart)
   {
      /* Before this specific device firmware */
      exb->exbFileOffset += length;
      return flOK;
   }

   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;
   }

   if (exb->exbFileOffset < exb->firmwareStart)
   {
      length -= exb->firmwareStart - exb->exbFileOffset;
      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
      {
         if ((waitForFullBuffer(&vol , buf , bufLen , &length,
                                FALSE) == FALSE) && /* 512 BYTES */
             (exb->exbFileOffset != exb->exbFileEnd)) /* Not last buffer */
            return flOK;
      }

      /* Update the module length according to its header */

      if (exb->moduleLength == 0)
      {
         /* 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) /* SPL */
         {
             case 1:
                hdr = &((SplHeader *)BUFFER)->biosHdr;
                /* calculate the number of buffers to use for the SPL */
                exb->moduleLength = (word)((exb->splEnd-exb->splStart) >> 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 = (word)(exb->moduleLength << 1);
                break;

             default : /* Get size from header */
                hdr = (BIOSHeader *) BUFFER;
                exb->moduleLength = hdr->lenMod512;
         }

         /* Check validy of bios header */

         if ((hdr->signature[0] != 0x55) || (hdr->signature[1] != 0xAA))
         {
            DFORMAT_PRINT(("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 */

               /* 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    += ((byte)(ipl->pnpHeader >> 8) +
                                    (byte)ipl->pnpHeader);
                  ipl->pnpHeader = 0;
               }

               /* Set DOC Window base explicitely */

               if( docWinBase > 0 )
               {
                  toLE2(ipl->windowBase , docWinBase);
                  ipl->dummy     -= (byte)( docWinBase );
                  ipl->dummy     -= (byte)( docWinBase >> 8 );
               }
               break;

            case 1:   /* SPL */

               spl = (SplHeader *)BUFFER;

               /* calculate EXB module size */

               /* generate random run-time ID and write it into splHeader. */

               tmpWord = (word)flRandByte();
               toUNAL2(spl->runtimeID, tmpWord);
               spl->chksumFix -= (byte)(tmpWord);
               spl->chksumFix -= (byte)(tmpWord >> 8);

               /* Write TFFS heap size into splHeader. */

               toUNAL2(spl->tffsHeapSize, (word)exb->tffsHeapSize);
               spl->chksumFix -= (byte)(exb->tffsHeapSize);
               spl->chksumFix -= (byte)(exb->tffsHeapSize >> 8);

               /* set explicit DOC window base */

               if( docWinBase > 0 )
               {
                  toUNAL2(spl->windowBase, docWinBase);
                  spl->chksumFix -= (byte)(docWinBase);
                  spl->chksumFix -= (byte)(docWinBase >> 8);
               }

               break;

            case 2:   /* Socket Services OR interupt 13 driver */

               /* The doc2000 driver and or socket services start
                  at 0x4000 so we have to jump over there. */
               if (vol.flash->mediaType == DOC_TYPE)
               {
                  bdkVol->actualUpdateLen -= 0x4000 - bdkVol->curUpdateImageAddress;
                  bdkVol->curUpdateImageAddress = 0x4000;
               }
               tffs             = (TffsHeader *)BUFFER;
               tffs->chksumFix -= (byte)(exb->tffsFarHeapSize);
               tffs->chksumFix -= (byte)(exb->tffsFarHeapSize >> 8);
               toUNAL2(tffs->heapLen, exb->tffsFarHeapSize);
               exb->exbFlags   &= ~NO_PNP_HEADER;

            default:

               /* put "install as first drive" & QUIET mark
                  into the TFFS header */

               tffs = (TffsHeader *)BUFFER;
               tffs->exbFlags   = (byte)exb->exbFlags;
               tffs->chksumFix -= (byte)exb->exbFlags;

           break;
         } /* end - switch of module type */
      } /* end - first buffer of module */

      exb->moduleLength--;

      /* Write module and clean buffer */

      switch (vol.moduleNo)
      {
         case 0: /* IPL data */

            switch (vol.flash->mediaType)
            {
               case MDOC_TYPE: /* Millennium 8 - use bdk to write IPL * 2 */

                  if (exb->moduleLength == exb->iplMod512 - 1)
                  {
                    /* Milennium DiskOnChip is the only device that the IPL
                       is duplicated in the exb file. The dupplication was
                       needed in earlier versions but it is currently ignored.
                       The IPL is still written twice only that the second
                       copy is not taken from the file but the first copy is
                       simply written twice. */
                    if ((exbFlags & LEAVE_EMPTY) == 0)
                    {
                       checkStatus(bdkCall(FL_BINARY_WRITE_BLOCK,
                                           &ioreq,vol.flash));
                       checkStatus(bdkCall(FL_BINARY_WRITE_BLOCK,
                                           &ioreq,vol.flash));
                    }
                  }
                  /* Change byte #406 to non-0xFF value to force
                     Internal EEprom Mode */
                  checkStatus(vol.flash->write(vol.flash,
                  ANAND_MARK_ADDRESS,anandMark,ANAND_MARK_SIZE,EXTRA));
                  break;

               case DOC2000TSOP_TYPE: /* Doc 2000 tsop - write to block 0 */
               case MDOCP_TYPE:   /* Millennium Plus - use MTD specific routine */
               case MDOCP_16_TYPE:

                  if (vol.flash->writeIPL == NULL)
                     return flFeatureNotSupported;
                  if ((exbFlags & LEAVE_EMPTY) != 0)
                  {
                     /* Erase previous IPL if all we need is to leave
                        space for the firmware and not realy write it */
                     tffsset(BUFFER,0xff,SECTOR_SIZE);
                  }
                  checkStatus(vol.flash->writeIPL(vol.flash,
                              BUFFER,SECTOR_SIZE,
                              (byte)(exb->iplMod512 - exb->moduleLength-1),
                              FL_IPL_MODE_NORMAL));
               default: /* DiskOnChip 2000 */

                  break; /* IPL is burnt onto ROM */
            }
            break;

         default:

            if ((exbFlags & LEAVE_EMPTY) == 0)
            {
               checkStatus(bdkCall(FL_BINARY_WRITE_BLOCK,&ioreq,vol.flash));
            }
      }
      tffsset(BUFFER,0xff,sizeof(BUFFER));

      if (exb->moduleLength == 0)
         vol.moduleNo++;
   }

   if (exb->exbFileOffset >= exb->firmwareEnd)
   {
      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);
}

#endif /* WRITE_EXB_IMAGE */

⌨️ 快捷键说明

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