Advertisement
Guest User

Patched update_syscon.pl

a guest
Dec 21st, 2012
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/perl
  2. #
  3. # Sony CONFIDENTIAL
  4. #
  5. # Copyright 2006 Sony Corporation.
  6. #
  7. # DO NOT COPY AND/OR REDISTRIBUTE WITHOUT PERMISSION.
  8. #
  9. # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  10. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  11. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  12. # ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  13. # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  14. # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  15. # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  16. # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  17. # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  18. # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  19. # SUCH DAMAGE.
  20. #
  21.  
  22. # do nothing if DisSW says "ignore SYSCON"
  23. `grep -q 0 /proc/ps3tool_gpio/SC_MODEX`;
  24. if ($? != 0) {
  25.     exit 0;
  26. }
  27.  
  28. if ($#ARGV < 1) {
  29.     print "usage: $0 updatefile version\n";
  30.     exit 1;
  31. }
  32.  
  33. $updatefile = shift @ARGV;
  34. $new_version = shift @ARGV;
  35.  
  36. $current_version = `/usr/local/sony/bin/scver`;
  37. $result = $?/256;
  38. if ($result == 0) {
  39.     # erase last "\n"
  40.     $current_version =~ s/\n$//;
  41.  
  42.     $result = &is_maskrom($current_version);
  43.     if ($result != 0) {
  44.         exit 0;
  45.     }
  46.  
  47.     $result = &parse_version($current_version,
  48.                 \$current_major,\$current_middle,\$current_minor,\$current_release);
  49.     if ($result != 0) {
  50.         $result += 100;
  51.         exit $result;
  52.     }
  53.  
  54.     $result = &parse_version($new_version,
  55.                 \$new_major,\$new_middle,\$new_minor,\$new_release);
  56.     if ($result != 0) {
  57.         $result += 200;
  58.         exit $result;
  59.     }
  60.  
  61.     if ($current_major > $new_major) {
  62.         #exit 0;
  63.     }
  64.     elsif ($current_major == $new_major) {
  65.  
  66.         if ($current_middle > $new_middle) {
  67.             #exit 0;
  68.         }
  69.         elsif ($current_middle == $new_middle) {
  70.  
  71.             if ($current_minor > $new_minor) {
  72.                 #exit 0;
  73.             }
  74.             elsif ($current_minor == $new_minor) {
  75.  
  76.                 if ($current_release > $new_release) {
  77.                     #exit 0;
  78.                 }
  79.                 elsif ($current_release == $new_release) {
  80.  
  81.                     if ($current_version eq $new_version) {
  82.                         #exit 0;
  83.                     }
  84.                 }
  85.             }
  86.         }
  87.     }
  88.  
  89.     print "Updating syscon: $current_version => $new_version...";
  90. }
  91. else {
  92.     print "Updating syscon to $new_version...";
  93. }
  94.  
  95. `/usr/local/sony/bin/scfirmup $updatefile`;
  96. $result = $?/256;
  97. if ($result == 0) {
  98.     print " done.\n";
  99. }
  100. else {
  101.     print " failed. ($result)\n";
  102. }
  103. exit $result;
  104.  
  105. sub cut_directory
  106. {
  107.     my($pathname) = $_[0];
  108.     my($index);
  109.  
  110.     $index = rindex($pathname, '/');
  111.     if ($index < 0) {
  112.         return $pathname;
  113.     }
  114.     else {
  115.         return substr($pathname, $index + 1, length($pathname) - $index - 1);
  116.     }
  117. }
  118.  
  119. sub is_maskrom
  120. {
  121.     my($version) = $_[0];
  122.     if ($version =~ /^.*_d.*$/) {
  123.         return 1;
  124.     }
  125.  
  126.     return 0;
  127. }
  128.  
  129. sub parse_version
  130. {
  131.     my($version)    = $_[0];
  132.     my($major)      = $_[1];
  133.     my($middle)     = $_[2];
  134.     my($minor)      = $_[3];
  135.     my($release)    = $_[4];
  136.     my($index);
  137.  
  138.     # erase directory parts
  139. #   $version = &cut_directory($version);
  140.  
  141.     # convert all non-digit characters => '_'
  142.     $version =~ tr/0-9/_/c;
  143.  
  144.     # erase top underscores
  145.     $version =~ s/^[_]*//;
  146.  
  147.     # extract top number as a major version
  148.     $index = index($version, '_');
  149.     if ($index < 0) {
  150.         return 1;
  151.     }
  152.     $$major = substr($version, 0, $index);
  153.  
  154.     # erase top number, underscores
  155.     $version =~ s/^[0-9]*[_]*//;
  156.  
  157.     # extract top number as a middle version
  158.     $index = index($version, '_');
  159.     if ($index < 0) {
  160.         return 2;
  161.     }
  162.     $$middle = substr($version, 0, $index);
  163.  
  164.     # erase top number, underscores
  165.     $version =~ s/^[0-9]*[_]*//;
  166.  
  167.     # extract top number as a minor version
  168.     $index = index($version, '_');
  169.     if ($index < 0) {
  170.         return 3;
  171.     }
  172.     $$minor = substr($version, 0, $index);
  173.  
  174.     # erase top number, underscores
  175.     $version =~ s/^[0-9]*[_]*//;
  176.  
  177.     # extract top number as a release version
  178.     $index = index($version, '_');
  179.     if ($index < 0) {
  180.         $$release = $version;
  181.     }
  182.     else {
  183.         $$release = substr($version, 0, $index);
  184.     }
  185.  
  186.     return 0;
  187. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement