Advertisement
Guest User

Evan Black

a guest
Nov 28th, 2010
378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.14 KB | None | 0 0
  1. <?php
  2.  
  3. $WIN32=0;
  4. $openocd_cmd="";
  5.  
  6. /* find out if we run on Linux/Windows*/
  7. /*if (strstr($_ENV["OS"], "Windows"))
  8.     $WIN32=1; */
  9.  
  10. if ($argc != 2){
  11.     print_help_message();
  12.     exit(1);
  13. }
  14.  
  15. $target= $argv[1];
  16.  
  17. if ($target != "nand" && $target != "mmc")
  18.     die("installer supports installing kernel and filesystem to: mmc, nand\n");
  19.  
  20. function print_help_message() {
  21.     global $WIN32;
  22.  
  23.     if ($WIN32==1)
  24.         echo "usage:  runme.exe [ nand | mmc ]\n";
  25.     else
  26.         echo "usage:  php runme.php [ nand | mmc ]\n";
  27. }
  28.  
  29. $fw_setenv= "uboot/uboot-env/fw_setenv";
  30. if ($WIN32==1){
  31.     /* executable for windows is with exe extention */
  32.     $fw_setenv= str_replace("/","\\",$fw_setenv);
  33.     $fw_setenv.= ".exe";
  34.  
  35.     /* add the win32 to the process PATH for Cygwin dll */
  36.     $path=getenv("PATH");
  37.     $dllpath= ";".getcwd()."\win32";
  38.     $path.= $dllpath;
  39.     putenv("PATH={$path}");
  40. }
  41. else
  42. {
  43. /*    if ($_ENV["USER"] != 'root')
  44.         die("You must run this as root\n"); */
  45.  
  46.     echo "\n ****   exec(modprobe ftdi_sio vendor=0x9e88 product=0x9e8f)";
  47.     exec("modprobe ftdi_sio vendor=0x9e88 product=0x9e8f", $out, $rc);
  48.  
  49.     if ($rc)
  50.         die("modprobe ftdi_sio vendor=0x9e88 product=0x9e8f FAILED\n");
  51. }
  52.  
  53. /* this routine adds uboot environment to uboot-env.bin that resides in CWD
  54.  * according to text file, skipping # and empty lines
  55.  */
  56. function set_uboot_env($infile) {
  57.     global $fw_setenv, $WIN32;
  58.  
  59.     if ($WIN32==1)
  60.         $infile= str_replace("/","\\",$infile);
  61.  
  62.     if (!file_exists($infile))
  63.         die("input file is missing: $infile");
  64.  
  65.     $lines = file($infile, FILE_SKIP_EMPTY_LINES | FILE_IGNORE_NEW_LINES);
  66.  
  67.     echo "reading $infile\n";
  68.  
  69.     for ($i=0; $i<count($lines); $i++) {
  70.         $line=trim($lines[$i]);
  71.         if (strlen($line) == 0)
  72.             continue;
  73.  
  74.         if (substr($line, 0, 1) == '#')
  75.             continue;
  76.  
  77.         $cmd= $fw_setenv." ";
  78.         $cmd.= ($WIN32==1) ? $line : escapeshellcmd($line);
  79.         echo "$cmd\n";
  80.         exec($cmd, $out, $rc);
  81.     }
  82.     return 0;
  83. }
  84.  
  85. function beep ($int_beeps = 1) {
  86.     for ($i = 0; $i < $int_beeps; $i++): $string_beeps .= "\x07"; endfor;
  87.     print $string_beeps;
  88. }
  89.  
  90. /* remove the last uboot-env.bin and create an empty one */
  91. if (file_exists("uboot-env.bin")){
  92.     unlink("uboot-env.bin");
  93.     if (file_exists("uboot-env.bin"))
  94.         die("could not delete uboot-env.bin");
  95. }
  96.  
  97. touch("uboot-env.bin");
  98.  
  99. echo "\n ****   Preparing environment variables file ...\n";
  100.  
  101. /* Update environment variable file image */
  102. set_uboot_env("uboot/uboot-env/uboot-dflt.txt");
  103. set_uboot_env("uboot/uboot-env/uboot-{$target}-custom.txt");
  104.  
  105. /* move the uboot-env.bin to the uboot directory */
  106. if (file_exists("uboot/uboot-env.bin")){
  107.     unlink("uboot/uboot-env.bin");
  108.     if (file_exists("uboot/uboot-env.bin"))
  109.         die("could not delete uboot/uboot-env.bin");
  110. }
  111.  
  112. rename("uboot-env.bin", "uboot/uboot-env.bin");
  113.  
  114. echo "\n ****   Burning uboot and environment variables ... This will take few minutes ...\n";
  115. if ($WIN32==1)
  116.     echo " **** When uboot.bin is written to NAND/SD, Disconnect and connect your mini USB cable\n";
  117.  
  118. chdir("uboot");
  119. $openocd_cmd= "openocd/openocd";
  120. $openocd_cmd.= ($WIN32==1) ? ".exe" : "";
  121. $openocd_cmd.= " -f openocd/config/board/sheevaplug.cfg";
  122. $openocd_cmd.= " -s openocd/config/";
  123. $openocd_cmd.= " -c init";
  124. $openocd_cmd.= " -c sheevaplug_reflash_uboot_env";
  125. $openocd_cmd.= " -c sheevaplug_reflash_uboot";
  126. $openocd_cmd.= ($WIN32==1) ? " -c init" : " -c exit";
  127.  
  128. /* replace slash to backslash for windows */
  129. if ($WIN32==1)
  130.     $openocd_cmd= str_replace("/","\\",$openocd_cmd);
  131.  
  132. unset($rc);
  133. /* Burn u-boot environment variables first, then u-boot */
  134. exec($openocd_cmd, $out, $rc);
  135.  
  136. /* remove the uboot-env.bin file */
  137. unlink("uboot-env.bin");
  138. chdir("..");
  139.  
  140. if ($rc) {
  141.     echo <<<EOT
  142.  ****   openocd FAILED
  143.  ****   Is the mini USB cable connected?
  144.  ****   Try powering down, then replugging the Sheevaplug
  145. EOT;
  146.     exit(1);
  147. }
  148.  
  149. if ($WIN32==1)
  150.     echo "\n ****   Disconnect and connect your mini USB cable";
  151. echo "\n ****   U-boot should be up and running now. Open your console ...\n";
  152. beep(1);
  153.  
  154. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement