2019-03-06 08:41:22 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
# Copyright (c) 2019 ARM Limited
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
2019-03-06 14:24:12 +00:00
|
|
|
from os.path import basename, splitext
|
2019-03-04 13:20:21 +00:00
|
|
|
from tools.resources import FileType
|
2019-02-28 14:26:37 +00:00
|
|
|
|
|
|
|
|
2019-03-04 13:20:21 +00:00
|
|
|
def find_secure_image(notify, resources, ns_image_path, configured_s_image_filename, image_type):
|
2019-02-28 14:26:37 +00:00
|
|
|
""" Find secure image. """
|
2019-03-07 16:00:20 +00:00
|
|
|
if configured_s_image_filename is None:
|
|
|
|
return None
|
2019-03-04 13:20:21 +00:00
|
|
|
|
|
|
|
assert ns_image_path and configured_s_image_filename, 'ns_image_path and configured_s_image_path are mandatory'
|
|
|
|
assert image_type in [FileType.BIN, FileType.HEX], 'image_type must be of type BIN or HEX'
|
|
|
|
|
2019-02-28 14:26:37 +00:00
|
|
|
image_files = resources.get_file_paths(image_type)
|
2019-03-04 13:20:21 +00:00
|
|
|
assert image_files, 'No image files found for this target'
|
|
|
|
|
|
|
|
secure_image = next((f for f in image_files if basename(f) == configured_s_image_filename), None)
|
2019-03-06 14:24:12 +00:00
|
|
|
secure_image = next(
|
|
|
|
(f for f in image_files if splitext(basename(f))[0] == splitext(basename(ns_image_path))[0]),
|
|
|
|
secure_image
|
|
|
|
)
|
2019-02-28 14:26:37 +00:00
|
|
|
|
|
|
|
if secure_image:
|
|
|
|
notify.debug("Secure image file found: %s." % secure_image)
|
|
|
|
else:
|
2019-03-04 13:20:21 +00:00
|
|
|
notify.debug("Secure image file %s not found. Aborting." % configured_s_image_filename)
|
2019-02-28 14:26:37 +00:00
|
|
|
raise Exception("Required secure image not found.")
|
|
|
|
|
|
|
|
return secure_image
|