2 # Copyright (c) 2020 Project CHIP Authors
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
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 """Flash an QPG6100 device.
17 Currently only support CMSIS mBed Drag and Drop for public use.
19 usage: qpg6100_firmware_utils.py [-h] [--application FILE] [--drive DRIVE]
22 -h, --help show this help message and exit
25 --verbose Report more verbosely
26 --drive Connected mBed USB mount to copy to
29 --application FILE Flash an image through drag and drop
38 # Additional options that can be use to configure an `Flasher`
39 # object (as dictionary keys) and/or passed as command line options.
41 # Configuration options define properties used in flashing operations.
43 # Tool configuration options.
45 'help': 'Location of the mBed mount',
56 class Flasher(firmware_utils.Flasher):
57 """Manage flashing."""
59 def __init__(self, **options):
60 super().__init__(platform='QPG6100', module=__name__, **options)
61 self.define_options(QPG6100_OPTIONS)
65 self.log(0, "Erase not supported")
68 def verify(self, image):
70 self.log(0, "Verify not supported")
73 def flash(self, image):
75 self.log(1, "Copying to {} drive {}".format(image, self.option.drive or "None"))
76 if not self.option.drive:
77 self.log(0, "--drive or -d required for copy action")
81 # Check for drive mount
82 if not os.path.exists(self.option.drive):
83 self.log(0, "Drive '{}' does not exist. Is the USB device mounted correctly ?".format(self.option.drive))
87 # Check for valid mBed device
88 mbed_marker = os.path.join(self.option.drive, 'MBED.HTM')
89 if not os.path.exists(mbed_marker):
90 self.log(0, "Drive '{}' not a path to an MBED device".format(self.option.drive))
94 shutil.copyfile(image, os.path.join(self.option.drive, os.path.basename(image)))
99 self.log(0, "Reset is triggered automatically after completion of mBed copy.")
103 """Perform actions on the device according to self.option."""
104 self.log(3, 'Options:', self.option)
106 if self.option.erase:
110 application = self.optional_file(self.option.application)
112 if self.flash(application).err:
114 if self.option.verify_application:
115 if self.verify(application).err:
117 if self.option.reset is None:
118 self.option.reset = True
120 if self.option.reset:
127 if __name__ == '__main__':
128 sys.exit(Flasher().flash_command(sys.argv))