diff --git a/build/chip/write_build_time_header.py b/build/chip/write_build_time_header.py index 7b421f19844c17..86e9879614db68 100755 --- a/build/chip/write_build_time_header.py +++ b/build/chip/write_build_time_header.py @@ -18,10 +18,10 @@ from datetime import datetime, timezone -def utc_time_in_matter_epoch_s(): +def utc_time_in_matter_epoch_s(time: datetime): """ Returns the time in matter epoch in s. """ # Matter epoch is 0 hours, 0 minutes, 0 seconds on Jan 1, 2000 UTC - utc_matter = datetime.now(tz=timezone.utc) - datetime(2000, 1, 1, 0, 0, 0, 0, timezone.utc) + utc_matter = time - datetime(2000, 1, 1, 0, 0, 0, 0, timezone.utc) return int(utc_matter.total_seconds()) @@ -33,17 +33,24 @@ def __init__(self, output, define_name, define_val): def GetOptions(): + fallback_lkgt = datetime(2023, 10, 3, 0, 0, 0, 0, timezone.utc) + parser = argparse.ArgumentParser() parser.add_argument('--output', help="Output header name (inside gen dir)") parser.add_argument('--gen-dir', help="Path to root of generated file directory tree.") + parser.add_argument('--use-current-time', default=False, action='store_true', + help="Set the LKGT to the current time. If this flag is not used, the LKGT is set to a hardcoded time.") cmdline_options = parser.parse_args() # The actual output file is inside the gen dir. output = os.path.join(cmdline_options.gen_dir, cmdline_options.output) define_name = 'CHIP_DEVICE_CONFIG_FIRMWARE_BUILD_TIME_MATTER_EPOCH_S' - build_time = utc_time_in_matter_epoch_s() + if cmdline_options.use_current_time: + build_time = utc_time_in_matter_epoch_s(datetime.now(tz=timezone.utc)) + else: + build_time = utc_time_in_matter_epoch_s(fallback_lkgt) return Options(output=output, define_name=define_name, diff --git a/src/credentials/BUILD.gn b/src/credentials/BUILD.gn index 2abc6e2795fd38..eb2d9c4884d51b 100644 --- a/src/credentials/BUILD.gn +++ b/src/credentials/BUILD.gn @@ -20,6 +20,7 @@ import("${chip_root}/src/platform/device.gni") declare_args() { chip_build_example_creds = true + update_last_known_good_time = false } action("gen_build_time_header") { @@ -35,6 +36,9 @@ action("gen_build_time_header") { "--gen-dir", rebase_path(include_dir, root_build_dir), ] + if (update_last_known_good_time) { + args += [ "--use-current-time" ] + } visibility = [ ":build_time_header" ] }