-
Notifications
You must be signed in to change notification settings - Fork 674
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
imgtool: Extend functionality with getpubhash and output to file #1752
imgtool: Extend functionality with getpubhash and output to file #1752
Conversation
scripts/imgtool/keys/general.py
Outdated
print("\n" + trailer, file=file) | ||
if len_format is not None: | ||
print(len_format.format(len(encoded_bytes)), file=file) | ||
sys.stdout.close = lambda: None |
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.
Could you explain it to me? Thanks! :)
Is it possible that it's not necessary if the the default file=sys.stdout is removed for the "emit functions" ?
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.
The sys.stdout
does not have the close method implemented and would throw an error when the with (open...
's scope ends. This way we add an empty method to prevent this error and there's no need for additional checks whether the file
is sys.stdout
or a regular file.
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.
I've tried it without the sys.stdout.close = lambda: None
line and it worked fine. Isn't it that with the is not sys.stdout
check it's avoided?
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.
You are right, my reasoning was not correct. 😬
sys.stdout
does have a close()
method but once it's called, the print()
will no longer work until the sys.stdout
's open()
is called again.
So a print() after the close() would cause a crash if this sys.stdout.close = lambda: None
is removed so as a workaround its close()
is overridden.
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.
Removed this solution from the latest patchset because it'd change the global state and it's not that clear either.
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.
Thanks for the update.
Another solution could have been to use the open()/close() methods directly, without with
.
00761c8
to
ca29872
Compare
Please rebase your PR, Zephyr build was broken, but it's been fixed by: #1755 |
da68716
to
650aaed
Compare
#nitpick
You can check these using either the |
Signed-off-by: Dávid Házi <david.hazi@arm.com> Signed-off-by: Bence Balogh <bence.balogh@arm.com> Change-Id: I6028955be5cbcd20d49ef2126dce8d4636b824a6
Signed-off-by: Dávid Házi <david.hazi@arm.com> Signed-off-by: Bence Balogh <bence.balogh@arm.com> Change-Id: Ia7f385e5e1b0471aae7693baa54e9a385ad3ae3f
650aaed
to
2aeb43e
Compare
Signed-off-by: Dávid Házi <david.hazi@arm.com> Signed-off-by: Bence Balogh <bence.balogh@arm.com> Change-Id: I91d5c07c1bb2b8abe2592cd49b2053c881465ba2
Signed-off-by: Bence Balogh <bence.balogh@arm.com> Change-Id: I48eabb1dc9696ef50d12fc8782616169ba8acc45
2aeb43e
to
26bd951
Compare
getpubhash
: It returns the sha256 hash of the public key. It can be useful ifMCUBOOT_HW_KEY
is set and only the hash has to be written to the device.getpubhash
to print to a file instead of stdout.getpubhash
to print the output as a raw value.