openbcm

Git mirror of https://github.com/Broadcom-Network-Switching-Software/OpenBCM
git clone git://git.finwo.net/mirror/broadcom/openbcm
Log | Files | Refs | README

mt2_version.py (1117B)


      1 #!/usr/bin/env python
      2 
      3 #
      4 # This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
      5 # 
      6 # Copyright 2007-2019 Broadcom Inc. All rights reserved.
      7 #
      8 
      9 import os, sys
     10 import array
     11 
     12 def parse_fw_file(fn):
     13     f = open(fn)
     14     data = f.read()
     15     f.close()
     16 
     17     length = len(data)
     18     hp = 0
     19 
     20     while (hp < length) :
     21        if (data[hp:hp+5] != "MAGIC") :
     22            print "Invalid firmware file !"
     23            return
     24 
     25 
     26        section_length =  (ord(data[hp+5]) << 16) + (ord(data[hp+6]) << 8) + ord(data[hp+7])
     27 
     28        if ((ord(data[hp+8]) == 0x1) and (ord(data[hp+10]) == 0x1)) :
     29            print "SRAM_CODE found"
     30            extract(data[hp+16:hp+16+section_length])
     31 #           return
     32 #       else:
     33 #           print "NON SRAM_SECTION"
     34 
     35        hp += section_length + 16
     36 
     37 
     38 def extract(data):
     39     a=array.array("L",data)
     40     a.byteswap()
     41     data=a.tostring()
     42     p = data[8:].split('\x00')
     43     print p[0]
     44 
     45 if __name__ == '__main__':
     46     if len(sys.argv) < 2:
     47         print 'Usage: version.py file'
     48     else:
     49         parse_fw_file(sys.argv[1])
     50 
     51