66#test:timeout 500
77#test:donotrun:gha
88#test:device each(D400*)
9+ #test:device D555
910
1011import sys
1112import os
1415import platform
1516import pyrealsense2 as rs
1617import pyrsutils as rsutils
17- from rspy import devices , log , test , file , repo
18+ from rspy import log , test , file , repo
1819import time
1920import argparse
2021
2122# Parse command-line arguments
2223parser = argparse .ArgumentParser (description = "Test firmware update" )
23- parser .add_argument ('--custom-fw-d400' , type = str , help = 'Path to custom firmware file' )
24+ parser .add_argument ('--custom-fw-d400' , type = str , help = 'Path to custom D400 firmware file' )
25+ parser .add_argument ('--custom-fw-d555' , type = str , help = 'Path to custom D555 firmware file' )
2426args = parser .parse_args ()
2527
26- custom_fw_d400_path = args .custom_fw_d400
27- if custom_fw_d400_path :
28- log .i (f"Custom firmware path provided: { custom_fw_d400_path } " )
29- else :
30- log .i (f"No Custom firmware path provided. using bundled firmware" )
31-
32- # This is the first test running, discover acroname modules.
33- # Not relevant to MIPI devices running on jetson for LibCI
34- if 'jetson' not in test .context :
35- if not devices .hub :
36- log .i ( "No hub library found; skipping device FW update" )
37- sys .exit (0 )
38- # Following will throw if no acroname module is found
39- from rspy import device_hub
40-
41- if device_hub .create () is None :
42- log .f ("No hub found" )
43- # Remove acroname -- we're likely running inside run-unit-tests in which case the
44- # acroname hub is likely already connected-to from there and we'll get an error
45- # thrown ('failed to connect to acroname (result=11)'). We do not need it -- just
46- # needed to verify it is available above...
47- devices .hub = None
48-
4928
5029def send_hardware_monitor_command (device , command ):
5130 # byte_index = -1
@@ -73,7 +52,7 @@ def extract_version_from_filename(file_path):
7352 return None
7453
7554 filename = os .path .basename (file_path )
76- match = re .search (r'(\d+)_ (\d+)_ (\d+)_ (\d+)\.bin$ ' , filename )
55+ match = re .search (r'[-_] (\d+)[._] (\d+)[._] (\d+)[._] (\d+)' , filename )
7756 if match :
7857 groups = match .groups ()
7958 if groups [3 ] == '0' :
@@ -95,6 +74,8 @@ def get_update_counter(device):
9574
9675 if product_line == "D400" :
9776 size = 0x2
77+ elif product_line == "D500" :
78+ return 0 # D500 do not have update counter
9879 else :
9980 log .f ( "Incompatible product line:" , product_line )
10081
@@ -163,29 +144,37 @@ def find_image_or_exit( product_name, fw_version_regex = r'(\d+\.){3}(\d+)' ):
163144if not fw_updater_exe :
164145 log .f ( "Could not find the update tool file (rs-fw-update.exe)" )
165146
166- devices .query ( monitor_changes = False )
167- sn_list = devices .all ()
168- # acroname should ensure there is always 1 available device
169- if len ( sn_list ) != 1 :
170- log .f ( "Expected 1 device, got" , len ( sn_list ) )
171- device = devices .get_first ( sn_list ).handle
172- log .d ( 'found:' , device )
147+ device , ctx = test .find_first_device_or_exit ()
173148product_line = device .get_info ( rs .camera_info .product_line )
174149product_name = device .get_info ( rs .camera_info .name )
175150log .d ( 'product line:' , product_line )
176151###############################################################################
177152#
178153
154+ current_fw_version = rsutils .version ( device .get_info ( rs .camera_info .firmware_version ))
155+ log .d ( 'current FW version:' , current_fw_version )
156+
157+ # Determine which firmware to use based on product
158+ bundled_fw_version = rsutils .version ("" )
159+ custom_fw_path = None
160+ custom_fw_version = None
161+ if product_line == "D400" and args .custom_fw_d400 :
162+ custom_fw_path = args .custom_fw_d400
163+ elif "D555" in product_name and args .custom_fw_d555 :
164+ custom_fw_path = args .custom_fw_d555
165+
179166
180167test .start ( "Update FW" )
181168# check if recovery. If so recover
182169recovered = False
183170if device .is_in_recovery_mode ():
184171 log .d ( "recovering device ..." )
185172 try :
186- # always flash signed fw when device on recovery befre flashing anything else
187- image_file = find_image_or_exit (product_name )
173+ # always flash signed fw when device on recovery before flashing anything else
174+ # on D555 we currently do not have bundled FW
175+ image_file = find_image_or_exit (product_name ) if "D555" not in product_name else custom_fw_path
188176 cmd = [fw_updater_exe , '-r' , '-f' , image_file ]
177+ del device , ctx
189178 log .d ( 'running:' , cmd )
190179 subprocess .run ( cmd )
191180 recovered = True
@@ -199,26 +188,28 @@ def find_image_or_exit( product_name, fw_version_regex = r'(\d+\.){3}(\d+)' ):
199188 test .unexpected_exception ()
200189 log .f ( "Unexpected error while trying to recover device:" , e )
201190 else :
202- devices .query ( monitor_changes = False )
203- device = devices .get_first ( devices .all () ).handle
191+ device , ctx = test .find_first_device_or_exit ()
192+ current_fw_version = rsutils .version (device .get_info (rs .camera_info .firmware_version ))
193+ log .d ("FW version after recovery:" , current_fw_version )
204194
205- current_fw_version = rsutils .version ( device .get_info ( rs .camera_info .firmware_version ))
206- log .d ( 'current FW version:' , current_fw_version )
207- bundled_fw_version = rsutils .version ( device .get_info ( rs .camera_info .recommended_firmware_version ) )
208- log .d ( 'bundled FW version:' , bundled_fw_version )
209- custom_fw_d400_version = extract_version_from_filename (custom_fw_d400_path )
210- log .d ( 'custom FW D400 version:' , custom_fw_d400_version )
211195
196+ if custom_fw_path :
197+ custom_fw_version = extract_version_from_filename (custom_fw_path )
198+ log .d ('Using custom FW version: ' , custom_fw_version )
199+ elif device .supports (rs .camera_info .recommended_firmware_version ): # currently, D500 does not support recommended FW
200+ log .i (f"No Custom firmware path provided. using bundled firmware" )
201+ bundled_fw_version = rsutils .version (device .get_info (rs .camera_info .recommended_firmware_version ))
202+ log .d ('bundled FW version:' , bundled_fw_version )
203+ else :
204+ log .w ("No custom FW provided and no bundled FW version available; skipping FW update test" )
205+ exit (0 )
212206
213- if (current_fw_version == bundled_fw_version and not custom_fw_d400_path ) or \
214- (current_fw_version == custom_fw_d400_version ):
207+ if (current_fw_version == bundled_fw_version and not custom_fw_path ) or \
208+ (current_fw_version == custom_fw_version ):
215209 if recovered or 'nightly' not in test .context :
216210 log .d ('versions are same; skipping FW update' )
217211 test .finish ()
218212 test .print_results_and_exit ()
219- else :
220- # It is expected that, post-recovery, the FW versions will be the same
221- test .check (not recovered , on_fail = test .ABORT )
222213
223214update_counter = get_update_counter ( device )
224215log .d ( 'update counter:' , update_counter )
@@ -231,29 +222,33 @@ def find_image_or_exit( product_name, fw_version_regex = r'(\d+\.){3}(\d+)' ):
231222if not bundled_fw_version .build ():
232223 fw_version_regex += ".0" # version drops the build if 0
233224fw_version_regex = re .escape ( fw_version_regex )
234- image_file = find_image_or_exit (product_name , fw_version_regex ) if not custom_fw_d400_path else custom_fw_d400_path
225+ image_file = find_image_or_exit (product_name , fw_version_regex ) if not custom_fw_path else custom_fw_path
235226# finding file containing image for FW update
236227
237228cmd = [fw_updater_exe , '-f' , image_file ]
238- if custom_fw_d400_path :
229+ if custom_fw_path :
239230 # Add '-u' only if the path doesn't include 'signed'
240- if 'signed' not in custom_fw_d400_path .lower ():
231+ if ('signed' not in custom_fw_path .lower ()
232+ and "d555" not in product_name .lower ()): # currently -u is not supported for D555
241233 cmd .insert (1 , '-u' )
234+
235+ # for DDS devices we need to close device and context to detect it back after FW update
236+ del device , ctx
242237log .d ( 'running:' , cmd )
243238sys .stdout .flush ()
244239subprocess .run ( cmd ) # may throw
245240
246241# make sure update worked
247242time .sleep (3 ) # MIPI devices do not re-enumerate so we need to give them some time to restart
248- devices .query ( monitor_changes = False )
249- sn_list = devices .all ()
250- device = devices .get_first ( sn_list ).handle
243+ device , ctx = test .find_first_device_or_exit ()
251244current_fw_version = rsutils .version ( device .get_info ( rs .camera_info .firmware_version ))
252- test .check_equal (current_fw_version , bundled_fw_version if not custom_fw_d400_path else custom_fw_d400_version )
245+
246+ expected_fw_version = custom_fw_version if custom_fw_path else bundled_fw_version
247+ test .check_equal (current_fw_version , expected_fw_version )
253248new_update_counter = get_update_counter ( device )
254249# According to FW: "update counter zeros if you load newer FW than (ever) before"
255250# TODO: check why update counter is 255 when installing cutom fw
256- if new_update_counter > 0 and not custom_fw_d400_version :
251+ if new_update_counter > 0 and not custom_fw_version :
257252 test .check_equal ( new_update_counter , update_counter + 1 )
258253
259254test .finish ()
0 commit comments