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

Fix sr3xx firmware image size and recovery checks #8876

Merged
merged 2 commits into from
May 13, 2021
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: 2 additions & 0 deletions include/librealsense2/h/rs_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ extern "C" {
* Firmware size constants
*/
const int signed_fw_size = 0x18031C;
const int signed_sr300_size = 0x0C025C;
const int unsigned_fw_size = 0x200000;
const int unsigned_sr300_size = 0x100000;

/**
* librealsense Recorder is intended for effective unit-testing
Expand Down
2 changes: 1 addition & 1 deletion src/fw-update/fw-update-factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ namespace librealsense

int get_product_line(const platform::usb_device_info &usb_info)
{
if( SR300_RECOVERY == usb_info.pid && platform::RS2_USB_CLASS_VENDOR_SPECIFIC == usb_info.cls )
if( SR300_RECOVERY == usb_info.pid )
return RS2_PRODUCT_LINE_SR300;
if( ds::RS_RECOVERY_PID == usb_info.pid )
return RS2_PRODUCT_LINE_D400;
Expand Down
21 changes: 16 additions & 5 deletions src/rs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2918,7 +2918,9 @@ void rs2_update_firmware_cpp(const rs2_device* device, const void* fw_image, int
{
VALIDATE_NOT_NULL(device);
VALIDATE_NOT_NULL(fw_image);
VALIDATE_FIXED_SIZE(fw_image_size, signed_fw_size); // check if the given FW size matches the expected FW size
// check if the given FW size matches the expected FW size
if (!val_in_range(fw_image_size, { signed_fw_size, signed_sr300_size }))
throw librealsense::invalid_value_exception(to_string() << "Unsupported firmware binary image provided - " << fw_image_size << " bytes");

auto fwu = VALIDATE_INTERFACE(device->device, librealsense::update_device_interface);

Expand All @@ -2933,7 +2935,9 @@ void rs2_update_firmware(const rs2_device* device, const void* fw_image, int fw_
{
VALIDATE_NOT_NULL(device);
VALIDATE_NOT_NULL(fw_image);
VALIDATE_FIXED_SIZE(fw_image_size, signed_fw_size); // check if the given FW size matches the expected FW size
// check if the given FW size matches the expected FW size
if (!val_in_range(fw_image_size, { signed_fw_size, signed_sr300_size }))
throw librealsense::invalid_value_exception(to_string() << "Unsupported firmware binary image provided - " << fw_image_size << " bytes");

if (fw_image_size <= 0)
throw std::runtime_error("invlid firmware image size provided to rs2_update");
Expand Down Expand Up @@ -2997,7 +3001,12 @@ void rs2_update_firmware_unsigned_cpp(const rs2_device* device, const void* imag
{
VALIDATE_NOT_NULL(device);
VALIDATE_NOT_NULL(image);
VALIDATE_FIXED_SIZE(image_size, unsigned_fw_size); // check if the given FW size matches the expected FW size
// check if the given FW size matches the expected FW size
if (!val_in_range(image_size, { unsigned_fw_size, unsigned_sr300_size }))
throw librealsense::invalid_value_exception(to_string() << "Unsupported firmware binary image (unsigned) provided - " << image_size << " bytes");

if (image_size <= 0)
throw std::runtime_error("invalid firmware image size provided to rs2_update_firmware_unsigned");

auto fwud = std::dynamic_pointer_cast<updatable>(device->device);
if (!fwud)
Expand All @@ -3016,10 +3025,12 @@ void rs2_update_firmware_unsigned(const rs2_device* device, const void* image, i
{
VALIDATE_NOT_NULL(device);
VALIDATE_NOT_NULL(image);
VALIDATE_FIXED_SIZE(image_size, unsigned_fw_size); // check if the given FW size matches the expected FW size
// check if the given FW size matches the expected FW size
if (!val_in_range(image_size, { unsigned_fw_size, unsigned_sr300_size }))
throw librealsense::invalid_value_exception(to_string() << "Unsupported firmware binary image (unsigned) provided - " << image_size << " bytes");

if (image_size <= 0)
throw std::runtime_error("invlid firmware image size provided to rs2_update_firmware_unsigned");
throw std::runtime_error("invalid firmware image size provided to rs2_update_firmware_unsigned");

auto fwud = std::dynamic_pointer_cast<updatable>(device->device);
if (!fwud)
Expand Down