2009-04-22 21:22:16 +03:00
|
|
|
/*
|
2009-07-09 17:42:29 +03:00
|
|
|
* Copyright(C) 2009 Qi Hardware Inc.,
|
2009-07-05 07:43:21 +03:00
|
|
|
* Authors: Xiangfu Liu <xiangfu@qi-hardware.com>
|
2009-04-22 21:22:16 +03:00
|
|
|
*
|
2009-07-09 17:42:29 +03:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-04-22 21:22:16 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2009-04-26 13:37:31 +03:00
|
|
|
#include <stdlib.h>
|
2009-05-04 19:08:03 +03:00
|
|
|
#include <getopt.h>
|
2009-06-25 07:33:46 +03:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
2009-07-02 12:22:33 +03:00
|
|
|
#include "xburst-tools_version.h"
|
2009-04-28 20:07:43 +03:00
|
|
|
#include "command_line.h"
|
2009-04-30 20:26:14 +03:00
|
|
|
#include "ingenic_usb.h"
|
|
|
|
#include "ingenic_cfg.h"
|
|
|
|
|
2009-11-03 19:51:33 +02:00
|
|
|
#define CONFIG_FILE_PATH (CFGDIR "/usbboot.cfg")
|
2009-07-20 18:43:05 +03:00
|
|
|
|
2009-04-30 20:26:14 +03:00
|
|
|
extern struct ingenic_dev ingenic_dev;
|
2009-05-20 11:13:10 +03:00
|
|
|
extern struct hand hand;
|
2009-04-22 21:22:16 +03:00
|
|
|
|
2009-04-28 17:09:07 +03:00
|
|
|
static void help(void)
|
|
|
|
{
|
2009-06-30 08:49:11 +03:00
|
|
|
printf("Usage: usbboot [options] ...(must run as root)\n"
|
2009-05-31 06:32:19 +03:00
|
|
|
" -h --help\t\t\tPrint this help message\n"
|
|
|
|
" -v --version\t\t\tPrint the version number\n"
|
2009-06-29 04:25:19 +03:00
|
|
|
" -c --command\t\t\tDirect run the commands, split by ';'\n"
|
2009-07-20 18:43:05 +03:00
|
|
|
" -f --configure\t\t\tconfigure file path\n"
|
2009-06-30 08:49:11 +03:00
|
|
|
" <run without options to enter commands via usbboot prompt>\n\n"
|
2009-07-05 07:43:21 +03:00
|
|
|
"Report bugs to <xiangfu@qi-hardware.com>.\n"
|
2009-04-28 17:09:07 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_version(void)
|
|
|
|
{
|
2009-06-30 08:49:11 +03:00
|
|
|
printf("usbboot version: %s\n", XBURST_TOOLS_VERSION);
|
2009-04-28 17:09:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct option opts[] = {
|
|
|
|
{ "help", 0, 0, 'h' },
|
|
|
|
{ "version", 0, 0, 'v' },
|
2009-05-04 18:57:06 +03:00
|
|
|
{ "command", 1, 0, 'c' },
|
2009-07-20 18:43:05 +03:00
|
|
|
{ "configure", 1, 0, 'f' },
|
2009-04-28 20:07:43 +03:00
|
|
|
{ 0, 0, 0, 0 }
|
2009-04-28 17:09:07 +03:00
|
|
|
};
|
|
|
|
|
2009-04-22 21:22:16 +03:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2009-05-04 18:57:06 +03:00
|
|
|
int command = 0;
|
2009-05-07 06:07:52 +03:00
|
|
|
char *cptr;
|
2009-06-25 08:37:17 +03:00
|
|
|
char com_buf[256] = {0};
|
2009-06-28 06:38:48 +03:00
|
|
|
char *cmdpt;
|
2009-07-20 18:43:05 +03:00
|
|
|
char *cfgpath = CONFIG_FILE_PATH;
|
2009-06-25 08:37:17 +03:00
|
|
|
|
2009-06-30 08:49:11 +03:00
|
|
|
printf("usbboot - Ingenic XBurst USB Boot Utility\n"
|
2009-06-25 19:39:24 +03:00
|
|
|
"(c) 2009 Ingenic Semiconductor Inc., Qi Hardware Inc., Xiangfu Liu, Marek Lindner\n"
|
|
|
|
"This program is Free Software and comes with ABSOLUTELY NO WARRANTY.\n\n");
|
2009-05-04 18:57:06 +03:00
|
|
|
|
2009-05-20 11:13:10 +03:00
|
|
|
while(1) {
|
2009-04-28 17:09:07 +03:00
|
|
|
int c, option_index = 0;
|
2009-07-20 18:43:05 +03:00
|
|
|
c = getopt_long(argc, argv, "hvc:f:", opts,
|
2009-04-28 17:09:07 +03:00
|
|
|
&option_index);
|
|
|
|
if (c == -1)
|
|
|
|
break;
|
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
case 'h':
|
|
|
|
help();
|
2009-04-28 21:13:19 +03:00
|
|
|
exit(EXIT_SUCCESS);
|
2009-04-28 17:14:58 +03:00
|
|
|
case 'v':
|
2009-04-28 17:09:07 +03:00
|
|
|
print_version();
|
2009-04-28 21:13:19 +03:00
|
|
|
exit(EXIT_SUCCESS);
|
2009-05-04 18:57:06 +03:00
|
|
|
case 'c':
|
|
|
|
command = 1;
|
2009-06-28 06:38:48 +03:00
|
|
|
cmdpt = optarg;
|
2009-05-04 18:57:06 +03:00
|
|
|
break;
|
2009-07-20 18:43:05 +03:00
|
|
|
case 'f':
|
|
|
|
cfgpath = optarg;
|
|
|
|
break;
|
2009-04-28 17:09:07 +03:00
|
|
|
default:
|
|
|
|
help();
|
|
|
|
exit(2);
|
|
|
|
}
|
2009-04-22 21:22:16 +03:00
|
|
|
}
|
|
|
|
|
2009-04-30 20:31:02 +03:00
|
|
|
if ((getuid()) || (getgid())) {
|
|
|
|
fprintf(stderr, "Error - you must be root to run '%s'\n", argv[0]);
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (usb_ingenic_init(&ingenic_dev) < 1)
|
2009-05-04 17:36:51 +03:00
|
|
|
return EXIT_FAILURE;
|
2009-04-30 20:31:02 +03:00
|
|
|
|
2009-07-20 18:43:05 +03:00
|
|
|
if (parse_configure(&hand, cfgpath) < 1)
|
2009-04-30 20:31:02 +03:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
2009-05-04 19:08:03 +03:00
|
|
|
if (command) { /* direct run command */
|
2009-06-28 06:38:48 +03:00
|
|
|
char *delim=";";
|
|
|
|
char *p;
|
|
|
|
p = strtok(cmdpt, delim);
|
|
|
|
strcpy(com_buf, p);
|
|
|
|
printf(" Execute command: %s \n",com_buf);
|
2009-05-04 18:57:06 +03:00
|
|
|
command_handle(com_buf);
|
2009-06-28 06:38:48 +03:00
|
|
|
|
|
|
|
while((p = strtok(NULL,delim))) {
|
|
|
|
strcpy(com_buf, p);
|
|
|
|
printf(" Execute command: %s \n",com_buf);
|
|
|
|
command_handle(com_buf);
|
|
|
|
}
|
2009-05-04 18:57:06 +03:00
|
|
|
goto out;
|
|
|
|
}
|
2009-04-28 20:07:43 +03:00
|
|
|
|
2009-04-28 18:57:53 +03:00
|
|
|
while (1) {
|
2009-06-30 08:49:11 +03:00
|
|
|
printf("usbboot :> ");
|
2009-05-07 06:07:52 +03:00
|
|
|
cptr = fgets(com_buf, 256, stdin);
|
2009-06-26 06:38:32 +03:00
|
|
|
if (cptr == NULL)
|
2009-04-28 20:22:07 +03:00
|
|
|
continue;
|
2009-05-07 06:07:52 +03:00
|
|
|
|
2009-05-04 18:57:06 +03:00
|
|
|
if (command_handle(com_buf) == -1 )
|
|
|
|
break;
|
2009-04-27 19:08:41 +03:00
|
|
|
}
|
2009-04-22 21:22:16 +03:00
|
|
|
|
2009-05-04 18:57:06 +03:00
|
|
|
out:
|
2009-05-01 19:14:55 +03:00
|
|
|
usb_ingenic_cleanup(&ingenic_dev);
|
2009-04-28 21:13:19 +03:00
|
|
|
return EXIT_SUCCESS;
|
2009-04-22 21:22:16 +03:00
|
|
|
}
|