您的位置:首页 > 其它

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

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

1、做一个批处理放在BSP的Files/premake目录下供PB调用,文件内容如下:
echo.
echo %_TGTPLAT%-preri processing...
echo.
if "%IMGMULTIXIP%"=="1" cd %_TARGETPLATROOT%/Files/premake
if "%IMGMULTIXIP%"=="1" copy %_FLATRELEASEDIR%/ce.bib %_TARGETPLATROOT%/Files/premake
if "%IMGMULTIXIP%"=="1" copy ce.bib ce_orig.bib
if "%IMGMULTIXIP%"=="1" oembibhelper multibin.txt ce_orig.bib ce.bib
if "%IMGMULTIXIP%"=="1" copy ce.bib %_FLATRELEASEDIR%
if "%IMGMULTIXIP%"=="1" cd %_FLATRELEASEDIR%
if "%IMGMULTIXIP%"=="1" romimage ce.bib

2、oembibhelper.vbs脚本的内容如下:
'
' Copyright (c) Microsoft Corporation.  All rights reserved.
'
'
' Use of this sample source code is subject to the terms of the Microsoft
' license agreement under which you licensed this sample source code. If
' you did not accept the terms of the license agreement, you are not
' authorized to use this sample source code. For the terms of the license,
' please see the license agreement between you and Microsoft or, if applicable,
' see the LICENSE.RTF on your install media or the root of your tools installation.
' THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
'

' Modified this bibhelper.vbs to modify the bib to implement the Multi-Bin
' For example: "nk.exe @XIPKERN" of config file will make nk.exe packed into XIPKERN.bin 
'
Public Function SplitEx(InputText,Delimiter)

' This function splits the sentence in InputText into
' words and returns a string array of the words. Each
' element of the array contains one word.

    ' This constant contains punctuation and characters
    ' that should be filtered from the input string.
    Dim strReplacedText
    Dim intIndex

    ' Replace tab characters with space characters.
    ' Replace tab characters with space characters.
    strReplacedText = Trim(Replace(InputText, vbTab, " "))

    ' Loop until all consecutive space characters are
    ' replaced by a single space character.
    Do While InStr(strReplacedText, "  ")
        strReplacedText = Replace(strReplacedText, "  ", " ")
    Loop

    ' Split the sentence into an array of words and return
    ' the array. If a delimiter is specified, use it.
    'MsgBox "String:" & strReplacedText
    If Len(Delimiter) = 0 Then
        SplitEx = Split(strReplacedText)
    Else
        SplitEx = Split(strReplacedText, Delimiter)
    End If
End Function

Private Function LoadConfigFile(Filename)
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim LCArray()
LoopVal = 0
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.OpenTextFile(Filename,ForReading,False)
Do While Not a.AtEndOfStream
    FileLine = a.ReadLine()
    if Left(FileLine,1) = ";" Then
        'Wscript.Echo "Skip ; for comments"'
    Else
        SubStrings = SplitEx(FileLine," ")
        If UBound(SubStrings) = 1 Then
            ReDim Preserve LCArray(LoopVal)
            LCArray(LoopVal) = SubStrings
            LoopVal = LoopVal + 1
        Else
            'Wscript.Echo "Skip blank lines"'
        End If
    End If
Loop
a.Close
LoadConfigFile = LCArray
End Function

Private Function CalcRegionString(InString, ConfigArrayElement)
CalcRegionString = InString
For LoopVal = 1 To UBound(ConfigArrayElement)
    If Left(ConfigArrayElement(LoopVal), 1) = "@" Then
    CalcRegionString = Right(ConfigArrayElement(LoopVal), Len(ConfigArrayElement(LoopVal))-1)
    End If
Next 
End Function

Private Function FindReplaceStrings(SubStrings, ConfigArray, StringToReplace, ReplaceString)
FindReplaceStrings = False
LoopVal = 0
For LoopVal = 0 To UBound(ConfigArray)
If SubStrings(0) = ConfigArray(LoopVal)(0) Then

    If UBound(SubStrings) = 2 Then
    TypeString = CalcRegionString("", ConfigArray(LoopVal))
    StringToReplace = SubStrings(1)
    ReplaceString = SubStrings(2) + " " + TypeString
    FindReplaceStrings = True
    End If
    
    If UBound(SubStrings) = 3 Then
    TypeString = CalcRegionString(SubStrings(3), ConfigArray(LoopVal))
    StringToReplace = SubStrings(2)
    ReplaceString = TypeString
    FindReplaceStrings = True
    End If

End If
Next
End Function

' Main Function
'
'
' Read Program Arguments
Set Args = Wscript.Arguments

if Args.count <> 3 then
Wscript.Echo "Error: Invalid Number of arguments"
Wscript.Echo ""
Wscript.Echo "Usage: cscript bibhelper.vbs configfile inbibfile outbibfile"
Wscript.Quit
End if

' Read the Configuration File to determine what modules need to be changed and how
ConfigArray = LoadConfigFile(Args(0))

'Open in and out bib files

Const ForReading = 1, ForWriting = 2, ForAppending = 8
   

Set fs = CreateObject("Scripting.FileSystemObject")
Set inbibfile = fs.OpenTextFile(Args(1),ForReading,False)
Set outbibfile = fs.OpenTextFile(Args(2),ForWriting,True)

' Loop through lines in bib file
Do While Not inbibfile.AtEndOfStream
' Read in current bib file line
FileLine = inbibfile.ReadLine()
SubStrings = SplitEx(FileLine," ")
' Determine if current in bib file line needs to be changed
ChangeLine = False
If UBound(SubStrings) > -1 Then ChangeLine = FindReplaceStrings(SubStrings, ConfigArray, StringToReplace, ReplaceString)
' Change in file line if necessary
If ChangeLine Then
ReplaceStartPos = InStr(1, FileLine, SubStrings(1), vbTextCompare) + Len(SubStrings(1))
FileLine = Left(FileLine, ReplaceStartPos-1) + Replace(FileLine, StringToReplace, ReplaceString, ReplaceStartPos)
End If
' Write in file line to out bib file
outbibfile.WriteLine (FileLine)
Loop

' Close bib files
inbibfile.Close
outbibfile.Close

3、multibin.txt是需要加入XIP的文件,可根据需要修改,内容如下仅供参考
; This file is input for oembibhelper.vbs.
; It only support the pairs like "nk.exe @XIPKERN"
; Besides that, it supports blank lines and comments start with ";" as first char of the line.

   nk.exe                   @XIPKERNEL
   osaxst0.dll              @XIPKERNEL
   hd.dll                   @XIPKERNEL
   coredll.dll              @XIPKERNEL
   filesys.exe              @XIPKERNEL
   fatfsd.dll               @XIPKERNEL
   diskcache.dll            @XIPKERNEL
   fatutil.dll              @XIPKERNEL
   binfs.dll                @XIPKERNEL
   fsdmgr.dll               @XIPKERNEL
   mspart.dll               @XIPKERNEL
   ;smflash.dll              @XIPKERNEL
   bibdrv.dll               @XIPKERNEL
   camera.dll               @XIPKERNEL
   ;ondisk.dll               @XIPKERNEL
   boot.hv                  @XIPKERNEL
   ;default.hv               @XIPKERNEL
   ;user.hv                  @XIPKERNEL

4、在PB的“Platform”-"Settings"-"Custom Build Actions"-"Post-Make Image"加入如下规则
%_TARGETPLATROOT%/Files/premake/S80-preri.bat
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: