Skip to content

Commit 1319948

Browse files
committed
Conditionally enable post build in uvision for managed bootloader
1 parent a0cce48 commit 1319948

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

tools/export/uvision/__init__.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
from builtins import str
33

44
import os
5-
from os.path import normpath, exists, dirname
5+
from os.path import normpath, exists, dirname, join, abspath
66
import ntpath
77
import copy
88
from collections import namedtuple
99
import shutil
1010
from subprocess import Popen, PIPE
1111
import re
12+
import json
1213

1314
from tools.resources import FileType
1415
from tools.targets import TARGET_MAP, CORE_ARCH
@@ -243,7 +244,30 @@ def generate(self):
243244
'include_paths': ';'.join(self.filter_dot(d) for d in
244245
self.resources.inc_dirs),
245246
'device': DeviceUvision(self.target),
247+
'postbuild_step_active': 0,
246248
}
249+
250+
if self.toolchain.config.has_regions:
251+
# Serialize region information
252+
export_info = {}
253+
restrict_size = getattr(self.toolchain.config.target, "restrict_size")
254+
if restrict_size:
255+
export_info["target"] = {
256+
"restrict_size": restrict_size
257+
}
258+
259+
binary_path = "BUILD/{}.hex".format(self.project_name)
260+
region_list = list(self.toolchain.config.regions)
261+
export_info["region_list"] = [
262+
r._replace(filename=binary_path) if r.active else r for r in region_list
263+
]
264+
# Enable the post build step
265+
ctx['postbuild_step'] = (
266+
'python mbed-os/tools/export/uvision/postbuild.py "$K\\" "#L"'
267+
)
268+
ctx['postbuild_step_active'] = 1
269+
ctx['export_info'] = json.dumps(export_info, indent=4)
270+
247271
sct_file_ref = self.resources.get_file_refs(FileType.LD_SCRIPT)[0]
248272
sct_file_ref = self.toolchain.correct_scatter_shebang(
249273
sct_file_ref, dirname(sct_file_ref.name)
@@ -271,10 +295,29 @@ def generate(self):
271295
'uvision/uvision_debug.tmpl', ctx, self.project_name + ".uvoptx"
272296
)
273297

298+
if ctx['postbuild_step_active']:
299+
self.gen_file(
300+
'uvision/debug_init.ini', ctx, 'debug_init.ini'
301+
)
302+
self.gen_file(
303+
'uvision/flash_init.ini', ctx, 'flash_init.ini'
304+
)
305+
self.gen_file(
306+
'uvision/export_info.tmpl', ctx, 'export_info.json'
307+
)
308+
274309
@staticmethod
275310
def clean(project_name):
276311
os.remove(project_name + ".uvprojx")
277312
os.remove(project_name + ".uvoptx")
313+
314+
if exists("export_info.json"):
315+
os.remove("export_info.json")
316+
if exists("debug_init.ini"):
317+
os.remove("debug_init.ini")
318+
if exists("flash_init.ini"):
319+
os.remove("flash_init.ini")
320+
278321
# legacy .build directory cleaned if exists
279322
if exists('.build'):
280323
shutil.rmtree('.build')

0 commit comments

Comments
 (0)