1
0
mirror of git://projects.qi-hardware.com/xburst-tools.git synced 2025-04-21 12:27:27 +03:00

renamed 'xburst-tools' utility back to 'usbboot'

This commit is contained in:
Wolfgang Spraul
2009-06-30 13:49:11 +08:00
parent aa534592e2
commit 6d4212b643
61 changed files with 55 additions and 50 deletions

8
usbboot/src/.gitignore vendored Normal file
View File

@@ -0,0 +1,8 @@
.deps
cmd.o
command_line.o
inflash
inflash_version.h
ingenic_cfg.o
ingenic_usb.o
main.o

28
usbboot/src/Makefile.am Normal file
View File

@@ -0,0 +1,28 @@
AM_CFLAGS = -pedantic -Wall -W -O1 -g3 -std=gnu99 -lusb -lconfuse
BUILD_BRANCH := $(shell git branch | grep ^\* | cut -d' ' -f2)
BUILD_HEAD := $(shell git show --pretty=oneline | head -n1 | cut -d' ' -f1 | cut -b1-16)
BUILD_VERSION := ${BUILD_BRANCH}_${BUILD_HEAD}
xburst_tools_version.h:
echo -e '#ifndef XBURST_TOOLS_VERSION' \
'\n#define XBURST_TOOLS_VERSION "20090630-1"' \
'\n#endif' > xburst_tools_version.h
BUILT_SOURCES = xburst_tools_version.h
bin_PROGRAMS = usbboot
usbboot_SOURCES = cmd.c command_line.c ingenic_cfg.c \
ingenic_usb.c main.c
prefix = /usr
datadir = /usr/share/xburst_tools
data_DATA = ../xburst_stage1/xburst_stage1.bin \
../xburst_stage2/xburst_stage2.bin \
usbboot.cfg
EXTRA_DIST = $(datadir)
../xburst_stage1/xburst_stage1.bin:
$(MAKE) -C ../xburst_stage1
../xburst_stage2/xburst_stage2.bin:
$(MAKE) -C ../xburst_stage2

931
usbboot/src/cmd.c Normal file
View File

@@ -0,0 +1,931 @@
/*
* Authors: Marek Lindner <lindner_marek@yahoo.de>
* 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
* as published by the Free Software Foundation; either version
* 3 of the License, or (at your option) any later version.
*/
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <ctype.h>
#include "cmd.h"
#include "ingenic_cfg.h"
#include "ingenic_usb.h"
#include "usb_boot_defines.h"
extern int com_argc;
extern char com_argv[MAX_ARGC][MAX_COMMAND_LENGTH];
struct ingenic_dev ingenic_dev;
struct hand hand;
struct sdram_in sdram_in;
struct nand_in nand_in;
static struct nand_out nand_out;
unsigned int total_size;
unsigned char code_buf[4 * 512 * 1024];
unsigned char check_buf[4 * 512 * 1024];
unsigned char cs[16];
unsigned char ret[8];
static const char IMAGE_TYPE[][30] = {
"with oob and ecc",
"with oob and without ecc",
"without oob",
};
static int load_file(struct ingenic_dev *ingenic_dev, const char *file_path)
{
struct stat fstat;
int fd, status, res = -1;
status = stat(file_path, &fstat);
if (status < 0) {
fprintf(stderr, "Error - can't get file size from '%s': %s\n",
file_path, strerror(errno));
goto out;
}
ingenic_dev->file_len = fstat.st_size;
ingenic_dev->file_buff = code_buf;
fd = open(file_path, O_RDONLY);
if (fd < 0) {
fprintf(stderr, "Error - can't open file '%s': %s\n",
file_path, strerror(errno));
goto out;
}
status = read(fd, ingenic_dev->file_buff, ingenic_dev->file_len);
if (status < ingenic_dev->file_len) {
fprintf(stderr, "Error - can't read file '%s': %s\n",
file_path, strerror(errno));
goto close;
}
/* write args to code */
memcpy(ingenic_dev->file_buff + 8, &hand.fw_args,
sizeof(struct fw_args));
res = 1;
close:
close(fd);
out:
return res;
}
/* after upload stage2. must init device */
void init_cfg()
{
if (usb_get_ingenic_cpu(&ingenic_dev) < 3) {
printf(" XBurst CPU not booted yet, boot it first!\n");
return;
}
ingenic_dev.file_buff = &hand;
ingenic_dev.file_len = sizeof(hand);
if (usb_send_data_to_ingenic(&ingenic_dev) != 1)
goto xout;
if (usb_ingenic_configration(&ingenic_dev, DS_hand) != 1)
goto xout;
if (usb_read_data_from_ingenic(&ingenic_dev, ret, 8) != 1)
goto xout;
printf(" Configuring XBurst CPU succeeded.\n");
return;
xout:
printf("Configuring XBurst CPU failed.\n");
}
int boot(char *stage1_path, char *stage2_path){
int status;
status = usb_get_ingenic_cpu(&ingenic_dev);
switch (status) {
case 1: /* Jz4740v1 */
status = 0;
hand.fw_args.cpu_id = 0x4740;
break;
case 2: /* Jz4750v1 */
status = 0;
hand.fw_args.cpu_id = 0x4750;
break;
case 3: /* Boot4740 */
status = 1;
hand.fw_args.cpu_id = 0x4740;
break;
case 4: /* Boot4750 */
status = 1;
hand.fw_args.cpu_id = 0x4750;
break;
default:
return 1;
}
if (status) {
printf(" Already booted.\n");
return 1;
} else {
printf(" CPU not yet booted, now booting...\n");
/* now we upload the boot stage1 */
printf(" Loading stage1 from '%s'\n", stage1_path);
if (load_file(&ingenic_dev, stage1_path) < 1)
return -1;
if (usb_ingenic_upload(&ingenic_dev, 1) < 1)
return -1;
/* now we upload the boot stage2 */
usleep(100);
printf(" Loading stage2 from '%s'\n", stage2_path);
if (load_file(&ingenic_dev, stage2_path) < 1)
return -1;
if (usb_ingenic_upload(&ingenic_dev, 2) < 1)
return -1;
printf(" Booted successfully!\n");
}
usleep(100);
init_cfg();
return 1;
}
/* nand function */
int error_check(unsigned char *org,unsigned char * obj,unsigned int size)
{
unsigned int i;
printf(" Comparing %d bytes - ", size);
for (i = 0; i < size; i++) {
if (org[i] != obj[i]) {
unsigned int s = (i < 8) ? i : i - 8; // start_dump
printf("FAIL at off %d, wrote 0x%x, read 0x%x\n", i, org[i], obj[i]);
printf(" off %d write: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", s,
org[s], org[s+1], org[s+2], org[s+3], org[s+4], org[s+5], org[s+6], org[s+7],
org[s+8], org[s+9], org[s+10], org[s+11], org[s+12], org[s+13], org[s+14], org[s+15]);
printf(" off %d read: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", s,
obj[s], obj[s+1], obj[s+2], obj[s+3], obj[s+4], obj[s+5], obj[s+6], obj[s+7],
obj[s+8], obj[s+9], obj[s+10], obj[s+11], obj[s+12], obj[s+13], obj[s+14], obj[s+15]);
return 0;
}
}
printf("SUCCESS\n");
return 1;
}
int nand_markbad(struct nand_in *nand_in)
{
if (usb_get_ingenic_cpu(&ingenic_dev) < 3) {
printf(" Device unboot! Boot it first!\n");
return -1;
}
printf(" mark bad block : %d\n",nand_in->start);
usb_send_data_address_to_ingenic(&ingenic_dev, nand_in->start);
usb_ingenic_nand_ops(&ingenic_dev, NAND_MARK_BAD);
usb_read_data_from_ingenic(&ingenic_dev, ret, 8);
printf(" Mark bad block at %d\n",((ret[3] << 24) |
(ret[2] << 16) |
(ret[1] << 8) |
(ret[0] << 0)) / hand.nand_ppb);
return 0;
}
int nand_program_check(struct nand_in *nand_in,
struct nand_out *nand_out,
unsigned int *start_page)
{
unsigned int i, page_num, cur_page = -1;
unsigned short temp;
printf(" Writing NAND page %d len %d...\n", nand_in->start, nand_in->length);
if (nand_in->length > (unsigned int)MAX_TRANSFER_SIZE) {
printf(" Buffer size too long!\n");
return -1;
}
#ifdef CONFIG_NAND_OUT
unsigned char status_buf[32];
nand_out->status = status_buf;
for (i = 0; i < nand_in->max_chip; i++)
(nand_out->status)[i] = 0; /* set all status to fail */
#endif
if (usb_get_ingenic_cpu(&ingenic_dev) < 3) {
printf(" Device unboot! Boot it first!\n");
return -1;
}
ingenic_dev.file_buff = nand_in->buf;
ingenic_dev.file_len = nand_in->length;
usb_send_data_to_ingenic(&ingenic_dev);
for (i = 0; i < nand_in->max_chip; i++) {
if ((nand_in->cs_map)[i]==0)
continue;
if (nand_in->option == NO_OOB) {
page_num = nand_in->length / hand.nand_ps;
if ((nand_in->length % hand.nand_ps) !=0)
page_num++;
} else {
page_num = nand_in->length /
(hand.nand_ps + hand.nand_os);
if ((nand_in->length% (hand.nand_ps + hand.nand_os)) !=0)
page_num++;
}
temp = ((nand_in->option << 12) & 0xf000) +
((i<<4) & 0xff0) + NAND_PROGRAM;
usb_send_data_address_to_ingenic(&ingenic_dev, nand_in->start);
usb_send_data_length_to_ingenic(&ingenic_dev, page_num);
usb_ingenic_nand_ops(&ingenic_dev, temp);
usb_read_data_from_ingenic(&ingenic_dev, ret, 8);
printf(" Finish! (len %d start_page %d page_num %d)", nand_in->length, nand_in->start, page_num);
usb_send_data_address_to_ingenic(&ingenic_dev, nand_in->start);
/* Read back to check! */
usb_send_data_length_to_ingenic(&ingenic_dev, page_num);
switch (nand_in->option) {
case OOB_ECC:
temp = ((OOB_ECC << 12) & 0xf000) +
((i << 4) & 0xff0) + NAND_READ;
usb_ingenic_nand_ops(&ingenic_dev, temp);
printf("Checking %d bytes...", nand_in->length);
usb_read_data_from_ingenic(&ingenic_dev, check_buf,
page_num * (hand.nand_ps + hand.nand_os));
usb_read_data_from_ingenic(&ingenic_dev, ret, 8);
break;
case OOB_NO_ECC: /* do not support data verify */
temp = ((OOB_NO_ECC << 12) & 0xf000) +
((i << 4) & 0xff0) + NAND_READ;
usb_ingenic_nand_ops(&ingenic_dev, temp);
printf("Checking %d bytes...", nand_in->length);
usb_read_data_from_ingenic(&ingenic_dev, check_buf,
page_num * (hand.nand_ps + hand.nand_os));
usb_read_data_from_ingenic(&ingenic_dev, ret, 8);
break;
case NO_OOB:
temp = ((NO_OOB << 12) & 0xf000) +
((i << 4) & 0xff0) + NAND_READ;
usb_ingenic_nand_ops(&ingenic_dev, temp);
printf("Checking %d bytes...", nand_in->length);
usb_read_data_from_ingenic(&ingenic_dev, check_buf,
page_num * hand.nand_ps);
usb_read_data_from_ingenic(&ingenic_dev, ret, 8);
break;
default:
;
}
cur_page = (ret[3] << 24) | (ret[2] << 16) | (ret[1] << 8) |
(ret[0] << 0);
if (nand_in->start < 1 &&
hand.nand_ps == 4096 &&
hand.fw_args.cpu_id == 0x4740) {
/* (nand_out->status)[i] = 1; */
printf(" no check! End at %d ",cur_page);
continue;
}
if (nand_in->check(nand_in->buf, check_buf, nand_in->length)) {
/* (nand_out->status)[i] = 1; */
printf(" pass! End at %d ",cur_page);
} else {
/* (nand_out->status)[i] = 0; */
printf(" fail! End at %d ",cur_page);
struct nand_in bad;
// tbd: doesn't the other side skip bad blocks too? Can we just deduct 1 from cur_page?
// tbd: why do we only mark a block as bad if the last page in the block was written?
bad.start = (cur_page - 1) / hand.nand_ppb;
if (cur_page % hand.nand_ppb == 0)
nand_markbad(&bad);
}
}
*start_page = cur_page;
return 0;
}
int nand_erase(struct nand_in *nand_in)
{
unsigned int start_blk, blk_num, end_block;
int i;
start_blk = nand_in->start;
blk_num = nand_in->length;
if (start_blk > (unsigned int)NAND_MAX_BLK_NUM) {
printf(" Start block number overflow!\n");
return -1;
}
if (blk_num > (unsigned int)NAND_MAX_BLK_NUM) {
printf(" Length block number overflow!\n");
return -1;
}
if (usb_get_ingenic_cpu(&ingenic_dev) < 3) {
printf(" Device unboot! Boot it first!\n");
return -1;
}
for (i = 0; i < nand_in->max_chip; i++) {
if ((nand_in->cs_map)[i]==0)
continue;
printf(" Erasing No.%d device No.%d flash (start_blk %u blk_num %u)......\n",
nand_in->dev, i, start_blk, blk_num);
usb_send_data_address_to_ingenic(&ingenic_dev, start_blk);
usb_send_data_length_to_ingenic(&ingenic_dev, blk_num);
unsigned short temp = ((i << 4) & 0xff0) + NAND_ERASE;
usb_ingenic_nand_ops(&ingenic_dev, temp);
usb_read_data_from_ingenic(&ingenic_dev, ret, 8);
printf(" Finish!");
}
end_block = ((ret[3] << 24) |
(ret[2] << 16) |
(ret[1] << 8) |
(ret[0] << 0)) / hand.nand_ppb;
printf(" Return: %02x %02x %02x %02x %02x %02x %02x %02x (position %d)\n", ret[0], ret[1], ret[2], ret[3], ret[4], ret[5], ret[6], ret[7], end_block);
if (!hand.nand_force_erase) {
/* not force erase, show bad block infomation */
printf(" There are marked bad blocks: %d\n",
end_block - start_blk - blk_num );
} else {
/* force erase, no bad block infomation can show */
printf(" Force erase, no bad block infomation!\n" );
}
return 1;
}
int nand_program_file(struct nand_in *nand_in,
struct nand_out *nand_out,
char *fname)
{
int flen, m, j, k;
unsigned int start_page = 0, page_num, code_len, offset, transfer_size;
int fd, status;
struct stat fstat;
struct nand_in n_in;
struct nand_out n_out;
#ifdef CONFIG_NAND_OUT
unsigned char status_buf[32];
nand_out->status = status_buf;
for (i=0; i<nand_in->max_chip; i++)
(nand_out->status)[i] = 0; /* set all status to fail */
#endif
status = stat(fname, &fstat);
if (status < 0) {
fprintf(stderr, "Error - can't get file size from '%s': %s\n",
fname, strerror(errno));
return -1;
}
flen = fstat.st_size;
fd = open(fname, O_RDONLY);
if (fd < 0) {
fprintf(stderr, "Error - can't open file '%s': %s\n",
fname, strerror(errno));
return -1;
}
printf(" Programing No.%d device, flen %d, start page %d...\n",nand_in->dev, flen, nand_in->start);
n_in.start = nand_in->start / hand.nand_ppb;
if (nand_in->option == NO_OOB) {
if (flen % (hand.nand_ppb * hand.nand_ps) == 0)
n_in.length = flen / (hand.nand_ps * hand.nand_ppb);
else
n_in.length = flen / (hand.nand_ps * hand.nand_ppb) + 1;
} else {
if (flen % (hand.nand_ppb * (hand.nand_ps + hand.nand_os)) == 0)
n_in.length = flen /
((hand.nand_ps + hand.nand_os) * hand.nand_ppb);
else
n_in.length = flen /
((hand.nand_ps + hand.nand_os) * hand.nand_ppb)
+ 1;
}
/* printf(" length %d flen %d\n", n_in.length, flen); */
n_in.cs_map = nand_in->cs_map;
n_in.dev = nand_in->dev;
n_in.max_chip = nand_in->max_chip;
if (nand_erase(&n_in) != 1)
return -1;
if (nand_in->option == NO_OOB)
transfer_size = (hand.nand_ppb * hand.nand_ps);
else
transfer_size = (hand.nand_ppb * (hand.nand_ps + hand.nand_os));
m = flen / transfer_size;
j = flen % transfer_size;
printf(" Size to send %d, transfer_size %d\n", flen, transfer_size);
printf(" Image type : %s\n", IMAGE_TYPE[nand_in->option]);
printf(" It will cause %d times buffer transfer.\n", j == 0 ? m : m + 1);
#ifdef CONFIG_NAND_OUT
for (i = 0; i < nand_in->max_chip; i++)
(nand_out->status)[i] = 1; /* set all status to success! */
#endif
offset = 0;
for (k = 0; k < m; k++) {
if (nand_in->option == NO_OOB)
page_num = transfer_size / hand.nand_ps;
else
page_num = transfer_size / (hand.nand_ps + hand.nand_os);
code_len = transfer_size;
status = read(fd, code_buf, code_len);
if (status < code_len) {
fprintf(stderr, "Error - can't read file '%s': %s\n",
fname, strerror(errno));
return -1;
}
nand_in->length = code_len; /* code length,not page number! */
nand_in->buf = code_buf;
if (nand_program_check(nand_in, &n_out, &start_page) == -1)
return -1;
if (start_page - nand_in->start > hand.nand_ppb)
printf(" Skip a old bad block !\n");
nand_in->start = start_page;
#ifdef CONFIG_NAND_OUT
for (i = 0; i < nand_in->max_chip; i++) {
(nand_out->status)[i] = (nand_out->status)[i] *
(n_out.status)[i];
}
#endif
offset += code_len ;
}
if (j) {
code_len = j;
if (j % hand.nand_ps)
j += hand.nand_ps - (j % hand.nand_ps);
memset(code_buf, 0, j); /* set all to null */
status = read(fd, code_buf, code_len);
if (status < code_len) {
fprintf(stderr, "Error - can't read file '%s': %s\n",
fname, strerror(errno));
return -1;
}
nand_in->length = j;
nand_in->buf = code_buf;
if (nand_program_check(nand_in, &n_out, &start_page) == -1)
return -1;
if (start_page - nand_in->start > hand.nand_ppb)
printf(" Skip a old bad block !");
#ifdef CONFIG_NAND_OUT
for (i=0; i < nand_in->max_chip; i++) {
(nand_out->status)[i] = (nand_out->status)[i] *
(n_out.status)[i];
}
#endif
}
close(fd);
return 1;
}
int nand_program_file_planes(struct nand_in *nand_in,
struct nand_out *nand_out,
char *fname)
{
printf(" not implement yet !\n");
return -1;
}
int init_nand_in(void)
{
nand_in.buf = code_buf;
nand_in.check = error_check;
nand_in.dev = 0;
nand_in.cs_map = cs;
memset(nand_in.cs_map, 0, MAX_DEV_NUM);
nand_in.max_chip = 16;
return 0;
}
int nand_prog(void)
{
char *image_file;
char *help = " Usage: nprog (1) (2) (3) (4) (5)\n"
" (1)\tstart page number\n"
" (2)\timage file name\n"
" (3)\tdevice index number\n"
" (4)\tflash index number\n"
" (5) image type must be:\n"
" \t-n:\tno oob\n"
" \t-o:\twith oob no ecc\n"
" \t-e:\twith oob and ecc\n";
if (com_argc != 6) {
printf(" not enough argument.\n");
printf("%s", help);
return 0;
}
init_nand_in();
nand_in.start = atoi(com_argv[1]);
image_file = com_argv[2];
nand_in.dev = atoi(com_argv[3]);
(nand_in.cs_map)[atoi(com_argv[4])] = 1;
if (!strcmp(com_argv[5], "-e"))
nand_in.option = OOB_ECC;
else if (!strcmp(com_argv[5], "-o"))
nand_in.option = OOB_NO_ECC;
else if (!strcmp(com_argv[5], "-n"))
nand_in.option = NO_OOB;
else
printf("%s", help);
if (hand.nand_plane > 1)
nand_program_file_planes(&nand_in, &nand_out, image_file);
else
nand_program_file(&nand_in, &nand_out, image_file);
#ifdef CONFIG_NAND_OUT
printf(" Flash check result:\n");
int i;
for (i = 0; i < 16; i++)
printf(" %d", (nand_out.status)[i]);
#endif
return 1;
}
int nand_query(void)
{
int i;
unsigned char csn;
if (com_argc < 3) {
printf(" Usage: nquery (1) (2)\n"
" (1):device index number\n"
" (2):flash index number\n");
return -1;
}
init_nand_in();
nand_in.dev = atoi(com_argv[1]);
(nand_in.cs_map)[atoi(com_argv[2])] = 1;
for (i = 0; i < nand_in.max_chip; i++) {
if ((nand_in.cs_map)[i] != 0)
break;
}
if (i >= nand_in.max_chip)
return -1;
if (usb_get_ingenic_cpu(&ingenic_dev) < 3) {
printf(" Device unboot! Boot it first!\n");
return -1;
}
csn = i;
printf(" ID of No.%d device No.%d flash: \n", nand_in.dev, csn);
unsigned short ops = ((csn << 4) & 0xff0) + NAND_QUERY;
usb_ingenic_nand_ops(&ingenic_dev, ops);
usb_read_data_from_ingenic(&ingenic_dev, ret, 8);
printf(" Vendor ID :0x%x \n",(unsigned char)ret[0]);
printf(" Product ID :0x%x \n",(unsigned char)ret[1]);
printf(" Chip ID :0x%x \n",(unsigned char)ret[2]);
printf(" Page ID :0x%x \n",(unsigned char)ret[3]);
printf(" Plane ID :0x%x \n",(unsigned char)ret[4]);
usb_read_data_from_ingenic(&ingenic_dev, ret, 8);
printf(" Operation status: Success!\n");
return 1;
}
int nand_read(int mode)
{
unsigned int i,j;
unsigned int start_addr, length, page_num;
unsigned char csn;
unsigned short temp = 0;
unsigned ram_addr = 0;
if (com_argc < 5) {
printf(" Usage: nread (1) (2) (3) (4)\n"
" 1:start page number\n"
" 2:length in byte\n"
" 3:device index number\n"
" 4:flash index number\n"
" 5:start SDRAM address\n");
return -1;
}
init_nand_in();
if (atoi(com_argv[4]) >= MAX_DEV_NUM) {
printf(" Flash index number overflow!\n");
return -1;
}
(nand_in.cs_map)[atoi(com_argv[4])] = 1;
nand_in.start = atoi(com_argv[1]);
nand_in.length= atoi(com_argv[2]);
nand_in.dev = atoi(com_argv[3]);
if (com_argc = 6) {
ram_addr = strtoul(com_argv[5], NULL, 0);
printf("==%s==", com_argv[5]);
}
start_addr = nand_in.start;
length = nand_in.length;
if (start_addr > NAND_MAX_PAGE_NUM || length > NAND_MAX_PAGE_NUM ) {
printf(" Page number overflow!\n");
return -1;
}
if (usb_get_ingenic_cpu(&ingenic_dev) < 3) {
printf(" Device unboot! Boot it first!\n");
return -1;
}
for (i = 0; i < nand_in.max_chip; i++)
if ((nand_in.cs_map)[i] != 0)
break;
if (i >= nand_in.max_chip) return 1;
csn = i;
printf(" Reading from No.%d device No.%d flash....\n",nand_in.dev,csn);
page_num = length / hand.nand_ps +1;
switch(mode) {
case NAND_READ:
temp = ((NO_OOB<<12) & 0xf000) + ((csn<<4) & 0xff0) + NAND_READ;
break;
case NAND_READ_OOB:
temp = ((csn<<4) & 0xff0) + NAND_READ_OOB;
break;
case NAND_READ_RAW:
temp = ((NO_OOB<<12) & 0xf000) + ((csn<<4) & 0xff0) +
NAND_READ_RAW;
break;
case NAND_READ_TO_RAM:
temp = ((NO_OOB<<12) & 0xf000) + ((csn<<4) & 0xff0) +
NAND_READ_TO_RAM;
printf(" Reading nand to RAM: 0x%x\n", ram_addr);
usb_ingenic_start(&ingenic_dev, VR_PROGRAM_START1, ram_addr);
break;
default:
printf(" unknow mode!\n");
return -1;
}
usb_send_data_address_to_ingenic(&ingenic_dev, start_addr);
usb_send_data_length_to_ingenic(&ingenic_dev, page_num);
usb_ingenic_nand_ops(&ingenic_dev, temp);
usb_read_data_from_ingenic(&ingenic_dev, nand_in.buf, page_num * hand.nand_ps);
for (j = 0; j < length; j++) {
if (j % 16 == 0)
printf("\n 0x%08x : ",j);
printf("%02x ",(nand_in.buf)[j]);
}
printf("\n");
usb_read_data_from_ingenic(&ingenic_dev, ret, 8);
printf(" Operation end position : %d \n",
(ret[3]<<24)|(ret[2]<<16)|(ret[1]<<8)|(ret[0]<<0));
return 1;
}
int debug_memory(int obj, unsigned int start, unsigned int size)
{
unsigned int buffer[8],tmp;
tmp = usb_get_ingenic_cpu(&ingenic_dev);
if (tmp > 2) {
printf(" This command only run under UNBOOT state!\n");
return -1;
}
switch (tmp) {
case 1:
tmp = 0;
hand.fw_args.cpu_id = 0x4740;
break;
case 2:
tmp = 0;
hand.fw_args.cpu_id = 0x4750;
break;
}
hand.fw_args.debug_ops = 1;/* tell device it's memory debug */
hand.fw_args.start = start;
if (size == 0)
hand.fw_args.size = total_size;
else
hand.fw_args.size = size;
printf(" Now test memory from 0x%x to 0x%x: \n",
start, start + hand.fw_args.size);
if (load_file(&ingenic_dev, STAGE1_FILE_PATH) < 1)
return -1;
if (usb_ingenic_upload(&ingenic_dev, 1) < 1)
return -1;
usleep(100);
usb_read_data_from_ingenic(&ingenic_dev, buffer, 8);
if (buffer[0] != 0)
printf(" Test memory fail! Last error address is 0x%x !\n",
buffer[0]);
else
printf(" Test memory pass!\n");
return 1;
}
int debug_gpio(int obj, unsigned char ops, unsigned char pin)
{
unsigned int tmp;
tmp = usb_get_ingenic_cpu(&ingenic_dev);
if (tmp > 2) {
printf(" This command only run under UNBOOT state!\n");
return -1;
}
switch (tmp) {
case 1:
tmp = 0;
hand.fw_args.cpu_id = 0x4740;
if (pin > 124) {
printf(" Jz4740 has 124 GPIO pin in all!\n");
return -1;
}
break;
case 2:
tmp = 0;
hand.fw_args.cpu_id = 0x4750;
if (pin > 178) {
printf(" Jz4750 has 178 GPIO pin in all!\n");
return -1;
}
break;
}
hand.fw_args.debug_ops = ops;/* tell device it's memory debug */
hand.fw_args.pin_num = pin;
if (ops == 2)
printf(" GPIO %d set!\n",pin);
else
printf(" GPIO %d clear!\n",pin);
if (load_file(&ingenic_dev, STAGE1_FILE_PATH) < 1)
return -1;
if (usb_ingenic_upload(&ingenic_dev, 1) < 1)
return -1;
return 0;
}
int debug_go(void)
{
unsigned int addr,obj;
if (com_argc<3) {
printf(" Usage: go (1) (2) \n"
" 1:start SDRAM address\n"
" 2:device index number\n");
return 0;
}
addr = strtoul(com_argv[1], NULL, 0);
obj = atoi(com_argv[2]);
printf(" Executing No.%d device at address 0x%x\n", obj, addr);
if (usb_ingenic_start(&ingenic_dev, VR_PROGRAM_START2, addr) < 1)
return -1;
return 1;
}
int sdram_load(struct sdram_in *sdram_in)
{
if (usb_get_ingenic_cpu(&ingenic_dev) < 3) {
printf(" Device unboot! Boot it first!\n");
return -1;
}
if (sdram_in->length > (unsigned int) MAX_LOAD_SIZE) {
printf(" Image length too long!\n");
return -1;
}
ingenic_dev.file_buff = sdram_in->buf;
ingenic_dev.file_len = sdram_in->length;
usb_send_data_to_ingenic(&ingenic_dev);
usb_send_data_address_to_ingenic(&ingenic_dev, sdram_in->start);
usb_send_data_length_to_ingenic(&ingenic_dev, sdram_in->length);
usb_ingenic_sdram_ops(&ingenic_dev, sdram_in);
usb_read_data_from_ingenic(&ingenic_dev, ret, 8);
printf(" Load last address at 0x%x\n",
((ret[3]<<24)|(ret[2]<<16)|(ret[1]<<8)|(ret[0]<<0)));
return 1;
}
int sdram_load_file(struct sdram_in *sdram_in, char *file_path)
{
struct stat fstat;
unsigned int flen,m,j,offset,k;
int fd, status, res = -1;
status = stat(file_path, &fstat);
if (status < 0) {
fprintf(stderr, "Error - can't get file size from '%s': %s\n",
file_path, strerror(errno));
goto out;
}
flen = fstat.st_size;
fd = open(file_path, O_RDONLY);
if (fd < 0) {
fprintf(stderr, "Error - can't open file '%s': %s\n",
file_path, strerror(errno));
goto out;
}
m = flen / MAX_LOAD_SIZE;
j = flen % MAX_LOAD_SIZE;
offset = 0;
printf(" Total size to send in byte is :%d\n", flen);
printf(" Loading data to SDRAM :\n");
for (k = 0; k < m; k++) {
status = read(fd, sdram_in->buf, MAX_LOAD_SIZE);
if (status < MAX_LOAD_SIZE) {
fprintf(stderr, "Error - can't read file '%s': %s\n",
file_path, strerror(errno));
goto close;
}
sdram_in->length = MAX_LOAD_SIZE;
if (sdram_load(sdram_in) < 1)
goto close;
sdram_in->start += MAX_LOAD_SIZE;
if ( k % 60 == 0)
printf(" 0x%x \n", sdram_in->start);
}
if (j) {
if (j % 4 !=0)
j += 4 - (j % 4);
status = read(fd, sdram_in->buf, j);
if (status < j) {
fprintf(stderr, "Error - can't read file '%s': %s\n",
file_path, strerror(errno));
goto close;
}
sdram_in->length = j;
if (sdram_load(sdram_in) < 1)
goto close;
}
res = 1;
close:
close(fd);
out:
return res;
}

28
usbboot/src/cmd.h Normal file
View File

@@ -0,0 +1,28 @@
/*
* Authors: 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
* as published by the Free Software Foundation; either version
* 3 of the License, or (at your option) any later version.
*/
#ifndef __CMD_H__
#define __CMD_H__
#include "usb_boot_defines.h"
#define COMMAND_NUM 31
#define MAX_ARGC 10
#define MAX_COMMAND_LENGTH 100
int boot(char *stage1_path, char *stage2_path);
int init_nand_in();
int nand_prog(void);
int nand_query(void);
int nand_erase(struct nand_in *nand_in);
int debug_memory(int obj, unsigned int start, unsigned int size);
int debug_gpio(int obj, unsigned char ops, unsigned char pin);
int debug_go(void);
#endif /* __CMD_H__ */

317
usbboot/src/command_line.c Normal file
View File

@@ -0,0 +1,317 @@
/*
* Authors: 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
* as published by the Free Software Foundation; either version
* 3 of the License, or (at your option) any later version.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "usb_boot_defines.h"
#include "ingenic_usb.h"
#include "cmd.h"
#include "xburst_tools_version.h"
extern struct nand_in nand_in;
extern struct sdram_in sdram_in;
extern unsigned char code_buf[4 * 512 * 1024];
int com_argc;
char com_argv[MAX_ARGC][MAX_COMMAND_LENGTH];
static const char COMMAND[][COMMAND_NUM]=
{
"",
"query",
"querya",
"erase",
"read",
"prog",
"nquery",
"nerase",
"nread",
"nreadraw",
"nreadoob", /* index 10 */
"nprog",
"help",
"version",
"go",
"fconfig",
"exit",
"readnand",
"gpios",
"gpioc",
"boot", /* index 20 */
"list",
"select",
"unselect",
"chip",
"unchip",
"nmark",
"nmake",
"load",
"memtest",
"run"
};
static int handle_help(void)
{
printf(" command support in current version:\n"
/* " query" */
/* " querya" */
/* " erase" */
/* " read" */
/* " prog" */
" nquery query NAND flash info\n"
" nerase erase NAND flash\n"
" nread read NAND flash data with checking bad block and ECC\n"
" nreadraw read NAND flash data without checking bad block and ECC\n"
" nreadoo read NAND flash oob without checking bad block and ECC\n" /* index 10 */
" nprog program NAND flash with data and ECC\n"
" help print this help\n"
" version show current USB Boot software version\n"
" go execute program in SDRAM\n"
" fconfig set USB Boot config file(not implement)\n"
" exit quit from telnet session\n"
" readnand read data from nand flash and store to SDRAM\n"
" gpios set one GPIO to high level\n"
" gpioc set one GPIO to low level\n"
" boot boot device and make it in stage2\n" /* index 20 */
" list show current device number can connect(not implement)\n"
/* " select" */
/* " unselect" */
/* " chip" */
/* " unchip" */
" nmark mark a bad block in NAND flash\n"
" nmake read all data from nand flash and store to file(not implement)\n"
" load load file data to SDRAM\n"
" memtest do SDRAM test\n"
" run run command script in file(implement by -c args)\n"
" sdprog program SD card(not implement)\n"
" sdread read data from SD card(not implement)\n");
return 1;
}
static int handle_version(void)
{
printf(" USB Boot Software current version: %s\n", XBURST_TOOLS_VERSION);
return 1;
}
/* need transfer two para :blk_num ,start_blk */
int handle_nerase(void)
{
if (com_argc < 5) {
printf(" Usage: nerase (1) (2) (3) (4)\n"
" 1:start block number\n"
" 2:block length\n"
" 3:device index number\n"
" 4:flash chip index number\n");
return -1;
}
init_nand_in();
nand_in.start = atoi(com_argv[1]);
nand_in.length = atoi(com_argv[2]);
nand_in.dev = atoi(com_argv[3]);
if (atoi(com_argv[4]) >= MAX_DEV_NUM) {
printf(" Flash index number overflow!\n");
return -1;
}
(nand_in.cs_map)[atoi(com_argv[4])] = 1;
if (nand_erase(&nand_in) < 1)
return -1;
return 1;
}
int handle_nmark(void)
{
if (com_argc < 4) {
printf(" Usage: nerase (1) (2) (3)\n"
" 1:bad block number\n"
" 2:device index number\n"
" 3:flash chip index number\n");
return -1;
}
init_nand_in();
nand_in.start = atoi(com_argv[1]);
nand_in.dev = atoi(com_argv[2]);
if (atoi(com_argv[3])>=MAX_DEV_NUM) {
printf(" Flash index number overflow!\n");
return -1;
}
(nand_in.cs_map)[atoi(com_argv[3])] = 1;
nand_markbad(&nand_in);
return 1;
}
int handle_memtest(void)
{
unsigned int start, size;
if (com_argc != 2 && com_argc != 4)
{
printf(" Usage: memtest (1) [2] [3]\n"
" 1:device index number\n"
" 2:SDRAM start address\n"
" 3:test size\n");
return -1;
}
if (com_argc == 4) {
start = strtoul(com_argv[2], NULL, 0);
size = strtoul(com_argv[3], NULL, 0);
} else {
start = 0;
size = 0;
}
debug_memory(atoi(com_argv[1]), start, size);
return 1;
}
int handle_gpio(int mode)
{
if (com_argc < 3) {
printf(" Usage:"
" gpios (1) (2)\n"
" 1:GPIO pin number\n"
" 2:device index number\n");
return -1;
}
debug_gpio(atoi(com_argv[2]), mode, atoi(com_argv[1]));
return 1;
}
int handle_load(void)
{
if (com_argc<4) {
printf(" Usage:"
" load (1) (2) (3) \n"
" 1:SDRAM start address\n"
" 2:image file name\n"
" 3:device index number\n");
return -1;
}
sdram_in.start=strtoul(com_argv[1], NULL, 0);
printf(" start:::::: 0x%x\n", sdram_in.start);
sdram_in.dev = atoi(com_argv[3]);
sdram_in.buf = code_buf;
sdram_load_file(&sdram_in, com_argv[2]);
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]=' ';
if (buf[0] == '\n')
return 0;
for (k = 0; k <= L; k++) {
if (*buf == ' ' || *buf == '\n') {
while ( *(++buf) == ' ' );
com_argv[i][j] = '\0';
i++;
if (i > MAX_ARGC)
return COMMAND_NUM + 1;
j = 0;
continue;
} else {
com_argv[i][j] = *buf;
j++;
if (j > MAX_COMMAND_LENGTH)
return COMMAND_NUM + 1;
}
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); /* get the command index */
switch (cmd) {
case 0:
break;
case 6:
nand_query();
break;
case 7:
handle_nerase();
break;
case 8: /* nread */
nand_read(NAND_READ);
break;
case 9: /* nreadraw */
nand_read(NAND_READ_RAW);
break;
case 10: /* nreadoob */
nand_read(NAND_READ_OOB);
break;
case 11:
nand_prog();
break;
case 12:
handle_help();
break;
case 13:
handle_version();
break;
case 14:
debug_go();
break;
case 16: /* exit */
printf(" exiting usbboot software\n");
return -1; /* return -1 to break the main.c while
* then run usb_ingenic_cleanup*/
/*case 17:
nand_read(NAND_READ_TO_RAM); */
break;
case 18:
handle_gpio(2);
break;
case 19:
handle_gpio(3);
break;
case 20:
boot(STAGE1_FILE_PATH, STAGE2_FILE_PATH);
break;
case 26:
handle_nmark();
break;
case 28:
handle_load();
break;
case 29:
handle_memtest();
break;
default:
printf(" command not support or input error!\n");
break;
}
return 1;
}

