znp.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /**************************************************************************************************
  2. Filename: znp.js
  3. Revised: $Date: 2010-08-23 12:24:40 -0700 (Mon, 23 Aug 2010) $
  4. Revision: $Revision: 23475 $
  5. Description: This file is a JScript file that can be run by the Windows Script Host,
  6. which is installed by default on Windows XP SP2 and later. The script acts on
  7. the arguments to do the tedious post-processing for the ZNP builds.
  8. Copyright 2010 Texas Instruments Incorporated. All rights reserved.
  9. IMPORTANT: Your use of this Software is limited to those specific rights
  10. granted under the terms of a software license agreement between the user
  11. who downloaded the software, his/her employer (which must be your employer)
  12. and Texas Instruments Incorporated (the "License"). You may not use this
  13. Software unless you agree to abide by the terms of the License. The License
  14. limits your use, and you acknowledge, that the Software may not be modified,
  15. copied or distributed unless embedded on a Texas Instruments microcontroller
  16. or used solely and exclusively in conjunction with a Texas Instruments radio
  17. frequency transceiver, which is integrated into your product. Other than for
  18. the foregoing purpose, you may not use, reproduce, copy, prepare derivative
  19. works of, modify, distribute, perform, display or sell this Software and/or
  20. its documentation for any purpose.
  21. YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
  22. PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  23. INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
  24. NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
  25. TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
  26. NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
  27. LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
  28. INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
  29. OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
  30. OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
  31. (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
  32. Should you have any questions regarding your right to use this Software,
  33. contact Texas Instruments Incorporated at www.TI.com.
  34. **************************************************************************************************/
  35. var ForReading = 1;
  36. var ForWriting = 2;
  37. var fPopMask = "znp-popmask.txt";
  38. // Get the mask of user disabled popups.
  39. function get_popmask() {
  40. var fso = new ActiveXObject("Scripting.FileSystemObject");
  41. if (fso.FileExists(fPopMask)) {
  42. var fin = fso.OpenTextFile(fPopMask, ForReading);
  43. var mask = fin.Read(4); // A 0/1 string is expected as the 1st 4 bytes of the 1st line.
  44. fin.Close();
  45. return (mask);
  46. }
  47. return "0000";
  48. }
  49. // Set the mask of user disabled popups.
  50. function set_popmask(mask) {
  51. var fso = new ActiveXObject("Scripting.FileSystemObject");
  52. var fout = fso.CreateTextFile(fPopMask, true);
  53. fout.WriteLine(mask);
  54. fout.WriteLine("The first byte of this file is a bit mask that forces the ZNP post processing");
  55. fout.WriteLine("to run popless for the corresponding build types.");
  56. fout.WriteLine("The bit mask is updated when the 'Cancel' button is pressed on a pop-up");
  57. fout.WriteLine("Simply delete this file to get all pop-ups back.");
  58. fout.Close();
  59. }
  60. // Generate an informational popup according to the build type.
  61. function popup(idx, fName, pName) {
  62. var popmask = get_popmask();
  63. // If the user had requested to suppress popups for this build type, just return.
  64. if (popmask.substr(idx, 1) != 0) {
  65. return;
  66. }
  67. var WshShell = WScript.CreateObject("WScript.Shell");
  68. var msg = "The output file can be found here:\n" + pName + fName;
  69. switch (idx) {
  70. case 1:
  71. msg += "\nThe .hex image is intended to be programmed and verified by a tool such as\
  72. \nthe TI SmartRF Programmer.";
  73. break;
  74. case 2:
  75. msg += "\nThe .bin image is intended to be programmed and verified by a tool that implements\
  76. \nthe SBL protocol such as the SBDemo.exe.\
  77. \nNOTE: The SBL must already be programmed into the target device, usually by having\
  78. \n already programmed the CC253xZNP-Prod.hex with a programming tool.";
  79. break;
  80. case 3:
  81. msg += "\nThe .hex image is intended to be programmed and verified by a tool such as the TI SmartRF Programmer.\
  82. \nNOTE: The checksum and shadow are forced to be equal, so external verification is crucial.";
  83. break;
  84. }
  85. // Show an info message that dimisses itself after 30 seconds and offers an OK and Cancel button.
  86. var BtnCode = WshShell.Popup(msg, 30, fName + " is in the dev!", 1 + 64);
  87. // If the user presses the 'Cancel' button, create a local file to suppress future pop-ups.
  88. if (BtnCode == 2) {
  89. var newmask = popmask.substring(0, idx) + 1 + popmask.substring(idx+1, 3);
  90. set_popmask(newmask);
  91. }
  92. }
  93. // void main(void)
  94. {
  95. var buildName = WScript.Arguments(0);
  96. var fso = new ActiveXObject("Scripting.FileSystemObject");
  97. var pZNP = fso.GetFile("znp.js");
  98. var fOut = buildName.substring(0, 6) + "ZNP" + buildName.substring(6, 11);
  99. var pOut = pZNP.Path.substr(0, pZNP.Path.length-12) + "dev";
  100. var pIn = pZNP.Path.substr(0, pZNP.Path.length-12) + buildName + "\\Exe\\";
  101. var fIn, fSBL;
  102. var buildType;
  103. var tgtType;
  104. if (!fso.FolderExists(pOut)) {
  105. fso.CreateFolder(pOut);
  106. }
  107. pOut += "\\";
  108. switch (buildName.substr(7)) {
  109. case "Debug":
  110. WScript.Quit(0); // Nothing to do for a Debug build.
  111. break;
  112. case "TestHex":
  113. buildType = 1;
  114. fOut += ".hex";
  115. break;
  116. case "ProdSBL":
  117. fIn = buildName.substring(0, 6) + ".sim"
  118. fOut += ".bin";
  119. buildType = 2;
  120. break;
  121. case "ProdHex":
  122. fIn = buildName.substring(0, 6) + ".a51"
  123. fOut += ".hex";
  124. buildType = 3;
  125. break;
  126. default:
  127. // Add handling of the Release Production .hex files.
  128. if ((buildName.substr(6, 3) == "Rel") || (buildName.substr(6, 3) == "-MK"))
  129. {
  130. pOut = pZNP.Path.substr(0, pZNP.Path.length-12) + "bin\\";
  131. fIn = buildName.substring(0, 9) + ".a51"
  132. if (buildName.substr(6, 3) == "Rel")
  133. {
  134. fOut = buildName.substring(0, 6) + "ZNP" + buildName.substr(9) + ".hex";
  135. }
  136. else
  137. {
  138. fOut = buildName.substring(0, 6) + "-MK" + buildName.substr(9) + ".hex";
  139. }
  140. buildType = 3;
  141. }
  142. else
  143. {
  144. WScript.Quit(0); // Nothing to do for a Debug build.
  145. }
  146. break;
  147. }
  148. switch (buildName.substr(5, 1)) {
  149. case "0":
  150. tgtType = 0;
  151. if (buildName.substr(6, 3) == "-MK")
  152. {
  153. fSBL = pZNP.Path.substr(0, pZNP.Path.length-12) + "bin\\CC2530-MK-SB.hex";
  154. }
  155. else
  156. {
  157. fSBL = pZNP.Path.substr(0, pZNP.Path.length-12) + "bin\\CC2530ZNP-SB.hex";
  158. }
  159. break;
  160. case "1":
  161. tgtType = 1;
  162. fSBL = pZNP.Path.substr(0, pZNP.Path.length-12) + "bin\\CC2531SB.hex";
  163. break;
  164. }
  165. switch (buildType) {
  166. case 1:
  167. fso.CopyFile(pIn+fOut, pOut+fOut, true);
  168. break;
  169. case 2:
  170. fso.CopyFile(pIn+fIn, "tmp.sim", true);
  171. var WshShell = new ActiveXObject("WScript.Shell");
  172. // Invoke and wait for the binary file conversion tool to finish.
  173. WshShell.Run("sim2bin.exe tmp.sim tmp.bin", 8, true);
  174. fso.CopyFile("tmp.bin", pOut+fOut, true);
  175. fso.DeleteFile("tmp.bin");
  176. fso.DeleteFile("tmp.sim");
  177. break;
  178. case 3:
  179. var fin = fso.OpenTextFile(fSBL, ForReading)
  180. var fout = fso.CreateTextFile(pOut+fOut, true);
  181. var line = new Array(3);
  182. var rIdx = 2;
  183. var wIdx = 0;
  184. // Need to throw away the last two lines since a valid .hex file will be appended.
  185. line[0] = fin.ReadLine();
  186. line[1] = fin.ReadLine();
  187. while (1)
  188. {
  189. fout.WriteLine(line[wIdx]);
  190. line[rIdx] = fin.ReadLine();
  191. if (fin.AtEndOfStream)
  192. {
  193. break;
  194. }
  195. rIdx = (rIdx+1) % 3;
  196. wIdx = (wIdx+1) % 3;
  197. }
  198. fin.Close();
  199. fin = fso.OpenTextFile(pIn+fIn, ForReading)
  200. fin.ReadLine(); // Throw away the first line since appending to a valid .hex file.
  201. while (!fin.AtEndOfStream)
  202. {
  203. var s = fin.ReadLine();
  204. fout.WriteLine(s);
  205. }
  206. fin.Close();
  207. fout.Close();
  208. break;
  209. }
  210. popup(buildType, fOut, pOut);
  211. }