From b48cd9fea6a045341ca4264479bf66543545605b Mon Sep 17 00:00:00 2001 From: Boris Mittelberg Date: Tue, 9 Aug 2022 23:52:51 -0700 Subject: [PATCH] cros-ec: adding stay-in-ro command if EC is in bootloader --- plugins/cros-ec/fu-cros-ec-usb-device.c | 39 ++++++++++++++++--------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/plugins/cros-ec/fu-cros-ec-usb-device.c b/plugins/cros-ec/fu-cros-ec-usb-device.c index 249bb5a8d..fea2c6df4 100644 --- a/plugins/cros-ec/fu-cros-ec-usb-device.c +++ b/plugins/cros-ec/fu-cros-ec-usb-device.c @@ -764,6 +764,29 @@ fu_cros_ec_usb_device_jump_to_rw(FuDevice *device) return TRUE; } +static gboolean +fu_cros_ec_usb_device_stay_in_ro(FuDevice *device, GError **error) +{ + gsize response_size = 1; + guint8 response; + guint16 subcommand = UPDATE_EXTRA_CMD_STAY_IN_RO; + guint8 command_body[2]; /* Max command body size. */ + gsize command_body_size = 0; + + if (!fu_cros_ec_usb_device_send_subcommand(device, + subcommand, + command_body, + command_body_size, + &response, + &response_size, + FALSE, + error)) { + return FALSE; + } + + return TRUE; +} + static gboolean fu_cros_ec_usb_device_write_firmware(FuDevice *device, FuFirmware *firmware, @@ -778,22 +801,10 @@ fu_cros_ec_usb_device_write_firmware(FuDevice *device, fu_device_remove_private_flag(device, FU_CROS_EC_USB_DEVICE_FLAG_SPECIAL); if (fu_device_has_private_flag(device, FU_CROS_EC_USB_DEVICE_FLAG_REBOOTING_TO_RO)) { - gsize response_size = 1; - guint8 response; - guint16 subcommand = UPDATE_EXTRA_CMD_STAY_IN_RO; - guint8 command_body[2]; /* Max command body size. */ - gsize command_body_size = 0; START_RESP start_resp; fu_device_remove_private_flag(device, FU_CROS_EC_USB_DEVICE_FLAG_REBOOTING_TO_RO); - if (!fu_cros_ec_usb_device_send_subcommand(device, - subcommand, - command_body, - command_body_size, - &response, - &response_size, - FALSE, - error)) { + if (!fu_cros_ec_usb_device_stay_in_ro(device, error)) { g_prefix_error(error, "failed to send stay-in-ro subcommand: "); return FALSE; } @@ -960,6 +971,8 @@ fu_cros_ec_usb_device_detach(FuDevice *device, FuProgress *progress, GError **er return TRUE; if (self->in_bootloader) { + /* If EC just rebooted - prevent jumping to RW during the update */ + fu_device_add_private_flag(device, FU_CROS_EC_USB_DEVICE_FLAG_REBOOTING_TO_RO); g_debug("skipping immediate reboot in case of already in bootloader"); /* in RO so skip reboot */ return TRUE;