View File

@@ -0,0 +1,16 @@
/*
* Authors: 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
* as published by the Free Software Foundation; either version
* 3 of the License, or (at your option) any later version.
*/
#ifndef __COMMAND_LINE_H__
#define __COMMAND_LINE_H__
int command_input(char *buf);
int command_handle(char *buf);
#endif /* __COMMAND_LINE_H__ */

204
usbboot/src/ingenic_cfg.c Normal file
View File

@@ -0,0 +1,204 @@
/*
* Authors: Marek Lindner <lindner_marek@yahoo.de>
*
* 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.
*/
#include <errno.h>
#include <confuse.h>
#include <unistd.h>
#include <string.h>
#include "ingenic_cfg.h"
#include "usb_boot_defines.h"
extern unsigned int total_size;
int hand_init_def(struct hand *hand)
{
/* nand flash info */
/* hand.nand_start=0; */ /* important !!!! */
hand->pt = JZ4740; /* cpu type */
hand->nand_bw = 8;
hand->nand_rc = 3;
hand->nand_ps = 2048;
hand->nand_os = 64;
hand->nand_ppb = 64;
hand->nand_eccpos = 6;
hand->nand_bbpage = 0;
hand->nand_bbpos = 0;
hand->nand_force_erase = 0;
/* hand.nand_ids=0; */ /* vendor_id & device_id */
hand->fw_args.cpu_id = 0x4740;
hand->fw_args.ext_clk = 12;
hand->fw_args.cpu_speed = 225 / hand->fw_args.ext_clk;
hand->fw_args.phm_div = 3;
hand->fw_args.use_uart = 0;
hand->fw_args.boudrate = 57600;
hand->fw_args.bus_width = 0;
hand->fw_args.bank_num = 1;
hand->fw_args.row_addr = 13;
hand->fw_args.col_addr = 9;
hand->fw_args.is_mobile = 0;
hand->fw_args.is_busshare = 1;
return 1;
}
int check_dump_cfg(struct hand *hand)
{
printf("Now checking whether all configure args valid:");
/* check PLL */
if (hand->fw_args.ext_clk > 27 || hand->fw_args.ext_clk < 12) {
printf(" EXTCLK setting invalid!\n");
return 0;
}
if (hand->fw_args.phm_div > 32 || hand->fw_args.ext_clk < 2) {
printf(" PHMDIV setting invalid!\n");
return 0;
}
if ((hand->fw_args.cpu_speed * hand->fw_args.ext_clk ) % 12 != 0) {
printf(" CPUSPEED setting invalid!\n");
return 0;
}
/* check SDRAM */
if (hand->fw_args.bus_width > 1 ) {
printf(" SDRAMWIDTH setting invalid!\n");
return 0;
}
if (hand->fw_args.bank_num > 1 ) {
printf(" BANKNUM setting invalid!\n");
return 0;
}
if (hand->fw_args.row_addr > 13 && hand->fw_args.row_addr < 11 ) {
printf(" ROWADDR setting invalid!\n");
return 0;
}
if (hand->fw_args.col_addr > 13 && hand->fw_args.col_addr < 11 ) {
printf(" COLADDR setting invalid!\n");
return 0;
}
/* check NAND */
if ( hand->nand_ps < 2048 && hand->nand_os > 16 ) {
printf(" PAGESIZE or OOBSIZE setting invalid!\n");
printf(" PAGESIZE is %d,\t OOBSIZE is %d\n",
hand->nand_ps, hand->nand_os);
return 0;
}
if ( hand->nand_ps < 2048 && hand->nand_ppb > 32 ) {
printf(" PAGESIZE or PAGEPERBLOCK setting invalid!\n");
return 0;
}
if ( hand->nand_ps > 512 && hand->nand_os <= 16 ) {
printf(" PAGESIZE or OOBSIZE setting invalid!\n");
printf(" PAGESIZE is %d,\t OOBSIZE is %d\n",
hand->nand_ps, hand->nand_os);
return 0;
}
if ( hand->nand_ps > 512 && hand->nand_ppb < 64 ) {
printf(" PAGESIZE or PAGEPERBLOCK setting invalid!\n");
return 0;
}
printf(" YES\n");
printf("Current device information:\n");
printf("CPU type is Ingenic XBurst Jz%x\n",hand->fw_args.cpu_id);
printf("Crystal work at %dMHz, the CCLK up to %dMHz and PMH_CLK up to %dMHz\n",
hand->fw_args.ext_clk,
(unsigned int)hand->fw_args.cpu_speed * hand->fw_args.ext_clk,
((unsigned int)hand->fw_args.cpu_speed * hand->fw_args.ext_clk) / hand->fw_args.phm_div);
printf("SDRAM Total size is %d MB, work in %d bank and %d bit mode\n",
total_size / 0x100000, 2 * (hand->fw_args.bank_num + 1),
16 * (2 - hand->fw_args.bus_width));
printf("Nand page size %d, "
"ECC offset in OOB %d, "
"bad block offset in OOB %d, "
"bad block page %d, "
"use %d plane mode\n",
hand->nand_ps,
hand->nand_eccpos,
hand->nand_bbpos,
hand->nand_bbpage,
hand->nand_plane);
return 1;
}
int parse_configure(struct hand *hand, char * file_path)
{
if (access(file_path, F_OK)) {
fprintf(stderr, "Error - can't read configure file %s.\n",
file_path);
return -1;
}
hand_init_def(hand);
cfg_opt_t opts[] = {
CFG_INT("BOUDRATE", 57600, CFGF_NONE),
CFG_SIMPLE_INT("EXTCLK", &hand->fw_args.ext_clk),
CFG_SIMPLE_INT("CPUSPEED", &hand->fw_args.cpu_speed),
CFG_SIMPLE_INT("PHMDIV", &hand->fw_args.phm_div),
CFG_SIMPLE_INT("USEUART", &hand->fw_args.use_uart),
CFG_SIMPLE_INT("BUSWIDTH", &hand->fw_args.bus_width),
CFG_SIMPLE_INT("BANKS", &hand->fw_args.bank_num),
CFG_SIMPLE_INT("ROWADDR", &hand->fw_args.row_addr),
CFG_SIMPLE_INT("COLADDR", &hand->fw_args.col_addr),
CFG_SIMPLE_INT("ISMOBILE", &hand->fw_args.is_mobile),
CFG_SIMPLE_INT("ISBUSSHARE", &hand->fw_args.is_busshare),
CFG_SIMPLE_INT("DEBUGOPS", &hand->fw_args.debug_ops),
CFG_SIMPLE_INT("PINNUM", &hand->fw_args.pin_num),
CFG_SIMPLE_INT("START", &hand->fw_args.start),
CFG_SIMPLE_INT("SIZE", &hand->fw_args.size),
CFG_SIMPLE_INT("NAND_BUSWIDTH", &hand->nand_bw),
CFG_SIMPLE_INT("NAND_ROWCYCLES", &hand->nand_rc),
CFG_SIMPLE_INT("NAND_PAGESIZE", &hand->nand_ps),
CFG_SIMPLE_INT("NAND_PAGEPERBLOCK", &hand->nand_ppb),
CFG_SIMPLE_INT("NAND_FORCEERASE", &hand->nand_force_erase),
CFG_SIMPLE_INT("NAND_OOBSIZE", &hand->nand_os),
CFG_SIMPLE_INT("NAND_ECCPOS", &hand->nand_eccpos),
CFG_SIMPLE_INT("NAND_BADBLOCKPOS", &hand->nand_bbpos),
CFG_SIMPLE_INT("NAND_BADBLOCKPAGE", &hand->nand_bbpage),
CFG_SIMPLE_INT("NAND_PLANENUM", &hand->nand_plane),
CFG_SIMPLE_INT("NAND_BCHBIT", &hand->nand_bchbit),
CFG_SIMPLE_INT("NAND_WPPIN", &hand->nand_wppin),
CFG_SIMPLE_INT("NAND_BLOCKPERCHIP", &hand->nand_bpc),
CFG_END()
};
cfg_t *cfg;
cfg = cfg_init(opts, 0);
if (cfg_parse(cfg, file_path) == CFG_PARSE_ERROR)
return -1;
hand->fw_args.boudrate = cfg_getint(cfg, "BOUDRATE");
cfg_free(cfg);
hand->fw_args.cpu_id = 0x4740;
if (hand->fw_args.bus_width == 32)
hand->fw_args.bus_width = 0 ;
else
hand->fw_args.bus_width = 1 ;
hand->fw_args.bank_num = hand->fw_args.bank_num / 4;
hand->fw_args.cpu_speed = hand->fw_args.cpu_speed / hand->fw_args.ext_clk;
total_size = (unsigned int)
(2 << (hand->fw_args.row_addr + hand->fw_args.col_addr - 1)) * 2
* (hand->fw_args.bank_num + 1) * 2
* (2 - hand->fw_args.bus_width);
if (check_dump_cfg(hand) < 1)
return -1;
return 1;
}

