Date:2010-04-28 12:06:28 (13 years 7 months ago)
Author:Xiangfu Liu
Commit:07bfc337127a7326bb6eabfcfe5f9832db77e7ab
Message:add more error check. remove the signal handler

Signed-off-by: Xiangfu Liu <xiangfu@sharism.cc>
Files: xbboot/host-app/Makefile.am (1 diff)
xbboot/host-app/host_main.c (4 diffs)

Change Details

xbboot/host-app/Makefile.am
1010xbboot_SOURCES = host_main.c
1111
1212prefix = /usr
13pkgdatadir = $(datadir)/xburst-tools
13pkgdatadir = $(datadir)/xburst-tools/
1414
1515if COND_FIRMWARE
1616pkgdata_DATA = ../target-stage1/stage1.bin
xbboot/host-app/host_main.c
1212#include <string.h>
1313#include <usb.h>
1414#include <time.h>
15#include <signal.h>
1615#include "xbboot_version.h"
1716
1817#define HIWORD(dw) (((dw) >> 16) & 0xFFFF)
...... 
4241#define INGENIC_IN_ENDPOINT 0x81
4342#define INGENIC_OUT_ENDPOINT 0x01
4443
44#define STAGE1_FILE_PATH (DATADIR "stage1.bin")
45#define STAGE1_ADDRESS ("0x80002000")
46
4547uint8_t xburst_interface = 0;
46int xkill = 0;
4748
4849struct usb_dev_handle* open_xburst_device();
4950void close_xburst_device(struct usb_dev_handle* xburst_h);
5051int send_request(struct usb_dev_handle* xburst_h, char* request, char* str_param);
51void signal_handler(int sig);
5252void show_help();
5353
5454int main(int argc, char** argv)
5555{
5656    struct usb_dev_handle* xburst_h;
5757
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
6258    if (argc < 2
6359        || !strcmp(argv[1], "-h")
6460        || !strcmp(argv[1], "--help")) {
...... 
7672    }
7773
7874    if (!strcmp(argv[1], "-d") || !strcmp(argv[1], "--daemon")) {
75        if (argc != 4) {
76            show_help();
77            goto xquit;
78        }
79
7980        struct timespec timx,tim1;
8081
8182        tim1.tv_sec = 1;
8283        tim1.tv_nsec = 0;
8384        while(1) {
85            nanosleep(&tim1,&timx);
86
8487            xburst_h = open_xburst_device();
8588            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                }
93122
94            if (nanosleep(&tim1,&timx) == -1){
95                perror("Error - ");
96123                goto xquit;
97124            }
98
99125        }
100126    }
101127
102128    xburst_h = open_xburst_device();
103129    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        }
105134xquit:
106135    close_xburst_device(xburst_h);
107136    return EXIT_SUCCESS;
...... 
378407        }
379408    }
380409
410    usleep(100);
381411    return 0;
382412
383413xout_xburst_interface:
384414    return 1;
385415}
386416
387void signal_handler(int sig){
388        switch(sig){
389    case SIGINT:
390        xkill = 1;
391        break;
392        }
393}
394
395417void show_help()
396418{
397419    printf("\n"

Archive Download the corresponding diff file



interactive