2009-04-22 18:22:16 +00:00
|
|
|
/*
|
2009-06-25 04:33:46 +00:00
|
|
|
* Authors: Xiangfu Liu <xiangfu.z@gmail.com>
|
2009-04-22 18:22:16 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
2009-06-25 04:33:46 +00:00
|
|
|
* as published by the Free Software Foundation; either version
|
|
|
|
* 3 of the License, or (at your option) any later version.
|
2009-04-22 18:22:16 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2009-04-26 10:37:31 +00:00
|
|
|
#include <stdlib.h>
|
2009-05-04 16:08:03 +00:00
|
|
|
#include <getopt.h>
|
2009-06-25 04:33:46 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
2009-06-09 19:16:39 +00:00
|
|
|
#include "inflash_version.h"
|
2009-04-28 17:07:43 +00:00
|
|
|
#include "command_line.h"
|
2009-04-30 17:26:14 +00:00
|
|
|
#include "ingenic_usb.h"
|
|
|
|
#include "ingenic_cfg.h"
|
|
|
|
|
|
|
|
extern struct ingenic_dev ingenic_dev;
|
2009-05-20 08:13:10 +00:00
|
|
|
extern struct hand hand;
|
2009-04-22 18:22:16 +00:00
|
|
|
|
2009-04-28 14:09:07 +00:00
|
|
|
static void help(void)
|
|
|
|
{
|
|
|
|
printf("Usage: inflash [options] ...(must run as root)\n"
|
2009-05-31 03:32:19 +00:00
|
|
|
" -h --help\t\t\tPrint this help message\n"
|
|
|
|
" -v --version\t\t\tPrint the version number\n"
|
2009-06-25 07:19:19 +00:00
|
|
|
" -c --command\t\t\tDirect run the command\n\n"
|
|
|
|
" <run without options to enter commands via inflash prompt>\n\n"
|
2009-06-24 10:13:50 +00:00
|
|
|
"Report bugs to <xiangfu.z@gmail.com>.\n"
|
2009-04-28 14:09:07 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_version(void)
|
|
|
|
{
|
2009-06-09 19:16:39 +00:00
|
|
|
printf("inflash version: %s\n", INFLASH_VERSION);
|
2009-04-28 14:09:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct option opts[] = {
|
|
|
|
{ "help", 0, 0, 'h' },
|
|
|
|
{ "version", 0, 0, 'v' },
|
2009-05-04 15:57:06 +00:00
|
|
|
{ "command", 1, 0, 'c' },
|
2009-04-28 17:07:43 +00:00
|
|
|
{ 0, 0, 0, 0 }
|
2009-04-28 14:09:07 +00:00
|
|
|
};
|
|
|
|
|
2009-04-22 18:22:16 +00:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2009-05-04 15:57:06 +00:00
|
|
|
int command = 0;
|
2009-05-07 03:07:52 +00:00
|
|
|
char *cptr;
|
2009-06-25 05:37:17 +00:00
|
|
|
char com_buf[256] = {0};
|
|
|
|
|
2009-06-25 16:39:24 +00:00
|
|
|
printf("inflash - Ingenic XBurst USB Boot Utility\n"
|
|
|
|
"(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 15:57:06 +00:00
|
|
|
|
2009-05-20 08:13:10 +00:00
|
|
|
while(1) {
|
2009-04-28 14:09:07 +00:00
|
|
|
int c, option_index = 0;
|
2009-05-04 15:57:06 +00:00
|
|
|
c = getopt_long(argc, argv, "hvc:", opts,
|
2009-04-28 14:09:07 +00:00
|
|
|
&option_index);
|
|
|
|
if (c == -1)
|
|
|
|
break;
|
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
case 'h':
|
|
|
|
help();
|
2009-04-28 18:13:19 +00:00
|
|
|
exit(EXIT_SUCCESS);
|
2009-04-28 14:14:58 +00:00
|
|
|
case 'v':
|
2009-04-28 14:09:07 +00:00
|
|
|
print_version();
|
2009-04-28 18:13:19 +00:00
|
|
|
exit(EXIT_SUCCESS);
|
2009-05-04 15:57:06 +00:00
|
|
|
case 'c':
|
|
|
|
command = 1;
|
|
|
|
strcpy(com_buf, optarg);
|
|
|
|
break;
|
2009-04-28 14:09:07 +00:00
|
|
|
default:
|
|
|
|
help();
|
|
|
|
exit(2);
|
|
|
|
}
|
2009-04-22 18:22:16 +00:00
|
|
|
}
|
|
|
|
|
2009-04-30 17:31:02 +00: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 14:36:51 +00:00
|
|
|
return EXIT_FAILURE;
|
2009-04-30 17:31:02 +00:00
|
|
|
|
|
|
|
if (parse_configure(&hand, CONFIG_FILE_PATH) < 1)
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
2009-05-04 16:08:03 +00:00
|
|
|
if (command) { /* direct run command */
|
2009-05-04 15:57:06 +00:00
|
|
|
command_handle(com_buf);
|
|
|
|
printf("\n");
|
|
|
|
goto out;
|
|
|
|
}
|
2009-04-28 17:07:43 +00:00
|
|
|
|
2009-04-28 15:57:53 +00:00
|
|
|
while (1) {
|
2009-06-25 16:39:24 +00:00
|
|
|
printf("\ninflash :> ");
|
2009-05-07 03:07:52 +00:00
|
|
|
cptr = fgets(com_buf, 256, stdin);
|
|
|
|
if (cptr == NULL)
|
2009-04-28 17:22:07 +00:00
|
|
|
continue;
|
2009-05-07 03:07:52 +00:00
|
|
|
|
2009-05-04 15:57:06 +00:00
|
|
|
if (command_handle(com_buf) == -1 )
|
|
|
|
break;
|
2009-04-27 16:08:41 +00:00
|
|
|
}
|
2009-04-22 18:22:16 +00:00
|
|
|
|
2009-05-04 15:57:06 +00:00
|
|
|
out:
|
2009-05-01 16:14:55 +00:00
|
|
|
usb_ingenic_cleanup(&ingenic_dev);
|
2009-04-28 18:13:19 +00:00
|
|
|
return EXIT_SUCCESS;
|
2009-04-22 18:22:16 +00:00
|
|
|
}
|