summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPali Rohár <pali.rohar@gmail.com>2012-08-10 14:56:38 +0200
committerPali Rohár <pali.rohar@gmail.com>2012-08-10 14:56:38 +0200
commit8eb58ad08c4cac4d0d572474792b18ed3acd3271 (patch)
tree17b34e715e8ae617d16ff2ce3f9d983988e974c0
parent32f2e5330400925d52531180ee72a8c2b2c468f8 (diff)
download0xFFFF-8eb58ad08c4cac4d0d572474792b18ed3acd3271.tar.bz2
Move checking for flashing protocol from main to cold-flash
-rw-r--r--src/cold-flash.c12
-rw-r--r--src/main2.c11
2 files changed, 16 insertions, 7 deletions
diff --git a/src/cold-flash.c b/src/cold-flash.c
index 6b14684..75f3b49 100644
--- a/src/cold-flash.c
+++ b/src/cold-flash.c
@@ -25,6 +25,8 @@
#include "cold-flash.h"
#include "image.h"
+#include "usb-device.h"
+#include "printf-utils.h"
#define READ_DEV 0x81
#define WRITE_DEV 0x01
@@ -307,6 +309,11 @@ static int ping_timeout(usb_dev_handle * udev) {
int cold_flash(struct usb_device_info * dev, struct image * x2nd, struct image * secondary) {
+ if ( dev->flash_device->protocol != FLASH_COLD ) {
+ printf_and_wait("Device is not in Cold Flash mode\nUnplug USB cable, turn device off, press ENTER and plug USB cable again");
+ return 1;
+ }
+
if ( x2nd->type != IMAGE_2ND ) {
fprintf(stderr, "Image type is not 2nd X-Loader\n");
return 1;
@@ -346,6 +353,11 @@ int leave_cold_flash(struct usb_device_info * dev) {
int ret;
+ if ( dev->flash_device->protocol != FLASH_COLD ) {
+ fprintf(stderr, "Device is not in Cold Flash mode\n");
+ return 1;
+ }
+
if ( ! read_asic(dev->udev) ) {
fprintf(stderr, "Reading ASIC ID failed\n");
return 1;
diff --git a/src/main2.c b/src/main2.c
index b18b1ee..0d11c1b 100644
--- a/src/main2.c
+++ b/src/main2.c
@@ -719,16 +719,13 @@ int main(int argc, char **argv) {
/* cold flash */
if ( dev_cold_flash ) {
- if ( usb_dev->flash_device->protocol != FLASH_COLD ) {
- usb_close_device(usb_dev);
- printf_and_wait("Unplug USB cable, turn device off, press ENTER and plug USB cable again");
- continue;
- }
-
- cold_flash(usb_dev, image_2nd, image_secondary);
+ ret = cold_flash(usb_dev, image_2nd, image_secondary);
usb_close_device(usb_dev);
usb_dev = NULL;
+ if ( ret != 0 )
+ continue;
+
if ( dev_flash ) {
dev_cold_flash = 0;
continue;