eva_ramboot.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/env python3
  2. import argparse
  3. from ftplib import FTP
  4. from sys import argv
  5. from os import stat
  6. parser = argparse.ArgumentParser(description='Tool to boot AVM EVA ramdisk images.')
  7. parser.add_argument('ip', type=str, help='IP-address to transfer the image to')
  8. parser.add_argument('image', type=str, help='Location of the ramdisk image')
  9. parser.add_argument('--offset', type=lambda x: int(x,0), help='Offset to load the image to in hex format with leading 0x. Only needed for non-lantiq devices.')
  10. args = parser.parse_args()
  11. size = stat(args.image).st_size
  12. # arbitrary size limit, to prevent the address calculations from overflows etc.
  13. assert size < 0x2000000
  14. if args.offset:
  15. addr = size
  16. haddr = args.offset
  17. else:
  18. # We need to align the address.
  19. # A page boundary seems to be sufficient on 7362sl and 7412
  20. addr = ((0x8000000 - size) & ~0xfff)
  21. haddr = 0x80000000 + addr
  22. img = open(args.image, "rb")
  23. ftp = FTP(args.ip, 'adam2', 'adam2')
  24. def adam(cmd):
  25. print("> %s"%(cmd))
  26. resp = ftp.sendcmd(cmd)
  27. print("< %s"%(resp))
  28. assert resp[0:3] == "200"
  29. ftp.set_pasv(True)
  30. # The following parameters allow booting the avm recovery system with this
  31. # script.
  32. adam('SETENV memsize 0x%08x'%(addr))
  33. adam('SETENV kernel_args_tmp mtdram1=0x%08x,0x88000000'%(haddr))
  34. adam('MEDIA SDRAM')
  35. ftp.storbinary('STOR 0x%08x 0x88000000'%(haddr), img)
  36. img.close()
  37. ftp.close()