char *Replace;\r
} MATCH_PAIR;\r
\r
+void\r
+Usage (char *Name)\r
+{\r
+ printf ("\n%s OldFile NewFile MatchString ReplaceString [MatchString2 ReplaceString2]*\n", Name);\r
+ printf (" OldFile - Must be arg[1] File to search for MatchStrings\n");\r
+ printf (" NewFile - Must be arg[2] File where MatchString has been replaced with ReplaceString\n");\r
+ printf (" MatchString & ReplaceString. Required arguments.\n");\r
+ printf (" More MatchString/ReplaceString pairs are supported.\n");\r
+}\r
+\r
//\r
// argv[1] - Old File\r
// argv[2] - New File\r
int Found;\r
\r
if (argc < 5) {\r
- // Need at least two files and two strings\r
+ fprintf (stderr, "Need at least two files and one Match/Replacement string pair\n");\r
+ Usage (argv[0]);\r
return -1;\r
} else if ((argc % 2) == 0) {\r
- // Match and Replace string must come in pairs\r
+ fprintf (stderr, "Match and Replace string must come in pairs\n");\r
return -4;\r
}\r
\r
fseek (In, 0, SEEK_END);\r
InFileSize = ftell (In);\r
if (InFileSize == 0) {\r
+ fprintf (stderr, "Could not open %s\n", argv[1]);\r
return -6;\r
}\r
fseek (In, 0, SEEK_SET);\r
\r
Out = fopen (argv[2], "w+");\r
if ((In == NULL) || (Out == NULL)) {\r
+ fprintf (stderr, "Could not open %s\n", argv[2]);\r
return -2;\r
}\r
\r
MaxMatch = (argc - 2)/2;\r
- printf ("\nMaxMatch = %d:%d\n", MaxMatch, argc);\r
Match = calloc (MaxMatch, sizeof (MATCH_PAIR));\r
if (Match == NULL) {\r
return -7;\r
Match[n].Match = argv[3 + n*2];\r
Match[n].MatchSize = strlen (argv[3 + n*2]);\r
Match[n].Replace = argv[3 + n*2 + 1];\r
-printf ("%s > %s\n", Match[n].Match, Match[n].Replace);\r
if (Match[n].MatchSize > MaxLenKey) {\r
// Max size of match/replace string pair\r
MaxLenKey = Match[n].MatchSize;\r
return -5;\r
}\r
\r
+ // Search for a match by reading every possition of the file\r
+ // into a buffer that is as big as the maximum search key size.\r
+ // Then we can search the keys for a match. If no match\r
+ // copy the old file character to the new file. If it is a match\r
+ // then copy the replacement string into the output file. \r
+ // This code assumes the file system is smart and caches the \r
+ // file in a buffer. So all the reads don't really hit the disk. \r
InFilePos = 0;\r
while (InFilePos < (InFileSize - MinLenKey)) {\r
fseek (In, InFilePos, SEEK_SET);\r
for (i = 0, Found = FALSE;i < MaxMatch; i++) {\r
if (ReadCount >= Match[i].MatchSize) {\r
if (!memcmp (Key, Match[i].Match, Match[i].MatchSize)) {\r
- printf ("Found [%s] @ %u\n", Match[i].Match, InFilePos);\r
InFilePos += (Match[i].MatchSize - 1);\r
- printf ("InFilePos = %u", InFilePos);\r
fputs (Match[i].Replace, Out);\r
Found = TRUE;\r
break;\r
InFilePos++;\r
}\r
\r
+ // We stoped searching when we got to the point that we could no longer match.\r
+ // So the last few bytes of the file are not copied in the privous loop\r
+ fseek (In, InFilePos, SEEK_SET);\r
+ while ((c = fgetc (In)) != EOF) {\r
+ fputc (c, Out);\r
+ }\r
\r
fclose (In);\r
fclose (Out);\r
free (Key);\r
+ free (Match);\r
return 0;\r
}\r
\r
@REM b release clean
@REM b -v -y build.log
-
+ECHO OFF
+@REM Setup Build environment. Sets WORKSPACE and puts build in path
CALL ..\edksetup.bat
+
+@REM Set for tools chain. Currently RVCT31
SET TARGET_TOOLS=RVCT31
SET TARGET=DEBUG
\r
@if /I "%1"=="RELEASE" (\r
+ @REM If 1st argument is release set TARGET to RELEASE and shift arguments to remove it \r
SET TARGET=RELEASE\r
shift /1\r
)\r
SET BUILD_ROOT=%WORKSPACE%\Build\BeagleBoard\%TARGET%_%TARGET_TOOLS%
-BUILD_ROOT=$WORKSPACE/Build/BeagleBoard/"$TARGET"_"$TARGET_TOOLS"
+@REM Build the Beagle Board firmware and creat an FD (FLASH Device) Image.
CALL build -p BeagleBoardPkg\BeagleBoardPkg.dsc -a ARM -t RVCT31 -b %TARGET% %1 %2 %3 %4 %5 %6 %7 %8
@if /I "%1"=="CLEAN" goto Clean\r
CALL nmake
ECHO Patching image with ConfigurationHeader.dat
-CALL GenerateImage -D ConfigurationHeader.dat -E 0x80008208 -I ../../Build/FV/BEAGLEBOARD_EFI.fd -O ../../Build/FV/BeagleBoard_EFI_flashboot.fd
+CALL GenerateImage -D ..\ConfigurationHeader.dat -E 0x80008208 -I %BUILD_ROOT%\FV\BEAGLEBOARD_EFI.fd -O %BUILD_ROOT%\FV\BeagleBoard_EFI_flashboot.fd
ECHO Patching ..\Debugger_scripts ...
SET DEBUGGER_SCRIPT=..\Debugger_scripts
-for /f %%a IN ('dir /b %DEBUGGER_SCRIPT%\*.inc %DEBUGGER_SCRIPT%\*.cmm') do (
- CALL replace %DEBUGGER_SCRIPT%\%%a %BUILD_ROOT%\%%a ZZZZZZ %BUILD_ROOT% WWWWWW %WORKSPACE%
+@for /f %%a IN ('dir /b %DEBUGGER_SCRIPT%\*.inc %DEBUGGER_SCRIPT%\*.cmm') do (
+ @CALL replace %DEBUGGER_SCRIPT%\%%a %BUILD_ROOT%\%%a ZZZZZZ %BUILD_ROOT% WWWWWW %WORKSPACE%
)
cd ..