Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

mkasm.py 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/env python3
  2. # Derived from pad_checksum in the Pico SDK, which carries the following
  3. # LICENSE.txt:
  4. # Copyright 2020 (c) 2020 Raspberry Pi (Trading) Ltd.
  5. #
  6. # Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
  7. # following conditions are met:
  8. #
  9. # 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
  10. # disclaimer.
  11. #
  12. # 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
  13. # disclaimer in the documentation and/or other materials provided with the distribution.
  14. #
  15. # 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products
  16. # derived from this software without specific prior written permission.
  17. #
  18. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  19. # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20. # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  21. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  22. # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  23. # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  24. # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. import argparse
  26. import binascii
  27. import struct
  28. import sys
  29. parser = argparse.ArgumentParser()
  30. parser.add_argument("ifile", help="Input file (binary)")
  31. parser.add_argument("ofile", help="Output file (assembly)")
  32. args = parser.parse_args()
  33. try:
  34. idata = open(args.ifile, "rb").read()
  35. except:
  36. sys.exit("Could not open input file '{}'".format(args.ifile))
  37. odata = idata
  38. try:
  39. with open(args.ofile, "w") as ofile:
  40. ofile.write("// ASM-ified version of: {}\n\n".format(args.ifile))
  41. ofile.write(".cpu cortex-m0plus\n")
  42. ofile.write(".thumb\n\n")
  43. ofile.write(".section .boot3, \"ax\"\n\n")
  44. for offs in range(0, len(odata), 16):
  45. chunk = odata[offs:min(offs + 16, len(odata))]
  46. ofile.write(".byte {}\n".format(", ".join("0x{:02x}".format(b) for b in chunk)))
  47. except:
  48. sys.exit("Could not open output file '{}'".format(args.ofile))