Skip to content

PSA tools: Find secure image at post-build #9894

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

Merged
merged 4 commits into from
Mar 6, 2019
Merged

PSA tools: Find secure image at post-build #9894

merged 4 commits into from
Mar 6, 2019

Conversation

mikisch81
Copy link
Contributor

Description

Add a common function which finds the relevant secure image of a non-secure target.
This function will be called during the post-build hook which merges the secure and non-secure images together.

The logic was taken from the PSOC6 post-build hook

Tested with Musca_a1.

Pull request type

[X] Fix
[ ] Refactor
[ ] Target update
[ ] Functionality change
[ ] Docs update
[ ] Test update
[ ] Breaking change

Reviewers

@theotherjimmy @orenc17

Release Notes

@cmonr cmonr requested a review from theotherjimmy February 28, 2019 20:59
@ciarmcom ciarmcom requested review from orenc17 and a team February 28, 2019 22:00
@ciarmcom
Copy link
Member

@mikisch81, thank you for your changes.
@orenc17 @ARMmbed/mbed-os-tools @ARMmbed/mbed-os-maintainers please review.

secure_image = next((f for f in image_files if basename(f) == basename(ns_image_path)), secure_image)

if secure_image:
toolchain.notify.debug("Secure image file found: %s." % secure_image)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resources has a notifier too, and if you're only using the notifier from the toolchain, pass in the notifier please.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well it didn't work for resources notifier:

Traceback (most recent call last):
  File "C:\miki_dev\mbed-os_backup\tools\test_api.py", line 2210, in build_test_worker
    bin_file, _ = build_project(*args, **kwargs)
  File "C:\miki_dev\mbed-os_backup\tools\build_api.py", line 584, in build_project
    res, _ = toolchain.link_program(resources, build_path, name)
  File "C:\miki_dev\mbed-os_backup\tools\toolchains\__init__.py", line 654, in link_program
    self.binary(r, elf, bin)
  File "C:\miki_dev\mbed-os_backup\tools\hooks.py", line 54, in wrapper
    post_res = tooldesc["post"](t_self, *args, **kwargs)
  File "C:\miki_dev\mbed-os_backup\tools\targets\__init__.py", line 604, in binary_hook
    secure_bin = find_secure_image(t_self, resources, binf, configured_secure_image_filename, FileType.BIN)
  File "C:\miki_dev\mbed-os_backup\tools\psa\__init__.py", line 12, in find_secure_image
    resources.notify.debug("Secure image file found: %s." % secure_image)
AttributeError: 'Resources' object has no attribute 'notify'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably private then. Pass in a notifier instead.

