mkimg_bifferboard.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/env python
  2. """
  3. Create firmware for 4/8MB Bifferboards, suitable for uploading using
  4. either bb_upload8.py or bb_eth_upload8.py
  5. """
  6. import struct, sys
  7. # Increase the kmax value if the script gives errors about the kernel being
  8. # too large. You need to set the Biffboot kmax value to the same value you
  9. # use here.
  10. kmax = 0x10
  11. # No need to change this for 4MB devices, it's only used to tell you if
  12. # the firmware is too large!
  13. flash_size = 0x800000
  14. # This is always the same, for 1MB, 4MB and 8MB devices
  15. config_extent = 0x6000
  16. kernel_extent = kmax * 0x10000
  17. if __name__ == "__main__":
  18. if len(sys.argv) != 4:
  19. print "usage: mkimg_bifferboard.py <kernel> <rootfs> <output file>"
  20. sys.exit(-1)
  21. bzimage = sys.argv[1]
  22. rootfs = sys.argv[2]
  23. target = sys.argv[3]
  24. # Kernel first
  25. fw = file(bzimage).read()
  26. if len(fw) > (kernel_extent - config_extent):
  27. raise IOError("Kernel too large")
  28. # Pad up to end of kernel partition
  29. while len(fw) < (kernel_extent - config_extent):
  30. fw += "\xff"
  31. fw += file(rootfs).read()
  32. # Check length of total
  33. if len(fw) > (flash_size - 0x10000 - config_extent):
  34. raise IOError("Rootfs too large")
  35. file(target,"wb").write(fw)
  36. print "Firmware written to '%s'" % target