conv_zip_test.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import binascii
  2. import os
  3. import sys
  4. import time
  5. import shutil
  6. LEN = 2**16
  7. huffman = False
  8. TARGET=os.getcwd()
  9. SOURCE=sys.argv[1]
  10. DEFLATE=os.path.basename(sys.argv[1]) + ".deflate"
  11. PATH="/Users/david/Devel/arch/avr/code/quickdev16/scripts"
  12. WINE="/Applications/Darwine/Wine.bundle/Contents/bin/wine"
  13. KZIP=os.path.join(PATH,"kzip.exe")
  14. DEFLOPT=os.path.join(PATH,"DeflOpt.exe")
  15. ZIP2RAW=os.path.join(PATH,"zip2raw.rb")
  16. method = 1
  17. if method==0:
  18. if os.path.isfile("rom.zip"):
  19. os.unlink("rom.zip")
  20. os.system("%s %s rom /s1 %s" % (WINE,KZIP,SOURCE))
  21. os.system("%s %s /a rom.zip" % (WINE,DEFLOPT))
  22. os.system("ruby %s rom.zip" % ZIP2RAW)
  23. if os.path.isfile("rom.zip"):
  24. os.unlink("rom.zip")
  25. data = open(DEFLATE).read()
  26. os.unlink(DEFLATE)
  27. else:
  28. os.system("gzip < %s >/tmp/test" % SOURCE )
  29. data = open("/tmp/test").read()
  30. os.unlink("/tmp/test")
  31. data = data[10:]
  32. zip_size = len(data)
  33. cfile = open("/tmp/loader_test.c","w")
  34. hfile = open("/tmp/loader_test.h","w")
  35. hfile.write('''
  36. #ifndef __FIFO_H__
  37. #define __FIFO_H__
  38. #define ROM_ZIP_SIZE %i
  39. ''' % zip_size)
  40. hfile.write('\n#endif\n')
  41. hfile.close()
  42. cfile.write('''/*
  43. File: %s
  44. Time: %s
  45. */
  46. ''')
  47. cfile.write('''
  48. const char _rom[%i] = {
  49. ''' % (zip_size))
  50. for idx,c in enumerate(data):
  51. c = ord(c)
  52. if idx<len(data)-1:
  53. cfile.write("0x%02x," % c)
  54. else:
  55. cfile.write("0x%02x" % c)
  56. if idx and idx%16==0:
  57. cfile.write("\n")
  58. cfile.write('''
  59. };
  60. ''')
  61. cfile.close()
  62. shutil.copy("/tmp/loader_test.c", os.path.join(TARGET,"loader_test.c"))
  63. shutil.copy("/tmp/loader_test.h", os.path.join(TARGET,"loader_test.h"))