flash.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # Copyright 2024 Google LLC
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from .. import PebbleCommander, exceptions, parsers
  15. # TODO: flash-write
  16. # Can't do it with pulse prompt :(
  17. @PebbleCommander.command()
  18. def flash_erase(cmdr, address, length):
  19. """ Erase flash area.
  20. """
  21. address = int(str(address), 0)
  22. length = int(str(length), 0)
  23. if address < 0:
  24. raise exceptions.ParameterError('address out of range: %d' % address)
  25. if length <= 0:
  26. raise exceptions.ParameterError('length out of range: %d' % length)
  27. # TODO: I guess catch errors
  28. ret = cmdr.send_prompt_command("erase flash 0x%X %d" % (address, length))
  29. if not ret[1].startswith("OK"):
  30. raise exceptions.PromptResponseError(ret)
  31. @PebbleCommander.command()
  32. def flash_crc(cmdr, address, length):
  33. """ Calculate CRC of flash area.
  34. """
  35. address = int(str(address), 0)
  36. length = int(str(length), 0)
  37. if address < 0:
  38. raise exceptions.ParameterError('address out of range: %d' % address)
  39. if length <= 0:
  40. raise exceptions.ParameterError('length out of range: %d' % length)
  41. # TODO: I guess catch errors
  42. ret = cmdr.send_prompt_command("crc flash 0x%X %d" % (address, length))
  43. if not ret[0].startswith("CRC: "):
  44. raise exceptions.PromptResponseError(ret)
  45. return [ret[0][5:]]
  46. @PebbleCommander.command()
  47. def prf_address(cmdr):
  48. """ Get address of PRF.
  49. """
  50. ret = cmdr.send_prompt_command("prf image address")
  51. if not ret[0].startswith("OK "):
  52. raise exceptions.PromptResponseError(ret)
  53. return [ret[0][3:]]