21
usbboot/src/ingenic_cfg.h Normal file
View File

@@ -0,0 +1,21 @@
/*
* Authors: 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
* as published by the Free Software Foundation; either version
* 3 of the License, or (at your option) any later version.
*/
#ifndef __INGENIC_CFG_H__
#define __INGENIC_CFG_H__
#include "usb_boot_defines.h"
#define CONFIG_FILE_PATH "/usr/share/xburst_tools/xburst_tools.cfg"
int hand_init_def(struct hand *hand);
int check_dump_cfg(struct hand *hand);
int parse_configure(struct hand *hand, char * file_path);
#endif /*__INGENIC_CFG_H__ */

393
usbboot/src/ingenic_usb.c Normal file
View File

@@ -0,0 +1,393 @@
/*
* Authors: Marek Lindner <lindner_marek@yahoo.de>
* 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
* as published by the Free Software Foundation; either version
* 3 of the License, or (at your option) any later version.
*/
#include <usb.h>
#include <stdio.h>
#include <string.h>
#include "usb_boot_defines.h"
#include "ingenic_usb.h"
extern unsigned int total_size;
static int get_ingenic_device(struct ingenic_dev *ingenic_dev)
{
struct usb_bus *usb_busses, *usb_bus;
struct usb_device *usb_dev;
int count = 0;
usb_busses = usb_get_busses();
for (usb_bus = usb_busses; usb_bus != NULL; usb_bus = usb_bus->next) {
for (usb_dev = usb_bus->devices; usb_dev != NULL;
usb_dev = usb_dev->next) {
if ((usb_dev->descriptor.idVendor == VENDOR_ID) &&
(usb_dev->descriptor.idProduct == PRODUCT_ID)) {
ingenic_dev->usb_dev = usb_dev;
count++;
}
}
}
return count;
}
static int get_ingenic_interface(struct ingenic_dev *ingenic_dev)
{
struct usb_config_descriptor *usb_config_desc;
struct usb_interface_descriptor *usb_if_desc;
struct usb_interface *usb_if;
int config_index, if_index, alt_index;
for (config_index = 0;
config_index < ingenic_dev->usb_dev->descriptor.bNumConfigurations;
config_index++) {
usb_config_desc = &ingenic_dev->usb_dev->config[config_index];
if (!usb_config_desc)
return 0;
for (if_index = 0; if_index < usb_config_desc->bNumInterfaces;
if_index++) {
usb_if = &usb_config_desc->interface[if_index];
if (!usb_if)
return 0;
for (alt_index = 0; alt_index < usb_if->num_altsetting;
alt_index++) {
usb_if_desc = &usb_if->altsetting[alt_index];
if (!usb_if_desc)
return 0;
if ((usb_if_desc->bInterfaceClass == 0xff) &&
(usb_if_desc->bInterfaceSubClass == 0)) {
ingenic_dev->interface =
usb_if_desc->bInterfaceNumber;
return 1;
}
}
}
}
return 0;
}
int usb_ingenic_init(struct ingenic_dev *ingenic_dev)
{
int num_ingenic, status = -1;
memset(ingenic_dev, 0, sizeof(struct ingenic_dev));
usb_init();
/* usb_set_debug(255); */
usb_find_busses();
usb_find_devices();
num_ingenic = get_ingenic_device(ingenic_dev);
if (num_ingenic == 0) {
fprintf(stderr, "Error - no XBurst device found\n");
goto out;
}
if (num_ingenic > 1) {
fprintf(stderr, "Error - too many XBurst devices found: %i\n",
num_ingenic);
goto out;
}
ingenic_dev->usb_handle = usb_open(ingenic_dev->usb_dev);
if (!ingenic_dev->usb_handle) {
fprintf(stderr, "Error - can't open XBurst device: %s\n",
usb_strerror());
goto out;
}
if (get_ingenic_interface(ingenic_dev) < 1) {
fprintf(stderr, "Error - can't find XBurst interface\n");
goto out;
}
if (usb_claim_interface(ingenic_dev->usb_handle, ingenic_dev->interface)
< 0) {
fprintf(stderr, "Error - can't claim XBurst interface: %s\n",
usb_strerror());
goto out;
}
status = 1;
out:
return status;
}
int usb_get_ingenic_cpu(struct ingenic_dev *ingenic_dev)
{
int status;
memset(&ingenic_dev->cpu_info_buff, 0,
ARRAY_SIZE(ingenic_dev->cpu_info_buff));
sleep(1);
status = usb_control_msg(ingenic_dev->usb_handle,
/* bmRequestType */ USB_ENDPOINT_IN | USB_TYPE_VENDOR |USB_RECIP_DEVICE,
/* bRequest */ VR_GET_CPU_INFO,
/* wValue */ 0,
/* wIndex */ 0,
/* Data */ ingenic_dev->cpu_info_buff,
/* wLength */ 8,
USB_TIMEOUT);
if (status != sizeof(ingenic_dev->cpu_info_buff) - 1 ) {
fprintf(stderr, "Error - "
"can't retrieve XBurst CPU information: %i\n", status);
return status;
}
ingenic_dev->cpu_info_buff[8] = '\0';
/* printf(" CPU data: %s\n", ingenic_dev->cpu_info_buff); */
if (!strcmp(ingenic_dev->cpu_info_buff,"JZ4740V1")) return 1;
if (!strcmp(ingenic_dev->cpu_info_buff,"JZ4750V1")) return 2;
if (!strcmp(ingenic_dev->cpu_info_buff,"Boot4740")) return 3;
if (!strcmp(ingenic_dev->cpu_info_buff,"Boot4750")) return 4;
return 0;
}
int usb_ingenic_flush_cache(struct ingenic_dev *ingenic_dev)
{
int status;
status = usb_control_msg(ingenic_dev->usb_handle,
/* bmRequestType */ USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
/* bRequest */ VR_FLUSH_CACHES,
/* wValue */ 0,
/* wIndex */ 0,
/* Data */ 0,
/* wLength */ 0,
USB_TIMEOUT);
if (status != 0) {
fprintf(stderr, "Error - can't flush cache: %i\n", status);
return status;
}
return 1;
}
int usb_send_data_length_to_ingenic(struct ingenic_dev *ingenic_dev, int len)
{
int status;
/* tell the device the length of the file to be uploaded */
status = usb_control_msg(ingenic_dev->usb_handle,
/* bmRequestType */ USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
/* bRequest */ VR_SET_DATA_LENGTH,
/* wValue */ STAGE_ADDR_MSB(len),
/* wIndex */ STAGE_ADDR_LSB(len),
/* Data */ 0,
/* wLength */ 0,
USB_TIMEOUT);
if (status != 0) {
fprintf(stderr, "Error - "
"can't set data length on Ingenic device: %i\n", status);
return -1;
}
return 1;
}
int usb_send_data_address_to_ingenic(struct ingenic_dev *ingenic_dev,
unsigned int stage_addr)
{
int status;
/* tell the device the RAM address to store the file */
status = usb_control_msg(ingenic_dev->usb_handle,
/* bmRequestType */ USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
/* bRequest */ VR_SET_DATA_ADDRESS,
/* wValue */ STAGE_ADDR_MSB(stage_addr),
/* wIndex */ STAGE_ADDR_LSB(stage_addr),
/* Data */ 0,
/* wLength */ 0,
USB_TIMEOUT);
if (status != 0) {
fprintf(stderr, "Error - "
"can't set the address on Ingenic device: %i\n", status);
return -1;
}
return 1;
}
int usb_send_data_to_ingenic(struct ingenic_dev *ingenic_dev)
{
int status;
status = usb_bulk_write(ingenic_dev->usb_handle,
/* endpoint */ INGENIC_OUT_ENDPOINT,
/* bulk data */ ingenic_dev->file_buff,
/* bulk data length */ ingenic_dev->file_len,
USB_TIMEOUT);
if (status < ingenic_dev->file_len) {
fprintf(stderr, "Error - "
"can't send bulk data to Ingenic CPU: %i\n", status);
return -1;
}
return 1;
}
int usb_read_data_from_ingenic(struct ingenic_dev *ingenic_dev,
unsigned char *buff, unsigned int len)
{
int status;
status = usb_bulk_read(ingenic_dev->usb_handle,
/* endpoint */ INGENIC_IN_ENDPOINT,
/* bulk data */ buff,
/* bulk data length */ len,
USB_TIMEOUT);
if (status < len) {
fprintf(stderr, "Error - "
"can't read bulk data from Ingenic device:%i\n", status);
return -1;
}
return 1;
}
int usb_ingenic_start(struct ingenic_dev *ingenic_dev, int rqst, int stage_addr)
{
int status;
/* tell the device to start the uploaded device */
status = usb_control_msg(ingenic_dev->usb_handle,
/* bmRequestType */ USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
/* bRequest */ rqst,
/* wValue */ STAGE_ADDR_MSB(stage_addr),
/* wIndex */ STAGE_ADDR_LSB(stage_addr),
/* Data */ 0,
/* wLength */ 0,
USB_TIMEOUT);
if (status != 0) {
fprintf(stderr, "Error - can't start the uploaded binary "
"on the Ingenic device: %i\n", status);
return status;
}
return 1;
}
int usb_ingenic_upload(struct ingenic_dev *ingenic_dev, int stage)
{
int status;
unsigned int stage2_addr;
stage2_addr = total_size + 0x80000000;
stage2_addr -= CODE_SIZE;
int stage_addr = (stage == 1 ? 0x80002000 : stage2_addr);
int rqst = VR_PROGRAM_START1;
usb_send_data_address_to_ingenic(ingenic_dev, stage_addr);
printf(" Download stage %d program and execute at 0x%08x\n",
stage, (stage_addr));
usb_send_data_to_ingenic(ingenic_dev);
if (stage == 2) {
if (usb_get_ingenic_cpu(ingenic_dev) < 1)
return -1;
usb_ingenic_flush_cache(ingenic_dev);
rqst = VR_PROGRAM_START2;
}
if (usb_ingenic_start(ingenic_dev, rqst, stage_addr) < 1)
return -1;
if (usb_get_ingenic_cpu(ingenic_dev) < 1)
return -1;
return 1;
}
void usb_ingenic_cleanup(struct ingenic_dev *ingenic_dev)
{
if ((ingenic_dev->usb_handle) && (ingenic_dev->interface))
usb_release_interface(ingenic_dev->usb_handle,
ingenic_dev->interface);
if (ingenic_dev->usb_handle)
usb_close(ingenic_dev->usb_handle);
}
int usb_ingenic_nand_ops(struct ingenic_dev *ingenic_dev, int ops)
{
int status;
status = usb_control_msg(ingenic_dev->usb_handle,
/* bmRequestType */ USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
/* bRequest */ VR_NAND_OPS,
/* wValue */ ops & 0xffff,
/* wIndex */ 0,
/* Data */ 0,
/* wLength */ 0,
USB_TIMEOUT);
if (status != 0) {
fprintf(stderr, "Error - "
"can't set Ingenic device nand ops: %i\n", status);
return -1;
}
return 1;
}
int usb_ingenic_configration(struct ingenic_dev *ingenic_dev, int ops)
{
int status;
status = usb_control_msg(ingenic_dev->usb_handle,
/* bmRequestType */ USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
/* bRequest */ VR_CONFIGRATION,
/* wValue */ ops,
/* wIndex */ 0,
/* Data */ 0,
/* wLength */ 0,
USB_TIMEOUT);
if (status != 0) {
fprintf(stderr, "Error - "
"can't init Ingenic configration: %i\n", status);
return -1;
}
return 1;
}
int usb_ingenic_sdram_ops(struct ingenic_dev *ingenic_dev, int ops)
{
int status;
status = usb_control_msg(ingenic_dev->usb_handle,
/* bmRequestType */ USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
/* bRequest */ VR_SDRAM_OPS,
/* wValue */ ops,
/* wIndex */ 0,
/* Data */ 0,
/* wLength */ 0,
USB_TIMEOUT);
if (status != 0) {
fprintf(stderr, "Error - "
"Device can't load file to sdram: %i\n", status);
return -1;
}
return 1;
}

