-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Add support for west sign
for Silabs SoCs
#92181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
005c0bb
10538da
9e1550d
436bb53
26222a4
3e6eef8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,6 +79,26 @@ | |
[rimage] sections in your west config file(s); this is especially useful | ||
when invoking west sign _indirectly_ through CMake/ninja. See how at | ||
https://docs.zephyrproject.org/latest/develop/west/sign.html | ||
|
||
silabs_commander | ||
---------------- | ||
|
||
To create a signed binary with the silabs_commander tool, run this from your | ||
build directory: | ||
|
||
west sign -t silabs_commander -- [--sign PRIVATE.pem] [--encrypt KEY] [--mic KEY] | ||
|
||
For this to work, either "commander" must be installed or you must pass | ||
the path to "commander" using the -p option. | ||
|
||
If an argument is not specified, the value provided by Kconfig | ||
(CONFIG_SIWX91X_SIGN_KEY, CONFIG_SIWX91X_MIC_KEY and CONFIG_SIWX91X_ENCRYPT) | ||
is used. | ||
|
||
The exact behavior of these option are described in Silabs UG574[1] or in the | ||
output of "commander rps converter --help" | ||
|
||
[1]: https://www.silabs.com/documents/public/user-guides/ug574-siwx917-soc-manufacturing-utility-user-guide.pdf | ||
''' | ||
|
||
class ToggleAction(argparse.Action): | ||
|
@@ -112,8 +132,8 @@ def do_add_parser(self, parser_adder): | |
|
||
# general options | ||
group = parser.add_argument_group('tool control options') | ||
group.add_argument('-t', '--tool', choices=['imgtool', 'rimage'], | ||
help='''image signing tool name; imgtool and rimage | ||
group.add_argument('-t', '--tool', choices=['imgtool', 'rimage', 'silabs_commander'], | ||
help='''image signing tool name; imgtool, rimage and silabs_commander | ||
are currently supported (imgtool is deprecated)''') | ||
group.add_argument('-p', '--tool-path', default=None, | ||
help='''path to the tool itself, if needed''') | ||
|
@@ -195,6 +215,8 @@ def do_run(self, args, ignored): | |
signer = ImgtoolSigner() | ||
elif args.tool == 'rimage': | ||
signer = RimageSigner() | ||
elif args.tool == 'silabs_commander': | ||
signer = CommanderSigner() | ||
# (Add support for other signers here in elif blocks) | ||
else: | ||
if args.tool is None: | ||
|
@@ -633,3 +655,54 @@ def sign(self, command, build_dir, build_conf, formats): | |
|
||
os.remove(out_bin) | ||
os.rename(out_tmp, out_bin) | ||
|
||
class CommanderSigner(Signer): | ||
@staticmethod | ||
def get_tool(command): | ||
if command.args.tool_path: | ||
tool = command.args.tool_path | ||
if not os.path.isfile(tool): | ||
command.die(f'--tool-path {tool}: no such file') | ||
else: | ||
tool = shutil.which('commander') | ||
if not tool: | ||
command.die('"commander" not found; either install it or provide --tool-path') | ||
return tool | ||
|
||
@staticmethod | ||
def get_keys(command, build_conf): | ||
sign_key = getattr(command.args, 'sign', | ||
build_conf.get('CONFIG_SIWX91X_SIGN_KEY', None)) | ||
mic_key = getattr(command.args, 'mic', | ||
build_conf.get('CONFIG_SIWX91X_MIC_KEY', None)) | ||
encrypt_key = None | ||
if build_conf.get('CONFIG_SIWX91X_ENCRYPT', False): | ||
encrypt_key = mic_key | ||
encrypt_key = getattr(command.args, 'encrypt', encrypt_key) | ||
return (sign_key, mic_key, encrypt_key) | ||
|
||
@staticmethod | ||
def get_input_output(command, build_dir, build_conf): | ||
kernel_prefix = (pathlib.Path(build_dir) / 'zephyr' / | ||
build_conf.get('CONFIG_KERNEL_BIN_NAME', "zephyr")) | ||
in_file = f'{kernel_prefix}.rps' | ||
out_file = command.args.sbin or f'{kernel_prefix}.signed.rps' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✔️ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This looks fun but you sent a notification for each one :-) ( |
||
return (in_file, out_file) | ||
|
||
def sign(self, command, build_dir, build_conf, formats): | ||
tool = self.get_tool(command) | ||
in_file, out_file = self.get_input_output(command, build_dir, build_conf) | ||
sign_key, mic_key, encrypt_key = self.get_keys(command, build_conf) | ||
|
||
commandline = [ tool, "rps", "convert", out_file, "--app", in_file ] | ||
if mic_key: | ||
commandline.extend(["--mic", mic_key]) | ||
if encrypt_key: | ||
commandline.extend(["--encrypt", encrypt_key]) | ||
if sign_key: | ||
commandline.extend(["--sign", sign_key]) | ||
commandline.extend(command.args.tool_args) | ||
|
||
if not command.args.quiet: | ||
command.inf("Signing with:", ' '.join(commandline)) | ||
subprocess.run(commandline, check=True) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,4 @@ if SOC_SERIES_SIWG917 | |
config NUM_IRQS | ||
default 99 | ||
|
||
config BUILD_OUTPUT_HEX | ||
default y | ||
|
||
endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo