eva_ramboot.py 1.3 KB

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