Lines Matching +full:write +full:- +full:command

3 # SPDX-License-Identifier: Apache-2.0
28 sys.path.insert(0, str(ZEPHYR_SCRIPTS / 'dts' / 'python-devicetree' / 'src'))
31 This command automates some of the drudgery of creating signed Zephyr
32 binaries for chain-loading by a bootloader.
36 west sign -t your_tool -- ARGS_FOR_YOUR_TOOL
40 which sort of ARGS_FOR_YOUR_TOOLS you use, the `--` separator/sentinel may
42 understand POSIX 12.2 Guideline 10, always use `--`.
44 See tool-specific help below for details.'''
48 -------
53 west sign -t imgtool -- --key YOUR_SIGNING_KEY.pem
56 or you must pass the path to imgtool.py using the -p option.
64 As shown above, extra arguments after a '--' are passed to imgtool
68 ------
73 west sign -t rimage -- -k YOUR_SIGNING_KEY.pem
76 the path to rimage using the -p option.
87 setattr(args, self.dest, not option.startswith('--no-'))
94 # Keep this in sync with the string in west-commands.yml.
95 'sign a Zephyr binary for bootloader chain-loading',
107 parser.add_argument('-d', '--build-dir',
109 parser.add_argument('-q', '--quiet', action='store_true',
110 help='suppress non-error output')
115 group.add_argument('-t', '--tool', choices=['imgtool', 'rimage'],
118 group.add_argument('-p', '--tool-path', default=None,
120 group.add_argument('-D', '--tool-data', default=None,
121 … help='''path to a tool-specific data/configuration directory, if needed''')
122 group.add_argument('--if-tool-available', action='store_true',
130 group.add_argument('--bin', '--no-bin', dest='gen_bin', nargs=0,
135 group.add_argument('-B', '--sbin', metavar='BIN',
142 group.add_argument('--hex', '--no-hex', dest='gen_hex', nargs=0,
147 group.add_argument('-H', '--shex', metavar='HEX',
174 '--bin given but CONFIG_BUILD_OUTPUT_BIN not set '
184 '--hex given but CONFIG_BUILD_OUTPUT_HEX not set '
194 self.die('imgtool does not support --if-tool-available')
201 self.die('one --tool is required')
215 def sign(self, command, build_dir, build_conf, formats): argument
218 :param command: the Sign instance
227 def sign(self, command, build_dir, build_conf, formats): argument
231 args = command.args
234 command.wrn("west sign using imgtool is deprecated and will be removed in a future release")
236 imgtool = self.find_imgtool(command, args)
238 appver = self.get_cfg(command, build_conf, 'CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION')
239 vtoff = self.get_cfg(command, build_conf, 'CONFIG_ROM_START_OFFSET')
240 # Flash device write alignment and the partition's slot size
242 flash = self.edt_flash_node(command, b, args.quiet)
243 align, addr, size = self.edt_flash_params(command, flash)
246 command.wrn("CONFIG_BOOTLOADER_MCUBOOT is not set to y in "
254 command.die(f"no unsigned .bin found at {in_bin}")
261 command.die(f"no unsigned .hex found at {in_hex}")
267 command.banner('image configuration:')
268 command.inf('partition offset: {0} (0x{0:x})'.format(addr))
269 command.inf('partition size: {0} (0x{0:x})'.format(size))
270 command.inf('rom start offset: {0} (0x{0:x})'.format(vtoff))
272 # Base sign command.
274 '--version', str(appver),
275 '--align', str(align),
276 '--header-size', str(vtoff),
277 '--slot-size', str(size)]
281 command.banner('signing binaries')
286 command.inf(f'unsigned bin: {in_bin}')
287 command.inf(f'signed bin: {out_bin}')
288 command.dbg(quote_sh_list(sign_bin))
294 command.inf(f'unsigned hex: {in_hex}')
295 command.inf(f'signed hex: {out_hex}')
296 command.dbg(quote_sh_list(sign_hex))
304 cmd.die(f'--tool-path {imgtool}: no such file')
309 '(e.g. "pip3 install imgtool") or provide --tool-path')
317 # https://github.com/zephyrproject-rtos/zephyr/issues/31876
323 def get_cfg(command, build_conf, item): argument
327 command.check_force(
354 "can't infer flash write block or slot0_partition slot sizes")
360 # Get the flash device's write alignment and offset from the
363 # when available, because in swap-move mode it can be one sector
386 if "write-block-size" not in flash.props:
387 cmd.die('DT zephyr,flash node has no write-block-size;',
388 "can't determine imgtool write alignment")
389 align = flash.props['write-block-size'].val
392 'DT flash device write-block-size {}'.format(align))
414 args = self.command.args
421 self.command.dbg(f'rimage config directory={conf_dir}')
425 'Runs the C pre-processor on config_dir/toml_basename.h'
428 preproc_cmd = [compiler_path, '-E', str(config_dir / (toml_basename + '.h'))]
429 # -P removes line markers to keep the .toml output reproducible. To
430 # trace #includes, temporarily comment out '-P' (-f*-prefix-map
432 # gcc-specific)
433 preproc_cmd += ['-P']
442 preproc_cmd += ['-DREM=']
444 preproc_cmd += ['-I', str(self.sof_src_dir / 'src')]
445 preproc_cmd += ['-imacros',
449 …full_preproc_cmd = preproc_cmd + ['-o', str(subdir / 'rimage_config_full.toml'), '-DLLEXT_FORCE_AL…
450 preproc_cmd += ['-o', str(subdir / 'rimage_config.toml')]
451 self.command.inf(quote_sh_list(preproc_cmd))
455 def sign(self, command, build_dir, build_conf, formats): argument
456 self.command = command
457 args = command.args
471 command.inf(msg)
474 command.die(msg)
499 # Clean any stale output. This is especially important when using --if-tool-available
506 command.config_get('rimage.path', None)
508 err_prefix = '--tool-path' if args.tool_path else 'west config'
511 command.check_force(shutil.which(tool_path),
516 err_msg = 'rimage not found; either install it or provide --tool-path'
518 command.wrn(err_msg)
519 command.wrn('zephyr binary _not_ signed!')
522 command.die(err_msg)
524 #### -c sof/rimage/config/signing_schema.toml ####
527 command.inf('Signing with tool {}'.format(tool_path))
530 sof_proj = command.manifest.get_projects(['sof'], allow_paths=False)
538 command.inf('Signing for SOC target ' + target)
540 # FIXME: deprecate --no-manifest and replace it with a much
541 # simpler and more direct `-- -e` which the user can _already_
543 if '--no-manifest' in args.tool_args:
545 args.tool_args.remove('--no-manifest')
549 # Non-SOF build does not have extended manifest data for
559 extra_ri_args = ['-e']
564 # Sub-command arg 'west sign -q' takes precedence over west '-v'
566 sign_base += ['-v'] * args.verbose
574 sign_config_extra_args = command.config_get_words('rimage.extra-args', [])
576 if '-k' not in sign_config_extra_args + args.tool_args:
579 extra_ri_args += [ '-k', str(sof_src_dir / 'keys' / cmake_default_key) ]
581 if args.tool_data and '-c' in args.tool_args:
582 command.wrn('--tool-data ' + args.tool_data + ' ignored! Overridden by: -- -c ... ')
584 if '-c' not in sign_config_extra_args + args.tool_args:
589command.die(f"Cannot have both {toml_basename + '.h'} and {toml_basename} in {conf_dir}")
594 extra_ri_args += ['-c', str(b / generated_subdir / 'rimage_config.toml')]
597 extra_ri_args += ['-c', str(toml_dir / toml_basename)]
599 # Warning: while not officially supported (yet?), the rimage --option that is last
600 # on the command line currently wins in case of duplicate options. So pay
602 sign_base += (['-o', out_bin] + sign_config_extra_args +
605 command.inf(quote_sh_list(sign_base))
613 command.inf('Prefixing ' + out_bin + ' with manifest ' + out_xman)
617 outfile.write(infile.read())