From ff3182da41eef87f6707159e6616f354a488f8b6 Mon Sep 17 00:00:00 2001 From: Xiangfu Liu Date: Wed, 2 Mar 2011 10:42:35 +0800 Subject: [PATCH] add new command: reset, then we can reboot device after reflash --- usbboot/src/cmd.c | 8 ++++++++ usbboot/src/cmd.h | 1 + usbboot/src/command_line.c | 2 ++ usbboot/src/ingenic_usb.c | 21 ++++++++++++++++++++ usbboot/src/ingenic_usb.h | 3 ++- usbboot/xburst_include/target/usb_boot.h | 2 +- usbboot/xburst_stage2/boothandler.c | 25 +++++++++++++++--------- usbboot/xburst_stage2/udc.c | 3 +++ 8 files changed, 54 insertions(+), 11 deletions(-) diff --git a/usbboot/src/cmd.c b/usbboot/src/cmd.c index faa217a..70770c8 100644 --- a/usbboot/src/cmd.c +++ b/usbboot/src/cmd.c @@ -962,3 +962,11 @@ close: out: return res; } + +int device_reset(int ops) +{ + if (usb_ingenic_reset(&ingenic_dev, ops) < 1) + return -1; + + return 1; +} diff --git a/usbboot/src/cmd.h b/usbboot/src/cmd.h index 0d01c77..b1259ab 100644 --- a/usbboot/src/cmd.h +++ b/usbboot/src/cmd.h @@ -33,5 +33,6 @@ 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); +int device_reset(int ops); #endif /* __CMD_H__ */ diff --git a/usbboot/src/command_line.c b/usbboot/src/command_line.c index 23286f3..a9f9fae 100644 --- a/usbboot/src/command_line.c +++ b/usbboot/src/command_line.c @@ -204,6 +204,8 @@ int command_handle(char *buf) debug_go(); else if (!strcmp("memtest", com_argv[0])) handle_memtest(); + else if (!strcmp("reset", com_argv[0])) + device_reset(0); else if (!strcmp("help", com_argv[0])) handle_help(); else if (!strcmp("exit", com_argv[0])) diff --git a/usbboot/src/ingenic_usb.c b/usbboot/src/ingenic_usb.c index 539d3c6..b01d4d7 100644 --- a/usbboot/src/ingenic_usb.c +++ b/usbboot/src/ingenic_usb.c @@ -406,3 +406,24 @@ int usb_ingenic_sdram_ops(struct ingenic_dev *ingenic_dev, int ops) return 1; } + +int usb_ingenic_reset(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_RESET, + /* wValue */ ops, + /* wIndex */ 0, + /* Data */ 0, + /* wLength */ 0, + USB_TIMEOUT); + + if (status != 0) { + fprintf(stderr, "Error - " + "reset XBurst device: %i\n", status); + return -1; + } + + return 1; +} diff --git a/usbboot/src/ingenic_usb.h b/usbboot/src/ingenic_usb.h index 0a90675..881500e 100644 --- a/usbboot/src/ingenic_usb.h +++ b/usbboot/src/ingenic_usb.h @@ -35,7 +35,7 @@ #define VR_NAND_OPS 0x07 #define VR_SDRAM_OPS 0x08 #define VR_CONFIGRATION 0x09 -#define VR_GET_NUM 0x0a +#define VR_RESET 0x0a #define JZ4740V1 1 #define JZ4750V1 2 @@ -77,5 +77,6 @@ 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); +int usb_ingenic_reset(struct ingenic_dev *ingenic_dev, int ops); #endif /* __INGENIC_USB_H__ */ diff --git a/usbboot/xburst_include/target/usb_boot.h b/usbboot/xburst_include/target/usb_boot.h index 9b0c37d..991b33e 100644 --- a/usbboot/xburst_include/target/usb_boot.h +++ b/usbboot/xburst_include/target/usb_boot.h @@ -44,7 +44,7 @@ enum USB_JZ4740_REQUEST /* add for USB_BOOT */ VR_NAND_OPS, VR_SDRAM_OPS, VR_CONFIGRATION, - VR_OTHER + VR_RESET }; #endif /* __USB_BOOT_H__ */ diff --git a/usbboot/xburst_stage2/boothandler.c b/usbboot/xburst_stage2/boothandler.c index 03b788c..3438380 100644 --- a/usbboot/xburst_stage2/boothandler.c +++ b/usbboot/xburst_stage2/boothandler.c @@ -51,8 +51,8 @@ extern void *memset(void *s, int c, size_t count); extern void *memcpy(void *dest, const void *src, size_t count); u32 ret_dat; -u32 start_addr; //program operation start address or sector -u32 ops_length; //number of operation unit ,in byte or sector +u32 start_addr; /* program operation start address or sector */ +u32 ops_length; /* number of operation unit ,in byte or sector */ u32 ram_addr; void dump_data(unsigned int *p, int size) @@ -117,7 +117,6 @@ int PROGRAM_START1_Handle(u8 *buf) { USB_DeviceRequest *dreq = (USB_DeviceRequest *)buf; ram_addr=(((u32)dreq->wValue)<<16)+(u32)dreq->wIndex; - //dprintf("\n RAM ADDRESS :%x", ram_addr); return ERR_OK; } @@ -127,9 +126,9 @@ int PROGRAM_START2_Handle(u8 *buf) USB_DeviceRequest *dreq = (USB_DeviceRequest *)buf; f=(void *) ((((u32)dreq->wValue)<<16)+(u32)dreq->wIndex); __dcache_writeback_all(); - //stop udc connet before execute program! - jz_writeb(USB_REG_POWER,0x0); //High speed - //dprintf("\n Execute program at %x",(u32)f); + /* stop udc connet before execute program! */ + jz_writeb(USB_REG_POWER,0x0); /* High speed */ + f(); return ERR_OK; } @@ -273,7 +272,6 @@ int SDRAM_OPS_Handle(u8 *buf) switch ((dreq->wValue)&0xf) { case SDRAM_LOAD: - //dprintf("\n Request : SDRAM_LOAD!"); ret_dat = (u32)memcpy((u8 *)start_addr,Bulk_out_buf,ops_length); handshake_PKT[0] = (u16) ret_dat; handshake_PKT[1] = (u16) (ret_dat>>16); @@ -291,7 +289,6 @@ void Borad_Init() switch (Hand.fw_args.cpu_id) { case 0x4740: - //Init nand flash nand_init_4740(Hand.nand_bw, Hand.nand_rc, Hand.nand_ps, Hand.nand_ppb, Hand.nand_bbpage, Hand.nand_bbpos, Hand.nand_force_erase, Hand.nand_eccpos); @@ -307,7 +304,6 @@ void Borad_Init() nand_mark_bad = nand_mark_bad_4740; break; case 0x4760: - //Init nand flash nand_init_4760(Hand.nand_bw, Hand.nand_rc, Hand.nand_ps, Hand.nand_ppb, Hand.nand_bchbit, Hand.nand_eccpos, Hand.nand_bbpos, Hand.nand_bbpage, Hand.nand_force_erase); @@ -351,3 +347,14 @@ int CONFIGRATION_Handle(u8 *buf) } +int RESET_Handle(u8 *buf) +{ + dprintf("\n RESET Device"); + __wdt_select_extalclk(); + __wdt_select_clk_div64(); + __wdt_set_data(100); + __wdt_set_count(0); + __tcu_start_wdt_clock(); + __wdt_start(); + while(1); +} diff --git a/usbboot/xburst_stage2/udc.c b/usbboot/xburst_stage2/udc.c index 83fb8a3..b0f8568 100644 --- a/usbboot/xburst_stage2/udc.c +++ b/usbboot/xburst_stage2/udc.c @@ -418,6 +418,9 @@ void usbHandleVendorReq(u8 *buf) SDRAM_OPS_Handle(buf); Bulk_out_size = 0; break; + case VR_RESET: + ret_state = RESET_Handle(buf); + break; } }