67
usbboot/src/ingenic_usb.h Normal file
View File

@@ -0,0 +1,67 @@
/*
* Authors: Xiangfu Liu <xiangfu.z@gmail.com>
* Marek Lindner <lindner_marek@yahoo.de>
*
* 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.
*/
#ifndef __INGENIC_USB_H__
#define __INGENIC_USB_H__
#include <stdint.h>
#define INGENIC_OUT_ENDPOINT 0x01
#define INGENIC_IN_ENDPOINT 0x81
#define VR_GET_CPU_INFO 0x00
#define VR_SET_DATA_ADDRESS 0x01
#define VR_SET_DATA_LENGTH 0x02
#define VR_FLUSH_CACHES 0x03
#define VR_PROGRAM_START1 0x04
#define VR_PROGRAM_START2 0x05
#define VR_NOR_OPS 0x06
#define VR_NAND_OPS 0x07
#define VR_SDRAM_OPS 0x08
#define VR_CONFIGRATION 0x09
#define VR_GET_NUM 0x0a
#define STAGE_ADDR_MSB(addr) ((addr) >> 16)
#define STAGE_ADDR_LSB(addr) ((addr) & 0xffff)
#define USB_PACKET_SIZE 512
#define USB_TIMEOUT 5000
#define VENDOR_ID 0x601a
#define PRODUCT_ID 0x4740
#define STAGE1_FILE_PATH "/usr/share/xburst_tools/xburst_stage1.bin"
#define STAGE2_FILE_PATH "/usr/share/xburst_tools/xburst_stage2.bin"
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
struct ingenic_dev {
struct usb_device *usb_dev;
struct usb_dev_handle *usb_handle;
uint8_t interface;
char cpu_info_buff[9];
char *file_buff;
unsigned int file_len;
};
int usb_ingenic_init(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);
void usb_ingenic_cleanup(struct ingenic_dev *ingenic_dev);
int usb_send_data_address_to_ingenic(struct ingenic_dev *ingenic_dev,
unsigned int stage_addr);
int usb_send_data_to_ingenic(struct ingenic_dev *ingenic_dev);
int usb_send_data_length_to_ingenic(struct ingenic_dev *ingenic_dev,
int len);
int usb_ingenic_nand_ops(struct ingenic_dev *ingenic_dev, int ops);
int usb_read_data_from_ingenic(struct ingenic_dev *ingenic_dev,unsigned char *buff, unsigned int len);
#endif /* __INGENIC_USB_H__ */

