wince自动生成XIP映像文件的一种方法

来源:互联网 发布:平板产品展示软件 编辑:程序博客网 时间:2024/05/17 08:19

在WINCE做MULTIBIN+XIP方式的启动映像文件时,往往需要分两步走:第一步、生成映像文件;第二步、修改ce.bib然后再romimage一次,以前的做法是手动修改极不方便,后来在网上找到了一些办法并整合到一起就能够做到一步到位。

1、做一个批处理放在BSP的Files/premake目录下供PB调用,文件内容如下:

[cpp] view plaincopy
  1. echo.  
  2. echo %_TGTPLAT%-preri processing...  
  3. echo.  
  4. if "%IMGMULTIXIP%"=="1" cd %_TARGETPLATROOT%/Files/premake  
  5. if "%IMGMULTIXIP%"=="1" copy %_FLATRELEASEDIR%/ce.bib %_TARGETPLATROOT%/Files/premake  
  6. if "%IMGMULTIXIP%"=="1" copy ce.bib ce_orig.bib  
  7. if "%IMGMULTIXIP%"=="1" oembibhelper multibin.txt ce_orig.bib ce.bib  
  8. if "%IMGMULTIXIP%"=="1" copy ce.bib %_FLATRELEASEDIR%  
  9. if "%IMGMULTIXIP%"=="1" cd %_FLATRELEASEDIR%  
  10. if "%IMGMULTIXIP%"=="1" romimage ce.bib  

2、oembibhelper.vbs脚本的内容如下:
[vb] view plaincopy
  1. '  
  2. ' Copyright (c) Microsoft Corporation.  All rights reserved.  
  3. '  
  4. '  
  5. ' Use of this sample source code is subject to the terms of the Microsoft  
  6. ' license agreement under which you licensed this sample source code. If  
  7. ' you did not accept the terms of the license agreement, you are not  
  8. ' authorized to use this sample source code. For the terms of the license,  
  9. ' please see the license agreement between you and Microsoft or, if applicable,  
  10. ' see the LICENSE.RTF on your install media or the root of your tools installation.  
  11. ' THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.  
  12. '  
  13.   
  14. ' Modified this bibhelper.vbs to modify the bib to implement the Multi-Bin  
  15. ' For example: "nk.exe @XIPKERN" of config file will make nk.exe packed into XIPKERN.bin   
  16. '  
  17. Public Function SplitEx(InputText,Delimiter)  
  18.   
  19. ' This function splits the sentence in InputText into  
  20. ' words and returns a string array of the words. Each  
  21. ' element of the array contains one word.  
  22.   
  23.     ' This constant contains punctuation and characters  
  24.     ' that should be filtered from the input string.  
  25.     Dim strReplacedText  
  26.     Dim intIndex  
  27.   
  28.     ' Replace tab characters with space characters.  
  29.     ' Replace tab characters with space characters.  
  30.     strReplacedText = Trim(Replace(InputText, vbTab, " "))  
  31.   
  32.   
  33.     ' Loop until all consecutive space characters are  
  34.     ' replaced by a single space character.  
  35.     Do While InStr(strReplacedText, "  ")  
  36.         strReplacedText = Replace(strReplacedText, "  "" ")  
  37.     Loop  
  38.   
  39.     ' Split the sentence into an array of words and return  
  40.     ' the array. If a delimiter is specified, use it.  
  41.     'MsgBox "String:" & strReplacedText  
  42.     If Len(Delimiter) = 0 Then  
  43.         SplitEx = Split(strReplacedText)  
  44.     Else  
  45.         SplitEx = Split(strReplacedText, Delimiter)  
  46.     End If  
  47. End Function  
  48.   
  49. Private Function LoadConfigFile(Filename)  
  50. Const ForReading = 1, ForWriting = 2, ForAppending = 8  
  51. Dim LCArray()  
  52. LoopVal = 0  
  53. Set fs = CreateObject("Scripting.FileSystemObject")  
  54. Set a = fs.OpenTextFile(Filename,ForReading,False)  
  55. Do While Not a.AtEndOfStream  
  56.     FileLine = a.ReadLine()  
  57.     if Left(FileLine,1) = ";" Then  
  58.         'Wscript.Echo "Skip ; for comments"'  
  59.     Else  
  60.         SubStrings = SplitEx(FileLine," ")  
  61.         If UBound(SubStrings) = 1 Then  
  62.             ReDim Preserve LCArray(LoopVal)  
  63.             LCArray(LoopVal) = SubStrings  
  64.             LoopVal = LoopVal + 1  
  65.         Else  
  66.             'Wscript.Echo "Skip blank lines"'  
  67.         End If  
  68.     End If  
  69. Loop  
  70. a.Close  
  71. LoadConfigFile = LCArray  
  72. End Function  
  73.   
  74. Private Function CalcRegionString(InString, ConfigArrayElement)  
  75. CalcRegionString = InString  
  76. For LoopVal = 1 To UBound(ConfigArrayElement)  
  77.     If Left(ConfigArrayElement(LoopVal), 1) = "@" Then  
  78.     CalcRegionString = Right(ConfigArrayElement(LoopVal), Len(ConfigArrayElement(LoopVal))-1)  
  79.     End If  
  80. Next   
  81. End Function  
  82.   
  83. Private Function FindReplaceStrings(SubStrings, ConfigArray, StringToReplace, ReplaceString)  
  84. FindReplaceStrings = False  
  85. LoopVal = 0  
  86. For LoopVal = 0 To UBound(ConfigArray)  
  87. If SubStrings(0) = ConfigArray(LoopVal)(0) Then  
  88.   
  89.     If UBound(SubStrings) = 2 Then  
  90.     TypeString = CalcRegionString("", ConfigArray(LoopVal))  
  91.     StringToReplace = SubStrings(1)  
  92.     ReplaceString = SubStrings(2) + " " + TypeString  
  93.     FindReplaceStrings = True  
  94.     End If  
  95.       
  96.     If UBound(SubStrings) = 3 Then  
  97.     TypeString = CalcRegionString(SubStrings(3), ConfigArray(LoopVal))  
  98.     StringToReplace = SubStrings(2)  
  99.     ReplaceString = TypeString  
  100.     FindReplaceStrings = True  
  101.     End If  
  102.   
  103. End If  
  104. Next  
  105. End Function  
  106.   
  107.   
  108. ' Main Function  
  109. '  
  110. '  
  111. ' Read Program Arguments  
  112. Set Args = Wscript.Arguments  
  113.   
  114. if Args.count <> 3 then  
  115. Wscript.Echo "Error: Invalid Number of arguments"  
  116. Wscript.Echo ""  
  117. Wscript.Echo "Usage: cscript bibhelper.vbs configfile inbibfile outbibfile"  
  118. Wscript.Quit  
  119. End if