summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPali Rohár <pali.rohar@gmail.com>2016-03-12 12:47:41 +0100
committerPali Rohár <pali.rohar@gmail.com>2016-03-12 12:47:41 +0100
commitd2e7b3d2425c9202d10a7659ed8b5d4398b03ace (patch)
tree74e58e9115d0f020d9029795826977148ce01445
parent54805eb0409bb9fda8cef33b9a5ae513d430999b (diff)
download0xFFFF-d2e7b3d2425c9202d10a7659ed8b5d4398b03ace.tar.bz2
mkii: Implement rebooting to Update mode
-rw-r--r--src/mkii.c18
-rw-r--r--src/mkii.h2
-rw-r--r--src/operations.c4
-rw-r--r--src/usb-device.c8
4 files changed, 22 insertions, 10 deletions
diff --git a/src/mkii.c b/src/mkii.c
index aa02432..7b36e43 100644
--- a/src/mkii.c
+++ b/src/mkii.c
@@ -340,18 +340,28 @@ int mkii_flash_image(struct usb_device_info * dev, struct image * image) {
}
-int mkii_reboot_device(struct usb_device_info * dev) {
+int mkii_reboot_device(struct usb_device_info * dev, int update) {
char buf[2048];
struct mkii_message * msg;
+ const char * str;
+ int len;
int ret;
msg = (struct mkii_message *)buf;
- printf("Rebooting device...\n");
+ if ( update ) {
+ printf("Rebooting device to Update mode...\n");
+ len = sizeof("reboot=update");
+ str = "reboot=update";
+ } else {
+ printf("Rebooting device...\n");
+ len = sizeof("reboot");
+ str = "reboot";
+ }
- memcpy(msg->data, "reboot", sizeof("reboot"));
- ret = mkii_send_receive(dev->udev, MKII_REBOOT, msg, sizeof("reboot"), msg, sizeof(buf));
+ memcpy(msg->data, str, len);
+ ret = mkii_send_receive(dev->udev, MKII_REBOOT, msg, len, msg, sizeof(buf));
if ( ret != 1 || msg->data[0] != 0 )
return -1;
diff --git a/src/mkii.h b/src/mkii.h
index 11fbd2a..c15c61b 100644
--- a/src/mkii.h
+++ b/src/mkii.h
@@ -31,7 +31,7 @@ int mkii_init(struct usb_device_info * dev);
enum device mkii_get_device(struct usb_device_info * dev);
int mkii_flash_image(struct usb_device_info * dev, struct image * image);
-int mkii_reboot_device(struct usb_device_info * dev);
+int mkii_reboot_device(struct usb_device_info * dev, int update);
int mkii_get_root_device(struct usb_device_info * dev);
int mkii_set_root_device(struct usb_device_info * dev, int device);
diff --git a/src/operations.c b/src/operations.c
index 8773b95..1fd4766 100644
--- a/src/operations.c
+++ b/src/operations.c
@@ -243,6 +243,8 @@ int dev_boot_device(struct device_info * dev, const char * cmdline) {
if ( protocol == FLASH_NOLO )
return nolo_boot_device(dev->usb, cmdline);
+ else if ( protocol == FLASH_MKII && strcmp(cmdline, "update") == 0 )
+ return mkii_reboot_device(dev->usb, 1);
usb_switch_to_nolo(dev->usb);
return -EAGAIN;
@@ -267,7 +269,7 @@ int dev_reboot_device(struct device_info * dev) {
else if ( protocol == FLASH_NOLO )
return nolo_reboot_device(dev->usb);
else if ( protocol == FLASH_MKII )
- return mkii_reboot_device(dev->usb);
+ return mkii_reboot_device(dev->usb, 0);
else {
usb_switch_to_nolo(dev->usb);
return -EAGAIN;
diff --git a/src/usb-device.c b/src/usb-device.c
index 895e56f..670eb9e 100644
--- a/src/usb-device.c
+++ b/src/usb-device.c
@@ -350,7 +350,7 @@ void usb_switch_to_nolo(struct usb_device_info * dev) {
if ( dev->flash_device->protocol == FLASH_COLD )
leave_cold_flash(dev);
else if ( dev->flash_device->protocol == FLASH_MKII )
- mkii_reboot_device(dev);
+ mkii_reboot_device(dev, 0);
else if ( dev->flash_device->protocol == FLASH_DISK )
printf_and_wait("Unplug USB cable, turn device off, press ENTER and plug USB cable again");
@@ -363,7 +363,7 @@ void usb_switch_to_cold(struct usb_device_info * dev) {
if ( dev->flash_device->protocol == FLASH_NOLO )
nolo_reboot_device(dev);
else if ( dev->flash_device->protocol == FLASH_MKII )
- mkii_reboot_device(dev);
+ mkii_reboot_device(dev, 0);
else if ( dev->flash_device->protocol == FLASH_DISK )
printf_and_wait("Unplug USB cable, turn device off, press ENTER and plug USB cable again");
@@ -378,7 +378,7 @@ void usb_switch_to_update(struct usb_device_info * dev) {
else if ( dev->flash_device->protocol == FLASH_NOLO )
nolo_boot_device(dev, "update");
else if ( dev->flash_device->protocol == FLASH_MKII && ! ( dev->data & MKII_UPDATE_MODE ) )
- mkii_reboot_device(dev);
+ mkii_reboot_device(dev, 1);
else if ( dev->flash_device->protocol == FLASH_DISK )
printf_and_wait("Unplug USB cable, turn device off, press ENTER and plug USB cable again");
@@ -395,7 +395,7 @@ void usb_switch_to_disk(struct usb_device_info * dev) {
printf_and_wait("Wait until device start, choose USB Mass Storage Mode and press ENTER");
} else if ( dev->flash_device->protocol == FLASH_MKII ) {
if ( dev->data & MKII_UPDATE_MODE )
- mkii_reboot_device(dev);
+ mkii_reboot_device(dev, 0);
else
printf_and_wait("Unplug USB cable, plug again, choose USB Mass Storage Mode and press ENTER");
}