Skip to content

Commit 684cf10

Browse files
authored
PR #13961 from remibettan: giving time for the device to be discovered after burning fw
2 parents 2b9f875 + da6881b commit 684cf10

File tree

2 files changed

+45
-32
lines changed

2 files changed

+45
-32
lines changed

src/ds/d400/d400-private.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ namespace librealsense
166166
{RS405_PID, "5.12.11.8" },
167167
{RS455_PID, "5.13.0.50" },
168168
{RS457_PID, "5.16.8.0" },
169-
{RS400_MIPI_RECOVERY_PID, "5.16.8.0" },
169+
{RS400_MIPI_RECOVERY_PID, "5.16.0.1" },
170170
{RS430_GMSL_PID, "5.16.8.0" }
171171
};
172172

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
}

0 commit comments

Comments
 (0)