11#!/usr/bin/env python3 
22
3- # Copyright (c) 2023-2024  Rivos, Inc. 
3+ # Copyright (c) 2023-2025  Rivos, Inc. 
44# SPDX-License-Identifier: Apache2 
55
66"""Create/update an OpenTitan backend flash file. 
@@ -57,8 +57,10 @@ class FlashGen:
5757       :param bl_offset: offset of the BL0 storage within the data partition. 
5858                         if forced to 0, do not reserve any space for BL0, i.e. 
5959                         dedicated all storage space to ROM_EXT section. 
60-        :discard_elf_check: whether to ignore mismatching binary/elf  files. 
60+        :discard_elf_check: whether to ignore mismatching binary/ELF  files. 
6161       :accept_invalid: accept invalid input files (fully ignore content) 
62+        :discard_time_check: whether to ignore mismatching time between binary 
63+                          and ELF files. 
6264    """ 
6365
6466    NUM_BANKS  =  2 
@@ -155,14 +157,16 @@ class FlashGen:
155157    BOOT_PARTS  =  2 
156158
157159    def  __init__ (self , bl_offset : Optional [int ] =  None ,
158-                  discard_elf_check : Optional [bool ] =  None ,
159-                  accept_invalid : Optional [bool ] =  None ):
160+                  discard_elf_check : bool  =  False ,
161+                  accept_invalid : bool  =  False ,
162+                  discard_time_check : bool  =  False ):
160163        self ._log  =  getLogger ('flashgen' )
161164        self ._check_manifest_size ()
162165        self ._bl_offset  =  bl_offset  if  bl_offset  is  not   None  \
163166            else  self .CHIP_ROM_EXT_SIZE_MAX 
164-         self ._accept_invalid  =  bool (accept_invalid )
165-         self ._check_elf  =  not  (bool (discard_elf_check ) or  self ._accept_invalid )
167+         self ._accept_invalid  =  accept_invalid 
168+         self ._check_elf  =  not  (discard_elf_check  or  self ._accept_invalid )
169+         self ._check_time  =  not  discard_time_check  and  self ._check_elf 
166170        hfmt  =  '' .join (self .HEADER_FORMAT .values ())
167171        header_size  =  scalc (hfmt )
168172        assert  header_size  ==  32 
@@ -314,7 +318,7 @@ def store_rom_ext(self, bank: int, dfp: BinaryIO,
314318            bintime  =  stat (dfp .name ).st_mtime 
315319            if  bintime  <  elftime :
316320                msg  =  'Application binary file is older than ELF file' 
317-                 if  self ._check_elf :
321+                 if  self ._check_time :
318322                    raise  RuntimeError (msg )
319323                self ._log .warning (msg )
320324            be_match  =  self ._compare_bin_elf (bindesc , elfpath )
@@ -351,7 +355,7 @@ def store_bootloader(self, bank: int, dfp: BinaryIO,
351355            bintime  =  stat (dfp .name ).st_mtime 
352356            if  bintime  <  elftime :
353357                msg  =  'Boot binary file is older than ELF file' 
354-                 if  self ._check_elf :
358+                 if  self ._check_time :
355359                    raise  RuntimeError (msg )
356360                self ._log .warning (msg )
357361            be_match  =  self ._compare_bin_elf (bindesc , elfpath )
@@ -634,6 +638,8 @@ def main():
634638        files .add_argument ('-t' , '--otdesc' , action = 'append' , default = [],
635639                           help = 'OpenTitan style file descriptor, ' 
636640                                'may be repeated' )
641+         files .add_argument ('-T' , '--ignore-time' , action = 'store_true' ,
642+                            help = 'Discard time checking on ELF files' )
637643        files .add_argument ('-U' , '--unsafe-elf' , action = 'store_true' ,
638644                           help = 'Discard sanity checking on ELF files' )
639645        files .add_argument ('-A' , '--accept-invalid' , action = 'store_true' ,
@@ -649,8 +655,8 @@ def main():
649655        configure_loggers (args .verbose , 'flashgen' , 'elf' )
650656
651657        use_bl0  =  bool (args .boot ) or  len (args .otdesc ) >  1 
652-         gen  =  FlashGen (args .offset  if  use_bl0  else  0 , bool ( args .unsafe_elf ) ,
653-                        bool ( args .accept_invalid ) )
658+         gen  =  FlashGen (args .offset  if  use_bl0  else  0 , args .unsafe_elf ,
659+                        args .accept_invalid ,  args . ignore_time )
654660        flash_pathname  =  args .flash [0 ]
655661        backup_filename  =  None 
656662        if  args .otdesc  and  any (filter (None , (args .bank ,
0 commit comments