| xbboot/host-app/host_main.c |
| 12 | 12 | #include <string.h> |
| 13 | 13 | #include <usb.h> |
| 14 | 14 | #include <time.h> |
| 15 | | #include <signal.h> |
| 16 | 15 | #include "xbboot_version.h" |
| 17 | 16 | |
| 18 | 17 | #define HIWORD(dw) (((dw) >> 16) & 0xFFFF) |
| ... | ... | |
| 42 | 41 | #define INGENIC_IN_ENDPOINT 0x81 |
| 43 | 42 | #define INGENIC_OUT_ENDPOINT 0x01 |
| 44 | 43 | |
| 44 | #define STAGE1_FILE_PATH (DATADIR "stage1.bin") |
| 45 | #define STAGE1_ADDRESS ("0x80002000") |
| 46 | |
| 45 | 47 | uint8_t xburst_interface = 0; |
| 46 | | int xkill = 0; |
| 47 | 48 | |
| 48 | 49 | struct usb_dev_handle* open_xburst_device(); |
| 49 | 50 | void close_xburst_device(struct usb_dev_handle* xburst_h); |
| 50 | 51 | int send_request(struct usb_dev_handle* xburst_h, char* request, char* str_param); |
| 51 | | void signal_handler(int sig); |
| 52 | 52 | void show_help(); |
| 53 | 53 | |
| 54 | 54 | int main(int argc, char** argv) |
| 55 | 55 | { |
| 56 | 56 | struct usb_dev_handle* xburst_h; |
| 57 | 57 | |
| 58 | | signal(SIGHUP, signal_handler); /* hangup signal */ |
| 59 | | signal(SIGTERM, signal_handler); /* software termination signal from kill */ |
| 60 | | signal(SIGINT, signal_handler); /* software termination signal from kill */ |
| 61 | | |
| 62 | 58 | if (argc < 2 |
| 63 | 59 | || !strcmp(argv[1], "-h") |
| 64 | 60 | || !strcmp(argv[1], "--help")) { |
| ... | ... | |
| 76 | 72 | } |
| 77 | 73 | |
| 78 | 74 | if (!strcmp(argv[1], "-d") || !strcmp(argv[1], "--daemon")) { |
| 75 | if (argc != 4) { |
| 76 | show_help(); |
| 77 | goto xquit; |
| 78 | } |
| 79 | |
| 79 | 80 | struct timespec timx,tim1; |
| 80 | 81 | |
| 81 | 82 | tim1.tv_sec = 1; |
| 82 | 83 | tim1.tv_nsec = 0; |
| 83 | 84 | while(1) { |
| 85 | nanosleep(&tim1,&timx); |
| 86 | |
| 84 | 87 | xburst_h = open_xburst_device(); |
| 85 | 88 | if (xburst_h) { |
| 86 | | printf("Info - found XBurst boot device.\n"); |
| 87 | | printf("Info - wait 5 seconds for Xburst device booting...\n"); |
| 88 | | sleep(5); |
| 89 | | } |
| 90 | | |
| 91 | | if (xkill) |
| 92 | | goto xquit; |
| 89 | printf("\nInfo - found XBurst boot device.\n"); |
| 90 | if (send_request(xburst_h, "set_addr", STAGE1_ADDRESS)) { |
| 91 | close_xburst_device(xburst_h); |
| 92 | continue; |
| 93 | } |
| 94 | if (send_request(xburst_h, "bulk_write", STAGE1_FILE_PATH)) { |
| 95 | close_xburst_device(xburst_h); |
| 96 | continue; |
| 97 | } |
| 98 | if (send_request(xburst_h, "start1", STAGE1_ADDRESS)) { |
| 99 | close_xburst_device(xburst_h); |
| 100 | continue; |
| 101 | } |
| 102 | if (send_request(xburst_h, "get_info", "NULL")) { |
| 103 | close_xburst_device(xburst_h); |
| 104 | continue; |
| 105 | } |
| 106 | if (send_request(xburst_h, "set_addr", argv[2])) { |
| 107 | close_xburst_device(xburst_h); |
| 108 | continue; |
| 109 | } |
| 110 | if (send_request(xburst_h, "bulk_write", argv[3])) { |
| 111 | close_xburst_device(xburst_h); |
| 112 | continue; |
| 113 | } |
| 114 | if (send_request(xburst_h, "flush_cache","NULL")) { |
| 115 | close_xburst_device(xburst_h); |
| 116 | continue; |
| 117 | } |
| 118 | if (send_request(xburst_h, "start2", argv[2])) { |
| 119 | close_xburst_device(xburst_h); |
| 120 | continue; |
| 121 | } |
| 93 | 122 | |
| 94 | | if (nanosleep(&tim1,&timx) == -1){ |
| 95 | | perror("Error - "); |
| 96 | 123 | goto xquit; |
| 97 | 124 | } |
| 98 | | |
| 99 | 125 | } |
| 100 | 126 | } |
| 101 | 127 | |
| 102 | 128 | xburst_h = open_xburst_device(); |
| 103 | 129 | if (xburst_h) |
| 104 | | send_request(xburst_h, argv[1], (argc == 2 ? NULL : argv[2])); |
| 130 | if (send_request(xburst_h, argv[1], (argc == 2 ? NULL : argv[2]))) { |
| 131 | close_xburst_device(xburst_h); |
| 132 | return EXIT_FAILURE; |
| 133 | } |
| 105 | 134 | xquit: |
| 106 | 135 | close_xburst_device(xburst_h); |
| 107 | 136 | return EXIT_SUCCESS; |
| ... | ... | |
| 378 | 407 | } |
| 379 | 408 | } |
| 380 | 409 | |
| 410 | usleep(100); |
| 381 | 411 | return 0; |
| 382 | 412 | |
| 383 | 413 | xout_xburst_interface: |
| 384 | 414 | return 1; |
| 385 | 415 | } |
| 386 | 416 | |
| 387 | | void signal_handler(int sig){ |
| 388 | | switch(sig){ |
| 389 | | case SIGINT: |
| 390 | | xkill = 1; |
| 391 | | break; |
| 392 | | } |
| 393 | | } |
| 394 | | |
| 395 | 417 | void show_help() |
| 396 | 418 | { |
| 397 | 419 | printf("\n" |