1
0
mirror of git://projects.qi-hardware.com/xburst-tools.git synced 2024-12-24 04:51:09 +02:00
xburst-tools/flash-tool/main.c

97 lines
2.1 KiB
C
Raw Normal View History

2009-04-22 21:22:16 +03:00
/*
* "Ingenic flash tool" - flash the Ingenic CPU via USB
*
* (C) Copyright 2009
2009-04-28 18:57:53 +03:00
* Author: Xiangfu Liu <xiangfu.z@gmail.com>
2009-04-22 21:22:16 +03:00
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 3 as published by the Free Software Foundation.
*
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA
*/
#include <stdio.h>
2009-04-28 18:57:53 +03:00
#include <getopt.h>
#include <unistd.h>
#include <stdlib.h>
2009-04-22 21:22:16 +03:00
#include <errno.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
2009-04-28 18:57:53 +03:00
#include "usb.h"
2009-04-28 20:07:43 +03:00
#include "config.h"
#include "command_line.h"
2009-04-22 21:22:16 +03:00
2009-04-28 17:09:07 +03:00
static void help(void)
{
printf("Usage: inflash [options] ...(must run as root)\n"
" -h --help\t\t\tPrint this help message\n"
" -v --version\t\t\tPrint the version number\n"
);
}
static void print_version(void)
{
2009-04-28 20:07:43 +03:00
printf("inflash version: %s\n", CURRENT_VERSION);
2009-04-28 17:09:07 +03:00
}
static struct option opts[] = {
{ "help", 0, 0, 'h' },
{ "version", 0, 0, 'v' },
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-04-28 17:09:07 +03:00
printf("inflash - (C) 2009\n"
"This program is Free Software and has ABSOLUTELY NO WARRANTY\n\n");
2009-04-28 18:57:53 +03:00
2009-04-22 21:22:16 +03:00
if ((getuid()) || (getgid())) {
fprintf(stderr, "Error - you must be root to run '%s'\n", argv[0]);
2009-04-28 17:09:07 +03:00
return -1;
}
while (1) {
int c, option_index = 0;
2009-04-28 20:07:43 +03:00
c = getopt_long(argc, argv, "hv", opts,
2009-04-28 17:09:07 +03:00
&option_index);
if (c == -1)
break;
switch (c) {
case 'h':
help();
exit(EXIT_SUCCESS);
2009-04-28 17:14:58 +03:00
case 'v':
2009-04-28 17:09:07 +03:00
print_version();
exit(EXIT_SUCCESS);
2009-04-28 17:09:07 +03:00
default:
help();
exit(2);
}
2009-04-22 21:22:16 +03:00
}
2009-04-28 20:07:43 +03:00
char com_buf[256];
printf("\n Welcome!");
printf("\n USB Boot Host Software!");
2009-04-28 18:57:53 +03:00
while (1) {
2009-04-28 20:07:43 +03:00
printf("\n inflash :> ");
if (!command_input(com_buf))
2009-04-28 20:22:07 +03:00
continue;
2009-04-28 18:57:53 +03:00
command_handle(com_buf);
2009-04-27 19:08:41 +03:00
}
2009-04-22 21:22:16 +03:00
return EXIT_SUCCESS;
2009-04-22 21:22:16 +03:00
}