def hexdump (bytes, addr=None, preamble=None, printfunc=None, stepsize=16):
  """hexdump(bytes[, addr[, preamble[, printfunc[, stepsize=16]]]])

  Outputs bytes in hexdump format lines similar to the following (here
  preamble='Bank1', stepsize=8, and len(bytes) == 15)::

    Bank1: 0xFD020000: 7f45  4c46  0102  0100  *.ELF....*
    Bank1: 0xFD020008: 0000  0000  0000  00    *....... *

  Where stepsize controls the number of bytes per line.  If addr is
  omitted, the address portion of the hexdump will not be output.
  Lines will be passed to printfunc for output, or Python's builtin
  print, if printfunc is omitted.

  If a byte is not in the range [32, 127), a period will rendered for
  the character portion of the output.
  """
  if preamble is None:
    preamble = ""

  bytes = bytearray(bytes)
  size  = len(bytes)

  for n in xrange(0, size, stepsize):
    if addr is not None:
      dump = preamble + "0x%04X: " % (addr + n)
    else:
      dump = preamble
    end   = min(size, n + stepsize)
    dump += hexdumpLine(bytes[n:end], stepsize)

    if printfunc is None:
      print dump
    else:
      printfunc(dump)