fw-update-factory.cpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2019 Intel Corporation. All Rights Reserved.
3 
4 #include "fw-update-factory.h"
5 #include "fw-update-device.h"
6 #include "usb/usb-enumerator.h"
7 #include "ds5/ds5-private.h"
9 #include "ivcam/sr300.h"
11 #include "l500/l500-private.h"
13 
14 #define FW_UPDATE_INTERFACE_NUMBER 0
15 #define DEFAULT_TIMEOUT 100
16 
17 namespace librealsense
18 {
19  bool is_l500_recovery(platform::rs_usb_device usb, bool &is_l500_device)
20  {
21  dfu_fw_status_payload payload;
22 
23  auto messenger = usb->open(FW_UPDATE_INTERFACE_NUMBER);
24  if (!messenger)
25  {
26  LOG_ERROR("Unable to open USB device: " << usb->get_info().id);
27  return false;
28  }
29 
30  // Step 1 - Detach device - mandatory before communicating with the DFU
31  {
32  auto timeout = 1000;
33  uint32_t transferred = 0;
34  auto res = messenger->control_transfer(0x21, RS2_DFU_DETACH, timeout, 0, NULL, 0, transferred, timeout);
36  LOG_WARNING("DFU - failed to detach device: " << platform::usb_status_to_string.at(res));
37  }
38 
39  // Step 2 - Verify device entered DFU idle state and ready to communicate with the host
40  {
42  uint32_t transferred = 0;
43  auto res = messenger->control_transfer(0xa1, RS2_DFU_GET_STATE, 0, 0, &state, 1, transferred, DEFAULT_TIMEOUT);
45  {
46  LOG_ERROR("Failed to get DFU device state! status is : " << platform::usb_status_to_string.at(res) << ", device ID is : " << usb->get_info().id);
47  return false;
48  }
49 
50  if (state != RS2_DFU_STATE_DFU_IDLE)
51  {
52  LOG_ERROR("DFU is not on detach state! state is : " << state << ", device ID is : " << usb->get_info().id);
53  return false;
54  }
55  }
56  // Step 3 - Query DFU information
57  {
58  uint32_t transferred = 0;
59  auto sts = messenger->control_transfer(0xa1, RS2_DFU_UPLOAD, 0, 0, reinterpret_cast<uint8_t*>(&payload), sizeof(payload), transferred, DEFAULT_TIMEOUT);
61  {
62  LOG_ERROR("Failed to read info from DFU device! , status is :" << platform::usb_status_to_string.at(sts));
63  return false;
64  }
65  }
66 
68  return true;
69  }
70 
72  {
73  if( SR300_RECOVERY == usb_info.pid && platform::RS2_USB_CLASS_VENDOR_SPECIFIC == usb_info.cls )
75  if( ds::RS_RECOVERY_PID == usb_info.pid )
76  return RS2_PRODUCT_LINE_D400;
77  if( L500_RECOVERY_PID == usb_info.pid || L535_RECOVERY_PID == usb_info.pid)
78  return RS2_PRODUCT_LINE_L500;
79  if( ds::RS_USB2_RECOVERY_PID == usb_info.pid || L500_USB2_RECOVERY_PID_OLD == usb_info.pid )
80  {
81  bool is_l500 = false;
82  {
84  if (usb)
85  {
86  // This function is a SW patch that overcome a problem found on FW of old L515 devices.
87  // The L515 units declare DS-5 PID while on DFU and connected as USB2
88  // Using the DFU version we identify L515 VS DS-5 devices.
89  // This issue is fixed on newer unit
90  if (!is_l500_recovery(usb, is_l500))
91  return 0;
92  }
93  }
94 
95  if (is_l500)
96  return RS2_PRODUCT_LINE_L500;
97  else
98  return RS2_PRODUCT_LINE_D400;
99  }
100  return 0;
101  }
102 
103 
104  std::vector<std::shared_ptr<device_info>> fw_update_info::pick_recovery_devices(
105  std::shared_ptr<context> ctx,
106  const std::vector<platform::usb_device_info>& usb_devices, int mask)
107  {
108  std::vector<std::shared_ptr<device_info>> list;
109  for (auto&& usb : usb_devices)
110  {
111  auto pl = get_product_line(usb);
112  if(pl & mask)
113  list.push_back(std::make_shared<fw_update_info>(ctx, usb));
114  }
115  return list;
116  }
117 
118 
119  std::shared_ptr<device_interface> fw_update_info::create(std::shared_ptr<context> ctx, bool register_device_notifications) const
120  {
122  for (auto&& info : devices)
123  {
124  if (info.id == _dfu.id)
125  {
127  if (!usb)
128  continue;
129  if (ds::RS_RECOVERY_PID == info.pid)
130  return std::make_shared<ds_update_device>(ctx, register_device_notifications, usb);
131  if (SR300_RECOVERY == info.pid)
132  return std::make_shared<sr300_update_device>(ctx, register_device_notifications, usb);
133  if (L500_RECOVERY_PID == info.pid || L535_RECOVERY_PID == info.pid)
134  return std::make_shared<l500_update_device>(ctx, register_device_notifications, usb);
136  {
137  bool dev_is_l500 = false;
138  if (is_l500_recovery(usb, dev_is_l500))
139  {
140  if (dev_is_l500)
141  return std::make_shared<l500_update_device>(ctx, register_device_notifications, usb);
142  else
143  return std::make_shared<ds_update_device>(ctx, register_device_notifications, usb);
144  }
145  }
146  }
147  }
148  throw std::runtime_error(to_string() << "Failed to create FW update device, device id: " << _dfu.id);
149  }
150 }
static rs_usb_device create_usb_device(const usb_device_info &info)
const uint16_t RS_RECOVERY_PID
Definition: ds5-private.h:31
const uint16_t SR300_RECOVERY
#define FW_UPDATE_INTERFACE_NUMBER
static std::vector< usb_device_info > query_devices_info()
#define LOG_WARNING(...)
Definition: src/types.h:241
GLint GLuint mask
unsigned char uint8_t
Definition: stdint.h:78
std::shared_ptr< device_interface > create(std::shared_ptr< context > ctx, bool register_device_notifications) const override
static std::map< usb_status, std::string > usb_status_to_string
Definition: usb-types.h:162
def info(name, value, persistent=False)
Definition: test.py:301
bool is_l500_recovery(platform::rs_usb_device usb, bool &is_l500_device)
unsigned int uint32_t
Definition: stdint.h:80
#define RS2_PRODUCT_LINE_D400
Definition: rs_context.h:94
devices
Definition: test-fg.py:9
const uint16_t L535_RECOVERY_PID
Definition: l500-private.h:18
const uint16_t RS_USB2_RECOVERY_PID
Definition: ds5-private.h:32
#define RS2_PRODUCT_LINE_L500
Definition: rs_context.h:96
#define LOG_ERROR(...)
Definition: src/types.h:242
#define DEFAULT_TIMEOUT
platform::usb_device_info _dfu
const uint16_t L500_USB2_RECOVERY_PID_OLD
Definition: l500-private.h:19
static std::vector< std::shared_ptr< device_info > > pick_recovery_devices(std::shared_ptr< context > ctx, const std::vector< platform::usb_device_info > &usb_devices, int mask)
GLbitfield GLuint64 timeout
int get_product_line(const platform::usb_device_info &usb_info)
#define NULL
Definition: tinycthread.c:47
GLuint res
Definition: glext.h:8856
const uint16_t L500_RECOVERY_PID
Definition: l500-private.h:17
#define RS2_PRODUCT_LINE_SR300
Definition: rs_context.h:95
std::shared_ptr< usb_device > rs_usb_device
Definition: usb-device.h:29
std::string to_string(T value)


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:15