Skip to content
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

rs-fw-update tool - handle D457 MIPI device #12054

Merged
merged 5 commits into from
Aug 14, 2023
Merged
Changes from 4 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
75 changes: 71 additions & 4 deletions tools/fw-update/rs-fw-update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ std::vector<uint8_t> read_fw_file(std::string file_path)
std::vector<uint8_t> rv;

std::ifstream file(file_path, std::ios::in | std::ios::binary | std::ios::ate);
auto file_deleter = std::unique_ptr< std::ifstream, void ( * )( std::ifstream * ) >( &file,
[]( std::ifstream * file )
{ file->close(); } );
OhadMeir marked this conversation as resolved.
Show resolved Hide resolved
if (file.is_open())
{
rv.resize(file.tellg());

file.seekg(0, std::ios::beg);
file.read((char*)rv.data(), rv.size());
file.close();
}

return rv;
Expand Down Expand Up @@ -119,7 +121,57 @@ void list_devices(rs2::context ctx)
}
}

int main(int argc, char** argv) try
int write_fw_to_mipi_device( const std::vector< uint8_t > & fw_image)
{
// Write firmware to appropriate file descritptor
std::cout << std::endl << "Update can take up to 2 minutes" << std::endl;
std::ofstream fw_path_in_device( "/dev/d4xx-dfu504", std::ios::binary );
OhadMeir marked this conversation as resolved.
Show resolved Hide resolved
auto file_deleter = std::unique_ptr< std::ofstream, void ( * )( std::ofstream * ) >( &fw_path_in_device,
[]( std::ofstream * file )
{ file->close(); } );
OhadMeir marked this conversation as resolved.
Show resolved Hide resolved
if( fw_path_in_device )
{
bool done = false;
std::thread show_progress_thread(
[&done]()
{
for( int i = 0; i < 101 && ! done; ++i ) // Show percentage [0-100]
{
OhadMeir marked this conversation as resolved.
Show resolved Hide resolved
printf( "%d%%\r", i );
std::cout.flush();
std::this_thread::sleep_for( std::chrono::seconds( 1 ) );
}
} );
fw_path_in_device.write( reinterpret_cast< const char * >( fw_image.data() ), fw_image.size() );
OhadMeir marked this conversation as resolved.
Show resolved Hide resolved
done = true;
show_progress_thread.join();
printf( " \r" ); // Delete progress, as it is not accurate, don't leave 85% when writing done
}
else
{
std::cout << std::endl << "Firmware Update failed - wrong path or permissions missing";
return EXIT_FAILURE;
}
std::cout << std::endl << "Firmware update done" << std::endl;

return EXIT_SUCCESS;
}

bool is_mipi_device( const rs2::device & dev )
{
std::string usb_type = "unknown";

if( dev.supports( RS2_CAMERA_INFO_USB_TYPE_DESCRIPTOR ) )
usb_type = dev.get_info( RS2_CAMERA_INFO_USB_TYPE_DESCRIPTOR );

bool d457_device = strcmp( dev.get_info( RS2_CAMERA_INFO_PRODUCT_ID ), "ABCD" ) == 0;

// Currently only D457 model has MIPI connection
return d457_device && usb_type.compare( "unknown" ) == 0;
}

int main( int argc, char ** argv )
try
{
#ifdef BUILD_EASYLOGGINGPP
rs2::log_to_console(RS2_LOG_SEVERITY_WARN);
Expand Down Expand Up @@ -301,7 +353,7 @@ int main(int argc, char** argv) try

if (d.supports(RS2_CAMERA_INFO_USB_TYPE_DESCRIPTOR))
{
std::string usb_type = d.get_info(RS2_CAMERA_INFO_USB_TYPE_DESCRIPTOR);
std::string usb_type = d.get_info( RS2_CAMERA_INFO_USB_TYPE_DESCRIPTOR );
if (usb_type.find("2.") != std::string::npos) {
std::cout << std::endl << "Warning! the camera is connected via USB 2 port, in case the process fails, connect the camera to a USB 3 port and try again" << std::endl;
}
Expand Down Expand Up @@ -331,7 +383,10 @@ int main(int argc, char** argv) try

auto temp = backup_arg.getValue();
std::ofstream file(temp.c_str(), std::ios::binary);
file.write((const char*)flash.data(), flash.size());
auto file_deleter = std::unique_ptr< std::ofstream, void ( * )( std::ofstream * ) >( &file,
[]( std::ofstream * file )
{ file->close(); } );
file.write( (const char *)flash.data(), flash.size() );
}

if (!file_arg.isSet())
Expand All @@ -342,6 +397,18 @@ int main(int argc, char** argv) try
std::cout << std::endl << "Updating device: " << std::endl;
print_device_info(d);

// If device is D457 connected by MIPI connector
if( is_mipi_device( d ) )
{
if( unsigned_arg.isSet() )
{
std::cout << std::endl << "Only signed FW is currently supported for MIPI devices" << std::endl;
return EXIT_FAILURE;
}

return write_fw_to_mipi_device( fw_image );
}

if (unsigned_arg.isSet())
{
std::cout << std::endl << "Firmware update started" << std::endl << std::endl;
Expand Down
Loading