-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bootload.py
48 lines (36 loc) · 1.51 KB
/
Bootload.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'''
@file Bootload.py
@author Pere Tuset-Peiro ([email protected])
@version v0.1
@date May, 2015
@brief
@copyright Copyright 2015, OpenMote Technologies, S.L.
This file is licensed under the GNU General Public License v2.
'''
import logging
import os
import subprocess
# Import logging configuration
logger = logging.getLogger(__name__)
class Bootload(object):
def __init__(self, serial_name = None, serial_speed = 115200, image = None):
self.python = "python"
self.bsl_path = os.path.join("..", "..", "tools", "cc2538-bsl")
self.bsl_file = "cc2538-bsl.py"
self.serial_name = serial_name
self.serial_speed = serial_speed
self.image = image
self.bsl_params = "-e -w --bootloader-invert-lines -p {} -b {} {}".format(self.serial_name, self.serial_speed, self.image)
self.script_cmd = os.path.join(self.bsl_path, self.bsl_file)
self.script_args = self.bsl_params
def start(self):
# Build bootload command
cmd = self.python + " " + self.script_cmd + " " + self.script_args
logger.info("start: Executing the bootload command '{}'.".format(cmd))
try:
# Execute bootload command
subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, check=True)
logger.info("start: Executed the bootload command successfully.")
return True
except:
logger.error("start: Error executing the bootload process.")