#!/usr/bin/python

# This tool convert the input file in "efuse+eeprom" format
# to the device.h format (to be compiled into IOS
# for verifying nvram content).
#   - The input file must be in the "eeprom" format.
#     This is the content generated by running the 
#     "eefuse.elf" program by reading out and displaying
#     the system efuse/eeprom
#
#       EFUSE[xx] = 01234567
#       ...
#       EEPROM[xxx] = 0123
#
#   - The output file device0.h will be generated.
#

import sys, string

lines = open(sys.argv[1]).readlines()

num = 0
last = 0

f = open("device%d.h" % num, "w")
f.write("u8 device[] = \n{");
line = {}
rawline = {}
for rawline in lines:
  line = string.rstrip(rawline)
  l = len(line)
  fuse = string.find(line, "FUSE")
  prom = string.find(line, "PROM")
  s = string.find(line, "=")
  print "==> line len=", l, " fuse=", fuse, "prom=", prom, "equal=", s
  if ((l > 15) and (fuse == 1) and (s > 9)):
    for i in range(s+2, l, 2):
      j = i + 1
      print i, j, l, line[i], line[j]
      f.write("0x"+line[i]+line[j]+", ")
  elif ((l > 15) and (prom == 2) and (s > 10)):
    for i in range(s+2, l, 2):
      j = i + 1
      print i, j, l, line[i], line[j]
      f.write("0x"+line[i]+line[j]+", ")
  else:
    print "skip line: ", line 

f.write("};\n");
f.write("\n");
f.close();

