From d16a613f6dc0e1b3ae1164e2eb26fa462e87b139 Mon Sep 17 00:00:00 2001 From: Rustam Ismayilov Date: Wed, 13 Dec 2023 12:33:49 +0100 Subject: [PATCH] imgtool: Assert "measurement value" is last in boot_record.py 'Measurement Value' added the 'properties' list initially, rather than adding it separately later. Added an assertion to ensure 'Measurement Value' remains as the last item in the 'properties' list Signed-off-by: Rustam Ismayilov Change-Id: I106059c6c903c3d560477d5114d866f48590ad7e --- scripts/imgtool/boot_record.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/scripts/imgtool/boot_record.py b/scripts/imgtool/boot_record.py index 8ab2f608..fb98b2ea 100644 --- a/scripts/imgtool/boot_record.py +++ b/scripts/imgtool/boot_record.py @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2021, Arm Limited. +# Copyright (c) 2019-2024, Arm Limited. # Copyright (c) 2020, Linaro Limited # # SPDX-License-Identifier: Apache-2.0 @@ -22,6 +22,7 @@ try: except ImportError: from cbor import dumps + class SwComponent(int, Enum): """ Software component property IDs specified by @@ -36,17 +37,16 @@ class SwComponent(int, Enum): def create_sw_component_data(sw_type, sw_version, sw_measurement_description, sw_measurement_value, sw_signer_id): - # List of software component properties (Key ID + value) - properties = { - SwComponent.TYPE: sw_type, - SwComponent.VERSION: sw_version, - SwComponent.SIGNER_ID: sw_signer_id, - SwComponent.MEASUREMENT_DESCRIPTION: sw_measurement_description, - } + properties = {SwComponent.TYPE: sw_type, + SwComponent.VERSION: sw_version, + SwComponent.SIGNER_ID: sw_signer_id, + SwComponent.MEASUREMENT_DESCRIPTION: sw_measurement_description, + SwComponent.MEASUREMENT_VALUE: sw_measurement_value, + } # Note: The measurement value must be the last item of the property # list because later it will be modified by the bootloader. - properties[SwComponent.MEASUREMENT_VALUE] = sw_measurement_value - + last_key = list(properties.keys())[-1] + assert SwComponent.MEASUREMENT_VALUE == last_key, 'Measurement value is not the last item of the property list' return dumps(properties)