You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

module_copy_mps2.py 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. """
  2. mbed SDK
  3. Copyright (c) 2011-2013 ARM Limited
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. """
  14. import re
  15. from os.path import join
  16. from host_test_plugins import HostTestPluginBase
  17. class HostTestPluginCopyMethod_MPS2(HostTestPluginBase):
  18. # MPS2 specific flashing / binary setup funcitons
  19. def mps2_set_board_image_file(self, disk, images_cfg_path, image0file_path, image_name='images.txt'):
  20. """ This function will alter image cfg file.
  21. Main goal of this function is to change number of images to 1, comment all
  22. existing image entries and append at the end of file new entry with test path.
  23. @return True when all steps succeed.
  24. """
  25. MBED_SDK_TEST_STAMP = 'test suite entry'
  26. image_path = join(disk, images_cfg_path, image_name)
  27. new_file_lines = [] # New configuration file lines (entries)
  28. # Check each line of the image configuration file
  29. try:
  30. with open(image_path, 'r') as file:
  31. for line in file:
  32. if re.search('^TOTALIMAGES', line):
  33. # Check number of total images, should be 1
  34. new_file_lines.append(re.sub('^TOTALIMAGES:[\t ]*[\d]+', 'TOTALIMAGES: 1', line))
  35. elif re.search('; - %s[\n\r]*$'% MBED_SDK_TEST_STAMP, line):
  36. # Look for test suite entries and remove them
  37. pass # Omit all test suite entries
  38. elif re.search('^IMAGE[\d]+FILE', line):
  39. # Check all image entries and mark the ';'
  40. new_file_lines.append(';' + line) # Comment non test suite lines
  41. else:
  42. # Append line to new file
  43. new_file_lines.append(line)
  44. except IOError as e:
  45. return False
  46. # Add new image entry with proper commented stamp
  47. new_file_lines.append('IMAGE0FILE: %s ; - %s\r\n'% (image0file_path, MBED_SDK_TEST_STAMP))
  48. # Write all lines to file
  49. try:
  50. with open(image_path, 'w') as file:
  51. for line in new_file_lines:
  52. file.write(line),
  53. except IOError:
  54. return False
  55. return True
  56. def mps2_select_core(self, disk, mobo_config_name=""):
  57. """ Function selects actual core
  58. """
  59. # TODO: implement core selection
  60. pass
  61. def mps2_switch_usb_auto_mounting_after_restart(self, disk, usb_config_name=""):
  62. """ Function alters configuration to allow USB MSD to be mounted after restarts
  63. """
  64. # TODO: implement USB MSD restart detection
  65. pass
  66. # Plugin interface
  67. name = 'HostTestPluginCopyMethod_MPS2'
  68. type = 'CopyMethod'
  69. capabilities = ['mps2']
  70. required_parameters = ['image_path', 'destination_disk']
  71. def setup(self, *args, **kwargs):
  72. """ Configure plugin, this function should be called before plugin execute() method is used.
  73. """
  74. return True
  75. def execute(self, capabilitity, *args, **kwargs):
  76. """ Executes capability by name.
  77. Each capability may directly just call some command line
  78. program or execute building pythonic function
  79. """
  80. result = False
  81. if self.check_parameters(capabilitity, *args, **kwargs) is True:
  82. if capabilitity == 'mps2':
  83. # TODO: Implement MPS2 firmware setup here
  84. pass
  85. return result
  86. def load_plugin():
  87. """ Returns plugin available in this module
  88. """
  89. return HostTestPluginCopyMethod_MPS2()