From b94a6f1fc3a3599d8d82d1f43f3d48de7eadd0b6 Mon Sep 17 00:00:00 2001 From: marius-alex-tache Date: Mon, 11 Dec 2023 11:15:32 +0200 Subject: [PATCH] [NXP] Clarify usage of hash id in factory data. Update MATTER_ROOT to use a more generic path Signed-off-by: marius-alex-tache --- scripts/tools/nxp/factory_data_generator/generate.py | 11 ++++++++--- scripts/tools/nxp/generate_certs.py | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/scripts/tools/nxp/factory_data_generator/generate.py b/scripts/tools/nxp/factory_data_generator/generate.py index 69b8bac3f5b9ef..a203ac9dee749e 100755 --- a/scripts/tools/nxp/factory_data_generator/generate.py +++ b/scripts/tools/nxp/factory_data_generator/generate.py @@ -27,8 +27,13 @@ SetupPasscode, StrArgument, UniqueId, VendorId, VendorName, Verifier) from default import InputArgument -# Global variable for hash ID -hash_id = "CE47BA5E" +# A magic value used in the factory data integrity check. +# The value will be checked at runtime, before verifying the +# factory data integrity. Factory data header has the following format: +# | hash id (4 bytes) | size (4 bytes) | hash (4 bytes) | +# If the hash id check fails, it means the factory data is either missing +# or has become corrupted. +HASH_ID = "CE47BA5E" def set_logger(): @@ -158,7 +163,7 @@ def to_bin(self, klv, out, aes128_key): fullContentCipher = size.to_bytes(4, "little") + fullContentCipher # Add hash id - hashId = bytearray.fromhex(hash_id) + hashId = bytearray.fromhex(HASH_ID) hashId.reverse() fullContentCipher = hashId + fullContentCipher diff --git a/scripts/tools/nxp/generate_certs.py b/scripts/tools/nxp/generate_certs.py index d6c23a92dc0f18..7a98f7138ebe05 100644 --- a/scripts/tools/nxp/generate_certs.py +++ b/scripts/tools/nxp/generate_certs.py @@ -20,7 +20,7 @@ import os import subprocess -MATTER_ROOT = os.path.dirname(os.path.realpath(__file__))[:-len("/scripts/tools/nxp")] +MATTER_ROOT = os.path.dirname(os.path.realpath(f"{__file__}/../../../")) def gen_test_certs(chip_cert_exe: str,