Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

777 lines
31 KiB

  1. /*
  2. * $Log: V:/Flite/archives/TrueFFS5/Src/DOC2EXB.C_V $
  3. *
  4. * Rev 1.26 Apr 15 2002 07:35:12 oris
  5. * Moved doc2exb internal functions declaration to blockdev.c.
  6. * Make sure all relevant data is stored in little endian format.
  7. *
  8. * Rev 1.25 Feb 19 2002 20:58:28 oris
  9. * Moved include directive and routine prototypes from H file.
  10. *
  11. * Rev 1.24 Jan 23 2002 23:31:18 oris
  12. * Removed warnings.
  13. * Replaced Alon based DiskOnChip writeIPL code with the MTD writeIPL routine.
  14. *
  15. * Rev 1.23 Jan 21 2002 20:44:02 oris
  16. * Bad support for firmware other then the default 3 firmwares (TrueFFS 4.3 backward compatibility firmware).
  17. * Added support for DiskOnChip Millennium Plus 16MB firmware.
  18. * Missing far heap initialization for DiskOnChip 2000 firmware.
  19. *
  20. * Rev 1.22 Jan 17 2002 22:58:32 oris
  21. * Added new flags for placeExbByBuffer - Choose firmware to place
  22. * Added firmware number to getExbInfo().
  23. * Changed debug print to Dformat print.
  24. * Removed exb size calculation when writing SPL - It is done as part of the firmware build
  25. * Added support for far malloc heap.
  26. * All DiskOnChip use the same STACK size definition.
  27. *
  28. * Rev 1.21 Nov 08 2001 10:44:50 oris
  29. * Removed warnings.
  30. *
  31. * Rev 1.20 Sep 24 2001 18:23:10 oris
  32. * Removed warnings.
  33. *
  34. * Rev 1.19 Sep 16 2001 21:47:42 oris
  35. * Bug fix - support for 1KB IPL code for DiskOnChip2000 tsop.
  36. *
  37. * Rev 1.18 Sep 15 2001 23:44:54 oris
  38. * Bug fix - The last 512 bytes of the last firmware were not written, and IPL was not loaded.
  39. *
  40. * Rev 1.17 Jul 30 2001 17:57:36 oris
  41. * Removed warrnings
  42. *
  43. * Rev 1.16 Jul 30 2001 00:20:52 oris
  44. * Support new IPL and SPL formats.
  45. *
  46. * Rev 1.15 Jul 13 2001 01:00:08 oris
  47. * Changed constant stack space from magic numbers to contents.
  48. * Added erase before write for the binary write operation.
  49. *
  50. * Rev 1.14 Jun 17 2001 08:17:16 oris
  51. * Changed placeExbByBuffer exbflags argument to word instead of byte to support /empty flag.
  52. * Adjust exb size field to fit OSAK 4.3 format.
  53. * Added \empty flag - Leaves exb space empty.
  54. *
  55. * Rev 1.13 May 29 2001 19:47:12 oris
  56. * Bug fix - trueffs heap size discounted boot units (heap too small)
  57. * Doc2000 exbOffset hardcoded to 40.
  58. *
  59. * Rev 1.12 May 16 2001 21:16:50 oris
  60. * Change "data" named variables to flData to avoid name clashes.
  61. * Removed warnings.
  62. *
  63. * Rev 1.11 May 09 2001 00:31:52 oris
  64. * Bug fix - Added check status to intializaion routine of place EXB by buffer.
  65. *
  66. * Rev 1.10 May 06 2001 22:41:34 oris
  67. * Reduced tffs head size for Millennium Plus and DOC2000 tsop devices.
  68. * Removed warnings.
  69. *
  70. * Rev 1.9 Apr 12 2001 06:48:46 oris
  71. * Added call to download routine in order to load new IPL.
  72. *
  73. * Rev 1.8 Apr 10 2001 16:40:22 oris
  74. * Removed warrnings.
  75. *
  76. * Rev 1.7 Apr 09 2001 14:59:04 oris
  77. * Reduced exb size read by the SPL to minimum.
  78. *
  79. * Rev 1.6 Apr 03 2001 18:08:42 oris
  80. * Bug fix - exb flags were not properly written.
  81. *
  82. * Rev 1.5 Apr 03 2001 16:34:50 oris
  83. * Removed unsused variables.
  84. *
  85. * Rev 1.4 Apr 03 2001 14:36:46 oris
  86. * Completly reviced in order to support alon devices.
  87. *
  88. * Rev 1.3 Apr 02 2001 00:54:32 oris
  89. * Added doc2000 exb family.
  90. * Supply the exact length of the exb in the binary partition.
  91. * Removed the no_pnp_header from the media.
  92. * Bug fix for calculation Spl size.
  93. *
  94. * Rev 1.2 Apr 01 2001 07:49:42 oris
  95. * Updated copywrite notice.
  96. * Added support for doc2300 firmware.
  97. * Bug fixes for mdoc plus.
  98. * Added support for 1k IPL.
  99. * Added consideration in media type in calculating tffs heap size.
  100. * Changed h\w to h/w
  101. * Changed 2400 family to doc plus family.
  102. *
  103. * Rev 1.1 Feb 08 2001 10:37:54 oris
  104. * Bug fix for unaligned file signature
  105. *
  106. * Rev 1.0 Feb 02 2001 12:59:48 oris
  107. * Initial revision.
  108. *
  109. */
  110. /***********************************************************************************/
  111. /* M-Systems Confidential */
  112. /* Copyright (C) M-Systems Flash Disk Pioneers Ltd. 1995-2001 */
  113. /* All Rights Reserved */
  114. /***********************************************************************************/
  115. /* NOTICE OF M-SYSTEMS OEM */
  116. /* SOFTWARE LICENSE AGREEMENT */
  117. /* */
  118. /* THE USE OF THIS SOFTWARE IS GOVERNED BY A SEPARATE LICENSE */
  119. /* AGREEMENT BETWEEN THE OEM AND M-SYSTEMS. REFER TO THAT AGREEMENT */
  120. /* FOR THE SPECIFIC TERMS AND CONDITIONS OF USE, */
  121. /* OR CONTACT M-SYSTEMS FOR LICENSE ASSISTANCE: */
  122. /* E-MAIL = [email protected] */
  123. /***********************************************************************************/
  124. /*****************************************************************************
  125. * File Header *
  126. * ----------- *
  127. * Project : TrueFFS source code *
  128. * *
  129. * Name : doc2exb.c *
  130. * *
  131. * Description : This file contains the code for analizing and writing *
  132. * M-Systems EXB firmware files *
  133. * *
  134. *****************************************************************************/
  135. #include "doc2exb.h"
  136. #include "bddefs.h"
  137. #ifdef WRITE_EXB_IMAGE
  138. extern FLStatus absMountVolume(Volume vol);
  139. #define BUFFER exb->buffer->flData
  140. exbStruct exbs[SOCKETS];
  141. #define roundedUpShift(a,bits) (((a - 1) >> bits)+1)
  142. /*----------------------------------------------------------------------*/
  143. /* g e t E x b I n f o */
  144. /* */
  145. /* Analize M-systems firmware file */
  146. /* Analizes M-systems firmware (exb) file, calclating the media space */
  147. /* required for it. */
  148. /* */
  149. /* Parameters: */
  150. /* vol : Pointer identifying drive */
  151. /* buf : Pointer to EXB file buffer */
  152. /* bufLen : Size of the buffer */
  153. /* bufFlags : Flags for the EXB - specifing type of */
  154. /* firmware to extract from the EXB file. */
  155. /* */
  156. /* Returns: */
  157. /* FLStatus : flOK on success. */
  158. /* flBadLength if buffer size is too small */
  159. /* flBadParameter on any other failure */
  160. /* vol.binaryLength : Total size needed in the binary partition */
  161. /* exbs[i].firmwareStart : offset of the firmware begining in the file */
  162. /* exbs[i].firmwareEnd : offset of the firmware end in the file */
  163. /* exbs[i]l.splOffset : offset of the spl start in the file */
  164. /* exbs[i]l.exbFileEnd : Total exb file size. */
  165. /*----------------------------------------------------------------------*/
  166. FLStatus getExbInfo(Volume vol, void FAR1 * buf, dword bufLen, word exbFlags)
  167. {
  168. byte i;
  169. byte mediaType;
  170. ExbGlobalHeader FAR1* globalHeader = (ExbGlobalHeader FAR1*)buf;
  171. FirmwareHeader FAR1* firmwareHeader = (FirmwareHeader FAR1*)
  172. flAddLongToFarPointer(buf,sizeof(ExbGlobalHeader));
  173. /* Make sure size given is big enough */
  174. if (bufLen < sizeof(FirmwareHeader) * LE4(globalHeader->noOfFirmwares) +
  175. sizeof(ExbGlobalHeader))
  176. {
  177. DFORMAT_PRINT(("ERROR - Buffer size not big enough.\r\n"));
  178. return flBadLength;
  179. }
  180. /* Make sure this is an M-systems EXB file */
  181. if (tffscmp(globalHeader->mSysSign,SIGN_MSYS,SIGN_MSYS_SIZE) != 0)
  182. {
  183. DFORMAT_PRINT(("ERROR - Given file is not M-systems EXB file.\r\n"));
  184. return flBadParameter;
  185. }
  186. i = (exbFlags & FIRMWARE_NO_MASK) >> FIRMWARE_NO_SHIFT;
  187. if(i == 0)
  188. {
  189. /* Make sure this is the correct version of TrueFFS */
  190. if (tffscmp(globalHeader->osakVer,TrueFFSVersion,SIGN_MSYS_SIZE) != 0)
  191. {
  192. DFORMAT_PRINT(("ERROR - Incorrect TrueFFS EXB file version.\r\n"));
  193. return flBadParameter;
  194. }
  195. /* Find the corrent firmware in the file */
  196. /* Automatic firmware detection - by DiskOnChip type */
  197. switch (vol.flash->mediaType)
  198. {
  199. case DOC_TYPE:
  200. case MDOC_TYPE:
  201. mediaType = DOC2000_FAMILY_FIRMWARE;
  202. break;
  203. case MDOCP_TYPE:
  204. mediaType = DOCPLUS_FAMILY_FIRMWARE;
  205. break;
  206. case MDOCP_16_TYPE:
  207. mediaType = DOCPLUS_INT1_FAMILY_FIRMWARE;
  208. break;
  209. case DOC2000TSOP_TYPE:
  210. mediaType = DOC2300_FAMILY_FIRMWARE;
  211. break;
  212. default:
  213. DFORMAT_PRINT(("Unknown H/W - Try specifing the firmware manualy.\r\n"));
  214. return flFeatureNotSupported;
  215. }
  216. for (i=0;i<LE4(globalHeader->noOfFirmwares);i++,firmwareHeader++)
  217. {
  218. if (LE4(firmwareHeader->type) == mediaType)
  219. break;
  220. }
  221. }
  222. else /* Use given firmware */
  223. {
  224. i--; /* 0 was used for automatic choose of firmware */
  225. }
  226. if (i >= LE4(globalHeader->noOfFirmwares))
  227. {
  228. DFORMAT_PRINT(("ERROR - The EXB file does not support the required firmware.\r\n"));
  229. return flBadParameter;
  230. }
  231. /* Initialize the volumes EXB fields */
  232. firmwareHeader = (FirmwareHeader FAR1*)flAddLongToFarPointer(buf,
  233. (sizeof(ExbGlobalHeader) + (i * sizeof(FirmwareHeader))));
  234. i = (byte)(&vol - vols);
  235. /* Save firmware files statstics recieved from the files header */
  236. exbs[i].firmwareStart = LE4(firmwareHeader->startOffset);
  237. exbs[i].firmwareEnd = LE4(firmwareHeader->endOffset);
  238. exbs[i].splStart = LE4(firmwareHeader->splStartOffset);
  239. exbs[i].splEnd = LE4(firmwareHeader->splEndOffset);
  240. exbs[i].exbFileEnd = LE4(globalHeader->fileSize);
  241. /* Calculate the binary partition size (good bytes) used to
  242. hold the EXB file. */
  243. exbs[i].iplMod512 = (word)((exbs[i].splStart - exbs[i].firmwareStart)
  244. >> SECTOR_SIZE_BITS);
  245. switch (vol.flash->mediaType)
  246. {
  247. /* NFTL formated device - IPL is placed on the binary partition */
  248. case DOC_TYPE:
  249. /* Size of EXB minus IPL which is placed in ROM */
  250. vol.binaryLength = exbs[i].firmwareEnd - exbs[i].splStart + 0x4000;
  251. break;
  252. case MDOC_TYPE: /* Millennium 8, write data as is */
  253. /* Size of entire EXB */
  254. vol.binaryLength = exbs[i].firmwareEnd - exbs[i].firmwareStart;
  255. break;
  256. /* INFTL formated device - IPL is not placed on the binary
  257. partition, but on a dedicated flash area */
  258. case DOC2000TSOP_TYPE: /* DOC2000 TSOP */
  259. case MDOCP_TYPE: /* MDOC PLUS 32MB */
  260. case MDOCP_16_TYPE: /* MDOC PLUS 16MB */
  261. vol.binaryLength = exbs[i].firmwareEnd - exbs[i].splStart;
  262. break;
  263. default :
  264. DFORMAT_PRINT(("ERROR - Firmware formater reports A None DiskOnChip media.\r\n"));
  265. return flBadParameter;
  266. }
  267. return flOK;
  268. }
  269. /*------------------------------------------------------------------------*/
  270. /* w a i t F o r H a l f B u f f e r */
  271. /* */
  272. /* Increament the EXB file pointers and store the files data unit a */
  273. /* full sector of data is read. */
  274. /* */
  275. /* Parameters: */
  276. /* exbs[i].bufferOffset : size of the buffer already filled with data */
  277. /* exbs[i].exbFileOffset : offset from the beginning of the file */
  278. /* exbs[i].buffer.data : internal volume buffer accumulation file data */
  279. /* buf : buffer containing the files data */
  280. /* bufLen : Length of the buffer containing the file data */
  281. /* length : Length of the buffer not yet used */
  282. /* half : Wait for full 512 bytes of only 256 */
  283. /* Returns: */
  284. /* boolean : TRUE on full buffer otherwise FALSE. */
  285. /* length : Updated length of unused buffer */
  286. /*------------------------------------------------------------------------*/
  287. FLBoolean waitForFullBuffer(Volume vol , byte FAR1 * buf ,
  288. dword bufLen , Sdword * length,FLBoolean half)
  289. {
  290. word bufferEnd;
  291. word tmp;
  292. byte i = (byte)(&vol - vols);
  293. if (half == TRUE)
  294. {
  295. bufferEnd = (SECTOR_SIZE >> 1);
  296. }
  297. else
  298. {
  299. bufferEnd = SECTOR_SIZE;
  300. }
  301. tmp = (word)TFFSMIN(*length , bufferEnd - exbs[i].bufferOffset);
  302. tffscpy(exbs[i].buffer->flData + exbs[i].bufferOffset ,
  303. flAddLongToFarPointer(buf,(bufLen-(*length))), tmp);
  304. exbs[i].bufferOffset += tmp;
  305. exbs[i].exbFileOffset += tmp;
  306. *length -= tmp;
  307. if (*length+tmp < bufferEnd)
  308. return FALSE;
  309. exbs[i].bufferOffset = 0;
  310. return TRUE;
  311. }
  312. /*------------------------------------------------------------------------*/
  313. /* f i r s t T i m e I n i t */
  314. /* */
  315. /* Initialize data structures for placing exb file. */
  316. /* full sector of data is read. */
  317. /* */
  318. /* Actions: */
  319. /* 1) Analize exb file buffer. */
  320. /* 2) Calculate TFFS heap size. */
  321. /* 3) Check if binary area with SPL signature is big enough. */
  322. /* 4) Calculate SPL start media address */
  323. /* 5) Calculate binary area used for the firmware. */
  324. /* 6) Initialize the volumes EXB record. */
  325. /* */
  326. /* Parameters: */
  327. /* vol : Pointer to volume record describing the volume. */
  328. /* exb : Pointer to exb record describing the volume. */
  329. /* buf : Exb file buffer. */
  330. /* bufLen : Length of exb file buffer. */
  331. /* ioreq : Internal ioreq record for binary operaions. */
  332. /* bdk : Bdk record which is a part of the ioreq packet. */
  333. /* */
  334. /* Affected Variables. */
  335. /* */
  336. /* Returns: */
  337. /* flOK : On success. */
  338. /* flNoSpaceInVolume : Not enough space on the binary area. */
  339. /*------------------------------------------------------------------------*/
  340. FLStatus firstTimeInit(Volume vol , exbStruct* exb, byte FAR1 * buf ,
  341. dword bufLen , IOreq* ioreq , BDKStruct* bdk ,
  342. word exbFlags)
  343. {
  344. if (vol.moduleNo == INVALID_MODULE_NO)
  345. {
  346. FLStatus status;
  347. TLInfo info;
  348. /* Use the sockets buffer */
  349. exb->buffer = flBufferOf((unsigned)(exbs-exb));
  350. /* Find the number of blocks used needed for the EXB file */
  351. checkStatus(getExbInfo(&vol,buf,bufLen,exbFlags));
  352. /* Find TFFS heap size */
  353. if (!(vol.flags & VOLUME_ABS_MOUNTED))
  354. checkStatus(absMountVolume(&vol));
  355. ioreq->irData = &info;
  356. checkStatus(vol.tl.getTLInfo(vol.tl.rec,&info));
  357. exb->tffsHeapSize = (dword)(vol.flash->chipSize * vol.flash->noOfChips) >> info.tlUnitBits;
  358. /* Add heap for dynamic allocation not related to convertion tables */
  359. if((exbFlags & FIRMWARE_NO_MASK) >> FIRMWARE_NO_SHIFT == 0)
  360. {
  361. /* virutal TABLE + physical table */
  362. exb->tffsFarHeapSize = (word)(((exb->tffsHeapSize * 3) >> SECTOR_SIZE_BITS) + 1);
  363. exb->tffsHeapSize = INFTL_NEAR_HEAP_SIZE;
  364. }
  365. else /* Old TrueFFS source */
  366. {
  367. exb->tffsFarHeapSize = 0;
  368. exb->tffsHeapSize = exb->tffsHeapSize * 3 + DEFAULT_DOC_STACK;
  369. }
  370. /* Check if binary partition is formated for EXB */
  371. bdk->startingBlock = 0;
  372. ioreq->irData = bdk;
  373. status = bdkCall(FL_BINARY_PARTITION_INFO,ioreq,vol.flash);
  374. if ((bdk->startingBlock < vol.binaryLength) || (status != flOK))
  375. {
  376. DFORMAT_PRINT(("ERROR - Not enough binary area marked for EXB.\r\n"));
  377. return flNoSpaceInVolume;
  378. }
  379. /* initialize binary area for writting the EXB file */
  380. bdk->length = ((vol.binaryLength-1) >> vol.flash->erasableBlockSizeBits) +1;
  381. bdk->startingBlock = 0;
  382. bdk->signOffset = EXB_SIGN_OFFSET;
  383. checkStatus(bdkCall(FL_BINARY_ERASE,ioreq,vol.flash)); /* ERASE */
  384. if ((exbFlags & LEAVE_EMPTY) == 0)
  385. {
  386. /* If actualy need to place firmware initialize Binary write */
  387. bdk->length = vol.binaryLength;
  388. bdk->flags = BDK_COMPLETE_IMAGE_UPDATE | EDC;
  389. bdkVol->bdkGlobalStatus |= BDK_S_INFO_FOUND; /* do not research */
  390. checkStatus(bdkCall(FL_BINARY_WRITE_INIT,ioreq,vol.flash));
  391. tffsset(BUFFER,0xff,SECTOR_SIZE);
  392. }
  393. exb->exbFileOffset = 0; /* start of exb file */
  394. exb->bufferOffset = 0; /* start of internal buffer */
  395. exb->moduleLength = 0; /* size of the current module */
  396. exb->exbFlags = exbFlags; /* see list in doc2exb.h */
  397. vol.moduleNo = 0; /* module IPL */
  398. }
  399. return flOK;
  400. }
  401. /*----------------------------------------------------------------------*/
  402. /* p l a c e E x b B y B u f f e r */
  403. /* */
  404. /* Place M-systems firmware file on the media. */
  405. /* This routine analizes the exb file calclating the media space needed */
  406. /* for it taking only the device specific code. */
  407. /* */
  408. /* Note : The media must be already formated with enough binary area */
  409. /* already marked with the SPL signature. This routine is best used */
  410. /* with the format routine where the format routine is givven the first */
  411. /* 512 bytes while the rest of the file is given with this routine */
  412. /* */
  413. /* Parameters: */
  414. /* vol : Pointer identifying drive */
  415. /* buf : Buffer containing EXB file data */
  416. /* bufLen : Size of the current buffer */
  417. /* windowBase : Optional set window base address */
  418. /* exbFlags : INSTALL_FIRST - Install device as drive C: */
  419. /* FLOPPY - Install device as drive A: */
  420. /* QUIET - Do not show TFFS titles */
  421. /* INT15_DISABLE - Do not hook int 15 */
  422. /* SIS5598 - Support for SIS5598 platforms */
  423. /* NO_PNP_HEADER - Do not place the PNP bios header */
  424. /* LEAVE_EMPTY - Leave space for firmware */
  425. /* */
  426. /* Returns: */
  427. /* FLStatus : 0 on success, otherwise failed */
  428. /*----------------------------------------------------------------------*/
  429. FLStatus placeExbByBuffer(Volume vol, byte FAR1 * buf, dword bufLen,
  430. word docWinBase ,word exbFlags)
  431. {
  432. IOreq ioreq;
  433. BDKStruct bdk;
  434. word tmpWord;
  435. Sdword length = bufLen;
  436. byte anandMark[2] = {0x55,0x55};
  437. exbStruct* exb = &exbs[(byte)(&vol-vols)];
  438. BIOSHeader* hdr;
  439. IplHeader *ipl;
  440. SplHeader *spl;
  441. TffsHeader *tffs;
  442. /* Initialize binary partition call packet */
  443. tffscpy(bdk.oldSign,SIGN_SPL,BINARY_SIGNATURE_NAME); /* firmware signature */
  444. ioreq.irData = &bdk;
  445. bdk.signOffset = EXB_SIGN_OFFSET;
  446. ioreq.irHandle = 0;
  447. /* First time initialization */
  448. checkStatus(firstTimeInit(&vol,exb,buf,bufLen,&ioreq, &bdk, exbFlags));
  449. /* Initialize the rest of the binary partition call packet */
  450. bdk.bdkBuffer = BUFFER; /* internal bufer */
  451. bdk.length = sizeof(BUFFER); /* buffer size */
  452. bdk.flags |= ERASE_BEFORE_WRITE; /* Erase each unit before writing */
  453. /* Make sure this is a relevant part of the file */
  454. if (exb->exbFileOffset + length < exb->firmwareStart)
  455. {
  456. /* Before this specific device firmware */
  457. exb->exbFileOffset += length;
  458. return flOK;
  459. }
  460. if (exb->exbFileOffset >= exb->firmwareEnd)
  461. {
  462. /* After this specific device firmware */
  463. exb->exbFileOffset += length;
  464. if (exb->exbFileOffset >= exb->exbFileEnd)
  465. {
  466. vol.moduleNo = INVALID_MODULE_NO;
  467. if (vol.flash->download != NULL)
  468. return vol.flash->download(vol.flash); /* download IPL */
  469. }
  470. return flOK;
  471. }
  472. if (exb->exbFileOffset < exb->firmwareStart)
  473. {
  474. length -= exb->firmwareStart - exb->exbFileOffset;
  475. exb->exbFileOffset = exb->firmwareStart;
  476. }
  477. /* Start writting the file modules */
  478. while ((exb->firmwareEnd > exb->exbFileOffset) && (length >0))
  479. {
  480. /* Read next page into internal buffer */
  481. /* DOC2000 IPL is ROM and it assumed small pages therefore
  482. read only the first 256 bytes of each page. */
  483. if ((vol.moduleNo == 1) && (vol.flash->mediaType == DOC_TYPE))
  484. {
  485. if (waitForFullBuffer(&vol , buf , bufLen , &length,
  486. TRUE) == FALSE) /* 256 BYTES */
  487. return flOK;
  488. }
  489. else
  490. {
  491. if ((waitForFullBuffer(&vol , buf , bufLen , &length,
  492. FALSE) == FALSE) && /* 512 BYTES */
  493. (exb->exbFileOffset != exb->exbFileEnd)) /* Not last buffer */
  494. return flOK;
  495. }
  496. /* Update the module length according to its header */
  497. if (exb->moduleLength == 0)
  498. {
  499. /* All modules except for the SPL start with biosHdr record
  500. SPL has a 2 bytes opCode preciding the biosHdr and an
  501. incorrect module length */
  502. switch (vol.moduleNo) /* SPL */
  503. {
  504. case 1:
  505. hdr = &((SplHeader *)BUFFER)->biosHdr;
  506. /* calculate the number of buffers to use for the SPL */
  507. exb->moduleLength = (word)((exb->splEnd-exb->splStart) >> SECTOR_SIZE_BITS);
  508. /* Doc 2000 writes in chunks of 256 bytes therfore need to
  509. double the amount of write operations */
  510. if (vol.flash->mediaType == DOC_TYPE)
  511. exb->moduleLength = (word)(exb->moduleLength << 1);
  512. break;
  513. default : /* Get size from header */
  514. hdr = (BIOSHeader *) BUFFER;
  515. exb->moduleLength = hdr->lenMod512;
  516. }
  517. /* Check validy of bios header */
  518. if ((hdr->signature[0] != 0x55) || (hdr->signature[1] != 0xAA))
  519. {
  520. DFORMAT_PRINT(("ERROR - EXB file is missing one of the BIOS driver modules.\r\n"));
  521. return flBadLength;
  522. }
  523. /* Update neccesary fields in the modules headers */
  524. switch (vol.moduleNo)
  525. {
  526. case 0: /* IPL */
  527. /* The IPL length is actualy the window size in order to */
  528. /* supply the BIOS the expantion range. The real size */
  529. /* if calculated according to the exb file header. */
  530. if (vol.moduleNo==0)
  531. exb->moduleLength = exb->iplMod512;
  532. ipl = (IplHeader *)BUFFER;
  533. /* Set 0000 pointer of ISA P&P Header */
  534. if(exb->exbFlags & NO_PNP_HEADER)
  535. {
  536. ipl->dummy += ((byte)(ipl->pnpHeader >> 8) +
  537. (byte)ipl->pnpHeader);
  538. ipl->pnpHeader = 0;
  539. }
  540. /* Set DOC Window base explicitely */
  541. if( docWinBase > 0 )
  542. {
  543. toLE2(ipl->windowBase , docWinBase);
  544. ipl->dummy -= (byte)( docWinBase );
  545. ipl->dummy -= (byte)( docWinBase >> 8 );
  546. }
  547. break;
  548. case 1: /* SPL */
  549. spl = (SplHeader *)BUFFER;
  550. /* calculate EXB module size */
  551. /* generate random run-time ID and write it into splHeader. */
  552. tmpWord = (word)flRandByte();
  553. toUNAL2(spl->runtimeID, tmpWord);
  554. spl->chksumFix -= (byte)(tmpWord);
  555. spl->chksumFix -= (byte)(tmpWord >> 8);
  556. /* Write TFFS heap size into splHeader. */
  557. toUNAL2(spl->tffsHeapSize, (word)exb->tffsHeapSize);
  558. spl->chksumFix -= (byte)(exb->tffsHeapSize);
  559. spl->chksumFix -= (byte)(exb->tffsHeapSize >> 8);
  560. /* set explicit DOC window base */
  561. if( docWinBase > 0 )
  562. {
  563. toUNAL2(spl->windowBase, docWinBase);
  564. spl->chksumFix -= (byte)(docWinBase);
  565. spl->chksumFix -= (byte)(docWinBase >> 8);
  566. }
  567. break;
  568. case 2: /* Socket Services OR interupt 13 driver */
  569. /* The doc2000 driver and or socket services start
  570. at 0x4000 so we have to jump over there. */
  571. if (vol.flash->mediaType == DOC_TYPE)
  572. {
  573. bdkVol->actualUpdateLen -= 0x4000 - bdkVol->curUpdateImageAddress;
  574. bdkVol->curUpdateImageAddress = 0x4000;
  575. }
  576. tffs = (TffsHeader *)BUFFER;
  577. tffs->chksumFix -= (byte)(exb->tffsFarHeapSize);
  578. tffs->chksumFix -= (byte)(exb->tffsFarHeapSize >> 8);
  579. toUNAL2(tffs->heapLen, exb->tffsFarHeapSize);
  580. exb->exbFlags &= ~NO_PNP_HEADER;
  581. default:
  582. /* put "install as first drive" & QUIET mark
  583. into the TFFS header */
  584. tffs = (TffsHeader *)BUFFER;
  585. tffs->exbFlags = (byte)exb->exbFlags;
  586. tffs->chksumFix -= (byte)exb->exbFlags;
  587. break;
  588. } /* end - switch of module type */
  589. } /* end - first buffer of module */
  590. exb->moduleLength--;
  591. /* Write module and clean buffer */
  592. switch (vol.moduleNo)
  593. {
  594. case 0: /* IPL data */
  595. switch (vol.flash->mediaType)
  596. {
  597. case MDOC_TYPE: /* Millennium 8 - use bdk to write IPL * 2 */
  598. if (exb->moduleLength == exb->iplMod512 - 1)
  599. {
  600. /* Milennium DiskOnChip is the only device that the IPL
  601. is duplicated in the exb file. The dupplication was
  602. needed in earlier versions but it is currently ignored.
  603. The IPL is still written twice only that the second
  604. copy is not taken from the file but the first copy is
  605. simply written twice. */
  606. if ((exbFlags & LEAVE_EMPTY) == 0)
  607. {
  608. checkStatus(bdkCall(FL_BINARY_WRITE_BLOCK,
  609. &ioreq,vol.flash));
  610. checkStatus(bdkCall(FL_BINARY_WRITE_BLOCK,
  611. &ioreq,vol.flash));
  612. }
  613. }
  614. /* Change byte #406 to non-0xFF value to force
  615. Internal EEprom Mode */
  616. checkStatus(vol.flash->write(vol.flash,
  617. ANAND_MARK_ADDRESS,anandMark,ANAND_MARK_SIZE,EXTRA));
  618. break;
  619. case DOC2000TSOP_TYPE: /* Doc 2000 tsop - write to block 0 */
  620. case MDOCP_TYPE: /* Millennium Plus - use MTD specific routine */
  621. case MDOCP_16_TYPE:
  622. if (vol.flash->writeIPL == NULL)
  623. return flFeatureNotSupported;
  624. if ((exbFlags & LEAVE_EMPTY) != 0)
  625. {
  626. /* Erase previous IPL if all we need is to leave
  627. space for the firmware and not realy write it */
  628. tffsset(BUFFER,0xff,SECTOR_SIZE);
  629. }
  630. checkStatus(vol.flash->writeIPL(vol.flash,
  631. BUFFER,SECTOR_SIZE,
  632. (byte)(exb->iplMod512 - exb->moduleLength-1),
  633. FL_IPL_MODE_NORMAL));
  634. default: /* DiskOnChip 2000 */
  635. break; /* IPL is burnt onto ROM */
  636. }
  637. break;
  638. default:
  639. if ((exbFlags & LEAVE_EMPTY) == 0)
  640. {
  641. checkStatus(bdkCall(FL_BINARY_WRITE_BLOCK,&ioreq,vol.flash));
  642. }
  643. }
  644. tffsset(BUFFER,0xff,sizeof(BUFFER));
  645. if (exb->moduleLength == 0)
  646. vol.moduleNo++;
  647. }
  648. if (exb->exbFileOffset >= exb->firmwareEnd)
  649. {
  650. exb->exbFileOffset += length;
  651. }
  652. if (exb->exbFileOffset >= exb->exbFileEnd)
  653. {
  654. vol.moduleNo = INVALID_MODULE_NO;
  655. if (vol.flash->download != NULL)
  656. return vol.flash->download(vol.flash); /* download IPL */
  657. }
  658. return(flOK);
  659. }
  660. #endif /* WRITE_EXB_IMAGE */