mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-22 15:43:33 +08:00
PX4 IO: Retry upgrades of IO
This adds robustness to system timing and bad link.
This commit is contained in:
+48
-33
@@ -2960,7 +2960,7 @@ PX4IO::ioctl(file *filep, int cmd, unsigned long arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* reboot into bootloader - arg must be PX4IO_REBOOT_BL_MAGIC */
|
/* reboot into bootloader - arg must be PX4IO_REBOOT_BL_MAGIC */
|
||||||
usleep(1);
|
usleep(50);
|
||||||
io_reg_set(PX4IO_PAGE_SETUP, PX4IO_P_SETUP_REBOOT_BL, arg);
|
io_reg_set(PX4IO_PAGE_SETUP, PX4IO_P_SETUP_REBOOT_BL, arg);
|
||||||
// we don't expect a reply from this operation
|
// we don't expect a reply from this operation
|
||||||
ret = OK;
|
ret = OK;
|
||||||
@@ -3451,45 +3451,60 @@ px4io_main(int argc, char *argv[])
|
|||||||
the user to hold the safety switch down
|
the user to hold the safety switch down
|
||||||
*/
|
*/
|
||||||
if (argc <= 3) {
|
if (argc <= 3) {
|
||||||
warnx("usage: px4io forceupdate MAGIC filename");
|
PX4_WARN("usage: px4io forceupdate MAGIC filename");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_dev == nullptr) {
|
|
||||||
warnx("px4io is not started, still attempting upgrade");
|
|
||||||
|
|
||||||
/* allocate the interface */
|
|
||||||
device::Device *interface = get_interface();
|
|
||||||
|
|
||||||
/* create the driver - it will set g_dev */
|
|
||||||
(void)new PX4IO(interface);
|
|
||||||
|
|
||||||
if (g_dev == nullptr) {
|
|
||||||
delete interface;
|
|
||||||
errx(1, "driver allocation failed");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t arg = atol(argv[2]);
|
uint16_t arg = atol(argv[2]);
|
||||||
int ret = g_dev->ioctl(nullptr, PX4IO_REBOOT_BOOTLOADER, arg);
|
constexpr unsigned MAX_RETRIES = 5;
|
||||||
|
unsigned retries = 0;
|
||||||
|
int ret = PX4_ERROR;
|
||||||
|
|
||||||
if (ret != OK) {
|
while (ret != OK && retries < MAX_RETRIES) {
|
||||||
warnx("reboot failed - %d", ret);
|
|
||||||
exit(1);
|
retries++;
|
||||||
|
// Sleep 200 ms before the next attempt
|
||||||
|
usleep(200 * 1000);
|
||||||
|
|
||||||
|
if (g_dev == nullptr) {
|
||||||
|
/* allocate the interface */
|
||||||
|
device::Device *interface = get_interface();
|
||||||
|
|
||||||
|
/* create the driver - it will set g_dev */
|
||||||
|
(void)new PX4IO(interface);
|
||||||
|
|
||||||
|
if (g_dev == nullptr) {
|
||||||
|
delete interface;
|
||||||
|
errx(1, "driver allocation failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to reboot
|
||||||
|
ret = g_dev->ioctl(nullptr, PX4IO_REBOOT_BOOTLOADER, arg);
|
||||||
|
|
||||||
|
if (ret != OK) {
|
||||||
|
PX4_WARN("reboot failed - %d", ret);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// tear down the px4io instance
|
||||||
|
delete g_dev;
|
||||||
|
g_dev = nullptr;
|
||||||
|
|
||||||
|
// upload the specified firmware
|
||||||
|
const char *fn[2];
|
||||||
|
fn[0] = argv[3];
|
||||||
|
fn[1] = nullptr;
|
||||||
|
PX4IO_Uploader *up = new PX4IO_Uploader;
|
||||||
|
|
||||||
|
// Upload and retry if it fails
|
||||||
|
ret = up->upload(&fn[0]);
|
||||||
|
delete up;
|
||||||
}
|
}
|
||||||
|
|
||||||
// tear down the px4io instance
|
PX4_INFO("IO update: %s, retries: %d (reboot)", (ret == OK) ? "done" : "failed", retries);
|
||||||
delete g_dev;
|
|
||||||
g_dev = nullptr;
|
|
||||||
|
|
||||||
// upload the specified firmware
|
exit(ret);
|
||||||
const char *fn[2];
|
|
||||||
fn[0] = argv[3];
|
|
||||||
fn[1] = nullptr;
|
|
||||||
PX4IO_Uploader *up = new PX4IO_Uploader;
|
|
||||||
up->upload(&fn[0]);
|
|
||||||
delete up;
|
|
||||||
exit(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* commands below here require a started driver */
|
/* commands below here require a started driver */
|
||||||
@@ -3671,6 +3686,6 @@ px4io_main(int argc, char *argv[])
|
|||||||
out:
|
out:
|
||||||
errx(1, "need a command, try 'start', 'stop', 'status', 'monitor', 'debug <level>',\n"
|
errx(1, "need a command, try 'start', 'stop', 'status', 'monitor', 'debug <level>',\n"
|
||||||
"'recovery', 'bind', 'checkcrc', 'safety_on', 'safety_off',\n"
|
"'recovery', 'bind', 'checkcrc', 'safety_on', 'safety_off',\n"
|
||||||
"'forceupdate', 'update', 'sbus1_out', 'sbus2_out', 'rssi_analog' or 'rssi_pwm',\n"
|
"'forceupdate 14662', 'sbus1_out', 'sbus2_out', 'rssi_analog' or 'rssi_pwm',\n"
|
||||||
"'test_fmu_fail', 'test_fmu_ok'");
|
"'test_fmu_fail', 'test_fmu_ok'");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user