]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Update so Windows build works like Cygwin buid
authorandrewfish <andrewfish@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 5 Feb 2010 18:43:49 +0000 (18:43 +0000)
committerandrewfish <andrewfish@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 5 Feb 2010 18:43:49 +0000 (18:43 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9940 6f19259b-4bc3-4df7-8a09-765794883524

BeagleBoardPkg/Tools/generate_image.c
BeagleBoardPkg/Tools/replace.c
BeagleBoardPkg/b.bat

index c1aebfef575721c28545428da5f89ebd182ec654..65351380c87ea2e28668d7f2bcaec7fcc8ee5afb 100644 (file)
@@ -255,7 +255,7 @@ PrepareConfigurationHeader (
   // Open data file
   DataFile = fopen(gDataFile, "rb");
   if (DataFile == NULL) {
   // Open data file
   DataFile = fopen(gDataFile, "rb");
   if (DataFile == NULL) {
-    fprintf(stderr, "Can't open data file %s.\n", gOutputImageFile);
+    fprintf(stderr, "Can't open data file %s.\n", gDataFile);
     exit(1);
   }
   
     exit(1);
   }
   
@@ -394,7 +394,6 @@ main (
         default:
           abort ();
       }
         default:
           abort ();
       }
-      printf ("\n%d(%x) - %s %s", i, TwoArg, argv[i], TwoArg ? argv[i+1] : &argv[i][2]); 
     }
   }
 
     }
   }
 
index d26d1274811f852121ea9e5e952b191a987d0e90..8e09d9a6a10d72b32a13697381b1b9178f37c30c 100755 (executable)
@@ -26,6 +26,16 @@ typedef struct {
   char  *Replace;\r
 } MATCH_PAIR;\r
 \r
   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
 //\r
 // argv[1] - Old File\r
 // argv[2] - New File\r
@@ -44,10 +54,11 @@ main (int argc, char **argv)
   int Found;\r
 \r
   if (argc < 5) {\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
     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
     return -4;\r
   }\r
 \r
@@ -55,6 +66,7 @@ main (int argc, char **argv)
   fseek (In, 0, SEEK_END);\r
   InFileSize = ftell (In);\r
   if (InFileSize == 0) {\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
     return -6;\r
   }\r
   fseek (In, 0, SEEK_SET);\r
@@ -62,11 +74,11 @@ main (int argc, char **argv)
 \r
   Out = fopen (argv[2], "w+");\r
   if ((In == NULL) || (Out == NULL)) {\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
     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 = calloc (MaxMatch, sizeof (MATCH_PAIR));\r
   if (Match == NULL) {\r
     return -7;\r
@@ -76,7 +88,6 @@ main (int argc, char **argv)
     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
     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
     if (Match[n].MatchSize > MaxLenKey) {\r
       // Max size of match/replace string pair\r
       MaxLenKey = Match[n].MatchSize;\r
@@ -91,6 +102,13 @@ printf ("%s > %s\n", Match[n].Match, Match[n].Replace);
     return -5;\r
   }\r
 \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
   InFilePos = 0;\r
   while (InFilePos < (InFileSize - MinLenKey)) {\r
     fseek (In, InFilePos, SEEK_SET);\r
@@ -98,9 +116,7 @@ printf ("%s > %s\n", Match[n].Match, Match[n].Replace);
     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
     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
           InFilePos += (Match[i].MatchSize - 1);\r
-          printf ("InFilePos = %u", InFilePos);\r
           fputs (Match[i].Replace, Out);\r
           Found = TRUE;\r
           break;\r
           fputs (Match[i].Replace, Out);\r
           Found = TRUE;\r
           break;\r
@@ -114,10 +130,17 @@ printf ("%s > %s\n", Match[n].Match, Match[n].Replace);
     InFilePos++;\r
   }\r
 \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
  \r
   fclose (In);\r
   fclose (Out);\r
   free (Key);\r
+  free (Match);\r
   return 0;\r
 }\r
 \r
   return 0;\r
 }\r
 \r
index 32501eea6dac898f1408bce2c6c54f585e27e89c..3643be3f4bc4e3e597e1b70817e21dcc3150bbf7 100755 (executable)
 @REM b release clean
 @REM b -v -y build.log
 
 @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
 CALL ..\edksetup.bat
+
+@REM Set for tools chain. Currently RVCT31
 SET TARGET_TOOLS=RVCT31
 SET TARGET=DEBUG
 \r
 @if /I "%1"=="RELEASE" (\r
 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%
   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 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
@@ -45,12 +49,12 @@ ECHO Building tools...
 CALL nmake 
 
 ECHO Patching image with ConfigurationHeader.dat
 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
 
 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 ..
 )
 
 cd ..