From 3b6d2ac28afc1c987e480790fff1b652f3ade5cd Mon Sep 17 00:00:00 2001 From: Amaury Pouly Date: Tue, 10 Sep 2013 23:07:40 +0200 Subject: hwstub: add delay functions, and plain binary/sb file generation Change-Id: Idbedb9277b355edcd93975ec5a268428c7b89633 --- utils/hwstub/stub/hwstub.make | 7 ++++++- utils/hwstub/stub/stmp/Makefile | 10 ++++++++-- utils/hwstub/stub/stmp/target.c | 15 +++++++++++++++ utils/hwstub/stub/target.h | 4 ++++ utils/hwstub/stub/usb_drv_arc.c | 5 ++++- 5 files changed, 37 insertions(+), 4 deletions(-) diff --git a/utils/hwstub/stub/hwstub.make b/utils/hwstub/stub/hwstub.make index b46a2736ef..d40fa87755 100644 --- a/utils/hwstub/stub/hwstub.make +++ b/utils/hwstub/stub/hwstub.make @@ -14,9 +14,10 @@ OBJ=$(SRC:.c=.o) OBJ:=$(OBJ:.S=.o) OBJ_EXCEPT_CRT0=$(filter-out $(BUILD_DIR)/crt0.o,$(OBJ)) EXEC_ELF=$(BUILD_DIR)/hwstub.elf +EXEC_BIN=$(BUILD_DIR)/hwstub.bin DEPS=$(foreach obj,$(OBJ),$(obj).d) -EXEC=$(EXEC_ELF) +EXEC+=$(EXEC_ELF) $(EXEC_BIN) SILENT?=@ PRINTS=$(SILENT)$(call info,$(1)) @@ -44,6 +45,10 @@ $(TMP_LDS): $(LINKER_FILE) $(EXEC_ELF): $(OBJ) $(TMP_LDS) $(call PRINTS,LD $(@F)) $(SILENT)$(LD) $(LDFLAGS) -o $@ $(OBJ_EXCEPT_CRT0) + +$(EXEC_BIN): $(EXEC_ELF) + $(call PRINTS,OC $(@F)) + $(SILENT)$(OC) -O binary $< $@ clean: $(SILENT)rm -rf $(OBJ) $(DEPS) $(EXEC) $(TMP_LDS) $(TMP_MAP) diff --git a/utils/hwstub/stub/stmp/Makefile b/utils/hwstub/stub/stmp/Makefile index 14e6d0fbba..3ac7e3bbd4 100644 --- a/utils/hwstub/stub/stmp/Makefile +++ b/utils/hwstub/stub/stmp/Makefile @@ -5,10 +5,16 @@ CC=arm-elf-eabi-gcc LD=arm-elf-eabi-gcc AS=arm-elf-eabi-gcc OC=arm-elf-eabi-objcopy +SBTOELF=$(CURDIR)/../../../imxtools/sbtools/elftosb DEFINES= INCLUDES=-I$(CURDIR) GCCOPTS=-mcpu=arm926ej-s BUILD_DIR=$(CURDIR)/build/ ROOT_DIR=$(CURDIR)/.. - -include ../hwstub.make \ No newline at end of file +EXEC=$(BUILD_DIR)/hwstub.sb + +include ../hwstub.make + +$(BUILD_DIR)/hwstub.sb: $(EXEC_BIN) + $(call PRINTS,SBTOELF $(@F)) + $(SILENT)$(SBTOELF) -z -c hwstub.db -o $@ $< \ No newline at end of file diff --git a/utils/hwstub/stub/stmp/target.c b/utils/hwstub/stub/stmp/target.c index 390480a71c..9b005063bd 100644 --- a/utils/hwstub/stub/stmp/target.c +++ b/utils/hwstub/stub/stmp/target.c @@ -273,3 +273,18 @@ void target_exit(void) return; } } + +void target_udelay(int us) +{ + uint32_t cur = HW_DIGCTL_MICROSECONDS; + uint32_t end = cur + us; + if(cur < end) + while(HW_DIGCTL_MICROSECONDS < end) {} + else + while(HW_DIGCTL_MICROSECONDS >= cur) {} +} + +void target_mdelay(int ms) +{ + return target_udelay(ms * 1000); +} diff --git a/utils/hwstub/stub/target.h b/utils/hwstub/stub/target.h index 56c960741f..43151e9a34 100644 --- a/utils/hwstub/stub/target.h +++ b/utils/hwstub/stub/target.h @@ -31,5 +31,9 @@ void target_exit(void); int target_get_info(int info, void **buffer); /* set atexit action or return -1 on error */ int target_atexit(int action); +/* Wait a very short time (us<=1000) */ +void target_udelay(int us); +/* Wait for a short time (ms <= 1000) */ +void target_mdelay(int ms); #endif /* __TARGET_H__ */ diff --git a/utils/hwstub/stub/usb_drv_arc.c b/utils/hwstub/stub/usb_drv_arc.c index 32275b6adb..ab87be8a4c 100644 --- a/utils/hwstub/stub/usb_drv_arc.c +++ b/utils/hwstub/stub/usb_drv_arc.c @@ -23,6 +23,7 @@ #include "usb_drv.h" #include "config.h" #include "memory.h" +#include "target.h" #define MAX_PKT_SIZE 1024 #define MAX_PKT_SIZE_EP0 64 @@ -323,9 +324,11 @@ void usb_drv_init(void) /* we don't know if USB was connected or not. In USB recovery mode it will * but in other cases it might not be. In doubt, disconnect */ REG_USBCMD &= ~USBCMD_RUN; + /* wait a short time for the host to realise */ + target_mdelay(50); /* reset the controller */ REG_USBCMD |= USBCMD_CTRL_RESET; - while (REG_USBCMD & USBCMD_CTRL_RESET); + while(REG_USBCMD & USBCMD_CTRL_RESET); /* put it in device mode */ REG_USBMODE = USBMODE_CTRL_MODE_DEVICE; /* reset address */ -- cgit v1.2.3