mirror of
git://projects.qi-hardware.com/xburst-tools.git
synced 2024-11-01 20:08:25 +02:00
add command line
This commit is contained in:
parent
46f40dbfa6
commit
f83f34e76b
@ -34,8 +34,8 @@ CFLAGS += -pedantic -Wall -W -O1 -g3 -std=gnu99
|
|||||||
LDFLAGS += -lusb -lconfuse
|
LDFLAGS += -lusb -lconfuse
|
||||||
BINARY_NAME = inflash
|
BINARY_NAME = inflash
|
||||||
|
|
||||||
SRC_C= main.c usb.c cmd_boot.c
|
SRC_C= main.c usb.c cmd_boot.c command_line.c
|
||||||
SRC_H= usb.h usb_boot_defines.h
|
SRC_H= ingenic_usb.h usb_boot_defines.h command_line.h cmd.h config.h
|
||||||
SRC_O= $(SRC_C:.c=.o)
|
SRC_O= $(SRC_C:.c=.o)
|
||||||
|
|
||||||
$(BINARY_NAME): $(SRC_O) $(SRC_H) Makefile
|
$(BINARY_NAME): $(SRC_O) $(SRC_H) Makefile
|
||||||
|
27
flash-tool/cmd.h
Normal file
27
flash-tool/cmd.h
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* "Ingenic flash tool" - flash the Ingenic CPU via USB
|
||||||
|
*
|
||||||
|
* (C) Copyright 2009
|
||||||
|
* Author: Xiangfu Liu <xiangfu.z@gmail.com>
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __CMD_H__
|
||||||
|
#define __CMD_H__
|
||||||
|
|
||||||
|
int boot(char *stage1_path, char *stage2_path, char *config_path);
|
||||||
|
|
||||||
|
#endif /* __CMD_H__ */
|
@ -19,7 +19,7 @@
|
|||||||
* Boston, MA 02110-1301, USA
|
* Boston, MA 02110-1301, USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "usb.h"
|
#include "ingenic_usb.h"
|
||||||
#include "usb_boot_defines.h"
|
#include "usb_boot_defines.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
207
flash-tool/command_line.c
Normal file
207
flash-tool/command_line.c
Normal file
@ -0,0 +1,207 @@
|
|||||||
|
/*
|
||||||
|
* "Ingenic flash tool" - flash the Ingenic CPU via USB
|
||||||
|
*
|
||||||
|
* (C) Copyright 2009
|
||||||
|
* Author: Xiangfu Liu <xiangfu.z@gmail.com>
|
||||||
|
*
|
||||||
|
* 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>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "usb_boot_defines.h"
|
||||||
|
#include "ingenic_usb.h"
|
||||||
|
#include "cmd.h"
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
static int com_argc;
|
||||||
|
static char com_argv[20][50];
|
||||||
|
|
||||||
|
static const char COMMAND[][30]=
|
||||||
|
{
|
||||||
|
"",
|
||||||
|
"query",
|
||||||
|
"querya",
|
||||||
|
"erase",
|
||||||
|
"read",
|
||||||
|
"prog",
|
||||||
|
"nquery",
|
||||||
|
"nerase",
|
||||||
|
"nread",
|
||||||
|
"nreadraw",
|
||||||
|
"nreadoob",
|
||||||
|
"nprog",
|
||||||
|
"help",
|
||||||
|
"version",
|
||||||
|
"go",
|
||||||
|
"fconfig",
|
||||||
|
"exit",
|
||||||
|
"readnand",
|
||||||
|
"gpios",
|
||||||
|
"gpioc",
|
||||||
|
"boot",
|
||||||
|
"list",
|
||||||
|
"select",
|
||||||
|
"unselect",
|
||||||
|
"chip",
|
||||||
|
"unchip",
|
||||||
|
"nmake",
|
||||||
|
"load",
|
||||||
|
"memtest",
|
||||||
|
"run"
|
||||||
|
};
|
||||||
|
|
||||||
|
void handle_exit(int res)
|
||||||
|
{
|
||||||
|
printf("\n exiting inflash software\n");
|
||||||
|
exit(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
int handle_nprog(void)
|
||||||
|
{
|
||||||
|
printf("\n not implement");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int handle_help(void)
|
||||||
|
{
|
||||||
|
printf("\n Command support in current version:");
|
||||||
|
printf("\n help print this help;");
|
||||||
|
printf("\n boot boot device and make it in stage2;");
|
||||||
|
printf("\n list show current device number can connect;");
|
||||||
|
printf("\n fconfig set USB Boot config file;");
|
||||||
|
printf("\n nquery query NAND flash info;");
|
||||||
|
printf("\n nread read NAND flash data with checking bad block and ECC;");
|
||||||
|
printf("\n nreadraw read NAND flash data without checking bad block and ECC;");
|
||||||
|
printf("\n nreadoob read NAND flash oob without checking bad block and ECC;");
|
||||||
|
printf("\n nerase erase NAND flash;");
|
||||||
|
printf("\n nprog program NAND flash with data and ECC;");
|
||||||
|
printf("\n nmark mark a bad block in NAND flash;");
|
||||||
|
printf("\n go execute program in SDRAM;");
|
||||||
|
printf("\n version show current USB Boot software version;");
|
||||||
|
printf("\n exit quit from telnet session;");
|
||||||
|
printf("\n readnand read data from nand flash and store to SDRAM;");
|
||||||
|
printf("\n load load file data to SDRAM;");
|
||||||
|
printf("\n run run command script in file;");
|
||||||
|
printf("\n memtest do SDRAM test;");
|
||||||
|
printf("\n gpios let one GPIO to high level;");
|
||||||
|
printf("\n gpioc let one GPIO to low level;");
|
||||||
|
/* printf("\n nmake read all data from nand flash and store to file(experimental);"); */
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int handle_version(void)
|
||||||
|
{
|
||||||
|
printf("\n USB Boot Software current version: %s", CURRENT_VERSION);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int handle_fconfig(void)
|
||||||
|
{
|
||||||
|
if (com_argc < 3) {
|
||||||
|
printf("\n Usage:");
|
||||||
|
printf(" fconfig (1) (2) ");
|
||||||
|
printf("\n 1:configration file name \
|
||||||
|
\n 2:deivce index number ");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
/* usb_infenic_config(atoi(com_argv[2]),com_argv[1]); */
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int handle_boot(void)
|
||||||
|
{
|
||||||
|
return boot(STAGE1_FILE_PATH, STAGE2_FILE_PATH, CONFIG_FILE_PATH);
|
||||||
|
}
|
||||||
|
|
||||||
|
int command_input(char *buf)
|
||||||
|
{
|
||||||
|
char *cptr;
|
||||||
|
cptr = fgets(buf, ARRAY_SIZE(buf), stdin);
|
||||||
|
|
||||||
|
if (cptr != NULL)
|
||||||
|
return 0;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int command_interpret(char * com_buf)
|
||||||
|
{
|
||||||
|
char *buf = com_buf;
|
||||||
|
int k, L, i=0, j = 0;
|
||||||
|
|
||||||
|
L = (int)strlen(buf);
|
||||||
|
buf[L]=' ';
|
||||||
|
for (k = 0; k <= L; k++) {
|
||||||
|
if (*buf==' '|| *buf=='\n') {
|
||||||
|
while(*(++buf)==' ');
|
||||||
|
com_argv[i][j]='\0';
|
||||||
|
i++;
|
||||||
|
if (i>9) {
|
||||||
|
printf("\n Para is too much! About!");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
j=0;
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
com_argv[i][j]=*buf;
|
||||||
|
j++;
|
||||||
|
if (j>100)
|
||||||
|
{
|
||||||
|
printf("\n Para is too long! About!");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
buf++;
|
||||||
|
}
|
||||||
|
|
||||||
|
com_argc=i;
|
||||||
|
|
||||||
|
for (i = 1; i <= COMMAND_NUM; i++)
|
||||||
|
if (!strcmp(COMMAND[i],com_argv[0]))
|
||||||
|
return i;
|
||||||
|
return COMMAND_NUM + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int command_handle(char *buf)
|
||||||
|
{
|
||||||
|
int cmd = command_interpret(buf);
|
||||||
|
int result = 0;
|
||||||
|
|
||||||
|
if (!cmd) return 1;
|
||||||
|
switch (cmd) {
|
||||||
|
case 11:
|
||||||
|
handle_nprog();
|
||||||
|
break;
|
||||||
|
case 12:
|
||||||
|
handle_help();
|
||||||
|
break;
|
||||||
|
case 13:
|
||||||
|
handle_version();
|
||||||
|
break;
|
||||||
|
case 16:
|
||||||
|
handle_exit(0);
|
||||||
|
break;
|
||||||
|
case 20:
|
||||||
|
handle_boot();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
printf("\n Command not support!");
|
||||||
|
result = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
27
flash-tool/command_line.h
Normal file
27
flash-tool/command_line.h
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* "Ingenic flash tool" - flash the Ingenic CPU via USB
|
||||||
|
*
|
||||||
|
* (C) Copyright 2009
|
||||||
|
* Author: Xiangfu Liu <xiangfu.z@gmail.com>
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
#ifndef __COMMAND_LINE_H__
|
||||||
|
#define __COMMAND_LINE_H__
|
||||||
|
|
||||||
|
int command_input(char *buf);
|
||||||
|
int command_handle(char *buf);
|
||||||
|
|
||||||
|
#endif /* __COMMAND_LINE_H__ */
|
26
flash-tool/config.h
Normal file
26
flash-tool/config.h
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* "Ingenic flash tool" - flash the Ingenic CPU via USB
|
||||||
|
*
|
||||||
|
* (C) Copyright 2009
|
||||||
|
* Author: Xiangfu Liu <xiangfu.z@gmail.com>
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
#ifndef __CONFIG_H__
|
||||||
|
#define __CONFIG_H__
|
||||||
|
|
||||||
|
#define CURRENT_VERSION "1.0"
|
||||||
|
|
||||||
|
#endif /* __CONFIG_H__ */
|
@ -18,6 +18,8 @@
|
|||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||||
* Boston, MA 02110-1301, USA
|
* Boston, MA 02110-1301, USA
|
||||||
*/
|
*/
|
||||||
|
#ifndef __INGENIC_USB_H__
|
||||||
|
#define __INGENIC_USB_H__
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
@ -47,6 +49,7 @@
|
|||||||
#define STAGE1_FILE_PATH "fw.bin"
|
#define STAGE1_FILE_PATH "fw.bin"
|
||||||
#define STAGE2_FILE_PATH "usb_boot.bin"
|
#define STAGE2_FILE_PATH "usb_boot.bin"
|
||||||
#define CONFIG_FILE_PATH "usb_boot.cfg"
|
#define CONFIG_FILE_PATH "usb_boot.cfg"
|
||||||
|
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
|
||||||
|
|
||||||
struct ingenic_dev {
|
struct ingenic_dev {
|
||||||
struct usb_device *usb_dev;
|
struct usb_device *usb_dev;
|
||||||
@ -61,3 +64,5 @@ int usb_ingenic_init(struct ingenic_dev *ingenic_dev);
|
|||||||
int usb_get_ingenic_cpu(struct ingenic_dev *ingenic_dev);
|
int usb_get_ingenic_cpu(struct ingenic_dev *ingenic_dev);
|
||||||
int usb_ingenic_upload(struct ingenic_dev *ingenic_dev, int stage);
|
int usb_ingenic_upload(struct ingenic_dev *ingenic_dev, int stage);
|
||||||
void usb_ingenic_cleanup(struct ingenic_dev *ingenic_dev);
|
void usb_ingenic_cleanup(struct ingenic_dev *ingenic_dev);
|
||||||
|
|
||||||
|
#endif /* __INGENIC_USB_H__ */
|
@ -28,30 +28,26 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include "usb.h"
|
#include "usb.h"
|
||||||
|
#include "config.h"
|
||||||
|
#include "command_line.h"
|
||||||
|
|
||||||
static void help(void)
|
static void help(void)
|
||||||
{
|
{
|
||||||
printf("Usage: inflash [options] ...(must run as root)\n"
|
printf("Usage: inflash [options] ...(must run as root)\n"
|
||||||
" -h --help\t\t\tPrint this help message\n"
|
" -h --help\t\t\tPrint this help message\n"
|
||||||
" -v --version\t\t\tPrint the version number\n"
|
" -v --version\t\t\tPrint the version number\n"
|
||||||
" -c --cfg \t\t\tSpecify the Configuration of inflash device\n"
|
|
||||||
" -o --stageone \t\tSpecify the stage one file(default ./bw.bin)\n"
|
|
||||||
" -t --stagetwo \t\tSpecify the stage two file(default ./usb_boot.bin)\n"
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print_version(void)
|
static void print_version(void)
|
||||||
{
|
{
|
||||||
printf("inflash version \n");
|
printf("inflash version: %s\n", CURRENT_VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct option opts[] = {
|
static struct option opts[] = {
|
||||||
{ "help", 0, 0, 'h' },
|
{ "help", 0, 0, 'h' },
|
||||||
{ "version", 0, 0, 'v' },
|
{ "version", 0, 0, 'v' },
|
||||||
{ "cfg", 1, 0, 'c' },
|
{ 0, 0, 0, 0 }
|
||||||
{ "stageone", 1, 0, 'o' },
|
|
||||||
{ "stagetwo", 1, 0, 't' },
|
|
||||||
{ NULL, 0, 0, NULL }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
@ -64,13 +60,9 @@ int main(int argc, char **argv)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *stage1_path = STAGE1_FILE_PATH;
|
|
||||||
char *stage2_path = STAGE2_FILE_PATH;
|
|
||||||
char *config_path = CONFIG_FILE_PATH;
|
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
int c, option_index = 0;
|
int c, option_index = 0;
|
||||||
c = getopt_long(argc, argv, "hvc:o:t:", opts,
|
c = getopt_long(argc, argv, "hv", opts,
|
||||||
&option_index);
|
&option_index);
|
||||||
if (c == -1)
|
if (c == -1)
|
||||||
break;
|
break;
|
||||||
@ -84,31 +76,21 @@ int main(int argc, char **argv)
|
|||||||
print_version();
|
print_version();
|
||||||
exit(0);
|
exit(0);
|
||||||
break;
|
break;
|
||||||
case 'c':
|
|
||||||
/* Configuration */
|
|
||||||
config_path = optarg;
|
|
||||||
break;
|
|
||||||
case 'o':
|
|
||||||
stage1_path = optarg;
|
|
||||||
break;
|
|
||||||
case 't':
|
|
||||||
stage2_path = optarg;
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
help();
|
help();
|
||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
char com_buf[256];
|
||||||
|
printf("\n Welcome!");
|
||||||
|
printf("\n USB Boot Host Software!");
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
printf("\n USBBoot :> ");
|
printf("\n inflash :> ");
|
||||||
if (!command_input(com_buf)) continue;
|
if (!command_input(com_buf)) continue;
|
||||||
command_handle(com_buf);
|
command_handle(com_buf);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
boot(stage1_path, stage2_path, config_path);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -19,9 +19,7 @@
|
|||||||
* Boston, MA 02110-1301, USA
|
* Boston, MA 02110-1301, USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "ingenic_usb.h"
|
||||||
|
|
||||||
#include "usb.h"
|
|
||||||
#include "usb_boot_defines.h"
|
#include "usb_boot_defines.h"
|
||||||
#include <usb.h>
|
#include <usb.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
Loading…
Reference in New Issue
Block a user