Fix NOLO communication
This commit is contained in:
1 parent
dc8844f112
commit
a1d95afbf7
4 files changed
+67
-26
No files matched your search
+50
-3
@@ -36,6 +36,7 @@
|
|||||||
#include "cold-flash.h"
|
#include "cold-flash.h"
|
||||||
#include "console.h"
|
#include "console.h"
|
||||||
#include "qmode.h"
|
#include "qmode.h"
|
||||||
|
#include "nolo.h"
|
||||||
|
|
||||||
#undef VERSION
|
#undef VERSION
|
||||||
#define VERSION "0.6"
|
#define VERSION "0.6"
|
||||||
@@ -330,10 +331,14 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
struct usb_device_info * usb_dev = NULL;
|
struct usb_device_info * usb_dev = NULL;
|
||||||
|
|
||||||
|
char hwrev[20];
|
||||||
|
char buf[512];
|
||||||
|
|
||||||
simulate = 0;
|
simulate = 0;
|
||||||
noverify = 0;
|
noverify = 0;
|
||||||
verbose = 0;
|
verbose = 0;
|
||||||
|
|
||||||
|
memset(hwrev, 0, sizeof(hwrev));
|
||||||
show_title();
|
show_title();
|
||||||
|
|
||||||
while ( ( c = getopt(argc, argv, optstring) ) != -1 ) {
|
while ( ( c = getopt(argc, argv, optstring) ) != -1 ) {
|
||||||
@@ -714,7 +719,7 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
if ( dev_boot || dev_reboot || dev_load || dev_flash || dev_cold_flash || dev_ident || set_root || set_usb || set_rd || set_rd_flags || set_hw || set_kernel || set_nolo || set_sw || set_emmc ) {
|
if ( dev_boot || dev_reboot || dev_load || dev_flash || dev_cold_flash || dev_ident || set_root || set_usb || set_rd || set_rd_flags || set_hw || set_kernel || set_nolo || set_sw || set_emmc ) {
|
||||||
|
|
||||||
while ( image_first ) {
|
do {
|
||||||
|
|
||||||
usb_dev = usb_open_and_wait_for_device();
|
usb_dev = usb_open_and_wait_for_device();
|
||||||
|
|
||||||
@@ -738,20 +743,62 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* device identify */
|
/* device identify */
|
||||||
// while(get_status());
|
if ( nolo_init(usb_dev) < 0 ) {
|
||||||
|
printf("Cannot initialize NOLO\n");
|
||||||
|
usb_close_device(usb_dev);
|
||||||
|
usb_dev = NULL;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
usb_dev->detected_device = nolo_get_device(usb_dev);
|
||||||
|
if ( ! usb_dev->detected_device ) {
|
||||||
|
printf("Cannot detect device\n");
|
||||||
|
usb_close_device(usb_dev);
|
||||||
|
usb_dev = NULL;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Device: %s\n", device_to_string(usb_dev->detected_device));
|
||||||
|
|
||||||
|
if ( nolo_get_hwrev(usb_dev, hwrev, sizeof(hwrev)) < 0 ) {
|
||||||
|
printf("Cannot detect HW revision\n");
|
||||||
|
usb_close_device(usb_dev);
|
||||||
|
usb_dev = NULL;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("HW revision: %s\n", hwrev);
|
||||||
|
|
||||||
|
buf[0] = 0;
|
||||||
|
nolo_get_sw_ver(usb_dev, buf, sizeof(buf));
|
||||||
|
printf("Software release version: %s\n", buf[0] ? buf : "(not detected)");
|
||||||
|
|
||||||
/* flash */
|
/* flash */
|
||||||
|
// if ( image_first )
|
||||||
|
|
||||||
/* configuration */
|
/* configuration */
|
||||||
|
|
||||||
/* load */
|
/* load */
|
||||||
|
// if ( image_first )
|
||||||
|
|
||||||
/* boot */
|
/* boot */
|
||||||
|
if ( dev_boot ) {
|
||||||
|
nolo_boot(usb_dev, dev_boot_arg);
|
||||||
|
usb_close_device(usb_dev);
|
||||||
|
usb_dev = NULL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
/* reboot */
|
/* reboot */
|
||||||
|
if ( dev_reboot ) {
|
||||||
|
nolo_reboot_device(usb_dev);
|
||||||
|
usb_close_device(usb_dev);
|
||||||
|
usb_dev = NULL;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} while ( dev_cold_flash || dev_flash );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+15
-22
@@ -52,6 +52,7 @@ int nolo_init(struct usb_device_info * dev) {
|
|||||||
|
|
||||||
uint32_t val = 1;
|
uint32_t val = 1;
|
||||||
|
|
||||||
|
printf("Initializing NOLO...\n");
|
||||||
while ( val != 0 )
|
while ( val != 0 )
|
||||||
if ( usb_control_msg(dev->udev, NOLO_QUERY, NOLO_STATUS, 0, 0, (char *)&val, 4, 2000) == -1 )
|
if ( usb_control_msg(dev->udev, NOLO_QUERY, NOLO_STATUS, 0, 0, (char *)&val, 4, 2000) == -1 )
|
||||||
ERROR_RETURN("NOLO_STATUS failed", -1);
|
ERROR_RETURN("NOLO_STATUS failed", -1);
|
||||||
@@ -71,7 +72,7 @@ int nolo_identify_string(struct usb_device_info * dev, const char * str, char *
|
|||||||
if ( ret < 0 )
|
if ( ret < 0 )
|
||||||
ERROR_RETURN("NOLO_IDENTIFY failed", -1);
|
ERROR_RETURN("NOLO_IDENTIFY failed", -1);
|
||||||
|
|
||||||
ptr = strstr(buf, str);
|
ptr = memmem(buf, ret, str, strlen(str));
|
||||||
if ( ! ptr )
|
if ( ! ptr )
|
||||||
ERROR_RETURN("Substring was not found", -1);
|
ERROR_RETURN("Substring was not found", -1);
|
||||||
|
|
||||||
@@ -85,7 +86,7 @@ int nolo_identify_string(struct usb_device_info * dev, const char * str, char *
|
|||||||
|
|
||||||
strncpy(out, ptr, size-1);
|
strncpy(out, ptr, size-1);
|
||||||
out[size-1] = 0;
|
out[size-1] = 0;
|
||||||
return 0;
|
return strlen(out);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,29 +108,19 @@ int nolo_flash_image(struct usb_device_info * dev, struct image * image) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int nolo_boot(struct usb_device_info * dev, const char * cmdline) {
|
int nolo_boot(struct usb_device_info * dev, char * cmdline) {
|
||||||
|
|
||||||
char * buf;
|
int size = 0;
|
||||||
int ret;
|
|
||||||
|
|
||||||
if ( cmdline )
|
if ( cmdline && cmdline[0] ) {
|
||||||
buf = strdup(cmdline);
|
printf("Booting kernel with cmdline: '%s'...\n", cmdline);
|
||||||
else
|
size = strlen(cmdline)+1;
|
||||||
buf = calloc(1, 1);
|
} else {
|
||||||
|
printf("Booting kernel with default cmdline...\n");
|
||||||
|
cmdline = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if ( ! buf )
|
if ( usb_control_msg(dev->udev, NOLO_WRITE, NOLO_BOOT, 0, 0, cmdline, size, 2000) < 0 )
|
||||||
ALLOC_ERROR_RETURN(-1);
|
|
||||||
|
|
||||||
if ( buf[0] )
|
|
||||||
printf("Booting kernel with cmdline: %s\n", buf);
|
|
||||||
else
|
|
||||||
printf("Booting kernel with default cmdline\n");
|
|
||||||
|
|
||||||
ret = usb_control_msg(dev->udev, NOLO_WRITE, NOLO_BOOT, 0, 0, buf, strlen(buf)+1, 2000);
|
|
||||||
|
|
||||||
free(buf);
|
|
||||||
|
|
||||||
if ( ret < 0 )
|
|
||||||
ERROR_RETURN("NOLO_BOOT failed", -1);
|
ERROR_RETURN("NOLO_BOOT failed", -1);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -142,6 +133,7 @@ int nolo_boot_to_update_mode(struct usb_device_info * dev) {
|
|||||||
|
|
||||||
int nolo_reboot_device(struct usb_device_info * dev) {
|
int nolo_reboot_device(struct usb_device_info * dev) {
|
||||||
|
|
||||||
|
printf("Rebooting device...\n");
|
||||||
if ( usb_control_msg(dev->udev, NOLO_WRITE, NOLO_REBOOT, 0, 0, NULL, 0, 2000) < 0 )
|
if ( usb_control_msg(dev->udev, NOLO_WRITE, NOLO_REBOOT, 0, 0, NULL, 0, 2000) < 0 )
|
||||||
ERROR_RETURN("NOLO_REBOOT failed", -1);
|
ERROR_RETURN("NOLO_REBOOT failed", -1);
|
||||||
return 0;
|
return 0;
|
||||||
@@ -159,6 +151,7 @@ int nolo_get_root_device(struct usb_device_info * dev) {
|
|||||||
|
|
||||||
int nolo_set_root_device(struct usb_device_info * dev, int device) {
|
int nolo_set_root_device(struct usb_device_info * dev, int device) {
|
||||||
|
|
||||||
|
printf("Setting root device to %d\n", device);
|
||||||
if ( usb_control_msg(dev->udev, NOLO_WRITE, NOLO_SET, device, NOLO_ROOT_DEVICE, NULL, 0, 2000) < 0 )
|
if ( usb_control_msg(dev->udev, NOLO_WRITE, NOLO_SET, device, NOLO_ROOT_DEVICE, NULL, 0, 2000) < 0 )
|
||||||
ERROR_RETURN("Cannot set root device", -1);
|
ERROR_RETURN("Cannot set root device", -1);
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
+1
-1
@@ -29,7 +29,7 @@ enum device nolo_get_device(struct usb_device_info * dev);
|
|||||||
|
|
||||||
int nolo_load_image(struct usb_device_info * dev, struct image * image);
|
int nolo_load_image(struct usb_device_info * dev, struct image * image);
|
||||||
int nolo_flash_image(struct usb_device_info * dev, struct image * image);
|
int nolo_flash_image(struct usb_device_info * dev, struct image * image);
|
||||||
int nolo_boot(struct usb_device_info * dev, const char * cmdline);
|
int nolo_boot(struct usb_device_info * dev, char * cmdline);
|
||||||
int nolo_boot_to_update_mode(struct usb_device_info * dev);
|
int nolo_boot_to_update_mode(struct usb_device_info * dev);
|
||||||
int nolo_reboot_device(struct usb_device_info * dev);
|
int nolo_reboot_device(struct usb_device_info * dev);
|
||||||
|
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ static struct usb_device_info * usb_device_is_valid(struct usb_device * dev) {
|
|||||||
|
|
||||||
if ( dev->descriptor.idVendor == usb_devices[i].vendor && dev->descriptor.idProduct == usb_devices[i].product ) {
|
if ( dev->descriptor.idVendor == usb_devices[i].vendor && dev->descriptor.idProduct == usb_devices[i].product ) {
|
||||||
|
|
||||||
|
printf("\b\b ");
|
||||||
PRINTF_END();
|
PRINTF_END();
|
||||||
PRINTF_ADD("Found ");
|
PRINTF_ADD("Found ");
|
||||||
usb_flash_device_info_print(&usb_devices[i]);
|
usb_flash_device_info_print(&usb_devices[i]);
|
||||||
|
|||||||
Reference in new issue
Block a user