if secure_image:
toolchain.notify.debug("Secure image file found: %s." % secure_image)
else:
toolchain.notify.debug("Secure image file %s not found. Aborting." % configured_s_image_path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resources has a notifier too, and if you're only using the notifier from the toolchain, pass in the notifier please.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

@theotherjimmy
Copy link
Contributor

@mikisch81 I'm not seeing a change that calls this new function. How does this get invoked?

@mikisch81
Copy link
Contributor Author

@mikisch81 I'm not seeing a change that calls this new function. How does this get invoked?

By the musca post-build hook

This is currently in a branch and will be added to #9221

@theotherjimmy
Copy link
Contributor

@mikisch81 That code is not on master or in the diff, so this looks like you're adding dead code, because from the perspective of this branch you are adding dead code. Could you include the modification to the post-build hook too?

@mikisch81
Copy link
Contributor Author

Do you suggest adding the musca post build hook here?

@theotherjimmy
Copy link
Contributor

@mikisch81 That could work, and I would be alright with that. but:

The logic was taken from the PSOC6 post-build hook

So why is the PSOC6 post-build hook not refactored to use this?

Copy link
Contributor

@theotherjimmy theotherjimmy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notifier changes requested offline.

secure_image = next((f for f in image_files if basename(f) == basename(ns_image_path)), secure_image)

if secure_image:
toolchain.notify.debug("Secure image file found: %s." % secure_image)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
toolchain.notify.debug("Secure image file found: %s." % secure_image)
notify.debug("Secure image file found: %s." % secure_image)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if secure_image:
toolchain.notify.debug("Secure image file found: %s." % secure_image)
else:
toolchain.notify.debug("Secure image file %s not found. Aborting." % configured_s_image_path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
toolchain.notify.debug("Secure image file %s not found. Aborting." % configured_s_image_path)
notify.debug("Secure image file %s not found. Aborting." % configured_s_image_path)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done



# Find secure image.
def find_secure_image(toolchain, resources, ns_image_path, configured_s_image_path, image_type):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def find_secure_image(toolchain, resources, ns_image_path, configured_s_image_path, image_type):
def find_secure_image(notify, resources, ns_image_path, configured_s_image_path, image_type):

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

from os.path import basename


# Find secure image.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you change this into a doc comment? You would place this in a string as the first statement inside the body of the function.

E.G.

def find_secure_image(toolchain, resources, ns_image_path, configured_s_image_path, image_type):
    """ Find secure image. """

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@orenc17
Copy link
Contributor

orenc17 commented Mar 1, 2019

@mikisch81 That could work, and I would be alright with that. but:

The logic was taken from the PSOC6 post-build hook

So why is the PSOC6 post-build hook not refactored to use this?

@theotherjimmy
Psoc6 postbuild hook is being used by a variety of platforms some support PSA some not
This change comes to provide a unified solution for PSA targets only

@theotherjimmy
Copy link
Contributor

@orenc17 That does not make sense. If the PSOC6 has the same logic within it, then replacing that logic with this logic works regardless of PSA or any other three letter acronym you care to use.

@theotherjimmy
Copy link
Contributor

My tone on my comments has been rather harsh. My apologies, I'll be editing my comments better in the future.

I had a discussion with the authors outside of this thread, and we will be working to wire this new method into the tools in the next few days so that it's tested and verified in this PR, or the PR that contains it.

- Used by Non-secure targets post-build hooks to find
  the relevant secure image.
@NirSonnenschein
Copy link
Contributor

starting CI

@mikisch81
Copy link
Contributor Author

@ARMmbed/mbed-os-maintainers This PR needs to be for 5.12.0, #9910 will need this.

@NirSonnenschein
Copy link
Contributor

@theotherjimmy , please re-review this PR

@mbed-ci
Copy link

mbed-ci commented Mar 3, 2019

Test run: SUCCESS

Summary: 13 of 13 test jobs passed
Build number : 1
Build artifacts

@orenc17
Copy link
Contributor

orenc17 commented Mar 3, 2019

This PR is required for #9910

@mikisch81
Copy link
Contributor Author

@theotherjimmy see this comment to see the proposed usage of this function in #9910

@mikisch81
Copy link
Contributor Author

@0xc0170 is it possible to merge, and if any new comments from @theotherjimmy come up a new PR will be opened?

@0xc0170 0xc0170 requested a review from a user March 4, 2019 07:31
@mikisch81
Copy link
Contributor Author

@theotherjimmy I added tests

Copy link
Contributor

@theotherjimmy theotherjimmy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have test. Looks great

@ghost ghost added the PM_ACCEPTED label Mar 4, 2019
@mikisch81
Copy link
Contributor Author

@0xc0170 Is it possible to start CI? @theotherjimmy approved

@theotherjimmy
Copy link
Contributor

@cmonr Your timezone starts soon. running CI appreciated. (this passed travis, so it should be the same result as current master)

@0xc0170
Copy link
Contributor

0xc0170 commented Mar 4, 2019

@0xc0170 Is it possible to start CI? @theotherjimmy approved

We are now focusing on rc1 PRs and nightly job has some failures we are investigating. We will start when able.

@mikisch81
Copy link
Contributor Author

Adding @maclobdell

@0xc0170
Copy link
Contributor

0xc0170 commented Mar 5, 2019

I'll run one job here (exporters will fail as master has one bug) but at least to get the rest tested now

@0xc0170
Copy link
Contributor

0xc0170 commented Mar 5, 2019

CI started

@mbed-ci
Copy link

mbed-ci commented Mar 5, 2019

Test run: FAILED

Summary: 1 of 13 test jobs failed
Build number : 2
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_exporter

@0xc0170
Copy link
Contributor

0xc0170 commented Mar 5, 2019

Failure in the exporters will be fixed, tracked here #9938

@mikisch81
Copy link
Contributor Author

@ARMmbed/mbed-os-maintainers Can we re-run the exporter job?

@NirSonnenschein
Copy link
Contributor

restarted exporter to check if issue is resolved

@@ -0,0 +1,23 @@
from os.path import basename
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing license header here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor

@0xc0170 0xc0170 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

license addition needed

@mikisch81
Copy link
Contributor Author

@0xc0170 Added missing license header

- For cases where non-secure image is HEX and secure image is BIN
@0xc0170
Copy link
Contributor

0xc0170 commented Mar 6, 2019

CI started

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meets post freeze criteria, PSA related. Approved.

@orenc17 orenc17 mentioned this pull request Mar 6, 2019
@mbed-ci
Copy link

mbed-ci commented Mar 6, 2019

Test run: SUCCESS

Summary: 13 of 13 test jobs passed
Build number : 3
Build artifacts

@cmonr cmonr merged commit f05a343 into ARMmbed:master Mar 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants