norpropgen.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/env python3
  2. # Copyright (C) 2018 RDA Technologies Limited and/or its affiliates("RDA").
  3. # All rights reserved.
  4. #
  5. # This software is supplied "AS IS" without any warranties.
  6. # RDA assumes no responsibility or liability for the use of the software,
  7. # conveys no license or title under any patent, copyright, or mask work
  8. # right to the product. RDA reserves the right to make changes in the
  9. # software without notification. RDA also make no representation or
  10. # warranty that such application will be suitable for the specified use
  11. # without further testing or modification.
  12. import argparse
  13. import sys
  14. import csv
  15. import re
  16. DESCRIPTION = """
  17. Generate nor flash properties from csv
  18. """
  19. def main():
  20. parser = argparse.ArgumentParser(description=DESCRIPTION)
  21. parser.add_argument("csv",
  22. help="csv file for nor flash properties")
  23. parser.add_argument("prop",
  24. help="output nor flash properties file")
  25. args = parser.parse_args()
  26. propnames = []
  27. props = []
  28. with open(args.csv, 'r') as fh:
  29. for row in csv.reader(fh):
  30. if not row[0] and not row[1]: # maybe empty line
  31. continue
  32. if not row[0]: # title
  33. propnames = row[1:]
  34. continue
  35. prop = {'name': row[0]}
  36. for n in range(len(propnames)):
  37. prop[propnames[n]] = row[n+1]
  38. props.append(prop)
  39. with open(args.prop, 'w') as fh:
  40. for prop in props:
  41. flash_name = prop['name']
  42. fh.write('#ifndef DISABLE_{}\n'.format(flash_name))
  43. fh.write('{{ // {}\n'.format(flash_name))
  44. for pname in propnames:
  45. fh.write(" .{} = {},\n".format(pname, prop[pname]))
  46. fh.write('},\n')
  47. fh.write('#endif\n')
  48. return 0
  49. if __name__ == "__main__":
  50. main()