export.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. /* export.c: Routines for file exports
  2. Copyright (C) 2002-2004 Sebastian Reichelt
  3. Copyright (C) 2003-2005 Kevin Kofler
  4. Copyright (C) 2004 Billy Charvet
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2, or (at your option)
  8. any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software Foundation,
  15. Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  16. #include "export.h"
  17. #ifdef TIOS_SUPPORT
  18. #include "exp_tios.h"
  19. #endif /* TIOS_SUPPORT */
  20. #ifdef FLASH_OS_SUPPORT
  21. #include "exp_os.h"
  22. #endif /* FLASH_OS_SUPPORT */
  23. #ifdef NOSTUB_DLL_SUPPORT
  24. #include "exp_ndll.h"
  25. #endif /* NOSTUB_DLL_SUPPORT */
  26. #ifdef FARGO_SUPPORT
  27. #include "exp_farg.h"
  28. #endif /* FARGO_SUPPORT */
  29. #ifdef DATA_VAR_SUPPORT
  30. #include "exp_data.h"
  31. #endif /* DATA_VAR_SUPPORT */
  32. #ifdef DEBUGGING_INFO_SUPPORT
  33. #include "exp_dbg.h"
  34. #endif /* DEBUGGING_INFO_SUPPORT */
  35. #include "../formats/tios.h"
  36. #include "../formats/tiosupgd.h"
  37. #include "../special.h"
  38. #include <string.h>
  39. typedef struct {
  40. OUTPUT_FILE_FUNCTION GetOutputFile;
  41. OUTPUT_FILE_FINALIZE_FUNCTION FinalizeOutputFile;
  42. GET_FILE_SIZE_FUNCTION GetFileSize;
  43. EXPORT_FILE_FUNCTION ExportFile, ExportDataFile;
  44. FileFormats FileFormat, DataFileFormat;
  45. unsigned int FileType, DataFileType;
  46. const char *Extension;
  47. } EXPORT_STRUCT;
  48. // Return the maximum file size allowed for a given format
  49. // (without header and footer).
  50. static SIZE GetMaxFileSize (FileFormats FileFormat, ProgramCalcs Calc)
  51. {
  52. switch (FileFormat)
  53. {
  54. case FF_TIOS:
  55. return MAX_TIOS_FILE_SIZE;
  56. case FF_TIOS_UPGRADE:
  57. if (Calc == CALC_V200 || (Calc == (CALC_TI89 | CALC_FLAG_TITANIUM)))
  58. return MAX_TIOS_UPGRADE_FILE_SIZE_NEW;
  59. else
  60. return MAX_TIOS_UPGRADE_FILE_SIZE_OLD;
  61. default:
  62. return 0;
  63. }
  64. }
  65. // Export the internal data structures to an external file for the given
  66. // calculator.
  67. static BOOLEAN ExportProgramToFormat (const PROGRAM *Program, const EXPORT_STRUCT *ExportStruct, ProgramCalcs Calc)
  68. {
  69. BOOLEAN Success;
  70. EXP_FILE File;
  71. SIZE Size, MaxSize;
  72. I4 EffectiveSize = 0;
  73. // Fill the output file struct with zeroes.
  74. memset (&File, 0, sizeof (File));
  75. // Get the file size needed to export the file.
  76. Size = ExportStruct->GetFileSize (Program);
  77. // A size of 0 indicates an error.
  78. if (Size <= 0)
  79. return FALSE;
  80. // Check for maximum file size.
  81. MaxSize = GetMaxFileSize (ExportStruct->FileFormat, Calc);
  82. if (Size > MaxSize)
  83. {
  84. Error (NULL, "Program size of %ld bytes exceeds maximum by %ld.", (long) Size, (long) (Size - MaxSize));
  85. return FALSE;
  86. }
  87. // Create an output file with the specified format.
  88. if (!(ExportStruct->GetOutputFile (&(File.File), Size, Calc, FR_MAIN, ExportStruct->FileFormat, ExportStruct->FileType, ExportStruct->Extension, !(Program->Library), &EffectiveSize)))
  89. return FALSE;
  90. // Export the program into the output file.
  91. Success = ExportStruct->ExportFile (Program, &File, Size, Calc);
  92. // Finalize and close the output file.
  93. if (ExportStruct->FinalizeOutputFile)
  94. ExportStruct->FinalizeOutputFile (&(File.File));
  95. if (Success)
  96. {
  97. if (Program->OptimizeInfo->ProgramSize < (SI4) EffectiveSize)
  98. Program->OptimizeInfo->ProgramSize = (SI4) EffectiveSize;
  99. }
  100. else
  101. return FALSE;
  102. #ifdef DATA_VAR_SUPPORT
  103. // Write the data file, if any.
  104. if (Program->DataVarInfo->Name && Program->DataSection)
  105. {
  106. if (ExportStruct->DataFileFormat == FF_NONE)
  107. {
  108. Error (NULL, "Data variable is not supported in this file format.");
  109. return FALSE;
  110. }
  111. // Fill the output file struct with zeroes.
  112. memset (&File, 0, sizeof (File));
  113. // Get the file size needed to export the file.
  114. Size = GetDataFileSize (Program);
  115. // A size of 0 indicates an error.
  116. if (Size <= 0)
  117. return FALSE;
  118. MaxSize = GetMaxFileSize (ExportStruct->DataFileFormat, Calc);
  119. // Check for maximum file size.
  120. if (Size > MaxSize)
  121. {
  122. Error (NULL, "Data variable size of %ld bytes exceeds maximum by %ld.", (long) Size, (long) (MaxSize - Size));
  123. return FALSE;
  124. }
  125. // Create an output file with the specified format.
  126. if (!(ExportStruct->GetOutputFile (&(File.File), Size, Calc, FR_DATA, ExportStruct->DataFileFormat, ExportStruct->DataFileType, "DAT", FALSE, &EffectiveSize)))
  127. return FALSE;
  128. // Export the program into the output file.
  129. Success = ExportStruct->ExportDataFile (Program, &File, Size, Calc);
  130. // Finalize and close the output file.
  131. if (ExportStruct->FinalizeOutputFile)
  132. ExportStruct->FinalizeOutputFile (&(File.File));
  133. if (Success)
  134. {
  135. if (Program->OptimizeInfo->DataSize < (SI4) EffectiveSize)
  136. Program->OptimizeInfo->DataSize = (SI4) EffectiveSize;
  137. }
  138. else
  139. return FALSE;
  140. }
  141. #endif /* DATA_VAR_SUPPORT */
  142. return TRUE;
  143. }
  144. // Export the internal data structures to external files, creating as many
  145. // files as needed.
  146. BOOLEAN ExportProgram (const PROGRAM *Program, OUTPUT_FILE_FUNCTION GetOutputFile, OUTPUT_FILE_FINALIZE_FUNCTION FinalizeOutputFile)
  147. {
  148. EXPORT_STRUCT ExportStruct = {GetOutputFile, FinalizeOutputFile, NULL, NULL, NULL, FF_TIOS, FF_TIOS, TIOS_TAG_ASM, TIOS_TAG_OTH, NULL};
  149. if (!GetOutputFile)
  150. return FALSE;
  151. #ifdef DEBUGGING_INFO_SUPPORT
  152. // If we have debugging information to export, do it.
  153. if (Program->HaveDebuggingInfo)
  154. {
  155. if (!ExportDebuggingInfo (Program, GetOutputFile, FinalizeOutputFile))
  156. return FALSE;
  157. }
  158. #endif
  159. switch (Program->Type)
  160. {
  161. #ifdef FLASH_OS_SUPPORT
  162. case PT_FLASH_OS:
  163. ExportStruct.GetFileSize = GetFlashOSFileSize;
  164. ExportStruct.ExportFile = ExportFlashOSFile;
  165. ExportStruct.FileFormat = FF_TIOS_UPGRADE;
  166. ExportStruct.FileType = 0; // Different types for Flash OSs do not exist.
  167. ExportStruct.DataFileFormat = FF_NONE;
  168. ExportStruct.DataFileType = 0;
  169. break;
  170. #endif /* FLASH_OS_SUPPORT */
  171. #ifdef NOSTUB_DLL_SUPPORT
  172. case PT_NOSTUB_DLL:
  173. ExportStruct.GetFileSize = GetNostubDLLFileSize;
  174. ExportStruct.ExportFile = ExportNostubDLLFile;
  175. ExportStruct.FileType = TIOS_TAG_OTH;
  176. ExportStruct.Extension = "DLL";
  177. break;
  178. #endif /* NOSTUB_DLL_SUPPORT */
  179. #ifdef FARGO_SUPPORT
  180. case PT_FARGO:
  181. ExportStruct.GetFileSize = GetFargoFileSize;
  182. ExportStruct.ExportFile = ExportFargoFile;
  183. ExportStruct.FileType = TIOS_TAG_PRGM;
  184. break;
  185. #endif /* FARGO_SUPPORT */
  186. default:
  187. #ifdef TIOS_SUPPORT
  188. ExportStruct.GetFileSize = GetTIOSFileSize;
  189. ExportStruct.ExportFile = ExportTIOSFile;
  190. #else /* !TIOS_SUPPORT */
  191. Error (NULL, "No default export target for this program type.");
  192. return FALSE;
  193. #endif /* !TIOS_SUPPORT */
  194. }
  195. #ifdef DATA_VAR_SUPPORT
  196. ExportStruct.ExportDataFile = ExportDataFile;
  197. #endif /* DATA_VAR_SUPPORT */
  198. {
  199. ProgramCalcs CurCalc;
  200. // For all calculators...
  201. for (CurCalc = 1; CurCalc <= HIGHEST_CALC; CurCalc <<= 1)
  202. {
  203. if (Program->Calcs & CurCalc)
  204. {
  205. if (!(ExportProgramToFormat (Program, &ExportStruct, CurCalc)))
  206. return FALSE;
  207. if (Program->Type == PT_FLASH_OS && CurCalc == CALC_TI89 && (Program->Calcs & CALC_FLAG_TITANIUM))
  208. {
  209. if (!(ExportProgramToFormat (Program, &ExportStruct, CurCalc | CALC_FLAG_TITANIUM)))
  210. return FALSE;
  211. }
  212. }
  213. }
  214. }
  215. Program->OptimizeInfo->RelocCount += Program->OptimizeInfo->NativeRelocCount;
  216. return TRUE;
  217. }
  218. // Non-embedded file output functions as defined in intrface.h.
  219. #ifndef TARGET_EMBEDDED
  220. #include <stdio.h>
  221. // Destination file name without extension.
  222. const char *DestFile = NULL;
  223. SIZE DestFileSize = 0;
  224. // Folder and variable name for main file.
  225. char ProgramFolder[MAX_NAME_LEN+1] = "main", ProgramName[MAX_NAME_LEN+1] = "program";
  226. #ifdef DATA_VAR_SUPPORT
  227. // Folder and variable name for data file.
  228. char DataFolder[MAX_NAME_LEN+1] = "", DataName[MAX_NAME_LEN+1] = "data";
  229. #endif /* DATA_VAR_SUPPORT */
  230. // Specifies whether to output only the binary image of the program.
  231. BOOLEAN OutputBin = FALSE;
  232. // Specifies whether to output only the binary image of the main file.
  233. BOOLEAN OutputBinMainOnly = FALSE;
  234. // Maximum length of a file extension.
  235. #define MAX_FILE_EXT_LEN 3
  236. BOOLEAN GetOutputFile (INT_EXP_FILE *File, SIZE FileSize, unsigned int DestCalc, unsigned int FileRole, unsigned int FileFormat, unsigned int FileType, const char *Extension, BOOLEAN Executable ATTRIBUTE_UNUSED, I4 *EffectiveSize)
  237. {
  238. // Keep some of the parameters for finalization.
  239. File->OutputBin = OutputBin || (OutputBinMainOnly && FileRole == FR_MAIN);
  240. File->FileFormat = FileFormat;
  241. File->FileType = FileType;
  242. File->Extension = Extension;
  243. // Determine the destination file format and act accordingly.
  244. switch (FileFormat)
  245. {
  246. #ifdef TIOS_FILE_SUPPORT
  247. case FF_TIOS:
  248. {
  249. const char *FolderName, *VarName;
  250. const char *FileExtCalc, *FileExtType;
  251. unsigned int LinkType;
  252. // Calculate the size needed for the two size bytes and the
  253. // tag.
  254. SIZE VarFileSize = 2 + FileSize + 1;
  255. // If the file has an extension, add the size needed for it.
  256. if (Extension)
  257. VarFileSize += 1 + strlen (Extension) + 1;
  258. // The variable size is what the user will see.
  259. *EffectiveSize = VarFileSize;
  260. // Determine the role of the file and set the folder and
  261. // variable names according to the user settings.
  262. switch (FileRole)
  263. {
  264. case FR_MAIN:
  265. FolderName = ProgramFolder;
  266. VarName = ProgramName;
  267. break;
  268. #ifdef DATA_VAR_SUPPORT
  269. case FR_DATA:
  270. if (*DataFolder)
  271. FolderName = DataFolder;
  272. else
  273. FolderName = ProgramFolder;
  274. VarName = DataName;
  275. break;
  276. #endif /* DATA_VAR_SUPPORT */
  277. default:
  278. Error (NULL, "Unknown file role.");
  279. return FALSE;
  280. }
  281. // Determine the destination calculator and set part of the
  282. // file extension.
  283. switch (DestCalc)
  284. {
  285. case CALC_TI92:
  286. FileExtCalc = "92";
  287. break;
  288. case CALC_TI89:
  289. FileExtCalc = "89";
  290. break;
  291. case CALC_TI92PLUS:
  292. FileExtCalc = "9x";
  293. break;
  294. case CALC_V200:
  295. FileExtCalc = "v2";
  296. break;
  297. default:
  298. Error (NULL, "Unknown calculator.");
  299. return FALSE;
  300. }
  301. // Determine the file type and set the other part of the file
  302. // extension.
  303. switch (FileType)
  304. {
  305. case TIOS_TAG_STR:
  306. FileExtType = "s";
  307. LinkType = TIOS_LINK_TYPE_STR;
  308. break;
  309. case TIOS_TAG_PRGM:
  310. FileExtType = "p";
  311. LinkType = TIOS_LINK_TYPE_PRGM;
  312. break;
  313. case TIOS_TAG_ASM:
  314. FileExtType = "z";
  315. LinkType = TIOS_LINK_TYPE_ASM;
  316. break;
  317. case TIOS_TAG_OTH:
  318. FileExtType = "y";
  319. LinkType = TIOS_LINK_TYPE_OTH;
  320. break;
  321. default:
  322. Error (NULL, "Unknown file type.");
  323. return FALSE;
  324. }
  325. {
  326. SIZE FileNameSize = DestFileSize;
  327. // Create a temporary file name string.
  328. char CurOutputFileName[FileNameSize+1+MAX_FILE_EXT_LEN+1];
  329. strncpy (CurOutputFileName, DestFile, FileNameSize);
  330. // Insert the dot into the file name.
  331. CurOutputFileName [FileNameSize++] = '.';
  332. // Insert the extension. Reverse in binary mode.
  333. if (File->OutputBin)
  334. {
  335. strcpy (CurOutputFileName + FileNameSize, FileExtType);
  336. FileNameSize += strlen (FileExtType);
  337. strcpy (CurOutputFileName + FileNameSize, FileExtCalc);
  338. FileNameSize += strlen (FileExtCalc);
  339. }
  340. else
  341. {
  342. strcpy (CurOutputFileName + FileNameSize, FileExtCalc);
  343. FileNameSize += strlen (FileExtCalc);
  344. strcpy (CurOutputFileName + FileNameSize, FileExtType);
  345. FileNameSize += strlen (FileExtType);
  346. }
  347. // Zero-terminate the string.
  348. CurOutputFileName [FileNameSize] = 0;
  349. // Open a file with the specified name.
  350. if (!(File->File = fopen (CurOutputFileName, "wb")))
  351. {
  352. Error (CurOutputFileName, "Could not open file for writing.");
  353. return FALSE;
  354. }
  355. // Write the host file header, if desired.
  356. if (!File->OutputBin)
  357. {
  358. TIOS_HOST_FILE_HEADER Header;
  359. memset (&Header, 0, sizeof (Header));
  360. // Write the signature.
  361. switch (DestCalc)
  362. {
  363. case CALC_TI92:
  364. strncpy (Header.Signature, "**TI92**", 8);
  365. break;
  366. case CALC_TI89:
  367. strncpy (Header.Signature, "**TI89**", 8);
  368. break;
  369. case CALC_TI92PLUS:
  370. case CALC_V200:
  371. strncpy (Header.Signature, "**TI92P*", 8);
  372. break;
  373. default:
  374. Error (NULL, "Unknown calculator.");
  375. return FALSE;
  376. }
  377. // Write folder name.
  378. strncpy (Header.FolderName, FolderName, sizeof (Header.FolderName));
  379. // Write variable name.
  380. strncpy (Header.VarName, VarName, sizeof (Header.VarName));
  381. // Write link type.
  382. WriteHI1 (Header.LinkType, LinkType);
  383. // Write file size.
  384. WriteHI4 (Header.FileSize, VarFileSize + sizeof (TIOS_HOST_FILE_HEADER) + sizeof (TIOS_HOST_FILE_FOOTER));
  385. // Write reserved bytes.
  386. Header.Reserved1 [0] = 0x01;
  387. Header.Reserved2 [0] = 0x01;
  388. Header.Reserved2 [2] = 0x52;
  389. Header.Reserved4 [0] = 0xA5;
  390. Header.Reserved4 [1] = 0x5A;
  391. // Export the header.
  392. fwrite (&Header, sizeof (Header), 1, File->File);
  393. }
  394. // Write the on-calc file header.
  395. {
  396. TI2 EncVarFileSize;
  397. // Encode the embedded size into the target
  398. // endianness.
  399. WriteTI2 (EncVarFileSize, VarFileSize - 2);
  400. // Export the file size.
  401. fwrite (&EncVarFileSize, 2, 1, File->File);
  402. // Update the checksum, since this is still included
  403. // in the on-calc file image.
  404. File->CheckSum += ReadTI1 (EncVarFileSize.Hi) + ReadTI1 (EncVarFileSize.Lo);
  405. }
  406. return TRUE;
  407. }
  408. }
  409. break;
  410. #endif /* TIOS_FILE_SUPPORT */
  411. #ifdef TIOS_UPGRADE_FILE_SUPPORT
  412. case FF_TIOS_UPGRADE:
  413. *EffectiveSize = FileSize + sizeof (TIOS_UPGRADE_CALC_FOOTER);
  414. if (File->OutputBin)
  415. {
  416. const char *FileExtCalc;
  417. // Determine the destination calculator and set part of the
  418. // file extension.
  419. switch (DestCalc)
  420. {
  421. case CALC_TI92:
  422. FileExtCalc = "92";
  423. break;
  424. case CALC_TI89:
  425. FileExtCalc = "89";
  426. break;
  427. case CALC_TI89 | CALC_FLAG_TITANIUM:
  428. FileExtCalc = "89ti";
  429. break;
  430. case CALC_TI92PLUS:
  431. FileExtCalc = "9x";
  432. break;
  433. case CALC_V200:
  434. FileExtCalc = "v2";
  435. break;
  436. default:
  437. Error (NULL, "Unknown calculator.");
  438. return FALSE;
  439. }
  440. {
  441. SIZE FileNameSize = DestFileSize;
  442. // Create a temporary file name string.
  443. char CurOutputFileName[FileNameSize+1+4+1+sizeof("tib")];
  444. strncpy (CurOutputFileName, DestFile, FileNameSize);
  445. // Insert a dash into the file name.
  446. CurOutputFileName [FileNameSize++] = '-';
  447. // Insert the calculator model into the file name.
  448. strcpy (CurOutputFileName + FileNameSize, FileExtCalc);
  449. FileNameSize += strlen (FileExtCalc);
  450. // Insert the dot into the file name.
  451. CurOutputFileName [FileNameSize++] = '.';
  452. // Insert the .tib extension.
  453. strcpy (CurOutputFileName + FileNameSize, "tib");
  454. FileNameSize += sizeof ("tib") - 1;
  455. // Zero-terminate the string.
  456. CurOutputFileName [FileNameSize] = 0;
  457. // Open a file with the specified name.
  458. if (!(File->File = fopen (CurOutputFileName, "wb")))
  459. {
  460. Error (CurOutputFileName, "Could not open file for writing.");
  461. return FALSE;
  462. }
  463. return TRUE;
  464. }
  465. }
  466. else
  467. Error (NULL, "Support for `.??u' files is not implemented yet. Use `--outputbin'.");
  468. break;
  469. #endif /* TIOS_UPGRADE_FILE_SUPPORT */
  470. #ifdef DEBUGGING_INFO_SUPPORT
  471. case FF_GDB_COFF:
  472. *EffectiveSize = FileSize;
  473. {
  474. SIZE FileNameSize = DestFileSize+4;
  475. // Create a temporary file name string.
  476. char CurOutputFileName[FileNameSize+1];
  477. strncpy (CurOutputFileName, DestFile, DestFileSize);
  478. // Append ".dbg" to the file name.
  479. strcpy (CurOutputFileName + DestFileSize, ".dbg");
  480. // Zero-terminate the string.
  481. CurOutputFileName [FileNameSize] = 0;
  482. // Open a file with the specified name.
  483. if (!(File->File = fopen (CurOutputFileName, "wb")))
  484. {
  485. Error (CurOutputFileName, "Could not open file for writing.");
  486. return FALSE;
  487. }
  488. return TRUE;
  489. }
  490. break;
  491. #endif /* DEBUGGING_INFO_SUPPORT */
  492. default:
  493. Error (NULL, "Unrecognized output file format.");
  494. }
  495. return FALSE;
  496. }
  497. void FinalizeOutputFile (INT_EXP_FILE *File)
  498. {
  499. // Determine the destination file format and finish it.
  500. switch (File->FileFormat)
  501. {
  502. #ifdef TIOS_FILE_SUPPORT
  503. case FF_TIOS:
  504. {
  505. // Write the on-calc file footer.
  506. {
  507. TI1 EncFileTag;
  508. // Export the possible file extension.
  509. if (File->Extension)
  510. {
  511. // Export the leading 0 byte.
  512. WriteTI1 (EncFileTag, 0);
  513. fwrite (&EncFileTag, 1, 1, File->File);
  514. // Export the extension string and terminating 0
  515. // byte.
  516. fwrite (File->Extension, 1, strlen (File->Extension) + 1, File->File);
  517. // Update the checksum.
  518. while (*(File->Extension))
  519. File->CheckSum += (*(File->Extension++));
  520. }
  521. // Encode the file tag.
  522. WriteTI1 (EncFileTag, File->FileType);
  523. // Export the file tag.
  524. fwrite (&EncFileTag, 1, 1, File->File);
  525. File->CheckSum += (I1) (File->FileType);
  526. }
  527. // Write the host file footer, if desired.
  528. if (!File->OutputBin)
  529. {
  530. TIOS_HOST_FILE_FOOTER Footer;
  531. memset (&Footer, 0, sizeof (Footer));
  532. // Write the checksum.
  533. WriteHI2 (Footer.CheckSum, File->CheckSum);
  534. // Export the footer.
  535. fwrite (&Footer, sizeof (Footer), 1, File->File);
  536. }
  537. }
  538. break;
  539. #endif /* TIOS_FILE_SUPPORT */
  540. #ifdef TIOS_UPGRADE_FILE_SUPPORT
  541. case FF_TIOS_UPGRADE:
  542. {
  543. // Write the on-calc upgrade file footer.
  544. {
  545. TIOS_UPGRADE_CALC_FOOTER Footer;
  546. // Since we do not have TI's private key, we cannot
  547. // write a real checksum and signature.
  548. memset (&Footer, 0, sizeof (Footer));
  549. // Encode the fixed data we know.
  550. WriteTI2 (Footer.SignatureHeader, 0x020D);
  551. WriteTI1 (Footer.SignatureType, 0x40);
  552. // Export the footer.
  553. fwrite (&Footer, sizeof (Footer), 1, File->File);
  554. }
  555. }
  556. break;
  557. #endif /* TIOS_UPGRADE_FILE_SUPPORT */
  558. #ifdef DEBUGGING_INFO_SUPPORT
  559. case FF_GDB_COFF:
  560. // Do nothing.
  561. break;
  562. #endif /* DEBUGGING_INFO_SUPPORT */
  563. }
  564. // Close the file.
  565. fclose (File->File);
  566. }
  567. #endif /* !TARGET_EMBEDDED */