1212import subprocess
1313import sys
1414
15- from west import log
1615from west import manifest
16+ from west .commands import Verbosity
1717from west .util import quote_sh_list
1818
1919from build_helpers import find_build_dir , is_zephyr_build , \
@@ -189,16 +189,16 @@ def do_run(self, args, ignored):
189189 # Delegate to the signer.
190190 if args .tool == 'imgtool' :
191191 if args .if_tool_available :
192- log .die ('imgtool does not support --if-tool-available' )
192+ self .die ('imgtool does not support --if-tool-available' )
193193 signer = ImgtoolSigner ()
194194 elif args .tool == 'rimage' :
195195 signer = RimageSigner ()
196196 # (Add support for other signers here in elif blocks)
197197 else :
198198 if args .tool is None :
199- log .die ('one --tool is required' )
199+ self .die ('one --tool is required' )
200200 else :
201- log .die (f'invalid tool: { args .tool } ' )
201+ self .die (f'invalid tool: { args .tool } ' )
202202
203203 signer .sign (self , build_dir , build_conf , formats )
204204
@@ -229,43 +229,43 @@ def sign(self, command, build_dir, build_conf, formats):
229229 args = command .args
230230 b = pathlib .Path (build_dir )
231231
232- log .wrn ("west sign using imgtool is deprecated and will be removed in a future release" )
232+ command .wrn ("west sign using imgtool is deprecated and will be removed in a future release" )
233233
234234 imgtool = self .find_imgtool (command , args )
235235 # The vector table offset and application version are set in Kconfig:
236236 appver = self .get_cfg (command , build_conf , 'CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION' )
237237 vtoff = self .get_cfg (command , build_conf , 'CONFIG_ROM_START_OFFSET' )
238238 # Flash device write alignment and the partition's slot size
239239 # come from devicetree:
240- flash = self .edt_flash_node (b , args .quiet )
241- align , addr , size = self .edt_flash_params (flash )
240+ flash = self .edt_flash_node (command , b , args .quiet )
241+ align , addr , size = self .edt_flash_params (command , flash )
242242
243243 if not build_conf .getboolean ('CONFIG_BOOTLOADER_MCUBOOT' ):
244- log .wrn ("CONFIG_BOOTLOADER_MCUBOOT is not set to y in "
245- f"{ build_conf .path } ; this probably won't work" )
244+ command .wrn ("CONFIG_BOOTLOADER_MCUBOOT is not set to y in "
245+ f"{ build_conf .path } ; this probably won't work" )
246246
247247 kernel = build_conf .get ('CONFIG_KERNEL_BIN_NAME' , 'zephyr' )
248248
249249 if 'bin' in formats :
250250 in_bin = b / 'zephyr' / f'{ kernel } .bin'
251251 if not in_bin .is_file ():
252- log .die (f"no unsigned .bin found at { in_bin } " )
252+ command .die (f"no unsigned .bin found at { in_bin } " )
253253 in_bin = os .fspath (in_bin )
254254 else :
255255 in_bin = None
256256 if 'hex' in formats :
257257 in_hex = b / 'zephyr' / f'{ kernel } .hex'
258258 if not in_hex .is_file ():
259- log .die (f"no unsigned .hex found at { in_hex } " )
259+ command .die (f"no unsigned .hex found at { in_hex } " )
260260 in_hex = os .fspath (in_hex )
261261 else :
262262 in_hex = None
263263
264264 if not args .quiet :
265- log .banner ('image configuration:' )
266- log .inf ('partition offset: {0} (0x{0:x})' .format (addr ))
267- log .inf ('partition size: {0} (0x{0:x})' .format (size ))
268- log .inf ('rom start offset: {0} (0x{0:x})' .format (vtoff ))
265+ command .banner ('image configuration:' )
266+ command .inf ('partition offset: {0} (0x{0:x})' .format (addr ))
267+ command .inf ('partition size: {0} (0x{0:x})' .format (size ))
268+ command .inf ('rom start offset: {0} (0x{0:x})' .format (vtoff ))
269269
270270 # Base sign command.
271271 sign_base = imgtool + ['sign' ,
@@ -276,34 +276,34 @@ def sign(self, command, build_dir, build_conf, formats):
276276 sign_base .extend (args .tool_args )
277277
278278 if not args .quiet :
279- log .banner ('signing binaries' )
279+ command .banner ('signing binaries' )
280280 if in_bin :
281281 out_bin = args .sbin or str (b / 'zephyr' / 'zephyr.signed.bin' )
282282 sign_bin = sign_base + [in_bin , out_bin ]
283283 if not args .quiet :
284- log .inf (f'unsigned bin: { in_bin } ' )
285- log .inf (f'signed bin: { out_bin } ' )
286- log .dbg (quote_sh_list (sign_bin ))
284+ command .inf (f'unsigned bin: { in_bin } ' )
285+ command .inf (f'signed bin: { out_bin } ' )
286+ command .dbg (quote_sh_list (sign_bin ))
287287 subprocess .check_call (sign_bin , stdout = subprocess .PIPE if args .quiet else None )
288288 if in_hex :
289289 out_hex = args .shex or str (b / 'zephyr' / 'zephyr.signed.hex' )
290290 sign_hex = sign_base + [in_hex , out_hex ]
291291 if not args .quiet :
292- log .inf (f'unsigned hex: { in_hex } ' )
293- log .inf (f'signed hex: { out_hex } ' )
294- log .dbg (quote_sh_list (sign_hex ))
292+ command .inf (f'unsigned hex: { in_hex } ' )
293+ command .inf (f'signed hex: { out_hex } ' )
294+ command .dbg (quote_sh_list (sign_hex ))
295295 subprocess .check_call (sign_hex , stdout = subprocess .PIPE if args .quiet else None )
296296
297297 @staticmethod
298- def find_imgtool (command , args ):
298+ def find_imgtool (cmd , args ):
299299 if args .tool_path :
300300 imgtool = args .tool_path
301301 if not os .path .isfile (imgtool ):
302- log .die (f'--tool-path { imgtool } : no such file' )
302+ cmd .die (f'--tool-path { imgtool } : no such file' )
303303 else :
304304 imgtool = shutil .which ('imgtool' ) or shutil .which ('imgtool.py' )
305305 if not imgtool :
306- log .die ('imgtool not found; either install it' ,
306+ cmd .die ('imgtool not found; either install it' ,
307307 '(e.g. "pip3 install imgtool") or provide --tool-path' )
308308
309309 if platform .system () == 'Windows' and imgtool .endswith ('.py' ):
@@ -327,18 +327,18 @@ def get_cfg(command, build_conf, item):
327327 return None
328328
329329 @staticmethod
330- def edt_flash_node (b , quiet = False ):
330+ def edt_flash_node (cmd , b , quiet = False ):
331331 # Get the EDT Node corresponding to the zephyr,flash chosen DT
332332 # node; 'b' is the build directory as a pathlib object.
333333
334334 # Ensure the build directory has a compiled DTS file
335335 # where we expect it to be.
336336 dts = b / 'zephyr' / 'zephyr.dts'
337337 if not quiet :
338- log .dbg ('DTS file:' , dts , level = log . VERBOSE_VERY )
338+ cmd .dbg ('DTS file:' , dts , level = Verbosity . DBG_MORE )
339339 edt_pickle = b / 'zephyr' / 'edt.pickle'
340340 if not edt_pickle .is_file ():
341- log .die ("can't load devicetree; expected to find:" , edt_pickle )
341+ cmd .die ("can't load devicetree; expected to find:" , edt_pickle )
342342
343343 # Load the devicetree.
344344 with open (edt_pickle , 'rb' ) as f :
@@ -348,13 +348,13 @@ def edt_flash_node(b, quiet=False):
348348 # partition information about the zephyr image to sign.
349349 flash = edt .chosen_node ('zephyr,flash' )
350350 if not flash :
351- log .die ('devicetree has no chosen zephyr,flash node;' ,
351+ cmd .die ('devicetree has no chosen zephyr,flash node;' ,
352352 "can't infer flash write block or slot0_partition slot sizes" )
353353
354354 return flash
355355
356356 @staticmethod
357- def edt_flash_params (flash ):
357+ def edt_flash_params (cmd , flash ):
358358 # Get the flash device's write alignment and offset from the
359359 # slot0_partition and the size from slot1_partition , out of the
360360 # build directory's devicetree. slot1_partition size is used,
@@ -366,7 +366,7 @@ def edt_flash_params(flash):
366366 # with label slot1_partition. By convention, the slots for consumption by
367367 # imgtool are linked into these partitions.
368368 if 'partitions' not in flash .children :
369- log .die ("DT zephyr,flash chosen node has no partitions," ,
369+ cmd .die ("DT zephyr,flash chosen node has no partitions," ,
370370 "can't find partitions for MCUboot slots" )
371371
372372 partitions = flash .children ['partitions' ]
@@ -377,31 +377,31 @@ def edt_flash_params(flash):
377377 }
378378
379379 if 'slot0_partition' not in slots :
380- log .die ("DT zephyr,flash chosen node has no slot0_partition partition," ,
380+ cmd .die ("DT zephyr,flash chosen node has no slot0_partition partition," ,
381381 "can't determine its address" )
382382
383383 # Die on missing or zero alignment or slot_size.
384384 if "write-block-size" not in flash .props :
385- log .die ('DT zephyr,flash node has no write-block-size;' ,
385+ cmd .die ('DT zephyr,flash node has no write-block-size;' ,
386386 "can't determine imgtool write alignment" )
387387 align = flash .props ['write-block-size' ].val
388388 if align == 0 :
389- log .die ('expected nonzero flash alignment, but got '
389+ cmd .die ('expected nonzero flash alignment, but got '
390390 'DT flash device write-block-size {}' .format (align ))
391391
392392 # The partitions node, and its subnode, must provide
393393 # the size of slot1_partition or slot0_partition partition via the regs property.
394394 slot_key = 'slot1_partition' if 'slot1_partition' in slots else 'slot0_partition'
395395 if not slots [slot_key ].regs :
396- log .die (f'{ slot_key } flash partition has no regs property;' ,
396+ cmd .die (f'{ slot_key } flash partition has no regs property;' ,
397397 "can't determine size of slot" )
398398
399399 # always use addr of slot0_partition, which is where slots are run
400400 addr = slots ['slot0_partition' ].regs [0 ].addr
401401
402402 size = slots [slot_key ].regs [0 ].size
403403 if size == 0 :
404- log .die ('expected nonzero slot size for {}' .format (slot_key ))
404+ cmd .die ('expected nonzero slot size for {}' .format (slot_key ))
405405
406406 return (align , addr , size )
407407
@@ -462,10 +462,10 @@ def sign(self, command, build_dir, build_conf, formats):
462462 if not target :
463463 msg = 'rimage target not defined in board.cmake'
464464 if args .if_tool_available :
465- log .inf (msg )
465+ command .inf (msg )
466466 sys .exit (0 )
467467 else :
468- log .die (msg )
468+ command .die (msg )
469469
470470 kernel_name = build_conf .get ('CONFIG_KERNEL_BIN_NAME' , 'zephyr' )
471471
@@ -490,7 +490,7 @@ def sign(self, command, build_dir, build_conf, formats):
490490
491491 tool_path = (
492492 args .tool_path if args .tool_path else
493- self . command .config_get ('rimage.path' , None )
493+ command .config_get ('rimage.path' , None )
494494 )
495495 err_prefix = '--tool-path' if args .tool_path else 'west config'
496496
@@ -502,16 +502,16 @@ def sign(self, command, build_dir, build_conf, formats):
502502 if not tool_path :
503503 err_msg = 'rimage not found; either install it or provide --tool-path'
504504 if args .if_tool_available :
505- log .wrn (err_msg )
506- log .wrn ('zephyr binary _not_ signed!' )
505+ command .wrn (err_msg )
506+ command .wrn ('zephyr binary _not_ signed!' )
507507 return
508508 else :
509- log .die (err_msg )
509+ command .die (err_msg )
510510
511511 #### -c sof/rimage/config/signing_schema.toml ####
512512
513513 if not args .quiet :
514- log .inf ('Signing with tool {}' .format (tool_path ))
514+ command .inf ('Signing with tool {}' .format (tool_path ))
515515
516516 try :
517517 sof_proj = command .manifest .get_projects (['sof' ], allow_paths = False )
@@ -522,7 +522,7 @@ def sign(self, command, build_dir, build_conf, formats):
522522 self .sof_src_dir = sof_src_dir
523523
524524
525- log .inf ('Signing for SOC target ' + target )
525+ command .inf ('Signing for SOC target ' + target )
526526
527527 # FIXME: deprecate --no-manifest and replace it with a much
528528 # simpler and more direct `-- -e` which the user can _already_
@@ -555,15 +555,15 @@ def sign(self, command, build_dir, build_conf, formats):
555555 components = [ ] if bootloader is None else [ bootloader ]
556556 components += [ kernel ]
557557
558- sign_config_extra_args = self . command .config_get_words ('rimage.extra-args' , [])
558+ sign_config_extra_args = command .config_get_words ('rimage.extra-args' , [])
559559
560560 if '-k' not in sign_config_extra_args + args .tool_args :
561561 # rimage requires a key argument even when it does not sign
562562 cmake_default_key = cache .get ('RIMAGE_SIGN_KEY' , 'key placeholder from sign.py' )
563563 extra_ri_args += [ '-k' , str (sof_src_dir / 'keys' / cmake_default_key ) ]
564564
565565 if args .tool_data and '-c' in args .tool_args :
566- log .wrn ('--tool-data ' + args .tool_data + ' ignored! Overridden by: -- -c ... ' )
566+ command .wrn ('--tool-data ' + args .tool_data + ' ignored! Overridden by: -- -c ... ' )
567567
568568 if '-c' not in sign_config_extra_args + args .tool_args :
569569 conf_dir = self .rimage_config_dir ()
@@ -594,7 +594,7 @@ def sign(self, command, build_dir, build_conf, formats):
594594 else :
595595 filenames = [out_xman , out_bin ]
596596 if not args .quiet :
597- log .inf ('Prefixing ' + out_bin + ' with manifest ' + out_xman )
597+ command .inf ('Prefixing ' + out_bin + ' with manifest ' + out_xman )
598598 with open (out_tmp , 'wb' ) as outfile :
599599 for fname in filenames :
600600 with open (fname , 'rb' ) as infile :
0 commit comments