121
usbboot/src/main.c Normal file
View File

@@ -0,0 +1,121 @@
/*
* Authors: 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
* as published by the Free Software Foundation; either version
* 3 of the License, or (at your option) any later version.
*/
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <unistd.h>
#include <string.h>
#include "xburst_tools_version.h"
#include "command_line.h"
#include "ingenic_usb.h"
#include "ingenic_cfg.h"
extern struct ingenic_dev ingenic_dev;
extern struct hand hand;
static void help(void)
{
printf("Usage: usbboot [options] ...(must run as root)\n"
" -h --help\t\t\tPrint this help message\n"
" -v --version\t\t\tPrint the version number\n"
" -c --command\t\t\tDirect run the commands, split by ';'\n"
" <run without options to enter commands via usbboot prompt>\n\n"
"Report bugs to <xiangfu.z@gmail.com>.\n"
);
}
static void print_version(void)
{
printf("usbboot version: %s\n", XBURST_TOOLS_VERSION);
}
static struct option opts[] = {
{ "help", 0, 0, 'h' },
{ "version", 0, 0, 'v' },
{ "command", 1, 0, 'c' },
{ 0, 0, 0, 0 }
};
int main(int argc, char **argv)
{
int command = 0;
char *cptr;
char com_buf[256] = {0};
char *cmdpt;
printf("usbboot - 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");
while(1) {
int c, option_index = 0;
c = getopt_long(argc, argv, "hvc:", opts,
&option_index);
if (c == -1)
break;
switch (c) {
case 'h':
help();
exit(EXIT_SUCCESS);
case 'v':
print_version();
exit(EXIT_SUCCESS);
case 'c':
command = 1;
cmdpt = optarg;
break;
default:
help();
exit(2);
}
}
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)
return EXIT_FAILURE;
if (parse_configure(&hand, CONFIG_FILE_PATH) < 1)
return EXIT_FAILURE;
if (command) { /* direct run command */
char *delim=";";
char *p;
p = strtok(cmdpt, delim);
strcpy(com_buf, p);
printf(" Execute command: %s \n",com_buf);
command_handle(com_buf);
while((p = strtok(NULL,delim))) {
strcpy(com_buf, p);
printf(" Execute command: %s \n",com_buf);
command_handle(com_buf);
}
goto out;
}
while (1) {
printf("usbboot :> ");
cptr = fgets(com_buf, 256, stdin);
if (cptr == NULL)
continue;
if (command_handle(com_buf) == -1 )
break;
}
out:
usb_ingenic_cleanup(&ingenic_dev);
return EXIT_SUCCESS;
}

