From 59a440415bcb604b26587bc5ac6e6d7904414cba Mon Sep 17 00:00:00 2001 From: Xiangfu Liu Date: Thu, 22 Apr 2010 17:13:47 +0800 Subject: [PATCH] add -d options. search xburst device every second --- xbboot/host-app/host_main.c | 105 +++++++++++++++++++++++++----------- 1 file changed, 74 insertions(+), 31 deletions(-) diff --git a/xbboot/host-app/host_main.c b/xbboot/host-app/host_main.c index 94276fe..431488f 100644 --- a/xbboot/host-app/host_main.c +++ b/xbboot/host-app/host_main.c @@ -1,5 +1,6 @@ // // Authors: Wolfgang Spraul +// Authors: Xiangfu Liu // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -10,6 +11,8 @@ #include #include #include +#include +#include #include "xbboot_version.h" #define HIWORD(dw) (((dw) >> 16) & 0xFFFF) @@ -40,36 +43,26 @@ #define INGENIC_OUT_ENDPOINT 0x01 uint8_t xburst_interface = 0; +int xkill = 0; struct usb_dev_handle* open_xburst_device(); void close_xburst_device(struct usb_dev_handle* xburst_h); int send_request(struct usb_dev_handle* xburst_h, char* request, char* str_param); +void signal_handler(int sig); +void show_help(); int main(int argc, char** argv) { + struct usb_dev_handle* xburst_h; + + signal(SIGHUP, signal_handler); /* hangup signal */ + signal(SIGTERM, signal_handler); /* software termination signal from kill */ + signal(SIGINT, signal_handler); /* software termination signal from kill */ + if (argc < 2 || !strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) { - printf("\n" - "xbboot version %s - Ingenic XBurst USB Boot Vendor Requests\n" - "(c) 2009 Wolfgang Spraul\n" - "Report bugs to .\n" - "\n" - "xbboot [vendor_request] ... (must run as root)\n" - " -h --help print this help message\n" - " -v --version print the version number\n" - "\n" - " bulk_read read len bulk bytes from USB, write to stdout\n" - " bulk_write write file at to USB\n" - " [get_info | VR_GET_CPU_INFO] read 8-byte CPU info and write to stdout\n" - " [set_addr | VR_SET_DATA_ADDRESS] send memory address\n" - " [set_len | VR_SET_DATA_LENGTH] send data length\n" - " [flush_cache | VR_FLUSH_CACHES] flush I-Cache and D-Cache\n" - " [start1 | VR_PROGRAM_START1] transfer data from D-Cache to I-Cache and branch to I-Cache\n" - " [start2 | VR_PROGRAM_START2] branch to directly\n" - "\n" - "- all numbers can be prefixed 0x for hex otherwise decimal\n" - "\n", XBBOOT_VERSION); + show_help(); return EXIT_SUCCESS; } if (!strcmp(argv[1], "-v") || !strcmp(argv[1], "--version")) { @@ -82,22 +75,39 @@ int main(int argc, char** argv) return EXIT_FAILURE; } - struct usb_dev_handle* xburst_h = open_xburst_device(); - if (!xburst_h) - return EXIT_FAILURE; + if (!strcmp(argv[1], "-d") || !strcmp(argv[1], "--daemon")) { + struct timespec timx,tim1; - char* parameter; - if (argc == 2) - parameter = NULL; - else - parameter = argv[2]; + tim1.tv_sec = 1; + tim1.tv_nsec = 0; + while(1) { + xburst_h = open_xburst_device(); + if (xburst_h) { + printf("Info - found XBurst boot device.\n"); + printf("Info - wait 5 seconds for Xburst device booting...\n"); + sleep(5); + } - send_request(xburst_h, argv[1], parameter); + if (xkill) + goto xquit; + + if (nanosleep(&tim1,&timx) == -1){ + perror("Error - "); + goto xquit; + } + + } + } + + xburst_h = open_xburst_device(); + if (xburst_h) + send_request(xburst_h, argv[1], (argc == 2 ? NULL : argv[2])); +xquit: close_xburst_device(xburst_h); - return EXIT_SUCCESS; } + void close_xburst_device(struct usb_dev_handle* xburst_h) { if (xburst_h && xburst_interface) @@ -137,7 +147,7 @@ struct usb_dev_handle* open_xburst_device() } } if (!xburst_dev) { - fprintf(stderr, "Error - no XBurst boot device found.\n"); + fprintf(stderr, "Info - no XBurst boot device found.\n"); goto xout; } } @@ -373,3 +383,36 @@ int send_request(struct usb_dev_handle* xburst_h, char* request, char* str_param xout_xburst_interface: return 1; } + +void signal_handler(int sig){ + switch(sig){ + case SIGINT: + xkill = 1; + break; + } +} + +void show_help() +{ + printf("\n" + "xbboot version %s - Ingenic XBurst USB Boot Vendor Requests\n" + "(c) 2009 Wolfgang Spraul\n" + "Report bugs to .\n" + "\n" + "xbboot [vendor_request] ... (must run as root)\n" + " -h --help print this help message\n" + " -v --version print the version number\n" + " [-d | --daemon]
\n" + "\n" + " bulk_read read len bulk bytes from USB, write to stdout\n" + " bulk_write write file at to USB\n" + " [get_info | VR_GET_CPU_INFO] read 8-byte CPU info and write to stdout\n" + " [set_addr | VR_SET_DATA_ADDRESS] send memory address\n" + " [set_len | VR_SET_DATA_LENGTH] send data length\n" + " [flush_cache | VR_FLUSH_CACHES] flush I-Cache and D-Cache\n" + " [start1 | VR_PROGRAM_START1] transfer data from D-Cache to I-Cache and branch to I-Cache\n" + " [start2 | VR_PROGRAM_START2] branch to directly\n" + "\n" + "- all numbers can be prefixed 0x for hex otherwise decimal\n" + "\n", XBBOOT_VERSION); +}