summaryrefslogtreecommitdiffstats
path: root/src/nolo.c
diff options
context:
space:
mode:
authorPali Rohár <pali.rohar@gmail.com>2012-08-10 21:23:19 +0200
committerPali Rohár <pali.rohar@gmail.com>2012-08-10 21:23:19 +0200
commita1d95afbf7ef368d0d9cd9a9e93eb795a4aae07e (patch)
tree73723d90bfd4ee481fbf4590efdfa7abd3d6ef0a /src/nolo.c
parentdc8844f1129b830ca1b1e8c984b0c65924b0a943 (diff)
download0xFFFF-a1d95afbf7ef368d0d9cd9a9e93eb795a4aae07e.tar.bz2
Fix NOLO communication
Diffstat (limited to 'src/nolo.c')
-rw-r--r--src/nolo.c37
1 files changed, 15 insertions, 22 deletions
diff --git a/src/nolo.c b/src/nolo.c
index ead89f1..9d8c78d 100644
--- a/src/nolo.c
+++ b/src/nolo.c
@@ -52,6 +52,7 @@ int nolo_init(struct usb_device_info * dev) {
uint32_t val = 1;
+ printf("Initializing NOLO...\n");
while ( val != 0 )
if ( usb_control_msg(dev->udev, NOLO_QUERY, NOLO_STATUS, 0, 0, (char *)&val, 4, 2000) == -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 )
ERROR_RETURN("NOLO_IDENTIFY failed", -1);
- ptr = strstr(buf, str);
+ ptr = memmem(buf, ret, str, strlen(str));
if ( ! ptr )
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);
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) {
-
- char * buf;
- int ret;
-
- if ( cmdline )
- buf = strdup(cmdline);
- else
- buf = calloc(1, 1);
+int nolo_boot(struct usb_device_info * dev, char * cmdline) {
- if ( ! buf )
- ALLOC_ERROR_RETURN(-1);
+ int size = 0;
- 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 ( cmdline && cmdline[0] ) {
+ printf("Booting kernel with cmdline: '%s'...\n", cmdline);
+ size = strlen(cmdline)+1;
+ } else {
+ printf("Booting kernel with default cmdline...\n");
+ cmdline = NULL;
+ }
- if ( ret < 0 )
+ if ( usb_control_msg(dev->udev, NOLO_WRITE, NOLO_BOOT, 0, 0, cmdline, size, 2000) < 0 )
ERROR_RETURN("NOLO_BOOT failed", -1);
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) {
+ printf("Rebooting device...\n");
if ( usb_control_msg(dev->udev, NOLO_WRITE, NOLO_REBOOT, 0, 0, NULL, 0, 2000) < 0 )
ERROR_RETURN("NOLO_REBOOT failed", -1);
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) {
+ 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 )
ERROR_RETURN("Cannot set root device", -1);
return 0;