Skip to content

giving time for the device to be discovered after burning fw #13961

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

Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion src/ds/d400/d400-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ namespace librealsense
{RS405_PID, "5.12.11.8" },
{RS455_PID, "5.13.0.50" },
{RS457_PID, "5.16.8.0" },
{RS400_MIPI_RECOVERY_PID, "5.16.8.0" },
{RS400_MIPI_RECOVERY_PID, "5.16.0.1" },
{RS430_GMSL_PID, "5.16.8.0" }
};

Expand Down
75 changes: 44 additions & 31 deletions tools/fw-update/rs-fw-update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@

using rsutils::json;

std::condition_variable cv;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason to move from main to global?
access from any place?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes - especially from the code that I have moved from main to private methods

std::mutex mutex;
std::string selected_serial_number;

rs2::device new_device;
rs2::update_device new_fw_update_device;

bool done = false;

std::vector<uint8_t> read_fw_file(std::string file_path)
{
Expand Down Expand Up @@ -139,7 +147,30 @@ void list_devices( rs2::context ctx )
}
}

int write_fw_to_mipi_device( const rs2::device & dev, const std::vector< uint8_t > & fw_image )

void waiting_for_device_to_reconnect(rs2::context& ctx, rs2::cli::value<std::string>& serial_number_arg)
{
std::cout << std::endl << "Waiting for device to reconnect..." << std::endl;
std::unique_lock<std::mutex> lk(mutex);
cv.wait_for(lk, std::chrono::seconds(WAIT_FOR_DEVICE_TIMEOUT), [&] { return !done || new_device; });

if (done)
{
auto devs = ctx.query_devices();
for (auto&& d : devs)
{
auto sn = d.supports(RS2_CAMERA_INFO_SERIAL_NUMBER) ? d.get_info(RS2_CAMERA_INFO_SERIAL_NUMBER) : "unknown";
if (serial_number_arg.isSet() && sn != selected_serial_number)
continue;

auto fw = d.supports(RS2_CAMERA_INFO_FIRMWARE_VERSION) ? d.get_info(RS2_CAMERA_INFO_FIRMWARE_VERSION) : "unknown";
std::cout << std::endl << "Device " << sn << " successfully updated to FW: " << fw << std::endl;
}
}

}

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 )
{
// Write firmware to appropriate file descriptor
std::cout << std::endl << "Update can take up to 2 minutes" << std::endl;
Expand Down Expand Up @@ -186,6 +217,10 @@ int write_fw_to_mipi_device( const rs2::device & dev, const std::vector< uint8_t
return EXIT_FAILURE;
}
std::cout << std::endl << "Firmware update done" << std::endl;

done = true;

waiting_for_device_to_reconnect(ctx, serial_number_arg);

return EXIT_SUCCESS;
}
Expand All @@ -205,15 +240,6 @@ bool is_mipi_device( const rs2::device & dev )
int main( int argc, char ** argv )
try
{
std::condition_variable cv;
std::mutex mutex;
std::string selected_serial_number;

rs2::device new_device;
rs2::update_device new_fw_update_device;

bool done = false;

using rs2::cli;
cli cmd( "librealsense rs-fw-update tool" );

Expand Down Expand Up @@ -477,25 +503,28 @@ try
// return EXIT_FAILURE;
// }

return write_fw_to_mipi_device( d, fw_image );
return write_fw_to_mipi_device(ctx, serial_number_arg, d, fw_image );
}

if( unsigned_arg.isSet() )
{
std::cout << std::endl << "Firmware update started. Please don't disconnect device!" << std::endl << std::endl;

std::cout << std::endl << "Unsigned Firmware update started. Please don't disconnect device!" << std::endl << std::endl;

if( ISATTY( FILENO( stdout ) ) )
{
d.as<rs2::updatable>().update_unsigned( fw_image, [&]( const float progress )
{
printf( "\rFirmware update progress: %d[%%]", (int)( progress * 100 ) );
printf( "\rUnsigned Firmware update progress: %d[%%]", (int)( progress * 100 ) );
std::cout.flush();
} );
}
else
d.as<rs2::updatable>().update_unsigned( fw_image, [&]( const float progress ) {} );

std::cout << std::endl << std::endl << "Firmware update done" << std::endl;
std::cout << std::endl << std::endl << "Unsigned Firmware update done" << std::endl;

done = true;
}
else
{
Expand Down Expand Up @@ -547,23 +576,7 @@ try
return EXIT_FAILURE;
}

std::cout << std::endl << "Waiting for device to reconnect..." << std::endl;
std::unique_lock<std::mutex> lk(mutex);
cv.wait_for(lk, std::chrono::seconds(WAIT_FOR_DEVICE_TIMEOUT), [&] { return !done || new_device; });

if (done)
{
auto devs = ctx.query_devices();
for (auto&& d : devs)
{
auto sn = d.supports(RS2_CAMERA_INFO_SERIAL_NUMBER) ? d.get_info(RS2_CAMERA_INFO_SERIAL_NUMBER) : "unknown";
if (serial_number_arg.isSet() && sn != selected_serial_number)
continue;

auto fw = d.supports(RS2_CAMERA_INFO_FIRMWARE_VERSION) ? d.get_info(RS2_CAMERA_INFO_FIRMWARE_VERSION) : "unknown";
std::cout << std::endl << "Device " << sn << " successfully updated to FW: " << fw << std::endl;
}
}
waiting_for_device_to_reconnect(ctx, serial_number_arg);

return EXIT_SUCCESS;
}
Expand Down
Loading