From e7a23fd7b6fdfe7d16878817e6152135392a060f Mon Sep 17 00:00:00 2001 From: xiangfu Date: Sat, 16 May 2009 02:57:10 +0000 Subject: [PATCH] delete repeat code --- flash-tool/cmd.c | 22 ++-- flash-tool/device_stage2/Makefile | 31 +++--- flash-tool/device_stage2/include/hand.h | 56 ---------- flash-tool/device_stage2/include/usb_boot.h | 101 +++++------------- .../device_stage2/nandflash/nandflash_4740.c | 2 +- .../device_stage2/nandflash/nandflash_4750.c | 2 +- .../device_stage2/usb_boot/boothandler.c | 2 +- flash-tool/device_stage2/usb_boot/main.c | 3 +- 8 files changed, 60 insertions(+), 159 deletions(-) delete mode 100644 flash-tool/device_stage2/include/hand.h diff --git a/flash-tool/cmd.c b/flash-tool/cmd.c index 9cc986b..8844ad7 100644 --- a/flash-tool/cmd.c +++ b/flash-tool/cmd.c @@ -110,6 +110,7 @@ out: return res; } +/* after upload stage2. must init device */ int init_cfg() { if (usb_get_ingenic_cpu(&ingenic_dev) < 3) { @@ -526,6 +527,14 @@ int nand_program_file(struct nand_in_t *nand_in, return 1; } +int nand_program_file_planes(struct nand_in_t *nand_in, + struct nand_out_t *nand_out, + char *fname) +{ + printf(" \n not implement yet !"); + return -1; +} + int init_nand_in(void) { nand_in.buf = code_buf; @@ -574,9 +583,9 @@ int nand_prog(void) printf("%s", help); if (hand.nand_plane > 1) - ;/* nand_program_file_planes(&nand_in,&nand_out, image_file); */ + nand_program_file_planes(&nand_in, &nand_out, image_file); else - nand_program_file(&nand_in,&nand_out, image_file); + nand_program_file(&nand_in, &nand_out, image_file); #ifdef CONFIG_NAND_OUT printf("\n Flash check result:"); @@ -584,16 +593,7 @@ int nand_prog(void) printf(" %d", (nand_out.status)[i]); #endif - printf("\n nprog %d %s %d %d %d", nand_in.start, - image_file, - nand_in.dev, - (nand_in.cs_map)[atoi(com_argv[4])], - nand_in.option); - - printf("\n not implement yet!! just test"); - return 1; - } int nand_query(void) diff --git a/flash-tool/device_stage2/Makefile b/flash-tool/device_stage2/Makefile index 046819a..d8d0fbb 100644 --- a/flash-tool/device_stage2/Makefile +++ b/flash-tool/device_stage2/Makefile @@ -13,49 +13,56 @@ CC := mipsel-linux-gcc AR := mipsel-linux-ar rcsv LD := mipsel-linux-ld OBJCOPY := mipsel-linux-objcopy -NM := mipsel-linux-nm +NM := mipsel-linux-nm OBJDUMP := mipsel-linux-objdump CFLAGS := -mips32 -O2 -FPIC \ - -fno-exceptions -ffunction-sections \ - -fomit-frame-pointer -msoft-float -G 0 + -fno-exceptions -ffunction-sections \ + -fomit-frame-pointer -msoft-float -G 0 #CFLAGS := -mips32 -O2 -FPIC -mno-abicalls -fno-builtin \ LDFLAGS := -nostdlib -T target.ld $(CFLAGS) -LIBS := -lstdc++ -lc -lm -lgcc +LIBS := -lstdc++ -lc -lm -lgcc -USBBOOTDIR := . +USBBOOTDIR := . LIBDIR := #SOURCES += $(wildcard $(USBBOOTDIR)/usb_boot/*.c) -SOURCES := ./usb_boot/main.c ./usb_boot/udc.c ./usb_boot/cache.c ./usb_boot/serial.c ./usb_boot/boothandler.c +SOURCES := ./usb_boot/main.c \ + ./usb_boot/udc.c \ + ./usb_boot/cache.c \ + ./usb_boot/serial.c \ + ./usb_boot/boothandler.c SOURCES += $(wildcard $(USBBOOTDIR)/nandflash/*.c) -SOURCES += $(wildcard $(USBBOOTDIR)/usb_boot/*.S) +SOURCES += $(wildcard $(USBBOOTDIR)/usb_boot/*.S) HEADS := $(SOCDIR)/head.S -CFLAGS += -I$(SOCDIR)/include -I$(USBBOOTDIR)/usb_boot -I$(USBBOOTDIR)/nandflash -I$(USBBOOTDIR)/include +CFLAGS += -I$(SOCDIR)/include -I$(USBBOOTDIR)/usb_boot \ + -I$(USBBOOTDIR)/nandflash -I$(USBBOOTDIR)/include \ + -I.. OBJS := $(addsuffix .o , $(basename $(notdir $(SOURCES)))) HEADO := $(addsuffix .o , $(basename $(notdir $(HEADS)))) -TARGET := usb_boot +TARGET := usb_boot APP := $(TARGET).elf -VPATH := $(ARCHDIR) $(SOCDIR) $(OSDIR) $(USBBOOTDIR)/usb_boot $(USBBOOTDIR)/norflash $(USBBOOTDIR)/nandflash +VPATH := $(ARCHDIR) $(SOCDIR) $(OSDIR) $(USBBOOTDIR)/usb_boot \ + $(USBBOOTDIR)/norflash $(USBBOOTDIR)/nandflash -all: $(APP) +all: $(APP) $(OBJCOPY) -O binary $(APP) $(TARGET).bin $(OBJDUMP) -D $(APP) > $(TARGET).dump $(NM) $(APP) | sort > $(TARGET).sym $(OBJDUMP) -h $(APP) > $(TARGET).map cp usb_boot.bin $(FLASH_TOOL_PATH) -$(APP): $(HEADO) $(OBJS) $(EXTLIBS) +$(APP): $(HEADO) $(OBJS) $(EXTLIBS) $(CC) $(LDFLAGS) $^ -o $@ .c.o: diff --git a/flash-tool/device_stage2/include/hand.h b/flash-tool/device_stage2/include/hand.h deleted file mode 100644 index 621d2c6..0000000 --- a/flash-tool/device_stage2/include/hand.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef __HAND_H__ -#define __HAND_H__ - -struct fw_args_t { - /* 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; - - /* for align */ - /* unsigned char align1; */ - /* unsigned char align2; */ -} __attribute__((packed)); - -struct hand_t { - - /* 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_t fw_args; -} __attribute__((packed)); - -#endif /* __HAND_H__ */ diff --git a/flash-tool/device_stage2/include/usb_boot.h b/flash-tool/device_stage2/include/usb_boot.h index e8d0e1b..16ecfb3 100644 --- a/flash-tool/device_stage2/include/usb_boot.h +++ b/flash-tool/device_stage2/include/usb_boot.h @@ -1,11 +1,29 @@ -#ifndef __USB_BOOT_H -#define __USB_BOOT_H +/* + * "Ingenic flash tool" - flash the Ingenic CPU via USB + * + * (C) Copyright 2009 + * Author: Xiangfu Liu + * + * 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 + */ -//#define dprintf(x...) -//printf(x); +#ifndef __USB_BOOT_H__ +#define __USB_BOOT_H__ -#define BULK_OUT_BUF_SIZE 0x21000 //buffer size : -#define BULK_IN_BUF_SIZE 0x21000 // too +#define BULK_OUT_BUF_SIZE 0x21000 +#define BULK_IN_BUF_SIZE 0x21000 enum UDC_STATE { @@ -14,7 +32,7 @@ enum UDC_STATE BULK_OUT }; -enum USB_JZ4740_REQUEST //add for USB_BOOT +enum USB_JZ4740_REQUEST /* add for USB_BOOT */ { VR_GET_CUP_INFO = 0, VR_SET_DATA_ADDERSS, @@ -28,71 +46,4 @@ enum USB_JZ4740_REQUEST //add for USB_BOOT VR_CONFIGRATION }; -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 -}; - - -/*typedef enum _USB_BOOT_STATUS -{ - USB_NO_ERR =0 , - GET_CPU_INFO_ERR, - SET_DATA_ADDRESS_ERR, - SET_DATA_LENGTH_ERR, - FLUSH_CAHCES_ERR, - PROGRAM_START1_ERR, - PROGRAM_START2_ERR, - NOR_OPS_ERR, - NAND_OPS_ERR, - NOR_FLASHTYPE_ERR, - OPS_NOTSUPPORT_ERR -}USB_BOOT_STATUS;*/ - -enum OPTION -{ - OOB_ECC, - OOB_NO_ECC, - NO_OOB, -}; - - - -#endif +#endif /* __USB_BOOT_H__ */ diff --git a/flash-tool/device_stage2/nandflash/nandflash_4740.c b/flash-tool/device_stage2/nandflash/nandflash_4740.c index 1e525c7..45c2844 100644 --- a/flash-tool/device_stage2/nandflash/nandflash_4740.c +++ b/flash-tool/device_stage2/nandflash/nandflash_4740.c @@ -1,7 +1,7 @@ #include "nandflash.h" #include "jz4740.h" #include "usb_boot.h" -#include "hand.h" +#include "usb_boot_defines.h" #define __nand_enable() (REG_EMC_NFCSR |= EMC_NFCSR_NFE1 | EMC_NFCSR_NFCE1) #define __nand_disable() (REG_EMC_NFCSR &= ~(EMC_NFCSR_NFCE1)) diff --git a/flash-tool/device_stage2/nandflash/nandflash_4750.c b/flash-tool/device_stage2/nandflash/nandflash_4750.c index 6e4eb20..37e996d 100644 --- a/flash-tool/device_stage2/nandflash/nandflash_4750.c +++ b/flash-tool/device_stage2/nandflash/nandflash_4750.c @@ -1,7 +1,7 @@ #include "jz4750.h" #include "nandflash.h" #include "usb_boot.h" -#include "hand.h" +#include "usb_boot_defines.h" #define dprintf(n...) diff --git a/flash-tool/device_stage2/usb_boot/boothandler.c b/flash-tool/device_stage2/usb_boot/boothandler.c index 96d42cb..0e5ec35 100644 --- a/flash-tool/device_stage2/usb_boot/boothandler.c +++ b/flash-tool/device_stage2/usb_boot/boothandler.c @@ -4,7 +4,7 @@ #include "usb.h" #include "error.h" #include "usb_boot.h" -#include "hand.h" +#include "usb_boot_defines.h" #include "nandflash.h" #include "udc.h" #define dprintf(x) serial_puts(x) diff --git a/flash-tool/device_stage2/usb_boot/main.c b/flash-tool/device_stage2/usb_boot/main.c index 466b0c0..0c90245 100644 --- a/flash-tool/device_stage2/usb_boot/main.c +++ b/flash-tool/device_stage2/usb_boot/main.c @@ -1,8 +1,7 @@ /* special main file! * do not edit! */ -//#include "jz4740.h" -#include "hand.h" +#include "usb_boot_defines.h" extern void usb_main(); unsigned int start_addr,got_start,got_end;