Skip to content

Commit c0a5a26

Browse files
committed
device discovered after dfu in fw-update tool
1 parent 63d8aab commit c0a5a26

File tree

2 files changed

+46
-49
lines changed

2 files changed

+46
-49
lines changed

tools/fw-update/rs-fw-update.cpp

Lines changed: 44 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@
3131

3232
using rsutils::json;
3333

34+
std::condition_variable cv;
35+
std::mutex mutex;
36+
std::string selected_serial_number;
37+
38+
rs2::device new_device;
39+
rs2::update_device new_fw_update_device;
40+
41+
bool done = false;
3442

3543
std::vector<uint8_t> read_fw_file(std::string file_path)
3644
{
@@ -139,7 +147,30 @@ void list_devices( rs2::context ctx )
139147
}
140148
}
141149

142-
int write_fw_to_mipi_device( const rs2::device & dev, const std::vector< uint8_t > & fw_image )
150+
151+
void waiting_for_device_to_reconnect(rs2::context& ctx, rs2::cli::value<std::string>& serial_number_arg)
152+
{
153+
std::cout << std::endl << "Waiting for device to reconnect..." << std::endl;
154+
std::unique_lock<std::mutex> lk(mutex);
155+
cv.wait_for(lk, std::chrono::seconds(WAIT_FOR_DEVICE_TIMEOUT), [&] { return !done || new_device; });
156+
157+
if (done)
158+
{
159+
auto devs = ctx.query_devices();
160+
for (auto&& d : devs)
161+
{
162+
auto sn = d.supports(RS2_CAMERA_INFO_SERIAL_NUMBER) ? d.get_info(RS2_CAMERA_INFO_SERIAL_NUMBER) : "unknown";
163+
if (serial_number_arg.isSet() && sn != selected_serial_number)
164+
continue;
165+
166+
auto fw = d.supports(RS2_CAMERA_INFO_FIRMWARE_VERSION) ? d.get_info(RS2_CAMERA_INFO_FIRMWARE_VERSION) : "unknown";
167+
std::cout << std::endl << "Device " << sn << " successfully updated to FW: " << fw << std::endl;
168+
}
169+
}
170+
171+
}
172+
173+
int write_fw_to_mipi_device( rs2::context& ctx, rs2::cli::value<std::string>& serial_number_arg, const rs2::device & dev, const std::vector< uint8_t > & fw_image )
143174
{
144175
// Write firmware to appropriate file descriptor
145176
std::cout << std::endl << "Update can take up to 2 minutes" << std::endl;
@@ -186,6 +217,10 @@ int write_fw_to_mipi_device( const rs2::device & dev, const std::vector< uint8_t
186217
return EXIT_FAILURE;
187218
}
188219
std::cout << std::endl << "Firmware update done" << std::endl;
220+
221+
done = true;
222+
223+
waiting_for_device_to_reconnect(ctx, serial_number_arg);
189224

190225
return EXIT_SUCCESS;
191226
}
@@ -205,15 +240,6 @@ bool is_mipi_device( const rs2::device & dev )
205240
int main( int argc, char ** argv )
206241
try
207242
{
208-
std::condition_variable cv;
209-
std::mutex mutex;
210-
std::string selected_serial_number;
211-
212-
rs2::device new_device;
213-
rs2::update_device new_fw_update_device;
214-
215-
bool done = false;
216-
217243
using rs2::cli;
218244
cli cmd( "librealsense rs-fw-update tool" );
219245

@@ -477,25 +503,28 @@ try
477503
// return EXIT_FAILURE;
478504
// }
479505

480-
return write_fw_to_mipi_device( d, fw_image );
506+
return write_fw_to_mipi_device(ctx, serial_number_arg, d, fw_image );
481507
}
482508

483509
if( unsigned_arg.isSet() )
484510
{
485-
std::cout << std::endl << "Firmware update started. Please don't disconnect device!" << std::endl << std::endl;
511+
512+
std::cout << std::endl << "Unsigned Firmware update started. Please don't disconnect device!" << std::endl << std::endl;
486513

487514
if( ISATTY( FILENO( stdout ) ) )
488515
{
489516
d.as<rs2::updatable>().update_unsigned( fw_image, [&]( const float progress )
490517
{
491-
printf( "\rFirmware update progress: %d[%%]", (int)( progress * 100 ) );
518+
printf( "\rUnsigned Firmware update progress: %d[%%]", (int)( progress * 100 ) );
492519
std::cout.flush();
493520
} );
494521
}
495522
else
496523
d.as<rs2::updatable>().update_unsigned( fw_image, [&]( const float progress ) {} );
497524

498-
std::cout << std::endl << std::endl << "Firmware update done" << std::endl;
525+
std::cout << std::endl << std::endl << "Unsigned Firmware update done" << std::endl;
526+
527+
done = true;
499528
}
500529
else
501530
{
@@ -547,23 +576,7 @@ try
547576
return EXIT_FAILURE;
548577
}
549578

550-
std::cout << std::endl << "Waiting for device to reconnect..." << std::endl;
551-
std::unique_lock<std::mutex> lk(mutex);
552-
cv.wait_for(lk, std::chrono::seconds(WAIT_FOR_DEVICE_TIMEOUT), [&] { return !done || new_device; });
553-
554-
if (done)
555-
{
556-
auto devs = ctx.query_devices();
557-
for (auto&& d : devs)
558-
{
559-
auto sn = d.supports(RS2_CAMERA_INFO_SERIAL_NUMBER) ? d.get_info(RS2_CAMERA_INFO_SERIAL_NUMBER) : "unknown";
560-
if (serial_number_arg.isSet() && sn != selected_serial_number)
561-
continue;
562-
563-
auto fw = d.supports(RS2_CAMERA_INFO_FIRMWARE_VERSION) ? d.get_info(RS2_CAMERA_INFO_FIRMWARE_VERSION) : "unknown";
564-
std::cout << std::endl << "Device " << sn << " successfully updated to FW: " << fw << std::endl;
565-
}
566-
}
579+
waiting_for_device_to_reconnect(ctx, serial_number_arg);
567580

568581
return EXIT_SUCCESS;
569582
}

unit-tests/test-fw-update.py

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,6 @@ def find_image_or_exit( product_name, fw_version_regex = r'(\d+\.){3}(\d+)' ):
173173
product_line = device.get_info( rs.camera_info.product_line )
174174
product_name = device.get_info( rs.camera_info.name )
175175
log.d( 'product line:', product_line )
176-
sn = device.get_info( rs.camera_info.serial_number )
177-
print("Device serial number = " + repr(sn))
178176
###############################################################################
179177
#
180178

@@ -186,7 +184,7 @@ def find_image_or_exit( product_name, fw_version_regex = r'(\d+\.){3}(\d+)' ):
186184
log.d( "recovering device ..." )
187185
try:
188186
image_file = find_image_or_exit(product_name) if not custom_fw_d400_path else custom_fw_d400_path
189-
cmd = [fw_updater_exe, '-r', '-f', image_file, '-s', sn]
187+
cmd = [fw_updater_exe, '-r', '-f', image_file]
190188
if custom_fw_d400_path:
191189
# unsiged fw
192190
cmd.insert(1, '-u')
@@ -232,7 +230,7 @@ def find_image_or_exit( product_name, fw_version_regex = r'(\d+\.){3}(\d+)' ):
232230
image_file = find_image_or_exit(product_name, fw_version_regex) if not custom_fw_d400_path else custom_fw_d400_path
233231
# finding file containing image for FW update
234232

235-
cmd = [fw_updater_exe, '-f', image_file, '-s', sn]
233+
cmd = [fw_updater_exe, '-f', image_file]
236234
if custom_fw_d400_path:
237235
# unsigned fw
238236
cmd.insert(1, '-u')
@@ -244,20 +242,6 @@ def find_image_or_exit( product_name, fw_version_regex = r'(\d+\.){3}(\d+)' ):
244242
time.sleep(3) # MIPI devices do not re-enumerate so we need to give them some time to restart
245243
devices.query( monitor_changes = False )
246244
sn_list = devices.all()
247-
sn_list_size = len(sn_list)
248-
if sn_list_size == 0:
249-
retries = 5
250-
while retries > 0 and sn_list_size == 0:
251-
retries -= 1
252-
time.sleep(2)
253-
devices.query( monitor_changes = False )
254-
sn_list = devices.all()
255-
sn_list_size = len(sn_list)
256-
if sn_list_size == 0:
257-
print("Device discovery... Device not found yet - remaining retries: " + repr(retries) )
258-
else:
259-
print("Device discovery... Device found.")
260-
261245
device = devices.get_first( sn_list ).handle
262246
current_fw_version = rsutils.version( device.get_info( rs.camera_info.firmware_version ))
263247
test.check_equal(current_fw_version, bundled_fw_version if not custom_fw_d400_path else custom_fw_d400_version)

0 commit comments

Comments
 (0)