programmer-core 1.0.29__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,667 @@
1
+ from os import makedirs
2
+ from os.path import join, isdir, isfile
3
+ import logging
4
+ import json
5
+ import pathlib
6
+
7
+ from flash_images_builder_core import (
8
+ PsramOption,
9
+ PSImageBuilder,
10
+ FIBUtility,
11
+ ACTIVATION_TYPE,
12
+ KEY_INFO_MAGIC_DEFAULT,
13
+ KEY_INFO_VERSION_DEFAULT,
14
+ KEY_INFO_SVN_DEFAULT,
15
+ KEY_INFO_SVN_POLICY_DEFAULT,
16
+ BOOT_SECTOR_SIZE_DEFAULT_KB,
17
+ )
18
+
19
+ try:
20
+ from utility import (
21
+ ProgrammerUtility,
22
+ AUTHENTICATION_BYPASS_FILES_FOLDER_NAME,
23
+ TOOL_SETTINGS,
24
+ ACTION_PARAMS,
25
+ )
26
+ from program_device import ProgramDevice
27
+ except ImportError:
28
+ from .utility import (
29
+ ProgrammerUtility,
30
+ AUTHENTICATION_BYPASS_FILES_FOLDER_NAME,
31
+ TOOL_SETTINGS,
32
+ ACTION_PARAMS,
33
+ )
34
+ from .program_device import ProgramDevice
35
+
36
+
37
+ FACTORY_PROGRAM_LOGGER = logging.getLogger("factory-program")
38
+
39
+
40
+ class FactoryProgramDevice:
41
+
42
+ def __init__(
43
+ self,
44
+ interface_type,
45
+ serial_number,
46
+ flash_type,
47
+ activation_type,
48
+ device_type,
49
+ verbose,
50
+ programmer_artifacts_path,
51
+ fib_artifacts_path,
52
+ signing_module=None,
53
+ full_flash_erase=False,
54
+ rollback_protection=True,
55
+ psram_type=PsramOption.NO_PSRAM.name,
56
+ enable_ota=False,
57
+ nvs_size=None,
58
+ key_storage_size=None,
59
+ vendor_specific_size=None,
60
+ bl2_size=None,
61
+ wsoc_size=None,
62
+ vendor_bl3_size=None,
63
+ tclk_delay=4,
64
+ chunk_size=1085,
65
+ signing_mode="classic_rot",
66
+ magic=KEY_INFO_MAGIC_DEFAULT,
67
+ key_info_version=KEY_INFO_VERSION_DEFAULT,
68
+ svn=KEY_INFO_SVN_DEFAULT,
69
+ svn_policy=KEY_INFO_SVN_POLICY_DEFAULT,
70
+ jlink_speed_khz=None,
71
+ ):
72
+ self.interface_type = interface_type
73
+ self.serial_number = serial_number
74
+
75
+ self.flash_type = flash_type
76
+ self.activation_type = activation_type
77
+ self.signing_module = signing_module
78
+ self.signing_mode = signing_mode
79
+ self.magic = magic
80
+ self.key_info_version = key_info_version
81
+ self.svn = svn
82
+ self.svn_policy = svn_policy
83
+ self.device_type = device_type
84
+ self.verbose = verbose
85
+ self.enable_ota = enable_ota
86
+ self.psram_type = psram_type
87
+ self.full_flash_erase = full_flash_erase
88
+ self.rollback_protection = rollback_protection
89
+
90
+ self.nvs_size = nvs_size
91
+ self.key_storage_size = key_storage_size
92
+ self.vendor_specific_size = vendor_specific_size
93
+ self.vendor_bl3_size = vendor_bl3_size
94
+ self.bl2_size = bl2_size
95
+ self.wsoc_size = wsoc_size
96
+
97
+ self.tclk_delay = tclk_delay
98
+ self.chunk_size = chunk_size
99
+ self.jlink_speed_khz = jlink_speed_khz
100
+
101
+ self.prog_dir = programmer_artifacts_path
102
+ self.fib_dir = fib_artifacts_path
103
+ self.prog_utility = ProgrammerUtility(self.prog_dir, self.fib_dir)
104
+ self.fib_utility = FIBUtility(self.fib_dir)
105
+ self.jsons_folder = self.prog_utility.get_config_folder()
106
+ self.logging_level = logging.INFO if verbose else logging.DEBUG
107
+
108
+ self.tmp_folder = self.prog_utility.get_programming_tmp_folder()
109
+
110
+ self.fuse_json_name = self.prog_utility.get_fuse_json_name(self.device_type)
111
+
112
+ self.fuse_conf_json = join(
113
+ self.jsons_folder,
114
+ AUTHENTICATION_BYPASS_FILES_FOLDER_NAME,
115
+ self.fuse_json_name,
116
+ )
117
+
118
+ # Get limits for default values
119
+ limits = self.fib_utility.get_limits_by_flash_device_name(
120
+ self.flash_type, self.enable_ota
121
+ )
122
+
123
+ if self.nvs_size is None:
124
+ self.nvs_size = limits["protected_storage"]["nvsSize"]["default"]
125
+ if self.key_storage_size is None:
126
+ self.key_storage_size = limits["protected_storage"]["keyStorageSize"][
127
+ "default"
128
+ ]
129
+ if self.vendor_specific_size is None:
130
+ self.vendor_specific_size = limits["protected_storage"]["vendorSize"]["default"]
131
+ if self.bl2_size is None:
132
+ self.bl2_size = limits["ti_components"]["bl2_size"]["default"]
133
+ if self.wsoc_size is None:
134
+ self.wsoc_size = limits["ti_components"]["wsoc_size"]["default"]
135
+ if self.vendor_bl3_size is None:
136
+ self.vendor_bl3_size = limits["vendor_components"]["vendorBl3Size"][
137
+ "default"
138
+ ]
139
+
140
+ ext_flash_dir_path = self.fib_utility.get_ext_flash_dir_path()
141
+ # move flash jsons files to tmp folder
142
+ self.xspi_json, self.otfde_json, self.ext_mem_json = (
143
+ self.prog_utility.move_flash_json_files(
144
+ flash_type_files_folder=ext_flash_dir_path,
145
+ flash_device=self.flash_type,
146
+ enable_ota=self.enable_ota,
147
+ )
148
+ )
149
+
150
+ if (
151
+ not isfile(self.xspi_json)
152
+ or not isfile(self.otfde_json)
153
+ or not isfile(self.ext_mem_json)
154
+ ):
155
+ raise Exception(
156
+ f"Some JSONs are missing for Flash Device {self.flash_type}"
157
+ )
158
+
159
+ # modify jsons by user parameters
160
+ self.ext_mem_json, self.otfde_json, self.xspi_json = (
161
+ self.fib_utility.update_flash_configuration_files(
162
+ ext_mem_json_path=self.ext_mem_json,
163
+ otfde_json_path=self.otfde_json,
164
+ xspi_json_path=self.xspi_json,
165
+ nvs_size_kb=self.nvs_size,
166
+ ks_size_kb=self.key_storage_size,
167
+ vs_size_kb=self.vendor_specific_size,
168
+ bl2_size_kb=self.bl2_size,
169
+ wsoc_size_kb=self.wsoc_size,
170
+ device_type=self.device_type,
171
+ vendor_bl3_size_kb=self.vendor_bl3_size,
172
+ psram_type=self.psram_type,
173
+ ota_enabled=self.enable_ota,
174
+ )
175
+ )
176
+
177
+ if (
178
+ not isfile(self.xspi_json)
179
+ or not isfile(self.otfde_json)
180
+ or not isfile(self.ext_mem_json)
181
+ ):
182
+ raise Exception(f"Some Modify JSONs are missing")
183
+
184
+ self.default_vendor_out_file = self.prog_utility.get_default_vendor_app(
185
+ device_type=self.device_type, enable_ota=self.enable_ota
186
+ )
187
+
188
+ self.default_conf_bin_file = self.prog_utility.get_default_conf_bin(device_type)
189
+
190
+ tbl_dir_path = self.prog_utility.get_tbl_dir_path()
191
+ self.tbl_bootloader_path = self.prog_utility.get_default_tbl_img(
192
+ self.device_type
193
+ )
194
+
195
+ self.wsoc_path = self.prog_utility.get_default_wsoc(self.device_type)
196
+
197
+ self.programming_sign_image_path = ""
198
+ self.vendor_sign_image_path = ""
199
+ self.vendor_bl3_sign_image_path = ""
200
+ self.prog_action_req_sign_path = ""
201
+ self.tbl_image_path = ""
202
+ self.wsoc_image_path = ""
203
+ self.tbl_programmer_path = self.prog_utility.get_default_prog(self.device_type)
204
+ self.boot_sector_image_path = ""
205
+ self.tool_settings_json_template = (
206
+ self.prog_utility.get_tool_settings_template()
207
+ )
208
+ self.is_rollback_fuse_prog_required = False
209
+
210
+ def _generate_programming_inst_image(self):
211
+
212
+ fuse_conf_json_mod = self.fuse_conf_json
213
+
214
+ if self.is_rollback_fuse_prog_required:
215
+ # Update fuses with rollback protection values based on image versions
216
+ fuses_name_json_mod = self.fuse_json_name.replace(".json", ".mod.json")
217
+ fuse_conf_json_mod = join(self.tmp_folder, fuses_name_json_mod)
218
+ with (
219
+ open(self.fuse_conf_json, "r") as fuses_file,
220
+ open(fuse_conf_json_mod, "w") as fuses_out,
221
+ ):
222
+ fuses_obj = json.load(fuses_file)
223
+ fuses_obj["rot"] = None
224
+
225
+ fuses_obj = self.fib_utility.update_rollback_fuses(
226
+ fuses_json_content=fuses_obj,
227
+ primary_tbl_image_path=self.tbl_image_path or None,
228
+ primary_wsoc_image_path=self.wsoc_image_path or None,
229
+ primary_vendor_image_path=self.vendor_sign_image_path or None,
230
+ device=self.device_type,
231
+ )
232
+ json.dump(fuses_obj, fuses_out, indent=4)
233
+
234
+ # build programming image
235
+ programming_unsign_image_path, programming_forsign_image_path = (
236
+ self.prog_utility.build_programming_image(
237
+ version="0.0.1.0",
238
+ pub_key_path=None,
239
+ activation_type=ACTIVATION_TYPE.AUTHENTICATION_BYPASS.value,
240
+ dir_out_path=self.tmp_folder,
241
+ fuses_programming_instructions=fuse_conf_json_mod,
242
+ flash_discovery_config_xspi=self.xspi_json,
243
+ flash_discovery_config_otfde=self.otfde_json,
244
+ flash_discovery_config_ext_mem=self.ext_mem_json,
245
+ device=self.device_type,
246
+ logging_level=self.logging_level,
247
+ )
248
+ )
249
+
250
+ # sign programming image
251
+ self.programming_sign_image_path = self.prog_utility.sign_programming_image(
252
+ programming_unsign_image=programming_unsign_image_path,
253
+ programming_forsign_image=programming_forsign_image_path,
254
+ activation_type=self.activation_type,
255
+ signing_module=self.signing_module,
256
+ dir_out_path=self.tmp_folder,
257
+ logging_level=self.logging_level,
258
+ )
259
+
260
+ # generate boot sector image
261
+ self.boot_sector_image_path = self.prog_utility.build_boot_sector(
262
+ programming_sign_image_path=self.programming_sign_image_path,
263
+ dir_out_path=self.tmp_folder,
264
+ device_type=self.device_type,
265
+ logging_level=self.logging_level,
266
+ )
267
+
268
+ FACTORY_PROGRAM_LOGGER.info(
269
+ "Successfully generated Programming Instruction Image and boot sector image"
270
+ )
271
+
272
+ def _generate_vendor_image(
273
+ self, vendor_out_file=None, conf_bin_file=None, vendor_app_version="0.0.1.0"
274
+ ):
275
+ # build vendor image
276
+ vendor_unsign_image_path, vendor_forsign_image_path = (
277
+ self.prog_utility.build_vendor_image(
278
+ vendor_out_file=(
279
+ self.default_vendor_out_file
280
+ if vendor_out_file is None
281
+ else vendor_out_file
282
+ ),
283
+ conf_bin_file=(
284
+ self.default_conf_bin_file
285
+ if conf_bin_file is None
286
+ else conf_bin_file
287
+ ),
288
+ version=vendor_app_version,
289
+ dir_out_path=self.tmp_folder,
290
+ device=self.device_type,
291
+ logging_level=self.logging_level,
292
+ signing_mode=self.signing_mode,
293
+ )
294
+ )
295
+
296
+ # sign vendor image
297
+ self.vendor_sign_image_path = self.prog_utility.sign_vendor_image(
298
+ vendor_unsign_image=vendor_unsign_image_path,
299
+ vendor_forsign_image=vendor_forsign_image_path,
300
+ activation_type=self.activation_type,
301
+ signing_module=self.signing_module,
302
+ dir_out_path=self.tmp_folder,
303
+ device=self.device_type,
304
+ logging_level=self.logging_level,
305
+ signing_mode=self.signing_mode,
306
+ magic=self.magic,
307
+ key_info_version=self.key_info_version,
308
+ svn=self.svn,
309
+ svn_policy=self.svn_policy,
310
+ )
311
+
312
+ FACTORY_PROGRAM_LOGGER.info("Successfully generated Vendor Image")
313
+
314
+ def _generate_vendor_bl3_image(
315
+ self, vendor_bl3_out_file, vendor_bl3_version="0.0.1.0"
316
+ ):
317
+ vendor_bl3_unsign_path, vendor_bl3_forsign_path = (
318
+ self.prog_utility.build_vendor_bl3_image(
319
+ bl3_bin_path=vendor_bl3_out_file,
320
+ dir_out_path=self.tmp_folder,
321
+ device=self.device_type,
322
+ version=vendor_bl3_version,
323
+ logging_level=self.logging_level,
324
+ signing_mode=self.signing_mode,
325
+ )
326
+ )
327
+
328
+ self.vendor_bl3_sign_image_path = self.prog_utility.sign_vendor_bl3_image(
329
+ vendor_bl3_unsign_image=vendor_bl3_unsign_path,
330
+ vendor_bl3_forsign_image=vendor_bl3_forsign_path,
331
+ activation_type=self.activation_type,
332
+ signing_module=self.signing_module,
333
+ dir_out_path=self.tmp_folder,
334
+ device=self.device_type,
335
+ logging_level=self.logging_level,
336
+ signing_mode=self.signing_mode,
337
+ magic=self.magic,
338
+ key_info_version=self.key_info_version,
339
+ svn=self.svn,
340
+ svn_policy=self.svn_policy,
341
+ )
342
+
343
+ FACTORY_PROGRAM_LOGGER.info("Successfully generated Vendor BL3 Image")
344
+
345
+ def _generate_prog_action_request(self):
346
+ template_action_params_path = self.prog_utility.get_action_params_template()
347
+ updated_action_params_path = join(self.tmp_folder, ACTION_PARAMS)
348
+
349
+ with open(template_action_params_path, "r") as f:
350
+ action_request_json_content = json.load(f)
351
+
352
+ prog_req_content = action_request_json_content["programming"]["payload_param"][
353
+ "payload"
354
+ ]["prog_req_content"]
355
+
356
+ # update action request json with programming flags
357
+ prog_req_content.update(
358
+ {
359
+ "fuse_programming_instruction_update": self.is_rollback_fuse_prog_required,
360
+ "flash_factory_reset": self.full_flash_erase,
361
+ "boot_sector": True,
362
+ "primary_tbl": True,
363
+ "secondary_tbl": False,
364
+ "primary_vendor_image": True,
365
+ "primary_vendor_sbl": self.vendor_bl3_size > 0,
366
+ "secondary_vendor_image": False,
367
+ "secondary_vendor_sbl": False,
368
+ "primary_ti_wsoc": False if self.wsoc_size == 0 else True,
369
+ "secondary_ti_wsoc": False,
370
+ "primary_ti_wsoc_bl2": False,
371
+ "secondary_ti_wsoc_bl2": False,
372
+ "protected_storage": True,
373
+ }
374
+ )
375
+
376
+ action_request_json_content["programming"]["payload_param"]["payload"][
377
+ "prog_req_content"
378
+ ] = prog_req_content
379
+
380
+ with open(updated_action_params_path, "w") as f:
381
+ json.dump(action_request_json_content, f, indent=4)
382
+
383
+ # build action request
384
+ prog_action_req_unsign_path, prog_action_req_forsign_path = (
385
+ self.prog_utility.build_action_request_image(
386
+ params_json=updated_action_params_path,
387
+ type="programming",
388
+ dir_out_path=self.tmp_folder,
389
+ device=self.device_type,
390
+ logging_level=self.logging_level,
391
+ )
392
+ )
393
+
394
+ # sign action request
395
+ self.prog_action_req_sign_path = self.prog_utility.sign_action_request_image(
396
+ unsign_request=prog_action_req_unsign_path,
397
+ forsign_request=prog_action_req_forsign_path,
398
+ activation_type=self.activation_type,
399
+ signing_module=self.signing_module,
400
+ dir_out_path=self.tmp_folder,
401
+ logging_level=self.logging_level,
402
+ )
403
+
404
+ FACTORY_PROGRAM_LOGGER.info("Successfully generated Action Request Image")
405
+
406
+ def _generate_tbl_flash_image(self):
407
+ self.tbl_image_path = self.prog_utility.build_tbl_image(
408
+ ti_sign_container=self.tbl_bootloader_path,
409
+ dir_out_path=self.tmp_folder,
410
+ device=self.device_type,
411
+ logging_level=self.logging_level,
412
+ )
413
+
414
+ FACTORY_PROGRAM_LOGGER.info("Successfully generated TI Bootloader image")
415
+
416
+ def _generate_wsoc_flash_image(self, wsoc_container_file=None):
417
+ wsoc_path = (
418
+ self.wsoc_path if wsoc_container_file is None else wsoc_container_file
419
+ )
420
+
421
+ self.wsoc_image_path = self.prog_utility.build_wsoc_image(
422
+ ti_sign_container=wsoc_path,
423
+ dir_out_path=self.tmp_folder,
424
+ device=self.device_type,
425
+ logging_level=self.logging_level,
426
+ )
427
+
428
+ FACTORY_PROGRAM_LOGGER.info(
429
+ f"Successfully generated TI Wireless Firmware image from {wsoc_path}"
430
+ )
431
+
432
+ def _generate_ps_image(self, vendor_specific_file=None):
433
+ vendor_specific_data = b""
434
+ if vendor_specific_file is not None:
435
+ with open(vendor_specific_file, "rb") as f:
436
+ vendor_specific_data = f.read()
437
+
438
+ self.vendor_specific_file = vendor_specific_file
439
+
440
+ psimg_builder = PSImageBuilder(
441
+ device=self.device_type,
442
+ vendor_specific_size_kb=self.vendor_specific_size,
443
+ nvs_data_max_size_kb=self.nvs_size,
444
+ key_storage_data_max_size_kb=self.key_storage_size,
445
+ vendor_specific_data=vendor_specific_data,
446
+ abs_dir_out_path=self.tmp_folder,
447
+ )
448
+
449
+ # Build and save
450
+ if not psimg_builder.build():
451
+ FACTORY_PROGRAM_LOGGER.error("Failed to build PS image")
452
+ raise Exception("Failed to build PS image")
453
+
454
+ if not psimg_builder.save("ps_image.bin"):
455
+ FACTORY_PROGRAM_LOGGER.error("Failed to save PS image")
456
+ raise Exception("Failed to save PS image")
457
+
458
+ # Success
459
+ self.psimage_path = join(self.tmp_folder, "ps_image.bin")
460
+ FACTORY_PROGRAM_LOGGER.info("Successfully generated Protect Storage Image")
461
+
462
+ def _generate_images(
463
+ self,
464
+ vendor_out_file=None,
465
+ conf_bin_file=None,
466
+ vendor_app_version="0.0.1.0",
467
+ wsoc_container_file=None,
468
+ vendor_specific_file=None,
469
+ vendor_bl3_out_file=None,
470
+ vendor_bl3_version="0.0.1.0",
471
+ ):
472
+ self._generate_tbl_flash_image()
473
+
474
+ if self.wsoc_size > 0:
475
+ self._generate_wsoc_flash_image(wsoc_container_file=wsoc_container_file)
476
+
477
+ self._generate_vendor_image(
478
+ vendor_out_file=vendor_out_file,
479
+ conf_bin_file=conf_bin_file,
480
+ vendor_app_version=vendor_app_version,
481
+ )
482
+
483
+ if self.vendor_bl3_size > 0:
484
+ self._generate_vendor_bl3_image(
485
+ vendor_bl3_out_file=vendor_bl3_out_file,
486
+ vendor_bl3_version=vendor_bl3_version,
487
+ )
488
+
489
+ # Check if rollback fuse programming is required (if rollback protection is enabled)
490
+ if not self.rollback_protection:
491
+ self.is_rollback_fuse_prog_required = False
492
+ else:
493
+ self.is_rollback_fuse_prog_required = (
494
+ self.fib_utility.is_rollback_fuse_programming_required(
495
+ primary_tbl_image_path=(
496
+ self.tbl_image_path if self.tbl_image_path != "" else None
497
+ ),
498
+ primary_wsoc_image_path=(
499
+ self.wsoc_image_path if self.wsoc_image_path != "" else None
500
+ ),
501
+ primary_vendor_image_path=(
502
+ self.vendor_sign_image_path
503
+ if self.vendor_sign_image_path != ""
504
+ else None
505
+ ),
506
+ device=self.device_type,
507
+ )
508
+ )
509
+
510
+ self._generate_programming_inst_image()
511
+
512
+ self._generate_ps_image(vendor_specific_file=vendor_specific_file)
513
+
514
+ self._generate_prog_action_request()
515
+
516
+ def _validate_generated_image_sizes(self):
517
+ is_valid, message, *_, max_vendor_app_size = (
518
+ self.fib_utility.validate_total_images_size(
519
+ flash_device=self.flash_type,
520
+ bl2_size_kb=self.bl2_size,
521
+ wsoc_size_kb=self.wsoc_size,
522
+ nvs_size_kb=self.nvs_size,
523
+ key_storage_size_kb=self.key_storage_size,
524
+ vendor_specific_size_kb=self.vendor_specific_size,
525
+ vendor_bl3_size_kb=self.vendor_bl3_size,
526
+ enable_ota=self.enable_ota,
527
+ )
528
+ )
529
+ if is_valid == False:
530
+ FACTORY_PROGRAM_LOGGER.error(message)
531
+ return False
532
+
533
+ protected_storage_size_kb = (
534
+ self.fib_utility.calc_protected_storage_size_bytes(
535
+ nvs_bytes=self.nvs_size * 1024,
536
+ key_storage_bytes=self.key_storage_size * 1024,
537
+ vendor_specific_bytes=self.vendor_specific_size * 1024,
538
+ )
539
+ / 1024
540
+ )
541
+
542
+ is_valid, _ = self.fib_utility.validate_images_sizes(
543
+ primary_tbl_path=self.tbl_image_path,
544
+ tbl_size_kb=self.bl2_size,
545
+ primary_wsoc_path=self.wsoc_image_path,
546
+ wsoc_size_kb=self.wsoc_size,
547
+ primary_vendor_path=self.vendor_sign_image_path,
548
+ vendor_size_kb=max_vendor_app_size,
549
+ primary_vendor_bl3_path=self.vendor_bl3_sign_image_path,
550
+ vendor_bl3_size_kb=self.vendor_bl3_size,
551
+ boot_sector_path=self.boot_sector_image_path,
552
+ boot_sector_size_kb=BOOT_SECTOR_SIZE_DEFAULT_KB,
553
+ vendor_specific_path=self.vendor_specific_file,
554
+ vendor_specific_size_kb=self.vendor_specific_size,
555
+ protected_storage_path=self.psimage_path,
556
+ protected_storage_size_kb=protected_storage_size_kb,
557
+ )
558
+ return is_valid
559
+
560
+ def _update_tool_settings_json(self):
561
+ tool_settings = json.load(open(self.tool_settings_json_template, "r"))
562
+
563
+ programming_debug_and_ota_signed_components = tool_settings[
564
+ "programming_debug_and_ota_signed_components"
565
+ ]
566
+
567
+ programming_debug_and_ota_signed_components["programming_instructions"] = str(
568
+ self.programming_sign_image_path
569
+ )
570
+
571
+ programming_debug_and_ota_signed_components["primary_vendor_image"] = str(
572
+ self.vendor_sign_image_path
573
+ )
574
+
575
+ programming_debug_and_ota_signed_components["actions_req_paths"][
576
+ "programming"
577
+ ] = str(self.prog_action_req_sign_path)
578
+
579
+ programming_debug_and_ota_signed_components["primary_tbl"] = str(
580
+ self.tbl_image_path
581
+ )
582
+
583
+ programming_debug_and_ota_signed_components["primary_ti_wsoc"] = (
584
+ None if self.wsoc_size == 0 else str(self.wsoc_image_path)
585
+ )
586
+
587
+ programming_debug_and_ota_signed_components["tbl_container_programming"] = str(
588
+ self.tbl_programmer_path
589
+ )
590
+
591
+ programming_debug_and_ota_signed_components["boot_sector"] = str(
592
+ self.boot_sector_image_path
593
+ )
594
+ programming_debug_and_ota_signed_components["protected_storage"] = str(
595
+ self.psimage_path
596
+ )
597
+
598
+ if self.vendor_bl3_sign_image_path:
599
+ programming_debug_and_ota_signed_components["primary_vendor_sbl"] = str(
600
+ self.vendor_bl3_sign_image_path
601
+ )
602
+
603
+ self.tool_settings_mod_json = join(
604
+ self.prog_utility.get_programming_tmp_folder(), TOOL_SETTINGS
605
+ )
606
+
607
+ json.dump(tool_settings, open(self.tool_settings_mod_json, "w"), indent=4)
608
+
609
+ FACTORY_PROGRAM_LOGGER.log(
610
+ self.logging_level,
611
+ f"Update tool settings json at: {self.tool_settings_mod_json}",
612
+ )
613
+
614
+ FACTORY_PROGRAM_LOGGER.info(
615
+ "Updated tool settings json with new images for factory programming"
616
+ )
617
+
618
+ def program(
619
+ self,
620
+ vendor_out_file=None,
621
+ conf_bin_file=None,
622
+ vendor_app_version="0.0.1.0",
623
+ wsoc_container_file=None,
624
+ vendor_specific_file=None,
625
+ vendor_bl3_out_file=None,
626
+ vendor_bl3_version="0.0.1.0",
627
+ ):
628
+ FACTORY_PROGRAM_LOGGER.info("Factory programming started")
629
+
630
+ self._generate_images(
631
+ vendor_out_file=vendor_out_file,
632
+ conf_bin_file=conf_bin_file,
633
+ vendor_app_version=vendor_app_version,
634
+ wsoc_container_file=wsoc_container_file,
635
+ vendor_specific_file=vendor_specific_file,
636
+ vendor_bl3_out_file=vendor_bl3_out_file,
637
+ vendor_bl3_version=vendor_bl3_version,
638
+ )
639
+
640
+ if not self._validate_generated_image_sizes():
641
+ FACTORY_PROGRAM_LOGGER.error(
642
+ "Error: Image size validation failed"
643
+ )
644
+ return False
645
+
646
+ self._update_tool_settings_json()
647
+
648
+ program_device = ProgramDevice(
649
+ interface_type=self.interface_type,
650
+ serial_number=self.serial_number,
651
+ tool_settings=self.tool_settings_mod_json,
652
+ device_type=self.device_type,
653
+ report_file_path=(pathlib.Path(self.tmp_folder) / "programming_report.txt"),
654
+ programmer_artifacts_path=self.prog_dir,
655
+ fib_artifacts_path=self.fib_dir,
656
+ tclk_delay=self.tclk_delay,
657
+ chunk_size=self.chunk_size,
658
+ verbose=self.verbose,
659
+ jlink_speed_khz=self.jlink_speed_khz,
660
+ )
661
+
662
+ if not program_device.program():
663
+ FACTORY_PROGRAM_LOGGER.error("Error: Factory programming failed")
664
+ return False
665
+ else:
666
+ FACTORY_PROGRAM_LOGGER.info("Factory programming ended successfully")
667
+ return True