memtest-hyperram.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/usr/bin/python3
  2. import sys
  3. from memtest import WishboneInterface, MemoryTester, HDMIOutput
  4. from memtest import HyperRAMController
  5. # ----------------------------------------------------------------------------
  6. # Main
  7. # ----------------------------------------------------------------------------
  8. def RAM_ADDR_CS(cs, addr):
  9. return (cs << 30) | addr
  10. def main(argv0, port='/dev/ttyUSB1', filename=None):
  11. # Connect to board
  12. wb = WishboneInterface(port)
  13. # Devices on the bus
  14. hyperram = HyperRAMController(wb, 0x00000)
  15. memtest = MemoryTester(wb, 0x10000)
  16. hdmi = HDMIOutput(wb, 0x20000)
  17. # Make sure to disable DMA
  18. hdmi.disable()
  19. wb.aux_csr(0)
  20. # Initialize HyperRAM core
  21. if hyperram.init() is False:
  22. print("[!] Init failed")
  23. return -1
  24. hyperram.set_runtime(True)
  25. # What mode ?
  26. if filename is None:
  27. # Run memtest
  28. for cs in range(4):
  29. if not (hyperram.csm & (1 << cs)):
  30. continue
  31. print("[+] Testing CS=%d" % cs)
  32. good = memtest.run(RAM_ADDR_CS(cs, 0), 1<<21)
  33. if good:
  34. print("[.] All good !")
  35. else:
  36. print("[!] Errors found !")
  37. else:
  38. # Load data file
  39. print("[+] Uploading image data")
  40. img = open(filename, 'rb').read()
  41. img = bytearray([(a << 4) | b for a, b in zip(img[0::2], img[1::2])])
  42. memtest.load_data(RAM_ADDR_CS(3, 0), img)
  43. # Palette (1:1)
  44. print("[+] Uploading palette")
  45. for i in range(4*16):
  46. hdmi.pal_write(i, i&15)
  47. # Start DMA
  48. print("[+] Starting DMA")
  49. wb.aux_csr(1)
  50. hdmi.enable(RAM_ADDR_CS(3, 0), 16)
  51. # Done
  52. return 0
  53. if __name__ == '__main__':
  54. sys.exit(main(*sys.argv) or 0)