Skip to content
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

Put the firmware build time update behind a build flag #29691

Merged
merged 5 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build/chip/fallback_lkgt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
750275722
cecille marked this conversation as resolved.
Show resolved Hide resolved
50 changes: 35 additions & 15 deletions build/chip/write_build_time_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@
import os
from datetime import datetime, timezone

SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
FALLBACK_LKGT_FILENAME = os.path.abspath(os.path.join(SCRIPT_DIR, 'fallback_lkgt'))

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())


Expand All @@ -32,31 +35,48 @@ def __init__(self, output, define_name, define_val):
self.define_val = define_val


def GetOptions():
def write_header(options):
with open(options.output, "w") as output_file:
output_file.write("// Generated by write_build_time_header.py\n")
output_file.write('#pragma once\n\n')

output_file.write(f'#define {options.define_name} {options.define_val}\n')


def update_fallback_time_in_file():
with open(FALLBACK_LKGT_FILENAME, "w") as output_file:
output_file.write(str(utc_time_in_matter_epoch_s(datetime.now(tz=timezone.utc))))


def main():
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.")
parser.add_argument('--update-fallback-time-in-file', default=False, action='store_true',
help='Write the current UTC time out to the fallback file')
cmdline_options = parser.parse_args()

if cmdline_options.update_fallback_time_in_file:
update_fallback_time_in_file()
return

# 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:
with open(FALLBACK_LKGT_FILENAME, "r") as input_file:
build_time = int(input_file.read())

return Options(output=output,
opts = Options(output=output,
define_name=define_name,
define_val=str(build_time))
write_header(opts)


def WriteHeader(options):
with open(options.output, "w") as output_file:
output_file.write("// Generated by write_build_time_header.py\n")
output_file.write('#pragma once\n\n')

output_file.write(f'#define {options.define_name} {options.define_val}\n')


options = GetOptions()
WriteHeader(options)
main()
4 changes: 4 additions & 0 deletions src/credentials/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand All @@ -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" ]
}
Expand Down
Loading