|
2 | 2 | from builtins import str
|
3 | 3 |
|
4 | 4 | import os
|
5 |
| -from os.path import normpath, exists, dirname |
| 5 | +from os.path import normpath, exists, dirname, join, abspath |
6 | 6 | import ntpath
|
7 | 7 | import copy
|
8 | 8 | from collections import namedtuple
|
9 | 9 | import shutil
|
10 | 10 | from subprocess import Popen, PIPE
|
11 | 11 | import re
|
| 12 | +import json |
12 | 13 |
|
13 | 14 | from tools.resources import FileType
|
14 | 15 | from tools.targets import TARGET_MAP, CORE_ARCH
|
@@ -243,7 +244,30 @@ def generate(self):
|
243 | 244 | 'include_paths': ';'.join(self.filter_dot(d) for d in
|
244 | 245 | self.resources.inc_dirs),
|
245 | 246 | 'device': DeviceUvision(self.target),
|
| 247 | + 'postbuild_step_active': 0, |
246 | 248 | }
|
| 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 | + |
247 | 271 | sct_file_ref = self.resources.get_file_refs(FileType.LD_SCRIPT)[0]
|
248 | 272 | sct_file_ref = self.toolchain.correct_scatter_shebang(
|
249 | 273 | sct_file_ref, dirname(sct_file_ref.name)
|
@@ -271,10 +295,29 @@ def generate(self):
|
271 | 295 | 'uvision/uvision_debug.tmpl', ctx, self.project_name + ".uvoptx"
|
272 | 296 | )
|
273 | 297 |
|
| 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 | + |
274 | 309 | @staticmethod
|
275 | 310 | def clean(project_name):
|
276 | 311 | os.remove(project_name + ".uvprojx")
|
277 | 312 | 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 | + |
278 | 321 | # legacy .build directory cleaned if exists
|
279 | 322 | if exists('.build'):
|
280 | 323 | shutil.rmtree('.build')
|
|
0 commit comments