From 8a21acc9cc96a12bda7c1b123a2b6073f61b2037 Mon Sep 17 00:00:00 2001 From: Pali Rohár Date: Sat, 11 Aug 2012 15:24:02 +0200 Subject: nolo: Merge functions nolo_boot and nolo_boot_to_update_mode to nolo_boot_device --- src/nolo.c | 31 ++++++++++++++++++------------- src/nolo.h | 3 +-- 2 files changed, 19 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/nolo.c b/src/nolo.c index 97466c8..4c7c595 100644 --- a/src/nolo.c +++ b/src/nolo.c @@ -158,11 +158,25 @@ int nolo_flash_image(struct usb_device_info * dev, struct image * image) { } -int nolo_boot(struct usb_device_info * dev, char * cmdline) { +int nolo_boot_device(struct usb_device_info * dev, char * cmdline) { int size = 0; - - if ( cmdline && cmdline[0] ) { + int mode = NOLO_BOOT_MODE_NORMAL; + + if ( cmdline && strncmp(cmdline, "update", strlen("update")) == 0 && cmdline[strlen("update")] <= 32 ) { + mode = NOLO_BOOT_MODE_UPDATE; + cmdline += strlen("update"); + if ( *cmdline ) ++cmdline; + while ( *cmdline && *cmdline <= 32 ) + ++cmdline; + if ( *cmdline ) { + printf("Booting kernel to update mode with cmdline: %s...\n", cmdline); + size = strlen(cmdline); + } else { + printf("Booting kernel to update mode with default cmdline...\n"); + cmdline = NULL; + } + } else if ( cmdline && cmdline[0] ) { printf("Booting kernel with cmdline: '%s'...\n", cmdline); size = strlen(cmdline)+1; } else { @@ -170,22 +184,13 @@ int nolo_boot(struct usb_device_info * dev, char * cmdline) { cmdline = NULL; } - if ( usb_control_msg(dev->udev, NOLO_WRITE, NOLO_BOOT, NOLO_BOOT_MODE_NORMAL, 0, cmdline, size, 2000) < 0 ) + if ( usb_control_msg(dev->udev, NOLO_WRITE, NOLO_BOOT, mode, 0, cmdline, size, 2000) < 0 ) ERROR_RETURN("Booting failed", -1); return 0; } -int nolo_boot_to_update_mode(struct usb_device_info * dev) { - - printf("Booting to update mode...\n"); - if ( usb_control_msg(dev->udev, NOLO_WRITE, NOLO_BOOT, NOLO_BOOT_MODE_UPDATE, 0, NULL, 0, 2000) < 0 ) - ERROR_RETURN("Booting failed", -1); - return 0; - -} - int nolo_reboot_device(struct usb_device_info * dev) { printf("Rebooting device...\n"); diff --git a/src/nolo.h b/src/nolo.h index f294d1a..f38cb64 100644 --- a/src/nolo.h +++ b/src/nolo.h @@ -29,8 +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_flash_image(struct usb_device_info * dev, struct image * image); -int nolo_boot(struct usb_device_info * dev, char * cmdline); -int nolo_boot_to_update_mode(struct usb_device_info * dev); +int nolo_boot_device(struct usb_device_info * dev, char * cmdline); int nolo_reboot_device(struct usb_device_info * dev); int nolo_get_root_device(struct usb_device_info * dev); -- cgit v1.2.3