|
4 | 4 |
|
5 | 5 | quiet = False
|
6 | 6 |
|
| 7 | + |
7 | 8 | def status(msg):
|
8 | 9 | """Print status message to stderr"""
|
9 | 10 | if not quiet:
|
10 | 11 | critical(msg)
|
11 | 12 |
|
| 13 | + |
12 | 14 | def critical(msg):
|
13 | 15 | """Print critical message to stderr"""
|
14 | 16 | sys.stderr.write("safeboot.py: ")
|
15 | 17 | sys.stderr.write(msg)
|
16 | 18 | sys.stderr.write("\n")
|
17 | 19 |
|
| 20 | + |
18 | 21 | # open "/safeboot" on target to restart in SafeBoot-mode
|
19 | 22 | def safeboot(source, target, env):
|
20 | 23 | upload_protocol = env.GetProjectOption("upload_protocol")
|
21 | 24 | upload_port = env.GetProjectOption("upload_port")
|
22 |
| - if upload_protocol != "espota": |
| 25 | + if upload_protocol != "espota": |
23 | 26 | critical("Wrong upload protocol (%s)" % upload_protocol)
|
24 | 27 | raise Exception("Wrong upload protocol!")
|
25 | 28 | else:
|
26 |
| - status("Trying to activate SafeBoot on: %s" % upload_port) |
27 |
| - req = urllib.request.Request('http://'+upload_port+'/safeboot', method='POST') |
28 |
| - try: |
| 29 | + status("Trying to activate SafeBoot on: %s" % upload_port) |
| 30 | + safeboot_path = env.GetProjectOption("custom_safeboot_restart_path", "/safeboot") |
| 31 | + req = urllib.request.Request("http://" + upload_port + safeboot_path, method="POST") |
| 32 | + try: |
29 | 33 | urllib.request.urlopen(req)
|
30 | 34 | except urllib.error.URLError as e:
|
31 | 35 | critical(e)
|
32 | 36 | # Raise exception when SafeBoot cannot be activated
|
33 | 37 | pass
|
34 |
| - |
| 38 | + |
35 | 39 | status("Activated SafeBoot on: %s" % upload_port)
|
36 | 40 |
|
| 41 | + |
37 | 42 | env.AddPreAction("upload", safeboot)
|
38 | 43 | env.AddPreAction("uploadfs", safeboot)
|
39 | 44 | env.AddPreAction("uploadfsota", safeboot)
|
0 commit comments