View File

@@ -0,0 +1,152 @@
/*
* Authors: Marek Lindner <lindner_marek@yahoo.de>
*
* 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.
*/
#ifndef __USB_BOOT_DEFINES_H__
#define __USB_BOOT_DEFINES_H__
#define SDRAM_SIZE ( 16 * 1024 * 1024 )
#define CODE_SIZE ( 4 * 1024 * 1024 )
/* #define START_ADDR ( 0x80000000 + SDRAM_SIZE - CODE_SIZE ) */
#define NAND_MAX_BLK_NUM 10000000 /*((Hand.nand_pn / Hand.nand_ppb) + 1)*/
#define NAND_MAX_PAGE_NUM 1073740824 /*Hand.nand_pn */
#define NAND_SECTION_NUM 23
#define MAX_TRANSFER_SIZE 0x100000
#define MAX_LOAD_SIZE 0x3000
#define NAND_MAX_BYTE_NUM (hand.nand_pn * hand.nand_ps)
#define MAX_DEV_NUM 16
enum CPUTYPE {
JZ4740,
JZ4750,
};
enum USB_Boot_State {
DISCONNECT,
CONNECT,
BOOT,
UNBOOT
};
enum OPTION {
OOB_ECC,
OOB_NO_ECC,
NO_OOB,
};
enum NOR_OPS_TYPE {
NOR_INIT = 0,
NOR_QUERY,
NOR_WRITE,
NOR_ERASE_CHIP,
NOR_ERASE_SECTOR
};
enum NOR_FLASH_TYPE
{
NOR_AM29 = 0,
NOR_SST28,
NOR_SST39x16,
NOR_SST39x8
};
enum NAND_OPS_TYPE {
NAND_QUERY = 0,
NAND_INIT,
NAND_MARK_BAD,
NAND_READ_OOB,
NAND_READ_RAW,
NAND_ERASE,
NAND_READ,
NAND_PROGRAM,
NAND_READ_TO_RAM
};
enum SDRAM_OPS_TYPE {
SDRAM_LOAD,
};
enum DATA_STRUCTURE_OB {
DS_flash_info ,
DS_hand
};
struct fw_args {
/* CPU ID */
unsigned int cpu_id;
/* PLL args */
unsigned char ext_clk;
unsigned char cpu_speed;
unsigned char phm_div;
unsigned char use_uart;
unsigned int boudrate;
/* SDRAM args */
unsigned char bus_width;
unsigned char bank_num;
unsigned char row_addr;
unsigned char col_addr;
unsigned char is_mobile;
unsigned char is_busshare;
/* debug args */
unsigned char debug_ops;
unsigned char pin_num;
unsigned int start;
unsigned int size;
} __attribute__((packed));
struct hand {
/* nand flash info */
int pt; /* cpu type */
unsigned int nand_bw; /* bus width */
unsigned int nand_rc; /* row cycle */
unsigned int nand_ps; /* page size */
unsigned int nand_ppb; /* page number per block */
unsigned int nand_force_erase;
unsigned int nand_pn; /* page number in total */
unsigned int nand_os; /* oob size */
unsigned int nand_eccpos;
unsigned int nand_bbpage;
unsigned int nand_bbpos;
unsigned int nand_plane;
unsigned int nand_bchbit;
unsigned int nand_wppin;
unsigned int nand_bpc; /* block number per chip */
struct fw_args fw_args;
} __attribute__((packed));
struct nand_in {
unsigned char dev;
unsigned char max_chip;
unsigned char *buf;
unsigned char *cs_map;
unsigned int start;
unsigned int length;
unsigned int option;
int (* check) (unsigned char *,unsigned char *,unsigned int);
};
struct nand_out {
unsigned char *status;
};
struct sdram_in {
unsigned char dev;
unsigned char *buf;
unsigned int start;
unsigned int length;
unsigned int option;
};
#endif /* __USB_BOOT_DEFINES_H__ */

52
usbboot/src/usbboot.cfg Normal file
View File

@@ -0,0 +1,52 @@
#
# usbboot configuration file
#
# Utility to respond to the Ingenic XBurst USB boot protocol, provide
# initial boot stages and ability to access NAND on device.
#
# Authors: Ingenic Semiconductor, Inc.
# Xiangfu Liu <xiangfu.z@gmail.com>
# Marek Lindner <lindner_marek@yahoo.de>
# Wolfgang Spraul <wolfgang@qi-hardware.com>
#
# 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.
#
# [PLL]
EXTCLK = 12 #Define the external crystal in MHz
CPUSPEED = 252 #Define the PLL output frequency
PHMDIV = 3 #Define the frequency divider ratio of PLL=CCLK:PCLK=HCLK=MCLK
BOUDRATE = 57600 #Define the uart boudrate
USEUART = 0 #Use which uart, 0/1 for jz4740,0/1/2/3 for jz4750
# [SDRAM]
BUSWIDTH = 16 #The bus width of the SDRAM in bits (16|32)
BANKS = 4 #The bank number (2|4)
ROWADDR = 13 #Row address width in bits (11-13)
COLADDR = 9 #Column address width in bits (8-12)
ISMOBILE = 0 #Define whether SDRAM is mobile SDRAM, this only valid for Jz4750 ,1:yes 0:no
ISBUSSHARE = 1 #Define whether SDRAM bus share with NAND 1:shared 0:unshared
DEBUGOPS = 0
# [NAND]
NAND_BUSWIDTH = 8 #The width of the NAND flash chip in bits (8|16|32)
NAND_ROWCYCLES = 3 #The row address cycles (2|3)
NAND_PAGESIZE = 2048 #The page size of the NAND chip in bytes(512|2048|4096)
NAND_PAGEPERBLOCK = 128 #The page number per block
NAND_FORCEERASE = 1 #The force to erase flag (0|1)
NAND_OOBSIZE = 64 #oob size in byte
NAND_ECCPOS = 6 #Specify the ECC offset inside the oob data (0-[oobsize-1])
NAND_BADBLOCKPOS = 0 #Specify the badblock flag offset inside the oob (0-[oobsize-1])
NAND_BADBLOCKPAGE = 127 #Specify the page number of badblock flag inside a block(0-[PAGEPERBLOCK-1])
NAND_PLANENUM = 1 #The planes number of target nand flash
NAND_BCHBIT = 4 #Specify the hardware BCH algorithm for 4750 (4|8)
NAND_WPPIN = 0 #Specify the write protect pin number
NAND_BLOCKPERCHIP = 0 #Specify the block number per chip,0 means ignore
#The program will calculate the total SDRAM size by : size = 2^(ROWADDR + COLADDR) * BANKNUM * (SDRAMWIDTH / 4)
#The CPUSPEED has restriction as: ( CPUSPEED % EXTCLK == 0 ) && ( CPUSPEED % 12 == 0 )
#For jz4750, the program just init BANK0(DSC0).
#Beware all variables must be set correct!