diff --git a/cp210x-cfg/Makefile b/cp210x-cfg/Makefile deleted file mode 100755 index 09f77243a..000000000 --- a/cp210x-cfg/Makefile +++ /dev/null @@ -1,40 +0,0 @@ - -include $(TOPDIR)/rules.mk - -PKG_NAME:=cp210x-cfg -PKG_VERSION:=1 -PKG_RELEASE:=1 - -PKG_SOURCE_PROTO:=git -PKG_SOURCE_URL=https://github.com/iuncuim/cp210x-cfg.git -PKG_SOURCE_DATE:=2023-05-18 -PKG_SOURCE_VERSION:=bf968c49c7cf004ebfba72f7deb0ba88330e1652 -PKG_MIRROR_HASH:=skip - -include $(INCLUDE_DIR)/package.mk - -define Package/cp210x-cfg - SECTION:=utils - CATEGORY:=Utilities - TITLE:=CLI utility for programming CP210x USB<->UART bridges - DEPENDS:=+libusb-1.0 -endef - -TARGET_CFLAGS += -I$(STAGING_DIR)/usr/include -TARGET_LDFLAGS += -L$(STAGING_DIR)/usr/lib - -define Package/cp210x-cfg/description - CLI utility for programming CP210x USB<->UART bridges -endef - -define Build/Prepare - mkdir -p $(PKG_BUILD_DIR) - $(CP) ./src/* $(PKG_BUILD_DIR)/ -endef - -define Package/cp210x-cfg/install - $(INSTALL_DIR) $(1)/sbin - $(INSTALL_BIN) $(PKG_BUILD_DIR)/cp210x-cfg $(1)/sbin/ -endef - -$(eval $(call BuildPackage,cp210x-cfg)) diff --git a/fbfdownloader/Makefile b/fbfdownloader/Makefile deleted file mode 100755 index 47dea3c72..000000000 --- a/fbfdownloader/Makefile +++ /dev/null @@ -1,36 +0,0 @@ - -include $(TOPDIR)/rules.mk - -PKG_NAME:=fbfdownloader -PKG_VERSION:=4.9.0.7 -PKG_RELEASE:=1 -PKG_BUILD_DIR:=$(BUILD_DIR)/fbfdownloader - - -include $(INCLUDE_DIR)/package.mk - -define Package/fbfdownloader - SECTION:=utils - CATEGORY:=Utilities - DEPENDS+= +libpthread - TITLE:=Firmware flash tool for ASR based modems -endef - -TARGET_CFLAGS += -I$(STAGING_DIR)/usr/include -TARGET_LDFLAGS += -L$(STAGING_DIR)/usr/lib - -define Package/fbfdownloader/description - This package contains utility for sim check manage. -endef - -define Build/Prepare - mkdir -p $(PKG_BUILD_DIR) - $(CP) ./src/* $(PKG_BUILD_DIR)/ -endef - -define Package/fbfdownloader/install - $(INSTALL_DIR) $(1)/usr/bin - $(INSTALL_BIN) $(PKG_BUILD_DIR)/fbfdownloader_cross $(1)/usr/bin -endef - -$(eval $(call BuildPackage,fbfdownloader)) diff --git a/fbfdownloader/src/ApplicationINI.h b/fbfdownloader/src/ApplicationINI.h deleted file mode 100644 index 79b6302e9..000000000 --- a/fbfdownloader/src/ApplicationINI.h +++ /dev/null @@ -1,432 +0,0 @@ - -// -////////////////////////////////////////////////////////////////////// - -#pragma once -#pragma warning ( disable : 4100 ) // Disable warning messages: unreferenced formal parameter -#pragma warning ( disable : 4189 ) // Disable warning messages: local variable is initialized but not referenced -#include "Macrodef.h" -//#include "BLFProperty.h" -#include "EnumVal.h" -#define MAX_FILE_LENGTH 1024 -#define SECTOR_UNIT 512 -#define EMMC_ERASE_UNIT (512*1024) // 512K -#define NAND_ERASE_UNIT (128*1024) // 128K -#define NOR_ERASE_UNIT (64*1024) // 64K -#define READ_BLOCK_SIZE 0x800000 //8M - -//different partitions of EMMC -#define PRIBOOT_PARTITION 1 -#define RECVBOOT_PARTITION 2 -#define RPMB_PARTITION 3 -/* general commands */ -#define DLCMD_DO_ERASE_ALL_FLASH (1) -#define DLCMD_DO_UPLOAD_DATA (2) -#define DLCMD_RESETBBT (4) -#define DLCMD_DO_ERASE_ALL_ONLY (16) - -const static TCHAR* FBF_IDNAME = _T("FBFD"); -const static TCHAR* DKB_IDNAME = _T("DKBI"); -const static TCHAR* OBM_IDNAME = _T("OBMI"); -const static TCHAR* WTM_IDNAME = _T("WTMI"); -const static TCHAR* TZI_IDNAME = _T("TZII"); -const static TCHAR* ROMC_IDNAME = _T("ROMC"); -const static TCHAR* FBF_IMAGE_TYPE = _T("FBF"); - -const static TCHAR* pszDKB_TIM_HEADER_NAME = _T("DKB_ntimheader.bin"); -const static TCHAR* pszDKB_TRUST_TIM_HEADER_NAME = _T("DKB_timheader.bin"); -const static TCHAR* pszDKB_DUMMY_BIN = _T("DKB_dummy.bin"); -const static TCHAR* pszFBF_NTIM_HEADER_NAME = _T("FBF_Ntimheader.bin"); -const static TCHAR* pszFBF_TRUST_TIM_HEADER_NAME = _T("FBF_timheader.bin"); -const static TCHAR* pszDKB_FILE_NAME = _T("Dkb.bin"); -const static TCHAR* pszPREFERENCES = _T("Preferences"); -const static TCHAR* pszRUN_TIME_DLG = _T("Run-Time Dialog"); -const static TCHAR* pszTIM_CFG = _T("TIM_Configuration"); -const static TCHAR* pszBLF_VERSION_PRO = _T("BLF_Version"); -const static TCHAR* pszBLF_VERSION_NUMBER = _T("V2.0.0"); -const static TCHAR* pszBLF_VERSION_NUMBER_SECTOR_FLASH = _T("V2.1.0"); -const static TCHAR* pszBLF_VERSION_NUMBER_SECTOR_FLASH_WITH_DTIMPPSETTING = _T("V2.2.0"); -const static TCHAR* pszBLF_VERSION_NAND_NOR_FLASH = _T("V3.0.0"); -const static TCHAR* pszBLF_VERSION = _T("Blf_Version_Number"); -const static TCHAR* pszRESET_BBT = _T("Reset_BBT"); -const static TCHAR* pszFBF_SECTOR_SIZE = _T("FBF_Sector_Size"); -const static TCHAR* pszDATA_PAGE_SIZE = _T("Data_Area_Size" ); -const static TCHAR* pszSPARE_AREA_SIZE = _T("Spare_Area_Size" ); -const static TCHAR* pszNAND_BLOCK_SIZE = _T("Flash_Block_Size"); -const static TCHAR* pszMAX_OTA_IAMGE_SIZE = _T("Max_OTA_Image_Size"); -const static TCHAR* pszOTA_IAMGE_SPLIT_SIZE = _T("OTA_Image_Split_Size"); -const static TCHAR* pszFLASH_FAMILY_PRO = _T("Flash_Family" ); -const static TCHAR* pszSKIP_BLOCK_NUMBER = _T("Skip_Blocks_Number"); -const static TCHAR* pszERASE_ALL_FLASH = _T("Erase_All_Flash"); -const static TCHAR* pszBOOTOPTION_AFTER_FLASH = _T("UE_Boot_Option"); -const static TCHAR* pszPROCESSOR_TYPE = _T("Processor_Type"); -const static TCHAR* pszBOOT_FLASH_SIG = _T("Boot_Flash_Signature"); -const static TCHAR* pszTRUSTED = _T("Trusted"); -const static TCHAR* pszVERSION = _T("Version"); -const static TCHAR* pszISSUDT = _T("Issue_Date"); -const static TCHAR* pszOEMUID = _T("OEM_UniqueID"); -const static TCHAR* pszSIZE_OF_IMG = _T("Number_of_Images"); -const static TCHAR* pszSIZE_OF_EMMCTYPE = _T("Number_of_EMMCTypes"); -const static TCHAR* pszSIZE_OF_RSV = _T("Size_of_Reserved_in_bytes"); -const static TCHAR* pszNUM_OF_KEYS = _T("Number_of_Keys"); -const static TCHAR* pszEXT_RSV_DATA = _T("[Extended_Reserved_Data]"); -const static TCHAR* pszRSV_DATA = _T("[Reserved_Data]"); -const static TCHAR* pszEND_RSV_DATA = _T("End_Reserved_Data"); -const static TCHAR* pszFBF_SPLIT_SIZE_SETTING = _T("Max_FBF_Split_Size"); -const static TCHAR* pszUPLOAD_MAX_SIZE_SETTING = _T("Max_Upload_Split_Size" ); -const static TCHAR* pszWTM_FL_SIGTURE = _T("WTM_Save_State_Flash_Signature"); -const static TCHAR* pszWTM_FL_EN_ADDR = _T("WTM_Save_State_Flash_Entry_Address"); -const static TCHAR* pszWTM_BK_EN_ADDR = _T("WTM_Save_State_BackUp_Entry_Address"); - - -const static TCHAR* pszAUTH_PATH = _T("Authentication Path"); -const static TCHAR* pszST_ADDR = _T("Start_Address"); -const static TCHAR* pszIMG_LIST = _T("Image_List"); -const static TCHAR* pszENBL = _T("Enable"); -const static TCHAR* pszTIM_INCLUDED = _T("Tim_Included"); -const static TCHAR* pszPATH = _T("Path"); -const static TCHAR* pszFL_ENTRY_ADDR = _T("Flash_Entry_Address"); -const static TCHAR* pszLOAD_ADDR = _T("Load_Address"); -const static TCHAR* pszSIZE_OF_IMGTOCRC = _T("Size_To_CRC_in_bytes"); -const static TCHAR* pszSIZE_OF_IMGTOHASH = _T("Image_Size_To_Hash_in_bytes"); -const static TCHAR* pszSIZE_OF_ERASE = _T("Erase_Size"); -const static TCHAR* pszPARTITION = _T("Partition_Number"); -const static TCHAR* pszIMGID_NAME = _T("ID_Name"); -const static TCHAR* pszIMGID = _T("Image_ID"); -const static TCHAR* pszNTIMGID = _T("Next_Image_ID"); -const static TCHAR* pszHASH_ALGT_ID = _T("Hash_Algorithm_ID"); -const static TCHAR* pszOFST = _T("Offset"); -const static TCHAR* pszTYPE = _T("Type"); -const static TCHAR* pszFLASH_PROP = _T("Flash_Properties"); -const static TCHAR* pszFLASH_OPTIONS = _T("Flash_Options"); -const static TCHAR* pszUE_OPTIONS = _T("UE_Options"); -const static TCHAR* pszNONE_ERASESIZE = _T(""); -const static TCHAR* pszSPARE_SIZE = _T("Spare_Area_Size"); -const static TCHAR* pszDATA_SIZE = _T("Data_Area_Size"); -const static TCHAR* pszFLASHNANDID = _T("Flash_NandID"); -const static TCHAR* pszJTAG_TRUSTED = _T("JTAG TRUSTED"); -const static TCHAR* pszJTAG_TIM = _T("TIM Path"); -const static TCHAR* pszJTAG_KEY = _T("KEY Path"); -const static TCHAR* pszPACKAGE_SIZE = _T("Package_Size"); - - - -const static TCHAR* pszERASE_ONLY_OPTION = _T("EraseOnly_Option"); -const static TCHAR* pszERASE_ONLY_NUM = _T("Total_Eraseonly_Areas"); -const static TCHAR* pszERASE_ONLY_START_ADD = _T("Eraseonly_Area_FlashStartAddress"); -const static TCHAR* pszERASE_ONLY_SIZE = _T("Eraseonly_Area_Size"); -const static TCHAR* pszERASE_ONLY_PARTITION = _T("Eraseonly_Area_Partition"); - - -//Add support for trusted mode -const static TCHAR* pszDIGITAL_SIGNATURE_DATA = _T("Digital_Signature_Data"); -const static TCHAR* pszEND_DIGITAL_SIGNATURE_DATA = _T("End_Digital_Signature_Data"); -const static TCHAR* pszKEYS_DATA = _T("Keys_Data"); -const static TCHAR* pszDSA_ALGORITHM = _T("DSA_Algorithm"); -const static TCHAR* pszHASHALG_ID = _T("Hash_Algorithm_ID"); -const static TCHAR* pszENCRYPT_ALGID = _T("Encrypt_Algorithm_ID"); -const static TCHAR* pszKEY_ID = _T("Key_ID"); -const static TCHAR* pszMODULUS_SIZE = _T("Modulus_Size_in_bytes"); -const static TCHAR* pszKEY_SIZE = _T("Key_Size_in_bits"); -const static TCHAR* pszPUBLIC_KEY_SIZE = _T("Public_Key_Size_in_bytes"); -const static TCHAR* pszRSA_PUBLIC_EXP = _T("RSA_Public_Exponent"); -const static TCHAR* pszEND_RSA_PUBLIC_EXP = _T("End_RSA_Public_Exponent"); -const static TCHAR* pszRSA_SYS_MODULUS = _T("RSA_System_Modulus"); -const static TCHAR* pszEND_RSA_SYS_MODULUS = _T("End_RSA_System_Modulus"); -const static TCHAR* pszRSA_PRIVATE_KEY = _T("RSA_Private_Key"); -const static TCHAR* pszEND_RSA_PRIVATE_KEY = _T("End_RSA_Private_Key"); -const static TCHAR* pszECDSA_PUBLIC_KEY_COMX = _T("ECDSA_Public_Key_CompX"); -const static TCHAR* pszEND_ECDSA_PUBLIC_KEY_COMX = _T("End_ECDSA_Public_Key_CompX"); -const static TCHAR* pszECDSA_PUBLIC_KEY_COMY = _T("ECDSA_Public_Key_CompY"); -const static TCHAR* pszEND_ECDSA_PUBLIC_KEY_COMY = _T("End_ECDSA_Public_Key_CompY"); -const static TCHAR* pszECDSA_PRIVATE_KEY = _T("ECDSA_Private_Key"); -const static TCHAR* pszEND_ECDSA_PRIVATE_KEY = _T("End_ECDSA_Private_Key"); - - -const static TCHAR* pszEND_EXT_RSV_DATA = _T("End_Extended_Reserved_Data"); -const static TCHAR* pszCLK_ENABLE = _T("Clock_Enable"); -const static TCHAR* pszEND_CLK_ENABLE = _T("End_Clock_Enable"); -const static TCHAR* pszDDR_GEO = _T("DDR_Geometry"); -const static TCHAR* pszEND_DDR_GEO = _T("End_DDR_Geometry"); -const static TCHAR* pszDDR_TIMING = _T("DDR_Timing"); -const static TCHAR* pszEND_DDR_TIMING = _T("End_DDR_Timing"); -const static TCHAR* pszDDR_CUSTOM = _T("DDR_Custom"); -const static TCHAR* pszEND_DDR_CUSTOM = _T("End_DDR_Custom"); -const static TCHAR* pszFREQ = _T("Frequency"); -const static TCHAR* pszEND_FREQ = _T("End_Frequency"); -const static TCHAR* pszVOL = _T("Voltages"); -const static TCHAR* pszEND_VOL = _T("End_Voltages"); -const static TCHAR* pszCFG_MEM_CTRL = _T("Configure_Memory_Control"); -const static TCHAR* pszEND_CFG_MEM_CTRL = _T("End_Configure_Memory_Control"); -const static TCHAR* pszTRUST_Z = _T("Trust_Zone"); -const static TCHAR* pszEND_TRUST_Z = _T("End_Trust_Zone"); -const static TCHAR* pszTRUST_Z_RE = _T("Trust_Zone_Regid"); -const static TCHAR* pszEND_TRUST_Z_RE = _T("End_Trus_Zone_Regid"); -const static TCHAR* pszOPDIV = _T("OpDiv"); -const static TCHAR* pszEND_OPDIV = _T("End_OpDiv"); -const static TCHAR* pszOPMOD = _T("OpMode"); -const static TCHAR* pszEND_OPMOD = _T("End_OpMode"); -const static TCHAR* pszERDVEC = _T("ErdVec"); -const static TCHAR* pszEND_ERDVEC = _T("End_ErdVec"); - -const static TCHAR* pszTR069_INFO = _T("TRFU"); -const static TCHAR* pszTR069_ENABLED = _T("Enabled"); -const static TCHAR* pszTR069_FLASH_ADDR = _T("Flash_Address"); -const static TCHAR* pszTR069_MAGIC = _T("Magic"); -const static TCHAR* pszTR069_INFO_END = _T("End_TRFU"); - -const static TCHAR* pszFOTA_INFO = _T("OTAI"); -const static TCHAR* pszFOTA_ENABLED = _T("Enabled"); -const static TCHAR* pszFOTA_FLASH_ADDR = _T("Flash_Address"); -const static TCHAR* pszFOTA_MAGIC = _T("Magic"); -const static TCHAR* pszFOTA_INFO_END = _T("End_OTAI"); - -const static TCHAR* pszDDR_TYPE_BEGIN = _T("DTYP"); -const static TCHAR* pszDDR_TYPE_VALUE = _T("DDR_Type"); -const static TCHAR* pszDDR_TYPE_END = _T("End_DTYP"); - -const static TCHAR* pszDDR_BYTE_SELECT_BEGIN = _T("DDBS"); -const static TCHAR* pszDDR_BYTE_SELECT = _T("DDR_Byte_Select"); -const static TCHAR* pszDDR_BYTE_SELECT_END = _T("End_DDBS"); - - -//LTG LWG SELECT PACKAGE -const static TCHAR* pszLTG_LWG_SELECT_BEGIN = _T("LTWS"); -const static TCHAR* pszLTG_LWG_SELECT_VALUE = _T("LTG_LWG_Select"); -const static TCHAR* pszLTG_LWG_SELECT_END = _T("End_LTWS"); - -const static TCHAR* pszCUSTOMER_TRANSFER_INFO = _T("CITA_CUMIZED_INFO_TRANSFER_TOAP_ID"); -const static TCHAR* pszCUSTOMER_TRANSFER_INFO_END = _T("End_CITA_CUMIZED_INFO_TRANSFER_TOAP_ID"); - -const static TCHAR* pszBBMIDTYPE = _T("BBMT"); -const static TCHAR* pszBBMIDTYPE_END = _T("End_BBMT"); - -const static TCHAR* pszFLASHGEOPKGID = _T("FGPI"); -const static TCHAR* pszFLASHGEOPKGID_END = _T("End_FGPI"); - -const static TCHAR* pszBBCS_BEGIN = _T("BBCS"); -const static TCHAR* pszBBCS_VALUE = _T("Enabled"); -const static TCHAR* pszBBCS_END = _T("End_BBCS"); - -const static TCHAR* pszCRCS_BEGIN = _T("CRCS"); -const static TCHAR* pszCRCS_VALUE = _T("Enabled"); -const static TCHAR* pszCRCS_END = _T("End_CRCS"); - -// Added by ZQQ to support DTIM 2012-03-28 -const static TCHAR* pszDTIM_KEYS_DATA = _T("DTIM_Keys_Data"); -const static TCHAR* pszEND_DTIM_KEYS_DATA = _T("End_DTIM_Keys_Data"); - -const static TCHAR* pszPRODUCTION_MODE = _T("ProductionMode"); - -const static TCHAR* pszDDR_FLASH_MCP_MAP = _T("DDR_Flash_Mcp_Map"); -const static TCHAR* pszEND_DDR_FLASH_MCP_MAP = _T("End_DDR_Flash_Mcp_Map"); - -// definition for PXA92x -//Added by zqq 2012-2-3 - -const static TCHAR* pszPXA92x_TIM_CFG = _T("TIM Configuration"); -const static TCHAR* pszPXA92x_SKIP_BLOCK_CFG = _T("Skip Block Configuration"); -const static TCHAR* pszPXA92x_TRUSTED = _T("Trusted"); -const static TCHAR* pszPXA92x_TOTAL_SKIPBLOCK = _T("Total Skip Block Numbers"); -const static TCHAR* pszPXA92x_SKIP_BLOCK_NUMBER = _T("Skip Block Number"); -const static TCHAR* pszPXA92x_ERASE_ALL_FLASH = _T("Erase All Flash"); -const static TCHAR* pszPXA92x_FLASHER_ADRES = _T("FlasherLoadAddress"); -const static TCHAR* pszPXA92x_VERSION = _T("Version"); -const static TCHAR* pszPXA92x_ISSUDT = _T("Issue Date"); -const static TCHAR* pszPXA92x_OEMUID = _T("OEM UniqueID"); -const static TCHAR* pszPXA92x_PROCESSOR_TYPE = _T("Processor Type"); -const static TCHAR* pszPXA92x_BOOT_FLASH_SIG = _T("Boot Flash Signature"); -const static TCHAR* pszPXA92x_SIZE_OF_IMG = _T("Number of Images"); -const static TCHAR* pszPXA92x_SIZE_OF_RSV = _T("Size of Reserved in bytes"); -const static TCHAR* pszPXA92x_NUM_OF_KEYS = _T("Number of Keys"); -const static TCHAR* pszPXA92x_EXT_RSV_DATA = _T("Extended Reserved Data"); -const static TCHAR* pszPXA92x_END_EXT_RSV_DATA = _T("End Extended Reserved Data"); -const static TCHAR* pszPXA92x_RSV_DATA = _T("[Reserved Data]"); -const static TCHAR* pszPXA92x_END_RSV_DATA = _T("End Reserved Data"); -const static TCHAR* pszPXA92x_WTM_FL_SIGTURE = _T("WTM Save State Flash Signature"); -const static TCHAR* pszPXA92x_WTM_FL_EN_ADDR = _T("WTM Save State Flash Entry Address"); -const static TCHAR* pszPXA92x_WTM_BK_EN_ADDR = _T("WTM Save State BackUp Entry Address"); - - -const static TCHAR* pszPXA92x_FL_PATH = _T("Flasher Path"); -const static TCHAR* pszPXA92x_AUTH_PATH = _T("Authentication Path"); -const static TCHAR* pszPXA92x_JTAG_TIM_PATH = _T("Jtag TIM File Path"); -const static TCHAR* pszPXA92x_ST_ADDR = _T("Start Address"); -const static TCHAR* pszPXA92x_IMEI_PATH = _T("IMEI File Path"); -const static TCHAR* pszPXA92x_MEP_PATH = _T("MEP File Path"); -const static TCHAR* pszPXA92x_IMG_LIST = _T("Image List"); -const static TCHAR* pszPXA92x_ENBL = _T("Enable"); -const static TCHAR* pszPXA92x_PATH = _T("Path"); -const static TCHAR* pszPXA92x_FL_ENTRY_ADDR = _T("Flash Entry Address"); -const static TCHAR* pszPXA92x_LOAD_ADDR = _T("Load Address"); -const static TCHAR* pszPXA92x_SIZE_OF_IMGTOCRC = _T("Image Size To CRC in bytes"); -const static TCHAR* pszPXA92x_SIZE_OF_IMGTOHASH = _T("Image Size To Hash in bytes"); -const static TCHAR* pszPXA92x_SIZE_OF_ERASE = _T("Erase Size"); - - -const static TCHAR* pszPXA92x_PARTITION = _T("Partition Number"); -const static TCHAR* pszPXA92x_IMGID_NAME = _T("ID Name"); -const static TCHAR* pszPXA92x_IMGID = _T("Image ID"); -const static TCHAR* pszPXA92x_NTIMGID = _T("Next Image ID"); -const static TCHAR* pszPXA92x_HASH_ALGT_ID = _T("Hash Algorithm ID"); -const static TCHAR* pszPXA92x_OFST = _T("Offset"); -const static TCHAR* pszPXA92x_TYPE = _T("Type"); -const static TCHAR* pszPXA92x_OLD_FLASHER = _T("Flasher Property"); -const static TCHAR* pszPXA92x_FLASH_PROP = _T("Flash Properties"); -const static TCHAR* pszPXA92x_CFG_FILE_PATH = _T("Flash Configuration File Path"); -const static TCHAR* pszPXA92x_TAVOR_PROP = _T("Tavor Flasher Properties"); -const static TCHAR* pszPXA92x_NONE_ERASESIZE = _T(""); -const static TCHAR* pszPXA92x_SPARE_SIZE = _T("Spare Area Size"); -const static TCHAR* pszPXA92x_DATA_SIZE = _T("Data Area Size"); - -const static TCHAR* pszPXA92x_JTAG_TRUSTED = _T("JTAG TRUSTED"); -const static TCHAR* pszPXA92x_JTAG_TIM = _T("TIM Path"); -const static TCHAR* pszPXA92x_JTAG_KEY = _T("KEY Path"); - -const static TCHAR* pszPXA92x_ERASE_ALL = _T("Erase All"); -const static TCHAR* pszPXA92x_END_ERASE_ALL = _T("End Erase All"); -const static TCHAR* pszPXA92x_CLK_ENABLE = _T("Clock Enable"); -const static TCHAR* pszPXA92x_END_CLK_ENABLE = _T("End Clock Enable"); -const static TCHAR* pszPXA92x_DDR_GEO = _T("DDR Geometry"); -const static TCHAR* pszPXA92x_END_DDR_GEO = _T("End DDR Geometry"); -const static TCHAR* pszPXA92x_DDR_TIMING = _T("DDR Timing"); -const static TCHAR* pszPXA92x_END_DDR_TIMING = _T("End DDR Timing"); -const static TCHAR* pszPXA92x_DDR_CUSTOM = _T("DDR Custom"); -const static TCHAR* pszPXA92x_END_DDR_CUSTOM = _T("End DDR Custom"); -const static TCHAR* pszPXA92x_FREQ = _T("Frequency"); -const static TCHAR* pszPXA92x_END_FREQ = _T("End Frequency"); -const static TCHAR* pszPXA92x_VOL = _T("Voltages"); -const static TCHAR* pszPXA92x_END_VOL = _T("End Voltages"); -const static TCHAR* pszPXA92x_CFG_MEM_CTRL = _T("Configure Memory Control"); -const static TCHAR* pszPXA92x_END_CFG_MEM_CTRL = _T("End Configure Memory Control"); -const static TCHAR* pszPXA92x_TRUST_Z = _T("Trust Zone"); -const static TCHAR* pszPXA92x_END_TRUST_Z = _T("End Trust Zone"); -const static TCHAR* pszPXA92x_TRUST_Z_RE = _T("Trust Zone Regid"); -const static TCHAR* pszPXA92x_END_TRUST_Z_RE = _T("End Trust Zone Regid"); -const static TCHAR* pszPXA92x_OPDIV = _T("OpDiv"); -const static TCHAR* pszPXA92x_END_OPDIV = _T("End OpDiv"); -const static TCHAR* pszPXA92x_OPMOD = _T("OpMode"); -const static TCHAR* pszPXA92x_END_OPMOD = _T("End OpMode"); -const static TCHAR* pszPXA92x_ERDVEC = _T("ErdVec"); -const static TCHAR* pszPXA92x_END_ERDVEC = _T("End ErdVec"); -const static TCHAR* pszPXA92x_DEVICE_USB_MAP = _T("DEVICE_USBPORT_MAP"); -const static TCHAR* pszPXA92x_DEVICE_USBPORT_NUMBER = _T("MAX Device USB Port Number"); -const static TCHAR* pszPXA92x_DEVICE_USB_PORT = _T("Device USB Port"); -const static TCHAR* pszPXA92x_ERASE_ONLY = _T("Erase only Area"); -const static TCHAR* pszPXA92x_ERASE_ONLY_NUM = _T("Erase Area Num"); -const static TCHAR* pszPXA92x_ERASE_ONLY_START_ADD = _T("Erase Flash Start Address"); -const static TCHAR* pszPXA92x_ERASE_ONLY_LENGTH = _T("Erase Length"); -const static TCHAR* pszPXA92x_ERASE_ONLY_PARTITION = _T("Erase Area Partition"); -const static TCHAR* pszPXA92x_DEV_HEADER_0 = _T("DEV_HEADER_0"); -const static TCHAR* pszPXA92x_BLOCK_SIZE_NAME = _T("Block_Size_0"); -const static TCHAR* pszPXA92x_FLASHFAMLIY = _T("FlashFamily"); -const static TCHAR* pszPXA92x_FLASHINI = _T("INTEL_FLASHER_INPUT_FILE"); -const static TCHAR* pszPXA92x_FLASH_BLOCKS = _T("Number_of_Blocks_0"); - - - - -const static TCHAR* pszUPLOAD_PROPERTY = _T("Upload_Property"); -const static TCHAR* pszMAX_UPLOAD_SIZE = _T("Max_Upload_Size"); -const static TCHAR* pszUPLOADAREA_NUM = _T("Upload_Area_Nums"); -const static TCHAR* pszUPLOAD_RESETUE = _T("ResetUE_AfterUpload"); -const static TCHAR* pszUPLOAD_TIMEDELAY_RESET = _T("Reset_DelayTime"); -const static TCHAR* pszUPLOADAREA_LIST = _T("Upload_Areas_List"); -const static TCHAR* pszUPLOADAREA_TYPE = _T("Area_Type"); -const static TCHAR* pszUPLOADAREA_SUBTYPE = _T("Area_SubType"); -const static TCHAR* pszUPLOADAREA_OFFSET = _T("Area_Offset"); -const static TCHAR* pszUPLOADAREA_DATATSIZE = _T("Area_DataSize"); -const static TCHAR* pszUPLOADAREA_PARTITION = _T("Area_Partition"); -const static TCHAR* pszUPLOADAREA_SPAREAREA = _T("Area_UploadWithSpareArea"); -const static TCHAR* pszUPLOADAREA_SAVEFILE = _T("Area_UploadData_SaveFile"); -const static TCHAR* pszBLFVERSION = _T("Blf_Version"); -const static TCHAR* pszFlashFamily = _T("Flash_Family"); -const static TCHAR* pszPlatFormType = _T("PlatForm_Type"); - -const static TCHAR* pszEMMCIMAGEPROPERTY = _T("EMMC_Images_list_Property"); -const static TCHAR* pszEMMCIMGIDNUM = _T("ImageID_num"); -const static TCHAR* pszEMMCTYPECFG = _T("EmmcType"); - -//mutliple Nand size -const static TCHAR* pszNAND_SIGNATURE_NUMBER = _T("Nand_Signature_Number"); -const static TCHAR* pszNAND_IMAGE_PROPERTY = _T("Nand_Images_list_Property"); -const static TCHAR* pszNANDSIGN = _T("NandSign"); -const static TCHAR* pszNANDSIGN_VALUE = _T("NandSign_Value"); -const static TCHAR* pszNANDSIGN_NANDIDNUMBER = _T("NandSign_NandIdNumber"); -const static TCHAR* pszNANDID = _T("NandId"); -const static TCHAR* pszNANDSIZE = _T("NandSize"); -const static TCHAR* pszIMAGENUMBER = _T("ImageNumber"); - -//#define pszNAND_SIGNATURE_NUMBER _T("NAND_Signature_Number") -//#define pszNAND_IMAGE_PROPERTY _T("NAND_Images_list_Property") -//#define pszNANDSIGN _T("NandSign") -//#define pszNANDSIGN_VALUE _T("NandSign_Value") -//#define pszNANDSIGN_NANDIDNUMBER _T("NandSign_NandIdNumber") -//#define pszNANDID _T("NandId") -//#define pszNANDSIZE _T("NandSize") -//#define pszIMAGENUMBER _T("ImageNumber") - - - - - - - - - - - - - - - - -#define MAX_DDR_VENDOR_NUM 34 -#define MAX_DDR_SIZE_NUM 20 - -struct stDdrVendorIdNameMap{ - unsigned int nDdrVendorID; - TCHAR strDdrVendorName[128]; -}; - -static const struct stDdrVendorIdNameMap vendorDdrPidNameMap[MAX_DDR_VENDOR_NUM]={ - {0x01,_T("SAMSUNG")}, - {0x02,_T("QIMONDA")}, - {0x03,_T("ELPIDA")}, - {0x04,_T("ETRON")}, - {0x05,_T("NANYA")}, - {0x06,_T("HYNIX")}, - {0x07,_T("MOSEL")}, - {0x08,_T("WINBOND")}, - {0x09,_T("ESMT")}, - {0x0A,_T("RESERVED")}, - {0x0B,_T("SPANSION")}, - {0x0C,_T("SST")}, - {0x0D,_T("ZMOS")}, - {0x0E,_T("INTEL")}, - {0x0F,_T("NUMONYX")}, - {0x10,_T("MICRON")}, - {0x11,_T("TOSHIBA")}, - {0x12,_T("FIDELIX")}, - {0x13,_T("ReservedVendor1")}, - {0x14,_T("ReservedVendor2")}, - {0x15,_T("ReservedVendor3")}, - {0x16,_T("ReservedVendor4")}, - {0x17,_T("ReservedVendor5")}, - {0x18,_T("ReservedVendor6")}, - {0x19,_T("ReservedVendor7")}, - {0x1A,_T("ReservedVendor8")}, - {0x1B,_T("ReservedVendor9")}, - {0x1C,_T("JSC")}, - {0x1D,_T("ReservedVendor11")}, - {0x1E,_T("ReservedVendor12")}, - {0xF8,_T("Fidelix")}, - {0xFD,_T("ESMT2")}, - {0xFE,_T("Numonyx")}, - {0xFF,_T("Micron")}, -}; - - -#define RESERVED_DDR_FOR_SMALLMEMORY 0x300000 /* Reserved 3MB DDR Size for OBM on platform Nezha and Nezha2 */ -#define RESERVED_DDR_FOR_LARGEMEMORY 0x1E00000 /* Reserved 30MB DDR Size for OBM */ -#define UNIT_GB 0x40000000 diff --git a/fbfdownloader/src/BinFileWtp.c b/fbfdownloader/src/BinFileWtp.c deleted file mode 100644 index fd5b3d871..000000000 --- a/fbfdownloader/src/BinFileWtp.c +++ /dev/null @@ -1,353 +0,0 @@ -#include "CommonFun.h" -#include "BinFileWtp.h" -#include -#define BINFILE _T("BinFile.bin") - - - -BOOL BinFileWtp_OpenBinFile(struct CBinFileWtp *me, const TCHAR *strOpenMode) -{ - - if (me->m_fBinFile) - BinFileWtp_CloseBinFIle(me); - me->m_fBinFile = _tfopen((const TCHAR *)me->m_strBinFilePath, strOpenMode); - if (NULL == me->m_fBinFile) - { - printf("Open BinFile.bin Failed!\n"); - return FALSE; - } - else - { - printf("Open BinFile.bin Successed!\n"); - return TRUE; - } -} - -UINT32 BinFileWtp_ReadBinFile(struct CBinFileWtp *me, void *buffer, size_t size, size_t count, const TCHAR *pszBinFile) -{ - UINT32 ret = 0; - UINT32 uRemain = 0; - UINT32 uRPos = 0; - khiter_t kfs, kfp; - kfs = kh_get(str2fs, me->m_mapFile2Struct, pszBinFile); - if (kfs == kh_end(me->m_mapFile2Struct)) - return ret; - uRemain = size * count; - kfp = kh_get(str2n, me->m_mapFile2PointPos, pszBinFile); - uRPos = kh_value(me->m_mapFile2PointPos, kfp); - if (0 == kh_value(me->m_mapFile2Struct, kfs).Head2 && 0 == kh_value(me->m_mapFile2Struct, kfs).Mid1 && 0 == kh_value(me->m_mapFile2Struct, kfs).Mid2 && 0 == kh_value(me->m_mapFile2Struct, kfs).Tail1) - { - fseek(me->m_fBinFile, uRPos, SEEK_SET); - ret = fread(buffer, size, count, me->m_fBinFile); - kh_value(me->m_mapFile2PointPos, kfp) += size * count; - } - else //分段读取情况 - { - fseek(me->m_fBinFile, uRPos, SEEK_SET); - if (uRPos >= kh_value(me->m_mapFile2Struct, kfs).Head1 && uRPos < kh_value(me->m_mapFile2Struct, kfs).Head2) - { - if (uRemain < kh_value(me->m_mapFile2Struct, kfs).Head2 - uRPos) - { - ret += fread(buffer, sizeof(BYTE), uRemain, me->m_fBinFile); - kh_value(me->m_mapFile2PointPos, kfp) += uRemain; - uRemain = 0; - } - else - { - ret += fread(buffer, sizeof(BYTE), kh_value(me->m_mapFile2Struct, kfs).Head2 - uRPos, me->m_fBinFile); - uRemain -= (kh_value(me->m_mapFile2Struct, kfs).Head2 - uRPos); - buffer = (void *)((char *)buffer + kh_value(me->m_mapFile2Struct, kfs).Head2 - uRPos); - uRPos = kh_value(me->m_mapFile2Struct, kfs).Mid1; - kh_value(me->m_mapFile2PointPos, kfp) = uRPos; - fseek(me->m_fBinFile, uRPos, SEEK_SET); - } - } - if (uRPos >= kh_value(me->m_mapFile2Struct, kfs).Mid1 && uRPos < kh_value(me->m_mapFile2Struct, kfs).Mid2) - { - if (uRemain < kh_value(me->m_mapFile2Struct, kfs).Mid2 - uRPos) - { - ret += fread(buffer, sizeof(BYTE), uRemain, me->m_fBinFile); - uRPos += uRemain; - kh_value(me->m_mapFile2PointPos, kfp) = uRPos; - uRemain = 0; - } - else - { - ret += fread(buffer, sizeof(BYTE), kh_value(me->m_mapFile2Struct, kfs).Mid2 - uRPos, me->m_fBinFile); - uRemain -= (kh_value(me->m_mapFile2Struct, kfs).Mid2 - uRPos); - buffer = (void *)((char *)buffer + kh_value(me->m_mapFile2Struct, kfs).Mid2 - uRPos); - uRPos = kh_value(me->m_mapFile2Struct, kfs).Tail1; - kh_value(me->m_mapFile2PointPos, kfp) = uRPos; - fseek(me->m_fBinFile, uRPos, SEEK_SET); - } - } - if (uRPos >= kh_value(me->m_mapFile2Struct, kfs).Tail1 && uRPos < kh_value(me->m_mapFile2Struct, kfs).Tail2) - { - ret += fread(buffer, sizeof(BYTE), uRemain, me->m_fBinFile); - kh_value(me->m_mapFile2PointPos, kfp) += uRemain; - uRemain = 0; - } - } - return ret; -} - -int BinFileWtp_FseekBin(struct CBinFileWtp *me, const TCHAR *pszBinFile, long _Offset, int _Origin) -{ - int ret; - khint_t kfs, kfp; - kfp = kh_get(str2n, me->m_mapFile2PointPos, pszBinFile); - kfs = kh_get(str2fs, me->m_mapFile2Struct, pszBinFile); - if (kfp == kh_end(me->m_mapFile2PointPos) || kfs == kh_end(me->m_mapFile2Struct)) - return -1; - if (SEEK_SET == _Origin) - { - ret = fseek(me->m_fBinFile, kh_value(me->m_mapFile2Struct, kfs).Head1 + _Offset, SEEK_SET); - kh_value(me->m_mapFile2PointPos, kfp) = kh_value(me->m_mapFile2Struct, kfs).Head1 + _Offset; - } - else if (SEEK_END == _Origin) - { - ret = fseek(me->m_fBinFile, kh_value(me->m_mapFile2Struct, kfs).Tail2 + _Offset, SEEK_SET); - kh_value(me->m_mapFile2PointPos, kfp) = kh_value(me->m_mapFile2Struct, kfs).Tail2 + _Offset; - } - else - { - fseek(me->m_fBinFile, kh_value(me->m_mapFile2PointPos, kfp) + _Offset, SEEK_SET); - } - return ret; -} - -UINT32 BinFileWtp_GetFileSize(struct CBinFileWtp *me, const TCHAR *pszBinFile) -{ - khiter_t kfs; - kfs = kh_get(str2fs, me->m_mapFile2Struct, pszBinFile); - if (kh_end(me->m_mapFile2Struct) == kfs) - return 0; - else - { - return kh_value(me->m_mapFile2Struct, kfs).Head2 - kh_value(me->m_mapFile2Struct, kfs).Head1 + kh_value(me->m_mapFile2Struct, kfs).Mid2 - kh_value(me->m_mapFile2Struct, kfs).Mid1 + kh_value(me->m_mapFile2Struct, kfs).Tail2 - kh_value(me->m_mapFile2Struct, kfs).Tail1; - } -} - -void BinFileWtp_CloseBinFIle(struct CBinFileWtp *me) -{ - if (NULL != me->m_fBinFile) - { - fclose(me->m_fBinFile); - me->m_fBinFile = NULL; - } -} - -void BinFileWtp_FreshBinOffset(struct CBinFileWtp *me) -{ - fseek(me->m_fBinFile, 0, SEEK_END); - me->m_uFileOffset = ftell(me->m_fBinFile); -} - -void BinFileWtp_ResetPara(struct CBinFileWtp *me) -{ - me->m_bHaveInitForFbfDown = FALSE; - me->m_uFileOffset = 0; - me->m_fBinFile = NULL; - if (me->m_mapFile2PointPos) - kh_destroy(str2n, me->m_mapFile2PointPos); - if (me->m_mapFile2Struct) - kh_destroy(str2fs, me->m_mapFile2Struct); - me->m_mapFile2PointPos = kh_init(str2n); - me->m_mapFile2Struct = kh_init(str2fs); -} - -void BinFileWtp_InitRead(struct CBinFileWtp *me) -{ - khiter_t kfs, kfp; - int ret; - for (kfs = kh_begin(me->m_mapFile2Struct); kfs != kh_end(me->m_mapFile2Struct); ++kfs) - if (kh_exist(me->m_mapFile2Struct, kfs)) - { - kfp = kh_put(str2n, me->m_mapFile2PointPos, kh_key(me->m_mapFile2Struct, kfs), &ret); - kh_value(me->m_mapFile2PointPos, kfp) = kh_value(me->m_mapFile2Struct, kfs).Head1; - } -} - -void BinFileWtp_InitParameter(struct CBinFileWtp *me) -{ - TCHAR buffer[1024]; - khiter_t kfp, kfs; - char *pstr; - int ret; - if (me->m_bHaveInitForFbfDown) - return; - BinFileWtp_ResetPara(me); -#if !defined(LINUX) - memset(me->m_strBinFilePath, 0x00, sizeof(me->m_strBinFilePath)); - tsnprintf(me->m_strBinFilePath, sizeof(me->m_strBinFilePath), _T("%s\\temp\\%s"), (pstr = GetAppPath().s), BINFILE); - free(pstr); -#else - memset(me->m_strBinFilePath, 0x00, sizeof(me->m_strBinFilePath)); - tsnprintf(me->m_strBinFilePath, sizeof(me->m_strBinFilePath), _T("%s/temp/%s"), (pstr = GetAppPath().s), BINFILE); - free(pstr); -#endif - - UINT32 uValue; - BinFileWtp_OpenBinFile(me, _T("rb")); - fseek(me->m_fBinFile, -1L * sizeof(UINT32), SEEK_END); - //读FBF文件最后的偏移,之后的为map信息 - fread(&uValue, sizeof(UINT32), 1, me->m_fBinFile); - printf("Read from File Value is %x\n", uValue); - uValue = le32toh(uValue); - printf("After Convert Value is %x\n", uValue); - fseek(me->m_fBinFile, uValue, SEEK_SET); - //读map size - fread(&uValue, sizeof(UINT32), 1, me->m_fBinFile); - uValue = le32toh(uValue); - unsigned int i = uValue; - while (i) - { - i--; - memset(buffer, 0, sizeof(buffer)); - //读路径文件长度 - fread(&uValue, sizeof(UINT32), 1, me->m_fBinFile); - //读路径文件 - uValue = le32toh(uValue); - fread(buffer, 1, uValue, me->m_fBinFile); - kfs = kh_put(str2fs, me->m_mapFile2Struct, buffer, &ret); - kfp = kh_put(str2n, me->m_mapFile2PointPos, buffer, &ret); - //读Head1 - fread(&uValue, sizeof(UINT32), 1, me->m_fBinFile); - uValue = le32toh(uValue); - kh_value(me->m_mapFile2Struct, kfs).Head1 = uValue; - kh_value(me->m_mapFile2PointPos, kfp) = uValue; - //读Head2 - fread(&uValue, sizeof(UINT32), 1, me->m_fBinFile); - uValue = le32toh(uValue); - kh_value(me->m_mapFile2Struct, kfs).Head2 = uValue; - //读Mid1 - fread(&uValue, sizeof(UINT32), 1, me->m_fBinFile); - uValue = le32toh(uValue); - kh_value(me->m_mapFile2Struct, kfs).Mid1 = uValue; - //读Mid2 - fread(&uValue, sizeof(UINT32), 1, me->m_fBinFile); - uValue = le32toh(uValue); - kh_value(me->m_mapFile2Struct, kfs).Mid2 = uValue; - //读Tail1 - fread(&uValue, sizeof(UINT32), 1, me->m_fBinFile); - uValue = le32toh(uValue); - kh_value(me->m_mapFile2Struct, kfs).Tail1 = uValue; - //读Tail2 - fread(&uValue, sizeof(UINT32), 1, me->m_fBinFile); - uValue = le32toh(uValue); - kh_value(me->m_mapFile2Struct, kfs).Tail2 = uValue; - } -} -BOOL BinFileWtp_InitParameter2(struct CBinFileWtp *me, const TCHAR *pBinFilePath, struct StringList *pFbfList) -{ - TCHAR buffer[1024]; - int ret, nPosBuf; - khiter_t kfp, kfs; - if (me->m_bHaveInitForFbfDown) - return TRUE; - BinFileWtp_ResetPara(me); - me->m_bHaveInitForFbfDown = TRUE; - -#if !defined(LINUX) - memset(me->m_strBinFilePath, 0x00, sizeof(me->m_strBinFilePath)); - tsnprintf(me->m_strBinFilePath, sizeof(me->m_strBinFilePath), _T("%s"), pBinFilePath); -#else - memset(me->m_strBinFilePath, 0x00, sizeof(me->m_strBinFilePath)); - tsnprintf(me->m_strBinFilePath, sizeof(me->m_strBinFilePath), _T("%s"), pBinFilePath); -#endif - - UINT32 uValue = 0; - if (FALSE == BinFileWtp_OpenBinFile(me, _T("rb"))) - { - return FALSE; - } - fseek(me->m_fBinFile, -1L * sizeof(UINT32), SEEK_END); - //读FBF文件最后的偏移,之后的为map信息 - fread(&uValue, sizeof(UINT32), 1, me->m_fBinFile); - printf("Read from File Value is %x\n", uValue); - uValue = le32toh(uValue); - printf("Convert Value is %x\n", uValue); - fseek(me->m_fBinFile, uValue, SEEK_SET); - printf("Offset of Map is %u\n", uValue); - //读map size - fread(&uValue, sizeof(UINT32), 1, me->m_fBinFile); - uValue = le32toh(uValue); - printf("Size of Map is %u\n", uValue); - unsigned int i = uValue; - - while (i) - { - i--; - memset(buffer, 0, sizeof(buffer)); - //读路径文件长度 - fread(&uValue, sizeof(UINT32), 1, me->m_fBinFile); - uValue = le32toh(uValue); - //读路径文件 - fread(buffer, 1, uValue, me->m_fBinFile); -#ifndef UNICODE - nPosBuf = 0; - for (int j = 0; j < uValue; j++) - { - if (buffer[j] != 0) - { - buffer[nPosBuf] = buffer[j]; - ++nPosBuf; - } - buffer[nPosBuf] = 0; - } -#endif - const char *buf2 = strdup(buffer); - printf("Find image name:%s\n", buf2); - kfp = kh_put(str2n, me->m_mapFile2PointPos, buf2, &ret); - kfs = kh_put(str2fs, me->m_mapFile2Struct, buf2, &ret); - - //读Head1 - fread(&uValue, sizeof(UINT32), 1, me->m_fBinFile); - uValue = le32toh(uValue); - kh_value(me->m_mapFile2Struct, kfs).Head1 = uValue; - kh_value(me->m_mapFile2PointPos, kfp) = uValue; - - //读Head2 - fread(&uValue, sizeof(UINT32), 1, me->m_fBinFile); - uValue = le32toh(uValue); - kh_value(me->m_mapFile2Struct, kfs).Head2 = uValue; - //读Mid1 - fread(&uValue, sizeof(UINT32), 1, me->m_fBinFile); - uValue = le32toh(uValue); - kh_value(me->m_mapFile2Struct, kfs).Mid1 = uValue; - //读Mid2 - fread(&uValue, sizeof(UINT32), 1, me->m_fBinFile); - uValue = le32toh(uValue); - kh_value(me->m_mapFile2Struct, kfs).Mid2 = uValue; - //读Tail1 - fread(&uValue, sizeof(UINT32), 1, me->m_fBinFile); - uValue = le32toh(uValue); - kh_value(me->m_mapFile2Struct, kfs).Tail1 = uValue; - //读Tail2 - fread(&uValue, sizeof(UINT32), 1, me->m_fBinFile); - uValue = le32toh(uValue); - kh_value(me->m_mapFile2Struct, kfs).Tail2 = uValue; - pFbfList->strL[pFbfList->nSize++] = buf2; - } - return TRUE; -} - -BOOL BinFileWtp_IsFileExist(struct CBinFileWtp *me, const TCHAR *pFileName) -{ - khiter_t k; - k = kh_get(str2fs, me->m_mapFile2Struct, pFileName); - if (k == kh_end(me->m_mapFile2Struct)) - return FALSE; - else - return TRUE; -} - -void BinFileWtp_DelMe(struct CBinFileWtp *me) -{ - khiter_t k; - for (k = kh_begin(me->m_mapFile2PointPos); k != kh_end(me->m_mapFile2PointPos); ++k) - if (kh_exist(me->m_mapFile2PointPos, k)) - { - free((void *)kh_key(me->m_mapFile2PointPos, k)); - } -} diff --git a/fbfdownloader/src/BinFileWtp.h b/fbfdownloader/src/BinFileWtp.h deleted file mode 100644 index 3c556d827..000000000 --- a/fbfdownloader/src/BinFileWtp.h +++ /dev/null @@ -1,51 +0,0 @@ -#pragma once - -#include "Macrodef.h" -#include "ApplicationINI.h" -#include "ParaDefine.h" -#include -#include -#include "khash.h" -#include "klist.h" - -typedef struct _FileStruct -{ - UINT32 Head1, Head2; - UINT32 Mid1, Mid2; - UINT32 Tail1, Tail2; -} FileStruct; - -KHASH_MAP_INIT_STR(str2n,UINT32) -KHASH_MAP_INIT_STR(str2fs,FileStruct) -#define BINFILE _T("BinFile.bin") - - -typedef khash_t(str2n) *t_FilePathWriteOffsetMap; - -typedef khash_t(str2fs)* t_FileNameFileStructMap; - -BOOL BinFileWtp_OpenBinFile(struct CBinFileWtp *me,const TCHAR* strOpenMode); -UINT32 BinFileWtp_ReadBinFile(struct CBinFileWtp *me,void *buffer, size_t size, size_t count, const TCHAR* pszBinFile); -int BinFileWtp_FseekBin(struct CBinFileWtp *me,const TCHAR* pszBinFile,long _Offset,int _Origin); -BOOL BinFileWtp_IsFileExist(struct CBinFileWtp *me,const TCHAR *pFileName); -UINT32 BinFileWtp_GetFileSize(struct CBinFileWtp *me,const TCHAR* pszBinFile); -BOOL BinFileWtp_InitParameter2(struct CBinFileWtp *me,const TCHAR *pBinFilePath, struct StringList*); -void BinFileWtp_InitParameter(struct CBinFileWtp *me); -void BinFileWtp_CloseBinFIle(struct CBinFileWtp *me); -void BinFileWtp_FreshBinOffset(struct CBinFileWtp *me); -void BinFileWtp_ResetPara(struct CBinFileWtp *me); -void BinFileWtp_InitRead(struct CBinFileWtp *me); -void BinFileWtp_DelMe(struct CBinFileWtp *me); - - -struct CBinFileWtp -{ - FILE* m_fBinFile; - t_FileNameFileStructMap m_mapFile2Struct; - t_FilePathWriteOffsetMap m_mapFile2PointPos;//文件指针位置 相对起始 - UINT32 m_uFileOffset;//Bin文件总偏移 - TCHAR m_strBinFilePath[MAX_FILE_LENGTH]; - BOOL m_bHaveInitForFbfDown; -}; - -extern struct CBinFileWtp gBinFileWtp; diff --git a/fbfdownloader/src/BulkDevNonDrv_Linux.c b/fbfdownloader/src/BulkDevNonDrv_Linux.c deleted file mode 100644 index 3162e345b..000000000 --- a/fbfdownloader/src/BulkDevNonDrv_Linux.c +++ /dev/null @@ -1,710 +0,0 @@ -#include "BulkDevNonDrv_Linux.h" - -#define MAX_RETRIES 5 - - -int BulkDevNonDrv_check(void *_desc, int nLen, unsigned int type, int size) -{ - unsigned char *desc = (unsigned char *)_desc; - - if(nLen < size) return 0; - if(desc[0] < size) return 0; - if(desc[0] > nLen) return 0; - if(desc[1] != type) return 0; - - return 1; -} - -int BulkDevNonDrv_badname(const char *name) -{ - while(*name) - { - if(!isdigit(*name++)) - return 1; - } - - return 0; -} - -int BulkDevNonDrv_OpenDev(USB_HANDLE *usb) -{ - char DevDesc[1024]; - int bRet = 0; - int hDevHandle = 0; - int nLen = 0; - int PipeIn = -1; - int PipeOut = -1; - int ifc_id = -1; - -#ifdef __ANDROID__ - chmod(usb->DevName,0777); -#endif - -#if 0 - char szBuffer[MAX_FILE_LENGTH]; - memset(szBuffer,0,sizeof(Tchar)*MAX_FILE_LENGTH); - snprintf(szBuffer,sizeof(szBuffer),("su -c \"chmod -R 777 /dev/bus/usb/\"")); - int r = system(szBuffer); - - if(r!=0) { - printf("Could not grant permissions to USB\n"); - } -#endif - - if((hDevHandle = open(usb->DevName, O_RDWR)) >= 0) - { -#if PRINTLOG - printf("Open dev OK\n"); -#endif - system("echo ---open usb OK--- > /dev/kmsg"); - nLen = read(hDevHandle, DevDesc, sizeof(DevDesc)); - if( BulkDevNonDrv_GetPipeOfDev(DevDesc, nLen, &PipeIn, &PipeOut, &ifc_id) ) - { - //printf("GetPipeOfWTPTP OK!\n"); - nLen = ioctl(hDevHandle, USBDEVFS_CLAIMINTERFACE, &ifc_id); - if(nLen == 0) - { -#if PRINTLOG - printf("Check ifc_id OK!\n"); -#endif - system("echo ---claim usb OK--- > /dev/kmsg"); - bRet = 1; - usb->nPipeIn = PipeIn; - usb->nPipeOut = PipeOut; - usb->hDevHandle = hDevHandle; -#if PRINTLOG - printf("DevName is %s, PipeIn is %d, PipeOut is %d, hDevHandle is 0x%X\n", usb->DevName, usb->nPipeIn, usb->nPipeOut, usb->hDevHandle); -#endif - } - else - { - system("echo ---claim usb FAIL--- > /dev/kmsg"); -#if PRINTLOG - printf("Check ifc_id fail! nLen: %d, errno(%d): %s\n", nLen, errno, strerror(errno)); -#endif - close(hDevHandle); - } - } -#if PRINTLOG - else - printf("GetPipeOfWTPTP fail!\n"); -#endif - } - else - { - system("echo ---open usb FAIL--- > /dev/kmsg"); -#if PRINTLOG - printf("Open dev fail, hDevHandle=0x%X\n", hDevHandle); -#endif - } - - return bRet; -} - -int BulkDevNonDrv_CloseDev(USB_HANDLE *usb) -{ - int hDevHandle; - - hDevHandle = usb->hDevHandle; - if(hDevHandle >= 0) - { - close(hDevHandle); -#if PRINTLOG - printf("WTPTP dev: %s was closed!\n", usb->DevName); -#endif - - memset(usb->DevName, 0, 256); - usb->hDevHandle = -1; - usb->nPipeIn = -1; - usb->nPipeOut = -1; - - return 1; - } - return 0; - -} - -int BulkDevNonDrv_WaitDev() -{ - struct sockaddr_nl client; - struct timeval tv; - int CppLive, rcvlen, ret; - fd_set fds; - int buffersize = 2048; - - CppLive = socket(AF_NETLINK, SOCK_RAW, NETLINK_KOBJECT_UEVENT); - memset(&client, 0, sizeof(client)); - client.nl_family = AF_NETLINK; - client.nl_pid = getpid(); - client.nl_groups = 1; - - setsockopt(CppLive, SOL_SOCKET, SO_RCVBUF, &buffersize, sizeof(buffersize)); - bind(CppLive, (struct sockaddr*)&client, sizeof(client)); - - //while(1) - { - char buff[2048] = {0}; - FD_ZERO(&fds); - FD_SET(CppLive, &fds); - tv.tv_sec = 0; - tv.tv_usec = 100 * 1000; - - ret = select(CppLive+1, &fds, NULL, NULL, &tv); - //if(ret<0) - // continue; - - //if(!(ret>0 && FD_ISSET(CppLive, &fds))) - // continue; - - rcvlen = recv(CppLive, &buff, sizeof(buff), 0); - if(rcvlen>0) - { - for(int nIndex=0; nIndexd_name)) - continue; - - sprintf(busname, "%s/%s", base, de->d_name); - devdir = opendir(busname); - if( 0 == devdir ) - continue; - - while( de = readdir(devdir) ) - { - if(BulkDevNonDrv_badname(de->d_name)) - { - continue; - } - - int nBuffLen = sprintf(devname, "%s/%s", busname, de->d_name); - if( ( hDevHandle = open(devname, O_RDWR) ) >= 0 ) - { - //printf("Opened %s\n", devname); - DevDesc = OrigiPtr; - nBuffLen = read(hDevHandle, DevDesc, 1024); - if( !BulkDevNonDrv_check( DevDesc, nBuffLen, USB_DT_DEVICE, USB_DT_DEVICE_SIZE ) ) - continue; - - dev = (struct usb_device_descriptor *)DevDesc; - nBuffLen -= dev->bLength; - DevDesc += dev->bLength; - - if( BulkDevNonDrv_ChecHWIds2(dev->idVendor, dev->idProduct) ) - { - if( !BulkDevNonDrv_check( DevDesc, nBuffLen, USB_DT_CONFIG, USB_DT_CONFIG_SIZE ) ) - continue; - - info.serial_number[0] = 0; - if(dev->iSerialNumber) - { - struct usbdevfs_ctrltransfer ctrl; - __u16 buffer[128]; - __u16 preCheck[128]; - int nPreCheckCount = 0; - int result; - - memset(buffer, 0, sizeof(buffer)); - memset(preCheck, 0, sizeof(preCheck)); - memset(&ctrl, 0, sizeof(ctrl)); - - ctrl.bRequestType = USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_DEVICE; - ctrl.bRequest = USB_REQ_GET_DESCRIPTOR; - ctrl.wValue = (USB_DT_STRING << 8) | 0; //dev->iSerialNumber; - ctrl.wIndex = 0;//__le16_to_cpu(0x409); - ctrl.wLength = sizeof(preCheck); - ctrl.data = preCheck; - - result = ioctl(hDevHandle, USBDEVFS_CONTROL, &ctrl); - if(result>0) - { - int nLoop; - nPreCheckCount = (result - 2) / 2; - - for( nLoop = 1; nLoop <= nPreCheckCount; nLoop++ ) - { - memset(buffer, 0, sizeof(buffer)); - memset(&ctrl, 0, sizeof(ctrl)); - - ctrl.bRequestType = USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_DEVICE; - ctrl.bRequest = USB_REQ_GET_DESCRIPTOR; - ctrl.wValue = (USB_DT_STRING << 8) | dev->iSerialNumber; - ctrl.wIndex = __le16_to_cpu(preCheck[nLoop]); - ctrl.wLength = sizeof(buffer); - ctrl.data = buffer; - - result = ioctl(hDevHandle, USBDEVFS_CONTROL, &ctrl); - if(result>0) - { - int i = 0; - result /= 2; - for(i=1; ibLength; - DevDesc += cfg->bLength; - - for(int loop=0; loopbNumInterfaces; ) - { - if( !BulkDevNonDrv_check( DevDesc, nBuffLen, USB_DT_INTERFACE, USB_DT_INTERFACE_SIZE ) ) - { - nBuffLen -= DevDesc[0]; - DevDesc += DevDesc[0]; - continue; - } - - ifc = (struct usb_interface_descriptor *)DevDesc; - nBuffLen -= ifc->bLength; - DevDesc += ifc->bLength; - - if( BulkDevNonDrv_ChecHWIds(dev->idVendor, dev->idProduct, ifc->bInterfaceNumber) ) - { - USB_HANDLE usb; - strcpy(usb.DevName, devname); - if( 0 == strlen(info.serial_number) ) - { - strcpy(usb.iSerialNumber, "None"); - } - else - { - strcpy(usb.iSerialNumber, info.serial_number); - } - hUSBArray[nIndex] = (PUSB_HANDLE)malloc(sizeof(USB_HANDLE)); - NEW_USB_HANDLE(hUSBArray[nIndex]); - COPY_USB_HANDLE(hUSBArray[nIndex],&usb); - nIndex++; - bRet = nIndex; - //printf("Got one supported dev: VID: 0x%X, PID: 0x%X, MI:0x%X\n", dev->idVendor, dev->idProduct, ifc->bInterfaceNumber); - } - loop++; - } - } - close(hDevHandle); - } - - //if(IsSupported(devname, nBuffLen, DevName, nDevNameLen, bAdd)) - // printf("%s\n", devname); - } - closedir(devdir); - } - closedir(busdir); - free(OrigiPtr); - DevDesc = NULL; - OrigiPtr = NULL; - return bRet; -} - -int BulkDevNonDrv_CheckDevForNetLink(USB_HANDLE *usb, const char *NetLinkBuff, int nBuffLen, int *bAdd) -{ - char DevName[256] = {0}; - int nDevNameLen = 0; - int bRet = 0; - - bRet = BulkDevNonDrv_IsSupported(NetLinkBuff, nBuffLen, DevName, &nDevNameLen, bAdd); - if(bRet) - { - strcpy(usb->DevName, DevName); - } - return bRet; -} - -int BulkDevNonDrv_IsSupported(const char *NetLinkBuff, int nBuffLen, char *Dev_Name, int *nDevNameLen, int *bAdd) -{ - int nIndex = 0; - char* position = NULL; - long lVID = 0, lPID = 0; - int bFound = 0; - int bRet = 0; - char tmpNetLinkBuff[4096]; - char* sUSBDescription; - /*AsiaTelco MIPS use proc instead of dev, really strange*/ - //string sDevName = "/proc/"; - char sDevName[512] = "/dev/"; - char sVID[64] = "0x"; - char sPID[64] = "0x"; - - // Prepare the device information buffer - memcpy(tmpNetLinkBuff, NetLinkBuff, nBuffLen); - for(; nIndexbLength; - ptr += dev->bLength; - - if(!BulkDevNonDrv_check(ptr, len, USB_DT_CONFIG, USB_DT_CONFIG_SIZE)) - return 0; - - cfg = (struct usb_config_descriptor *) ptr; - len -= cfg->bLength; - ptr += cfg->bLength; - - //info.dev_vendor = dev->idVendor; - //info.dev_product = dev->idProduct; - //info.dev_class = dev->bDeviceClass; - //info.dev_subclass = dev->bDeviceSubClass; - //info.dev_protocol = dev->bDeviceProtocol; - //info.writable = writable; - - // read device serial number (if there is one) - /*info.serial_number[0] = 0; - if (dev->iSerialNumber) - { - - struct usbdevfs_ctrltransfer ctrl; - __u16 buffer[128]; - int result; - - memset(buffer, 0, sizeof(buffer)); - - ctrl.bRequestType = USB_DIR_IN|USB_TYPE_STANDARD|USB_RECIP_DEVICE; - ctrl.bRequest = USB_REQ_GET_DESCRIPTOR; - ctrl.wValue = (USB_DT_STRING << 8) | dev->iSerialNumber; - ctrl.wIndex = 0; - ctrl.wLength = sizeof(buffer); - ctrl.data = buffer; - - result = ioctl(fd, USBDEVFS_CONTROL, &ctrl); - if (result > 0) - { - int i; - // skip first word, and copy the rest to the serial string, changing shorts to bytes. - result /= 2; - for (i = 1; i < result; i++) - info.serial_number[i - 1] = buffer[i]; - info.serial_number[i - 1] = 0; - } - else - { - printf("errno(%d): %s\n", errno, strerror(errno)); - } - }*/ - - for(i = 0; i < cfg->bNumInterfaces;) - { - if( !BulkDevNonDrv_check( ptr, len, USB_DT_INTERFACE, USB_DT_INTERFACE_SIZE ) ) - { - len -= *ptr; - ptr += *ptr; - continue; - } - - i++; - ifc = (struct usb_interface_descriptor *) ptr; - len -= ifc->bLength; - ptr += ifc->bLength; - - if( !BulkDevNonDrv_ChecHWIds(dev->idVendor, dev->idProduct, ifc->bInterfaceNumber) ) - continue; - - in = -1; - out = -1; - //info.ifc_class = ifc->bInterfaceClass; - //info.ifc_subclass = ifc->bInterfaceSubClass; - //info.ifc_protocol = ifc->bInterfaceProtocol; - - for(e = 0; e < ifc->bNumEndpoints; e++) - { - if(!BulkDevNonDrv_check(ptr, len, USB_DT_ENDPOINT, USB_DT_ENDPOINT_SIZE)) - return 0; - - ept = (struct usb_endpoint_descriptor *) ptr; - len -= ept->bLength; - ptr += ept->bLength; - - if((ept->bmAttributes & 0x03) != 0x02) - continue; - - if(ept->bEndpointAddress & 0x80) - { - in = ept->bEndpointAddress; - } - else - { - out = ept->bEndpointAddress; - } - } - - //info.has_bulk_in = (in != -1); - //info.has_bulk_out = (out != -1); - *ept_in_id = in; - *ept_out_id = out; - *ifc_id = ifc->bInterfaceNumber; - //printf("ept_in_id: %d, ept_out_id: %d, ifc_id: %d\n", *ept_in_id, *ept_out_id, *ifc_id); - - return 1; - } - return 0; -} -int BulkDevNonDrv_Write(USB_HANDLE *h, const void *_data, int len) -{ - unsigned char *data = (unsigned char*) _data; - unsigned count = 0; - struct usbdevfs_bulktransfer bulk; - int n; - - if(h->nPipeOut == 0) - { - return -1; - } - - if(len == 0) - { - bulk.ep = h->nPipeOut; - bulk.len = 0; - bulk.data = data; - bulk.timeout = 0; - - n = ioctl(h->hDevHandle, USBDEVFS_BULK, &bulk); - if(n != 0) - { -#if DEBUG_MODE - printf("1ERROR: n = %d, errno = %d (%s)\n", - n, errno, strerror(errno)); -#endif - - return -1; - } - return n; - } - - while(len > 0) - { - int xfer; - xfer = len; - bulk.ep = h->nPipeOut; - bulk.len = xfer; - bulk.data = data; - bulk.timeout = 5000; - n = ioctl(h->hDevHandle, USBDEVFS_BULK, &bulk); - if(n != xfer) - { -#if DEBUG_MODE - printf("2ERROR: n = %d, errno = %d (%s)\n", - n, errno, strerror(errno)); -#endif - return -1; - } - - count += xfer; - len -= xfer; - data += xfer; - } - return count; -} - -int BulkDevNonDrv_Read(USB_HANDLE *h, void *_data, int len, int timeout) -{ - unsigned char *data = (unsigned char*) _data; - unsigned count = 0; - struct usbdevfs_bulktransfer bulk; - int n, retry; - - if(h->nPipeIn == 0) - { - return -1; - } - - while(len > 0) - { - int xfer = len; - //int xfer = (len > 4096) ? 4096 : len; - bulk.ep = h->nPipeIn; - bulk.len = xfer; - bulk.data = data; - bulk.timeout = timeout; - retry = 0; - - do - { - n = ioctl(h->hDevHandle, USBDEVFS_BULK, &bulk); - if( n < 0 ) - { - - if ( ++retry > MAX_RETRIES ) - { -#if DEBUG_MODE - printf("ERROR: n = %d, errno = %d (%s)\n",n, errno, strerror(errno)); -#endif - - return -1; - } - usleep(10000); - } - } - while( n < 0 ); - - count += n; - len -= n; - data += n; - - if(n < xfer) - { - break; - } - } - - return count; -} diff --git a/fbfdownloader/src/BulkDevNonDrv_Linux.h b/fbfdownloader/src/BulkDevNonDrv_Linux.h deleted file mode 100644 index bd563655f..000000000 --- a/fbfdownloader/src/BulkDevNonDrv_Linux.h +++ /dev/null @@ -1,156 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 20) -#include -#else -#include -#endif -#include - -#ifdef __ANDROID__ -#include -#endif - -#define MAX_DEVNUM 5 -#define MAX_FILE_LENGTH 1024 - -static int HWIds_WTPTPTable[37][3] = -{ - {0x8086, 0xE001, -1}, - {0x8086, 0xC001, -1}, - {0x8086, 0xD001, -1}, - {0x1286, 0x8100, -1}, - {0x1286, 0x8101, -1}, - {0x1286, 0x8102, -1}, - {0x1286, 0x8103, -1}, - {0x1286, 0x8104, -1}, - {0x1286, 0x8105, -1}, - {0x1286, 0x8106, -1}, - {0x1286, 0x8111, -1}, - {0x1286, 0x8112, -1}, - {0x1286, 0x8113, -1}, - {0x1286, 0x8114, -1}, - {0x1286, 0x8115, -1}, - {0x1286, 0x8116, -1}, - {0x1286, 0x8117, -1}, - {0x1286, 0x8118, -1}, - {0x1286, 0x8128, -1}, - {0x1286, 0x8129, -1}, - {0x1286, 0x812a, -1}, - {0x1286, 0x8130, -1}, - {0x1286, 0x8164, -1}, - {0x1286, 0x8170, -1}, - {0x1286, 0x8165, -1}, - {0x1286, 0x8174, -1}, - {0x1286, 0x8175, -1}, - {0x1286, 0x8181, -1}, - {0x1286, 0x8182, -1}, - {0x1286, 0x8189, -1}, - {0x1286, 0x8167, -1}, - {0x2ECC, 0x3001, -1}, - {0x2ECC, 0x3002, -1}, - {0x2ECC, 0x3003, -1}, - {0x19D2, 0x1491, -1}, - {0x305A, 0x1413, -1}, - - {0x0, 0x0, 0x0} -}; - -static int HWIds_USBDiagTable[11][3] = -{ - {0x1286, 0x4E3C, 0}, - {0x1286, 0x4E38, 4}, - {0x1286, 0x4E2C, 0}, - {0x1286, 0x4E28, 4}, - {0x1286, 0x4E30, 0}, - {0x1286, 0x4E31, 2}, - {0x0BB4, 0x4E49, 0}, - {0x0BB4, 0x4E4A, 4}, - {0x0BB4, 0x4E4D, 3}, - {0x0BB4, 0x4E4E, 0}, - {0x0, 0x0, 0x0} -}; - - -static int (*HWIds_CurrentTable)[3] = HWIds_WTPTPTable; - -typedef struct _USB_HANDLE -{ - char DevName[256]; - char iSerialNumber[256]; - int hDevHandle; - int nPipeIn; - int nPipeOut; - - -} USB_HANDLE, *PUSB_HANDLE; -static void NEW_USB_HANDLE(PUSB_HANDLE me) -{ - memset(me->DevName, 0, sizeof(me->DevName)); - memset(me->iSerialNumber, 0, sizeof(me->iSerialNumber)); - me->hDevHandle = -1; - me->nPipeIn = -1; - me->nPipeOut = -1; -} - -static void COPY_USB_HANDLE(PUSB_HANDLE me, PUSB_HANDLE pusb) -{ - strcpy(me->DevName, pusb->DevName); - strcpy(me->iSerialNumber, pusb->iSerialNumber); - me->hDevHandle = pusb->hDevHandle; - me->nPipeIn = pusb->nPipeIn; - me->nPipeOut = pusb->nPipeOut; -} - - -typedef struct _USB_IFC_INFO -{ - unsigned short dev_vendor; - unsigned short dev_product; - - unsigned char dev_class; - unsigned char dev_subclass; - unsigned char dev_protocol; - - unsigned char ifc_class; - unsigned char ifc_subclass; - unsigned char ifc_protocol; - - unsigned char has_bulk_in; - unsigned char has_bulk_out; - - unsigned char writable; - - char serial_number[256]; -} USB_IFC_INFO, *PUSB_IFC_INFO; - -int BulkDevNonDrv_OpenDev(USB_HANDLE *usb); -int BulkDevNonDrv_CloseDev(USB_HANDLE *usb); -int BulkDevNonDrv_Write(USB_HANDLE *h, const void *_data, int nLen); -int BulkDevNonDrv_Read(USB_HANDLE *h, void *_data, int nLen, int timeout); -int BulkDevNonDrv_CheckDevForNetLink(USB_HANDLE *usb, const char *NetLinkBuff, int nBuffLen, int *bAdd); -int BulkDevNonDrv_WaitDev(); -int BulkDevNonDrv_FindAllSupportedDevices(PUSB_HANDLE hUSBArray[]); -int BulkDevNonDrv_check(void *_desc, int nLen, unsigned int type, int size); -int BulkDevNonDrv_badname(const char *name); -int BulkDevNonDrv_ChecHWIds(long idVendor, long idProduct, long MI); -int BulkDevNonDrv_IsSupported(const char *NetLinkBuff, int nBuffLen, char *Dev_Name, int *nDevNameLen, int *bAdd); -int BulkDevNonDrv_GetPipeOfDev(/*int fd, */char *ptr, int nLen, int *ept_in_id, int *ept_out_id, int *ifc_id); -#define BulkDevNonDrv_ChecHWIds2(a,b) BulkDevNonDrv_ChecHWIds(a,b,-1) \ No newline at end of file diff --git a/fbfdownloader/src/CommonFun.c b/fbfdownloader/src/CommonFun.c deleted file mode 100644 index 020860d1d..000000000 --- a/fbfdownloader/src/CommonFun.c +++ /dev/null @@ -1,190 +0,0 @@ -#include "kstring.h" -#include "CommonFun.h" -#include -#ifdef _WINDOWS -#include -#endif -#define MAX_FILE_LENGTH 1024 -#pragma warning ( disable : 4996) -#ifdef MACDOWNLOAD -#include -#endif - -kstring_t GetAppPath() -{ - kstring_t strRet = { 0, 0, NULL }; - TCHAR exeFullPath[MAX_FILE_LENGTH] = {0}; - TCHAR exeAbsFullPath[MAX_FILE_LENGTH] = {0}; -#ifdef LINUX -#ifdef MACDOWNLOAD - UINT32 size = MAX_FILE_LENGTH; - _NSGetExecutablePath(exeFullPath, &size); - //exeFullPath[size] = '\0'; - realpath(exeFullPath,exeAbsFullPath); - TCHAR *p = _tcsrchr(exeAbsFullPath,'/'); - if(p) *p = 0; -#if PRINTLOG - tprintf(_T("GetAppPath: %s.....\n\n"),exeAbsFullPath); -#endif - kputs(exeAbsFullPath,&strRet); - return strRet; -#else - - readlink ("/proc/self/exe", exeFullPath, MAX_FILE_LENGTH); - TCHAR *p = _tcsrchr(exeFullPath,'/'); - if(p) *p = 0; - kputs(exeFullPath,&strRet); - return strRet; -#endif - -#else - kstring_t strAppPath = {0,0,NULL}; - TCHAR szFullExeName[MAX_FILE_LENGTH]; - DWORD nResult = ::GetModuleFileName(NULL, szFullExeName, MAX_FILE_LENGTH); - kstring_t strFullFileName= {0,0,NULL}; - kputs(szFullExeName,&strFullFileName); - char* cPos = strrchr(szFullExeName,'\\'); - *cPos = 0; - kputs(szFullExeName,&strAppPath); - return strAppPath; -#endif - -} - - - - -void DelFile(const TCHAR* pszFile) -{ - if (ACCESS_FILE_EXIST != taccess(pszFile,ACCESS_FILE_EXIST)) - { - return; - } -#ifdef LINUX - chmod(pszFile,0777); - TCHAR szBuffer[MAX_FILE_LENGTH]; - memset(szBuffer,0,sizeof(TCHAR)*MAX_FILE_LENGTH); - tsnprintf(szBuffer,sizeof(szBuffer),_T("rm -f %s"),pszFile); - system(szBuffer); -#else - SetFileAttributes(pszFile,FILE_ATTRIBUTE_NORMAL); - DeleteFile(pszFile); -#endif -} - - - -BOOL IsFileExist(const TCHAR *pFileName) -{ - if(taccess(pFileName,0)!=0) - { - return FALSE; - } - return TRUE; -} - - - -unsigned int Str2Uint32 (const TCHAR* pValue) -{ - unsigned int iRetVal = 0; - if (pValue[0]== _T('0') && (pValue[1]== _T('x') || pValue[1]== _T('X'))) - tsscanf( pValue, _T("%x"), &iRetVal ); - else - tsscanf( pValue, _T("%i"), &iRetVal ); - return iRetVal; -} - - -UINT64 TranslateEx (kstring_t sValue) -{ - int *fields,n; - if(strstr(sValue.s,_T("0xffffffffff"))!=NULL|| - strstr(sValue.s,_T("0xFFFFFFFFFF"))!=NULL) - { - UINT64 iRetVal = 0xFFFFFFFFFFll; - return iRetVal; - } - if(strstr(sValue.s,_T("0xffffffff"))!=NULL|| - strstr(sValue.s,_T("0xFFFFFFFF"))!=NULL) - { - return 0xFFFFFFFF; - } - - - UINT64 iRetVal = 0; - // remove leading whitespace - // remove any trailing whitespace - fields = ksplit(&sValue, 0, &n); - kstrcpy(&sValue,sValue.s+fields[0]); - free(fields); - - if(strstr(sValue.s,_T("0x"))!=NULL || strstr(sValue.s,_T("0X"))!=NULL) - { - tsscanf( sValue.s, _T("%llx"), &iRetVal ); - } - else - { - tsscanf( sValue.s, _T("%lli"), &iRetVal ); - } - - return iRetVal; -} - - -void EndianConvertMasterBlockHeader(MasterBlockHeader *mbHeader) -{ - int i; - for (i = 0; i < NUM_OF_SUPPORTED_FLASH_DEVS; i++){ - mbHeader->Flash_Device_Spare_Area_Size[i] = le16toh(mbHeader->Flash_Device_Spare_Area_Size[i]); - } - mbHeader->Format_Version = le16toh(mbHeader->Format_Version); - mbHeader->Size_of_Block = le16toh(mbHeader->Size_of_Block); - mbHeader->Bytes_To_Program = le32toh(mbHeader->Bytes_To_Program); - mbHeader->Bytes_To_Verify = le32toh(mbHeader->Bytes_To_Verify); - mbHeader->Number_of_Bytes_To_Erase = le32toh(mbHeader->Number_of_Bytes_To_Erase); - mbHeader->Main_Commands = le32toh(mbHeader->Main_Commands); - mbHeader->nOfDevices = le32toh(mbHeader->nOfDevices); - mbHeader->DLerVersion = le32toh(mbHeader->DLerVersion); - for (i = 0; i < MAX_NUMBER_OF_FLASH_DEVICES_IN_MASTER_HEADER; i++){ - mbHeader->deviceHeaderOffset[i] = le32toh(mbHeader->deviceHeaderOffset[i]); - } -} - -void EndianConvertDeviceHeader_V11(DeviceHeader_V11 *pDeviceHeader) -{ - int i; - pDeviceHeader->DeviceFlags = le32toh(pDeviceHeader->DeviceFlags); - for (i = 0; i < 16; i++){ - pDeviceHeader->DeviceParameters[i] = le32toh(pDeviceHeader->DeviceParameters[i]); - } - pDeviceHeader->FlashOpt.EraseAll = le32toh(pDeviceHeader->FlashOpt.EraseAll); - pDeviceHeader->FlashOpt.ResetBBT = le32toh(pDeviceHeader->FlashOpt.ResetBBT); - pDeviceHeader->FlashOpt.NandID = le32toh(pDeviceHeader->FlashOpt.NandID); - for (i = 0; i < MAX_RESEVERD_LEN-1; i++){ - pDeviceHeader->FlashOpt.Reserved[i] = le32toh(pDeviceHeader->FlashOpt.Reserved[i]); - } - pDeviceHeader->FlashOpt.Skip_Blocks_Struct.Total_Number_Of_SkipBlocks = le32toh(pDeviceHeader->FlashOpt.Skip_Blocks_Struct.Total_Number_Of_SkipBlocks); - for (i = 0; i < MAX_NUM_SKIP_BLOCKS; i++){ - pDeviceHeader->FlashOpt.Skip_Blocks_Struct.Skip_Blocks[i] = le32toh(pDeviceHeader->FlashOpt.Skip_Blocks_Struct.Skip_Blocks[i]); - } - pDeviceHeader->ProductionMode = le32toh(pDeviceHeader->ProductionMode); - for (i = 0; i < MAX_RESEVERD_LEN-2; i++){ - pDeviceHeader->Reserved[i] = le32toh(pDeviceHeader->Reserved[i]); - } - pDeviceHeader->nOfImages = le32toh(pDeviceHeader->nOfImages); - for (i = 0; i < MAX_NUMBER_OF_IMAGE_STRUCTS_IN_DEVICE_HEADER; i++){ - pDeviceHeader->imageStruct[i].Image_ID = le32toh(pDeviceHeader->imageStruct[i].Image_ID); - pDeviceHeader->imageStruct[i].Image_In_TIM = le32toh(pDeviceHeader->imageStruct[i].Image_In_TIM); - pDeviceHeader->imageStruct[i].Flash_partition = le32toh(pDeviceHeader->imageStruct[i].Flash_partition); - pDeviceHeader->imageStruct[i].Flash_erase_size = le32toh(pDeviceHeader->imageStruct[i].Flash_erase_size); - pDeviceHeader->imageStruct[i].commands = le32toh(pDeviceHeader->imageStruct[i].commands); - pDeviceHeader->imageStruct[i].First_Sector = le32toh(pDeviceHeader->imageStruct[i].First_Sector); - pDeviceHeader->imageStruct[i].length = le32toh(pDeviceHeader->imageStruct[i].length); - pDeviceHeader->imageStruct[i].Flash_Start_Address = le32toh(pDeviceHeader->imageStruct[i].Flash_Start_Address); - for (int j = 0; j < MAX_RESEVERD_LEN; j++){ - pDeviceHeader->imageStruct[i].Reserved[j] = le32toh(pDeviceHeader->imageStruct[i].Reserved[j]); - } - pDeviceHeader->imageStruct[i].ChecksumFormatVersion2 = le32toh(pDeviceHeader->imageStruct[i].ChecksumFormatVersion2); - } -} diff --git a/fbfdownloader/src/CommonFun.h b/fbfdownloader/src/CommonFun.h deleted file mode 100644 index ab4561977..000000000 --- a/fbfdownloader/src/CommonFun.h +++ /dev/null @@ -1,41 +0,0 @@ -#pragma once - -#include "Typedef.h" -#include -#if !defined(LINUX) -#include "StdAfx.h" -#include -#include -#include -#include -#include "Shlwapi.h" -#else -#include -#include -#include -#endif -#include "downloader.h" -#define _countof(array) (sizeof(array) / sizeof(array[0])) - -kstring_t GetAppPath(); -void DelFile(const TCHAR* pszFile); - -unsigned int Str2Uint32 (const TCHAR* pValue); -UINT64 TranslateEx (kstring_t sValue); -BOOL IsFileExist(const TCHAR *pFileName); - -//inline function -inline int CloseFilePtr(FILE** fpFile) -{ - int ret = 0; - if (NULL != *fpFile) - { - ret = fclose(*fpFile); - *fpFile = NULL; - } - return ret; -} - -void EndianConvertMasterBlockHeader(MasterBlockHeader *mbHeader); - -void EndianConvertDeviceHeader_V11(DeviceHeader_V11 *pDeviceHeader); \ No newline at end of file diff --git a/fbfdownloader/src/ConvetEdian.c b/fbfdownloader/src/ConvetEdian.c deleted file mode 100644 index a23422130..000000000 --- a/fbfdownloader/src/ConvetEdian.c +++ /dev/null @@ -1,60 +0,0 @@ - -#include "ConvetEdian.h" - - - - -UINT32 Endian32ConvertLToB(struct CConvertLT2B *me,UINT32 InputNum) -{ - if(!me->m_bIsLittleEndian) ////big endian ,please convert - { - UINT32 ConvertNum =((((UINT32)(InputNum) & 0xff000000) >> 24) - + (((UINT32)(InputNum) & 0x00ff0000) >> 8) - + (((UINT32)(InputNum) & 0x0000ff00) << 8) - + (((UINT32)(InputNum) & 0x000000ff) << 24)); - return ConvertNum; - - } - else - { - return InputNum; - } - -} - - -UINT16 Endian16ConvertLToB(struct CConvertLT2B *me,UINT16 InputNum) -{ - if(!me->m_bIsLittleEndian) //big endian ,please convert - { - return ((((UINT16)(InputNum) & 0xff00) >> 8) |(((UINT16)(InputNum) & 0x00ff) << 8)); - } - else - { - return InputNum; - } - -} - -void IsLittleEndian(struct CConvertLT2B *me) -{ - int a=1; - char *b; - b = (char *)&a; - if((*b)==1) - { - me->m_bIsLittleEndian = TRUE; - //tprintf (_T("Little Endian\n")); - } - else - { - me->m_bIsLittleEndian = FALSE; - //tprintf (_T("Big Endian\n")); - } -} -void NewCConvertLT2B (struct CConvertLT2B *me) -{ - me->m_bIsLittleEndian = TRUE; - IsLittleEndian(me); -} - diff --git a/fbfdownloader/src/ConvetEdian.h b/fbfdownloader/src/ConvetEdian.h deleted file mode 100644 index b5dc6a9f8..000000000 --- a/fbfdownloader/src/ConvetEdian.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include "Typedef.h" -#include -#include -struct CConvertLT2B -{ - BOOL m_bIsLittleEndian; -}; - -UINT32 Endian32ConvertLToB(struct CConvertLT2B *me,UINT32 InputNum); -UINT16 Endian16ConvertLToB(struct CConvertLT2B *me,UINT16 InputNum); -void IsLittleEndian(struct CConvertLT2B *me); -void NewCConvertLT2B (struct CConvertLT2B *me); - - diff --git a/fbfdownloader/src/EnumVal.h b/fbfdownloader/src/EnumVal.h deleted file mode 100644 index fbe9b4c23..000000000 --- a/fbfdownloader/src/EnumVal.h +++ /dev/null @@ -1,145 +0,0 @@ -#pragma once -enum eProcessorType { PXA_NONE = -1, - PXA168 = 0, - PXA30x, PXA31x, PXA32x, - PXA688, - PXA91x, PXA92x, PXA93x, PXA94x, PXA95x, - ARMADA168, - PXA2128, - MG1, - TAVOR_PV_MG2, - ESHEL, - PXA988, - PXA1088, - PXA1202, - PXA1802, - PXA1928, - PXA1920, - PXA1822, - ARMADA620, - ESHEL_LTE, - ARMADA622, - WUKONG, - PXA1826, - PXA1908, - PXA1936, - PXA1956, - PXA1918, - PXAMAX_PT -}; - - - - -typedef enum -{ - BLF_V_3_0_0 = 0, - BLF_V_2_0_0 = 1, - UNKNOWN_VERSION = 0xFF - -}eBLFVersion; - -typedef enum -{ - FLASH = 0, - DDR, - UNKNOWN_TYPE -}EUploadType; -typedef enum _eFlashType -{ - FLASH_NAND = 0, - FLASH_EMMC = 1, - FLASH_SPINOR = 2, - FLASH_ONENAND = 3, - FLASH_SPINAND = 4, - FLASH_UNKNOWN = 10 -} -eFlashType; - -enum eEraseAllMode -{ - ERASE_ALL_NOTSET = 0, - ERASE_ALL_BEFOREBURNING = 1, - ERASE_ALL_WIHTOUTBURNING = 2, - UNKNOWN_MODE = 0xFF - -}; - -typedef enum _eUserBootMode -{ - UE_NORESET = 0, - UE_RESET = 1, - UNKNOWN_BOOT_MODE = 0xFF - -} -eUserBootMode; -typedef enum -{ - PLAT_PXA92x_Old=0, - PLAT_PXA92x , - PLAT_MMP2 , - PLAT_WUKONG, - PLAT_NEVO,// - PLAT_MMP3, - PLAT_NEZHA, - PLAT_NEVO_OTA, - PLAT_EMEI, - PLAT_HELAN, - PLAT_EDEN, //PLAT_EDEN_Zx - PLAT_HELANLTE, - PLAT_NEZHA2, - PLAT_HELAN2, - PLAT_EDEN_A0, - PLAT_NEZHA3, - PLAT_ULC1, - PLAT_HELAN3, - PLAT_HELAN4, - PLAT_ULC2, - PLAT_UNKNOWN = 0xff -} ePlatForm; - -//subtype enum for upload -enum EUploadSubType -{ - DEFAULT_FLASH_PROBE = 0, - HSI1, - X16_ONENAND, - XIP_FLASH_X16, - X16_NAND_HAMMING, - X16_XIP_SIBLEY, - NAND_X8_HAMMING, - SDMMC_FLASH_OPT0, - SDMMC_FLASH_OPT1, - SDMMC_FLASH_OPT2, - SPI_FALSH, - SDMMC_FLASH_OPT3, - SDMMC_FLASH_OPT4, - X16_NAND_BCH, - X8_NAND_BCH, - CS1_XIP_FLASH, // XIP (CS1) - for SV only - NAND_FLASH_X16_BCH_OPT1, // x16 NAND BCH (16 bit correction per 1K) - NAND_FLASH_X8_BCH_OPT1, // x8 NAND BCH (16 bit correction per 1K) - NAND_FLASH_X16_NO_ECC,// x16 NAND No ECC (ECC is done by flash device) - NAND_FLASH_X8_NO_ECC, // x8 NAND No ECC (ECC is done by flash device) - SDIO_BUS, - BOOTSPI_FLASH, - SPI_NAND_FLASH = 26, - UNKOWN_SUBTYPE = 0xff -}; - -enum eProductMode{ - DO_NOTHING_FUSE, - ONLY_BURN_FUSE, - ONLY_READ_FUSE, - BURN_READ_FUSE, - DONTBURN_ONLY_BURN_FUSE, - DONTBURN_ONLY_READ_FUSE, - DONTBURN_BURN_READ_FUSE, -}; - -enum eDDREMMCTypeMode{ - NoneType, - DDRType, - EMMCType, - DDRandEMMCType, -}; diff --git a/fbfdownloader/src/ErrorCode.h b/fbfdownloader/src/ErrorCode.h deleted file mode 100644 index 74df362ab..000000000 --- a/fbfdownloader/src/ErrorCode.h +++ /dev/null @@ -1,369 +0,0 @@ -/************************************************************************** -** -** (C) Copyright December 2006 Marvell International Ltd. -** -** All Rights Reserved. -** -** -** THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE -** IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR -** PURPOSE ARE EXPRESSLY DISCLAIMED. -** -** FILENAME: ErrorCodes.h -** -** PURPOSE: Contains DKB error definitions -** -******************************************************************************/ - -#pragma once - -#ifndef ERROR_CODE_H -#define ERROR_CODE_H -#include "Macrodef.h" -#define MAXERRORCODES 1024 -#define MAXNOTIFICATIONSCODES 256 - -typedef enum EDDREMMCMatchResult -{ - kMatchNoError, - kDDRMismatchError, - kEMMCMismatchError, - kImagePreparationError, -} eDDREMMCMatchResult; - -#ifndef COMPRESSDATA -typedef struct -{ - unsigned int ErrorCode; - TCHAR Description[100]; -} ERRORCODETABLE; - -typedef struct -{ - unsigned int NotificationCode; - TCHAR Description[100]; -} NOTIFICATIONTABLE; -#else - typedef struct - { - unsigned int ErrorCode; - } ERRORCODETABLE; - - typedef struct - { - unsigned int NotificationCode; - } NOTIFICATIONTABLE; - -#endif - /* General error code definitions 0x0 - 0x1F - **/ - -#define PlatformBusy 0x1 -#define PlatformReady 0x2 -#define PlatformResetBBT 0x3 -#define PlatformEraseAllFlash 0x4 - - -#define PlatformDisconnect 0x5 -#define PlatformEraseAllFlashDone 0x6 -#define PlatformEraseAllFlashWithoutBurn 0x7 -#define PlatformEraseAllFlashWithoutBurnDone 0x8 -#define PlatformFuseOperationStart 0x9 -#define PlatformFuseOperationDone 0xA -#define PlatformUEInfoStart 0xB -#define PlatformUEInfoDone 0xc - - -#define PXA92x_PlatformBusy 0x7 -#define PXA92x_PlatformReady 0x8 - -#define PXA92x_PlatformDisconnect 0xC -#define ERRORFLAG 0x64 - - -#define NoError 0x0 -#define NotFoundError 0x1 -#define GeneralError 0x2 -#define WriteError 0x3 -#define ReadError 0x4 -#define NotSupportedError 0x5 -#define InvalidPlatformConfigError 0x6 -#define InvalidPlatformState 0x7 -#define InvalidSizeError 0x9 -#define ProbeListExhaustError 0xA -#define DDR_NotInitializedError 0xB -#define UnknownReservedPackage 0xD -#define NULLPointer 0xE -#define NANDIDDISMATCH 0xF -#define FBF_VersionNotMatch 0x10 -#define FBF_DeviceMoreThanOne 0x11 -#define PlatformConfigBuckError 0x12 -#define ChipIdMismatch 0x13 - - - -// Flash Related Errors 0x20 - 0x3F -#define EraseError 0x20 -#define ProgramError 0x21 -#define InvalidBootTypeError 0x22 -#define ProtectionRegProgramError 0x23 -#define NoOTPFound 0x24 -#define BBTReadError 0x25 -#define MDOCInitFailed 0x26 -#define OneNandInitFailed 0x27 -#define MDOCFormatFailed 0x28 -#define BBTExhaustedError 0x29 -#define NANDNotFound 0x2A -#define SDMMCNotFound 0x2B -#define FlexOneNANDNotFound 0x2C -#define SDMMCReadError 0x2D -#define XIPReadError 0x2E -#define FlexOneNANDError 0x2F -#define FlashDriverInitError 0x30 -#define FlashFuncNotDefined 0x31 -#define OTPError 0x32 -#define InvalidAddressRangeError 0x33 -#define FlashLockError 0x34 -#define ReadDisturbError 0x35 -#define FlashReadError 0x36 -#define SPIFlashNotResponding 0x37 -#define ImageOverlayError 0x38 -#define FlashAddrNotChunkAlign 0x39 -#define FlashAddrNotWordAlign 0x3A -#define BBTOUTOFRANGE 0x3B -#define FlashWriteVerifyError 0x3C -#define FlashAddrOutOfRange 0x3d - -// DFC Related Errors 0x40 - 0x4F -#define DFCDoubleBitError 0x40 -#define DFCSingleBitError 0x41 -#define DFCCS0BadBlockDetected 0x42 -#define DFCCS1BadBlockDetected 0x43 -#define DFCInitFailed 0x44 -#define DFCONFIConfigError 0x45 -#define DFC_WRREQ_TO 0x46 -#define DFC_WRCMD_TO 0x47 -#define DFC_RDDREQ_TO 0x48 -#define DFC_RDY_TO 0x49 -#define DFCCS0CommandDoneError 0x4A -#define DFCCS1CommandDoneError 0x4B -#define DFC_PGDN_TO 0x4C -// SPI Related Errors -#define SPINORPROGRAMFAIL 0x50 -#define SPINORERASEFAIL 0x51 - -// Security Related Errors 0x60 - 0x8F -#define InvalidOEMVerifyKeyError 0x60 -#define InvalidOBMImageError 0x61 -#define SecureBootFailureError 0x62 -#define InvalidSecureBootMethodError 0x63 -#define UnsupportedFlashError 0x64 -#define InvalidCaddoFIFOEntryError 0x65 -#define InvalidCaddoKeyNumberError 0x66 -#define InvalidCaddoKeyTypeError 0x67 -#define RSADigitalSignatureDecryptError 0x68 -#define InvalidHashValueLengthError 0x69 -#define InvalidTIMImageError 0x6A -#define HashSizeMismatch 0x6B -#define InvalidKeyHashError 0x6C -#define TIMNotFound 0x6D -#define WTMStateError 0x6E -#define FuseRWError 0x6F -#define InvalidOTPHashError 0x70 -#define CRCFailedError 0x71 -#define SaveStateNotFound 0x72 -#define WTMInitializationError 0x73 -#define ImageNotFound 0x74 -#define InvalidImageHash 0x75 -#define MicroCodePatchingError 0x76 -#define SetJtagKeyError 0x77 -#define WTMDisabled 0x78 -#define PlatformVerifyFailure 0x79 -#define ImageLoadError 0x7A -#define IPPCPHASHERROR 0x7B - -// Download Protocols 0x90 - 0x9F -#define DownloadPortError 0x90 -#define DownloadError 0x91 -#define FlashNotErasedError 0x92 -#define InvalidKeyLengthError 0x93 -#define DownloadImageTooBigError 0x94 -#define UsbPreambleError 0x95 -#define TimeOutError 0x96 -#define UartReadWriteTimeOutError 0x97 -#define UnknownImageError 0x98 -#define MessageBufferFullError 0x99 -#define NoEnumerationResponseTimeOutError 0x9A -#define UnknownProtocolCmd 0x9B -#define UsbRxError 0x9C -#define ForceDownloadPseudoError 0x9D -#define UsbTxError 0x9E - -//JTAG ReEnable Error Codes 0xB0 - 0xCF -#define JtagReEnableError 0xB0 -#define JtagReEnableOEMPubKeyError 0xB1 -#define JtagReEnableOEMSignedPassWdError 0xB2 -#define JtagReEnableTimeOutError 0xB3 -#define JtagReEnableOEMKeyLengthError 0xB4 - -// SDMMC Errors 0xD0-0xE5 -#define SDMMC_SWITCH_ERROR 0xD0 -#define SDMMC_ERASE_RESET_ERROR 0xD1 -#define SDMMC_CIDCSD_OVERWRITE_ERROR 0xD2 -#define SDMMC_OVERRUN_ERROR 0xD3 -#define SDMMC_UNDERUN_ERROR 0xD4 -#define SDMMC_GENERAL_ERROR 0xD5 -#define SDMMC_CC_ERROR 0xD6 -#define SDMMC_ECC_ERROR 0xD7 -#define SDMMC_ILL_CMD_ERROR 0xD8 -#define SDMMC_COM_CRC_ERROR 0xD9 -#define SDMMC_LOCK_ULOCK_ERRROR 0xDA -#define SDMMC_LOCK_ERROR 0xDB -#define SDMMC_WP_ERROR 0xDC -#define SDMMC_ERASE_PARAM_ERROR 0xDD -#define SDMMC_ERASE_SEQ_ERROR 0xDE -#define SDMMC_BLK_LEN_ERROR 0xDF -#define SDMMC_ADDR_MISALIGN_ERROR 0xE0 -#define SDMMC_ADDR_RANGE_ERROR 0xE1 -#define SDMMCDeviceNotReadyError 0xE2 -#define SDMMCInitializationError 0xE3 -#define SDMMCDeviceVoltageNotSupported 0xE4 -#define SDMMCWriteError 0xE5 -#define SDMMCAltBootDataAlignmentError 0xE6 -#define SDMMC_SGPT_ILLEGAL_LENGTH 0xE7 - -// SDIO Errors 0xF0 - -#define SDIOReadError 0xF0 -#define SDIOWriteError 0xF1 -#define SDIOOutOfSyncError 0xF2 -#define SDIONullBuffer 0xF3 -#define SDIOBufferMisalignError 0xF4 -#define SDIOImageSizeError 0xF5 - - -// WTM FuseBlock Errors -#define FUSE_FuseBlockNotActive 0x100 -#define FUSE_BufferTooSmall 0x101 -#define FUSE_FuseBlockLocked 0x102 -#define FUSE_UnsupportedFuseBlock 0x103 -#define FUSE_IncompleteBurnRequest 0x104 -#define FUSE_NoBurnRequest 0x105 -#define FUSE_FuseBlockFieldNotActive 0x106 -#define FUSE_BurnError 0x107 -#define FUSE_FuseBlockFieldOverflow 0x108 -#define FUSE_InvalidFuseBlockField 0x109 -#define FUSE_FuseBlockCompareFailed 0x10A -#define FUSE_InvalidState 0x10B -#define FUSE_InvalidBufferSize 0x10C -#define FUSE_BitSetError 0x10D -#define FUSE_FuseBlockLockedAndNotReadable 0x10E -#define FUSE_FuseBlockFieldFull 0x10F -#define FUSE_FuseSoftwareResetTimeout 0x110 -#define FUSE_FuseBurnTimeout 0x111 -#define FUSE_FuseBlockStickyBitSet 0x112 -#define FUSE_UsbPhyBandgapNotEnabled 0x113 -#define FUSE_UncorrectableEccError 0x114 -#define FUSE_FieldWriteProtectedByEcc 0x115 -#define FUSE_LastLogicalBitBurned 0x116 -#define FUSE_TamperError 0x117 -#define FUSE_FuseReprogrammingError 0x118 -#define FUSE_IncompleteFuseFieldsSetup 0x119 - -// GEU FuseBlock Errors -#define GEU_FuseBlockNotActive 0x100 -#define GEU_BufferTooSmall 0x101 -#define GEU_FuseBlockLocked 0x102 -#define GEU_UnsupportedFuseBlock 0x103 -#define GEU_IncompleteBurnRequest 0x104 -#define GEU_NoBurnRequest 0x105 -#define GEU_FuseBlockFieldNotActive 0x106 -#define GEU_BurnError 0x107 -#define GEU_FuseBlockFieldOverflow 0x108 -#define GEU_InvalidFuseBlockField 0x109 -#define GEU_FuseBlockCompareFailed 0x10A -#define GEU_InvalidState 0x10B -#define GEU_InvalidBufferSize 0x10C -#define GEU_BitSetError 0x10D -#define GEU_FuseBlockLockedAndNotReadable 0x10E -#define GEU_FuseBlockFieldFull 0x10F -#define GEU_FuseSoftwareResetTimeout 0x110 -#define GEU_FuseBurnTimeout 0x111 -#define GEU_FuseBlockStickyBitSet 0x112 -#define GEU_UsbPhyBandgapNotEnabled 0x113 -#define GEU_UncorrectableEccError 0x114 -#define GEU_FieldWriteProtectedByEcc 0x115 -#define GEU_LastLogicalBitBurned 0x116 -#define GEU_TamperError 0x117 -#define GEU_FuseReprogrammingError 0x118 -#define GEU_IncompleteFuseFieldsSetup 0x119 - - -// TrustZone Related Errors -#define TZ_Region0NotProtected 0x120 -#define TZ_FusesNotConfiguredForTrustzone 0x121 -#define TZ_PackageNotFound 0x122 -#define TZ_InitDisabled 0x123 -#define TZ_UnknownOperation 0x124 - -//DDR Related Error Codes -#define DDR_Package_Obsolete 0x200 -#define DDR_Unknown_Operation 0x201 -#define DDR_MemoryTest_Failed 0x202 -#define DDR_InitDisabled 0x203 -#define DDR_CMCC_Package_Obsolete 0x204 -#define DDR_Trustzone_Package_Obsolete 0x205 -#define DDR_PackageNotFound 0x206 -#define DDR_FusesNotConfiguredForTrustzone 0x207 - - - -//Instruction related codes -#define UnknownInstruction 0x300 -#define InstructionTimeout 0x301 -#define INSTR_InvalidAddress 0x302 -#define INSTR_InvalidScratchMemoryId 0x303 -#define INSTR_InvalidMaskOrValue 0x304 - -// sparse file related codes -#define Sparse_ImageLengthLimitExceeded 0x400 -#define Sparse_BadMagic 0x401 -#define Sparse_IncompatibleFormat 0x402 -#define Sparse_BadChunkSize 0x403 -#define Sparse_BogusDontCareChunk 0x404 -#define Sparse_UnknownChunkId 0x405 -#define Sparse_WriteError 0x406 - -//Relate to EMMC error -#define SDH_CMD_TIMEOUT_ERR 0x420 -#define SDH_CMD_CRC_ERR 0x421 -#define SDH_CMD_END_BIT_ERR 0x422 -#define SDH_CMD_INDEX_ERR 0x423 -#define SDH_DATA_TIMEOUT_ERR 0x424 -#define SDH_RD_DATA_CRC_ERR 0x425 -#define SDH_RD_DATA_END_BIT_ERR 0x426 -#define SDH_AUTO_CMD12_ERR 0x427 -#define SDH_ADMA_ERR 0x428 -#define SDH_TUNE_ERR 0x429 -#define SDH_SPI_ERR 0x42A -#define SDH_AXI_RESP_ERR 0x42B -#define SDH_CPL_TIMEOUT_ERR 0x42C -#define SDH_CRC_STATUS_ERR 0x42D - - -// DTIM related codes -#define IMAP_PackageNotFound 0x500 -#define IMAP_ErrorFormat 0x501 -#define IMAP_DTIMNotFound 0x502 -#define IMAP_DTIMLoadError 0x503 -#define IMAP_DTIMValidationFailed 0x504 -#define IMAP_BootFailed 0x505 -#define IMAP_KeyNotFound 0x506 -#define IMAP_ImageLoadError 0x507 -#define IMAP_ImageValidateError 0x508 - -// MRD related codes -#define MRD_BadMagic 0x520 -#define MRD_CheckSumNotMatch 0x521 -#define MRD_IMEINotMatch 0x522 - -#endif diff --git a/fbfdownloader/src/FBFDownloader.c b/fbfdownloader/src/FBFDownloader.c deleted file mode 100644 index 3d1c8f5d4..000000000 --- a/fbfdownloader/src/FBFDownloader.c +++ /dev/null @@ -1,900 +0,0 @@ -#include - -#include "CommonFun.h" -#include "downloader.h" -#include "WtptpDownLoad.h" -#include -#include "ParaDefine.h" -#include "BinFileWtp.h" -#include "kstring.h" -#include "fbfdownload.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define SUCCEED 0 -#define FAILED 1 - -#define MIN_ARGS 3 - -#define FBF_TIMHEADER 'i' -#define FBF_FILE 'f' -#define DKB_TIMHEADER 't' -#define DKB_FILE 'd' -#define BIN_FILE 'b' -#define LOG_PATH 'p' -// #define PLATFORM_TYPE 'p' - -#define MAX_FILE_LENGTH 256 - - -kstring_t g_DkbTimPath={0,0,NULL}, g_DkbFilePath={0,0,NULL}, g_BinFilePath={0,0,NULL}; - -kstring_t strDeviceDetectFile={0,0,NULL}; -BOOL bDownload = TRUE; -BOOL bUpload = FALSE; -BOOL bSingle = TRUE; -BOOL btimeoutset = FALSE; -BOOL bIgnoreBlankLines = TRUE; -int exit_code = -1; -int timeout = 0; - -pthread_mutex_t mutex; -pthread_cond_t cond; - -int g_nDownloadPercent = 0; -int g_nBurnPercent = 0; - -const TCHAR* pszSWDReleaseDate = _T("2020-6-19"); -const TCHAR* pszSWDReleaseVersion = _T("4.9.0.7"); - -//char SWDLOCKFILE[255] = "/var/run/swdlinux.pid"; -char SWDLOCKFILE[255] = "./fbfdownloader.pid"; -extern char g_LogPath[255]; - -#define LOCKMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) - -#if DEBUG_MODE -BOOL bDebugTrace = TRUE; -#else -BOOL bDebugTrace = FALSE; -#endif - - -int lockfile(int fd) -{ - struct flock fl; - - fl.l_type = F_WRLCK; - fl.l_start = 0; - fl.l_whence = SEEK_SET; - fl.l_len = 0; - return(fcntl(fd, F_SETLK, &fl)); -} - -int already_running(void) -{ - int fd; - if (strlen(g_LogPath) > 0) - { - strncpy(SWDLOCKFILE,g_LogPath,_countof(SWDLOCKFILE)); - strncat(SWDLOCKFILE,"/fbfdownloader.pid",_countof(SWDLOCKFILE)); - } - fd = open(SWDLOCKFILE, O_RDWR | O_CREAT, LOCKMODE); - if (fd < 0) { - //syslog(LOG_ERR, "can't open %s: %s", SWDLOCKFILE, strerror(errno)); -#if PRINTLOG - printf("can't open %s: %s", SWDLOCKFILE, strerror(errno)); -#endif - exit(1); - } - if (lockfile(fd) < 0) { - if (errno == EACCES || errno == EAGAIN) { - close(fd); - return(1); - } - //syslog(LOG_ERR, "can't lock %s: %s", SWDLOCKFILE, strerror(errno)); -#if PRINTLOG - printf("can't lock %s: %s", SWDLOCKFILE, strerror(errno)); -#endif - exit(1); - } - //close(fd); - return(0); -} - -BOOL ParseCommandLine(int argc, char* argv[]) -{ - int currentOption = 1; - BYTE Option = 0; - - while (currentOption < argc) - { - - if (*argv[currentOption] == '-') - { - Option = *++argv[currentOption++]; - - switch (Option) - { - case FBF_FILE: - { -/* - TCHAR szFbfPath[MAX_FILE_LENGTH]; - memset(szFbfPath, 0, sizeof(TCHAR)*MAX_FILE_LENGTH); - _tcscpy(szFbfPath, argv[currentOption]); - tstring strFbfPath(szFbfPath); - - g_lpFbfImageList->push_back(strFbfPath); -*/ - } - break; - case FBF_TIMHEADER: - { - /* - TCHAR szFbfTimPath[MAX_FILE_LENGTH]; - memset(szFbfTimPath, 0, sizeof(TCHAR)*MAX_FILE_LENGTH); - _tcscpy(szFbfTimPath, argv[currentOption]); - tstring strFbfTimPath(szFbfTimPath); - - g_lpFbfImageList->push_front(strFbfTimPath); - */ - } - break; - case DKB_FILE: - { - // g_DkbFilePath = argv[currentOption]; - } - break; - case DKB_TIMHEADER: - { - // g_DkbTimPath = argv[currentOption]; - } - break; - case BIN_FILE: - { - kstrcpy(&g_BinFilePath, argv[currentOption]); - } - break; - case LOG_PATH: - { - strncpy(g_LogPath,argv[currentOption],_countof(g_LogPath)); - - if (strlen(g_LogPath) >0 && g_LogPath[strlen(g_LogPath)-1] == '/') - { - g_LogPath[strlen(g_LogPath)-1] = 0; - } - } - break; - default: - { -#if PRINTLOG - printf("\n Error: Command line option -%c is invalid!\n", Option); -#endif - return FALSE; - } - break; - } - } - else - { - currentOption++; - } - } - - return TRUE; -} - - -void CallbackProc(PProcInfo pNotifyInfo) -{ - //tprintf(_T("CallbackProc......\n")); - - if (!bIgnoreBlankLines) - { -#if PRINTLOG - tprintf(_T("\n")); - tprintf(_T("\n")); - tprintf(_T("\n")); - tprintf(_T("\n")); - tprintf(_T("\n")); - tprintf(_T("\n")); - tprintf(_T("\n")); - tprintf(_T("\n")); - tprintf(_T("\n")); - tprintf(_T("\n")); - tprintf(_T("\n")); - tprintf(_T("\n")); -#endif - } - - - switch ((eProcessState)pNotifyInfo->eProcState) - { - case kProcConnecting: - { - g_nDownloadPercent = 0; -#if PRINTLOG - tprintf(_T("|%s:Add an device |\n"), pNotifyInfo->pszUSBPortAddress); -#endif - } - break; - case kProcDownloading: - { - if (!bIgnoreBlankLines) - { -#if PRINTLOG - tprintf(_T("|%s:Download percentage is:%d |\r"), pNotifyInfo->pszUSBPortAddress, pNotifyInfo->nDownloadedPercent); -#endif - } - else if (pNotifyInfo->nDownloadedPercent > g_nDownloadPercent) - { -#if PRINTLOG - tprintf(_T("|%s:Download percentage is:%d |\r"), pNotifyInfo->pszUSBPortAddress, pNotifyInfo->nDownloadedPercent); -#endif - g_nDownloadPercent = pNotifyInfo->nDownloadedPercent; - } - - if ( _tcscmp(pNotifyInfo->pszProcMsg, _T("BadBlkNum") ) == 0 ) - { - kstring_t g_strBBPath = GetAppPath(); - kstring_t strBBFile ={0,0,NULL}; - kputs(_T("/bbcs.txt"),&g_strBBPath); - FILE* BbcLogFile = _tfopen(g_strBBPath.s,_T("w")); - tfprintf (BbcLogFile,_T("%lf"),le32toh(pNotifyInfo->lpBadBlk.TotalBadBlocks)/le32toh(pNotifyInfo->lpBadBlk.TotalBlocks)); - fflush(BbcLogFile); - fclose(BbcLogFile); - free(g_strBBPath.s); - // tprintf(_T("\rFlash Info: TotalBadBlocks = %d, Total Blocks = %d"), - // le32toh(pNotifyInfo->lpBadBlk.TotalBadBlocks), le32toh(pNotifyInfo->lpBadBlk.TotalBlocks)); - - //To do your code, you can abort the download at certain bad blocks number. - /* if(((pNotifyInfo->lpBadBlk.TotalBadBlocks)*50) > pNotifyInfo->lpBadBlk.TotalBlocks) - { - tprintf(_T("|%s:Too many bad blocks |\n"), pNotifyInfo->pszUSBPortAddress); - exit_code = FAILED; - pthread_cond_signal(&cond); - } - */ - } - } - break; - case kProcAborting: - { -#if PRINTLOG - tprintf(_T("\n|%s:Abort in download |"), pNotifyInfo->pszUSBPortAddress); -#endif - exit_code = FAILED; - pthread_cond_signal(&cond); - - } - break; - case kProcCompleted: - { - if (bUpload) - { -#if PRINTLOG - tprintf(_T("|%s:Upload Successfully |\n"), pNotifyInfo->pszUSBPortAddress); -#endif - } - else - { -#if PRINTLOG - tprintf(_T("|%s:Burn Successfully |\n"), pNotifyInfo->pszUSBPortAddress); -#endif - } - - exit_code = SUCCEED; - pthread_cond_signal(&cond); - } - break; - case kProcBurningFlash: - { - if (!bIgnoreBlankLines) - { -#if PRINTLOG - tprintf(_T("|%s:Burning Flash percentage is:%d |\r"), pNotifyInfo->pszUSBPortAddress, pNotifyInfo->nDownloadedPercent); -#endif - } - else if (pNotifyInfo->nDownloadedPercent > g_nBurnPercent && pNotifyInfo->nDownloadedPercent <= 100) - { -#if PRINTLOG - tprintf(_T("|%s:Burning Flash percentage is:%d |\r"), pNotifyInfo->pszUSBPortAddress, pNotifyInfo->nDownloadedPercent); -#endif - g_nBurnPercent = pNotifyInfo->nDownloadedPercent; - } - - if ( _tcscmp(pNotifyInfo->pszProcMsg, _T("CRCS") ) == 0 ) - { -// tprintf(_T("\t\nBurning, Devices: MCPID: 0x%x, ImageNum: %d\n"), -// le32toh(pNotifyInfo->lpImageCrc.MCPID), le32toh(pNotifyInfo->lpImageCrc.ImageNum)); - kstring_t g_strAppPath = GetAppPath(); - kputs(_T("/crcs.txt"),&g_strAppPath); - FILE* CrcLogFile = _tfopen(g_strAppPath.s,_T("w")); - for(UINT32 i = 0; i < le32toh(pNotifyInfo->lpImageCrc.ImageNum); i++) - { -// tprintf(_T("ImageID: 0x%x, CrcData: 0x%8X\n"), -// le32toh(pNotifyInfo->lpImageCrc.ImageCRC[i].ImageID), le32toh(pNotifyInfo->lpImageCrc.ImageCRC[i].CRC32)); - if(i != le32toh(pNotifyInfo->lpImageCrc.ImageNum) -1) - tfprintf (CrcLogFile,_T("0x%08x-"),le32toh(pNotifyInfo->lpImageCrc.ImageCRC[i].CRC32)); - else - tfprintf (CrcLogFile,_T("0x%08x"),le32toh(pNotifyInfo->lpImageCrc.ImageCRC[i].CRC32)); - } - free(g_strAppPath.s); - fflush(CrcLogFile); - fclose(CrcLogFile); - } - - } - break; - case kProcUploadingData: - { -#if PRINTLOG - tprintf(_T("|%s:Uploading percentage is:%d |\r"), pNotifyInfo->pszUSBPortAddress, pNotifyInfo->nDownloadedPercent); -#endif - } - break; - case kProcDebugLog: - { -#if PRINTLOG - tprintf(_T("|%s: %s |\n"),pNotifyInfo->pszProcMsg,pNotifyInfo->pszUSBPortAddress); -#endif - } - break; - case kProcEraseAllFlash: - { -#if PRINTLOG - tprintf(_T("|%s:Erasing all flash percentage is:%d |\r"), pNotifyInfo->pszUSBPortAddress, pNotifyInfo->nDownloadedPercent); -#endif - } - break; - default: - break; - - } -#if PRINTLOG - if (!bIgnoreBlankLines) - { - tprintf(_T("\n")); - tprintf(_T("\n")); - tprintf(_T("\n")); - tprintf(_T("\n")); - tprintf(_T("\n")); - tprintf(_T("\n")); - tprintf(_T("\n")); - tprintf(_T("\n")); - tprintf(_T("\n")); - tprintf(_T("\n")); - } -#endif - fflush(stdout); -} - -BOOL InitInstanceParams(PInstanceParams lpInstanceParam, struct StringList* pFbfList) -{ -#define KNEWSTR(ps,src) \ - ps = (kstring_t*)malloc(sizeof(kstring_t)); \ - ps->s = NULL;ps->l = ps->m = 0; \ - kstrcpy(ps, src); - - - //提取Dkb和DKBTimeheader - for (int i = 0; i < pFbfList->nSize; i++) - { - const char * strFile = pFbfList->strL[i]; - printf("Init %s\n",strFile); - if (strstr(strFile,_T("DKB_timheader.bin")) != NULL || strstr(strFile,_T("DKB_ntimheader.bin")) != NULL) - { - kstrcpy(&g_DkbTimPath,strFile); - for (int j = i; j < pFbfList->nSize-1; j++) - pFbfList->strL[j] = pFbfList->strL[j+1]; - i--; - pFbfList->nSize--; - } else if (strstr(strFile,_T("Dkb.bin"))) - { - kstrcpy(&g_DkbFilePath,strFile); - for (int j = i; j < pFbfList->nSize-1; j++) - pFbfList->strL[j] = pFbfList->strL[j+1]; - i--; - pFbfList->nSize--; - } - } -#if PRINTLOG - tprintf(_T("DKB_timheader is %s DKB is %s\n"),g_DkbTimPath.s, g_DkbFilePath.s); -#endif - //g_lpFbfImageList->sort(); - for (int i = 0; i < pFbfList->nSize-1; i++) - for (int j = i+1; j < pFbfList->nSize; j++) - if (strcmp(pFbfList->strL[i], pFbfList->strL[j]) > 0) - { - const char *strTmp = pFbfList->strL[i]; - pFbfList->strL[i] = pFbfList->strL[j]; - pFbfList->strL[j] = strTmp; - } - int ite = 0; - if (strstr(pFbfList->strL[ite],_T("0x")) != NULL ) - { - //Multi DDR case - while(ite!=pFbfList->nSize) - { - const char* tpos = strstr(pFbfList->strL[ite],_T("0x")); - if (tpos!= NULL) - { - DDR_FLASH_DOWNLOADIMAGE_INFO_SPEC *pDDRFlashImagInfo = (pDDR_FLASH_DOWNLOADIMAGE_INFO_SPEC)malloc(sizeof(DDR_FLASH_DOWNLOADIMAGE_INFO_SPEC)); - New_DDR_FLASH_DOWNLOADIMAGE_INFO_SPEC(pDDRFlashImagInfo); - char buf[32]; - int ite2 = ite; - memset(buf, 0, sizeof(buf)); - strncpy(buf,tpos,6); - kstrcpy(&pDDRFlashImagInfo->sVendorDDRId,buf); - //pDDRFlashImagInfo->sVendorDDRId = ite->substr(tpos,6); - strncpy(buf,tpos+6,6); - - kstrcpy(&pDDRFlashImagInfo->sFlashInfo,buf); - //pDDRFlashImagInfo->sFlashInfo = ite->substr(tpos+6,6); - //tstring sDdrFlashInfo = ite->substr(tpos,12); - ite2++; - printf("VendorDDRId:%s FlashInfo:%s\n",pDDRFlashImagInfo->sVendorDDRId.s,pDDRFlashImagInfo->sFlashInfo.s); - if (strstr(pFbfList->strL[ite],_T("header")) != NULL) - { - kstring_t *kps; - KNEWSTR(kps,pFbfList->strL[ite2]) - *kl_pushf(pstrl, *pDDRFlashImagInfo->pImagelist) = kps; - KNEWSTR(kps,pFbfList->strL[ite]) - *kl_pushf(pstrl, *pDDRFlashImagInfo->pImagelist) = kps; - //pDDRFlashImagInfo->pImagelist->push_front(new tstring(*ite2)); - //pDDRFlashImagInfo->pImagelist->push_front(new tstring(*ite)); -#if PRINTLOG - printf("FBF head:%s FBF:%s\n",pFbfList->strL[ite],pFbfList->strL[ite2]); -#endif - } else - { - kstring_t *kps; - KNEWSTR(kps,pFbfList->strL[ite]) - *kl_pushf(pstrl, *pDDRFlashImagInfo->pImagelist) = kps; - KNEWSTR(kps,pFbfList->strL[ite2]) - *kl_pushf(pstrl, *pDDRFlashImagInfo->pImagelist) = kps; -#if PRINTLOG - printf("FBF head:%s FBF:%s\n",pFbfList->strL[ite2],pFbfList->strL[ite]); -#endif - } - //g_lpFbfImageList->erase(ite++); - //g_lpFbfImageList->erase(ite2++); - for (int k = ite; k < pFbfList->nSize-3; k+=2) - { - pFbfList->strL[k] = pFbfList->strL[k+2]; - pFbfList->strL[k+1] = pFbfList->strL[k+3]; - } - pFbfList->nSize -= 2; - pDDRFlashImagInfo->TotalFlashTypeNum = 1; - pDDRFlashImagInfo->TotalVendorDDRTypeNum = 1; - *kl_pushp(dfdil,*lpInstanceParam->pDownloadImagesList)=pDDRFlashImagInfo; - } - //pDDRFlashImagInfo->pImagelist->push_back(new tstring(*ite)); - ite = 0; - } - } else - { - DDR_FLASH_DOWNLOADIMAGE_INFO_SPEC *pDDRFlashImagInfo = (pDDR_FLASH_DOWNLOADIMAGE_INFO_SPEC)malloc(sizeof(DDR_FLASH_DOWNLOADIMAGE_INFO_SPEC)); - New_DDR_FLASH_DOWNLOADIMAGE_INFO_SPEC(pDDRFlashImagInfo); - kstrcpy(&pDDRFlashImagInfo->sVendorDDRId,"Reserve"); - kstrcpy(&pDDRFlashImagInfo->sFlashInfo,"Reserve"); - int ite2 = ite; - ite2++; - kstring_t *kps; - if (strstr(pFbfList->strL[ite],_T("header")) != NULL ) - { - KNEWSTR(kps,pFbfList->strL[ite2]) - *kl_pushf(pstrl, *pDDRFlashImagInfo->pImagelist) = kps; - KNEWSTR(kps,pFbfList->strL[ite]) - *kl_pushf(pstrl, *pDDRFlashImagInfo->pImagelist) = kps; -#if PRINTLOG - printf("FBF head:%s FBF:%s\n",pFbfList->strL[ite],pFbfList->strL[ite2]); -#endif - } else{ - KNEWSTR(kps,pFbfList->strL[ite]) - *kl_pushf(pstrl, *pDDRFlashImagInfo->pImagelist) = kps; - KNEWSTR(kps,pFbfList->strL[ite2]) - *kl_pushf(pstrl, *pDDRFlashImagInfo->pImagelist) = kps; -#if PRINTLOG - printf("FBF head:%s FBF:%s\n",pFbfList->strL[ite2],pFbfList->strL[ite]); -#endif - } - for (int k = ite; k < pFbfList->nSize-4; k+=2) - { - pFbfList->strL[k] = pFbfList->strL[k+2]; - pFbfList->strL[k+1] = pFbfList->strL[k+3]; - } - pFbfList->nSize -= 2; - - pDDRFlashImagInfo->TotalFlashTypeNum = 1; - pDDRFlashImagInfo->TotalVendorDDRTypeNum = 1; - *kl_pushp(dfdil,*lpInstanceParam->pDownloadImagesList) = pDDRFlashImagInfo; - } - - - - TCHAR* pszTimFile = (TCHAR*)malloc(sizeof(TCHAR)*(g_DkbTimPath.l + 1)); - memset(pszTimFile, 0, (g_DkbTimPath.l + 1) * sizeof(TCHAR)); - memcpy(pszTimFile, g_DkbTimPath.s, g_DkbTimPath.l * sizeof(TCHAR)); - lpInstanceParam->pszDKBTim = pszTimFile; - - TCHAR* pszDkbFile = (TCHAR*)malloc(sizeof(TCHAR)*(g_DkbFilePath.l + 1)); - memset(pszDkbFile, 0, (g_DkbFilePath.l + 1) * sizeof(TCHAR)); - memcpy(pszDkbFile, g_DkbFilePath.s, g_DkbFilePath.l * sizeof(TCHAR)); - lpInstanceParam->pszDKBbin = pszDkbFile; - //lpInstanceParam->pDownloadImagesList->front()->pImagelist->back(); - kstring_t strFbfFile = *(*kl_back(pstrl, *kl_val(kl_begin(*lpInstanceParam->pDownloadImagesList))->pImagelist)); - BinFileWtp_OpenBinFile(&gBinFileWtp,_T("rb")); - // FILE* fpFile = _tfopen(strFbfFile.c_str(),_T("rb")); - // if (NULL == fpFile) - // { - // tprintf(_T("Open file failed:%s"),strFbfFile.c_str()); - // return FALSE; - // } - - MasterBlockHeader masterBlkHeader; - BinFileWtp_FseekBin(&gBinFileWtp,strFbfFile.s,4L,SEEK_SET); - BinFileWtp_ReadBinFile(&gBinFileWtp,&masterBlkHeader,sizeof(MasterBlockHeader),1,strFbfFile.s); - EndianConvertMasterBlockHeader(&masterBlkHeader); - printf("MasterBlkHeader.SizeOfBlock=%x\n",masterBlkHeader.Size_of_Block); - // fseek(fpFile,4,SEEK_SET); - // fread(&masterBlkHeader,sizeof(MasterBlockHeader),1,fpFile); - - DeviceHeader_V11 deviceHeaderBuf; - BinFileWtp_FseekBin(&gBinFileWtp,strFbfFile.s,masterBlkHeader.deviceHeaderOffset[0] + 4,SEEK_SET); - BinFileWtp_ReadBinFile(&gBinFileWtp,&deviceHeaderBuf,sizeof(DeviceHeader_V11),1,strFbfFile.s); - EndianConvertDeviceHeader_V11(&deviceHeaderBuf); - printf("deviceHeaderBuf.DeviceFlags=%x\n",deviceHeaderBuf.DeviceFlags); - // fseek(fpFile,masterBlkHeader.deviceHeaderOffset[0] + 4,SEEK_SET); - // fread(&deviceHeaderBuf,sizeof(DeviceHeader_V11),1,fpFile); - - lpInstanceParam->PlaformType = deviceHeaderBuf.ChipID; - lpInstanceParam->Commands |= (deviceHeaderBuf.FlashOpt.EraseAll?1:0); - lpInstanceParam->Commands |= (deviceHeaderBuf.FlashOpt.ResetBBT? (1<<2):0); - if (deviceHeaderBuf.FlashOpt.NandID) - { - lpInstanceParam->FlashType = 0; - } - /*Note: the BBCS and CRCS on/off are controlled by the blf via which fbf file was created. - Here for fbfdownloader pc side, just assume both are ON in order to avoid extract the information from TIMH. - The CallbackProc only try to read the infos when BBCS or CRCS success although the on/off at PC are always set to ON - lpInstanceParam->GetBadBlk = 1; - lpInstanceParam->ImageCrcEn = 1; - */ - lpInstanceParam->GetBadBlk = deviceHeaderBuf.BBCS_EN; - lpInstanceParam->ImageCrcEn = deviceHeaderBuf.CRCS_EN; - - BinFileWtp_CloseBinFIle(&gBinFileWtp); - // fclose(fpFile); - return TRUE; -#undef KNEWSTR -} - - -#ifdef STATICLIB_FBFDOWNLOAD -int fbfdownload(char * strBinFilePath, int nTimeout) -{ - struct StringList g_lpFbfImageList; - int i = 0; - BOOL bIsInProcess = FALSE; - memset(&g_lpFbfImageList,0,sizeof(struct StringList)); - //SetDebugMode(bDebugTrace); - pthread_mutex_init(&mutex, NULL); - pthread_cond_init(&cond, NULL); - -#if PRINTLOG - printf("\n\nfbfdownloader version: %s\n", pszSWDReleaseVersion); - printf("fbfdownloader date: %s\n\n", pszSWDReleaseDate); -#endif - //remove wtptp.ko - //system("rmmod wtptp.ko"); - if (nTimeout <= 0) - { - btimeoutset = FALSE; - }else - { - btimeoutset = TRUE; - timeout = nTimeout; - } - kstrcpy(&g_BinFilePath, strBinFilePath); - if (!IsFileExist(strBinFilePath)) - { - tprintf("BinFilePath Error\n"); - return 1; - } - - PInstanceParams lpInstanceParam = (PInstanceParams)malloc(sizeof(InstanceParams)); - if (NULL == lpInstanceParam) - { -#if PRINTLOG - tprintf("malloc memory failed.\n"); -#endif - return 1; - } - NewInstanceParams(lpInstanceParam); - if (g_BinFilePath.l > 0) - { - BinFileWtp_InitParameter2(&gBinFileWtp,g_BinFilePath.s, &g_lpFbfImageList); - } - - strDeviceDetectFile = GetAppPath(); - kputs("/swdl_linux_wtptp_device_detect.log", &strDeviceDetectFile); - - - if (bDownload) - { - if (InitInstanceParams(lpInstanceParam,&g_lpFbfImageList)) - { - lpInstanceParam->CallbackProc = CallbackProc; - if (bSingle) - { - lpInstanceParam->DownloadMode = 1; - } - if (!InitializeBL(lpInstanceParam)) - { -#if PRINTLOG - printf("InitializeBL failed , please check failed root cause....\n"); -#endif - DelInstanceParams(lpInstanceParam); - free(lpInstanceParam); - return 1; - } - bIsInProcess = TRUE; - } - else - { - DelInstanceParams(lpInstanceParam); - free(lpInstanceParam); - return 1; - } - - - } - - if (bIsInProcess) - { - if (bSingle) - { - if (btimeoutset) - { - struct timespec to; - pthread_mutex_lock(&mutex); - to.tv_sec = time(NULL) + timeout; - to.tv_nsec = 0; - if (ETIMEDOUT == pthread_cond_timedwait(&cond, &mutex, &to)) - { - exit_code = FAILED; - printf("swdl_linux timeout exit\n"); - printf("current timeout time is %d seconds, please increase timeout time to retry.\n", timeout); - } - - TerminateBL(); - } - else - { - pthread_mutex_lock(&mutex); - pthread_cond_wait(&cond, &mutex); - TerminateBL(); - } - printf("FBFDownloader EXIT.....\n"); - } - else - { - if (btimeoutset) - { - struct timespec to; - pthread_mutex_lock(&mutex); - to.tv_sec = time(NULL) + timeout; - to.tv_nsec = 0; - if (ETIMEDOUT == pthread_cond_timedwait(&cond, &mutex, &to)) - { - exit_code = FAILED; - printf("swdl_linux timeout exit\n"); - printf("current timeout time is %d seconds, please increase timeout time to retry.\n", timeout); - } - TerminateBL(); - } - else - { - - while (1) - { - sleep(2); - if (tolower(getchar()) == (int)'q') - { - TerminateBL(); - DelFile(strDeviceDetectFile.s); - DelInstanceParams(lpInstanceParam); - free(lpInstanceParam); - return 1; - } - } - } - } - } - DelFile(strDeviceDetectFile.s); - DelInstanceParams(lpInstanceParam); - free(lpInstanceParam); - return exit_code; -} -#else -int main(int argc, char *argv[]) -{ - struct StringList g_lpFbfImageList; - memset(&g_lpFbfImageList,0,sizeof(struct StringList)); - if (!ParseCommandLine(argc, argv)) - { -#if PRINTLOG - printf("Command line error.\n"); -#endif - - return 1; - } - if (already_running() == 1) - { - printf("\n\nthere is already an fbfdownloader is running, you can't run it again.\n\n"); - return 1; - } - int i = 0; - BOOL bIsInProcess = FALSE; - //SetDebugMode(bDebugTrace); - pthread_mutex_init(&mutex, NULL); - pthread_cond_init(&cond, NULL); - -#if PRINTLOG - printf("\n\nfbfdownloader version: %s\n", pszSWDReleaseVersion); - printf("fbfdownloader date: %s\n\n", pszSWDReleaseDate); -#endif - if (argc < MIN_ARGS) - { -#if PRINTLOG - tprintf(_T("Invalid parameters\n")); - tprintf(_T("Function: Do Remote or automatically Software Download to board\n")); - tprintf(_T("CommandLine: fbfdownloader -b BinFile [-p path of Log File]\n")); - tprintf(_T("Usage: FBFDownloader -b BinFile.bin \n\n")); -#endif - fflush(stdout); - - return 1; - } - - //remove wtptp.ko - //system("rmmod wtptp.ko"); - - - if (!IsFileExist(g_BinFilePath.s)) - { - tprintf("BinFilePath Error\n"); - return 1; - } - - - - PInstanceParams lpInstanceParam = (PInstanceParams)malloc(sizeof(InstanceParams)); - if (NULL == lpInstanceParam) - { -#if PRINTLOG - tprintf("malloc memory failed.\n"); -#endif - return 1; - } - NewInstanceParams(lpInstanceParam); - printf("BinFilePath is :%s\n",g_BinFilePath.s); - if (g_BinFilePath.l > 0) - { - if (FALSE == BinFileWtp_InitParameter2(&gBinFileWtp,g_BinFilePath.s, &g_lpFbfImageList)) - { - printf("BinFileWtp_InitParameter2 Faile!\n"); - return FAILED; - } else - { - printf("BinFileWtp_InitParameter2 Success!\n"); - } - } - strDeviceDetectFile = GetAppPath(); - //kputs("/swdl_linux_wtptp_device_detect.log", &strDeviceDetectFile); - printf("AppPath is :%s\n",strDeviceDetectFile.s); - if (bDownload) - { - if (InitInstanceParams(lpInstanceParam, &g_lpFbfImageList)) - { - lpInstanceParam->CallbackProc = CallbackProc; - if (bSingle) - { - lpInstanceParam->DownloadMode = 1; - } - if (!InitializeBL(lpInstanceParam)) - { -#if PRINTLOG - printf("InitializeBL failed , please check failed root cause....\n"); -#endif - DelInstanceParams(lpInstanceParam); - free(lpInstanceParam); - return 1; - } - bIsInProcess = TRUE; - } - else - { - DelInstanceParams(lpInstanceParam); - free(lpInstanceParam); - return 1; - } - - - } - - if (bIsInProcess) - { - if (bSingle) - { - if (btimeoutset) - { - struct timespec to; - pthread_mutex_lock(&mutex); - to.tv_sec = time(NULL) + timeout; - to.tv_nsec = 0; - if (ETIMEDOUT == pthread_cond_timedwait(&cond, &mutex, &to)) - { - exit_code = FAILED; - printf("swdl_linux timeout exit\n"); - printf("current timeout time is %d seconds, please increase timeout time to retry.\n", timeout); - } - - TerminateBL(); - } - else - { - pthread_mutex_lock(&mutex); - pthread_cond_wait(&cond, &mutex); - TerminateBL(); - } - printf("FBFDownloader EXIT.....\n"); - } - else - { - if (btimeoutset) - { - struct timespec to; - pthread_mutex_lock(&mutex); - to.tv_sec = time(NULL) + timeout; - to.tv_nsec = 0; - if (ETIMEDOUT == pthread_cond_timedwait(&cond, &mutex, &to)) - { - exit_code = FAILED; - printf("swdl_linux timeout exit\n"); - printf("current timeout time is %d seconds, please increase timeout time to retry.\n", timeout); - } - TerminateBL(); - } - else - { - - while (1) - { - sleep(2); - if (tolower(getchar()) == (int)'q') - { - TerminateBL(); - DelFile(strDeviceDetectFile.s); - DelInstanceParams(lpInstanceParam); - free(lpInstanceParam); - return 1; - } - } - } - } - } - DelFile(strDeviceDetectFile.s); - DelInstanceParams(lpInstanceParam); - free(lpInstanceParam); - return exit_code; -} -#endif diff --git a/fbfdownloader/src/FBFDownloader_makefile b/fbfdownloader/src/FBFDownloader_makefile deleted file mode 100644 index 286862ac2..000000000 --- a/fbfdownloader/src/FBFDownloader_makefile +++ /dev/null @@ -1,47 +0,0 @@ -############################################################### -# Makefile for the Marvell download for MMP2/wukong/NEVO on linux platform. -# -# -############################################################## - - -CC = gcc -static -BASE:=$(shell pwd) -IFL_PATH = ./ -IFL_INCLUDE_DIR = $(IFL_PATH)/ -IFL_LIBRARY_DIR = $(IFL_PATH) - -TBBOBJS = CommonFun.o\ - ParaDefine.o\ - WTPCOMMCLASS.o\ - BinFileWtp.o\ - WtptpDownloader.o\ - WtptpDownLoad.o\ - ConvetEdian.o\ - BulkDevNonDrv_Linux.o\ - kstring.o\ - FBFDownloader.o\ - -CCFLAGS += -O2 -D LINUX=1 -D WINDOWS=0 -D DEBUG_MODE=0 -D PRINTLOG=1 -std=c99 - -LIBS = -lpthread - - - -CCFLAGS += -D TRUSTED_BOOT=1 -I $(IFL_INCLUDE_DIR) -OUTPUT = fbfdownloader - - -OBJS = $(TBBOBJS) - -all: $(OBJS) - $(CC) -g -o $(OUTPUT) $(OBJS) $(LIBS) -ldl - -rm *.o - -$(TBBOBJS): %.o: $(BASE)/%.c - $(CC) -g $(CCFLAGS) -c $(BASE)/$*.c -o $(BASE)/$*.o - -.PHONY: clean tar tar-% -clean: - -rm *.o $(OUTPUT) - diff --git a/fbfdownloader/src/FBFDownloader_makefile_android b/fbfdownloader/src/FBFDownloader_makefile_android deleted file mode 100644 index 5dc04a071..000000000 --- a/fbfdownloader/src/FBFDownloader_makefile_android +++ /dev/null @@ -1,55 +0,0 @@ -############################################################### -# Makefile for the Marvell download for MMP2/wukong/NEVO on linux platform. -# -# -############################################################## - - -#CC = arm_1103_le-g++ -static -#CC = mipsel-linux-uclibc-g++ -static -#CC = mipsel-openwrt-linux-g++ -static -#CC = arm-hisiv200-linux-gnueabi-g++ --static - -CC = ${CROSS}gcc #-static -BASE:=$(shell pwd) -IFL_PATH = ./ -IFL_INCLUDE_DIR = $(IFL_PATH)/ -IFL_LIBRARY_DIR = $(IFL_PATH) - -TBBOBJS = CommonFun.o\ - ParaDefine.o\ - WTPCOMMCLASS.o\ - BinFileWtp.o\ - WtptpDownloader.o\ - WtptpDownLoad.o\ - ConvetEdian.o\ - BulkDevNonDrv_Linux.o\ - kstring.o\ - FBFDownloader.o\ - -CCFLAGS += -O2 -D LINUX=1 -D WINDOWS=0 -D DEBUG_MODE=0 -D PRINTLOG=1 -std=c99 -fPIE - - LIBS = -lc - - - -CCFLAGS += -D TRUSTED_BOOT=1 -I $(IFL_INCLUDE_DIR) -OUTPUT = fbfdownloader_cross - - -OBJS = $(TBBOBJS) - -all: $(OBJS) - $(CC) -g -o $(OUTPUT) $(OBJS) $(LIBS) -ldl -fPIE -pie - -rm *.o - -$(TBBOBJS): %.o: $(BASE)/%.c - $(CC) -g $(CCFLAGS) -c $(BASE)/$*.c -o $(BASE)/$*.o - -.PHONY: clean -clean: - -rm *.o $(OUTPUT) - - - - diff --git a/fbfdownloader/src/FBFDownloader_makefile_cross b/fbfdownloader/src/FBFDownloader_makefile_cross deleted file mode 100644 index 527e39c3d..000000000 --- a/fbfdownloader/src/FBFDownloader_makefile_cross +++ /dev/null @@ -1,55 +0,0 @@ -############################################################### -# Makefile for the Marvell download for MMP2/wukong/NEVO on linux platform. -# -# -############################################################## - - -#CC = arm_1103_le-g++ -static -#CC = mipsel-linux-uclibc-g++ -static -#CC = mipsel-openwrt-linux-g++ -static -#CC = arm-hisiv200-linux-gnueabi-g++ --static - -CC = ${CROSS}gcc #-static -BASE:=$(shell pwd) -IFL_PATH = ./ -IFL_INCLUDE_DIR = $(IFL_PATH) -IFL_LIBRARY_DIR = $(IFL_PATH) - -TBBOBJS = CommonFun.o\ - ParaDefine.o\ - WTPCOMMCLASS.o\ - BinFileWtp.o\ - WtptpDownloader.o\ - WtptpDownLoad.o\ - ConvetEdian.o\ - BulkDevNonDrv_Linux.o\ - kstring.o\ - FBFDownloader.o\ - -CCFLAGS += -O2 -D LINUX=1 -D WINDOWS=0 -D DEBUG_MODE=0 -D PRINTLOG=1 -std=gnu99 - - LIBS = -lpthread -lc -lgcc_eh - - - -CCFLAGS += -D TRUSTED_BOOT=1 -I $(IFL_INCLUDE_DIR) -OUTPUT = fbfdownloader_cross - - -OBJS = $(TBBOBJS) - -all: $(OBJS) - $(CC) -g -o $(OUTPUT) $(OBJS) $(LIBS) -ldl - -rm *.o - -$(TBBOBJS): %.o: $(BASE)/%.c - $(CC) -g $(CCFLAGS) -c $(BASE)/$*.c -o $(BASE)/$*.o - -.PHONY: clean -clean: - -rm *.o $(OUTPUT) - - - - diff --git a/fbfdownloader/src/Macrodef.h b/fbfdownloader/src/Macrodef.h deleted file mode 100644 index 7ce156656..000000000 --- a/fbfdownloader/src/Macrodef.h +++ /dev/null @@ -1,141 +0,0 @@ -#pragma once -#pragma warning ( disable : 4100 ) // Disable warning messages: unreferenced formal parameter -#pragma warning ( disable : 4189 ) // Disable warning messages: local variable is initialized but not referenced -#include -#include -#include -#include "klist.h" -#include "kstring.h" -#ifdef LINUX -#include -#if defined(__BYTE_ORDER__)&&(__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) -#define htobe16(x) (x) -#define htobe32(x) (x) -#define htobe64(x) (x) -#define htole16(x) __builtin_bswap16(x) -#define htole32(x) __builtin_bswap32(x) -#define htole64(x) __builtin_bswap64(x) -#else -#define htobe16(x) __builtin_bswap16(x) -#define htobe32(x) __builtin_bswap32(x) -#define htobe64(x) __builtin_bswap64(x) -#define htole16(x) (x) -#define htole32(x) (x) -#define htole64(x) (x) -#endif /* __BYTE_ORDER__ */ -#define be16toh(x) htobe16(x) -#define le16toh(x) htole16(x) -#define be32toh(x) htobe32(x) -#define le32toh(x) htole32(x) -#define be64toh(x) htobe64(x) -#define le64toh(x) htole64(x) - -#include -#include -#include -#include -#include - -#define _tmain main -#define _TCHAR TCHAR -#define _fseeki64 fseeko -#ifndef VOID -#define VOID void -typedef char CHAR; -typedef short SHORT; -typedef long LONG; -#endif - -#undef FALSE -#undef TRUE -#undef NULL -#define FALSE 0 -#define TRUE 1 -#define NULL 0 - -#ifdef UNICODE -#define _T L## -#define TCHAR wchar_t -#define _tprintf wprintf -#define _tcslen wcslen -#define tsnprintf snwprintf -#define _tcslen wcslen -#define _tcscmp wcscmp -#define _tfopen _wfopen -#define _tcsstr wcsstr -#define _tcscat wcscat -#define _taccess access -#define _tcstoul wcstoul -#define _tcsrchr wcsrchr -#define _tcscpy wcscpy -#define _tcsncpy wcsncpy -#define _ttoi _wtoi -#define _ttot _itow -#define _vstprintf vswprintf -#define _trename _wrename -#define _tremove _wremove -#define _stscanf swscanf -#else -#define _T -#define TCHAR char -#define _tprintf printf -#define _tcslen strlen -#define tsnprintf snprintf -#define _tcslen strlen -#define _tcscmp strcmp -#define _tfopen fopen -#define _tcsstr strstr -#define _tcscat strcat -#define _taccess access -#define _tcstoul strtoul -#define _tcsrchr strrchr -#define _tcscpy strcpy -#define _tcsncpy strncpy -#define _ttoi atoi -#define _ttot itoa -#define _vstprintf vsprintf -#define _trename rename -#define _tremove remove -#define _stscanf sscanf -#endif - -#else -#ifdef UNICODE -#define tsnprintf _snwprintf -#else -#define tsnprintf _snprintf -#endif -#endif - - -#ifdef UNICODE -#define tsprintf swprintf -#define taccess _waccess -#define tatoi _wtoi -#define titoa _itow -#define tsscanf swscanf -#define ttolower towlower -#define ttoupper towupper -#define tfprintf fwprintf -#define tprintf wprintf - -#define t_splitpath_s _wsplitpath_s - -#else -#define tsprintf sprintf -#define taccess access -#define tatoi atoi -#define titoa itoa -#define tsscanf sscanf -#define ttolower tolower -#define ttoupper toupper -#define tfprintf fprintf -#define tprintf printf -#define t_splitpath_s _splitpath_s -#endif - - -#define ACCESS_FILE_EXIST 0 -#define COMPARE_EQUAL 0 - - diff --git a/fbfdownloader/src/Makefile b/fbfdownloader/src/Makefile deleted file mode 100644 index 527e39c3d..000000000 --- a/fbfdownloader/src/Makefile +++ /dev/null @@ -1,55 +0,0 @@ -############################################################### -# Makefile for the Marvell download for MMP2/wukong/NEVO on linux platform. -# -# -############################################################## - - -#CC = arm_1103_le-g++ -static -#CC = mipsel-linux-uclibc-g++ -static -#CC = mipsel-openwrt-linux-g++ -static -#CC = arm-hisiv200-linux-gnueabi-g++ --static - -CC = ${CROSS}gcc #-static -BASE:=$(shell pwd) -IFL_PATH = ./ -IFL_INCLUDE_DIR = $(IFL_PATH) -IFL_LIBRARY_DIR = $(IFL_PATH) - -TBBOBJS = CommonFun.o\ - ParaDefine.o\ - WTPCOMMCLASS.o\ - BinFileWtp.o\ - WtptpDownloader.o\ - WtptpDownLoad.o\ - ConvetEdian.o\ - BulkDevNonDrv_Linux.o\ - kstring.o\ - FBFDownloader.o\ - -CCFLAGS += -O2 -D LINUX=1 -D WINDOWS=0 -D DEBUG_MODE=0 -D PRINTLOG=1 -std=gnu99 - - LIBS = -lpthread -lc -lgcc_eh - - - -CCFLAGS += -D TRUSTED_BOOT=1 -I $(IFL_INCLUDE_DIR) -OUTPUT = fbfdownloader_cross - - -OBJS = $(TBBOBJS) - -all: $(OBJS) - $(CC) -g -o $(OUTPUT) $(OBJS) $(LIBS) -ldl - -rm *.o - -$(TBBOBJS): %.o: $(BASE)/%.c - $(CC) -g $(CCFLAGS) -c $(BASE)/$*.c -o $(BASE)/$*.o - -.PHONY: clean -clean: - -rm *.o $(OUTPUT) - - - - diff --git a/fbfdownloader/src/ParaDefine.c b/fbfdownloader/src/ParaDefine.c deleted file mode 100644 index 79e1f380b..000000000 --- a/fbfdownloader/src/ParaDefine.c +++ /dev/null @@ -1,161 +0,0 @@ -#include "ParaDefine.h" -#include "BinFileWtp.h" -#include "WtptpDownloader.h" - -extern kstring_t strDeviceDetectFile, g_DkbFilePath,g_DkbTimPath,g_BinFilePath; -void Copy_NotifyStatus(PProcInfo me,struct _NotifyStatus* rhs) -{ - me->nDevice = rhs->nDevice; - me->nDevType = rhs->nDevType; - me->nDownloadedPercent = rhs->nDownloadedPercent; - me->lpBadBlk = rhs->lpBadBlk; - me->lpImageCrc = rhs->lpImageCrc; - me->eProcState = rhs->eProcState; - me->eProcStatus = rhs->eProcStatus; - me->nErrorCode = rhs->nErrorCode; - memcpy(&me->pszProcMsg,&rhs->pszProcMsg,sizeof(me->pszProcMsg)); - memcpy(&me->pszUSBPortAddress,&rhs->pszUSBPortAddress,sizeof(me->pszUSBPortAddress)); -} - -void New_DDR_FLASH_DOWNLOADIMAGE_INFO_SPEC(pDDR_FLASH_DOWNLOADIMAGE_INFO_SPEC me) -{ - me->pImagelist = (t_stringList*)malloc(sizeof(t_stringList)); - *me->pImagelist = kl_init(pstrl); - ks_release(&me->sVendorDDRId); - ks_release(&me->sFlashInfo); - me->TotalVendorDDRTypeNum = 0; - me->TotalFlashTypeNum = 1; -} - -void Del_DDR_FLASH_DOWNLOADIMAGE_INFO_SPEC(pDDR_FLASH_DOWNLOADIMAGE_INFO_SPEC me) -{ - - if( me->pImagelist!=NULL) - { - t_stringListIter ImagesIter = kl_begin(*me->pImagelist); - while(ImagesIter!= kl_end(*me->pImagelist) ) - { - if (kl_val(ImagesIter)->s) - free(kl_val(ImagesIter)->s); - free(kl_val(ImagesIter)); - ImagesIter = kl_next(ImagesIter); - } - kl_destroy(pstrl, *me->pImagelist); - free(me->pImagelist); - me->pImagelist = NULL; - } - if (me->sFlashInfo.s) - free(me->sFlashInfo.s); - if (me->sVendorDDRId.s) - free(me->sVendorDDRId.s); - ks_release(&me->sFlashInfo); - ks_release(&me->sVendorDDRId); -} - -void Copy_DDR_FLASH_DOWNLOADIMAGE_INFO_SPEC(pDDR_FLASH_DOWNLOADIMAGE_INFO_SPEC me,struct _DDR_FLASH_DOWNLOADIMAGE_INFO_SPEC* DDRFlashDownloadImageInfo) -{ - #define KNEWSTR(ps,src) \ - ps = (kstring_t*)malloc(sizeof(kstring_t)); \ - ps->s = NULL;ps->l = ps->m = 0; \ - kstrcpy(ps, src); - for(t_stringListIter ite = kl_begin(*me->pImagelist); ite != kl_end(*me->pImagelist); ite = kl_next(ite)) - { - if (kl_val(ite)->s) - free(kl_val(ite)->s); - free( kl_val(ite)); - } - kl_clear(pstrl,*me->pImagelist); - - me->sVendorDDRId = DDRFlashDownloadImageInfo->sVendorDDRId; - me->sFlashInfo = DDRFlashDownloadImageInfo->sFlashInfo; - me->TotalVendorDDRTypeNum = DDRFlashDownloadImageInfo->TotalVendorDDRTypeNum; - me->TotalFlashTypeNum = DDRFlashDownloadImageInfo->TotalFlashTypeNum; - t_stringListIter ImagesIter = kl_begin(*DDRFlashDownloadImageInfo->pImagelist); - while(ImagesIter!= kl_end(*DDRFlashDownloadImageInfo->pImagelist) ) - { - kstring_t *kps; - KNEWSTR(kps,kl_val(ImagesIter)->s); - *kl_pushp(pstrl,*me->pImagelist) = kps; - ImagesIter = kl_next(ImagesIter); - } - #undef KNEWSTR -} - - -void Copy_WTPTPREAMBLECOMMAND(pWTPTPREAMBLECOMMAND me,struct _WTPTPREAMBLECOMMAND* WTPCMD) -{ - me->CMD = WTPCMD->CMD; - me->SEQ = WTPCMD->SEQ; - me->CID = WTPCMD->CID; - me->Flags = WTPCMD->Flags; - me->LEN = WTPCMD->LEN; - memcpy(WTPCMD->Data,me->Data,CMDDATALENGTH); -} - - -void DelInstanceParams(PInstanceParams me) -{ - if (NULL != me->pszDKBbin) {free((void*)me->pszDKBbin);me->pszDKBbin = NULL;} - if (NULL != me->pszDKBTim) {free((void*)me->pszDKBTim);me->pszDKBTim = NULL;} - if (NULL != me->pszOBMFile) {free((void*)me->pszOBMFile);me->pszOBMFile = NULL;} - if (NULL != me->pszWTMFile) {free((void*)me->pszWTMFile);me->pszWTMFile = NULL;} - if (NULL != me->pszJTAGKeyFile) {free((void*)me->pszJTAGKeyFile);me->pszJTAGKeyFile = NULL;} - if (NULL != me->pszTZIIFile) {free((void*)me->pszTZIIFile);me->pszTZIIFile = NULL;} - if (NULL != me->pWtptpPreaCmd){free((void*)me->pWtptpPreaCmd); me->pWtptpPreaCmd = NULL;} - if (NULL != me->pUploadSpecs) - { - for (t_UpLoadDataSpecIter iter = kl_begin(*me->pUploadSpecs);iter != kl_end(*me->pUploadSpecs);iter = kl_next(iter)) - { - free( kl_val(iter)); - } - free( me->pUploadSpecs); - me->pUploadSpecs = NULL; - } - - if (NULL != me->pDownloadImagesList) - { - for (t_DdrFlashDownloadImgInfoIter iter = kl_begin(*me->pDownloadImagesList);iter != kl_end(*me->pDownloadImagesList);iter = kl_next(iter)) - { - Del_DDR_FLASH_DOWNLOADIMAGE_INFO_SPEC(kl_val(iter)); - free( kl_val(iter)); - } - } - kl_destroy(dfdil, *me->pDownloadImagesList); - free( me->pDownloadImagesList); - DelCWtptpDownLoad(&gWtptpDownload); - BinFileWtp_DelMe(&gBinFileWtp); - - //global var - free(strDeviceDetectFile.s); - free(g_DkbFilePath.s); - free(g_DkbTimPath.s); - free(g_BinFilePath.s); -} -void NewInstanceParams(PInstanceParams me) -{ - me->pszDKBbin=NULL; - me->pszDKBTim= NULL; - me->CallbackProc=NULL; - me->pszOBMFile=NULL; - me->pszWTMFile=NULL; - me->pszJTAGKeyFile=NULL; - me->pszTZIIFile=NULL; - me->pUploadSpecs=NULL; - me->pWtptpPreaCmd=NULL; - me->Commands=0; - me->FlashType=5; - me->PlaformType=4; - me->FlashPageSize=0; - me->DownloadMode=0; - me->ProductionMode=0; - me->GetBadBlk=0; - me->ImageCrcEn=0; - me->ReservedVal[0] = BADBLOCKRATE_BASE*100;//坏块率默认值 - me->pDownloadImagesList = (t_DdrFlashDownloadImgInfoList*)malloc(sizeof(t_DdrFlashDownloadImgInfoList)); - (*me->pDownloadImagesList) = kl_init(dfdil); - memset(&gBinFileWtp, 0, sizeof(struct CBinFileWtp)); - BinFileWtp_ResetPara(&gBinFileWtp); - memset(&gWtptpDownload, 0, sizeof(struct CWtptpDownLoad)); - NewCWtptpDownLoad(&gWtptpDownload); -} - diff --git a/fbfdownloader/src/ParaDefine.h b/fbfdownloader/src/ParaDefine.h deleted file mode 100644 index 4373321ae..000000000 --- a/fbfdownloader/src/ParaDefine.h +++ /dev/null @@ -1,774 +0,0 @@ -#ifndef PARADEFINE_H -#define PARADEFINE_H - -#include "./Macrodef.h" -#include "./Typedef.h" -#include "ErrorCode.h" -#include "./UploadParaDef.h" -#include "kstring.h" -#define BADBLOCKRATE_BASE 10000 - -extern struct CWtptpDownLoad gWtptpDownload; -extern struct CBinFileWtp gBinFileWtp; - - -#define __pstrl_free(x) -KLIST_INIT(pstrl,kstring_t*,__pstrl_free) - - -struct StringList -{ - const char* strL[64]; - int nSize; -}; - -typedef struct -{ - UINT32 ImageID; - UINT32 BadCnt; -}ImageBBInfo; - -typedef struct -{ - UINT32 ImageID; - UINT32 CRC32; -}CRCInfo; - -// Badblock data -typedef struct { - UINT32 TotalBadBlocks; - UINT32 TotalBlocks; - ImageBBInfo BadCount[8]; //reserved for critical partitions support -} BadBlockData, *pBadBlockData; - -// Image CRC data -typedef struct -{ - UINT32 MCPID; - UINT32 ImageNum; - CRCInfo ImageCRC[32]; //Crc32 of all images, support 32 images at maximum -}ImageCRCInfo, *pImageCRCInfo; - - -typedef enum EProcessState -{ - kProcIdle = 0, // Not active - kProcInit = 1, // Initialization - kProcBootRom = 2, // Initialization for BootRom - kProcPrepareData = 3, // Preparation images downloading - kProcConnecting = 4, // Open connection and handshake - kProcDownloading = 5, // Downloading Data - kProcAborting = 6, // Aborting in process - kProcFileCompleted = 7, // File downloading process is completed - kProcCompleted = 8, // Downloading process is completed - kProcUsbRemove = 9, // Usb device is removed - kProcDebugLog = 10, // Debug message report - kProcBurningFlash = 11, // Burning Data - kProcUploadingData = 12, // Uploading Data - kProcWaitingUploadData = 13, // Waiting UE to get upload data - kProcEraseAllFlash = 14, // Erase all Flash - kProcErrorCode = 15, // Error code in downloading - kProcFuseInfo = 16, // fuse Info - kProcFuseInfoError = 17, // fuse Info operate error report - kProcUEInfo = 18, // fuse Info - kProcStateMax = 0xfe -}eProcessState; - - -typedef enum -{ - stOK, // Finished OK - stInvalid, // Couldn't create instance - stUsbError, // Couldn't connect to the USB driver - stNoReply, // Target is not responding - stBadReply, // Protocol error - stDownloadMBError, // Downloading error - stFailedToConnect, // Handshake failure/TimeOut - stFailedFileCreate, // Create file failed - stParseFile, // Parse file error - stEmptyFileList, // Image file list is empty - stFileError, // AXF file not found or file format error - stFilePathError, // File path is not exist - stAborted, // Aborted using abort Process() - stThreadError, // Error creating the instance thread - stNack, // Not acknowledge - stCalculationError, // Check sum calculation error - stImgConversionFail, // Error Image conversion - stImgCheckOverlapFail, // Error image overlap - stImgBuildFail, // Error image build - stFolderError, // Work folder error - stMepBndError, // Error binding Mep data - stBurningFlashError, // Error in burning flash - stUEErrorTrace = 0xff // Target error trace -} eProcessStatus; - - -//Providing process evaluation information via Callback function -typedef struct _NotifyStatus -{ - int nDevice, // Active device number - nDevType, // Device type kUnknown = 0, kBootRom = 1, kBootloader = 2 - nDownloadedPercent; // Downloading percent - TCHAR pszProcMsg[1024]; // Callback message - TCHAR pszUSBPortAddress[260]; // USB socket address - BadBlockData lpBadBlk; // flash bad block data - ImageCRCInfo lpImageCrc; // CRC value of Images read back from flash - eProcessState eProcState; // Current process state - eProcessStatus eProcStatus; // Current process status - int nErrorCode; // Errorcode in download or burning - - - -}NotifyStatus, *PProcInfo; - - -typedef void (/*__stdcall*/ * CALLBACKPROC)(PProcInfo pNotifyInfo); - - -typedef klist_t(pstrl)* t_stringList; -typedef kliter_t(pstrl)* t_stringListIter; - -typedef struct _DDR_FLASH_DOWNLOADIMAGE_INFO_SPEC -{ - t_stringList* pImagelist; - kstring_t sVendorDDRId; - kstring_t sFlashInfo; - int TotalVendorDDRTypeNum; - int TotalFlashTypeNum; -} DDR_FLASH_DOWNLOADIMAGE_INFO_SPEC,*pDDR_FLASH_DOWNLOADIMAGE_INFO_SPEC; - - -#define __dfdi_free(x) -KLIST_INIT(dfdil,DDR_FLASH_DOWNLOADIMAGE_INFO_SPEC*,__dfdi_free) - - -typedef klist_t(dfdil)* t_DdrFlashDownloadImgInfoList; -typedef kliter_t(dfdil)* t_DdrFlashDownloadImgInfoIter; - -#define CMDDATALENGTH 8196 -typedef struct _WTPTPREAMBLECOMMAND -{ - BYTE CMD; - BYTE SEQ; - BYTE CID; - BYTE Flags; - UINT32 LEN; - BYTE Data[CMDDATALENGTH]; - -}WTPTPREAMBLECOMMAND,*pWTPTPREAMBLECOMMAND; - - - - - -#define CFG_VERSION _T("V1.3") -#define CFG_SECTION_NAME _T("DownloadPackageCfg") -#define CFG_VERSION_NUMBER _T("CfgVersion") -#define CFG_IMAGE_NUM _T("ImageNum") -#define CFG_FBF_SET_NUM _T("FbfSetNum") -#define CFG_DDRTYPE_NUM _T("DDRVendorTypeNum") -#define CFG_FLASHTYPE_NUM _T("FlashTypeNum") -#define CFG_IMAGE_IDX _T("Image_") -#define CFG_DDREMMC_TYPE _T("DDRVendorID_EMMC") -#define CFG_DDRTYPE_NAME _T("DDRVendorName") -#define CFG_DDRTYPE_ID _T("DDRVendorID") -#define CFG_FLASH_INFO _T("FlashInfo") -#define CFG_DKB_BIN _T("DKBbin") -#define CFG_DKB_TIM _T("DKBTim") -#define CFG_OBM_FILE _T("OBMFile") -#define CFG_TZII_FILE _T("TZIIFile") -#define CFG_WTM_FILE _T("WTMFile") -#define CFG_IMEI_FILE _T("IMEIFile") -#define CFG_MEP_FILE _T("MEPFile") -#define CFG_PLATFORM_TYPE _T("PlatFormType") -#define CFG_FLASH_TYPE _T("FlashFamilyType") -#define CFG_COMMAND _T("Command") -#define CFG_FLASH_PAGE_SIZE _T("FlashPageSize") -#define CFG_PRODUCTIONMODE _T("ProductionMode") - -#define MAX_RESERVED_DATA 4 - -typedef struct _InstanceParams -{ - t_DdrFlashDownloadImgInfoList * pDownloadImagesList; - const TCHAR* pszDKBbin; // Download file for Bootrom - const TCHAR* pszDKBTim; // Primary flasher file path(*.bin, *.axf, *.elf) (can be either Comm. or App flasher) - const TCHAR* pszOBMFile; // OBM file path - const TCHAR* pszWTMFile; // WTM file path - const TCHAR* pszTZIIFile; //TZII file path - const TCHAR* pszJTAGKeyFile; // OEM Key file path to do re-eanble JTAG in case JTAG is disable - CALLBACKPROC CallbackProc; // Callback function that will back relevant process information - pWTPTPREAMBLECOMMAND pWtptpPreaCmd; // Customize Preamble Command - unsigned int PlaformType; /* 2-MMP2 */ - /* 3-WUKONG */ - /* 4-PXA978 */ - /* 5-MMP3 */ - /* 6-PXA1802 */ - /* 8-PXA988/986 */ - /* 9-PXA1088 */ - /* 10-PXA1928 */ - /* 11-PXA1920 */ - /* 15-PXA1826 */ - unsigned int FlashType; // 0-NAND, 1-eMMC,3-SPINOR,4-ONENAND,others-Unknown - unsigned int Commands; // flags description /* bit switches */, user only need to set bit3 if user want to use customized preamble - /*bit 0:Erase all flash flag*/ - /*bit 1: Upload flag */ - /*bit 2: Reset BBT flag */ - /*bit 3: Customized preamble flag*/ - /*bit 4: erase all flash only flag */ - /*bit 5: JTAG Re enable flag */ - /*bit 6 ~ bit31 reserved */ - unsigned int FlashPageSize; // Nand Flash Data page size - unsigned int DownloadMode; // Single_Download 1,multi_download 0; - unsigned int ProductionMode; // ; - unsigned int GetBadBlk; //get flash bad block enabled 1; otherwise: 0 - unsigned int ImageCrcEn; // Image CRC enabled: 1,Image CRC disabled: 0; - unsigned int ReservedVal[MAX_RESERVED_DATA]; - t_UpLoadDataSpecList* pUploadSpecs; // Upload spec Info - -}InstanceParams, *PInstanceParams; - -#ifndef COMPRESSDATA -static ERRORCODETABLE WTPTPErrorCodes[MAXERRORCODES]= -{ - {NoError,_T("NoError")}, - {NotFoundError,_T("NotFoundError")}, - {GeneralError,_T("GeneralError")}, - {WriteError,_T("WriteError")}, - {ReadError,_T("ReadError")} , - {NotSupportedError,_T("NotSupportedError")} , - {InvalidPlatformConfigError,_T("InvalidPlatformConfigError")}, - {InvalidPlatformState,_T("InvalidPlatformState")}, - {InvalidSizeError,_T("InvalidSizeError")}, - {ProbeListExhaustError,_T("ProbeListExhaustError")}, - {DDR_NotInitializedError,_T("DDR_NotInitializedError")}, - {UnknownReservedPackage,_T("UnknownReservedPackage")}, - {NULLPointer,_T("NULLPointer")}, - {NANDIDDISMATCH ,_T("NANDIDDISMATCH")}, - {FBF_VersionNotMatch,_T("FBF_VersionNotMatch")}, - {FBF_DeviceMoreThanOne,_T("FBF_DeviceMoreThanOne")}, - {PlatformConfigBuckError,_T("PlatformConfigBuckError")}, - {ChipIdMismatch,_T("ChipIdMismatch")}, - {EraseError,_T("EraseError ")}, - {ProgramError,_T("ProgramError")}, - {InvalidBootTypeError,_T("InvalidBootTypeError")}, - {ProtectionRegProgramError,_T("ProtectionRegProgramError")}, - {NoOTPFound,_T("NoOTPFound")}, - {BBTReadError,_T("BBTReadError")}, - {MDOCInitFailed,_T("MDOCInitFailed ")}, - {OneNandInitFailed,_T("OneNandInitFailed")}, - {MDOCFormatFailed,_T("MDOCFormatFailed ")}, - {BBTExhaustedError,_T("BBTExhaustedError ")}, - {NANDNotFound,_T("NANDNotFound ")}, - {SDMMCNotFound,_T("SDMMCNotFound ")}, - {FlexOneNANDNotFound,_T("FlexOneNANDNotFound ")}, - {SDMMCReadError,_T("SDMMCReadError ")}, - {XIPReadError,_T("XIPReadError ")}, - {FlexOneNANDError,_T("FlexOneNANDError ")}, - {FlashDriverInitError,_T("FlashDriverInitError")}, - {FlashFuncNotDefined,_T("FlashFuncNotDefined")}, - {OTPError,_T("OTPError")}, - {InvalidAddressRangeError,_T("InvalidAddressRangeError")}, - {FlashLockError,_T("FlashLockError ")}, - {ReadDisturbError,_T("ReadDisturbError")}, - {FlashReadError,_T("FlashReadError")}, - {SPIFlashNotResponding,_T("SPIFlashNotResponding")}, - {ImageOverlayError,_T("ImageOverlayError ")}, - {FlashAddrNotChunkAlign ,_T("FlashAddrNotChunkAlign")}, - {FlashAddrNotWordAlign ,_T("FlashAddrNotWordAlign")}, - {BBTOUTOFRANGE ,_T("BBTOUTOFRANGE")}, - {FlashWriteVerifyError ,_T("FlashWriteVerifyError")}, - {FlashAddrOutOfRange ,_T("FlashAddrOutOfRange")}, - {DFCDoubleBitError,_T("DFCDoubleBitError ")}, - {DFCSingleBitError,_T("DFCSingleBitError ")}, - {DFCCS0BadBlockDetected,_T("DFCCS0BadBlockDetected ")}, - {DFCCS1BadBlockDetected,_T("DFCCS1BadBlockDetected ")}, - {DFCInitFailed,_T("DFCInitFailed")}, - {DFCONFIConfigError,_T("DFCONFIConfigError")}, - {DFC_WRREQ_TO,_T("DFC_WRREQ_TO")}, - {DFC_WRCMD_TO,_T("DFC_WRCMD_TO")}, - {DFC_RDDREQ_TO,_T("DFC_RDDREQ_TO")} , - {DFC_RDY_TO,_T("DFC_RDY_TO ")}, - {DFCCS0CommandDoneError,_T("DFCCS0CommandDoneError")}, - {DFCCS1CommandDoneError,_T("DFCCS1CommandDoneError ")}, - {DFC_PGDN_TO,_T("DFC_PGDN_TO")}, - {SPINORPROGRAMFAIL,_T("SPINORPROGRAMFAIL")}, - {SPINORERASEFAIL,_T("SPINORERASEFAIL")}, - {InvalidOEMVerifyKeyError,_T("InvalidOEMVerifyKeyError")}, - {InvalidOBMImageError,_T("InvalidOBMImageError")}, - {SecureBootFailureError,_T("SecureBootFailureError ")}, - {InvalidSecureBootMethodError,_T("InvalidSecureBootMethodError")}, - {UnsupportedFlashError,_T("UnsupportedFlashError")}, - {InvalidCaddoFIFOEntryError,_T("InvalidCaddoFIFOEntryError ")}, - {InvalidCaddoKeyNumberError,_T("InvalidCaddoKeyNumberError ")}, - {InvalidCaddoKeyTypeError,_T("InvalidCaddoKeyTypeError")}, - {RSADigitalSignatureDecryptError,_T("RSADigitalSignatureDecryptError")}, - {InvalidHashValueLengthError,_T("InvalidHashValueLengthError ")}, - {InvalidTIMImageError,_T("InvalidTIMImageError")}, - {HashSizeMismatch,_T("HashSizeMismatch")}, - {InvalidKeyHashError,_T("InvalidKeyHashError")}, - {TIMNotFound,_T("TIMNotFound")}, - {WTMStateError,_T("WTMStateError")}, - {FuseRWError,_T("FuseRWError")}, - {InvalidOTPHashError,_T("InvalidOTPHashError, keypair in current blf configuration is not the key of fuse")}, - {CRCFailedError,_T("CRCFailedError ")}, - {SaveStateNotFound,_T("SaveStateNotFound")}, - {WTMInitializationError,_T("WTMInitializationError")}, - {ImageNotFound,_T("ImageNotFound")}, - {InvalidImageHash,_T("InvalidImageHash")}, - {MicroCodePatchingError,_T("MicroCodePatchingError")}, - {SetJtagKeyError,_T("SetJtagKeyError")}, - {WTMDisabled,_T("WTMDisabled")}, - {PlatformVerifyFailure,_T("PlatformVerifyFailure")}, - {ImageLoadError,_T("ImageLoadError ")}, - {IPPCPHASHERROR,_T("IPPCPHASHERROR ")}, - {DownloadPortError,_T("DownloadPortError")}, - {DownloadError,_T("DownloadError")}, - {FlashNotErasedError,_T("FlashNotErasedError")}, - {InvalidKeyLengthError,_T("InvalidKeyLengthError")}, - {DownloadImageTooBigError,_T("DownloadImageTooBigError")}, - {UsbPreambleError,_T("UsbPreambleError")}, - {TimeOutError,_T("TimeOutError")}, - {UartReadWriteTimeOutError,_T("UartReadWriteTimeOutError")}, - {UnknownImageError,_T("UnknownImageError")}, - {MessageBufferFullError,_T("MessageBufferFullError")}, - {NoEnumerationResponseTimeOutError,_T("NoEnumerationResponseTimeOutError")}, - {UnknownProtocolCmd,_T("UnknownProtocolCmd")}, - {UsbRxError,_T("UsbRxError")}, - {ForceDownloadPseudoError,_T("ForceDownloadPseudoError")}, - {UsbTxError,_T("UsbTxError")}, - {JtagReEnableError,_T("JtagReEnableError")} , - {JtagReEnableOEMPubKeyError,_T("JtagReEnableOEMPubKeyError")}, - {JtagReEnableOEMSignedPassWdError,_T("JtagReEnableOEMSignedPassWdError")}, - {JtagReEnableTimeOutError,_T("JtagReEnableTimeOutError")}, - {JtagReEnableOEMKeyLengthError,_T("JtagReEnableOEMKeyLengthError ")} , - {SDMMC_SWITCH_ERROR,_T("SDMMC_SWITCH_ERROR")}, - {SDMMC_ERASE_RESET_ERROR,_T("SDMMC_ERASE_RESET_ERROR")}, - {SDMMC_CIDCSD_OVERWRITE_ERROR,_T("SDMMC_CIDCSD_OVERWRITE_ERROR")}, - {SDMMC_OVERRUN_ERROR,_T("SDMMC_OVERRUN_ERROR ")}, - {SDMMC_UNDERUN_ERROR,_T("SDMMC_UNDERUN_ERROR ")}, - {SDMMC_GENERAL_ERROR,_T("SDMMC_GENERAL_ERROR ")}, - {SDMMC_CC_ERROR,_T("SDMMC_CC_ERROR")}, - {SDMMC_ECC_ERROR,_T("SDMMC_ECC_ERROR")}, - {SDMMC_ILL_CMD_ERROR,_T("SDMMC_ILL_CMD_ERROR")}, - {SDMMC_COM_CRC_ERROR,_T("SDMMC_COM_CRC_ERROR")}, - {SDMMC_LOCK_ULOCK_ERRROR,_T("SDMMC_LOCK_ULOCK_ERRROR")}, - {SDMMC_LOCK_ERROR,_T("SDMMC_LOCK_ERROR ")}, - {SDMMC_WP_ERROR,_T("SDMMC_WP_ERROR")}, - {SDMMC_ERASE_PARAM_ERROR,_T("SDMMC_ERASE_PARAM_ERROR")}, - {SDMMC_ERASE_SEQ_ERROR,_T("SDMMC_ERASE_SEQ_ERROR")}, - {SDMMC_BLK_LEN_ERROR,_T("SDMMC_BLK_LEN_ERROR")}, - {SDMMC_ADDR_MISALIGN_ERROR,_T("SDMMC_ADDR_MISALIGN_ERROR")}, - {SDMMC_ADDR_RANGE_ERROR,_T("SDMMC_ADDR_RANGE_ERROR")}, - {SDMMCDeviceNotReadyError,_T("SDMMCDeviceNotReadyError")}, - {SDMMCInitializationError,_T("SDMMCInitializationError")}, - {SDMMCDeviceVoltageNotSupported,_T("SDMMCDeviceVoltageNotSupported")}, - {SDMMCWriteError,_T("SDMMCWriteError")}, - {SDMMCAltBootDataAlignmentError,_T("SDMMCAltBootDataAlignmentError")}, - {SDMMC_SGPT_ILLEGAL_LENGTH,_T("SDMMC_SGPT_ILLEGAL_LENGTH")}, - {SDIOReadError,_T("SDIOReadError")}, - {SDIOWriteError,_T("SDIOWriteError")}, - {SDIOOutOfSyncError,_T("SDIOOutOfSyncError")}, - {SDIONullBuffer,_T("SDIONullBuffer")}, - {SDIOBufferMisalignError,_T("SDIOBufferMisalignError")}, - {SDIOImageSizeError,_T("SDIOImageSizeError")}, - {FUSE_FuseBlockNotActive,_T("FUSE_FuseBlockNotActive")}, - {FUSE_BufferTooSmall,_T("FUSE_BufferTooSmall")}, - {FUSE_FuseBlockLocked,_T("FUSE_FuseBlockLocked ")}, - {FUSE_UnsupportedFuseBlock,_T("FUSE_UnsupportedFuseBlock")}, - {FUSE_IncompleteBurnRequest,_T("FUSE_IncompleteBurnRequest")}, - {FUSE_NoBurnRequest,_T("FUSE_NoBurnRequest")}, - {FUSE_FuseBlockFieldNotActive,_T("FUSE_FuseBlockFieldNotActive")}, - {FUSE_BurnError,_T("FUSE_BurnError")}, - {FUSE_FuseBlockFieldOverflow,_T("FUSE_FuseBlockFieldOverflow")}, - {FUSE_InvalidFuseBlockField,_T("FUSE_InvalidFuseBlockField")}, - {FUSE_FuseBlockCompareFailed,_T("FUSE_FuseBlockCompareFailed")}, - {FUSE_InvalidState,_T("FUSE_InvalidState")}, - {FUSE_InvalidBufferSize,_T("FUSE_InvalidBufferSize")}, - {FUSE_BitSetError,_T("FUSE_BitSetError")}, - {FUSE_FuseBlockLockedAndNotReadable,_T("FUSE_FuseBlockLockedAndNotReadable")}, - {FUSE_FuseBlockFieldFull,_T("FUSE_FuseBlockFieldFull")}, - {FUSE_FuseSoftwareResetTimeout,_T("FUSE_FuseSoftwareResetTimeout")}, - {FUSE_FuseBurnTimeout,_T("FUSE_FuseBurnTimeout")}, - {FUSE_FuseBlockStickyBitSet,_T("FUSE_FuseBlockStickyBitSet")}, - {FUSE_UsbPhyBandgapNotEnabled,_T("FUSE_UsbPhyBandgapNotEnabled")}, - {FUSE_UncorrectableEccError,_T("FUSE_UncorrectableEccError")}, - {FUSE_FieldWriteProtectedByEcc,_T("FUSE_FieldWriteProtectedByEcc")}, - {FUSE_LastLogicalBitBurned,_T("FUSE_LastLogicalBitBurned")}, - {FUSE_TamperError,_T("FUSE_TamperError")}, - {FUSE_FuseReprogrammingError,_T("FUSE_FuseReprogrammingError")}, - {FUSE_IncompleteFuseFieldsSetup,_T("FUSE_IncompleteFuseFieldsSetup")}, - {GEU_FuseBlockNotActive,_T("GEU_FuseBlockNotActive")}, - {GEU_BufferTooSmall,_T("GEU_BufferTooSmall")}, - {GEU_FuseBlockLocked,_T("GEU_FuseBlockLocked")}, - {GEU_UnsupportedFuseBlock,_T("GEU_UnsupportedFuseBlock ")}, - {GEU_IncompleteBurnRequest,_T("GEU_IncompleteBurnRequest ")}, - {GEU_NoBurnRequest,_T("GEU_NoBurnRequest")}, - {GEU_FuseBlockFieldNotActive,_T("GEU_FuseBlockFieldNotActive")}, - {GEU_BurnError,_T("GEU_BurnError")}, - {GEU_FuseBlockFieldOverflow,_T("GEU_FuseBlockFieldOverflow")}, - {GEU_InvalidFuseBlockField,_T("GEU_InvalidFuseBlockField")}, - {GEU_FuseBlockCompareFailed,_T("GEU_FuseBlockCompareFailed")}, - {GEU_InvalidState,_T("GEU_InvalidState")}, - {GEU_InvalidBufferSize,_T("GEU_InvalidBufferSize")}, - {GEU_BitSetError,_T("GEU_BitSetError")}, - {GEU_FuseBlockLockedAndNotReadable,_T("GEU_FuseBlockLockedAndNotReadable")}, - {GEU_FuseBlockFieldFull,_T("GEU_FuseBlockFieldFull")}, - {GEU_FuseSoftwareResetTimeout,_T("GEU_FuseSoftwareResetTimeout")}, - {GEU_FuseBurnTimeout,_T("GEU_FuseBurnTimeout")}, - {GEU_FuseBlockStickyBitSet,_T("GEU_FuseBlockStickyBitSet")}, - {GEU_UsbPhyBandgapNotEnabled,_T("GEU_UsbPhyBandgapNotEnabled")}, - {GEU_UncorrectableEccError,_T("GEU_UncorrectableEccError")}, - {GEU_FieldWriteProtectedByEcc,_T("GEU_FieldWriteProtectedByEcc")}, - {GEU_LastLogicalBitBurned,_T("GEU_LastLogicalBitBurned")}, - {GEU_TamperError,_T("GEU_TamperError")}, - {GEU_FuseReprogrammingError,_T("GEU_FuseReprogrammingError")}, - {GEU_IncompleteFuseFieldsSetup,_T("GEU_IncompleteFuseFieldsSetup")}, - {TZ_Region0NotProtected,_T("TZ_Region0NotProtected")}, - {TZ_FusesNotConfiguredForTrustzone,_T("TZ_FusesNotConfiguredForTrustzone")}, - {TZ_PackageNotFound ,_T("TZ_PackageNotFound")}, - {TZ_InitDisabled ,_T("TZ_InitDisabled")}, - {TZ_UnknownOperation ,_T("TZ_UnknownOperation")}, - {DDR_Package_Obsolete,_T("DDR_Package_Obsolete")}, - {DDR_Unknown_Operation,_T("DDR_Unknown_Operation")}, - {DDR_MemoryTest_Failed,_T("DDR_MemoryTest_Failed")}, - {DDR_InitDisabled,_T("DDR_InitDisabled")}, - {DDR_CMCC_Package_Obsolete,_T("DDR_CMCC_Package_Obsolete")}, - {DDR_Trustzone_Package_Obsolete,_T("DDR_Trustzone_Package_Obsolete")}, - {DDR_PackageNotFound,_T("DDR_PackageNotFound")}, - {DDR_FusesNotConfiguredForTrustzone,_T("DDR_FusesNotConfiguredForTrustzone")}, - {UnknownInstruction,_T("UnknownInstruction ")}, - {InstructionTimeout,_T("InstructionTimeout")}, - {INSTR_InvalidAddress,_T("INSTR_InvalidAddress")}, - {INSTR_InvalidScratchMemoryId,_T("INSTR_InvalidScratchMemoryId")}, - {INSTR_InvalidMaskOrValue,_T("INSTR_InvalidMaskOrValue")}, - {Sparse_ImageLengthLimitExceeded,_T("Sparse_ImageLengthLimitExceeded")}, - {Sparse_BadMagic,_T("Sparse_BadMagic")}, - {Sparse_IncompatibleFormat,_T("Sparse_IncompatibleFormat")}, - {Sparse_BadChunkSize,_T("Sparse_BadChunkSize")}, - {Sparse_BogusDontCareChunk,_T("Sparse_BogusDontCareChunk")}, - {Sparse_UnknownChunkId,_T("Sparse_UnknownChunkId")}, - {Sparse_WriteError,_T("Sparse_WriteError")}, - {SDH_CMD_TIMEOUT_ERR,_T("SDH_CMD_TIMEOUT_ERR")}, - {SDH_CMD_CRC_ERR,_T("SDH_CMD_CRC_ERR")}, - {SDH_CMD_END_BIT_ERR,_T("SDH_CMD_END_BIT_ERR")}, - {SDH_CMD_INDEX_ERR,_T("SDH_CMD_INDEX_ERR")}, - {SDH_DATA_TIMEOUT_ERR,_T("SDH_DATA_TIMEOUT_ERR")}, - {SDH_RD_DATA_CRC_ERR,_T("SDH_RD_DATA_CRC_ERR")}, - {SDH_RD_DATA_END_BIT_ERR,_T("SDH_RD_DATA_END_BIT_ERR")}, - {SDH_AUTO_CMD12_ERR ,_T("SDH_AUTO_CMD12_ERR")}, - {SDH_ADMA_ERR,_T("SDH_ADMA_ERR")}, - {SDH_TUNE_ERR,_T("SDH_TUNE_ERR")}, - {SDH_SPI_ERR,_T("SDH_SPI_ERR")}, - {SDH_AXI_RESP_ERR,_T("SDH_AXI_RESP_ERR")}, - {SDH_CPL_TIMEOUT_ERR,_T("SDH_CPL_TIMEOUT_ERR")}, - {SDH_CRC_STATUS_ERR,_T("SDH_CRC_STATUS_ERR")}, - {IMAP_PackageNotFound,_T("IMAP_PackageNotFound")}, - {IMAP_ErrorFormat,_T("IMAP_ErrorFormat")}, - {IMAP_DTIMNotFound,_T("IMAP_DTIMNotFound")}, - {IMAP_DTIMLoadError,_T("IMAP_DTIMLoadError")}, - {IMAP_DTIMValidationFailed,_T("IMAP_DTIMValidationFailed")}, - {IMAP_BootFailed,_T("IMAP_BootFailed")}, - {IMAP_KeyNotFound,_T("IMAP_KeyNotFound")}, - {IMAP_ImageLoadError,_T("IMAP_ImageLoadError")}, - {IMAP_ImageValidateError,_T("IMAP_ImageValidateError")}, - {MRD_BadMagic,_T("MRD_BadMagic")}, - {MRD_CheckSumNotMatch,_T("MRD_CheckSumNotMatch")}, - {MRD_IMEINotMatch,_T("MRD_IMEINotMatch")}, - -}; - - -static NOTIFICATIONTABLE WTPTPNotificationMsg[MAXNOTIFICATIONSCODES] = -{ - {PlatformBusy,_T("Platform is busy")}, - {PlatformReady,_T("Platform is Ready")}, - {PlatformResetBBT,_T("Reset BBT")}, - {PlatformEraseAllFlash,_T("Erase All flash begin")}, - {PlatformDisconnect,_T("platform is disconnect")}, - {PlatformEraseAllFlashDone,_T("Erase All flash done")}, - {PlatformEraseAllFlashWithoutBurn,_T("Erase All flash without burning begin")}, - {PlatformEraseAllFlashWithoutBurnDone,_T("Erase All flash without burning Done")}, - {PlatformFuseOperationStart,_T("Platform Fuse Operation Start")}, - {PlatformFuseOperationDone,_T("Platform Fuse Operation Done")}, - {PlatformUEInfoStart,_T("Platform UE Info Operation Start")}, - {PlatformUEInfoDone,_T("Platform UE Info Operation Done")} -}; -#else -static ERRORCODETABLE WTPTPErrorCodes[MAXERRORCODES]= -{ - {NoError}, - {NotFoundError}, - {GeneralError}, - {WriteError}, - {ReadError} , - {NotSupportedError} , - {InvalidPlatformConfigError}, - {InvalidPlatformState}, - {InvalidSizeError}, - {ProbeListExhaustError}, - {DDR_NotInitializedError}, - {UnknownReservedPackage}, - {NULLPointer}, - {NANDIDDISMATCH }, - {FBF_VersionNotMatch}, - {FBF_DeviceMoreThanOne}, - {PlatformConfigBuckError}, - {ChipIdMismatch}, - {EraseError}, - {ProgramError}, - {InvalidBootTypeError}, - {ProtectionRegProgramError}, - {NoOTPFound}, - {BBTReadError}, - {MDOCInitFailed}, - {OneNandInitFailed}, - {MDOCFormatFailed}, - {BBTExhaustedError}, - {NANDNotFound}, - {SDMMCNotFound}, - {FlexOneNANDNotFound}, - {SDMMCReadError}, - {XIPReadError}, - {FlexOneNANDError}, - {FlashDriverInitError}, - {FlashFuncNotDefined}, - {OTPError}, - {InvalidAddressRangeError}, - {FlashLockError}, - {ReadDisturbError}, - {FlashReadError}, - {SPIFlashNotResponding}, - {ImageOverlayError}, - {FlashAddrNotChunkAlign }, - {FlashAddrNotWordAlign }, - {BBTOUTOFRANGE }, - {FlashWriteVerifyError }, - {FlashAddrOutOfRange }, - {DFCDoubleBitError}, - {DFCSingleBitError}, - {DFCCS0BadBlockDetected}, - {DFCCS1BadBlockDetected}, - {DFCInitFailed}, - {DFCONFIConfigError}, - {DFC_WRREQ_TO}, - {DFC_WRCMD_TO}, - {DFC_RDDREQ_TO} , - {DFC_RDY_TO}, - {DFCCS0CommandDoneError}, - {DFCCS1CommandDoneError}, - {DFC_PGDN_TO}, - {SPINORPROGRAMFAIL}, - {SPINORERASEFAIL}, - {InvalidOEMVerifyKeyError}, - {InvalidOBMImageError}, - {SecureBootFailureError}, - {InvalidSecureBootMethodError}, - {UnsupportedFlashError}, - {InvalidCaddoFIFOEntryError}, - {InvalidCaddoKeyNumberError}, - {InvalidCaddoKeyTypeError}, - {RSADigitalSignatureDecryptError}, - {InvalidHashValueLengthError}, - {InvalidTIMImageError}, - {HashSizeMismatch}, - {InvalidKeyHashError}, - {TIMNotFound}, - {WTMStateError}, - {FuseRWError}, - {InvalidOTPHashError}, - {CRCFailedError}, - {SaveStateNotFound}, - {WTMInitializationError}, - {ImageNotFound}, - {InvalidImageHash}, - {MicroCodePatchingError}, - {SetJtagKeyError}, - {WTMDisabled}, - {PlatformVerifyFailure}, - {ImageLoadError}, - {IPPCPHASHERROR}, - {DownloadPortError}, - {DownloadError}, - {FlashNotErasedError}, - {InvalidKeyLengthError}, - {DownloadImageTooBigError}, - {UsbPreambleError}, - {TimeOutError}, - {UartReadWriteTimeOutError}, - {UnknownImageError}, - {MessageBufferFullError}, - {NoEnumerationResponseTimeOutError}, - {UnknownProtocolCmd}, - {UsbRxError}, - {ForceDownloadPseudoError}, - {UsbTxError}, - {JtagReEnableError} , - {JtagReEnableOEMPubKeyError}, - {JtagReEnableOEMSignedPassWdError}, - {JtagReEnableTimeOutError}, - {JtagReEnableOEMKeyLengthError} , - {SDMMC_SWITCH_ERROR}, - {SDMMC_ERASE_RESET_ERROR}, - {SDMMC_CIDCSD_OVERWRITE_ERROR}, - {SDMMC_OVERRUN_ERROR}, - {SDMMC_UNDERUN_ERROR}, - {SDMMC_GENERAL_ERROR}, - {SDMMC_CC_ERROR}, - {SDMMC_ECC_ERROR}, - {SDMMC_ILL_CMD_ERROR}, - {SDMMC_COM_CRC_ERROR}, - {SDMMC_LOCK_ULOCK_ERRROR}, - {SDMMC_LOCK_ERROR}, - {SDMMC_WP_ERROR}, - {SDMMC_ERASE_PARAM_ERROR}, - {SDMMC_ERASE_SEQ_ERROR}, - {SDMMC_BLK_LEN_ERROR}, - {SDMMC_ADDR_MISALIGN_ERROR}, - {SDMMC_ADDR_RANGE_ERROR}, - {SDMMCDeviceNotReadyError}, - {SDMMCInitializationError}, - {SDMMCDeviceVoltageNotSupported}, - {SDMMCWriteError}, - {SDMMCAltBootDataAlignmentError}, - {SDMMC_SGPT_ILLEGAL_LENGTH}, - {SDIOReadError}, - {SDIOWriteError}, - {SDIOOutOfSyncError}, - {SDIONullBuffer}, - {SDIOBufferMisalignError}, - {SDIOImageSizeError}, - {FUSE_FuseBlockNotActive}, - {FUSE_BufferTooSmall}, - {FUSE_FuseBlockLocked}, - {FUSE_UnsupportedFuseBlock}, - {FUSE_IncompleteBurnRequest}, - {FUSE_NoBurnRequest}, - {FUSE_FuseBlockFieldNotActive}, - {FUSE_BurnError}, - {FUSE_FuseBlockFieldOverflow}, - {FUSE_InvalidFuseBlockField}, - {FUSE_FuseBlockCompareFailed}, - {FUSE_InvalidState}, - {FUSE_InvalidBufferSize}, - {FUSE_BitSetError}, - {FUSE_FuseBlockLockedAndNotReadable}, - {FUSE_FuseBlockFieldFull}, - {FUSE_FuseSoftwareResetTimeout}, - {FUSE_FuseBurnTimeout}, - {FUSE_FuseBlockStickyBitSet}, - {FUSE_UsbPhyBandgapNotEnabled}, - {FUSE_UncorrectableEccError}, - {FUSE_FieldWriteProtectedByEcc}, - {FUSE_LastLogicalBitBurned}, - {FUSE_TamperError}, - {FUSE_FuseReprogrammingError}, - {FUSE_IncompleteFuseFieldsSetup}, - {GEU_FuseBlockNotActive}, - {GEU_BufferTooSmall}, - {GEU_FuseBlockLocked}, - {GEU_UnsupportedFuseBlock}, - {GEU_IncompleteBurnRequest}, - {GEU_NoBurnRequest}, - {GEU_FuseBlockFieldNotActive}, - {GEU_BurnError}, - {GEU_FuseBlockFieldOverflow}, - {GEU_InvalidFuseBlockField}, - {GEU_FuseBlockCompareFailed}, - {GEU_InvalidState}, - {GEU_InvalidBufferSize}, - {GEU_BitSetError}, - {GEU_FuseBlockLockedAndNotReadable}, - {GEU_FuseBlockFieldFull}, - {GEU_FuseSoftwareResetTimeout}, - {GEU_FuseBurnTimeout}, - {GEU_FuseBlockStickyBitSet}, - {GEU_UsbPhyBandgapNotEnabled}, - {GEU_UncorrectableEccError}, - {GEU_FieldWriteProtectedByEcc}, - {GEU_LastLogicalBitBurned}, - {GEU_TamperError}, - {GEU_FuseReprogrammingError}, - {GEU_IncompleteFuseFieldsSetup}, - {TZ_Region0NotProtected}, - {TZ_FusesNotConfiguredForTrustzone}, - {TZ_PackageNotFound }, - {TZ_InitDisabled }, - {TZ_UnknownOperation }, - {DDR_Package_Obsolete}, - {DDR_Unknown_Operation}, - {DDR_MemoryTest_Failed}, - {DDR_InitDisabled}, - {DDR_CMCC_Package_Obsolete}, - {DDR_Trustzone_Package_Obsolete}, - {DDR_PackageNotFound}, - {DDR_FusesNotConfiguredForTrustzone}, - {UnknownInstruction}, - {InstructionTimeout}, - {INSTR_InvalidAddress}, - {INSTR_InvalidScratchMemoryId}, - {INSTR_InvalidMaskOrValue}, - {Sparse_ImageLengthLimitExceeded}, - {Sparse_BadMagic}, - {Sparse_IncompatibleFormat}, - {Sparse_BadChunkSize}, - {Sparse_BogusDontCareChunk}, - {Sparse_UnknownChunkId}, - {Sparse_WriteError}, - {SDH_CMD_TIMEOUT_ERR}, - {SDH_CMD_CRC_ERR}, - {SDH_CMD_END_BIT_ERR}, - {SDH_CMD_INDEX_ERR}, - {SDH_DATA_TIMEOUT_ERR}, - {SDH_RD_DATA_CRC_ERR}, - {SDH_RD_DATA_END_BIT_ERR}, - {SDH_AUTO_CMD12_ERR }, - {SDH_ADMA_ERR}, - {SDH_TUNE_ERR}, - {SDH_SPI_ERR}, - {SDH_AXI_RESP_ERR}, - {SDH_CPL_TIMEOUT_ERR}, - {SDH_CRC_STATUS_ERR}, - {IMAP_PackageNotFound}, - {IMAP_ErrorFormat}, - {IMAP_DTIMNotFound}, - {IMAP_DTIMLoadError}, - {IMAP_DTIMValidationFailed}, - {IMAP_BootFailed}, - {IMAP_KeyNotFound}, - {IMAP_ImageLoadError}, - {IMAP_ImageValidateError}, - {MRD_BadMagic}, - {MRD_CheckSumNotMatch}, - {MRD_IMEINotMatch} - -}; - - -static NOTIFICATIONTABLE WTPTPNotificationMsg[MAXNOTIFICATIONSCODES] = -{ - {PlatformBusy}, - {PlatformReady}, - {PlatformResetBBT}, - {PlatformEraseAllFlash}, - {PlatformDisconnect}, - {PlatformEraseAllFlashDone}, - {PlatformEraseAllFlashWithoutBurn}, - {PlatformEraseAllFlashWithoutBurnDone}, - {PlatformFuseOperationStart}, - {PlatformFuseOperationDone}, - {PlatformUEInfoStart}, - {PlatformUEInfoDone} -}; - -#endif - -void Copy_NotifyStatus(PProcInfo me,struct _NotifyStatus* rhs); -void New_DDR_FLASH_DOWNLOADIMAGE_INFO_SPEC(pDDR_FLASH_DOWNLOADIMAGE_INFO_SPEC me); -void Del_DDR_FLASH_DOWNLOADIMAGE_INFO_SPEC(pDDR_FLASH_DOWNLOADIMAGE_INFO_SPEC me); -void Copy_DDR_FLASH_DOWNLOADIMAGE_INFO_SPEC(pDDR_FLASH_DOWNLOADIMAGE_INFO_SPEC me,struct _DDR_FLASH_DOWNLOADIMAGE_INFO_SPEC* DDRFlashDownloadImageInfo); -void Copy_WTPTPREAMBLECOMMAND(pWTPTPREAMBLECOMMAND me,struct _WTPTPREAMBLECOMMAND* WTPCMD); -void DelInstanceParams(PInstanceParams me); -void NewInstanceParams(PInstanceParams me); - -#endif diff --git a/fbfdownloader/src/ReadMe.txt b/fbfdownloader/src/ReadMe.txt deleted file mode 100644 index 70e7cab4c..000000000 --- a/fbfdownloader/src/ReadMe.txt +++ /dev/null @@ -1,9 +0,0 @@ -FBFDownloader_makefile is the Makefile of fbfdownloader -libmakefile is the Makefile of libfbfdown.a, api is in fbfdownload.h. - - -//return 0 SUCCRSS -//return 1 FAIL -//timeout 0 Infinite Wait -//timeout >0 Wait N seconds for Download -int fbfdownload(char * strBinFilePath, int timeout); \ No newline at end of file diff --git a/fbfdownloader/src/Tim.h b/fbfdownloader/src/Tim.h deleted file mode 100644 index 30e1ef6f0..000000000 --- a/fbfdownloader/src/Tim.h +++ /dev/null @@ -1,960 +0,0 @@ -#ifndef __TIM_H__ -#define __TIM_H__ - -//#include "general.h" -#include "Macrodef.h" -#include "TimIncludedType.h" -/******************* TIM Layout ************************************/ -/* Below Presents the Maxiumum Size TIM layout in memory - -VERSION_I VersionBind; // 0 -FLASH_I FlashInfo; // 0x10 -UINT_T NumImages; // 0x20 -UINT_T NumKeys; // 0x24 -UINT_T SizeOfReserved; // 0x28 -IMAGE_INFO IMG[MAX_IMAGES]; // 0x2C -KEY_MOD Key[MAX_KEYS]; // 0x284 -UINT_T Reserved[0x4E8]; // 0x908 (0x4E8 bytes) -PLAT_DS TBTIM_DS; // 0xDF0 - // 0x1000 = 4 KB -Below Presents the Maxiumum Size NTIM layout in memory - -VERSION_I VersionBind; // 0 -FLASH_I FlashInfo; // 0x10 -UINT_T NumImages; // 0x20 -UINT_T NumKeys; // 0x24 -UINT_T SizeOfReserved; // 0x28 -IMAGE_INFO IMG[MAX_IMAGES]; // 0x2C -UINT_T Reserved[0xD80]; // 0x284 -NTIM, *pNTIM; // 0x1000 = 4KB -/******************* TIM Layout ************************************/ - - -// TIM Versions -#define TIM_3_1_01 0x30101 -#define TIM_3_2_00 0x30200 // Support for Partitioning -#define TIM_3_3_00 0x30300 // Support for ECDSA-256 and 64 bit addressing -#define TIM_3_4_00 0x30400 // Support for ECDSA-521 -#define TIM_3_5_00 0x30500 // Support for Encrypted Boot - -const int MAX_HASH = 256; -const int MAX_HASH_IN_BITS = 512; // 512 bits - -// B1 TIM -#include "Typedef.h" -#define MAX_IMAGES 100 -#define MAX_KEYS 3 -#define MAX_TIM_SIZE 0x1000 -#define TIMBUFFER 4096 //4k for a Tim structure size -#define MAXKEYSIZEWORDS 64 // 2048 bits -#define MAXRSAKEYSIZEWORDS 64 // 2048 bits -#define MAXECCKEYSIZEWORDS 17 // 521 bits+ - -// Predefined Image Identifiers -#define TIMIDENTIFIER 0x54494D48 // "TIMH" -#define TIM1IDENTIFIER 0x54494D31 // "TIM1" -#define TIM4IDENTIFIER 0x54494D34 // "TIM4" -#define WTMIDENTIFIER 0x57544D49 // "WTMI" -#define OBMIDENTIFIER 0x4F424D49 // "OBMI" -#define MONITORIDENTIFIER 0x4D4F4E49 // "MONI" -#define TZSWIDENTIFIER 0x545A5349 // "TZSI" This is also used as consumer ID -#define TBRIDENTIFIER 0x54425249 // "TBRI" This is also used as consumer ID -#define DKBIDENTIFIER 0x444B4249 // "DKBI" -#define JTAGIDENTIFIER 0x4A544147 // "JTAG" -#define AUTHIDENTIFIER 0x41555448 // "AUTH" -#define PATCHIDENTIFIER 0x50415443 // "PATC" -#define TCAIDENTIFIER 0x5443414B // "TCAK" -#define OSLOADERID 0x4F534C4F // "OSLO" -#define ROMC 0x524F4D43 // "ROMC" -#define DSIGIDENTIFIER 0x44534947 // "DSIG" -#define ENCKIDENTIFIER 0x454E434B // "ENCK" - -// WTP Format Recognized Reserved Area Indicator -#define WTPRESERVEDAREAID 0x4F505448 // "OPTH" - -// Reserved Area Package Headers -#define AUTOBIND 0x42494E44 // "BIND" -#define TERMINATORID 0x5465726D // "Term" -#define GPIOID 0x4750494F // "GPIO" -#define UARTID 0x55415254 // "UART" -#define USBID 0x00555342 // "USB" -#define RESUMEID 0x5265736D // "Resm" -#define USBVENDORREQ 0x56524551 // "VREQ" -#define TBR_XFER 0x54425258 // "TBRX" -#define RESUMEBLID 0x52736D32 // "Rsm2" -#define ESCAPESEQID 0x45534353 // "ESCS" -#define ESCSEQID_v2 0x45537632 // "ESv2" Escape Sequence Version 2 -#define OEMCUSTOMID 0x43555354 // "CUST" -#define NOMONITORID 0x4E4F4D43 // "NOMC" -#define COREID 0x434F5245 // "CORE" -#define BBMTID 0x42424D54 // "BBMT" -#define QNXBOOT 0x514E5850 // "QNXP" -#define GPP1ID 0x47505031 // "GPP1" Processed in RESERVEDAREA_State -#define GPP2ID 0x47505032 // "GPP2" Processed in XFER_State -#define ROMRESUMEID 0x52736D33 // "Rsm3" -#define PINID 0x50494E50 // "PINP" -#define IMAPID 0x494D4150 // "IMAP" - - -// DDR Related ID's -#define DDRID 0x44447248 // "DDrH" -#define DDRGID 0x44445247 // "DDRG" -#define DDRTID 0x44445254 // "DDRT" -#define DDRCID 0x44445243 // "DDRC" -#define CMCCID 0x434d4343 // "CMCC" - -// trust zone package -#define CIDPID 0x43494450 // "CIDP" -#define TZRI 0x545A5249 // ”TZRI?#endif - -// Operating mode related ID's -#define FREQID 0x46524551 // "FREQ" -#define VOLTID 0x564f4c54 // "VOLT" -#define OPMODEID 0x4d4f4445 // "MODE" -#define OPDIVID 0x4f504456 // "OPDV" -#define CLKEID 0x434c4b45 // "CLKE" - -// trust zone package -#define TZID 0x545A4944 // "TZID" -#define TZON 0x545A4f4E // "TZON" Register based - -#define FUNC 0x46554E43 // "FUNC" -#define PROI 0x50524F49 // "PROI" - -#define ERASID 0x45524153 //ERAS -#define SKIPID 0x534B4950 //SKIP -// USB -#define DESCRIPTOR_RES_ID 0x55534200 // "USB" -#define NUM_USB_DESCRIPTORS 10 -#define MAX_USB_STRINGS 7 - -#define NOFREQUENCYID 0x4E4F4643 // "NOFC" -#define NOKEYDETECTID 0x4E4F4B44 // "NOKD" - -#define TRFU 0x54524655 //TR069 control info. -#define DTYP 0x44545950 //DDR type -#define LTWS 0x4C545753 //LTG LWG SELECT PACKAGE -#define OTAI 0x4F544149 //FOTA Info -#define DDR_FLASH_MCP_MAP_PACKAGE_ID 0X44464D50 // "DFMP" -#define CITA_CUMIZED_INFO_TRANSFER_TOAP_ID 0X43495441 // "CITA" -#define BBMTYPEID 0x42424D54 // "BBMT" -#define FLASH_GEO_PKG_ID 0x46475049 // "FGPI" Flash Geometry Package ID -#define BBCS 0x42424353 //Bad block report switch -#define CRCS 0x43524353 //CRC switch - - -/*************************************************************************** -* -* New package for DDR auto adjust -- start -* -****************************************************************************/ - -#define DDRBYTESELECT 0x44444253 // "DDBS", ddr byte select -#define DDR_SAMSUNG_ID 0x49443031 // "ID01" -#define DDR_QIMONDA_ID 0x49443032 // "ID02" -#define DDR_ELPIDA_ID 0x49443033 // "ID03" -#define DDR_ETRON_ID 0x49443034 // "ID04" -#define DDR_NANYA_ID 0x49443035 // "ID05" -#define DDR_HYNIX_ID 0x49443036 // "ID06" -#define DDR_MOSEL_ID 0x49443037 // "ID07" -#define DDR_WINBOND_ID 0x49443038 // "ID08" -#define DDR_ESMT_ID 0x49443039 // "ID09" -#define DDR_RESERVED_ID 0x49443041 // "ID0A" -#define DDR_SPANSION_ID 0x49443042 // "ID0B" -#define DDR_SST_ID 0x49443043 // "ID0C" -#define DDR_ZMOS_ID 0x49443044 // "ID0D" -#define DDR_INTEL_ID 0x49443045 // "ID0E" -#define DDR_NUMONYX_ID 0x49443046 // "ID0F" -#define DDR_MICRON_ID 0x49443130 // "ID10" -#define DDR_TOSHIBA_ID 0x49443131 // "ID11" - - -typedef enum -{ - eUSB_DEVICE_DESCRIPTOR = (DESCRIPTOR_RES_ID | 0), - eUSB_CONFIG_DESCRIPTOR = (DESCRIPTOR_RES_ID | 1), - eUSB_INTERFACE_DESCRIPTOR = (DESCRIPTOR_RES_ID | 2), - eUSB_LANGUAGE_STRING_DESCRIPTOR = (DESCRIPTOR_RES_ID | 3), - eUSB_MANUFACTURER_STRING_DESCRIPTOR = (DESCRIPTOR_RES_ID | 4), - eUSB_PRODUCT_STRING_DESCRIPTOR = (DESCRIPTOR_RES_ID | 5), - eUSB_SERIAL_STRING_DESCRIPTOR = (DESCRIPTOR_RES_ID | 6), - eUSB_INTERFACE_STRING_DESCRIPTOR = (DESCRIPTOR_RES_ID | 7), - eUSB_DEFAULT_STRING_DESCRIPTOR = (DESCRIPTOR_RES_ID | 8), - eUSB_ENDPOINT_DESCRIPTOR = (DESCRIPTOR_RES_ID | 9) -} USB_DESCRIPTORS; - -typedef enum -{ - COREID_MP1 = 0, - COREID_MP2 = 1, - COREID_MM = 2 -} -COREID_T; - -typedef enum -{ - BBMT_TYPE_NO_BBM = 0, - BBMT_TYPE_LEGACY = 1, - BBMT_TYPE_MARVELL_FM_V1 = 2, - BBMT_TYPE_MARVELL_FM_V2 = 3 -} -BBMT_TYPE_T; -// Global Identifiers -#define FFIDENTIFIER 0x00004646 // "FF" -#define ALTIDENTIFIER 0x00414C54 // "ALT" -#define DIFFIDENTIFIER 0x44696666 // "Diff" -#define SEIDENTIFIER 0x00005345 // "SE" -#define U2DIDENTIFIER 0x55534232 // "USB2" -#define PINSIDENTIFIER 0x50696E73 // "Pins" -#define MDOCFORMATID 0x6d444f43 // "mDOC" -#define MDOCBINID 0x6d42944E // "mBIN" -#define MDOCBDTLID 0x6d424454 // "mBDT" -#define CI2IDENTIFIER 0x00434932 // "CI2" -#define OTGIDENTIFIER 0x554F5447 // "UOTG" -#define INVALIDID 0x21212121 // "!!!!" Should never appear in actual TIM file -#define PARTIONIDENTIFIER 0x50415254 // "PART" -// identifier for common tools Marvell Format image file -#define FBFIDENTIFIER 0x46424649 // "FBFI" Should never appear in actual TIM file - - -// Miscellanous -#define BINDKEYSIZE 128 // (MAXKEYSIZEWORDS * 2) -#define FLASHSIGMASK 0x0000000F // mask off the 4 bits of platform state - - - - -typedef enum INSTRUCTION_OP_CODE_SPEC_E -{ - // Enums specify the following: - INSTR_NOP = 0, - INSTR_WRITE = 1, - INSTR_READ = 2 , - INSTR_DELAY = 3, - INSTR_WAIT_FOR_BIT_SET = 4, - INSTR_WAIT_FOR_BIT_CLEAR = 5, - INSTR_AND_VAL = 6, - INSTR_OR_VAL = 7, - // new DDR Script instructions - INSTR_SET_BITFIELD = 8, - INSTR_WAIT_FOR_BIT_PATTERN = 9, - INSTR_TEST_IF_ZERO_AND_SET = 10, - INSTR_TEST_IF_NOT_ZERO_AND_SET = 11, - INSTR_LOAD_SM_ADDR = 12, - INSTR_LOAD_SM_VAL = 13, - INSTR_STORE_SM_ADDR = 14, - INSTR_MOV_SM_SM = 15, - INSTR_RSHIFT_SM_VAL = 16, - INSTR_LSHIFT_SM_VAL = 17, - INSTR_AND_SM_VAL = 18, - INSTR_OR_SM_VAL = 19, - INSTR_OR_SM_SM = 20, - INSTR_AND_SM_SM = 21, - INSTR_TEST_SM_IF_ZERO_AND_SET = 22, - INSTR_TEST_SM_IF_NOT_ZERO_AND_SET = 23, - // conditional execution branch and subroutine call instructions - INSTR_LABEL = 24, - INSTR_TEST_ADDR_AND_BRANCH = 25, - INSTR_TEST_SM_AND_BRANCH = 26, - INSTR_BRANCH = 27, - // Interpreter Directives - INSTR_END = 28, - //Add/Subtract - INSTR_ADD_SM_VAL = 29, - INSTR_ADD_SM_SM = 30, - INSTR_SUB_SM_VAL = 31, - INSTR_SUB_SM_SM = 32, - INSTR_LOAD_SM_FROM_ADDR_IN_SM = 33, - INSTR_STORE_SM_TO_ADDR_IN_SM = 34, - // New values go above here - INSTRUCTION_OP_CODE_E_MAX, - - // These enums identify pseudo op code that - // are used by tools for syntax shortcuts. The - // bootrom does not recognize the pseudo op - // code. When TBB is writing the TIM.bin, the pseudo - // op codes are converted to one or more instructions - // using the above INSTRUCTION_OP_CODE_SPEC_T enums. - - // pseudo instruction op codes used only by tools - // Enums specify the following: - INSTRUCTION_PSEUDO_OP_CODE_E_MIN = 10000, - - INSTR_PP_WRITE = 10001, - INSTR_PP_TABLEHEADER = 10002, - // New values go above here - INSTRUCTION_PSEUDO_OP_CODE_E_MAX, - -} INSTRUCTION_OP_CODE_SPEC_T; - - typedef struct -{ - unsigned int InstructionId; // InstructionID determines # of params for defined instructions - unsigned int Parameter; // first of the variable sized list of Parameters[ MAX_NUMBER_PARAMS = 3 ] -} INSTRUCTION_S, *pINSTRUCTION_S; - - - -typedef struct -{ - unsigned int OpId; - unsigned int OpValue; -} TZ_OPERATION, *pTZ_OPERATION; - -typedef enum TZ_OPERATION_SPEC_E -{ - TZ_NOP = 0, // Enums specify the following: - TZ_CONFIG_ENABLE, // TZ config enable flag (1 = configure) - // New values go above here - TZ_OPERATION_SPEC_E_MAX -} TZ_OPERATION_SPEC_T; - - - typedef enum DDR_OPERATION_SPEC_E -{ - DDR_NOP = 0, // Enums specify the following: - DDR_INIT_ENABLE, // DDR init flag (1 = init) - DDR_MEMTEST_ENABLE, // DDR Memtest flag (1 = test) - DDR_MEMTEST_START_ADDR, // Memtest start addr (Current default is 0) - DDR_MEMTEST_SIZE, // NumBytes to test (Current default is 2K) - DDR_INIT_LOOP_COUNT, // Loop Count for initialization attempts - DDR_IGNORE_INST_TO, // Treat a time out waiting for a bit to set/clear - // as informational only, operation continues - // New values go above here - DDR_OPERATION_SPEC_E_MAX -} DDR_OPERATION_SPEC_T; - -/********** WTP Recognized Reserved Area Layout ******************************** -* -* WTPTP_Defined_Reserved_Format_ID \ This clues BR, OBM and DKB that the reserved area is in a known format -* Number of Reserved Area Packages / For each package there is a header, payload size and payload -* -* Header \ Indicates what type of a Reserved Area Package -* Size \ Size Comprises a single Reserved Area Package -* Payload / There may be any number of Packages so long as TIM/NTIM < 4KB -* / -* -* Header \ The Last one should be a Package with a Terminator Header -* Size / The size should be 8 bytes (the size of this package) -* -**********************************************************************************/ -typedef struct -{ - UINT_T WTPTP_Reserved_Area_ID; // This clues BR, OBM and DKB that the reserved area is in a known format - UINT_T NumReservedHeaders; // For each package there is a header, payload size and payload -}WTP_RESERVED_AREA, *pWTP_RESERVED_AREA; - -typedef struct -{ - UINT_T Identifier; // Identification of this reserved area entry - UINT_T Size; // Size = Payload Size + 2 words (8 bytes). -}WTP_RESERVED_AREA_HEADER, *pWTP_RESERVED_AREA_HEADER; - -typedef struct -{ - WTP_RESERVED_AREA_HEADER WRAH; - UINT_T bmRequestType; - UINT_T bRequest; - UINT_T wValue; - UINT_T wIndex; - UINT_T wLength; - UINT_T wData; // First word of the proceeding Data. Note, there may be more traialing data -} USB_VENDOR_REQ, *pUSB_VENDOR_REQ; // There is no restriction that data need be 32 bit aligned. - -typedef struct -{ - volatile int *Addr; - UINT_T Value; -}GPIO_DEF, *pGPIO_DEF; -// General Purpose Patch (GPPx) related structures -typedef struct -{ - unsigned int OpId; - unsigned int OpValue; -} GPP_OPERATION, *pGPP_OPERATION; - -typedef enum GPP_OPERATION_SPEC_E -{ - GPP_NOP = 0, // Enums specify the following: - GPP_IGNORE_INST_TO = 6, // Treat a time out waiting for a bit to set/clear - // as informational only, operation continues - // New values go above here - GPP_OPERATION_SPEC_E_MAX -} GPP_OPERATION_SPEC_T; - -typedef struct -{ - WTP_RESERVED_AREA_HEADER WRAH; - unsigned int NumberOperations; - unsigned int NumberInstructions; - GPP_OPERATION GPP_Operations; // GPP_Op[NumberOperations]; - INSTRUCTION_S GPP_Instructions; // GPP_Instruction[NumberInstructions]; -} GPP_PACKAGE, *pGPP_PACKAGE; -// End General Purpose Patch related structures - - -#if 0 // requires general.h -typedef struct -{ - WTP_RESERVED_AREA_HEADER WRAH; - UINT_T XferLoc; //location to put the XFER table - UINT_T NumPairs; - XFER_DATA_PAIR_T pXferPairs[0]; -}}OPT_XFER_SET, *pOPT_XFER_SET; -#endif - -typedef struct -{ - WTP_RESERVED_AREA_HEADER WRAH; - UINT_T Port; - UINT_T Enabled; // 1 - Enabled -}OPT_PROTOCOL_SET, *pOPT_PROTCOL_SET; - -typedef struct -{ - WTP_RESERVED_AREA_HEADER WRAH; - UINT_T EscSeqTimeOutMS; // Value is interpreted in milli secs. -}OPT_ESCAPE_SEQUENCE, *P_OPT_ESCAPE_SEQUENCE; - - -typedef struct -{ - WTP_RESERVED_AREA_HEADER WRAH; - UINT_T Enable; // enable TR069 firmware upgrade or not - UINT_T FlashAddr; // flash address to store FBF header - UINT_T Magic; // Magic number of FBF header -}TR069_INFO, *pTR069_INFO; - -typedef struct -{ - WTP_RESERVED_AREA_HEADER WRAH; - UINT_T Type; -}DDR_Type, *pDDR_Type; - - -typedef struct -{ - UINT MFPR_address; - UINT MFPR_value; -} MFPR_PAIR_T, *pMFPR_PAIR_T; - -typedef struct -{ - WTP_RESERVED_AREA_HEADER WRAH; - UINT_T GPIO_number; //GPIO to check - UINT_T GPIO_trigger_val; //value of GPIO to trigger the escape sequence - UINT_T num_MFPR_pairs; //number of MFPR pairs contained in this package - MFPR_PAIR_T mfpr_pairs[1]; //MFPR address/value pairs: array will be of size 'num_MFPR_pairs" -} OPT_ESC_SEQ_v2, *P_OPT_ESC_SEQ_v2; - -typedef struct -{ - WTP_RESERVED_AREA_HEADER WRAH; - UINT_T NumGpios; - pGPIO_DEF GPIO; -}OPT_GPIO_SET, *pOPT_GPIO_SET; - -typedef struct -{ - UINT_T ResumeAddr; - UINT_T ResumeParam; - UINT_T ResumeFlag; -}OPT_RESUME_DDR_INFO, *pOPT_RESUME_DDR_INFO; - -typedef struct -{ - WTP_RESERVED_AREA_HEADER WRAH; - OPT_RESUME_DDR_INFO ResumeDDRInfo; -// pOPT_RESUME_DDR_INFO pResumeDDRInfo; -}OPT_RESUME_SET, *pOPT_RESUME_SET; - -typedef struct -{ - WTP_RESERVED_AREA_HEADER WRAH; - UINT_T ACCR_VALUE; - UINT_T MDCNFG_VALUE; - UINT_T DDR_HCAL_VALUE; - UINT_T MDREFR_VALUE; -}OPT_DDR_SET, *pOPT_DDR_SET; - -typedef struct -{ - WTP_RESERVED_AREA_HEADER WRAH; - UINT_T ImageAddr; -// UINT_T ImageSize; -// UINT_T ImageCRC; -}OPT_RESM_LOC, *pOPT_RESM_LOC; - -typedef struct -{ - WTP_RESERVED_AREA_HEADER WRAH; - UINT_T AutoBind; -}OPT_AUTOBIND, *pOPT_AUTOBIND; - -/**** Used only for backwards compatability!!! ***/ -typedef struct -{ - UINT_T Identifier; - UINT_T PortType; - UINT_T Port; - UINT_T GPIOPresent; - UINT_T NumGpios; - pGPIO_DEF GPIO; -}OPT_SET, *pOPT_SET; - -//mDOC general formatting parameters -// look in flstruct.h and flcommon.h -// for parameter definitions -// not spelled out here -//---------------------------------- -typedef struct -{ /* byte totals */ - WTP_RESERVED_AREA_HEADER WRAH; /*0x08 bytes */ - UINT_T percentUse; /*0x0C */ /* NAND flash inherently contains some bad blocks. TrueFFS handles - * those blocks by managing a pool of spare blocks also called transfer - * units. This format parameter specifies the percentage of the media - * to use. Starting from TrueFFS 6.3.0 alpha 4 this field is no longer a - * configurable formatting argument. You must set this field to - * TL_DEFAULT_PERCENTAGE = 0, letting TrueFFS to choose this value for you. */ - UINT_T noOfBDTLPartitions; /*0x10 */ /* Indicates the number of Disk partition (1 to 4). */ - UINT_T noOfBinaryPartitions; /*0x14 */ /* Indicates the number of binary partitions (up to 3). 0 will - * cause formatting with no binary partition. This value is ignored - * if TL_LEAVE_BINARY_AREA flag is set in the irFlags field the ioreq */ - UINT_T cascadedDeviceNo; /*0x18*/ /* Not used */ - UINT_T noOfCascadedDevices; /*0x1C*/ /* Not used */ - UINT_T progressCallback; /*0x20*/ /* Progress callback routine, will be called if not NULL. - The callback routine is called after erasing each unit, - and its parameters are the total number of erase units - to format and the number erased so far. - The callback routine returns a Status value. A value of - OK (0) allows formatting to continue. Any other value - will abort the formatting with the returned status code. */ - /* In case the FL_REPORT_MOUNT_PROGRESS compilation flag is set the - routine will also report the mount progress of the mount routine - for each of the Disk partitions. A 0,0 return values will report - the end of a format status and of a mount operation */ - UINT_T FP_0_RFU_0; /*0x24*/ /* Reserved 0 */ - UINT_T FP_1_RFU_0; /*0x28*/ /* Reserved 0 */ - - /* Note the following section is not used by for DiskOnChips */ - /*************************************************************/ - UINT_T bootImageLen; /*0x2C*/ /* Reserved 0 */ - UINT_T vmAddressingLimit; /*0x30*/ /* Reserved 0 */ - UINT_T embeddedCISlength; /*0x34*/ /* Reserved 0 */ - UINT_T *embeddedCIS; /*0x38*/ /* Reserved NULL */ -}MDOC_FORMAT_INFO, *pMDOCFORMAT_INFO; - -//mDOC BDTL partition type -//------------------------ -typedef struct -{ - WTP_RESERVED_AREA_HEADER WRAH; /*0x08 bytes */ - UINT_T length; /*0x0c */ /* The size in bytes of the usable storage space. The size - rounded upwards to a multiplication of a block size. - The size of the last partition will calculated automatically, - but if the requested size is greater then the remaining space - an error code will be returned,. Requesting zero size for any - partition but the last will generate an flBadParameters status. */ - - UINT_T fastAreaLength; /*0x10*/ - UINT_T lengthType; /*0x14*/ - UINT_T fastAreaLengthType; /*0x18*/ - UINT_T fastAreaVirtualFactor; /*0x1C*/ /* Should be set to FL_NORMAL_SPACING = 1 */ - UINT_T noOfSpareUnits; /*0x20*/ /* BDTL needs at least one spare erase unit in order to function - as a read/write media. It is possible to specify more than one - spare unit, which takes more media space. The advantage of - specifying more than one spare unit is that if one of the flash - erase units becomes bad and un-erasable in the future, then one - of the spare units can replace it. In that case, a second spare - unit enables TrueFFS to continue its read/write functionality, - whereas if no second spare unit is available the media goes into - read-only mode. The standard value used is 3 */ - - UINT_T BDTLFP_0_RFU_0; /*0x24*/ /* Reserved 0 */ - UINT_T BDTLFP_1_RFU_0; /*0x28*/ /* Reserved 0 */ - UINT_T BDTLFP_2_RFU_0; /*0x2C*/ /* Reserved 0 */ - UINT_T BDTLFP_3_RFU_0; /*0x30*/ /* Reserved 0 */ - UINT_T protectionKey[8]; /*0x50*/ /* The key for the protection*/ - UINT_T protectionType; /*0x54*/ /* PROTECTABLE - Can receive protection */ - /* READ_PROTECTED - Protect against read operations */ - /* WRITE_PROTECTED - Protect against write operations */ - /* LOCK_ENABLED - Enables the hardware lock signal */ - /* PROTECTABLE - This partition can be protected */ - /* CHANGEABLE_PROTECTION - protection type can be changed */ - /* The ratio between the real media size and the virtual size - reported to the file system when compression is active. */ - -}MDOC_BDTL_PARTITION, *pMDOC_BDTL_PARTITION; - -//mDOC binary partition type -//------------------------ -typedef struct -{ - WTP_RESERVED_AREA_HEADER WRAH; /*0x08 bytes */ - UINT_T length; /*0x0c*/ /* Required number of usable bytes (rounded to units) */ - /* in the partition. */ - - UINT_T lengthType; /*0x10*/ /* Must be FL_LENGTH_IN_BYTES = 0 */ - UINT_T sign[4]; /*0x20*/ /* signature of the binary partition to format. Typically "BIPO" - The signature 0xFFFF FFFF is not a valid signature */ - - UINT_T flags; /*0x24*/ /* TL_NORMAL_FORMAT=0 / TL_SPL_FORMAT=0xF0 */ - UINT_T spareBlocks; /*0x28*/ /* Spare blocks for DBB support, should be at least 1 */ - UINT_T BDKFP_0_RFU_0; /*0x2C*/ /* Reserved 0 */ - UINT_T BDKFP_1_RFU_0; /*0x30*/ /* Reserved 0 */ - UINT_T BDKFP_2_RFU_0; /*0x34*/ /* Reserved 0 */ - UINT_T BDKFP_3_RFU_0; /*0x38*/ /* Reserved 0 */ - UINT_T protectionKey[8]; /*0x58*/ /* The key for the protection*/ - UINT_T protectionType; /*0x5C*/ /* PROTECTABLE - Can receive protection */ - /* READ_PROTECTED - Protect against read operations */ - /* WRITE_PROTECTED - Protect against write operations */ - /* LOCK_ENABLED - Enables the hardware lock signal */ - /* PROTECTABLE - This partition can be protected */ - /* CHANGEABLE_PROTECTION - protection type can be changed */ -}MDOC_BINARY_PARTITION, *pMDOC_BINARY_PARTITION; - -/*********************************************************************************/ - -typedef enum -{ - PlatformVerificationKey, - NetworkOperatorCAKey, - SoftwareUpdateCAKey, - DRMDeviceCAKey, - OEMReservedKey1, - OEMReservedKey2, - NUMKEYMODULES -} -KEYMODULES_T; - -typedef enum -{ - Marvell_DS = 0, - PKCS1_v1_5_Caddo = 1, - PKCS1_v2_1_Caddo = 2, - PKCS1_v1_5_Ippcp = 3, - PKCS1_v2_1_Ippcp = 4, - ECDSA_256 = 5, - ECDSA_521 = 6 -} -ENCRYPTALGORITHMID_T; - -#define Intel_DS Marvell_DS - -typedef enum -{ - MRVL_SHA160 = 20, - MRVL_SHA256 = 32, - MRVL_SHA512 = 64 -} -HASHALGORITHMID_T; - -typedef struct -{ - UINT_T Version; - UINT_T Identifier; // "TIMH" - UINT_T Trusted; // 1- Trusted, 0 Non - UINT_T IssueDate; - UINT_T OEMUniqueID; -} VERSION_I, *pVERSION_I; // 0x10 bytes - -typedef struct -{ - UINT_T WTMFlashSign; - UINT_T WTMEntryAddr; - UINT_T WTMEntryAddrBack; - UINT_T WTMPatchSign; - UINT_T WTMPatchAddr; - UINT_T BootFlashSign; -} FLASH_I, *pFLASH_I; // 0x10 bytes - -typedef struct -{ - UINT_T KeyID; // Associate an ID with this key - UINT_T HashAlgorithmID; // See HASHALGORITHMID_T - UINT_T ModulusSize; // 1024 bit or 2048 bit keys - UINT_T PublicKeySize; - UINT_T RSAPublicExponent[MAXKEYSIZEWORDS]; // Contents depend on PublicKeySize - UINT_T RSAModulus[MAXKEYSIZEWORDS];// Up to 2K bits - UINT_T KeyHash[8]; // Reserve 256 bits for the hash -} KEY_MOD, *pKEY_MOD; // 0x22C bytes - -typedef struct -{ - UINT_T ImageID; // Indicate which Image - UINT_T NextImageID; // Indicate next image in the chain - UINT_T FlashEntryAddr; // Block numbers for NAND - UINT_T LoadAddr; - UINT_T ImageSize; - UINT_T ImageSizeToHash; - UINT_T HashAlgorithmID; // See HASHALGORITHMID_T - UINT_T Hash[8]; // Reserve 256 bits for the hash - UINT_T PartitionNumber; // This is new for V3.2.0 -} IMAGE_INFO_3_2_0, *pIMAGE_INFO_3_2_0; // 0x40 bytes - -typedef struct -{ - UINT_T ImageID; // Indicate which Image - UINT_T NextImageID; // Indicate next image in the chain - UINT_T FlashEntryAddr; // Block numbers for NAND - UINT_T LoadAddr; - UINT_T ImageSize; - UINT_T ImageSizeToHash; - UINT_T HashAlgorithmID; // See HASHALGORITHMID_T - UINT_T Hash[8]; // Reserve 256 bits for the hash -} IMAGE_INFO_3_1_0, *pIMAGE_INFO_3_1_0; // 0x3C bytes - -typedef struct -{ - UINT_T ImageID; // Indicate which Image - UINT_T NextImageID; // Indicate next image in the chain - UINT_T FlashEntryAddr; // Block numbers for NAND - UINT_T LoadAddr; - UINT_T ImageSize; - UINT_T ImageSizeToHash; - UINT_T HashAlgorithmID; // See HASHALGORITHMID_T - UINT_T Hash[16]; // Reserve 512 bits for the hash, this is new for V3.4.0 - UINT_T PartitionNumber; -} IMAGE_INFO_3_4_0, *pIMAGE_INFO_3_4_0; // 0x60 bytes - -typedef struct -{ - UINT_T ImageID; // Indicate which Image - UINT_T NextImageID; // Indicate next image in the chain - UINT_T FlashEntryAddr; // Block numbers for NAND - UINT_T LoadAddr; - UINT_T ImageSize; - UINT_T ImageSizeToHash; - HASHALGORITHMID_T HashAlgorithmID; // See HASHALGORITHMID_T - UINT_T Hash[16]; // Reserve 512 bits for the hash - UINT_T PartitionNumber; - ENCRYPTALGORITHMID_T EncAlgorithmID; // See ENCRYPTALGORITHMID_T - UINT_T EncryptStartOffset; - UINT_T EncryptSize; -} IMAGE_INFO_3_5_0, *pIMAGE_INFO_3_5_0; // 0x60 bytes - -typedef struct -{ - UINT_T KeyID; // Associate an ID with this key - UINT_T HashAlgorithmID; // 160 - SHA1, 256 - SHA2 - UINT_T KeySize; // Specified in bits - UINT_T PublicKeySize; // Specified in bits - UINT_T RSAPublicExponent[MAXRSAKEYSIZEWORDS]; // Contents depend on PublicKeySize - UINT_T RSAModulus[MAXRSAKEYSIZEWORDS]; // Up to 2K bits - UINT_T KeyHash[8]; // Reserve 256 bits for the hash -} KEY_MOD_3_1_0, *pKEY_MOD_3_1_0; // 0x22C bytes -typedef struct -{ - UINT_T KeyID; // Associate an ID with this key - HASHALGORITHMID_T HashAlgorithmID; // See HASHALGORITHMID_T - UINT_T KeySize; // Specified in bits - UINT_T PublicKeySize; // Specified in bits - UINT_T RSAPublicExponent[MAXRSAKEYSIZEWORDS]; // Contents depend on PublicKeySize - UINT_T RSAModulus[MAXRSAKEYSIZEWORDS]; // Up to 2K bits - UINT_T KeyHash[8]; // Reserve 256 bits for the hash -} KEY_MOD_3_2_0, *pKEY_MOD_3_2_0; // 0x22C bytes - -#if RVCT -#pragma anon_unions -#endif -typedef struct -{ - UINT_T KeyID; // Associate an ID with this key - HASHALGORITHMID_T HashAlgorithmID; // See HASHALGORITHMID_T - UINT_T KeySize; // Specified in bits - UINT_T PublicKeySize; // Specified in bits - ENCRYPTALGORITHMID_T EncryptAlgorithmID; // See ENCRYPTALGORITHMID_T; - union - { - struct - { - UINT_T RSAPublicExponent[MAXRSAKEYSIZEWORDS]; // Contents depend on PublicKeySize - UINT_T RSAModulus[MAXRSAKEYSIZEWORDS]; // Up to 2K bits - }Rsa; - - struct - { - UINT_T PublicKeyCompX[MAXECCKEYSIZEWORDS]; // Contents depend on PublicKeySize - UINT_T PublicKeyCompY[MAXECCKEYSIZEWORDS]; // Up to 521 bits - // Pad this struct so it remains consistent with RSA struct - UINT_T Reserved[(2*MAXRSAKEYSIZEWORDS)-(2*MAXECCKEYSIZEWORDS)]; - }Ecdsa; - }; - - UINT_T KeyHash[8]; // Reserve 256 bits for the hash -} KEY_MOD_3_3_0, *pKEY_MOD_3_3_0; // - - -// use EncryptedBitMask to access bit 31 of EncryptedAlgorithmID -// if bit 31 == 0 the access KEY_MOD_3_4_0 using the Rsa or Ecdsa structs -// if bit 31 == 1 the access KEY_MOD_3_4_0 using the EncryptedRsa or Encrypted Ecdsa structs -#define EncryptedBitMask 0x80000000 -typedef struct -{ - UINT_T KeyID; // Associate an ID with this key - HASHALGORITHMID_T HashAlgorithmID; // See HASHALGORITHMID_T - UINT_T KeySize; // Specified in bits - UINT_T PublicKeySize; // Specified in bits - ENCRYPTALGORITHMID_T EncryptAlgorithmID; // See ENCRYPTALGORITHMID_T; - union - { - struct - { - UINT_T RSAPublicExponent[MAXRSAKEYSIZEWORDS]; // Contents depend on PublicKeySize - UINT_T RSAModulus[MAXRSAKEYSIZEWORDS]; // Up to 2K bits - }Rsa; - - struct - { - UINT_T PublicKeyCompX[MAXECCKEYSIZEWORDS]; // Contents depend on PublicKeySize - UINT_T PublicKeyCompY[MAXECCKEYSIZEWORDS]; // Up to 521 bits - // Pad this struct so it remains consistent with RSA struct - UINT_T Reserved[(2*MAXRSAKEYSIZEWORDS)-(2*MAXECCKEYSIZEWORDS)]; - }Ecdsa; - - struct - { - UINT_T EncryptedHashRSAPublicExponent[MAXRSAKEYSIZEWORDS]; // Contents depend on PublicKeySize - UINT_T EncryptedHashRSAModulus[MAXRSAKEYSIZEWORDS]; // Up to 2K bits - }EncryptedRsa; - - struct - { - UINT_T EncryptedHashPublicKeyCompX_R[MAXECCKEYSIZEWORDS]; // Contents depend on PublicKeySize - UINT_T EncryptedHashPublicKeyCompX_S[MAXECCKEYSIZEWORDS]; // Contents depend on PublicKeySize - - UINT_T EncryptedHashPublicKeyCompY_R[MAXECCKEYSIZEWORDS]; // Up to 521 bits - UINT_T EncryptedHashPublicKeyCompY_S[MAXECCKEYSIZEWORDS]; // Up to 521 bits - - // Pad this struct so it remains consistent with encrypted RSA struct - UINT_T Reserved[(2 * MAXRSAKEYSIZEWORDS)-(4 * MAXECCKEYSIZEWORDS)]; - }EncryptedEcdsa; - }; - - UINT_T KeyHash[16]; // Reserve 512 bits for the hash -} KEY_MOD_3_4_0, *pKEY_MOD_3_4_0; // - - - -typedef struct -{ - ENCRYPTALGORITHMID_T DSAlgorithmID; // See ENCRYPTALGORITHMID_T - HASHALGORITHMID_T HashAlgorithmID; // See HASHALGORITHMID_T - UINT_T KeySize; // Specified in bits - UINT_T Hash[8]; // Reserve 256 bits for the hash - union // Note that this union should not be included as part of the hash for TIM in the Digital Signature - { - struct - { - UINT_T RSAPublicExponent[MAXRSAKEYSIZEWORDS]; - UINT_T RSAModulus[MAXRSAKEYSIZEWORDS]; // Up to 2K bits - UINT_T RSADigS[MAXRSAKEYSIZEWORDS]; // Contains TIM Hash - }Rsa; - struct - { - UINT_T ECDSAPublicKeyCompX[MAXECCKEYSIZEWORDS]; // Allow for 544 bits (17 words, 68 bytes for use with EC-521) - UINT_T ECDSAPublicKeyCompY[MAXECCKEYSIZEWORDS]; - UINT_T ECDSADigS_R[MAXECCKEYSIZEWORDS]; - UINT_T ECDSADigS_S[MAXECCKEYSIZEWORDS]; - UINT_T Reserved[(MAXRSAKEYSIZEWORDS*3)-(MAXECCKEYSIZEWORDS*4)]; - } Ecdsa; - }; -} PLAT_DS, *pPLAT_DS; // 0x780 bytes - -// Constant part of the TIMs -typedef struct -{ - VERSION_I VersionBind; // 0 - FLASH_I FlashInfo; // 0x10 - UINT_T NumImages; // 0x20 - UINT_T NumKeys; // 0x24 - UINT_T SizeOfReserved; // 0x28 -} CTIM, *pCTIM; // 0x2C - -// TIM structure for use by DKB/OBM/BootROM -/*typedef struct -{ - pCTIM pConsTIM; // Constant part - pIMAGE_INFO pImg; // Pointer to Images - pKEY_MOD pKey; // Pointer to Keys - PUINT pReserved; // Pointer to Reserved Area - pPLAT_DS pTBTIM_DS; // Pointer to Digital Signature -} -TIM, *pTIM;*/ - -// NTIM structure for use by DKB/OBM/BootROM -typedef struct -{ - pCTIM pConsTIM; // Constant part - pIMAGE_INFO_3_1_0 pImg; // Pointer to Images - PUINT pReserved; // Pointer to Reserved Area -} NTIM_3_1_0, *pNTIM_3_1_0; -typedef struct -{ - pCTIM pConsTIM; // Constant part - pIMAGE_INFO_3_2_0 pImg; // Pointer to Images - PUINT pReserved; // Pointer to Reserved Area -} NTIM_3_2_0, *pNTIM_3_2_0; -typedef struct -{ - pCTIM pConsTIM; // Constant part - pIMAGE_INFO_3_4_0 pImg; // Pointer to Images - PUINT pReserved; // Pointer to Reserved Area -} NTIM_3_4_0, *pNTIM_3_4_0; - - -// Defined for DTIM support 2012-3 - - - -typedef enum -{ - PRIMARYIMAGE = 0, // Primary image - RECOVERYIMAGE = 1, // Recovery image - CPIMAGE = 2 , // CP image - PPSETINGIMAG = 3, //PP Setting image - MARVELL_RESERVED_MAX = 9 , - CUSTMOZIEDIMAGE_TYPE1 = 10, - CUSTMOZIEDIMAGE_TYPE2 = 11, - CUSTMOZIEDIMAGE_TYPE3 = 12, - CUSTMOZIEDIMAGE_TYPE4 = 13, - CUSTMOZIEDIMAGE_TYPE5 = 14, - CUSTMOZIEDIMAGE_TYPE6 = 15, - CUSTMOZIEDIMAGE_TYPE7 = 16, - CUSTMOZIEDIMAGE_TYPE8 = 17, - CUSTMOZIEDIMAGE_TYPE9 = 18, - CUSTMOZIEDIMAGE_TYPE10 = 19, - CUSTMOZIEDIMAGE_TYPE11 = 20, - CUSTMOZIEDIMAGE_TYPE12 = 21, - CUSTMOZIEDIMAGE_TYPE13 = 22, - CUSTMOZIEDIMAGE_TYPE14 = 23, - CUSTMOZIEDIMAGE_TYPE15 = 24, - CUSTMOZIEDIMAGE_TYPE16 = 25, - CUSTMOZIEDIMAGE_TYPE17 = 26, - CUSTMOZIEDIMAGE_TYPE18 = 27, - CUSTMOZIEDIMAGE_TYPE19 = 28, - CUSTMOZIEDIMAGE_TYPE20 = 29, - CUSTMOZIEDIMAGE_TYPE_MAX = 50, -} OTA_IMAGE_TYPE; - -typedef struct -{ - UINT_T ImageID; // 0x54494Dxx - secondary tim ID (TIMx) - OTA_IMAGE_TYPE ImageType; // OTA_IMAGE_TYPE (Primary VS Recovery) - UINT_T FlashEntryAddr[2]; // Reserve 2 words for future compatibility - UINT_T PartitionNumber; // Partition # in the flash -} IMG_MAP_INFO, *pIMG_MAP_INFO; - -typedef struct -{ - WTP_RESERVED_AREA_HEADER WRAH; // Let it contain IMAP as package ID - UINT_T NumberOfMappedImages; // Number of images with mapping information - IMG_MAP_INFO pImgMapInfo[1]; // First image map information struct -} IMAGE_MAP, *pIMAGE_MAP; - - - -#endif - - - diff --git a/fbfdownloader/src/TimIncludedType.h b/fbfdownloader/src/TimIncludedType.h deleted file mode 100644 index d43343f87..000000000 --- a/fbfdownloader/src/TimIncludedType.h +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once - -typedef enum -{ - TIMH_NOTINC = 0, - TIMH_INC = 1, - DTIM_PRIMARY = 2, - DTIM_RECOVERY = 3, - DTIM_CP = 4, - TIMH_RECOVERYINC = 5, - DTIM_PPINFO = 6, - DTIM_CUSTMOZIEDTYPE1 = 10, - DTIM_CUSTMOZIEDTYPE2 = 11, - DTIM_CUSTMOZIEDTYPE3 = 12, - DTIM_CUSTMOZIEDTYPE4 = 13, - DTIM_CUSTMOZIEDTYPE5 = 14, - DTIM_CUSTMOZIEDTYPE6 = 15, - DTIM_CUSTMOZIEDTYPE7 = 16, - DTIM_CUSTMOZIEDTYPE8 = 17, - DTIM_CUSTMOZIEDTYPE9 = 18, - DTIM_CUSTMOZIEDTYPE10 = 19, - DTIM_CUSTMOZIEDTYPE11 = 20, - DTIM_CUSTMOZIEDTYPE12 = 21, - DTIM_CUSTMOZIEDTYPE13 = 22, - DTIM_CUSTMOZIEDTYPE14 = 23, - DTIM_CUSTMOZIEDTYPE15 = 24, - DTIM_CUSTMOZIEDTYPE16 = 25, - DTIM_CUSTMOZIEDTYPE17 = 26, - DTIM_CUSTMOZIEDTYPE18 = 27, - DTIM_CUSTMOZIEDTYPE19 = 28, - DTIM_CUSTMOZIEDTYPE20 = 29, - DKB_TIM = 100, - FBF_TIM = 101, - UNKOWN_TIMTYPE = 0xFF -} -TIMINCLUDEDTYPE_T; \ No newline at end of file diff --git a/fbfdownloader/src/Typedef.h b/fbfdownloader/src/Typedef.h deleted file mode 100644 index 616729cb5..000000000 --- a/fbfdownloader/src/Typedef.h +++ /dev/null @@ -1,110 +0,0 @@ -/****************************************************************************** - * - * (C)Copyright 2001-2009 Marvell. All Rights Reserved. - * - * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF MARVELL. - * The copyright notice above does not evidence any actual or intended - * publication of such source code. - * This Module contains Proprietary Information of Marvell and should be - * treated as Confidential. - * The information in this file is provided for the exclusive use of the - * licensees of Marvell. - * Such users have the right to use, modify, and incorporate this code into - * products for purposes authorized by the license agreement provided they - * include this notice and the associated copyright notice with any such - * product. - * The information in this file is provided "AS IS" without warranty. - * - ******************************************************************************/ - -#ifndef _TYPEDEF_H_ -#define _TYPEDEF_H_ - - -#include "Macrodef.h" - -typedef volatile unsigned long VUINT32_T; -typedef unsigned long UINT32_T; -typedef volatile unsigned int VUINT_T; -typedef unsigned int UINT_T; -typedef int INT_T; -typedef unsigned short UINT16_T, USHORT; -typedef volatile unsigned short VUINT16_T; -typedef unsigned char UINT8_T; -typedef char INT8_T; -typedef int BOOL; - - - -#ifdef LINUX -typedef unsigned long *PDWORD; -typedef unsigned char *PBYTE; -typedef unsigned int UINT, *PUINT; // The size is not important -typedef unsigned long long UINT64, *PUINT64; -typedef unsigned int UINT32, *PUINT32; -typedef unsigned short UINT16, *PUINT16; -typedef unsigned char UINT8, *PUINT8; -typedef unsigned char UCHAR,BYTE,*PUCHAR; -typedef unsigned long DWORD; -typedef BYTE* LPBYTE; - -typedef int INT, *PINT; // The size is not important -typedef long long INT64, *PINT64; -typedef int INT32, *PINT32; -typedef short INT16, *PINT16; -typedef signed char INT8, *PINT8; -#define VOID void -#define PVOID void* -#else -#include "stdafx.h" -#endif - - -#define LOCKED 1 -#define UNLOCKED 0 - - - -typedef void(*FnPVOID)(void); - - - - - -typedef volatile UINT VUINT, *PVUINT; // The size is not important -typedef volatile UINT64 VUINT64, *PVUINT64; -typedef volatile UINT32 VUINT32, *PVUINT32; -typedef volatile UINT16 VUINT16, *PVUINT16; -typedef volatile UINT8 VUINT8, *PVUINT8; -typedef volatile UCHAR VUCHAR, *PVUCHAR; - -typedef volatile INT VINT, *PVINT; // The size is not important -typedef volatile INT64 VINT64, *PVINT64; -typedef volatile INT32 VINT32, *PVINT32; -typedef volatile INT16 VINT16, *PVINT16; -typedef volatile INT8 VINT8, *PVINT8; -typedef volatile CHAR VCHAR, *PVCHAR; - -typedef struct{ - UINT_T ErrorCode; - UINT_T StatusCode; - UINT_T PCRCode; -}FUNC_STATUS, *pFUNC_STATUS; - -#ifdef LINUX -#ifdef _UNICODE -#define My_strcpy(a,b,c) wcscpy(a,c) -#else -#define My_strcpy(a,b,c) strcpy(a,c) -#endif -#else -#ifdef _UNICODE -#define My_strcpy(a,b,c) _tcscpy_s(a,b,c) -#else -#define My_strcpy(a,b,c) strcpy(a,c) -#endif -#endif// LINUX - - - -#endif //_TYPEDEF_H_ diff --git a/fbfdownloader/src/UploadParaDef.h b/fbfdownloader/src/UploadParaDef.h deleted file mode 100644 index a5a59652b..000000000 --- a/fbfdownloader/src/UploadParaDef.h +++ /dev/null @@ -1,62 +0,0 @@ -#pragma once -#include "Macrodef.h" - -#pragma pack(push,1) -typedef struct _UPLOAD_DATA_PARAMS -{ - BYTE Type; - BYTE SubType; - BYTE Partition; - BYTE Times;// Total Number of upload Areas - unsigned int Offset; - unsigned int DataSize; - BYTE IncludeSpareAreas; // indicate this upload include spare areas or not - BYTE ResetUE; - BYTE ResetTimeDelay; - BYTE Reserved2; // 用来存放DataSize的高32位,支持一次性upload大于4GB的内容 - -} UPLOAD_DATA_PARAMS; -static void NEW_UPLOAD_DATA_PARAMS(UPLOAD_DATA_PARAMS *me){me->Reserved2 = 0;} -static void COPY_UPLOAD_DATA_PARAMS(UPLOAD_DATA_PARAMS *me,UPLOAD_DATA_PARAMS* UpLoadDataPara) - { - me->Type = UpLoadDataPara->Type; - me->SubType = UpLoadDataPara->SubType; - me->Partition = UpLoadDataPara->Partition; - me->Times = UpLoadDataPara->Times; - me->Offset = UpLoadDataPara->Offset; - me->DataSize = UpLoadDataPara->DataSize; - me->IncludeSpareAreas = UpLoadDataPara->IncludeSpareAreas; // indicate this upload include spare areas or not - me->ResetUE = UpLoadDataPara->ResetUE; - me->ResetTimeDelay = UpLoadDataPara->ResetTimeDelay; - me->Reserved2 = UpLoadDataPara->Reserved2; - } -#pragma pack(pop) - - -#pragma pack(push,1) -typedef struct _UPLOAD_DATA_SPEC -{ - UPLOAD_DATA_PARAMS m_Params; - kstring_t strOutputFileName; - kstring_t strComparisonFileName; - BOOL bCreateNewFile; -} UPLOAD_DATA_SPEC,*pUPLOAD_DATA_SPEC; -static void NewUPLOAD_DATA_SPEC(pUPLOAD_DATA_SPEC me,struct _UPLOAD_DATA_SPEC* UpLoadDataSpec) - { - me->m_Params = UpLoadDataSpec->m_Params; - me->strOutputFileName = UpLoadDataSpec->strOutputFileName; - me->strComparisonFileName = UpLoadDataSpec->strComparisonFileName; - me->bCreateNewFile = UpLoadDataSpec->bCreateNewFile; - } -#pragma pack(pop) - - - -#define __uds_free(x) - -KLIST_INIT(pudsl,UPLOAD_DATA_SPEC*,__uds_free) - - - -typedef klist_t(pudsl)* t_UpLoadDataSpecList; -typedef kliter_t(pudsl)* t_UpLoadDataSpecIter; \ No newline at end of file diff --git a/fbfdownloader/src/WTPCOMMCLASS.c b/fbfdownloader/src/WTPCOMMCLASS.c deleted file mode 100644 index 78cc6e812..000000000 --- a/fbfdownloader/src/WTPCOMMCLASS.c +++ /dev/null @@ -1,1409 +0,0 @@ -// WTPCOMMCLASS.cpp: implementation of the CWtpComm class. -// -////////////////////////////////////////////////////////////////////// -#include "./Macrodef.h" -#include -#include "WTPCOMMCLASS.h" -#include -#include -#include -#include -#include "WTPIOCTL.h" - -#include "ErrorCode.h" -#include -#include - - -const short PACKET_SIZE = 16376; // plus command makes 4096 -#define OPEN_RETRY 10 -////////////////////////////////////////////////////////////////////// -// Construction/Destruction -////////////////////////////////////////////////////////////////////// - -void NewCWtpComm (struct CWtpComm *me) -{ - NewCConvertLT2B(&(me->MyConvertLT2B)); - me->m_PortType = UNKNOWNPORT; - me->m_iPortNumber = 1; - me->m_ThreadExit = 0; - me->m_liTimeout = 0; - me->m_bVerbose = FALSE; - me->m_bMsg = FALSE; - me->MessageMode = DISABLED; - me->m_bBaudRateSet = FALSE; - me->m_bInterfaceSpecified = FALSE; - me->m_hLog = NULL; - me->m_uiPacketSize = PACKET_SIZE; - me->m_bfastDownload = GET; - me->m_blastData = GET; - me->m_bIsNonNewWTPTP = FALSE; -#if DEBUG_MODE - me->m_bDebugTrace = TRUE; -#else - me->m_bDebugTrace = FALSE; -#endif - -} - - -void CWtpCommSetBootDeviceType(struct CWtpComm *me,EDeviceType eType) -{ - me->m_DeviceType = eType; -} - -void SetPlatformType(struct CWtpComm *me,ePlatForm ePlatformType) -{ - me->m_PlatformType = ePlatformType; -} - -void SetPortType (struct CWtpComm *me,int iSelect) -{ - switch (iSelect) - { - case USB: - me->m_PortType = USB; - break; - - case SERIALPORT: - me->m_PortType = SERIALPORT; - break; - - default: - me->m_PortType = UNKNOWNPORT; - break; - } -} - -int GetPortType (struct CWtpComm *me) -{ - return me->m_PortType; -} - -void SetInterfaceName (struct CWtpComm *me,TCHAR* pInterfaceName) -{ - _tcscpy( me->m_szInterfaceName, pInterfaceName ); - me->m_bInterfaceSpecified = TRUE; -} - - -void SetUsbPortTimeout (struct CWtpComm *me,long int lTimeout) -{ - me->m_liTimeout = lTimeout; -} - -void SetPacketSize(struct CWtpComm *me, unsigned short uiSize ) -{ - me->m_uiPacketSize = (((uiSize+63)/64) * 64)-8; -} - -unsigned short GetPacketSize(struct CWtpComm *me) -{ - return me->m_uiPacketSize; -} - - -void SetMessageMode (struct CWtpComm *me,MESSAGE_MODES MessageModeOnOff) -{ - me->MessageMode = MessageModeOnOff; -} - -void HandleTraceLog(struct CWtpComm *me,const TCHAR* format,...) -{ - if(me->m_bDebugTrace) - { - char szBuffer[1024]; - va_list pArgs; - va_start (pArgs, format); - vsprintf (szBuffer, format, pArgs); - va_end (pArgs); - printf(szBuffer); - fprintf(me->m_hLog, szBuffer); - } -} -BOOL SendPreamble (struct CWtpComm *me,BOOL bIsCustPreamble) -{ - BOOL IsOk = TRUE; - WTPSTATUS* pWtpStatus = (WTPSTATUS*)malloc(sizeof(WTPSTATUS)); - memset( pWtpStatus, 0, sizeof(WTPSTATUS) ); - me->m_iSequence = 0x00; - - HandleTraceLog(me,_T("SendPreamble command\n")); - - WTPCOMMAND WtpCmd = {PREAMBLE,0xD3,0x02,0x2B,htole32(0x00D3022B)}; - IsOk = WriteUSB(me,&WtpCmd,4); - if(IsOk) - { - if(!ReadUSB (me,pWtpStatus,4+34)) - { - IsOk = FALSE; - } - - if (pWtpStatus->CMD != PREAMBLE && pWtpStatus->SEQ != 0xD3 && pWtpStatus->CID != 0x02) - { - IsOk = FALSE; -#if PRINTLOG - printf("SendPreamble returned a wrong status\n"); -#endif - fprintf(me->m_hLog, "SendPreamble returned a wrong status\n"); - } - if (pWtpStatus->Status == NACK) - { - IsOk = FALSE; -#if PRINTLOG - printf("Error: SendPreamble returned a NACK!\n"); -#endif - fprintf(me->m_hLog,"Error: SendPreamble returned a NACK!\n"); - } - - - HandleTraceLog(me,"ReadUSB is ok in sending preamble...\n"); - - - } - free( pWtpStatus); - return IsOk; -} - -BOOL GetVersion (struct CWtpComm *me,WTPSTATUS *pWtpStatus) -{ - HandleTraceLog(me,_T("GetVersion command......\n")); - BOOL IsOk = TRUE; - me->m_iSequence = 0x00; - WTPCOMMAND WtpCmd = {GETVERSION,me->m_iSequence,0x00,0x00,htole32(0x00000000)}; - memset( pWtpStatus, 0, sizeof(WTPSTATUS) ); - pWtpStatus->Flags = 0x01; - HandlePendingMessages(me,pWtpStatus); - - HandleTraceLog(me,_T("WriteUSB in GetVersion command\n")); - IsOk = WriteUSB (me,&WtpCmd,8); - - if(IsOk) - { - IsOk = FALSE; - HandleTraceLog(me,_T("ReadUSB in GetVersion command\n")); - IsOk = ReadUSB(me,pWtpStatus,30); - if(!IsOk) - { - HandleTraceLog(me,_T("ReadUSB failed in GetVersion command\n")); - return FALSE; - } - if (IsOk && pWtpStatus->Status == NACK) - { - IsOk = FALSE; -#if PRINTLOG - printf("Error: GetVersion returned a NACK!\n"); -#endif - fprintf(me->m_hLog,"Error: GetVersion returned a NACK!\n"); - } - - } - else - { - HandleTraceLog(me,_T("WriteUSB failed in GetVersion command\n")); - return FALSE; - } - - HandleTraceLog(me,_T("GetVersion command return\n")); - return IsOk; -} - -BOOL GetBadBlockInfo(struct CWtpComm *me,WTPSTATUS *pWtpStatus) -{ - BOOL IsOk = TRUE; - me->m_iSequence = 0x00; - WTPCOMMAND WtpCmd = {GETBADBLOCK,me->m_iSequence,0x00,0x00,htole32(0x00000000)}; - - if (kBootLoader == me->m_DeviceType) - { - memset( pWtpStatus, 0, sizeof(WTPSTATUS) ); - pWtpStatus->Flags = 0x01; - - HandlePendingMessages(me, pWtpStatus ); - - HandleTraceLog(me,_T("WriteUSB in GetBadBlockInfo command\n")); - IsOk = WriteUSB (me,&WtpCmd,8); - - if(IsOk) - - { - IsOk = FALSE; - HandleTraceLog(me,_T("ReadUSB in GetBadBlockInfo command\n")); - IsOk = ReadUSB(me,pWtpStatus,6+sizeof(BadBlockData)); - if(!IsOk) - { - HandleTraceLog(me,_T("ReadUSB failed in GetBadBlockInfo command\n")); - return FALSE; - } - } - else - { - HandleTraceLog(me,_T("WriteUSB failed in GetBadBlockInfo command\n")); - return FALSE; - } - - if (pWtpStatus->Status == NACK) - { - IsOk = FALSE; -#if PRINTLOG - printf("Error: GetVersion returned a NACK!\n"); -#endif - - tfprintf(me->m_hLog,"Error: GetVersion returned a NACK!\n"); - } - - fflush(me->m_hLog); - } - return IsOk; -} - -BOOL GetImageCrc(struct CWtpComm *me,WTPSTATUS *pWtpStatus) -{ - BOOL IsOk = TRUE; - me->m_iSequence = 0x00; - WTPCOMMAND WtpCmd = {GETIMAGECRC,me->m_iSequence,0x00,0x00,htole32(0x00000000)}; - - if (kBootLoader == me->m_DeviceType) - { - memset( pWtpStatus, 0, sizeof(WTPSTATUS) ); - pWtpStatus->Flags = 0x01; - - HandlePendingMessages(me, pWtpStatus ); - - HandleTraceLog(me,_T("WriteUSB in GetImageCrc command\n")); - IsOk = WriteUSB (me,&WtpCmd,8); - - if(IsOk) - - { - IsOk = FALSE; - HandleTraceLog(me,_T("ReadUSB in GetImageCrc command\n")); - IsOk = ReadUSB(me,pWtpStatus,6+sizeof(ImageCRCInfo)); - if(!IsOk) - { - HandleTraceLog(me,_T("ReadUSB failed in GetImageCrc command\n")); - return FALSE; - } - } - else - { - HandleTraceLog(me,_T("WriteUSB failed in GetImageCrc command\n")); - return FALSE; - } - - if (pWtpStatus->Status == NACK) - { - IsOk = FALSE; - tfprintf(me->m_hLog,_T("Error: GetImageCrc returned a NACK!\n")); - } - - fflush(me->m_hLog); - } - return IsOk; -} - - -BOOL SelectImage (struct CWtpComm *me,UINT32 *pImageType) -{ - HandleTraceLog(me,_T("SelectImage command\n")); - WTPCOMMAND WtpCmd = {SELECTIMAGE,0x00,0x00,0x00,htole32(0x00000000)}; - WTPSTATUS* pWtpStatus = (WTPSTATUS*)malloc(sizeof(WTPSTATUS)); - memset( pWtpStatus, 0, sizeof(WTPSTATUS) ); - BOOL Isok = TRUE; - HandlePendingMessages(me, pWtpStatus ); - - if (WriteUSB (me,&WtpCmd,8) == FALSE) - Isok = FALSE; - if (Isok) - { - if(ReadUSB (me,pWtpStatus,10) == FALSE) - { - Isok = FALSE; - } - else - { - if (pWtpStatus->Status == NACK) - { - Isok = FALSE; -#if PRINTLOG - printf("Error: SelectImage returned a NACK!\n"); -#endif - fprintf(me->m_hLog,"Error: SelectImage returned a NACK!\n"); - } - if(me->m_bDebugTrace) - { - for(int i =0; i<4; i++) - tprintf(_T("pWtpStatus->Data[%d] =%c\n"),i,pWtpStatus->Data[i]); - } - *pImageType = pWtpStatus->Data[0]; - *pImageType |= pWtpStatus->Data[1] << 8; - *pImageType |= pWtpStatus->Data[2] << 16; - *pImageType |= pWtpStatus->Data[3] << 24; - - } - } - - HandlePendingMessages(me, pWtpStatus ); - free( pWtpStatus); - pWtpStatus = NULL; - - HandleTraceLog(me,_T("SelectImage command return\n")); - return Isok; -} - - -BOOL VerifyImage (struct CWtpComm *me,BYTE AckOrNack) -{ - HandleTraceLog(me,_T("VerifyImage command\n")); - - BOOL IsOk = TRUE, EnableMessages = TRUE; - me->m_iSequence = 0x00; - WTPCOMMAND WtpCmd = {VERIFYIMAGE,me->m_iSequence,0x00,0x00,htole32(0x00000001),AckOrNack}; - WTPSTATUS* pWtpStatus = (WTPSTATUS*)malloc(sizeof(WTPSTATUS)); - DWORD BytesRead = 0; - memset( pWtpStatus, 0, sizeof(WTPSTATUS) ); - //HandlePendingMessages( pWtpStatus ); - - if (WriteUSB (me,&WtpCmd,9) == FALSE) - IsOk = FALSE; - if(IsOk) - { - if (ReadUSB (me,pWtpStatus,6) == FALSE) - { - IsOk = FALSE; - } - } - - if (AckOrNack == NACK) - { - IsOk = FALSE; -#if PRINTLOG - printf(_T("\nError: Image asked for by target does not exist!")); -#endif - tfprintf (me->m_hLog,_T("\nError: Image asked for by target does not exist!")); - } - if (pWtpStatus->Status == NACK) - { - IsOk = FALSE; -#if PRINTLOG - printf(_T("\nError: VerifyImage returned a NACK!")); -#endif - tfprintf (me->m_hLog,_T("\nError: VerifyImage returned a NACK!")); - } - - HandlePendingMessages(me,pWtpStatus ); - free( pWtpStatus); - pWtpStatus = NULL; - - HandleTraceLog(me,_T("VerifyImage command return\n")); - return IsOk; -} - -BOOL DataHeader (struct CWtpComm *me,unsigned int uiRemainingData,WTPSTATUS *pWtpStatus,BOOL bFastDownload) -{ - HandleTraceLog(me,_T("DataHeader command\n")); - - BOOL IsOk = TRUE; - WTPCOMMAND WtpCmd = {DATAHEADER,++me->m_iSequence,0x00,0x00,htole32(4)}; - DWORD BytesRead = 0, StatusLength = 0; - /* Fix me please. getFastDownload is buggy*/ - if(me->m_bDebugTrace) - { - tfprintf (me->m_hLog,_T("\nDataHeader command, uiRemainingData size:%d\n"),uiRemainingData); - } - - //if (isFastDownload(GET, FDMODE)) - if (bFastDownload) - WtpCmd.Flags = 0x4; - - HandlePendingMessages(me, pWtpStatus ); - WtpCmd.Data[0] = uiRemainingData & 0x000000FF; - WtpCmd.Data[1] = (uiRemainingData & 0x0000FF00) >> 8; - WtpCmd.Data[2] = (uiRemainingData & 0x00FF0000) >> 16; - WtpCmd.Data[3] = (uiRemainingData & 0xFF000000) >> 24; - pWtpStatus->Status = ACK; - - if (WriteUSB (me,&WtpCmd,12) == FALSE) - IsOk = FALSE; - if(IsOk) - { - //make workaround for helan2 bootrom download,05/06/2014,llzhou - if(PLAT_HELAN2 == me->m_PlatformType) - { - usleep(20000); - } - - if (ReadUSB (me,pWtpStatus,10) == FALSE) - { - IsOk = FALSE; - } - else - { - if (pWtpStatus->Status == NACK) - { - IsOk = FALSE; -#if PRINTLOG - printf("Error: DataHeader returned a NACK!\n"); -#endif - fprintf(me->m_hLog,"Error: DataHeader returned a NACK!\n"); - } - if(me->m_bDebugTrace) - { - for(int i =0; i<4; i++) - tprintf(_T("pWtpStatus->Data[%d] =%d\n"),i,pWtpStatus->Data[i]); - } - - } - } - - HandlePendingMessages(me, pWtpStatus ); - - HandleTraceLog(me,_T("DataHeader command return\n")); - - return IsOk; -} - -BOOL Data (struct CWtpComm *me,PBYTE pData,UINT32 Length) -{ - HandleTraceLog(me,_T("Data command\n")); - - BOOL IsOk = TRUE; - WTPCOMMAND WtpCmd = {DATA,++me->m_iSequence,0x00,0x00,htole32(Length)}; - WTPSTATUS* pWtpStatus = (WTPSTATUS*)malloc(sizeof(WTPSTATUS)); - DWORD BytesRead = 0; - unsigned int tmp = 0; - BOOL bFoundChar = TRUE; - - memset( pWtpStatus, 0, sizeof(WTPSTATUS) ); - // HandlePendingMessages( pWtpStatus ); - if (isFastDownload (me,GET, FDMODE)) - { - HandleTraceLog(me,_T("Begin WriteUSBWithNoRsp\n")); - if (WriteUSBWithNoRsp (me,pData,(DWORD)Length) ) - { - HandleTraceLog(me,_T("Finish WriteUSBWithNoRsp\n")); - if (isLastData(me,GET, FDMODE)) - { - HandleTraceLog(me,_T("Begin ReadUSB\n")); - if(!ReadUSB (me,pWtpStatus,6)) - { - free( pWtpStatus); - return FALSE; - } - HandleTraceLog(me,_T("Finish ReadUSB\n")); - - if(pWtpStatus->CMD!=WtpCmd.CMD&&pWtpStatus->Status == NACK) - { - free( pWtpStatus); - return FALSE; - } - - if(me->m_bDebugTrace) - { - tprintf (_T("\nBytesRead : %lu GetWTPMESSAGE:%x %x %x %x %x %x \n"), - BytesRead, - pWtpStatus->CMD, - pWtpStatus->SEQ, - pWtpStatus->CID, - pWtpStatus->Status, - pWtpStatus->Flags, - pWtpStatus->DLEN); - } - - } - } - else - { - IsOk = FALSE; - } - - } - else - { - memcpy(WtpCmd.Data,pData,Length); - HandleTraceLog(me,_T("Begin WriteUSB\n")); - if (WriteUSB (me,&WtpCmd,8 + (DWORD)Length) == FALSE) - { - IsOk = FALSE; - } - else - { - HandleTraceLog(me,_T("Begin ReadUSB\n")); - if (ReadUSB (me,pWtpStatus,6) == FALSE) - { - IsOk = FALSE; - } - } - - } - - HandlePendingMessages(me, pWtpStatus ); - free( pWtpStatus); - pWtpStatus = NULL; - - HandleTraceLog(me,_T("Data command return\n")); - - return IsOk; - -} - -BOOL Done (struct CWtpComm *me) -{ - - HandleTraceLog(me,_T("Done command\n")); - - BOOL IsOk = TRUE, EnableMessages = TRUE; - me->m_iSequence = 0x00; - WTPCOMMAND WtpCmd = {DONE,me->m_iSequence,0x00,0x00,htole32(0x00000000)}; - WTPSTATUS* pWtpStatus = (WTPSTATUS*)malloc(sizeof(WTPSTATUS)); - DWORD BytesRead = 0; - - memset( pWtpStatus, 0, sizeof(WTPSTATUS) ); - pWtpStatus->Flags = 0x01; - HandlePendingMessages(me, pWtpStatus ); - if (WriteUSB (me,&WtpCmd,8) == FALSE) - IsOk = FALSE; - if (ReadUSB(me,pWtpStatus,6) == FALSE) - { - IsOk = FALSE; - } - else - { - if(pWtpStatus->CMD!=DONE) - { - if (WriteUSB (me,&WtpCmd,8) == FALSE) - IsOk = FALSE; - else - { - if (ReadUSB(me,pWtpStatus,6) == FALSE) - { - IsOk = FALSE; - } - // Sleep(100); - if (ReadUSB(me,pWtpStatus,6) == FALSE) - { - IsOk = FALSE; - } - - if(pWtpStatus->CMD!=DONE) - { - IsOk = FALSE; - } - - if (pWtpStatus->Status == NACK) - { - IsOk = FALSE; -#if PRINTLOG - printf ("Error: Done returned a NACK!"); -#endif - fprintf (me->m_hLog,"Error: Done returned a NACK!"); - } - } - - } - } - HandlePendingMessages(me, pWtpStatus ); - - free( pWtpStatus); - pWtpStatus = NULL; - - HandleTraceLog(me,_T("Done command return\n")); - - return IsOk; -} - -BOOL Disconnect (struct CWtpComm *me,WTPSTATUS* pWtpStatus) -{ - - BOOL IsOk = TRUE; - me->m_iSequence = 0x00; - WTPCOMMAND WtpCmd = {DISCONNECT,me->m_iSequence,0x00,0x00,htole32(0x00000000)}; - DWORD BytesRead; - HandlePendingMessages(me, pWtpStatus ); - - HandleTraceLog(me,_T("Disconnect command\n")); - - - if (!WriteUSB (me,&WtpCmd,8)) - { - IsOk = FALSE; - } - else - { - if (ReadUSB (me,pWtpStatus,6) == FALSE) - { - IsOk = FALSE; - } - if (pWtpStatus->Status == NACK) - { - //now try disconnect once more - pWtpStatus->Status = ACK; - - HandlePendingMessages(me, pWtpStatus ); - if (WriteUSB(me,&WtpCmd,8) == FALSE) - IsOk = FALSE; - if(IsOk) - { - if (ReadUSB(me,pWtpStatus,6) == FALSE) - { - IsOk = FALSE; - } - } - - } - } - HandlePendingMessages(me, pWtpStatus ); - - - if(IsOk == FALSE) - pWtpStatus->Status = NACK; - - - HandleTraceLog(me,_T("Disconnect command return\n")); - - return IsOk; - -} - - - -BOOL GetWtpMessage (struct CWtpComm *me,WTPSTATUS *pWtpStatus) -{ - //tfprintf (m_hLog,_T("\n GetWtpMessage..........\n")); - BOOL IsOk = TRUE, bFoundChar = TRUE; - me->m_iSequence = 0x00; - WTPCOMMAND WtpCmd = {MESSAGE,me->m_iSequence,0x00,0x00,htole32(0x00000000)}; - DWORD StatusLength, BytesRead; - TCHAR WtpMessage[MESSAGELENGTH]; - int i; - - memset (WtpMessage,'\0',MESSAGELENGTH); - - pWtpStatus->Status = NACK; - switch (me->m_PortType) - { - case USB: - { - if (!WriteUSB(me,&WtpCmd,8)) - { - IsOk = FALSE; - tfprintf (me->m_hLog,_T("\nWriteUsb failed in GetWtpMessage\n")); - } - else - { - if (pWtpStatus->DLEN > 0) - { - pWtpStatus->Status = ACK; - // IsOk = FALSE; - // return IsOk; - } - if (pWtpStatus->Status != ACK) - { - pWtpStatus->Status = NACK; - //IsOk = FALSE; - // return IsOk; - } - if (ReadUSB (me,pWtpStatus,6 + MESSAGELENGTH) == FALSE) - { - IsOk = FALSE; - } - else - { - switch(me->m_DeviceType) - { - case kBootLoader: - { - UINT32 ReturnCode = 0; - int i ; - for ( i = 0; i < 4; i++) - { - ReturnCode |= pWtpStatus->Data[i+2] << (8 * i); - } - if(pWtpStatus->Data[0]== WTPTPNOTIFICATION) - { - BOOL bFound = FALSE; - for (i = 0; i < MAXNOTIFICATIONSCODES; i++) - { - if (WTPTPNotificationMsg[i].NotificationCode == ReturnCode) - { -#ifndef COMPRESSDATA - tfprintf (me->m_hLog,_T("\nWTPTP Notification: %s 0x%X\n"),WTPTPNotificationMsg[i].Description,ReturnCode); -#else - tfprintf (me->m_hLog,_T("\nWTPTP Notification: 0x%X\n"),ReturnCode); -#endif - bFound = TRUE; - break;; - } - - } - if(!bFound) - { - tfprintf (me->m_hLog,_T("\nNotification Code: 0x%X\n"),ReturnCode); - } - } - else if(pWtpStatus->Data[0]== WTPTPERRORREPORT && kBootLoader == me->m_DeviceType) - { - TCHAR szMessage[1024]; - BOOL bFound = FALSE; - for (i = 0; i < MAXERRORCODES; i++) - { - if (WTPTPErrorCodes[i].ErrorCode == ReturnCode) - { - - - #ifndef COMPRESSDATA - tfprintf (me->m_hLog,_T("\nWTPTP Error: %s : Errorcode is 0x%X\n"),WTPTPErrorCodes[i].Description,ReturnCode); - #else - tfprintf (me->m_hLog,_T("\nWTPTP Errorcode is 0x%X\n"),ReturnCode); - #endif - bFound = TRUE; - break; - } - } - - if(!bFound) - { - - - tfprintf (me->m_hLog,_T("\nUser customized ErrorCode: 0x%X\n"),ReturnCode); - - - - } - - IsOk = FALSE; - - } - else if (WTPTPNOTIFICATION_UPLOAD == pWtpStatus->Data[0]) - { - tfprintf (me->m_hLog,_T("\nFlash_NandID: 0x%X\n"),ReturnCode); - } - else if (WTPTPNOTIFICATION_FLASHSIZE == pWtpStatus->Data[0]) - { - - tfprintf (me->m_hLog,_T("\nFlash_Size: 0x%X bytes\n"),ReturnCode); - } - } - break; - default: - break; - } - } - } - } - } - return IsOk; -} - -BOOL GetTargetMessage (struct CWtpComm *me,WTPSTATUS *pWtpStatus) -{ - - BOOL IsOk = TRUE; - unsigned long int Seconds = 0, DelayTime = 120; - - - while ( (pWtpStatus->Status == ACK) && Seconds m_hLog,_T("\n GetWtpMessage...\n")); - if (!GetWtpMessage (me,pWtpStatus)) - { - - IsOk = FALSE; - break; - } - - // This is to add a delay for WTPTP while DKB is busy on the target. - if (pWtpStatus->Data[0] == PlatformBusy && kBootLoader == me->m_DeviceType ) - { - do - { - GetWtpMessage(me,pWtpStatus); - - if ( pWtpStatus->Data[0] == PlatformDisconnect ) - break; - tfprintf (me->m_hLog,_T("\n usleep(2000000) in GetWtpMessage...\n")); - usleep(2000000); - Seconds += 2000; - - } - while(pWtpStatus->Data[0] != PlatformReady); - } - tfprintf (me->m_hLog,_T(" Platform ready status: %X\n"), pWtpStatus->Data[0]); - - if ( pWtpStatus->Data[0] == PlatformDisconnect ) - { - tfprintf (me->m_hLog,_T("Target requested disconnect!!!\n")); - return FALSE; - } - - - if ( pWtpStatus->Data[0] == PlatformReady && (pWtpStatus->Flags & 0x1) != MESSAGEPENDING) - { - break; - } - - } - - return IsOk; -} - - -int OpenUsbPort (struct CWtpComm *me) -{ - tfprintf(me->m_hLog,_T("\ntry to openUsbPort:%s....\n"),me->m_pLinuxUsb->DevName); - me->m_bXDB_BREAKPOINT_RETRY = TRUE; - _tcscpy(me->m_szDeviceName,me->m_pLinuxUsb->DevName); - int retry = 0; - system("echo ---begin open usb--- > /dev/kmsg"); -Retry: - retry++; - int retValue = BulkDevNonDrv_OpenDev(me->m_pLinuxUsb); - if(0 == retValue) - { -#if PRINTLOG - perror(_T("open")); -#endif - usleep(5000*100); - if(retrym_hLog,_T("\nopenUsbPort timeout\n")); - } - } - tfprintf(me->m_hLog,_T("\nopenUsbPort m_fdUsb = %s....\n"),me->m_pLinuxUsb->DevName); - return retValue; -} - - -BOOL CloseUsbPort(struct CWtpComm *me) -{ - //tfprintf(m_hLog,_T("\nCloseUsbPort....\n")); - if (me->m_pLinuxUsb->hDevHandle != 0) - BulkDevNonDrv_CloseDev(me->m_pLinuxUsb); -#if PRINTLOG - tprintf(_T("\nCloseUsbPort devName = %s....\n"),me->m_pLinuxUsb->DevName); -#endif - return TRUE; -} - - -void HandlePendingMessages(struct CWtpComm *me, WTPSTATUS *pWtpStatus ) -{ - // this is a bogus way to let the bootrom that uses a small packetsize - // have a little more time to process the command - - HandleTraceLog(me,_T("HandlePendingMessages CMD\n")); - - pWtpStatus->Status = ACK; - do - { - if ((pWtpStatus->Flags & 0x1 )== MESSAGEPENDING ) - { - GetTargetMessage (me,pWtpStatus); - HandleTraceLog(me,_T("HandlePendingMessages CMD\n")); - } - else - { - HandleTraceLog(me,_T("HandlePendingMessages break\n")); - break; - } - } - while( pWtpStatus->Status != ACK ); - - HandleTraceLog(me,_T("HandlePendingMessages return\n")); - -} - - -BOOL isFastDownload(struct CWtpComm *me,BOOL mode, BOOL value) //added to set/get the fast download mode. -{ - - if (mode) - me->m_bfastDownload = value; - else - return me->m_bfastDownload; - - return FDMODE; -} -BOOL isLastData(struct CWtpComm *me,BOOL mode, BOOL value) //added to set/get the last data condition. -{ - - if (mode) - me->m_blastData = value; - else - return me->m_blastData; - - return FDMODE; -} -BOOL WriteUSB(struct CWtpComm *me,WTPCOMMAND* pWtpCmd,size_t dwSize) -{ - HandleTraceLog(me,_T("WriteUSB\n")); - BOOL bRes = TRUE; - size_t dwBytes = -1; - int iMsgCnt = 0; - - if(me->m_ThreadExit==STOPFLAG) - { - tfprintf(me->m_hLog,_T("Thread is to be exit")); - return FALSE; - } - - if (me->m_pLinuxUsb->hDevHandle == -1) - { -#if PRINTLOG - tprintf(_T("\nError: device is not exist\n")); -#endif - return FALSE; - } -Retry: -#ifdef MACDOWNLOAD - int iVal = m_WtptpCommunicator.Write(pWtptpDev,pWtpCmd, dwSize); - if(iVal!=0) - { - fprintf(me->m_hLog, "Write USB failed\n"); - bRes = FALSE; - } -#else - dwBytes = BulkDevNonDrv_Write(me->m_pLinuxUsb,pWtpCmd,dwSize); - if(dwBytes<=0) - bRes = FALSE; -#endif - if (!bRes) - { - tfprintf(me->m_hLog,_T("\nError: write failed and return -1\n")); -#if PRINTLOG - printf(_T("\nError: write failed and return -1 iMsgCnt=%d\n"),iMsgCnt); -#endif - iMsgCnt++; - - usleep(200); - - if ( iMsgCnt == 10 ) - { -#if PRINTLOG - tprintf(_T("Error: Write failed with error %s.\n"),strerror(errno)); -#endif - return FALSE; - - } - - usleep(1000); - goto Retry; - } - else - { - HandleTraceLog(me,_T("WriteUSB dwBytes = %d\n"),dwBytes); - } - return bRes; -} - -BOOL WriteUSBWithNoRsp (struct CWtpComm *me,BYTE *pData,size_t dwSize) -{ - TCHAR Message[256] = {0}; - BOOL bRes = TRUE; - size_t dwBytes = -1; - int iMsgCnt = 0; - - if(me->m_ThreadExit==STOPFLAG) - { - tfprintf(me->m_hLog,_T("Thread is to be exit")); - return FALSE; - } - - if (me->m_pLinuxUsb->hDevHandle == -1) - { - sprintf (Message,_T(" Error: device is not exist!")); - tfprintf(me->m_hLog,_T("\n%s\n"),Message); - return FALSE; - } - - if(me->m_bDebugTrace) - { - sprintf (Message,_T("WriteUSBWithNoRsp dwSize is %d"),dwSize); - tfprintf(me->m_hLog,_T("\n%s\n"),Message); - tprintf(_T("\n%s\n"),Message); - } -Retry: - -#ifdef MACDOWNLOAD - int iVal = me->m_WtptpCommunicator.Write(pWtptpDev,pData, dwSize); - if(iVal!=0) - { - fprintf(me->m_hLog, "SelectImage Write USB failed\n"); - bRes = FALSE; - } -#else - dwBytes = BulkDevNonDrv_Write (me->m_pLinuxUsb,pData,dwSize); - if(dwBytes<=0) - bRes = FALSE; -#endif - - if (!bRes) - { - iMsgCnt++; - if(me->m_bDebugTrace) - { - tprintf(_T("Retry in WriteUSBWithNoRsp\n")); - } - if ( iMsgCnt == 20 ) - { -#ifdef PRINTLOG - tprintf(_T("Error: Write failed with error: %s,ErrorCode:%d.\n"),strerror(errno),errno); -#endif - fprintf(me->m_hLog,_T("Error: Write failed with error: %s,ErrorCode:%d.\n"),strerror(errno),errno); - - return FALSE; - - } - - usleep(1000); - goto Retry; - } - return bRes; -} - -BOOL ReadUSB (struct CWtpComm *me,WTPSTATUS *pWtpStatus,size_t dwSize) -{ - - BOOL bRes = TRUE; - size_t dwBytes = -1; - int iMsgCnt = 0; - - if(me->m_ThreadExit==STOPFLAG) - { - tfprintf(me->m_hLog,_T("Thread is to be exit")); - return FALSE; - } - if (me->m_pLinuxUsb->hDevHandle == -1) - { -#if PRINTLOG - tprintf (_T(" Error: device is not exist!\n")); -#endif - tfprintf(me->m_hLog,_T("\n Error: device is not exist!\n")); - return FALSE; - } - memset(pWtpStatus,0,sizeof(WTPSTATUS)); -Retry: - -#ifdef MACDOWNLOAD - int ival = me->m_WtptpCommunicator.Read(pWtptpDev,pWtpStatus, dwSize); - if(ival!=0) - { - fprintf(me->m_hLog, "Read USB failed\n"); - bRes = FALSE; - } -#else - dwBytes = BulkDevNonDrv_Read(me->m_pLinuxUsb,pWtpStatus,dwSize,0); - if(dwBytes<=0) - bRes = FALSE; -#endif - if (!bRes) - { - iMsgCnt++; - - HandleTraceLog(me,_T("Retry in ReadUSB\n")); - - if(iMsgCnt == 10 ) - { - tfprintf(me->m_hLog,_T("Error: ReadUSB failed with error %s.errno = %d\n"),strerror(errno),errno); -#if PRINTLOG - tprintf(_T("Error: ReadUSB failed with error %s.errno = %d\n"),strerror(errno),errno); -#endif - return FALSE; - } - - usleep(1000); - goto Retry; - } - else - { - //tfprintf(m_hLog,_T("\nReadUSB dwBytes = %d\n"),dwBytes); - TCHAR m_szMessage[256]; - sprintf (m_szMessage,_T("\nBytesRead : %d pWtpStatus:%x %x %x %x %x %x %x"), - dwBytes, - pWtpStatus->CMD, - pWtpStatus->SEQ, - pWtpStatus->CID, - pWtpStatus->Status, - pWtpStatus->Flags, - pWtpStatus->DLEN, - pWtpStatus->Data[0]); - - // tfprintf (m_hLog,_T("\nReadUSB message%s\n"),m_szMessage); - HandleTraceLog(me,_T("\nReadUSB message%s\n"),m_szMessage); - if (dwBytes<1) - { - iMsgCnt++; - - HandleTraceLog(me,_T("Retry in ReadUSB for read bytes is 0\n")); - - if(iMsgCnt == 10 ) - { -#if PRINTLOG - tprintf(_T("Error: ReadUSB failed for no data got.\n"),strerror(errno)); -#endif - return FALSE; - - } - - usleep(1000); - goto Retry; - } - } - - return bRes; -} -// features added to support upload 2010-12-28 -BOOL GetProtocolVersion (struct CWtpComm *me, PROTOCOL_VERSION* pTargetProtocolVersion ) -{ - WTPSTATUS WtpStatus = {0}; - BOOL IsOk = TRUE, EnableMessages = TRUE, bFoundChar = TRUE; - me->m_iSequence = 0x00; - WTPCOMMAND WtpCmd = {PROTOCOLVERSION,me->m_iSequence,0x00,0x00,htole32(0x00000000)}; - DWORD BytesRead = 0, StatusLength = 0; - - - //set to defaults - memset( &WtpStatus, 0, sizeof(WTPSTATUS) ); - HandlePendingMessages(me, &WtpStatus ); - - if(me->m_bDebugTrace) - { -#if PRINTLOG - tprintf(_T("GetProtocolVersion....\n")); -#endif - } - IsOk = WriteUSB (me,&WtpCmd,8); - - if(IsOk) - { - IsOk = FALSE; - IsOk = ReadUSB(me,&WtpStatus,6+sizeof(PROTOCOL_VERSION)); - - } - - if (WtpStatus.Status == NACK) - { - IsOk = FALSE; - tsprintf (me->m_szMessage,_T(" Error: GetProtocolVersion returned a NACK!")); - - } - else if (WtpStatus.Status == ACK) - { - if ( pTargetProtocolVersion ) - { - if ( WtpStatus.DLEN != sizeof(PROTOCOL_VERSION) ) - tfprintf(me->m_hLog,_T("nProtocolVersion returned LEN is not correct! LEN == %c\n"), WtpStatus.DLEN); - - memset( pTargetProtocolVersion, 0, sizeof(PROTOCOL_VERSION) ); - pTargetProtocolVersion->MajorVersion = WtpStatus.Data[0]; - pTargetProtocolVersion->MinorVersion = WtpStatus.Data[1]; - pTargetProtocolVersion->Build = Endian16ConvertLToB(&me->MyConvertLT2B,*((short*)&WtpStatus.Data[2])) ; - - tfprintf(me->m_hLog,_T("\nProtocolVersion: %d"), pTargetProtocolVersion->MajorVersion); - tfprintf(me->m_hLog,_T(".%d"), pTargetProtocolVersion->MinorVersion); - tfprintf(me->m_hLog,_T(".%d\n"), pTargetProtocolVersion->Build); - fflush(me->m_hLog); - if(me->m_bDebugTrace) - { - tprintf(_T("\nProtocolVersion: %d"), pTargetProtocolVersion->MajorVersion); - tprintf(_T(".%d"), pTargetProtocolVersion->MinorVersion); - tprintf(_T(".%d\n"), pTargetProtocolVersion->Build); - } - } - } - else - { - //Do nothing! - } - - HandlePendingMessages(me, &WtpStatus ); - - return IsOk; -} - - -BOOL GetParameters (struct CWtpComm *me, TARGET_PARAMS* pTargetParams ) -{ - WTPSTATUS WtpStatus = {0}; - BOOL IsOk = TRUE, EnableMessages = TRUE, bFoundChar = TRUE; - me->m_iSequence = 0x00; - WTPCOMMAND WtpCmd = {GETPARAMETERS,me->m_iSequence,0x00,0x00,htole32(0x00000000)}; - DWORD BytesRead = 0, StatusLength = 0; - - - HandlePendingMessages(me, &WtpStatus ); - if(me->m_bDebugTrace) - { - tprintf(_T("GetParameters....\n")); - } - if (!WriteUSB (me,&WtpCmd,8)) - { - IsOk = FALSE; - } - if(IsOk) - { - IsOk = FALSE; - IsOk = ReadUSB(me,&WtpStatus,6+sizeof(TARGET_PARAMS)); - - } - - if (WtpStatus.Status == NACK) - { - IsOk = FALSE; - tfprintf(me->m_hLog,_T(" Error: GetParameters returned a NACK!")); - fflush( me->m_hLog); - } - else if (WtpStatus.Status == ACK) - { - if ( WtpStatus.DLEN != 16 ) - { - tfprintf(me->m_hLog,_T("GetParameters returned LEN is not correct! LEN == %c\n"), WtpStatus.DLEN); - } - - - tfprintf(me->m_hLog, _T("\nBuffer Size: %d"), Endian32ConvertLToB(&me->MyConvertLT2B,*(unsigned int*)(&WtpStatus.Data[0]))); - tfprintf(me->m_hLog, _T("\nRsvd1: %d"), Endian32ConvertLToB(&me->MyConvertLT2B,*(unsigned int*)(&WtpStatus.Data[4]))); - tfprintf(me->m_hLog, _T("\nRsvd2: %d"), Endian32ConvertLToB(&me->MyConvertLT2B,*(unsigned int*)(&WtpStatus.Data[8]))); - tfprintf(me->m_hLog, _T("\nRsvd3: %d\n"), Endian32ConvertLToB(&me->MyConvertLT2B,*(unsigned int*)(&WtpStatus.Data[12]))); - fflush( me->m_hLog); - pTargetParams->BufferSize = Endian32ConvertLToB(&me->MyConvertLT2B,*(unsigned int*)(&WtpStatus.Data[0])); - pTargetParams->Rsvd1 = Endian32ConvertLToB(&me->MyConvertLT2B,*(unsigned int*)(&WtpStatus.Data[4])); - pTargetParams->Rsvd2 = Endian32ConvertLToB(&me->MyConvertLT2B,*(unsigned int*)(&WtpStatus.Data[8])); - pTargetParams->Rsvd3 = Endian32ConvertLToB(&me->MyConvertLT2B,*(unsigned int*)(&WtpStatus.Data[12])); - - if(me->m_bDebugTrace) - { - tprintf(_T("\nBuffer Size: %d"), Endian32ConvertLToB(&me->MyConvertLT2B,*(unsigned int*)(&WtpStatus.Data[0]))); - tprintf(_T("\nRsvd1: %d"), Endian32ConvertLToB(&me->MyConvertLT2B,*(unsigned int*)(&WtpStatus.Data[4]))); - tprintf(_T("\nRsvd2: %d"), Endian32ConvertLToB(&me->MyConvertLT2B,*(unsigned int*)(&WtpStatus.Data[8]))); - tprintf(_T("\nRsvd3: %d\n"), Endian32ConvertLToB(&me->MyConvertLT2B,*(unsigned int*)(&WtpStatus.Data[12]))); - } - } - else - { - //Do nothing! - } - - HandlePendingMessages(me, &WtpStatus ); - - return IsOk; - -} - - -BOOL UploadDataHeader (struct CWtpComm *me, UPLOAD_DATA_PARAMS* pUploadDataParams ) -{ - WTPSTATUS WtpStatus = {0}; - BOOL IsOk = TRUE, EnableMessages = TRUE, bFoundChar = TRUE; - me->m_iSequence = 0x00; - unsigned int i = 0; - WTPCOMMAND WtpCmd = {UPLOADDATAHEADER,me->m_iSequence,0x00,0x00,htole32(sizeof(UPLOAD_DATA_PARAMS))}; - DWORD BytesRead = 0, StatusLength = 0; - - // put upload parameters in - memcpy( WtpCmd.Data, pUploadDataParams, sizeof(UPLOAD_DATA_PARAMS) ); - - HandlePendingMessages(me, &WtpStatus ); - - if(me->m_bDebugTrace) - { - tprintf(_T("UploadDataHeader....\n")); - } - - if (!WriteUSB (me,&WtpCmd,8+sizeof(UPLOAD_DATA_PARAMS))) - { - IsOk = FALSE; - } - if(IsOk) - { - IsOk = FALSE; - IsOk = ReadUSB(me,&WtpStatus,6); - - } - - if (WtpStatus.Status == NACK) - { - IsOk = FALSE; - // tsprintf (m_szMessage,); - tfprintf(me->m_hLog, _T(" Error: UploadDataHeader returned a NACK!")); - if(WtpStatus.DLEN > 0) - { - tfprintf(me->m_hLog, _T("\nErrorCode in UploadData Header: %x\n"), Endian32ConvertLToB(&me->MyConvertLT2B,*(unsigned int*)&WtpStatus.Data[0])); -#if PRINTLOG - for (i = 0; i < MAXERRORCODES; i++) - { - if (WTPTPErrorCodes[i].ErrorCode == WtpStatus.Data[0]) - { -#ifndef COMPRESSDATA - tprintf(_T("Code: %s\n"), WTPTPErrorCodes[i].Description); -#endif - tprintf(_T("0x%x\n"), WtpStatus.Data[0]); - } - } -#endif - } - - } - fflush( me->m_hLog); - HandlePendingMessages(me, &WtpStatus ); - - return IsOk; -} - -BOOL UploadData(struct CWtpComm *me, PBYTE pData, unsigned int Length , WTPSTATUS* pWtpStatus) -{ - - BOOL IsOk = TRUE, EnableMessages = TRUE, bFoundChar = TRUE; - me->m_iSequence = 0x00; - WTPCOMMAND WtpCmd = {UPLOADDATA,me->m_iSequence,0x00,0x00,htole32(0x00000000)}; - DWORD StatusLength = Length; - - unsigned int i = 0; - - HandlePendingMessages(me, pWtpStatus ); - - if (!WriteUSBWithNoRsp (me,(PBYTE)&WtpCmd,8)) - { - IsOk = FALSE; - } - if(IsOk) - { - IsOk = FALSE; - IsOk = ReadUSB(me,pWtpStatus, 6+StatusLength); - - } - - if (pWtpStatus->Status == NACK) - { - IsOk = FALSE; - //tsprintf (m_szMessage,); - tfprintf(me->m_hLog,_T("Error: Data returned a NACK!")); - - } - else - { - // copy data back to data buffer - // exclude the 6 bytes used for the wtpstatus at the head of the packet - memcpy( pData, pWtpStatus->Data, StatusLength ); - HandlePendingMessages(me, pWtpStatus); - } - - fflush( me->m_hLog); - return IsOk; -} -void SetLogFile(struct CWtpComm *me,FILE *hLog) {me->m_hLog = hLog;} -FILE * GetLogFile(struct CWtpComm *me) {return me->m_hLog;} -void SetExitHandle(struct CWtpComm *me,int ThreadExit) {me->m_ThreadExit = ThreadExit;} -BOOL GetWTPTPFlag(struct CWtpComm *me){return me->m_bIsNonNewWTPTP;} -void SetWTPTPFlag(struct CWtpComm *me,BOOL IsNonNewWTPTP){me->m_bIsNonNewWTPTP = IsNonNewWTPTP;} -void SetLinuxDev(struct CWtpComm *me,USB_HANDLE* pLinuxDev) { me->m_pLinuxUsb = pLinuxDev;} -USB_HANDLE* GetLinuxDev(struct CWtpComm *me) { return me->m_pLinuxUsb ;} - diff --git a/fbfdownloader/src/WTPCOMMCLASS.h b/fbfdownloader/src/WTPCOMMCLASS.h deleted file mode 100644 index fe7469ad1..000000000 --- a/fbfdownloader/src/WTPCOMMCLASS.h +++ /dev/null @@ -1,113 +0,0 @@ -// WTPCOMMCLASS.h: interface for the CWtpComm class. -// -////////////////////////////////////////////////////////////////////// - -#if !defined(AFX_WTPCOMMCLASS_H__EFECE7AD_7863_476C_A5A5_65A1D728610A__INCLUDED_) -#define AFX_WTPCOMMCLASS_H__EFECE7AD_7863_476C_A5A5_65A1D728610A__INCLUDED_ - -#if _MSC_VER > 1000 -#pragma once -#endif // _MSC_VER > 1000 -#include -#include "define.h" -#include "WTPdef.h" -#include "ParaDefine.h" -#include "ConvetEdian.h" -#include "ApplicationINI.h" -#include "BulkDevNonDrv_Linux.h" - -static const PROTOCOL_VERSION TARGET_PROTOCOL_VERSION = {0x01, 0x01, 0x0000}; - -struct CWtpComm -{ - /*void GetCustomizePreambleCmd(pWTPTPREAMBLECOMMAND pCustCmd);*/ - struct CConvertLT2B MyConvertLT2B; - - - - - - USB_HANDLE * m_pLinuxUsb; - int m_PortType; - int m_iPortNumber; - BYTE m_iSequence; - size_t m_BytesWritten, m_BytesRead; - long int m_liTimeout; - TCHAR m_szMessage[1024]; - BOOL m_bVerbose; - BOOL m_bLogFile; - BOOL m_bMsg; - volatile int m_ThreadExit; - MESSAGE_MODES MessageMode; - BOOL m_bBaudRateSet; - TCHAR m_szInterfaceName[256]; - TCHAR m_szDeviceName[256]; - BOOL m_bInterfaceSpecified; - unsigned int m_uiPacketSize; - BOOL m_bXDB_BREAKPOINT_RETRY; - //pWTPTPREAMBLECOMMAND m_pCustPreambleCmd; - FILE *m_hLog; - BOOL m_bfastDownload ; - BOOL m_blastData ; - BOOL m_bIsNonNewWTPTP; - BOOL m_bDebugTrace; - EDeviceType m_DeviceType; - ePlatForm m_PlatformType; - -}; -void NewCWtpComm (struct CWtpComm *me); -void SetPortType (struct CWtpComm *me,int iSelect); -int GetPortType (struct CWtpComm *me); -void SetUsbPortTimeout (struct CWtpComm *me,long int lTimeout); -int OpenUsbPort (struct CWtpComm *me); -BOOL CloseUsbPort (struct CWtpComm *me); -BOOL SendPreamble (struct CWtpComm *me,BOOL bIsCustPreamble); -BOOL GetVersion (struct CWtpComm *me,WTPSTATUS *pWtpStatus); -BOOL GetBadBlockInfo(struct CWtpComm *me,WTPSTATUS *pWtpStatus); -BOOL GetImageCrc(struct CWtpComm *me,WTPSTATUS *pWtpStatus); -BOOL SelectImage (struct CWtpComm *me,UINT32 *pImageType); -BOOL VerifyImage (struct CWtpComm *me,BYTE AckOrNack); -BOOL DataHeader (struct CWtpComm *me,unsigned int uiRemainingData,WTPSTATUS *pWtpStatus, BOOL bFastDownload); -BOOL Data (struct CWtpComm *me,PBYTE pData,UINT32 Length); -BOOL DebugBoot (struct CWtpComm *me,PBYTE pFlashType); -BOOL Done (struct CWtpComm *me); -BOOL Disconnect (struct CWtpComm *me,WTPSTATUS *pWtpStatus); -BOOL PublicKey (struct CWtpComm *me); -BOOL Password (struct CWtpComm *me,WTPSTATUS *pWtpStatus); -BOOL SignedPassword (struct CWtpComm *me); -BOOL GetWtpMessage (struct CWtpComm *me,WTPSTATUS *pWtpStatus); -BOOL GetTargetMessage (struct CWtpComm *me,WTPSTATUS *pWtpStatus); -void SetFlashType (struct CWtpComm *me,BYTE FlashCode); -BYTE GetFlashType (struct CWtpComm *me); -BOOL OtpView (struct CWtpComm *me); -void SetLogFileMode (struct CWtpComm *me,BOOL bLogOnOff); -void SetInterfaceName (struct CWtpComm *me,TCHAR* pInterfaceName); -void SetMessageMode (struct CWtpComm *me,MESSAGE_MODES MessageModeOnOff); -BOOL WaitForHostReply (struct CWtpComm *me,WTPSTATUS *pWtpStatus,int nCharsRead,int nTotalChars); -void SetPacketSize(struct CWtpComm *me, unsigned short uiSize ); -unsigned short GetPacketSize(struct CWtpComm *me); -void SetLogFile(struct CWtpComm *me,FILE *hLog); -FILE * GetLogFile(struct CWtpComm *me); -int GetUSBPort(struct CWtpComm *me); -void SetExitHandle(struct CWtpComm *me,int ThreadExit); -BOOL GetWTPTPFlag(struct CWtpComm *me); -void SetWTPTPFlag(struct CWtpComm *me,BOOL IsNonNewWTPTP); -void HandlePendingMessages(struct CWtpComm *me,WTPSTATUS *pWtpStatus); -BOOL isLastData(struct CWtpComm *me,BOOL mode, BOOL value); //added to set/get the last data condition. -BOOL WriteUSB (struct CWtpComm *me,WTPCOMMAND* pWtpCmd,size_t dwSize); -BOOL WriteUSBWithNoRsp (struct CWtpComm *me,BYTE *pData,size_t dwSize); -BOOL ReadUSB (struct CWtpComm *me,WTPSTATUS *WtpStatus,size_t dwSize); -BOOL isFastDownload(struct CWtpComm *me,BOOL mode, BOOL value); -// features added to support upload -BOOL GetProtocolVersion (struct CWtpComm *me, PROTOCOL_VERSION* pTargetProtocolVersion ); -BOOL GetParameters (struct CWtpComm *me, TARGET_PARAMS* pTargetParams ); -BOOL UploadDataHeader (struct CWtpComm *me, UPLOAD_DATA_PARAMS* pUploadDataParams ); -BOOL UploadData(struct CWtpComm *me, PBYTE pData, unsigned int Length , WTPSTATUS* pWtpStatus); -BOOL HandleUploadDataPacket(struct CWtpComm *me, PBYTE pData, unsigned int Length ); -void HandleTraceLog(struct CWtpComm *me,const TCHAR* format,...); -void CWtpCommSetBootDeviceType(struct CWtpComm *me,EDeviceType eType); -void SetPlatformType(struct CWtpComm *me,ePlatForm ePlatformType); -void SetLinuxDev(struct CWtpComm *me,USB_HANDLE* pLinuxDev); -USB_HANDLE* GetLinuxDev(struct CWtpComm *me); - -#endif // !defined(AFX_WTPCOMMCLASS_H__EFECE7AD_7863_476C_A5A5_65A1D728610A__INCLUDED_) diff --git a/fbfdownloader/src/WTPIOCTL.h b/fbfdownloader/src/WTPIOCTL.h deleted file mode 100644 index 7411b340d..000000000 --- a/fbfdownloader/src/WTPIOCTL.h +++ /dev/null @@ -1,134 +0,0 @@ -/************************************************************************** -** -** (C) Copyright December 2006 Marvell International Ltd. -** -** All Rights Reserved. -** -** This software file (the "File") is distributed by Marvell International -** Ltd. under the terms of the GNU General Public License Version 2, June -** 1991 (the "License"). You may use, redistribute and/or modify this File -** in accordance with the terms and conditions of the License, a copy of -** which is available along with the File in the license.txt file or by -** writing to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, -** Boston, MA 02111-1307 or on the worldwide web at -** http://www.gnu.org/licenses/gpl.txt. -** -** THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE -** IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR -** PURPOSE ARE EXPRESSLY DISCLAIMED. The License provides additional -** details about this warranty disclaimer. -** -** FILENAME: WTPIOCTL.H -** -** PURPOSE: This contains the IoCtl code(s) and other external interfaces -** supported in BOOT. -** -** IMPORTANT NOTE: -** Because this header file includes the DEFINE_GUID declaration -** it should only be included in the WTPUSBLIB dll. This is -** because the GUID for the USB driver should only be advertised -** once to the operating system. -** -** Environment: -** Kernel mode only -** -******************************************************************************/ - -#pragma warning (disable : 4005) - -#ifndef WTPIOCTLDEF -#define WTPIOCTLDEF - -#define CTL_CODE(DeviceType, Function, Method, Access) ( ((DeviceType) << 16) | \ - ((Access) << 14) | \ - ((Function) << 2) | \ - (Method) ) - -#define FILE_ANY_ACCESS 0 -#define FILE_DEVICE_UNKNOWN 0x00000022 - -#define METHOD_BUFFERED 0 -#define METHOD_IN_DIRECT 1 -#define METHOD_OUT_DIRECT 2 -#define METHOD_NEITHER 3 - -#define BOOT_IOCTL_INDEX 0xDF0 // specific ioctls based from here. - -#define BOOT_IOCTL_METHOD_NEITHER(function) CTL_CODE(FILE_DEVICE_UNKNOWN, \ - (BOOT_IOCTL_INDEX + function), \ - METHOD_NEITHER, FILE_ANY_ACCESS) - -#define BOOT_IOCTL_METHOD_IN_DIRECT(function) CTL_CODE(FILE_DEVICE_UNKNOWN, \ - (BOOT_IOCTL_INDEX + function), \ - METHOD_IN_DIRECT, FILE_ANY_ACCESS) - -#define BOOT_IOCTL_METHOD_OUT_DIRECT(function) CTL_CODE(FILE_DEVICE_UNKNOWN, \ - (BOOT_IOCTL_INDEX + function), \ - METHOD_OUT_DIRECT, FILE_ANY_ACCESS) - -#define BOOT_IOCTL_METHOD_BUFFERED(function) CTL_CODE(FILE_DEVICE_UNKNOWN, \ - (BOOT_IOCTL_INDEX + function), \ - METHOD_BUFFERED, FILE_ANY_ACCESS) - -#define IOCTL_BOOT_PREAMBLE BOOT_IOCTL_METHOD_BUFFERED(9) -#define IOCTL_BOOT_GETVERSION BOOT_IOCTL_METHOD_BUFFERED(9) -#define IOCTL_BOOT_PUBLICKEYXMIT BOOT_IOCTL_METHOD_BUFFERED(9) -#define IOCTL_BOOT_SEEDPASSWORDRECEIVE BOOT_IOCTL_METHOD_BUFFERED(9) -#define IOCTL_BOOT_SIGNEDPASSWORDXMIT BOOT_IOCTL_METHOD_BUFFERED(9) -#define IOCTL_BOOT_SELECTIMAGE BOOT_IOCTL_METHOD_BUFFERED(9) -#define IOCTL_BOOT_JUMPADDRESS BOOT_IOCTL_METHOD_BUFFERED(9) -#define IOCTL_BOOT_IMAGEDATAXMIT BOOT_IOCTL_METHOD_BUFFERED(8) -#define IOCTL_BOOT_VERIFYIMAGE BOOT_IOCTL_METHOD_BUFFERED(9) -#define IOCTL_BOOT_DATAHEADER BOOT_IOCTL_METHOD_BUFFERED(9) -#define IOCTL_BOOT_OTPVIEW BOOT_IOCTL_METHOD_BUFFERED(9) -#define IOCTL_BOOT_DEBUGBOOT BOOT_IOCTL_METHOD_BUFFERED(9) -#define IOCTL_BOOT_DISCONNECT BOOT_IOCTL_METHOD_BUFFERED(9) -#define IOCTL_BOOT_DONE BOOT_IOCTL_METHOD_BUFFERED(9) -#define IOCTL_BOOT_MESSAGE BOOT_IOCTL_METHOD_BUFFERED(9) -#define IOCTL_BOOT_PROTOCOLVERSION BOOT_IOCTL_METHOD_BUFFERED(9) -#define IOCTL_BOOT_GETPARAMETERS BOOT_IOCTL_METHOD_BUFFERED(9) -#define IOCTL_BOOT_UPLOADDATAHEADER BOOT_IOCTL_METHOD_BUFFERED(9) -#define IOCTL_BOOT_UPLOADDATA BOOT_IOCTL_METHOD_BUFFERED(9) -#define IOCTL_BOOT_SEND BOOT_IOCTL_METHOD_BUFFERED(14) -#define IOCTL_BOOT_RECEIVE BOOT_IOCTL_METHOD_BUFFERED(15) - -typedef unsigned long ULONG; - -#pragma pack(push,1) - typedef struct _BOOTROM_COMMAND { - UCHAR Command; - UCHAR Sequence; - USHORT Length; - UCHAR Data[3996]; - } BOOTROM_COMMAND, *PBOOTROM_COMMAND; - - typedef struct _BOOTROM_PREAMBLE { - UCHAR Data[4]; - } BOOTROM_PREAMBLE, *PBOOTROM_PREAMBLE; - - typedef struct _BOOTROM_SENDPUBLICKEY { - UCHAR Command; - UCHAR Sequence; - USHORT Length; - ULONG KeyLength; // can be 16, 32, or 64. units is 4 byte words - UCHAR PublicKeyAndModulus[4 * 64 + 4 * 64]; // pub key & mod are same leng - // mod immediately follows actual pub key with no padding - } BOOTROM_SENDPUBLICKEY, *PBOOTROM_SENDPUBLICKEY; - - typedef struct _BOOTROM_SENDENCRYPTEDSIGNATURE { - UCHAR Command; - UCHAR Sequence; - USHORT Length; - UCHAR EncryptedSignature[4 * 64]; - } BOOTROM_SENDENCRYPTEDSIGNATURE, *PBOOTROM_SENDENCRYPTEDSIGNATURE; - - typedef union _BOOTROM_PACKET { - BOOTROM_PREAMBLE Preamble; - BOOTROM_COMMAND Command; - BOOTROM_SENDPUBLICKEY SendPublicKey; - BOOTROM_SENDENCRYPTEDSIGNATURE SendEncryptedSignature; - } BOOTROM_PACKET, *PBOOTROM_PACKET; -#pragma pack(pop) - - -#endif diff --git a/fbfdownloader/src/WTPdef.h b/fbfdownloader/src/WTPdef.h deleted file mode 100644 index ca19a48c5..000000000 --- a/fbfdownloader/src/WTPdef.h +++ /dev/null @@ -1,186 +0,0 @@ -/************************************************************************** -** -** (C) Copyright December 2006 Marvell International Ltd. -** -** All Rights Reserved. -** -** This software file (the "File") is distributed by Marvell International -** Ltd. under the terms of the GNU General Public License Version 2, June -** 1991 (the "License"). You may use, redistribute and/or modify this File -** in accordance with the terms and conditions of the License, a copy of -** which is available along with the File in the license.txt file or by -** writing to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, -** Boston, MA 02111-1307 or on the worldwide web at -** http://www.gnu.org/licenses/gpl.txt. -** -** THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE -** IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR -** PURPOSE ARE EXPRESSLY DISCLAIMED. The License provides additional -** details about this warranty disclaimer. -** -** FILENAME: WTPdef.h -** -** PURPOSE: Definition file for the WTPTP software tools.. -** -******************************************************************************/ - -#ifndef WTPDEF_H // Only make declarations once. -#define WTPDEF_H -#include "kstring.h" -#include "./Macrodef.h" - -#define DATALENGTH 0x4000 -//#define RETURNDATALENGTH 0x1FFA // Update for upload data size is 0x2000 -#define MESSAGELENGTH 256 - - -#ifndef __cplusplus - #define ISMSGPORT FALSE // Use this to enable port handshaking errors for debugging. -#endif - - - - -#define USB 0 -#define SERIALPORT 1 -#define UNKNOWNPORT -1 - -#define ACK 0 -#define NACK 1 -#define MESSAGEPENDING 1 -#define MESSAGESTRING 0 -#define MESSAGEERRORCODE 1 - -// Image ID definitions -#define TIMH 0x54494D48 -#define DKBI 0x444B4249 -#define OBMI 0x4F424D49 -#define FBFI 0x46424649 -#define FBFD 0x46424644 -#define PART 0x50415254 -#define TZII 0x545A4949 -#define WTMI 0x57544D49 - - -#define NOFASTDOWNLOAD 'N' //added for fast download proj--used to turn off fast download -#define GET 0 //added for fast download proj--flag for fast download. -#define SET 1 //added for fast download proj--flag for fast download. -#define FDMODE 1 //dummy/default value when getting the value for fast download. - -typedef enum -{ - DISABLED = 1, // Standard WTPTP download - MSG_ONLY = 2, //Turn on message mode(listen for msgs forever) - MSG_AND_DOWNLOAD = 3 //Msg mode and WTPTP download -} MESSAGE_MODES; - -struct stImageFile -{ - UINT32 nFileType; - const char* strImageFile; -}; -#define __stI_free(x) -KLIST_INIT(stifl,struct stImageFile,__stI_free) - -struct stImageFileByDDR -{ - klist_t(stifl) *ImageFileList; - kstring_t sDDRVendorID; - kstring_t sFlashInfo; -}; -static void New_stImageFileByDDR(struct stImageFileByDDR * me) -{ - me->ImageFileList = kl_init(stifl); -} -static void Del_stImageFileByDDR(struct stImageFileByDDR * me) -{ - if (me == NULL) return; - printf("kl_destroy(stifl, me->ImageFileList);\n"); - kl_destroy(stifl, me->ImageFileList); - free( me); -} - - -#define __stID_free(x) Del_stImageFileByDDR(kl_val(x)) - -KLIST_INIT(stifdl,struct stImageFileByDDR*,__stID_free) - -typedef klist_t(stifl)* t_ImageFileList; -typedef kliter_t(stifl)* t_ImageFileListIter; -typedef kliter_t(stifl)* t_ImageFileListConstIter; - -typedef klist_t(stifdl)* t_ImageFileByDDRList; -typedef kliter_t(stifdl)* t_ImageFileByDDRIter; - -// Protocol command definitions -#define PREAMBLE 0x00 -#define PUBLICKEY 0x24 -#define PASSWORD 0x28 -#define SIGNEDPASSWORD 0x25 -#define GETVERSION 0x20 -#define SELECTIMAGE 0x26 -#define VERIFYIMAGE 0x27 -#define DATAHEADER 0x2A -#define DATA 0x22 -#define MESSAGE 0x2B -#define OTPVIEW 0x2C -#define DEBUGBOOT 0x2D -#define IMEIBIND 0x2E -#define IMEIDATA 0x2F -#define DONE 0x30 -#define DISCONNECT 0x31 -#define UPLOADDATAHEADER 0x32 -#define UPLOADDATA 0x33 -#define PROTOCOLVERSION 0x34 -#define GETPARAMETERS 0x35 -#define GETBADBLOCK 0x37 -#define GETIMAGECRC 0x38 -#define UNKNOWNCOMMAND 0xFF - - -#define UPLOAD_WITH_SPAREAREA 1 -#define UPLOAD_WITHOUT_SPAREAREA 0 - - - -#pragma pack(push,1) -typedef struct -{ - BYTE CMD; - BYTE SEQ; - BYTE CID; - BYTE Flags; - UINT32 LEN; - BYTE Data[DATALENGTH]; -} WTPCOMMAND; - - -typedef struct -{ - BYTE CMD; - BYTE SEQ; - BYTE CID; - BYTE Status; - BYTE Flags; - BYTE DLEN; - BYTE Data[DATALENGTH]; -} WTPSTATUS; - -typedef struct -{ - BYTE MajorVersion; - BYTE MinorVersion; - short Build; -} PROTOCOL_VERSION; - -typedef struct -{ - unsigned int BufferSize; - unsigned int Rsvd1; - unsigned int Rsvd2; - unsigned int Rsvd3; -} TARGET_PARAMS; - -#pragma pack(pop) - -#endif diff --git a/fbfdownloader/src/WtptpDownLoad.c b/fbfdownloader/src/WtptpDownLoad.c deleted file mode 100644 index 1b8c7ee50..000000000 --- a/fbfdownloader/src/WtptpDownLoad.c +++ /dev/null @@ -1,21 +0,0 @@ - -#include "WtptpDownLoad.h" -#include "WtptpDownloader.h" - -struct CWtptpDownLoad gWtptpDownload; -BOOL InitializeBL(PInstanceParams pInstParam) -{ - return WtptpDownLoad_InitializeBL(&gWtptpDownload,pInstParam); - -} -#if 0 -BOOL InitializeBLEx(PInstanceParams pInstParam,const TCHAR* pszBlfFile,const TCHAR* pszFBFTimfile, const TCHAR* pszFBFFile) -{ - return WtptpDownLoad_InitializeBLEx(&gWtptpDownload,pInstParam,pszBlfFile,pszFBFTimfile,pszFBFFile); - -} -#endif -BOOL TerminateBL() -{ - return WtptpDownLoad_TerminateBL(&gWtptpDownload); -} diff --git a/fbfdownloader/src/WtptpDownLoad.h b/fbfdownloader/src/WtptpDownLoad.h deleted file mode 100644 index 0d200e92f..000000000 --- a/fbfdownloader/src/WtptpDownLoad.h +++ /dev/null @@ -1,7 +0,0 @@ -#include "ParaDefine.h" -extern struct CWtptpDownLoad gWtptpDownload; - - -BOOL InitializeBL(PInstanceParams pInstParam); -//BOOL InitializeBLEx(PInstanceParams pInstParam,const TCHAR* pszBlfFile,const TCHAR* pszFBFTimfile, const TCHAR* pszFBFFile); -BOOL TerminateBL(); diff --git a/fbfdownloader/src/WtptpDownloader.c b/fbfdownloader/src/WtptpDownloader.c deleted file mode 100644 index efc93bd9a..000000000 --- a/fbfdownloader/src/WtptpDownloader.c +++ /dev/null @@ -1,3386 +0,0 @@ -// WtptpDownLoad.cpp : Defines the entry point for the DLL application. -// - -#include "Macrodef.h" -#ifdef PCIEDOWNLOAD -#include "Parser.h" -#ifdef LS_PCIEDOWNLOAD -#include "asm/types.h" //for lightsurfuring -#endif -#endif -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "ErrorCode.h" -#include "WtptpDownloader.h" -#include "WTPCOMMCLASS.h" -#include "Tim.h" -//#include "listdefine.h" -#include "Typedef.h" -#include "WTPdef.h" -#include "ParaDefine.h" -#include "CommonFun.h" - -/****************************************************/ -#define UEVENT_BUFFER_SIZE 2048 -#define UNIT_GB 0X40000000 -static BOOL isFastDownloadSwtchSet = 1; - -struct CBinFileWtp gBinFileWtp; - -char g_LogPath[255] = {0}; - - -const struct stFlatformBootLoaderInfo gstFlatformBLInfoSet[] = { - {PLAT_ULC2, ULC2_BOOTLOADER_DATE, ULC2_BOOTLOADER_PROCESSOR, ULC2_BOOTLOADER_VERSION}, - {PLAT_HELAN4, HELAN4_BOOTLOADER_DATE, HELAN4_BOOTLOADER_PROCESSOR, HELAN4_BOOTLOADER_VERSION}, - {PLAT_HELAN3, HELAN3_BOOTLOADER_DATE, HELAN3_BOOTLOADER_PROCESSOR, HELAN3_BOOTLOADER_VERSION}, - {PLAT_ULC1, ULC1_BOOTLOADER_DATE, ULC1_BOOTLOADER_PROCESSOR, ULC1_BOOTLOADER_VERSION}, - {PLAT_NEZHA3, NEZHA3_BOOTLOADER_DATE, NEZHA3_BOOTLOADER_PROCESSOR, NEZHA3_BOOTLOADER_VERSION}, - {PLAT_EDEN_A0, EDENA0_BOOTLOADER_DATE, EDENA0_BOOTLOADER_PROCESSOR, EDENA0_BOOTLOADER_VERSION}, - {PLAT_HELAN2, HELAN2_BOOTLOADER_DATE, HELAN2_BOOTLOADER_PROCESSOR, HELAN2_BOOTLOADER_VERSION}, - /*{PLAT_NEZHA2, NEZHA2_BOOTLOADER_DATE, NEZHA2_BOOTLOADER_PROCESSOR, NEZHA2_BOOTLOADER_VERSION},*/ - {PLAT_EDEN, EDEN_BOOTLOADER_DATE, EDEN_BOOTLOADER_PROCESSOR, EDEN_BOOTLOADER_VERSION}, - {PLAT_HELANLTE, HELAN_BOOTLOADER_DATE, HELAN_BOOTLOADER_PROCESSOR, HELAN_BOOTLOADER_VERSION}, - {PLAT_HELAN, HELAN_BOOTLOADER_DATE, HELAN_BOOTLOADER_PROCESSOR, HELAN_BOOTLOADER_VERSION}, - {PLAT_EMEI, EMEI_BOOTLOADER_DATE, EMEI_BOOTLOADER_PROCESSOR, EMEI_BOOTLOADER_VERSION}, - {PLAT_NEVO_OTA, NEVO_BOOTLOADER_DATE, NEVO_BOOTLOADER_PROCESSOR, NEVO_BOOTLOADER_VERSION}, - {PLAT_NEVO, NEVO_BOOTLOADER_DATE, NEVO_BOOTLOADER_PROCESSOR, NEVO_BOOTLOADER_VERSION}, - {PLAT_MMP3, MMP3_BOOTLOADER_DATE, MMP3_BOOTLOADER_PROCESSOR, MMP3_BOOTLOADER_VERSION}, - {PLAT_PXA92x, PXA92X_BOOTLOADER_DATE, PXA92X_BOOTLOADER_PROCESSOR, PXA92X_BOOTLOADER_VERSION}, - {PLAT_MMP2, MMP2_BOOTLOADER_DATE, MMP2_BOOTLOADER_PROCESSOR, MMP2_BOOTLOADER_VERSION}, - {PLAT_WUKONG, WKNG_BOOTLOADER_DATE, WKNG_BOOTLOADER_PROCESSOR, WKNG_BOOTLOADER_VERSION} -}; - -void NewCWtptpDownLoad (struct CWtptpDownLoad *me) -{ - NewCConvertLT2B(&me->MyConvertLT2B); - me->m_nBurningSpeed = 0; - me->m_bTerminateDownload = FALSE; - if (me->m_WtptpDeviceList) - kl_destroy(pdevl, me->m_WtptpDeviceList); - me->m_WtptpDeviceList = kl_init(pdevl); -#if DEBUG_MODE - me->m_bDebugTrace = TRUE; -#else - me->m_bDebugTrace = FALSE; -#endif - if (me->m_DisplayInfoList) - kl_destroy(pdisl, me->m_DisplayInfoList); - me->m_DisplayInfoList = kl_init(pdisl); - if (me->m_lBootRomImageWithDDRList) - kl_destroy(stifdl,me->m_lBootRomImageWithDDRList); - me->m_lBootRomImageWithDDRList = kl_init(stifdl); - if (me->m_lBootLoaderImageWithDDRList) - kl_destroy(stifdl, me->m_lBootLoaderImageWithDDRList); - me->m_lBootLoaderImageWithDDRList = kl_init(stifdl); - if (me->m_lJtagEnabledImageWithDDRList) - kl_destroy(stifdl, me->m_lJtagEnabledImageWithDDRList); - me->m_lJtagEnabledImageWithDDRList = kl_init(stifdl); - me->m_bOnlyOBMDownload = FALSE; - me->m_bTerminateUSBDetect = FALSE; - me->m_bSingleDownload = FALSE; - me->m_bIsLittleEndian = FALSE; - me->m_uTotalDDRTypeNum = 0; - me->m_uTotalFlashTypeNum = 0; - IsLittleEndian(&me->MyConvertLT2B); - -} -void DelCWtptpDownLoad (struct CWtptpDownLoad *me) -{ - printf("DelCWtptpDownLoad\n"); - for(t_DisplayInfoIter iter = kl_begin(me->m_DisplayInfoList); iter!=kl_end(me->m_DisplayInfoList); iter = kl_next(iter)) - { - free( kl_val(iter)); - } - kl_destroy(pdisl,me->m_DisplayInfoList); - kl_destroy(pdevl, me->m_WtptpDeviceList); - kl_destroy(stifdl,me->m_lBootRomImageWithDDRList); - kl_destroy(stifdl,me->m_lBootLoaderImageWithDDRList); - kl_destroy(stifdl,me->m_lJtagEnabledImageWithDDRList); - - /*for(t_DeviceIter iter = m_WtptpDeviceList.begin(); iter != m_WtptpDeviceList.end(); ++iter) - { - delete (*iter)->pWtpComm; - delete *iter; - } - m_WtptpDeviceList.clear();*/ - pthread_mutex_destroy(&me->DeviceList_mutex); - pthread_mutex_destroy(&me->Quit_mutex); - pthread_mutex_destroy(&me->callback_mutex); -} - - -BOOL WtptpDownLoad_RemoveEntryList(struct CWtptpDownLoad *me,PDEVICE pDev) -{ - t_DeviceIter iter; - for( t_DeviceIter iter = kl_begin(me->m_WtptpDeviceList); iter != kl_end(me->m_WtptpDeviceList); iter = kl_next(iter)) - { - if(pDev==kl_val(iter)) - { - CloseUsbPort(pDev->pWtpComm); - kl_erase(pdevl, me->m_WtptpDeviceList, &iter); - if (pDev->pWtpComm != NULL) - { - free( pDev->pWtpComm); - pDev->pWtpComm = NULL; - } - if (pDev != NULL) - { - free( pDev); - pDev = NULL; - } - break; - } - } - return TRUE; -} - -PVOID WtptpDownLoad_BootRomIOThread(PVOID Arg) -{ - - BOOL bSuccess = FALSE; - PDOWNLOADTARGET pTarget = (PDOWNLOADTARGET)Arg; - PDEVICE pDev = pTarget->pDev ; - - tfprintf (pDev->hLog,_T("\nEnter BootRomIOThread\n")); - static int ActiveBootRomDev; - - BOOL bReport = TRUE; - - tfprintf (pDev->hLog,_T("\nEnter BootRom Thread\n")); - fflush(pDev->hLog); - bSuccess = WtptpDownLoad_WTPTPDownLoad(pTarget->pWtptpDownload,pDev); - - - if (bSuccess) - { - tfprintf (pDev->hLog,_T("\nDownLoad Images to BootRom Completed\n")); - } - else - { - pDev->kProState =kProcAborting; - WtptpDownLoad_AddDisplayInfoDevice(pTarget->pWtptpDownload,pDev); - WtptpDownLoad_Report(pTarget->pWtptpDownload); - tfprintf (pDev->hLog,_T("\nAbnormal Termination in BootRom\n")); - tprintf(_T("Download failed in BootRom thread\n")); - } - - tfprintf (pDev->hLog,_T("\nExit BootRom Thread\n")); - fflush(pDev->hLog); - - if (pDev->hLog != NULL ) - { - fclose (pDev->hLog); - pDev->hLog = NULL; - } - - for(int i =0; ipWtptpDownload->m_nBootRomDevNum%32; i++) - { - if(pDev->ThreadId == pTarget->pWtptpDownload->BootRomTypeThread[i]) - { - pTarget->pWtptpDownload->BootRomTypeThread[i] = 0; - break; - } - } - - if(!bSuccess) - { - - time_t now; - char strtemp[255]; - time(&now); - struct tm *timenow; - timenow = localtime(&now); - char szfailedlogname[256] = {0}; - sprintf(szfailedlogname,"%s/%d_%d_%d_%d_%d_%d_failed_wtp.log", pTarget->pWtptpDownload->m_szSWDPath,timenow->tm_year+1900,timenow->tm_mon+1,timenow->tm_mday,timenow->tm_hour,timenow->tm_min,timenow->tm_sec); - tprintf(_T("failelog name is %s\n"),szfailedlogname); - if(taccess(pDev->LogFileName,0)==0) - { - tprintf(_T("rename is %s\n"),pDev->LogFileName); - rename(pDev->LogFileName,szfailedlogname); - } - } - - WtptpDownLoad_RemoveDisplayInfoDevice(pTarget->pWtptpDownload,pDev); - pthread_mutex_lock(&pTarget->pWtptpDownload->DeviceList_mutex); - pTarget->pWtptpDownload->m_nBootRomDevNum--; - WtptpDownLoad_RemoveEntryList(pTarget->pWtptpDownload,pDev); - pthread_mutex_unlock(&pTarget->pWtptpDownload->DeviceList_mutex); - - free( pTarget); - pTarget = NULL; - pthread_detach(pthread_self()); - - return NULL; -} - - - - - -PVOID WtptpDownLoad_BootLoaderIOThread(PVOID Arg) -{ -#if PRINTLOG - tprintf(_T("Enter into BootLoaderIOThread\n")); -#endif - PDOWNLOADTARGET pTarget = (PDOWNLOADTARGET)Arg; - PDEVICE pDev = pTarget->pDev ; - - tfprintf (pDev->hLog,_T("\nEnter into BootLoader Thread\n")); - fflush(pDev->hLog); - BOOL bSuccess = FALSE; - if(pTarget->pWtptpDownload->m_bSingleDownload) - { - pTarget->pWtptpDownload->m_bTerminateUSBDetect = TRUE; - } - bSuccess = WtptpDownLoad_WTPTPDownLoad(pTarget->pWtptpDownload,pDev); - - if(bSuccess) - { - pDev->kProState =kProcCompleted; - WtptpDownLoad_AddDisplayInfoDevice( pTarget->pWtptpDownload,pDev); - WtptpDownLoad_Report(pTarget->pWtptpDownload); - - } - else - { - pDev->kProState =kProcAborting; - WtptpDownLoad_AddDisplayInfoDevice( pTarget->pWtptpDownload,pDev); - WtptpDownLoad_Report(pTarget->pWtptpDownload); - tfprintf (pDev->hLog,_T("\nAbnormal Termination in BootLoader\n")); - - time_t now; - char strtemp[255]; - time(&now); - struct tm *timenow; - timenow = localtime(&now); - char szfailedlogname[256] = {0}; - sprintf(szfailedlogname,"%s/%d_%d_%d_%d_%d_%d_failed_wtp.log", pTarget->pWtptpDownload->m_szSWDPath,timenow->tm_year+1900,timenow->tm_mon+1,timenow->tm_mday,timenow->tm_hour,timenow->tm_min,timenow->tm_sec); - tprintf(_T("failelog name is %s\n"),szfailedlogname); - if(taccess(pDev->LogFileName,0)==0) - { - tprintf(_T("rename is %s\n"),pDev->LogFileName); - rename(pDev->LogFileName,szfailedlogname); - } - } - - tfprintf (pDev->hLog,_T("\nBootLoader Thread Completed!\n")); - fflush(pDev->hLog); - - if (pDev->hLog != NULL ) - { - fclose (pDev->hLog); - pDev->hLog = NULL; -#if PRINTLOG - tprintf(_T("\nBootLoader Thread Completed A!\n")); -#endif - } - -#ifndef __ANDROID__ - WtptpDownLoad_RemoveDisplayInfoDevice(pTarget->pWtptpDownload,pDev); - pthread_mutex_lock(&pTarget->pWtptpDownload->DeviceList_mutex); - pTarget->pWtptpDownload->m_nBootLoaderDevNum--; - WtptpDownLoad_RemoveEntryList(pTarget->pWtptpDownload,pDev); - pthread_mutex_unlock(&pTarget->pWtptpDownload->DeviceList_mutex); -#endif -#if PRINTLOG - tprintf(_T("\nBootLoader Thread Completed B!\n")); -#endif - free( pTarget); - pTarget = NULL; -#if PRINTLOG - tprintf(_T("\nBootLoader Thread Completed C!\n")); -#endif - pthread_detach(pthread_self()); //detach thread to release memory resources for joinable thread -#if PRINTLOG - tprintf(_T("\nBootLoader Thread Completed E!\n")); -#endif - return NULL; - -} - - - -PVOID WtptpDownLoad_BootLoaderUploadThread(PVOID Arg) -{ - tprintf(_T("Enter BootLoaderIOThread\n")); - static int ActiveUploadBootloader = 0; - PDOWNLOADTARGET pTarget = (PDOWNLOADTARGET)Arg; - PDEVICE pDev = pTarget->pDev ; - tfprintf (pDev->hLog,_T("\nEnter BootLoader Thread\n")); - fflush(pDev->hLog); - BOOL bSuccess = FALSE; - bSuccess = WtptpDownLoad_UploadDataFromTarget(pTarget->pWtptpDownload,pDev); - if(bSuccess) - { - pDev->kProState =kProcCompleted; - WtptpDownLoad_AddDisplayInfoDevice( pTarget->pWtptpDownload,pDev); - WtptpDownLoad_Report(pTarget->pWtptpDownload); - tfprintf (pDev->hLog,_T("\nBootLoader Upload Thread Completed!\n")); - } - else - { - pDev->kProState =kProcAborting; - WtptpDownLoad_AddDisplayInfoDevice( pTarget->pWtptpDownload,pDev); - WtptpDownLoad_Report(pTarget->pWtptpDownload); - - tfprintf (pDev->hLog,_T("\nAbnormal Termination in BootUpload\n")); - - } - - fflush(pDev->hLog); - if (pDev->hLog != NULL ) - { - fclose (pDev->hLog); - pDev->hLog = NULL; - - } - pthread_mutex_lock(&pTarget->pWtptpDownload->DeviceList_mutex); - pTarget->pWtptpDownload->m_nUploadDevNum--; - WtptpDownLoad_RemoveEntryList( pTarget->pWtptpDownload,pDev); - pthread_mutex_unlock(&pTarget->pWtptpDownload->DeviceList_mutex); - free( pTarget); - pTarget = NULL; - - tprintf (_T("\nBootLoader Upload Thread Completed!\n")); - pthread_detach(pthread_self()); - - return NULL; -} - - -void WtptpDownLoad_AddDisplayInfoDevice(struct CWtptpDownLoad *me,PDEVICE pDev) -{ - if(kl_size(pdisl,me->m_DisplayInfoList)==0) - { - PDISPLAYINFO pDevDisplayInfo = (PDISPLAYINFO)malloc(sizeof(DISPLAYINFO)); - memset(pDevDisplayInfo,0,sizeof(DISPLAYINFO)); - memcpy(pDevDisplayInfo->UsbDevName,pDev->UsbDevName,sizeof(pDev->UsbDevName)); - memcpy(pDevDisplayInfo->szCurrentMsg,pDev->szCurrentMsg,sizeof(pDev->szCurrentMsg)); - memcpy(&pDevDisplayInfo->szBadBlk,&pDev->DevBadBlk,sizeof(pDev->DevBadBlk)); - memcpy(&pDevDisplayInfo->szImageCrc,&pDev->DevImageCrc,sizeof(pDev->DevImageCrc)); - pDevDisplayInfo->kProState = pDev->kProState; - pDevDisplayInfo->npercent = pDev->npercent; - *kl_pushp(pdisl, me->m_DisplayInfoList) = pDevDisplayInfo; - } - else - { - BOOL bIsDeviceExist = FALSE; - t_DisplayInfoIter Iter = kl_begin(me->m_DisplayInfoList); - const char* sDeviceName, *stmp; - sDeviceName = pDev->UsbDevName; - while(Iter!=kl_end(me->m_DisplayInfoList)) - { - stmp = kl_val(Iter)->UsbDevName; - if(strstr(stmp,sDeviceName)!=NULL) - { - bIsDeviceExist = TRUE; - memcpy(kl_val(Iter)->UsbDevName,pDev->UsbDevName,sizeof(pDev->UsbDevName)); - memcpy(kl_val(Iter)->szCurrentMsg,pDev->szCurrentMsg,sizeof(pDev->szCurrentMsg)); - memcpy(&kl_val(Iter)->szBadBlk,&pDev->DevBadBlk,sizeof(pDev->DevBadBlk)); - memcpy(&kl_val(Iter)->szImageCrc,&pDev->DevImageCrc,sizeof(pDev->DevImageCrc)); - kl_val(Iter)->kProState = pDev->kProState; - kl_val(Iter)->npercent = pDev->npercent; - break; - } - Iter = kl_next(Iter); - } - - if(!bIsDeviceExist) - { - PDISPLAYINFO pDevDisplayInfo = (PDISPLAYINFO)malloc(sizeof(DISPLAYINFO)); - memset(pDevDisplayInfo,0,sizeof(DISPLAYINFO)); - memcpy(pDevDisplayInfo->UsbDevName,pDev->UsbDevName,sizeof(pDev->UsbDevName)); - memcpy(pDevDisplayInfo->szCurrentMsg,pDev->szCurrentMsg,sizeof(pDev->szCurrentMsg)); - memcpy(&pDevDisplayInfo->szBadBlk,&pDev->DevBadBlk,sizeof(pDev->DevBadBlk)); - memcpy(&pDevDisplayInfo->szImageCrc,&pDev->DevImageCrc,sizeof(pDev->DevImageCrc)); - pDevDisplayInfo->kProState = pDev->kProState; - pDevDisplayInfo->npercent = pDev->npercent; - *kl_pushp(pdisl,me->m_DisplayInfoList)=pDevDisplayInfo; - } - - } -} -void WtptpDownLoad_RemoveDisplayInfoDevice(struct CWtptpDownLoad *me,PDEVICE pDev) -{ - - if(kl_size(pdisl,me->m_DisplayInfoList)==0) - { - return; - } - else - { - t_DisplayInfoIter Iter = kl_begin(me->m_DisplayInfoList); - const char* sDeviceName,*stmp; - sDeviceName = pDev->UsbDevName; - while(Iter!=kl_end(me->m_DisplayInfoList)) - { - stmp = kl_val(Iter)->UsbDevName; - if(strstr(stmp,sDeviceName)!= NULL) - { - free( kl_val(Iter)); - kl_val(Iter) = NULL; - kl_erase(pdisl,me->m_DisplayInfoList,&Iter); - break; - } - Iter = kl_next(Iter); - } - } - -} - -void WtptpDownLoad_Report(struct CWtptpDownLoad *me) -{ - - t_DisplayInfoIter iter = kl_begin(me->m_DisplayInfoList); - while(iter!=kl_end(me->m_DisplayInfoList)) - { - NotifyStatus ProcInfo; - memset(&ProcInfo,0, sizeof(ProcInfo)); - My_strcpy(ProcInfo.pszUSBPortAddress,_tcslen(kl_val(iter)->UsbDevName)+1,kl_val(iter)->UsbDevName); - My_strcpy(ProcInfo.pszProcMsg,_tcslen(kl_val(iter)->szCurrentMsg)+1,kl_val(iter)->szCurrentMsg); - memcpy(&ProcInfo.lpBadBlk,&kl_val(iter)->szBadBlk,sizeof(BadBlockData)); - memcpy(&ProcInfo.lpImageCrc,&kl_val(iter)->szImageCrc,sizeof(ImageCRCInfo)); - ProcInfo.eProcState = kl_val(iter)->kProState; - ProcInfo.nDownloadedPercent = kl_val(iter)->npercent; - - if (me->m_lpInstParam->CallbackProc) - { - pthread_mutex_lock(&me->callback_mutex); - ((CALLBACKPROC)me->m_lpInstParam->CallbackProc)(&ProcInfo); - pthread_mutex_unlock(&me->callback_mutex); - } - iter = kl_next(iter); - } - - -} - -BOOL WtptpDownLoad_SetAndWaitForThreadExit(struct CWtptpDownLoad *me,PDEVICE pDev) -{ - //pthread_mutex_lock(&Device_mutex); - pDev->ThreadExit = STOPFLAG; - SetExitHandle(pDev->pWtpComm,1); - //pthread_mutex_unlock(&Device_mutex); - usleep(2000000); - WtptpDownLoad_RemoveEntryList(me,pDev); - - return TRUE; -} - -void WtptpDownLoad_WtptpOpenDevice(struct CWtptpDownLoad *me,struct CWtptpDownLoad *pWtptpDownLoad, USB_HANDLE *pLinuxUsb) -{ - PDEVICE pDev = (PDEVICE)malloc(sizeof(DEVICE)); - memset(pDev, 0, sizeof(DEVICE)); - struct CWtpComm *pWtpComm = (struct CWtpComm *)malloc(sizeof(struct CWtpComm)); - NewCWtpComm(pWtpComm); - pDev->pWtpComm = pWtpComm; -#if PRINTLOG - printf(_T("add DevName:%s\n"), pLinuxUsb->DevName); -#endif - char szBuffer[MAX_FILE_LENGTH]; - memset(szBuffer,0,sizeof(TCHAR)*MAX_FILE_LENGTH); - snprintf(szBuffer,sizeof(szBuffer),("echo ---add DevName:%s--- > /dev/kmsg"),pLinuxUsb->DevName); - system(szBuffer); - PUSB_HANDLE pUsb = (PUSB_HANDLE) malloc(sizeof(USB_HANDLE)); - NEW_USB_HANDLE(pUsb); - COPY_USB_HANDLE(pUsb, pLinuxUsb); - SetLinuxDev(pDev->pWtpComm,pUsb); - - sprintf(pDev->UsbDevName, _T("%s"), pLinuxUsb->DevName); - char sUSBName[128]; - strcpy(sUSBName, pLinuxUsb->DevName); - WtptpDownLoad_replace_all(sUSBName, _T("/"), _T("_")); - sprintf(pDev->LogFileName, _T("%s/wtp%s.log"), pWtptpDownLoad->m_szSWDPath, sUSBName); - #if PRINTLOG - printf(_T("LogFileName is:%s\n"), pDev->LogFileName); -#endif - if (WtptpDownLoad_OpenDevice(pWtptpDownLoad,pDev)) - { - pthread_mutex_lock(&pWtptpDownLoad->DeviceList_mutex); - *kl_pushp(pdevl,pWtptpDownLoad->m_WtptpDeviceList)=pDev; - pthread_mutex_unlock(&pWtptpDownLoad->DeviceList_mutex); - - pDev->kProState = kProcConnecting; - WtptpDownLoad_AddDisplayInfoDevice(pWtptpDownLoad,pDev); - WtptpDownLoad_Report(pWtptpDownLoad); -#if PRINTLOG - tprintf(_T("Open device successfully\n")); -#endif - fflush(stdout); - } - else - { - pDev->kProState = kProcAborting; - WtptpDownLoad_AddDisplayInfoDevice(pWtptpDownLoad,pDev); - WtptpDownLoad_Report(pWtptpDownLoad); - tprintf(_T("Open device failed\n")); - fflush(stdout); - free( pDev); - pDev = NULL; - } -} - -PVOID WtptpDownLoad_WtptpDeviceDetectThread(PVOID Arg) -{ - - struct CWtptpDownLoad* pWtptpDownLoad = (struct CWtptpDownLoad*)Arg; - PUSB_HANDLE hUSBDev[MAX_DEVNUM]; - - int hotplug_sock = WtptpDownLoad_init_hotplug_sock(); - int existing_num = BulkDevNonDrv_FindAllSupportedDevices(hUSBDev); - if (0 == existing_num) - { -#if PRINTLOG - tprintf(_T("Please plug your USB device\n")); -#endif - fflush(stdout); - } - else - { - for (int loops = 0; loops < existing_num; loops++) - { - WtptpDownLoad_WtptpOpenDevice(pWtptpDownLoad,pWtptpDownLoad,hUSBDev[loops]); - tprintf(_T("Open existing USB device number %d\n"), loops); - fflush(stdout); - free( hUSBDev[loops]); - } - } - - while (1) - { - pthread_mutex_lock(&(pWtptpDownLoad->Quit_mutex)); - if(pWtptpDownLoad->m_bTerminateDownload) - { -#if PRINTLOG - tprintf(_T("\nQuit from detect device.....\n")); -#endif - break; - } - pthread_mutex_unlock(&(pWtptpDownLoad->Quit_mutex)); - usleep(100); - - /* Netlink message buffer */ - TCHAR buf[UEVENT_BUFFER_SIZE * 2] = {0}; - int nLen = recv(hotplug_sock, &buf, sizeof(buf), 0); - //printf(_T("Recieve message is:%s\n"), buf); - USB_HANDLE *pLinuxUsb; - int bAdd = 0; - pLinuxUsb = (USB_HANDLE *)calloc(1, sizeof(USB_HANDLE)); - if ( BulkDevNonDrv_CheckDevForNetLink(pLinuxUsb, buf, nLen, &bAdd) ) - { - if ( 1 == bAdd ) - { - if(pWtptpDownLoad->m_bTerminateUSBDetect) - { - continue; //不检测插入的新设备,但是可以检测移除的设备 - } - system("echo ---bAdd=1--- > /dev/kmsg"); - WtptpDownLoad_WtptpOpenDevice(pWtptpDownLoad,pWtptpDownLoad, pLinuxUsb); - } - else - if (0 == bAdd) - { - const char* sCurrentRemoveDevice = pLinuxUsb->DevName; -#if PRINTLOG - printf(_T("remove DevName:%s\n"), pLinuxUsb->DevName); -#endif - system("echo ---remove DevName--- > /dev/kmsg"); - pthread_mutex_lock(&pWtptpDownLoad->DeviceList_mutex); - if(kl_size(pdevl,pWtptpDownLoad->m_WtptpDeviceList)>0) - { - t_DeviceIter iter = kl_begin(pWtptpDownLoad->m_WtptpDeviceList); - while(iter!=kl_end(pWtptpDownLoad->m_WtptpDeviceList)) - { - const char* strDev = GetLinuxDev((kl_val(iter))->pWtpComm)->DevName; - const char* strtmp = pLinuxUsb->DevName; - if(strstr(sCurrentRemoveDevice,strtmp)!= NULL) // it this device is removed , so will terminate thread - { - WtptpDownLoad_SetAndWaitForThreadExit(pWtptpDownLoad,kl_val(iter)); - break; - } - iter = kl_next(iter); - } - } - pthread_mutex_unlock(&pWtptpDownLoad->DeviceList_mutex); - } - } - - - free( pLinuxUsb); - } - close(hotplug_sock); //close socket. - pthread_detach(pthread_self()); - return NULL; -} - -int WtptpDownLoad_init_hotplug_sock() -{ - const int buffersize = 1024*16*16; - int ret; - - struct sockaddr_nl snl; -#ifdef __ANDROID__ - memset(&snl, 0, sizeof(struct sockaddr_nl)); -#else - bzero(&snl, sizeof(struct sockaddr_nl)); -#endif - snl.nl_family = AF_NETLINK; - snl.nl_pid = getpid(); - snl.nl_groups = 1; -#if PRINTLOG - tprintf(_T("init_hotplug_sock\n")); -#endif - fflush(stdout); - - //tprintf(_T("enter into init_hotplug_sock, snl.nl_pid = %d,snl.nl_groups = %d\n"),snl.nl_pid,snl.nl_groups); - - int s = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT); - if (s == -1) - { -#if PRINTLOG - perror(_T("socket")); -#endif - return -1; - } - //tprintf(_T("socket return %d\n"),s); - ret = setsockopt(s, SOL_SOCKET, SO_RCVBUF, &buffersize, sizeof(buffersize)); - if (ret < 0) - { -#if PRINTLOG - perror(_T("setsockopt")); -#endif - } - - ret = bind(s, (struct sockaddr *)&snl, sizeof(struct sockaddr_nl)); - - if (ret < 0) - { - tprintf(_T("bind return %d... , errno %d\n"),ret , errno); - printf("strerror: %s\n", strerror(errno)); - close(s); - return -1; - } - - //tprintf(_T("Please plug your USB device\n")); - fflush(stdout); - - return s; -} - - -void WtptpDownLoad_SetBootDeviceType(struct CWtptpDownLoad *me,PDEVICE pDev,EDeviceType eDevieBootType) -{ - CWtpCommSetBootDeviceType(pDev->pWtpComm,eDevieBootType); - pDev->nDevType = eDevieBootType; - if (kBootLoader == eDevieBootType) - { - strcpy(pDev->szCurrentMsg,"Open an BootLoader Device"); - tfprintf (pDev->hLog,_T("\nOpen an BootLoader Device\n")); - } - else - { - strcpy(pDev->szCurrentMsg,"Open an BootRom Device"); - tfprintf (pDev->hLog,_T("\nOpen an BootRom Device\n")); - } - fflush(pDev->hLog); - - pDev->kProState = kProcDebugLog; - WtptpDownLoad_AddDisplayInfoDevice(me,pDev); - WtptpDownLoad_Report(me); - -} - - - -BOOL WtptpDownLoad_GetDeviceBootType(struct CWtptpDownLoad *me,PDEVICE pDev) -{ - IsLittleEndian(&me->MyConvertLT2B); -#if PRINTLOG - tprintf(_T("Getting type of Device.....\n")); -#endif - if(me->m_bDebugTrace) - { - tprintf(_T("Getting type of Device.....\n")); - } - - tfprintf (pDev->hLog,_T("\nGetting type of Device\n")); - pDev->nDevType = kNone; - - MESSAGE_MODES currentMessageMode=MSG_AND_DOWNLOAD; - SetMessageMode( pDev->pWtpComm,currentMessageMode); - - - if (!OpenUsbPort(pDev->pWtpComm)) - { - tfprintf (pDev->hLog,_T("\n Open Usb Port in GetDeviceBootType failed\n")); - return FALSE; - } - SetPortType(pDev->pWtpComm,0);//set usb port as default - - if( PLAT_HELAN ==me->m_ePlatformType) - { - sleep (1); - } - if (!SendPreamble(pDev->pWtpComm,me->m_bCustPreamble) ) - { - tprintf (_T("\nSendPreamble failed in GetDeviceBootType\n")); - return FALSE; - } - - tfprintf (pDev->hLog,_T("\n GetTargetMessage after sendpreamble\n")); - WTPSTATUS WtpStatus = {0x00, 0x00, 0x00, 0x00, 0x01, htole32(0x00)}; - if (currentMessageMode == MSG_AND_DOWNLOAD ) - { - WtpStatus.Status = ACK; - if(!GetTargetMessage(pDev->pWtpComm,&WtpStatus)) - { - tfprintf (pDev->hLog,_T("\n GetTargetMessage after sendpreamble failed\n")); - return FALSE; - } - WtpStatus.Flags = 0x1; - } - - tfprintf(pDev->hLog,_T("\nGetting Version...\n")); - WtpStatus.CMD = 0x0; - WtpStatus.SEQ = 0x0; - WtpStatus.CID = 0x0; - WtpStatus.Status= 0x0; - WtpStatus.Flags = 0x1; - WtpStatus.DLEN = 0x0; - fflush(pDev->hLog); - - if (!GetVersion(pDev->pWtpComm,&WtpStatus)) - { - tprintf (_T("\nGetting Version failed\n")); - return FALSE; - } - if(ACK != WtpStatus.Status) - { - CWtpCommSetBootDeviceType(pDev->pWtpComm,kNone); - pDev->nDevType = kNone; - tprintf(_T("Can't get response from Target when getting type of device\n")); - tfprintf (pDev->hLog,_T("\nUnknown Device\n")); - fflush(pDev->hLog); - return FALSE; - } - - - TCHAR Processor[24]; - TCHAR Version[24]; - TCHAR Date[24]; - memset(Processor, 0, 24); - memset(Version, 0, 24); - memset(Date, 0, 24); - - if(me->m_bDebugTrace) - { - tprintf(_T("\nVersion: %c%c%c%c\n"),WtpStatus.Data[3],WtpStatus.Data[2],WtpStatus.Data[1],WtpStatus.Data[0]); - tprintf(_T("\nDate: %08X\n"),le32toh(*(unsigned int *)&WtpStatus.Data[4])); - tprintf(_T("\nProcessor: %c%c%c%c\n"),WtpStatus.Data[11],WtpStatus.Data[10],WtpStatus.Data[9],WtpStatus.Data[8]); - - } - sprintf(Version,_T("%c%c%c%c"),WtpStatus.Data[3],WtpStatus.Data[2],WtpStatus.Data[1],WtpStatus.Data[0]); - sprintf(Date,_T("%02x%02x%02x%02x"),WtpStatus.Data[7],WtpStatus.Data[6],WtpStatus.Data[5],WtpStatus.Data[4]); - sprintf(Processor,_T("%c%c%c%c"),WtpStatus.Data[11],WtpStatus.Data[10],WtpStatus.Data[9],WtpStatus.Data[8]); - const char* strProcessor,*strVersion,*strDate; - strProcessor = Processor; - strVersion = Version; - strDate = Date; - tfprintf(pDev->hLog,_T("\nVersion: %c%c%c%c"),WtpStatus.Data[3],WtpStatus.Data[2],WtpStatus.Data[1],WtpStatus.Data[0]); - tfprintf(pDev->hLog,_T("\nDate: %08X"),le32toh(*(unsigned int *)&WtpStatus.Data[4])); - tfprintf(pDev->hLog,_T("\nProcessor: %c%c%c%c"),WtpStatus.Data[11],WtpStatus.Data[10],WtpStatus.Data[9],WtpStatus.Data[8]); - fflush(pDev->hLog); - - - - BOOL bObmSupportMutliDDR = FALSE; - BOOL bObmSupportMultiFlash = FALSE; - UINT32 uiEMMCSize = 0; - UINT32 uiDdrVendorId = 0; - UINT32 uiDdrUnitSize = 0; - TCHAR szDDRVendorID[20]; - memset(szDDRVendorID,0,sizeof(szDDRVendorID)); - //new OBM return DDR Vendor ID and DDR SIZE 8 bytes: 4 bytes for Vendor ID : ID01,ID02;DDR size : 0001,0002 the value is unit(512M) - if(20 == WtpStatus.DLEN) - { - tsprintf(szDDRVendorID,_T("0x%c%c"),WtpStatus.Data[13],WtpStatus.Data[12]); - uiDdrVendorId = Str2Uint32(szDDRVendorID); - uiDdrUnitSize = *(unsigned long *)&WtpStatus.Data[16]; - bObmSupportMutliDDR = TRUE; - } - else if (24 == WtpStatus.DLEN) - { - tsprintf(szDDRVendorID,_T("0x%c%c"),WtpStatus.Data[13],WtpStatus.Data[12]); - uiDdrVendorId = Str2Uint32(szDDRVendorID); - uiDdrUnitSize = *(unsigned long *)&WtpStatus.Data[16]; - uiEMMCSize = *(unsigned long *)&WtpStatus.Data[20]; - bObmSupportMutliDDR = TRUE; - bObmSupportMultiFlash = TRUE; - } - - EDeviceType eBootDeviceType = WtptpDownLoad_GetDeviceType(me,me->m_ePlatformType,strDate,strVersion,strProcessor); - if (kNone == eBootDeviceType) - { - strcpy(pDev->szCurrentMsg,"Unkown Device"); - pDev->kProState = kProcErrorCode; - WtptpDownLoad_AddDisplayInfoDevice(me,pDev); - WtptpDownLoad_Report(me); - - tfprintf (pDev->hLog,_T("\nUnkown Device\n")); - fflush(pDev->hLog); - return FALSE; - } - - WtptpDownLoad_SetBootDeviceType(me,pDev, eBootDeviceType); - - - if(kBootLoader ==pDev->nDevType ) - { - if (FLASH_EMMC == me->m_FlashType) - { - if (me->m_uTotalDDRTypeNum>0 && !bObmSupportMutliDDR) - { - tfprintf (pDev->hLog,_T("Current OBM don't suppport multiple DDR feature, please update OBM.\n")); - return FALSE; - } - - if (me->m_uTotalFlashTypeNum>1 && !bObmSupportMultiFlash) - { - tfprintf (pDev->hLog,_T("Current OBM don't suppport multiple eMMC feature, please update OBM.\n")); - return FALSE; - } - - eDDREMMCMatchResult eError = WtptpDownLoad_HandleDownloadImagesByDDRIDandEMMCSize(me,uiDdrVendorId,uiDdrUnitSize,uiEMMCSize); - if(eError!=kMatchNoError) - { - - TCHAR szMessage[MAX_FILE_LENGTH]={0}; - if(kDDRMismatchError==eError) - { - tsnprintf(szMessage,MAX_FILE_LENGTH,_T("DDRType is not found , OBM read vendor DDR Pid 0x%x, can't find it in blf configure \n"),uiDdrVendorId<<8|uiDdrUnitSize); - } - else if(kEMMCMismatchError==eError) - { - tsnprintf(szMessage,MAX_FILE_LENGTH,_T("EMMC Size Type is not found , OBM read EMMC Size is %08X, can't find it in blf configure \n"),uiEMMCSize); - } - else - tsnprintf(szMessage,MAX_FILE_LENGTH,_T("InitialBL have issue\n")); - - tfprintf (pDev->hLog,szMessage); - return FALSE; - } - } - else if (FLASH_NAND == me->m_FlashType) - { - if (me->m_uTotalDDRTypeNum>0 && !bObmSupportMutliDDR) - { - tfprintf (pDev->hLog,_T("Current OBM don't suppport multiple DDR feature, please update OBM.\n")); - return FALSE; - } - - eDDREMMCMatchResult eError = WtptpDownLoad_HandleNandDLImgByDDRID(me,uiDdrVendorId,uiDdrUnitSize); - if(eError!=kMatchNoError) - { - TCHAR szMessage[MAX_FILE_LENGTH]={0}; - if(kDDRMismatchError==eError) - { - tsnprintf(szMessage,MAX_FILE_LENGTH,_T("DDRType is not found , OBM read vendor DDR Pid 0x%x, can't find it in blf configure \n"),uiDdrVendorId<<8|uiDdrUnitSize); - } - tfprintf (pDev->hLog,szMessage); - return FALSE; - } - } - else - { - t_ImageFileByDDRIter Iter = kl_begin(me->m_lBootLoaderImageWithDDRList); - me->m_plBootLoaderImageList = &((kl_val(Iter))->ImageFileList); - } - } - fflush(pDev->hLog); - return TRUE; -} - - -BOOL WtptpDownLoad_OpenDevice(struct CWtptpDownLoad *me,PDEVICE pDev) -{ - PDOWNLOADTARGET pTarget = (PDOWNLOADTARGET)malloc(sizeof(DOWNLOADTARGET)); - pTarget->pDev = pDev; - pTarget->pWtptpDownload = me; - if((pDev->hLog = _tfopen (pDev->LogFileName,_T("w"))) == NULL) - { - tprintf(_T("Create log file failed\n")); - return FALSE; - } - else - { - SetLogFile(pDev->pWtpComm,pDev->hLog); - } - SetPlatformType(pDev->pWtpComm,me->m_ePlatformType); - //Do upload only after detect a device if user want to do upload - if(me->m_bDumpFlash) - { - pDev->nDevType = kBootLoader; - pDev->SerialNo = me->m_nUploadDevNum; - int res= pthread_create(&me->UploadThread[me->m_nUploadDevNum%32], NULL,WtptpDownLoad_BootLoaderUploadThread , pTarget); - if(res!=0) - { -#if PRINTLOG - perror (_T("Thread creation failed\n")); -#endif - free( pTarget); - return FALSE; - } - else - { - pDev->ThreadId = me->UploadThread[me->m_nUploadDevNum%32]; - me->m_nUploadDevNum++; - - } - } - else - { - if(WtptpDownLoad_GetDeviceBootType(me,pDev)) - { -#if PRINTLOG - tprintf(_T("Get type of device successfully\n")); -#endif - tfprintf(pDev->hLog,_T("\nGet type of device successfully\n")); - fflush(pDev->hLog); - } - else - { - tprintf(_T("Get type of device failed\n")); - tfprintf(pDev->hLog,_T("\nGet type of device failed\n")); - fflush(pDev->hLog); - fclose(pDev->hLog); - free( pTarget); - return FALSE; - } - if(pDev->nDevType == kBootRom) - { - int res = pthread_create(&me->BootRomTypeThread[me->m_nBootRomDevNum%32], NULL,WtptpDownLoad_BootRomIOThread , pTarget); - if(res!=0) - { -#if PRINTLOG - perror (_T("Thread creation failed\n")); -#endif - fclose(pDev->hLog); - free( pTarget); - return FALSE; - } - else - { - pDev->ThreadId = me->BootRomTypeThread[me->m_nUploadDevNum%32]; - me->m_nBootRomDevNum++; - } - } - else if(pDev->nDevType == kBootLoader) - { -#if PRINTLOG - tprintf (_T("Thread creation BootLoaderTypeThread\n")); -#endif - int res = pthread_create(&me->BootLoaderTypeThread[me->m_nBootLoaderDevNum%32], NULL,WtptpDownLoad_BootLoaderIOThread , pTarget); - if(res!=0) - { -#if PRINTLOG - perror (_T("Thread creation failed\n")); -#endif - fclose(pDev->hLog); - free( pTarget); - return FALSE; - } - else - { - pDev->ThreadId = me->BootLoaderTypeThread[me->m_nBootLoaderDevNum%32]; - me->m_nBootLoaderDevNum++; - } - - } - } - - - return TRUE; - -} - - -BOOL WtptpDownLoad_DownloadImage(struct CWtptpDownLoad *me,PDEVICE pdev, int iFile,const t_ImageFileList* plImgFileList, UINT64 uiAllimgsize,UINT64 *uidownloadsize,int nImages,char* strDownloadImgName) -{ - if(pdev->ThreadExit == STOPFLAG) - { - pdev->kProState = kProcAborting; - WtptpDownLoad_AddDisplayInfoDevice(me,pdev); - WtptpDownLoad_Report(me); - return FALSE; - } - _tcscpy(pdev->szCurrentMsg,_T("Begin DownloadImage...........")); - pdev->kProState = kProcDebugLog; - WtptpDownLoad_AddDisplayInfoDevice(me,pdev); - WtptpDownLoad_Report(me); - tfprintf (pdev->hLog,_T("%s\n"),pdev->szCurrentMsg); - fflush(pdev->hLog); - - WTPCOMMAND WtpCmd; - eProcessState eProcState; - MESSAGE_MODES currentMessageMode=MSG_AND_DOWNLOAD; - SetMessageMode(pdev->pWtpComm,currentMessageMode); - WTPSTATUS WtpStatus = {0x00, 0x00, 0x00, 0x00, 0x01, 0x00}; - UINT32 ImageType = 0; - BYTE IsImage = NACK; - unsigned int uiRemainingBytes = 0; - unsigned int uiBufferSize = 0; - TCHAR szFileName[MAX_PATH]; - memset(szFileName,0,MAX_PATH); - long lFileSize = 0,BytesRead; - FILE* hFile = NULL; - int i = 0; - - - if(iFile!=0) - { - tfprintf (pdev->hLog,_T("\nSending Preamble...\n")); - - if(me->m_bDebugTrace) - { - _tcscpy(pdev->szCurrentMsg,_T("Sending Preamble...")); - pdev->kProState = kProcDebugLog; - WtptpDownLoad_AddDisplayInfoDevice(me,pdev); - WtptpDownLoad_Report(me); - tfprintf (pdev->hLog,_T("%s\n"),pdev->szCurrentMsg); - } - - - if (!SendPreamble(pdev->pWtpComm,me->m_bCustPreamble)) - { - _tcscpy(pdev->szCurrentMsg,_T("SendPreamble can not get ACK...")); - pdev->kProState = kProcDebugLog; - WtptpDownLoad_AddDisplayInfoDevice(me,pdev); - WtptpDownLoad_Report(me); - tfprintf (pdev->hLog,_T("%s\n"),pdev->szCurrentMsg); - return FALSE; - } - - if (currentMessageMode == MSG_AND_DOWNLOAD ) - { - WtpStatus.Status = ACK; - GetTargetMessage(pdev->pWtpComm,&WtpStatus); - WtpStatus.Flags = 0x1; - } - tfprintf (pdev->hLog,_T("\nGetting Version...\n")); - - if(me->m_bDebugTrace) - { - _tcscpy(pdev->szCurrentMsg,_T("Getting Version...")); - WtptpDownLoad_AddDisplayInfoDevice(me,pdev); - WtptpDownLoad_Report(me); - } - - if (!GetVersion(pdev->pWtpComm,&WtpStatus)) - { - _tcscpy(pdev->szCurrentMsg,_T("GetVersion failed...")); - pdev->kProState = kProcDebugLog; - WtptpDownLoad_AddDisplayInfoDevice(me,pdev); - WtptpDownLoad_Report(me); - tfprintf (pdev->hLog,_T("%s\n"),pdev->szCurrentMsg); - return FALSE; - } - - - } - fflush(pdev->hLog); - if (!SelectImage(pdev->pWtpComm,&ImageType)) - { - _tcscpy(pdev->szCurrentMsg,_T("SelectImage failed...")); - pdev->kProState = kProcDebugLog; - WtptpDownLoad_AddDisplayInfoDevice(me,pdev); - WtptpDownLoad_Report(me); - tfprintf (pdev->hLog,_T("%s\n"),pdev->szCurrentMsg); - - return FALSE; - } - - - IsImage = WtptpDownLoad_AckWithImageName(me,ImageType,szFileName,plImgFileList); - strcpy(strDownloadImgName, szFileName); - if (!VerifyImage(pdev->pWtpComm,IsImage)) - { - _tcscpy(pdev->szCurrentMsg,_T("Verify image failed...")); - pdev->kProState = kProcDebugLog; - WtptpDownLoad_AddDisplayInfoDevice(me,pdev); - WtptpDownLoad_Report(me); - tfprintf (pdev->hLog,_T("%s\n"),pdev->szCurrentMsg); - - return FALSE; - - } - tsprintf(pdev->szCurrentMsg,_T("download file name is %s"),szFileName); - pdev->kProState = kProcDebugLog; - WtptpDownLoad_AddDisplayInfoDevice(me,pdev); - WtptpDownLoad_Report(me); - tfprintf (pdev->hLog,_T("%s\n"),pdev->szCurrentMsg); - - /*if ((hFile = _tfopen (szFileName,_T("rb"))) == NULL) - { - TCHAR szMessage[1024]; - sprintf(szMessage,_T("\nError: Can't open %s file!\n"),szFileName); - _tcscpy(pdev->szCurrentMsg,szMessage); - pdev->kProState = kProcDebugLog; - AddDisplayInfoDevice(pdev); - Report(); - tfprintf (pdev->hLog,_T("%s\n"),pdev->szCurrentMsg); - - return FALSE; - }*/ - if (!BinFileWtp_IsFileExist(&gBinFileWtp,szFileName)) - { - TCHAR szMessage[1024]; - sprintf(szMessage,_T("\nError: Can't open %s file!\n"),szFileName); - _tcscpy(pdev->szCurrentMsg,szMessage); - pdev->kProState = kProcDebugLog; - WtptpDownLoad_AddDisplayInfoDevice(me,pdev); - WtptpDownLoad_Report(me); - tfprintf (pdev->hLog,_T("%s\n"),pdev->szCurrentMsg); - - return FALSE; - - } - - //fseek (hFile,0L,SEEK_END); // Set position to EOF - //lFileSize = ftell (hFile); // Get position of file, thus the file size. - lFileSize = BinFileWtp_GetFileSize(&gBinFileWtp,szFileName); - - if ((ImageType == TIMH) || (ImageType == PART)) - { - //fseek (hFile,0L,SEEK_SET); // Set position to SOF - BinFileWtp_FseekBin(&gBinFileWtp,szFileName, 0L, SEEK_SET); - uiRemainingBytes = (unsigned int)lFileSize; - } - else - { - //fseek (hFile,4L,SEEK_SET); // Set position to SOF - BinFileWtp_FseekBin(&gBinFileWtp,szFileName, 4L, SEEK_SET); - uiRemainingBytes = (unsigned int)lFileSize - 4; - } - - if ((ImageType == FBFD) && me->m_bGetBadBlk && (!me->m_bEraseAllFlashOnly)) - { - /* - before download the FBF image, first judge the Bad block number - */ - _tcscpy(pdev->szCurrentMsg, _T("Getting Bad Blocks......")); - pdev->kProState = kProcDebugLog; - WtptpDownLoad_AddDisplayInfoDevice(me,pdev); - WtptpDownLoad_Report(me); - tfprintf (pdev->hLog,_T("%s\n"),pdev->szCurrentMsg); - - if (!GetBadBlockInfo(pdev->pWtpComm,&WtpStatus)) - { - _tcscpy(pdev->szCurrentMsg, _T("BBCError")); - pdev->kProState = kProcDownloading; - WtptpDownLoad_AddDisplayInfoDevice(me,pdev); - WtptpDownLoad_Report(me); - - tfprintf (pdev->hLog,_T("Error: GetBadBlockInfo failed!\n")); - fflush(pdev->hLog); - //return FALSE; //Don't interrupt here, can do it in the mainfrm.cpp - } - else - { - pBadBlockData pFlashBadBlockData = (pBadBlockData)WtpStatus.Data; - memset(&pdev->DevBadBlk, 0, sizeof(BadBlockData)); - memcpy(&pdev->DevBadBlk,pFlashBadBlockData, sizeof(BadBlockData)); - _tcscpy(pdev->szCurrentMsg, _T("BadBlkNum")); - pdev->kProState = kProcDownloading; - WtptpDownLoad_AddDisplayInfoDevice(me,pdev); - WtptpDownLoad_Report(me); - - tfprintf(pdev->hLog, _T("\nTotalBadBlocks: %d, Total Blocks: %d"),le32toh(pFlashBadBlockData->TotalBadBlocks),le32toh(pFlashBadBlockData->TotalBlocks)); - tfprintf(pdev->hLog, _T("\nImage ID: %s, bad Blocks: %d\n"),le32toh(pFlashBadBlockData->BadCount[0].ImageID),le32toh(pFlashBadBlockData->BadCount[0].BadCnt)); - - tfprintf (pdev->hLog,_T("GetBadBlockInfo OK!\n")); - fflush(pdev->hLog); - int u32TotalBlocks = le32toh(pdev->DevBadBlk.TotalBlocks); - int u32BadBlocks = le32toh(pdev->DevBadBlk.TotalBadBlocks); - if ( u32BadBlocks > (int)((double)(me->m_uFlashBadBlockRate*u32TotalBlocks)/(double)BADBLOCKRATE_BASE)) - { - _tcscpy(pdev->szCurrentMsg,_T("BadBlockRate is out of range!")); - pdev->kProState = kProcDebugLog; - WtptpDownLoad_AddDisplayInfoDevice(me,pdev); - WtptpDownLoad_Report(me); - tfprintf (pdev->hLog,_T("%s\n"),pdev->szCurrentMsg); - fflush(pdev->hLog); - return FALSE; - } - } - } - - pdev->kProState = kProcDownloading; - BOOL bFastDownload = FALSE; - //Helan2/Eden_A0 BootRom֧��fastdownload,����ƽֻ̨��BootLoader֧��fastdownload - if(kBootLoader == pdev->nDevType - || PLAT_EDEN_A0 == me->m_ePlatformType - || PLAT_HELAN2 == me->m_ePlatformType - || PLAT_ULC1 == me->m_ePlatformType - || PLAT_HELAN3 == me->m_ePlatformType - || PLAT_HELAN4== me->m_ePlatformType ) - { - bFastDownload = TRUE; - isFastDownload(pdev->pWtpComm,SET, TRUE); - } - else - { - isFastDownload(pdev->pWtpComm,SET, FALSE); - } - - if (!DataHeader(pdev->pWtpComm,uiRemainingBytes,&WtpStatus,bFastDownload)) - { - if (hFile != NULL) - fclose (hFile); - - tfprintf (pdev->hLog,_T("\nData header CMD failed\n")); - return FALSE; - } - else - { - for (int i = 0; i < (int)WtpStatus.DLEN; i++) - uiBufferSize |= WtpStatus.Data[i] << (8 * i); - } - - if(kBootRom== pdev->nDevType && PLAT_EDEN_A0 == me->m_ePlatformType) - { - usleep(100000); //100ms - } - - - tfprintf(pdev->hLog,_T("\nReturn flag in Dataheader CMD: %d,FDSwitch is %d,BufferSize is 0x%X\n"),WtpStatus.Flags,isFastDownloadSwtchSet,uiBufferSize); - fflush(pdev->hLog); - if(me->m_bDebugTrace) - { - TCHAR szMessage[1024]; - sprintf(szMessage,_T("Return flag in Dataheader CMD: %d,FDSwitch is %d"),WtpStatus.Flags,isFastDownloadSwtchSet); - _tcscpy(pdev->szCurrentMsg,szMessage); - pdev->kProState = kProcDebugLog; - WtptpDownLoad_AddDisplayInfoDevice(me,pdev); - WtptpDownLoad_Report(me); - tfprintf (pdev->hLog,_T("%s"),pdev->szCurrentMsg); - - } - if (WtpStatus.Flags & 0x4 && isFastDownloadSwtchSet) - { - fprintf (pdev->hLog,"\n*******NOTE:: Fast Download is NOW activated!\n"); - isFastDownload(pdev->pWtpComm,SET, TRUE); - fflush(pdev->hLog); - } - else - { - isFastDownload(pdev->pWtpComm,SET, FALSE); - fprintf (pdev->hLog,"\nFast Download is not activated\n"); - fflush(pdev->hLog); - } - - unsigned int uitotalsize=uiRemainingBytes; - double percentage; - unsigned int downloadbytes; - int loop =0; - while (uiRemainingBytes > 0) - { - - - if (! isFastDownload(pdev->pWtpComm,GET, FDMODE) && loop) - { - - if (!DataHeader(pdev->pWtpComm,uiRemainingBytes,&WtpStatus,FALSE) ) - { - tfprintf (pdev->hLog,_T("Error: WtpComm.DataHeader failed to receive an ACK!\n")); - if (hFile != NULL) fclose (hFile); - return FALSE; - } - else - { - for (int i = 0; i < (int)WtpStatus.DLEN; i++) - uiBufferSize |= WtpStatus.Data[i] << (8 * i); - } - - //workaround for eden a0 bootrom failed - if(kBootRom== pdev->nDevType && PLAT_EDEN_A0 == me->m_ePlatformType) - { - usleep(100000); //100ms - } - } - loop ++; - - - if(uiBufferSize > uiRemainingBytes) - { - uiBufferSize = uiRemainingBytes; - } - - - uiRemainingBytes -= uiBufferSize; // Calculate remaining bytes - if (isFastDownload(pdev->pWtpComm,GET, FDMODE)) - { - /* Code to see if last data */ - if(uiRemainingBytes == 0) - { - - tfprintf (pdev->hLog,_T("Last Data\n")); - isLastData(pdev->pWtpComm,SET, TRUE); - } - } - - - BYTE* pSendDataBuffer = (BYTE*)malloc(sizeof(BYTE)*uiBufferSize); - if(NULL == pSendDataBuffer) - { - tfprintf (pdev->hLog,_T("Molloc Memory failed in DownloadImage.\n")); - return FALSE; - } - - //BytesRead = fread (pSendDataBuffer,1,uiBufferSize,hFile); - BytesRead = BinFileWtp_ReadBinFile(&gBinFileWtp,pSendDataBuffer, 1, uiBufferSize, szFileName); - - - if ((BytesRead != (long)uiBufferSize)) - { - - if (hFile != NULL) fclose (hFile); - tfprintf (pdev->hLog,_T("Error:Read file failed!\n")); - free(pSendDataBuffer); - return FALSE; - } - - else - { - unsigned int totalSize = 0; - unsigned int mark = 0; - - // We do not split packets based on packetSize for FastDownload - - unsigned int packetSize = isFastDownload(pdev->pWtpComm,GET, FDMODE)? uiBufferSize : GetPacketSize(pdev->pWtpComm); - totalSize = uiBufferSize; - - if (totalSize > packetSize ) - { - do - { - if (!Data(pdev->pWtpComm,pSendDataBuffer + mark,packetSize) ) - { - if (hFile != NULL) fclose (hFile); - free(pSendDataBuffer); - return FALSE; - } - else - { - downloadbytes=uitotalsize-uiRemainingBytes; - percentage=(double)(*uidownloadsize+downloadbytes)/(double)uiAllimgsize; - double nPercent = percentage*100; - - pdev->kProState = kProcDownloading; - pdev->npercent = (int)nPercent; - WtptpDownLoad_AddDisplayInfoDevice(me,pdev); - WtptpDownLoad_Report(me); - } - - mark += packetSize; - totalSize-=packetSize; - - if (totalSize <= packetSize) - packetSize = totalSize; - - } - while (totalSize > 0); - - } - else - { - if (!Data(pdev->pWtpComm,pSendDataBuffer,uiBufferSize)) - { - tfprintf (pdev->hLog,_T("\nData command failed\n")); - if (hFile != NULL) fclose (hFile); - free(pSendDataBuffer); - return FALSE; - } - else - { - downloadbytes=uitotalsize-uiRemainingBytes; - percentage=(double)(*uidownloadsize+downloadbytes)/(double)uiAllimgsize; - double nPercent = percentage*100; - - pdev->kProState = kProcDownloading; - pdev->npercent = (int)nPercent; - WtptpDownLoad_AddDisplayInfoDevice(me,pdev); - WtptpDownLoad_Report(me); - - } - } - } - - free(pSendDataBuffer); - pSendDataBuffer = NULL; - - } - tfprintf (pdev->hLog,_T("Download data finished\n")); - fflush(pdev->hLog); - if(me->m_bDebugTrace) - { - pdev->kProState = kProcDebugLog; - _tcscpy(pdev->szCurrentMsg,_T("Download data finished")); - WtptpDownLoad_AddDisplayInfoDevice(me,pdev); - WtptpDownLoad_Report(me); - - tfprintf (pdev->hLog,_T("%s"),pdev->szCurrentMsg); - - } - - Done(pdev->pWtpComm); - - if (isFastDownload(pdev->pWtpComm,GET, FDMODE)) - { - isLastData (pdev->pWtpComm,SET, FALSE); - } - - *uidownloadsize+=uitotalsize; - if (hFile != NULL) - fclose (hFile); - - - pdev->kProState = kProcDebugLog; - sprintf(pdev->szCurrentMsg,_T("Completed DownLoad file: %s"),szFileName); - WtptpDownLoad_AddDisplayInfoDevice(me,pdev); - WtptpDownLoad_Report(me); - tfprintf (pdev->hLog,_T("%s\n"),pdev->szCurrentMsg); - fflush(pdev->hLog); - - return TRUE; -} - - -BYTE WtptpDownLoad_AckWithImageName (struct CWtptpDownLoad *me,const UINT32 ImageType,TCHAR *szFileName,const t_ImageFileList* plImageList) -{ - BYTE IsImage = NACK; - - for (t_ImageFileListConstIter ite = kl_begin(*plImageList); ite != kl_end(*plImageList); ite = kl_next(ite)) - { - if (kl_val(ite).nFileType == ImageType) - { - IsImage = ACK; - _tcscpy (szFileName,kl_val(ite).strImageFile); - break; - } - } - - return IsImage; -} - - -#define __u32_free(x) -KLIST_INIT(u32,UINT32,__u32_free) - -BOOL WtptpDownLoad_ParseTim (struct CWtptpDownLoad *me,t_ImageFileByDDRList* ImageFileByDDRlist) -{ - t_ImageFileByDDRIter DDRDownloadIMGIter = kl_begin(*ImageFileByDDRlist); - klist_t(u32)* lImageIDList = kl_init(u32); - while(DDRDownloadIMGIter!= kl_end(*ImageFileByDDRlist)) - { - BOOL bFoundTim = FALSE; - const char* strTimFile; - for (t_ImageFileListIter ite = kl_begin(kl_val(DDRDownloadIMGIter)->ImageFileList); ite != kl_end(kl_val(DDRDownloadIMGIter)->ImageFileList); ite = kl_next(ite)) - { - FILE* fpFile = NULL; //= _tfopen(ite->strImageFile.c_str(), _T("rb")); - UINT32 dwTimId; - BinFileWtp_OpenBinFile(&gBinFileWtp,_T("rb")); - //fseek(fpFile,sizeof(UINT32),SEEK_SET); - BinFileWtp_FseekBin(&gBinFileWtp,kl_val(ite).strImageFile, sizeof(UINT32), SEEK_SET); - //fread(&dwTimId,sizeof(UINT32),1,fpFile); - BinFileWtp_ReadBinFile(&gBinFileWtp,&dwTimId,sizeof(UINT32) , 1,kl_val(ite).strImageFile); -#if PRINTLOG - printf("TIMH=0x%x dwTimId=0x%x le32toh(dwTimId)=0x%x\n",TIMH,dwTimId,le32toh(dwTimId)); -#endif - if (TIMH == le32toh(dwTimId)) - { - if (!bFoundTim) - { - bFoundTim = TRUE; - kl_val(ite).nFileType = TIMH; - strTimFile = kl_val(ite).strImageFile; - } - else - { - printf(_T("Find two Tim image in downloadImageList\n")); - kl_destroy(u32, lImageIDList); - return FALSE; - } - } - CloseFilePtr(&fpFile); - } - - if (!bFoundTim) - { - printf(_T("\nA Tim image file was not supplied! Exiting program.\n")); - kl_destroy(u32, lImageIDList); - return FALSE; - } - - - FILE *hTimFile = NULL; - CTIM TimHeader; - /*if ((hTimFile = _tfopen (strTimFile.c_str(), _T("rb"))) == NULL) - { - printf(_T("\n_tfopen failed to open Tim file: %s.\n"),strTimFile.c_str()); - return FALSE; - }*/ - if (!BinFileWtp_IsFileExist(&gBinFileWtp,strTimFile)) - { - printf(_T("\n_tfopen failed to open Tim file: %s.\n"),strTimFile); - kl_destroy(u32, lImageIDList); - return FALSE; - } - //fseek (hTimFile,0L,SEEK_SET); // Set position to SOF - BinFileWtp_FseekBin(&gBinFileWtp,strTimFile, 0L, SEEK_SET); - //fread (&TimHeader,sizeof(CTIM),1,hTimFile); - BinFileWtp_ReadBinFile(&gBinFileWtp,&TimHeader, sizeof(CTIM), 1, strTimFile); - int nImages = le32toh(TimHeader.NumImages); -#if PRINTLOG - printf(_T("Number of Images listed in TIM: %d\n"),nImages); -#endif - if (kl_size(stifl,kl_val(DDRDownloadIMGIter)->ImageFileList) != nImages) - { - printf(_T("Number of Images listed in TIM is %d, but provide image number is %d\n"),nImages,kl_size(stifl,kl_val(DDRDownloadIMGIter)->ImageFileList)); - kl_destroy(u32, lImageIDList); - return FALSE; - } - - - if(le32toh(TimHeader.VersionBind.Version) >= TIM_3_1_01 && le32toh(TimHeader.VersionBind.Version) < TIM_3_2_00) - { - IMAGE_INFO_3_1_0 ImageInfo; - for (int i = 0; i < nImages; i++) - { - //fread (&ImageInfo,sizeof(IMAGE_INFO_3_1_0),1,hTimFile); - BinFileWtp_ReadBinFile(&gBinFileWtp,&ImageInfo,sizeof(IMAGE_INFO_3_1_0),1,strTimFile); - *kl_pushp(u32,lImageIDList) = le32toh(ImageInfo.ImageID); - } - } - else if(le32toh(TimHeader.VersionBind.Version) >= TIM_3_2_00&& le32toh(TimHeader.VersionBind.Version) < TIM_3_4_00) - { - IMAGE_INFO_3_2_0 ImageInfo; - for (int i = 0; i < nImages; i++) - { - //fread (&ImageInfo,sizeof(IMAGE_INFO_3_2_0),1,hTimFile); - BinFileWtp_ReadBinFile(&gBinFileWtp,&ImageInfo,sizeof(IMAGE_INFO_3_2_0),1,strTimFile); - *kl_pushp(u32,lImageIDList) = le32toh(ImageInfo.ImageID); - } - } - else if(TIM_3_4_00 == le32toh(TimHeader.VersionBind.Version)) - { - IMAGE_INFO_3_4_0 ImageInfo; - for (int i = 0; i < nImages; i++) - { - //fread (&ImageInfo,sizeof(IMAGE_INFO_3_4_0),1,hTimFile); - BinFileWtp_ReadBinFile(&gBinFileWtp,&ImageInfo,sizeof(IMAGE_INFO_3_4_0),1,strTimFile); - *kl_pushp(u32,lImageIDList) = le32toh(ImageInfo.ImageID); - } - } - else if(TIM_3_5_00 == le32toh(TimHeader.VersionBind.Version)) - { - IMAGE_INFO_3_5_0 ImageInfo; - for (int i = 0; i < nImages; i++) - { - //fread (&ImageInfo,sizeof(IMAGE_INFO_3_5_0),1,hTimFile); - BinFileWtp_ReadBinFile(&gBinFileWtp,&ImageInfo,sizeof(IMAGE_INFO_3_5_0),1,strTimFile); - *kl_pushp(u32,lImageIDList) = le32toh(ImageInfo.ImageID); - } - } - else - { - printf(_T("\nTim Version is unknown:0X%X\n"),TimHeader.VersionBind.Version); - kl_destroy(u32, lImageIDList); - return FALSE; - } - - CloseFilePtr(&hTimFile); - - //���image Id�Ƿ������TIM�� - BOOL bFoundInTim = FALSE; - for (t_ImageFileListIter ite = kl_begin(kl_val(DDRDownloadIMGIter)->ImageFileList); ite != kl_end(kl_val(DDRDownloadIMGIter)->ImageFileList); ite = kl_next(ite)) - { - if (TIMH == kl_val(ite).nFileType) - { - continue; - } - - FILE* fpFile = NULL;//_tfopen(ite->strImageFile.c_str(), _T("rb")); - UINT32 dwImageId; - //fread(&dwImageId, sizeof(UINT32), 1, fpFile); - BinFileWtp_FseekBin(&gBinFileWtp,kl_val(ite).strImageFile,0L,SEEK_SET); - BinFileWtp_ReadBinFile(&gBinFileWtp,&dwImageId, sizeof(UINT32), 1, kl_val(ite).strImageFile); - dwImageId = le32toh(dwImageId); - - kl_val(ite).nFileType = dwImageId; - CloseFilePtr(&fpFile); - - BOOL bFound = FALSE; - for (kliter_t(u32) *imgIdIte = kl_begin(lImageIDList); imgIdIte != kl_end(lImageIDList);imgIdIte = kl_next(imgIdIte)) - { - if (kl_val(imgIdIte) == dwImageId) - { - bFound = TRUE; - } - } - - if (!bFound) - { - printf(_T("Tim don't contain ImageId 0X%X, imageFile:%s"), dwImageId,kl_val(ite).strImageFile); - kl_destroy(u32, lImageIDList); - return FALSE; - } - } - - //���TIM�а�����image�Ƿ���� - for (kliter_t(u32) * ite = kl_begin(lImageIDList); ite != kl_end(lImageIDList); ite = kl_next(ite)) - { - BOOL bFound = FALSE; - for (t_ImageFileListIter imgFileListIte = kl_begin(kl_val(DDRDownloadIMGIter)->ImageFileList);\ - imgFileListIte != kl_end(kl_val(DDRDownloadIMGIter)->ImageFileList);\ - imgFileListIte = kl_next(imgFileListIte)) - { - if (kl_val(ite) == kl_val(imgFileListIte).nFileType) - { - bFound = TRUE; - } - } - - if (!bFound) - { - printf(_T("Tim contains imageId 0X%X, but the image file don't exist."),*ite); - kl_destroy(u32, lImageIDList); - return FALSE; - } - } - DDRDownloadIMGIter = kl_next(DDRDownloadIMGIter); - } - kl_destroy(u32, lImageIDList); - return TRUE; -} - - -BOOL WtptpDownLoad_UploadDataFromTarget(struct CWtptpDownLoad *me,PDEVICE pDev) -{ - if(pDev->ThreadExit==STOPFLAG) - { - printf(_T("Thread is to be exit")); - return FALSE; - } - - _tcscpy(pDev->szCurrentMsg,_T("Enter into UploadDataFromTarget.....")); - pDev->kProState = kProcDebugLog; - WtptpDownLoad_AddDisplayInfoDevice(me,pDev); - WtptpDownLoad_Report(me); - tfprintf (pDev->hLog,_T("%s"),pDev->szCurrentMsg); - - MESSAGE_MODES currentMessageMode = DISABLED; - WTPSTATUS WtpStatus = {0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00}; - isFastDownload (pDev->pWtpComm,SET, TRUE); - tfprintf (pDev->hLog,_T("Enter Upload Data\n")); - eProcessState eProcState; - long uiAllimgsize=0; - long uiUploadsize=0; - SetPacketSize(pDev->pWtpComm,USBPACKETSIZE); - int retryAttempts = 3; - tfprintf (pDev->hLog,_T("\nBegin OpenUsbPort\n")); - fflush(pDev->hLog); - if (!OpenUsbPort (pDev->pWtpComm)) - { - _tcscpy(pDev->szCurrentMsg,_T("Can not open USB.....")); - pDev->kProState = kProcDebugLog; - WtptpDownLoad_AddDisplayInfoDevice(me,pDev); - WtptpDownLoad_Report(me); - tfprintf (pDev->hLog,_T("%s"),pDev->szCurrentMsg); - - return FALSE; - } - else - SetPortType(pDev->pWtpComm,0);//set usb port as default - - _tcscpy(pDev->szCurrentMsg,_T("Waiting for Uploading data...")); - pDev->kProState = kProcDebugLog; - WtptpDownLoad_AddDisplayInfoDevice(me,pDev); - WtptpDownLoad_Report(me); - - if(me->m_bCustPreamble) - { - tprintf (_T("\nCustomize Preamble Mode\n")); - } - else - { - tprintf (_T("\nOriginal Preamble Mode\n")); - } - - - t_UpLoadDataSpecIter iter; - iter = kl_begin(*me->m_lpUpLoadDataSpecList); - UPLOAD_DATA_SPEC* pUploadSpec = NULL; - while ( iter != kl_end(*me->m_lpUpLoadDataSpecList) ) - { - - if (!SendPreamble(pDev->pWtpComm,me->m_bCustPreamble)) - { - return FALSE; - } - else - { - - PROTOCOL_VERSION TargetProtocolVersion; - memset( &TargetProtocolVersion, 0, sizeof(TargetProtocolVersion) ); - if ( GetProtocolVersion (pDev->pWtpComm, &TargetProtocolVersion ) ) - { - if ( TargetProtocolVersion.MajorVersion >= TARGET_PROTOCOL_VERSION.MajorVersion - && TargetProtocolVersion.MinorVersion >= TARGET_PROTOCOL_VERSION.MinorVersion - && TargetProtocolVersion.Build >= TARGET_PROTOCOL_VERSION.Build ) - { - TARGET_PARAMS TargetParams; - if (GetParameters(pDev->pWtpComm, &TargetParams ) ) - { - - pUploadSpec = kl_val(iter); - UINT32 OriginalUploadBytes = pUploadSpec->m_Params.DataSize; - - tprintf (_T("\n")); - tprintf (_T("\n")); - tprintf (_T("Uploading:\n")); - tprintf (_T("Type: %d\n"), kl_val(iter)->m_Params.Type); - tprintf (_T("SubType: %d\n"), kl_val(iter)->m_Params.SubType ); - tprintf (_T("Partition: %d\n"), kl_val(iter)->m_Params.Partition ); - if(FLASH_EMMC==me->m_FlashType) - { - tprintf (_T("Offset: %d\n"), (kl_val(iter)->m_Params.Offset*512)); - } - else - { - tprintf (_T("Offset: %d\n"), (kl_val(iter)->m_Params.Offset)); - } - tprintf (_T("DataSize: %d\n"), kl_val(iter)->m_Params.DataSize); - tprintf (_T("Upload Save file name is: %s\n"), kl_val(iter)->strOutputFileName.s); - tprintf (_T("ResetUE: %d\n"), (kl_val(iter)->m_Params.ResetUE)); - tprintf (_T("ResetTimeDelay: %d\n"), kl_val(iter)->m_Params.ResetTimeDelay); - tprintf (_T("\n")); - tprintf (_T("\n")); - tfprintf (pDev->hLog,_T("Uploading:\n")); - tfprintf (pDev->hLog,_T("Type: %d\n"), kl_val(iter)->m_Params.Type); - tfprintf (pDev->hLog,_T("SubType: %d\n"), kl_val(iter)->m_Params.SubType ); - tfprintf (pDev->hLog,_T("Partition: %d\n"), kl_val(iter)->m_Params.Partition ); - if(FLASH_EMMC==me->m_FlashType) - { - tfprintf (pDev->hLog,_T("Offset: %d\n"), (kl_val(iter)->m_Params.Offset*512)); - } - else - { - tfprintf (pDev->hLog,_T("Offset: %d\n"), (kl_val(iter)->m_Params.Offset)); - } - tfprintf (pDev->hLog,_T("DataSize: %d\n"), kl_val(iter)->m_Params.DataSize); - tfprintf (pDev->hLog,_T("ResetUE: %d\n"), (kl_val(iter)->m_Params.ResetUE)); - tfprintf (pDev->hLog,_T("ResetTimeDelay: %d\n"), kl_val(iter)->m_Params.ResetTimeDelay); - fflush(pDev->hLog); - TCHAR szOutPutFileName[MAX_PATH] = {0}; - TCHAR szComFileName[MAX_PATH] = {0}; - strncpy( szOutPutFileName, pUploadSpec->strOutputFileName.s, MAX_PATH ); - tfprintf (pDev->hLog,_T("Output File: %s\n"), szOutPutFileName); - //begin to save upload data into FILE - FILE* ofs = NULL; - if (pUploadSpec->bCreateNewFile) - { - ofs = fopen(szOutPutFileName,"a+"); - } - else - { - ofs = fopen(szOutPutFileName,"a+"); - } - if ( ofs == NULL ) - { - tfprintf (pDev->hLog,_T("Can't open file: %s\n"), szOutPutFileName); - return FALSE; - } - - strncpy( szComFileName, pUploadSpec->strComparisonFileName.s, MAX_PATH); - tfprintf (pDev->hLog,_T("Comparison File: %s\n"), szComFileName); - TCHAR Msg[1024]; - sprintf(Msg,_T("Begin to upload data from 0x%x to 0x%x to file %s"),kl_val(iter)->m_Params.Offset*512,kl_val(iter)->m_Params.Offset*512+kl_val(iter)->m_Params.DataSize,szOutPutFileName); - tfprintf (pDev->hLog,_T("%s"),Msg); - //Report(kProcDebugLog, Msg, pDev); - - if ( UploadDataHeader(pDev->pWtpComm, &pUploadSpec->m_Params ) ) - { - unsigned int UploadBytes = pUploadSpec->m_Params.DataSize; - if(me->m_nFlashDataPageSize>0&&pUploadSpec->m_Params.IncludeSpareAreas==UPLOAD_WITH_SPAREAREA) - { - UploadBytes +=(((int)(UploadBytes)/me->m_nFlashDataPageSize))*(me->m_nFlashDataPageSize/32); - } - unsigned int BytesRemaining = UploadBytes; - tfprintf (pDev->hLog,_T("\n All Bytes to upload is %d\n"),BytesRemaining); - unsigned int BytesWritten = 0; - unsigned int uiWholesize = BytesRemaining; - unsigned int BytesReceived = 0; - unsigned int uiBufferLength = 0; - if(pUploadSpec->m_Params.IncludeSpareAreas==UPLOAD_WITH_SPAREAREA) - { - sprintf(Msg,_T("\nUploading data with Spare Area from 0x%x to 0x%x to file %s\n"),kl_val(iter)->m_Params.Offset*512,kl_val(iter)->m_Params.Offset*512+OriginalUploadBytes,szOutPutFileName); - } - else - { - sprintf(Msg,_T("\nUploading data from 0x%x to 0x%x to file %s\n"),kl_val(iter)->m_Params.Offset*512,kl_val(iter)->m_Params.Offset*512+OriginalUploadBytes,szOutPutFileName); - } - - //Report(kProcDebugLog, Msg, pDev); - tprintf (_T("%s"),Msg); - BYTE* pUploadDataBuffer = (BYTE*) malloc(sizeof(BYTE)*8186); - WTPSTATUS* pWtpStatus = (WTPSTATUS*)malloc(sizeof(WTPSTATUS)); - while ( BytesRemaining > 0 ) - { - uiBufferLength = ( BytesRemainingpWtpComm, pUploadDataBuffer, uiBufferLength,pWtpStatus)) - { - - tprintf (_T("Error: Upload Failed!\n")); - free(pUploadDataBuffer); - - UINT32 ReturnCode = 0; - int i ; - for ( i = 0; i < 4; i++) - { - ReturnCode |= pWtpStatus->Data[i] << (8 * i); - } - if((pWtpStatus->DLEN >0)) - { - tfprintf (pDev->hLog,_T("\nAbort in upload data because of MESSAGE ERRORCODE \n")); - //ReportError(eProcState = kProcDebugLog, stBurningFlashError,_T("Upload data Error"), pDev,ReturnCode); - TCHAR szMessage[1024]; - tprintf (_T(" ERROR CODE: %X\n"), ReturnCode ); - //tfprintf (pDev->hLog,szMessage); - return FALSE; - - } - return FALSE; - } - else - { - fwrite(pUploadDataBuffer,sizeof(BYTE),uiBufferLength,ofs); - BytesWritten +=uiBufferLength; - double percentage; - BytesReceived += uiBufferLength; - percentage=(double)(BytesReceived)/(double)uiWholesize; - int nPercent = percentage*100; - tprintf (_T("Uploading file percentage is:%d\r"), nPercent); - BytesRemaining -= uiBufferLength; - - } - } - } - - free(pWtpStatus); - pWtpStatus = NULL; - tprintf(_T("Finish to upload data to file %s\n"),szOutPutFileName); - - //Report(kProcDebugLog, Msg, pDev); - free(pUploadDataBuffer); - - tfprintf (pDev->hLog,_T("Finish saving upload data file %s!\n"),szOutPutFileName); - fflush(pDev->hLog); - - } - else - { - tfprintf (pDev->hLog,_T("UploadDataheader Failed!\n")); - tprintf (_T("UploadDataheader Failed!\n")); - return FALSE; - } - - fclose(ofs); - - iter = kl_next(iter); - if(!Done(pDev->pWtpComm)) - { - tprintf(_T("Done CMD failed in Upload\n")); - break; - } - - - } - else - { - tfprintf (pDev->hLog,_T("GetParameters failed.....\n")); - tprintf(_T("GetParameters failed.....\n")); - return FALSE; - - } - } - - } - else - { - tfprintf (pDev->hLog,_T("GetProtocolVersion failed.....\n")); - tprintf(_T("GetProtocolVersion failed.....\n")); - return FALSE; - } - } - } - tfprintf (pDev->hLog ,_T("Upload procedure finished\n")); - fflush(pDev->hLog); - tprintf (_T("Upload procedure finished\n")); - WTPSTATUS WTPStatus = {0x00, 0x00, 0x00, 0x01, 0x00, 0x00}; - Disconnect(pDev->pWtpComm,&WTPStatus); - - return TRUE; -} - - - -UINT32 WtptpDownLoad_GetWTPTPMSGReturnCode(struct CWtptpDownLoad *me,WTPSTATUS *pWtpStatus) -{ - UINT32 ReturnCode = 0; - int i ; - for ( i = 0; i < 4; i++) - { - ReturnCode |= pWtpStatus->Data[i+2] << (8 * i); - } - return ReturnCode; -} -BOOL WtptpDownLoad_ValidateWTPTPMSGReport(struct CWtptpDownLoad *me,PDEVICE pDev, WTPSTATUS *pWtpStatus, UINT32 *ReturnCode) -{ - *ReturnCode = 0; - int i ; - for ( i = 0; i < 4; i++) - { - *ReturnCode |= pWtpStatus->Data[i+2] << (8 * i); - } - - if(pWtpStatus->Data[0]== WTPTPNOTIFICATION) - { - BOOL bFound = FALSE; - for (i = 0; i < MAXNOTIFICATIONSCODES; i++) - { - if (WTPTPNotificationMsg[i].NotificationCode == *ReturnCode) - { -#ifndef COMPRESSDATA - tfprintf (pDev->hLog,_T("\nWTPTP Notification: %s ,Notification code is :0x%X\n"),WTPTPNotificationMsg[i].Description,*ReturnCode); -#else - tfprintf (pDev->hLog,_T("\nWTPTP Notification code is :0x%X\n"),*ReturnCode); -#endif - fflush(pDev->hLog); - bFound = TRUE; - break;; - } - - } - if(!bFound) - { - TCHAR Msg[1024]; - sprintf(Msg,_T("\nNotification Code: 0x%X\n"),*ReturnCode); - tfprintf (pDev->hLog,_T("%s"),Msg); - fflush(pDev->hLog); - } - - if((*ReturnCode == PlatformEraseAllFlash)&&(!me->m_bEraseAllFlash)) - { - - tfprintf (pDev->hLog,_T("\n Do unexpected erase all flash in OBM\n")); - fflush(pDev->hLog); - return FALSE; - - } - - if((*ReturnCode == PlatformResetBBT)&&(!me->m_bResetBBT)) - { - - tfprintf (pDev->hLog,_T("\n Do unexpected ResetBBT in OBM\n")); - fflush(pDev->hLog); - return FALSE; - - } - return TRUE; - } - else if(pWtpStatus->Data[0]== WTPTPERRORREPORT) - { - TCHAR szMessage[1024]; - BOOL bFound = FALSE; - for (i = 0; i < MAXNOTIFICATIONSCODES; i++) - { - if (WTPTPErrorCodes[i].ErrorCode == *ReturnCode) - { - #ifndef COMPRESSDATA - sprintf (szMessage,_T("\nWTPTP Error: %s 0x%X\n"),WTPTPErrorCodes[i].Description,*ReturnCode ); - #else - sprintf (szMessage,_T("\nWTPTP Error: 0x%X\n"),*ReturnCode ); - #endif - tfprintf (pDev->hLog,_T("%s"),szMessage); - fflush(pDev->hLog); - bFound = TRUE; - break; - } - } - tfprintf (pDev->hLog,_T("%s"),szMessage); - return FALSE; - - } - return TRUE; -} - -BOOL WtptpDownLoad_WTPTPDownLoad(struct CWtptpDownLoad *me,PDEVICE pDev) -{ -#if PRINTLOG - tprintf(_T("Enter into WTPTPDownLoad\n")); -#endif - if(pDev->ThreadExit==STOPFLAG) - { - tfprintf(pDev->hLog,_T("Thread is to be exit")); - fflush(pDev->hLog); - return FALSE; - } - - pDev->kProState = kProcDebugLog; - _tcscpy(pDev->szCurrentMsg,_T("Enter into WTPTPDownLoad....")); - WtptpDownLoad_AddDisplayInfoDevice(me,pDev); - WtptpDownLoad_Report(me); - tfprintf (pDev->hLog,_T("%s"),pDev->szCurrentMsg); - - MESSAGE_MODES currentMessageMode = DISABLED; - WTPSTATUS WtpStatus = {0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00}; - isFastDownload (pDev->pWtpComm,SET, TRUE); - tfprintf (pDev->hLog,_T("Enter WTPTPDownload\n")); - fflush(pDev->hLog); - if(me->m_bEraseAllFlash) - { - tfprintf (pDev->hLog,_T("Erase all flag FBF file\n")); - } - if(me->m_bResetBBT) - { - tfprintf (pDev->hLog,_T("Reset flag in FBF file\n")); - } - if(me->m_bGetBadBlk) - { - tfprintf (pDev->hLog,_T("Flash bad block report is enabled in FBF file\n")); - } - if(me->m_bImageCrcEnable) - { - tfprintf (pDev->hLog,_T("Image Crc report is enabled in FBF file\n")); - } - t_ImageFileList *pimgfilesList; - if(pDev->nDevType == kBootLoader) - { - pimgfilesList = me->m_plBootLoaderImageList; - } - else if(pDev->nDevType == kBootRom) - { - pimgfilesList = me->m_plBootRomImageList; - } - else - { - return FALSE; - } - - FILE* hFile; - eProcessState eProcState; - TCHAR szFileName[MAX_PATH]; - UINT64 uiAllimgsize=0; - UINT64 uidownloadsize=0; - UINT32 uiCurrentFileSize = 0; - for (t_ImageFileListConstIter ite = kl_begin(*pimgfilesList); ite != kl_end(*pimgfilesList); ite = kl_next(ite)) - { - if(TIMH == kl_val(ite).nFileType) - { - //uiAllimgsize += GetFileSize(ite->strImageFile.c_str()); - uiAllimgsize += BinFileWtp_GetFileSize(&gBinFileWtp,kl_val(ite).strImageFile); - } - else - { - //uiAllimgsize += GetFileSize(ite->strImageFile.c_str()) - IMAGEID_LEN; - uiAllimgsize += BinFileWtp_GetFileSize(&gBinFileWtp,kl_val(ite).strImageFile) - IMAGEID_LEN; - } - } - - SetPacketSize(pDev->pWtpComm,USBPACKETSIZE); - - //FileIndex = nImages; // Just in case user supplies more files than required - BOOL retry=TRUE; - int retryAttempts = 3; - tfprintf (pDev->hLog,_T("\nBegin OpenUsbPort\n")); - SetPortType(pDev->pWtpComm,0);//set usb port as default - - - pDev->kProState = kProcDebugLog; - _tcscpy(pDev->szCurrentMsg,_T("Start Image Downloading...")); - WtptpDownLoad_AddDisplayInfoDevice(me,pDev); - WtptpDownLoad_Report(me); - tfprintf (pDev->hLog,_T("%s"),pDev->szCurrentMsg); - - if(me->m_bCustPreamble) - { - tfprintf (pDev->hLog,_T("\nCustomize Preamble Mode\n")); - } - else - { - tfprintf (pDev->hLog,_T("\nOriginal Preamble Mode\n")); - } - fflush(pDev->hLog); - - int nImageNum = kl_size(stifl,*pimgfilesList); - for (int i = 0; i < nImageNum; ++i) - { - if(pDev->ThreadExit == STOPFLAG) - { - return FALSE; - } - - if(0 != GetLinuxDev(pDev->pWtpComm)->hDevHandle) - { - char strDownloadImgName[256]; - if (WtptpDownLoad_DownloadImage (me,pDev,i, pimgfilesList,uiAllimgsize,&uidownloadsize,nImageNum,strDownloadImgName) == FALSE) - { - - tfprintf (pDev->hLog,_T("\nRetry to DownloadImage: %s\n"),strDownloadImgName); - return FALSE; - } - else //Download completed - { - - if(i!=0&&pDev->nDevType == kBootLoader) - { - - WTPSTATUS *pWtpStatus = (WTPSTATUS*)malloc(sizeof(WTPSTATUS)); - hFile = NULL;//_tfopen(strDownloadImgName.c_str(),_T("rb")); - double npercent; - BOOL bIsEraseAllDone = FALSE; - BOOL bIsEraseAllOnlyDone = FALSE; - //fseek (hFile,0L,SEEK_END); - BinFileWtp_FseekBin(&gBinFileWtp,strDownloadImgName,0L,SEEK_END); - if(i==0) - { - uiCurrentFileSize = BinFileWtp_GetFileSize(&gBinFileWtp,strDownloadImgName); - //uiCurrentFileSize = ftell(hFile); - } - else - { - uiCurrentFileSize = BinFileWtp_GetFileSize(&gBinFileWtp,strDownloadImgName) - 4; - //uiCurrentFileSize = ftell(hFile)-4; - } - long uiDownloadSize = 0; - UINT32 WtptpReturnCode = 0; - UINT32 uiBurntSize = 4096;// first sector is no need to burnt to falsh , so add this size - //fclose(hFile); - - tfprintf (pDev->hLog,_T("\nBegin Buring image %s,size %d\n"),strDownloadImgName,uiCurrentFileSize); - - pWtpStatus->Status = ACK; - - switch(me->m_ePlatformType) - { - case PLAT_PXA92x: - { - tfprintf (pDev->hLog,_T("\n PXA92x burning flash.... \n")); - fflush(pDev->hLog); - while (pWtpStatus->Status == ACK) - { - - - if(pDev->ThreadExit == STOPFLAG) - { - pDev->kProState = kProcAborting; - WtptpDownLoad_AddDisplayInfoDevice(me,pDev); - WtptpDownLoad_Report(me); - free(pWtpStatus); - pWtpStatus = NULL; - return FALSE; - } - if (! GetWtpMessage (pDev->pWtpComm,pWtpStatus)) - { - break; - } - else - { - - if(pWtpStatus->Data[0]>ERRORFLAG) - { - tfprintf (pDev->hLog,_T("\nAbort becasue of MESSAGE ERRORCODE \n")); - TCHAR szMessage[1024]; - sprintf (szMessage,_T(" ERROR CODE: %X\n"), pWtpStatus->Data[0] ); - tfprintf (pDev->hLog,_T("%s"),szMessage); - fflush(pDev->hLog); - free(pWtpStatus); - pWtpStatus = NULL; - return FALSE; - } - } - // This is to add a delay for WTPTP while the flash is being erased by DKB. - if (pWtpStatus->Data[0] == PXA92x_PlatformBusy ) - { - pDev->kProState = kProcDebugLog; - _tcscpy(pDev->szCurrentMsg,_T("Begin Burning flash...")); - WtptpDownLoad_AddDisplayInfoDevice(me,pDev); - WtptpDownLoad_Report(me); - tfprintf (pDev->hLog,_T("%s"),pDev->szCurrentMsg); - fflush(pDev->hLog); - pDev->kProState=kProcBurningFlash; - unsigned long int DelayTime_tmp = 0; - do - { - - GetWtpMessage( pDev->pWtpComm,pWtpStatus); - if(pWtpStatus->Data[0]>ERRORFLAG) - { - tfprintf (pDev->hLog,_T("\nAbort becasue of MESSAGE ERRORCODE \n")); - TCHAR szMessage[1024]; - sprintf (szMessage,_T(" ERROR CODE: %X\n"), pWtpStatus->Data[0] ); - tfprintf (pDev->hLog,_T("%s"),szMessage); - fflush(pDev->hLog); - free(pWtpStatus); - pWtpStatus = NULL; - return FALSE; - } - if ( pWtpStatus->Data[0] == PXA92x_PlatformDisconnect ) - break; - if(pDev->ThreadExit == STOPFLAG) - { - pDev->kProState = kProcAborting; - WtptpDownLoad_AddDisplayInfoDevice(me,pDev); - WtptpDownLoad_Report(me); - free(pWtpStatus); - pWtpStatus = NULL; - return FALSE; - } - - if(DelayTime_tmp>2000*5000) - { - tfprintf (pDev->hLog,_T("\nBurning flash timeout\n")); - fflush(pDev->hLog); - break; - } - usleep(1000000); - npercent= (double)uiDownloadSize*100/(double)uiCurrentFileSize; - uiDownloadSize +=me->m_nBurningSpeed*1000; - - pDev->kProState = kProcBurningFlash; - pDev->npercent = (int)npercent; - WtptpDownLoad_AddDisplayInfoDevice(me,pDev); - WtptpDownLoad_Report(me); - DelayTime_tmp += 1000; - } - while(pWtpStatus->Data[0] != PXA92x_PlatformReady); - } - if ( pWtpStatus->Data[0] == PXA92x_PlatformDisconnect ) - { - tfprintf (pDev->hLog,_T("\nAbort in Burnning flash\n")); - fflush(pDev->hLog); - pDev->kProState = kProcDebugLog; - _tcscpy(pDev->szCurrentMsg,_T("Abort in Burnning flash")); - WtptpDownLoad_AddDisplayInfoDevice(me,pDev); - WtptpDownLoad_Report(me); - free(pWtpStatus); - pWtpStatus = NULL; - return FALSE; - } - - if ( pWtpStatus->Data[0] == PXA92x_PlatformReady ) - { - npercent = 100; - pDev->kProState = kProcBurningFlash; - pDev->npercent = (int)npercent; - WtptpDownLoad_AddDisplayInfoDevice(me,pDev); - WtptpDownLoad_Report(me); - tfprintf (pDev->hLog,_T("\nBurnning flash Successfully\n")); - fflush(pDev->hLog); - - break; - } - - } - } - break; - default: - { - - while (pWtpStatus->Status == ACK) - { - - if(pDev->ThreadExit == STOPFLAG) - { - pDev->kProState = kProcAborting; - WtptpDownLoad_AddDisplayInfoDevice(me,pDev); - WtptpDownLoad_Report(me); - free(pWtpStatus); - pWtpStatus = NULL; - return FALSE; - } - - - if (! GetWtpMessage (pDev->pWtpComm,pWtpStatus)) - { - tfprintf (pDev->hLog,_T("\nGetWtpMessage failed before burning flash\n")); - fflush(pDev->hLog); - break; - if((pWtpStatus->DLEN >0)) - { - if(! WtptpDownLoad_ValidateWTPTPMSGReport(me,pDev,pWtpStatus,&WtptpReturnCode)) - { - free(pWtpStatus); - pWtpStatus = NULL; - return FALSE; - } - } - } - // This is to add a delay for WTPTP while the flash is being erased by DKB. - if (WtptpDownLoad_GetWTPTPMSGReturnCode(me,pWtpStatus)== PlatformBusy ) - { - - pDev->kProState = kProcDebugLog; - _tcscpy(pDev->szCurrentMsg,_T("Begin Burning flash...")); - WtptpDownLoad_AddDisplayInfoDevice(me,pDev); - WtptpDownLoad_Report(me); - tfprintf (pDev->hLog,_T("%s"),pDev->szCurrentMsg); - fflush(pDev->hLog); - - - - pDev->kProState=kProcBurningFlash; - unsigned long int DelayTime_tmp = 0; - UINT32 FlashSize = 0; - do - { - - if(pDev->ThreadExit == STOPFLAG) - { - pDev->kProState = kProcAborting; - WtptpDownLoad_AddDisplayInfoDevice(me,pDev); - WtptpDownLoad_Report(me); - free(pWtpStatus); - pWtpStatus = NULL; - return FALSE; - } - - if(!GetWtpMessage(pDev->pWtpComm,pWtpStatus)) - { - tfprintf (pDev->hLog,_T("\nGetWtpMessage failed\n")); - fflush(pDev->hLog); - free(pWtpStatus); - pWtpStatus = NULL; - return FALSE; - } - else - { - - if((pWtpStatus->DLEN >0)) - { - if(!WtptpDownLoad_ValidateWTPTPMSGReport(me,pDev,pWtpStatus,&WtptpReturnCode)) - { - free(pWtpStatus); - pWtpStatus = NULL; - return FALSE; - } - - else - { - if(pWtpStatus->Data[0]== WTPTPNOTIFICATION_BURNTSIZE) - { - uiBurntSize+=WtptpReturnCode; - // make a round to burnt size to multiple of 4096(FBF_Sector size) - if(uiBurntSize%4096) - { - uiBurntSize+=((4096-(uiBurntSize%4096))); - } - WtptpReturnCode = 0; - npercent= (double)uiBurntSize/(double)uiCurrentFileSize; - npercent = npercent*100; - uiDownloadSize =uiBurntSize; - - pDev->npercent = (int)npercent; - WtptpDownLoad_AddDisplayInfoDevice(me,pDev); - WtptpDownLoad_Report(me); - } - if((WtptpReturnCode == PlatformEraseAllFlashDone)) - { - bIsEraseAllDone = TRUE; - - } - - if((WtptpReturnCode == PlatformEraseAllFlashWithoutBurnDone)) - { - bIsEraseAllOnlyDone = TRUE; - - } - - - - } - - } - - } - - if(DelayTime_tmp>2000*5000) - { - tfprintf (pDev->hLog,_T("\nBurning flash timeout\n")); - fflush(pDev->hLog); - break; - } - usleep(1000000); - DelayTime_tmp += 1000; - - if(me->m_bEraseAllFlash&&(!bIsEraseAllDone)&&(i==1)) - { - - if(FLASH_SPINOR==me->m_FlashType) - { - if(FlashSize == 0x2000000)//32M - npercent+=SPINOR_32M_ERASE_SPEED; - else - npercent+=SPINOR_16M_ERASE_SPEED; - } - else if(FLASH_EMMC == me->m_FlashType) - { - npercent+=EMMC_ERASE_SPPED; - } - else if(FLASH_SPINAND==me->m_FlashType) - { - npercent+=EMMC_ERASE_SPPED; - } - else - npercent+=NAND_ERASE_SPPED; - pDev->kProState = kProcEraseAllFlash; - pDev->npercent = (int)npercent; - WtptpDownLoad_AddDisplayInfoDevice(me,pDev); - - } - - if(me->m_bEraseAllFlashOnly&&(!bIsEraseAllOnlyDone)&&(i==1)) - { - - - if(FLASH_SPINOR==me->m_FlashType) - { - if(FlashSize == 0x2000000)//32M - npercent+=SPINOR_32M_ERASE_SPEED; - else - npercent+=SPINOR_16M_ERASE_SPEED; - } - else if(FLASH_EMMC == me->m_FlashType) - { - npercent+=EMMC_ERASE_SPPED; - } - else if(FLASH_SPINAND==me->m_FlashType) - { - npercent+=EMMC_ERASE_SPPED; - } - else - npercent+=NAND_ERASE_SPPED; - pDev->kProState = kProcEraseAllFlash; - pDev->npercent = (int)npercent; - WtptpDownLoad_AddDisplayInfoDevice(me,pDev); - - } - - - else - { - npercent= (double)uiDownloadSize*100/(double)uiCurrentFileSize; - uiDownloadSize +=me->m_nBurningSpeed*1000; - - pDev->kProState = kProcBurningFlash; - pDev->npercent = (int)npercent; - WtptpDownLoad_AddDisplayInfoDevice(me,pDev); - } - WtptpDownLoad_Report(me); - - if ( WtptpDownLoad_GetWTPTPMSGReturnCode(me,pWtpStatus) == PlatformDisconnect ) - break; - - } - while(WtptpDownLoad_GetWTPTPMSGReturnCode(me,pWtpStatus) != PlatformReady); - } - if ( WtptpDownLoad_GetWTPTPMSGReturnCode(me,pWtpStatus) == PlatformDisconnect ) - { - tfprintf (pDev->hLog,_T("\nPlatformDisconnect\n")); - fflush(pDev->hLog); - pDev->kProState = kProcDebugLog; - _tcscpy(pDev->szCurrentMsg,_T("PlatformDisconnect")); - WtptpDownLoad_AddDisplayInfoDevice(me,pDev); - WtptpDownLoad_Report(me); - tfprintf (pDev->hLog,_T("%s"),pDev->szCurrentMsg); - fflush(pDev->hLog); - free(pWtpStatus); - pWtpStatus = NULL; - return FALSE; - } - - if ( WtptpDownLoad_GetWTPTPMSGReturnCode(me,pWtpStatus) == PlatformReady ) - { - - npercent = 100; - pDev->kProState = kProcBurningFlash; - pDev->npercent = (int)npercent; - WtptpDownLoad_AddDisplayInfoDevice(me,pDev); - WtptpDownLoad_Report(me); - - - tfprintf (pDev->hLog,_T("\nBurnning flash Successfully\n")); - fflush(pDev->hLog); - break; - } - - } - } - break; - } - - free(pWtpStatus); - pWtpStatus = NULL; - } - } - - } - else - { - tfprintf (pDev->hLog,_T("\nIOThead is not exist\n")); - fclose (pDev->hLog); - return FALSE; - } - } - - WTPSTATUS WTPStatus = {0x00, 0x00, 0x00, 0x01, 0x00, 0x00}; - - if(me->m_bImageCrcEnable && (!me->m_bEraseAllFlashOnly)) - { - tfprintf (pDev->hLog,_T("\nGetting ImageCrc...\n")); - fflush(pDev->hLog); - - if (!GetImageCrc(pDev->pWtpComm,&WTPStatus)) - { - _tcscpy(pDev->szCurrentMsg,_T("CRCERROR")); - pDev->kProState = kProcBurningFlash; - WtptpDownLoad_AddDisplayInfoDevice(me,pDev); - WtptpDownLoad_Report(me); - - tfprintf (pDev->hLog,_T("Error: GetImageCrc failed!\n")); - fflush(pDev->hLog); - //return FALSE;//Don't interrupt here, can do it in the mainfrm.cpp - } - else - { - pImageCRCInfo pImageCrc = (pImageCRCInfo)WTPStatus.Data; - memset(&pDev->DevImageCrc, 0, sizeof(ImageCRCInfo)); - memcpy(&pDev->DevImageCrc, pImageCrc, sizeof(ImageCRCInfo)); - _tcscpy(pDev->szCurrentMsg,_T("CRCS")); - pDev->kProState = kProcBurningFlash; - WtptpDownLoad_AddDisplayInfoDevice(me,pDev); - WtptpDownLoad_Report(me); - - fprintf(pDev->hLog, _T("\n MCPID: 0x%x, ImageNum: %d, "),le32toh(pImageCrc->MCPID), le32toh(pImageCrc->ImageNum)); - for(UINT32 i = 0; i < le32toh(pImageCrc->ImageNum); i++) - fprintf(pDev->hLog, _T("\n ImageID: 0x%x, CrcData: 0x%08X"),le32toh(pImageCrc->ImageCRC[i].ImageID), le32toh(pImageCrc->ImageCRC[i].CRC32)); - - } - } - - tfprintf (pDev->hLog,_T("\nBegin to disconnect\n")); - Disconnect(pDev->pWtpComm,&WTPStatus); - - if(kBootRom== pDev->nDevType && PLAT_EDEN_A0 == me->m_ePlatformType) - { - usleep(100000); //100ms - } - - tfprintf (pDev->hLog,_T("\nFinish to disconnect\n")); - fflush(pDev->hLog); - - _tcscpy(pDev->szCurrentMsg,_T("Finish to disconnect")); - pDev->kProState = kProcDebugLog; - WtptpDownLoad_AddDisplayInfoDevice(me,pDev); - WtptpDownLoad_Report(me); - - return TRUE; -} - - - - -BOOL WtptpDownLoad_TerminateBL(struct CWtptpDownLoad *me) -{ - if(!me->m_binitFlag) // there is no InitializeBL - return TRUE; -#if PRINTLOG - tprintf(_T("\nTerminateBL.....\n")); -#endif - pthread_mutex_lock(&me->Quit_mutex); - me->m_bTerminateDownload = TRUE; - me->m_bTerminateUSBDetect = TRUE; - pthread_mutex_unlock(&me->Quit_mutex); - - // kill all download thread for all device - usleep(2000000); - pthread_mutex_lock(&me->DeviceList_mutex); - for(t_DeviceIter iter = kl_begin(me->m_WtptpDeviceList);iter != kl_end(me->m_WtptpDeviceList); iter = kl_next(iter)) - { - if((kl_val(iter)) != NULL) - { - (kl_val(iter))->ThreadExit = STOPFLAG; - SetExitHandle((kl_val(iter))->pWtpComm,1); - usleep(2000000); - CloseUsbPort((kl_val(iter))->pWtpComm); - free((kl_val(iter))->pWtpComm); - (kl_val(iter))->pWtpComm = NULL; - free(kl_val(iter)); - } - } - pthread_mutex_unlock(&me->DeviceList_mutex); -#if PRINTLOG - tprintf(_T("\nplease wait .....\n")); -#endif - usleep(100000); - BinFileWtp_CloseBinFIle(&gBinFileWtp); - return TRUE; -} - -#if 0 -BOOL WtptpDownLoadInitializeBLEx(struct CWtptpDownLoad *me,PInstanceParams pInstParam,const TCHAR * pszBLFfileName ,const TCHAR * pszFBFTimFile,const TCHAR * pszFBFfileName) -{ -#ifdef PCIEDOWNLOAD - _tprintf(_T("\nInitializeBLEx parameter.....\n")); - - if(_tcslen(pszBLFfileName)==0) - { - _tprintf(_T("\nblf file is empty.....\n")); - return FALSE; - } - else - { - if(_taccess(pszBLFfileName,0)!=0) - { - _tprintf(_T("\n%s is not exist.....\n"),pszBLFfileName); - return FALSE; - } - - } - - - if(_tcslen(pszFBFTimFile)==0) - { - _tprintf(_T("\nFBF tim file is empty.....\n")); - return FALSE; - } - else - { - if(_taccess(pszFBFTimFile,0)!=0) - { - _tprintf(_T("\n%s is not exist.....\n"),pszFBFTimFile); - return FALSE; - } - - } - - if(_tcslen(pszFBFfileName)==0) - { - _tprintf(_T("\nFBF file is empty.....\n")); - return FALSE; - } - else - { - if(_taccess(pszFBFfileName,0)!=0) - { - _tprintf(_T("\n%s is not exist.....\n"),pszFBFfileName); - return FALSE; - } - - } - me->m_bOnlyOBMDownload = TRUE; - - CParser blfparser; - me->m_ePlatformType = blfparser.GetPlatFormType(pszBLFfileName); - me->m_FlashType = blfparser.GetFlashType(pszBLFfileName); - pInstParam->PlaformType = me->m_ePlatformType; - pInstParam->FlashType = me->m_FlashType; - // m_nFlashDataPageSize = pInstParam->FlashPageSize; - - /*tstring ss = pszFBFTimFile; - m_ImageList.push_back(ss); - ss = pszFBFfileName; - m_ImageList.push_back(ss);*/ - DDR_FLASH_DOWNLOADIMAGE_INFO_SPEC* lpDdrFlashDLImgInfoSpec = new DDR_FLASH_DOWNLOADIMAGE_INFO_SPEC(); - lpDdrFlashDLImgInfoSpec->pImagelist->push_back(new string(pszFBFTimFile)); - lpDdrFlashDLImgInfoSpec->pImagelist->push_back(new string(pszFBFfileName)); - pInstParam->pDownloadImagesList = new t_DdrFlashDownloadImgInfoList(); - pInstParam->pDownloadImagesList->push_back(lpDdrFlashDLImgInfoSpec); - - pInstParam->pszDKBbin = NULL; - pInstParam->pszDKBTim = NULL; - pInstParam->pszWTMFile = NULL; - pInstParam->pszOBMFile = NULL; - - pInstParam->PlaformType = (unsigned int)m_ePlatformType; - pInstParam->FlashType = (unsigned int)m_FlashType; - - eEraseAllMode m_eEraseAllFlash = (eEraseAllMode)blfparser.GetBlfInt(pszFLASH_OPTIONS,pszERASE_ALL_FLASH,0,pszBLFfileName); - BOOL m_bResetBBT = blfparser.GetBlfInt(pszFLASH_OPTIONS,pszRESET_BBT,-1,pszBLFfileName); - - unsigned int nCommand = 0; - if(m_eEraseAllFlash==ERASE_ALL_BEFOREBURNING) - { - nCommand|=DLCMD_DO_ERASE_ALL_FLASH_MSK; - } - if(m_bResetBBT) - { - nCommand|=DLCMD_DO_RESETBBT_MSK; - } - if(m_eEraseAllFlash==ERASE_ALL_WIHTOUTBURNING) - { - nCommand|=DLCMD_DO_ERASE_ALL_FLASH_ONLY_MSK; - } - - pInstParam->Commands =nCommand; - - - WtptpDownLoad_InitializeBL(me,pInstParam); -#endif - return TRUE; -} -#endif - - -BOOL WtptpDownLoad_InitializeBL(struct CWtptpDownLoad *me,PInstanceParams pInstParam) -{ - int iBootRomFileIndex = 0,iBootLoaderFileIndex=0; - me->m_nBootRomDevNum = 0; - me->m_nBootLoaderDevNum = 0; - readlink ("/proc/self/exe", me->m_szSWDPath, MAX_FILE_LENGTH); - TCHAR *p = _tcsrchr( me->m_szSWDPath,'/'); - if(p) *p = 0; -#if PRINTLOG - tprintf(_T("SWD Path is %s \n"),me->m_szSWDPath); - //getwd(m_szSWDPath); - tprintf(_T("Begin to initialize WTPTPDownload parameter\n")); -#endif - if (strlen(g_LogPath) > 0) - { - strncpy(me->m_szSWDPath,g_LogPath,_countof(me->m_szSWDPath)); - } - int res = pthread_mutex_init(&me->DeviceList_mutex,NULL); - if(res!=0) - { -#if PRINTLOG - perror(_T("DeviceList_mutex initialization failed")); -#endif - exit(EXIT_FAILURE); - } - /*res = pthread_mutex_init(&Device_mutex,NULL); - if(res!=0) - { - perror(_T("Device Mutex initialization failed")); - exit(EXIT_FAILURE); - }*/ - - res = pthread_mutex_init(&me->Quit_mutex,NULL); - if(res!=0) - { -#if PRINTLOG - perror(_T("Quit_mutex initialization failed")); -#endif - exit(EXIT_FAILURE); - } - - res = pthread_mutex_init(&me->callback_mutex,NULL); - if(res!=0) - { -#if PRINTLOG - perror(_T("callback_mutex initialization failed")); -#endif - exit(EXIT_FAILURE); - } - - - kl_clear(pdisl,me->m_DisplayInfoList); - me->m_lpInstParam = pInstParam; - me->m_nFlashDataPageSize = pInstParam->FlashPageSize; - me->m_ePlatformType = (ePlatForm)pInstParam->PlaformType; - me->m_FlashType = (eFlashType)pInstParam->FlashType; - - if(me->m_FlashType==FLASH_NAND) - { - me->m_nBurningSpeed = NAND_BURNNING_SPEED; - } - else if(me->m_FlashType==FLASH_EMMC) - { - me->m_nBurningSpeed = EMMC_BURNNING_SPEED; - } - else - { - me->m_nBurningSpeed = SPINOR_BURNNING_SPEED; - } - - me->m_bEraseAllFlash = (((pInstParam->Commands)&DLCMD_DO_ERASE_ALL_FLASH_MSK) ==DLCMD_DO_ERASE_ALL_FLASH_MSK)?TRUE:FALSE; - me->m_bEraseAllFlashOnly = (((pInstParam->Commands)&DLCMD_DO_ERASE_ALL_FLASH_ONLY_MSK) ==DLCMD_DO_ERASE_ALL_FLASH_ONLY_MSK)?TRUE:FALSE; - me->m_bResetBBT = (((pInstParam->Commands)&DLCMD_DO_RESETBBT_MSK) == DLCMD_DO_RESETBBT_MSK)?TRUE:FALSE; - me->m_bSingleDownload = (pInstParam->DownloadMode==1)?TRUE:FALSE; - me->m_bGetBadBlk = (pInstParam->GetBadBlk==1)?TRUE:FALSE; - me->m_bImageCrcEnable = (pInstParam->ImageCrcEn==1)?TRUE:FALSE; - memset(me->m_szPrimaryDkbPath,0,sizeof(me->m_szPrimaryDkbPath)); - memset(me->m_szPrimTimPath,0,sizeof(me->m_szPrimTimPath)); - memset(me->m_szOBMPath, 0, sizeof(me->m_szOBMPath)); - memset(me->m_szWTMPath, 0, sizeof(me->m_szWTMPath)); - memset(me->m_szTZIPath, 0 ,sizeof(me->m_szTZIPath)); - - me->m_lpUpLoadDataSpecList = me->m_lpInstParam->pUploadSpecs; - me->m_bDumpFlash = (((pInstParam->Commands)&DLCMD_DO_UPLOAD_DATA_MSK) ==DLCMD_DO_UPLOAD_DATA_MSK)?TRUE:FALSE; - me->m_uFlashBadBlockRate = pInstParam->ReservedVal[0];//坏块率门限 - - - if(me->m_bDumpFlash) - { - if (!WtptpDownLoad_prepareDumpFlashParam(me,pInstParam)) - { - printf (_T("prepareDumpFlashParam failed.\n")); - return FALSE; - } - } - else if(me->m_bEnabledJtag) - { - if (!WtptpDownLoad_prepareEnabledJtagImg(me,pInstParam)) - { - printf(_T("Prepare enabledJtag images failed.\n")); - return FALSE; - } - } - else - { - BinFileWtp_InitParameter(&gBinFileWtp); - if (!WtptpDownLoad_prepareDownloadImg(me,pInstParam)) - { -#if PRINTLOG - printf(_T("Prepared download image failed.")); -#endif - return FALSE; - } -#if PRINTLOG - printf(_T("\nParse DKB Tim image.\n")); -#endif - BinFileWtp_InitRead(&gBinFileWtp); - if (!WtptpDownLoad_ParseTim(me,&me->m_lBootRomImageWithDDRList)) - { - printf(_T("Parse DKB Tim failed.\n")); - return FALSE; - } -#if PRINTLOG - printf(_T("\nParse FBF Tim image.\n")); -#endif - if (!WtptpDownLoad_ParseTim(me,&me->m_lBootLoaderImageWithDDRList)) - { - printf(_T("Parse FBF Tim failed.\n")); - return FALSE; - } - } - - - me->m_binitFlag = TRUE; -#if PRINTLOG - tprintf(_T("\nComplete to Initilize parameter\n")); -#endif - fflush(stdout); - - res = pthread_create(&me->DetectThread, NULL,WtptpDownLoad_WtptpDeviceDetectThread ,me); - if(res!=0) - { -#if PRINTLOG - perror (_T("\nThread creation failed\n")); -#endif - return FALSE; - } - else - { -#if PRINTLOG - tprintf(_T("\nBegin to detect wtptp device....\n")); -#endif - } - fflush(stdout); - return TRUE; -} - - -BOOL WtptpDownLoad_prepareDumpFlashParam(struct CWtptpDownLoad *me,const PInstanceParams pInstParam) -{ -#if PRINTLOG - printf(_T("Prepare UpLoadDataSpecList for dump flash\n")); -#endif - if(NULL == pInstParam->pUploadSpecs || kl_size(pudsl,*pInstParam->pUploadSpecs)==0) - { - printf(_T(" Upload area list is NULL")); - return FALSE; - } - - - me->m_lpUpLoadDataSpecList = (t_UpLoadDataSpecList*)malloc(sizeof(t_UpLoadDataSpecList)); - (*me->m_lpUpLoadDataSpecList) = kl_init(pudsl); - for (t_UpLoadDataSpecIter iter = kl_begin(*pInstParam->pUploadSpecs); - iter != kl_end(*pInstParam->pUploadSpecs); - iter = kl_next(iter)) - { - pUPLOAD_DATA_SPEC pTmp; - pTmp = (UPLOAD_DATA_SPEC*)malloc(sizeof(UPLOAD_DATA_SPEC)); - *kl_pushp(pudsl,*me->m_lpUpLoadDataSpecList) = pTmp; - NewUPLOAD_DATA_SPEC(pTmp,kl_val(iter)); - } - - return TRUE; -} - -BOOL WtptpDownLoad_prepareEnabledJtagImg(struct CWtptpDownLoad *me,const PInstanceParams pInstParam) -{ -#if PRINTLOG - printf(_T("Prepare BR images for enabled Jtag\n")); -#endif - int nJtagEnabledImgIdx = 0; - if (pInstParam->pszDKBTim) //check if user enter any security file path. - { - if (!IsFileExist(pInstParam->pszDKBTim)) - { - tprintf(_T("DKBTim file %s is not exist"),pInstParam->pszDKBTim); - return FALSE; - } - struct stImageFile stTmp; - stTmp.nFileType = TIMH; - stTmp.strImageFile = pInstParam->pszDKBTim; - *kl_pushp(stifl,*me->m_plJtagEnabledImageList) = stTmp; - } - else - { - tprintf(_T("Miss Timheader image in re-enabled jtag.")); - return FALSE; - } - - if (pInstParam->pszDKBbin) - { - if (!IsFileExist(pInstParam->pszDKBbin)) - { - tprintf(_T("DKB file %s is not exist"),pInstParam->pszDKBbin); - return FALSE; - } - struct stImageFile stTmp; - stTmp.nFileType = OBMI; - stTmp.strImageFile = pInstParam->pszDKBbin; - *kl_pushp(stifl,*me->m_plJtagEnabledImageList) = stTmp; - } - else - { - tprintf(_T("Miss OBM image in re-enabled jtag.")); - return FALSE; - } - - if (pInstParam->pszTZIIFile) - { - if (!IsFileExist(pInstParam->pszTZIIFile)) - { - tprintf(_T("TZII file %s is not exist"),pInstParam->pszTZIIFile); - return FALSE; - } - struct stImageFile stTmp; - stTmp.nFileType = TZII; - stTmp.strImageFile = pInstParam->pszTZIIFile; - *kl_pushp(stifl,*me->m_plJtagEnabledImageList) = stTmp; - } - - for (t_ImageFileListIter ite = kl_begin(*me->m_plJtagEnabledImageList); ite != kl_end(*me->m_plJtagEnabledImageList); ite = kl_next(ite)) - { - if (!IsFileExist(kl_val(ite).strImageFile)) - { - tprintf(_T("%s image don't exist:%s"),stringer(kl_val(ite).nFileType),kl_val(ite).strImageFile); - return FALSE; - } - } - - - -/* if (pInstParam->pszJTAGKeyFile) // check if user enter any security file path. - { - if (!IsFileExist(pInstParam->pszJTAGKeyFile)) - { - tprintf(_T("JTAGKeyFile file %s is not exist "),pInstParam->pszJTAGKeyFile); - return FALSE; - } - m_strJtagKeyFile = pInstParam->pszJTAGKeyFile; - } - else - { - tprintf(_T("Miss JtagKeyFile in re-enabled jtag.")); - return FALSE; - }*/ - return TRUE; -} - -BOOL WtptpDownLoad_prepareDownloadImg(struct CWtptpDownLoad *me,const PInstanceParams pInstParam) -{ - BOOL bIsBootRomlistPrepared = FALSE; - if(0==kl_size(dfdil,*pInstParam->pDownloadImagesList)) - return FALSE; - - - t_DdrFlashDownloadImgInfoIter DDRDownloadIMGIter = kl_begin(*pInstParam->pDownloadImagesList); - while(DDRDownloadIMGIter!= kl_end(*pInstParam->pDownloadImagesList)) - { - - struct stImageFileByDDR *pImageFileByDDRBL = (struct stImageFileByDDR*)malloc(sizeof(struct stImageFileByDDR)); - memset(pImageFileByDDRBL,0,sizeof(struct stImageFileByDDR)); - New_stImageFileByDDR(pImageFileByDDRBL); - t_stringListIter imageiter = kl_begin(*kl_val(DDRDownloadIMGIter)->pImagelist); - me->m_uTotalDDRTypeNum = kl_val(DDRDownloadIMGIter)->TotalVendorDDRTypeNum; - me->m_uTotalFlashTypeNum =kl_val(DDRDownloadIMGIter)->TotalFlashTypeNum; - - while(imageiter!=kl_end(*kl_val(DDRDownloadIMGIter)->pImagelist)) - { - //if (!IsFileExist((*imageiter)->c_str())) - if (!BinFileWtp_IsFileExist(&gBinFileWtp,kl_val(imageiter)->s)) - { - tprintf(_T("File %s can't exist\n"),kl_val(imageiter)->s); - return FALSE; - } - struct stImageFile stiTmp; - stiTmp.nFileType = 0; - stiTmp.strImageFile = kl_val(imageiter)->s; - *kl_pushp(stifl,pImageFileByDDRBL->ImageFileList) = stiTmp; - imageiter = kl_next(imageiter); - } - - pImageFileByDDRBL->sDDRVendorID = (kl_val(DDRDownloadIMGIter))->sVendorDDRId; - pImageFileByDDRBL->sFlashInfo = (kl_val(DDRDownloadIMGIter))->sFlashInfo; - *kl_pushp(stifdl,me->m_lBootLoaderImageWithDDRList) = pImageFileByDDRBL; - - if(bIsBootRomlistPrepared) - { - DDRDownloadIMGIter = kl_next(DDRDownloadIMGIter); - continue; - } - - bIsBootRomlistPrepared = TRUE; - struct stImageFileByDDR *pImageFileByDDRBR = (struct stImageFileByDDR*)malloc(sizeof(struct stImageFileByDDR)); - memset(pImageFileByDDRBR,0,sizeof(struct stImageFileByDDR)); - New_stImageFileByDDR(pImageFileByDDRBR); - pImageFileByDDRBR->sDDRVendorID = kl_val(DDRDownloadIMGIter)->sVendorDDRId; - pImageFileByDDRBR->sFlashInfo = kl_val(DDRDownloadIMGIter)->sFlashInfo; - - - if (pInstParam->pszDKBTim) // check if user enter any security file path. - { - //if (!IsFileExist(pInstParam->pszDKBTim)) - if (!BinFileWtp_IsFileExist(&gBinFileWtp,pInstParam->pszDKBTim)) - { - tprintf(_T("DKB Tim header file %s is not exist "),pInstParam->pszDKBTim); - return FALSE; - } - struct stImageFile stiTmp; - stiTmp.nFileType = TIMH; - stiTmp.strImageFile = pInstParam->pszDKBTim; - *kl_pushp(stifl,pImageFileByDDRBR->ImageFileList) = stiTmp; - } - - if(pInstParam->pszDKBbin) - { - //if (!IsFileExist(pInstParam->pszDKBbin)) - if (!BinFileWtp_IsFileExist(&gBinFileWtp,pInstParam->pszDKBbin)) - { - tprintf(_T("DKB Bin file %s is not exist "),pInstParam->pszDKBbin); - return FALSE; - } - struct stImageFile stiTmp; - stiTmp.nFileType = DKBI; - stiTmp.strImageFile = pInstParam->pszDKBbin; - *kl_pushp(stifl,pImageFileByDDRBR->ImageFileList) = stiTmp; - } - - if (PLAT_MMP2 == me->m_ePlatformType) - { - if(pInstParam->pszOBMFile) - { - //if (!IsFileExist(pInstParam->pszOBMFile)) - if (!BinFileWtp_IsFileExist(&gBinFileWtp,pInstParam->pszOBMFile)) - { - tprintf(_T("OBM Bin file %s is not exist "),pInstParam->pszOBMFile); - return FALSE; - } - struct stImageFile stiTmp; - stiTmp.nFileType = OBMI; - stiTmp.strImageFile = pInstParam->pszOBMFile; - *kl_pushp(stifl,pImageFileByDDRBR->ImageFileList) = stiTmp; - } - } - - if (PLAT_MMP2 == me->m_ePlatformType - || PLAT_MMP3 == me->m_ePlatformType - || PLAT_EDEN== me->m_ePlatformType - || PLAT_EDEN_A0 == me->m_ePlatformType - || PLAT_HELAN2== me->m_ePlatformType - || PLAT_HELAN3== me->m_ePlatformType - || PLAT_HELAN4== me->m_ePlatformType) - { - if(pInstParam->pszWTMFile) - { - //if (!IsFileExist(pInstParam->pszWTMFile)) - if (!BinFileWtp_IsFileExist(&gBinFileWtp,pInstParam->pszWTMFile)) - { - tprintf(_T("WTM Bin file %s is not exist "),pInstParam->pszWTMFile); - } - struct stImageFile stiTmp; - stiTmp.nFileType = WTMI; - stiTmp.strImageFile = pInstParam->pszWTMFile; - *kl_pushp(stifl,pImageFileByDDRBR->ImageFileList) = stiTmp; - } - } - - if (PLAT_EDEN== me->m_ePlatformType - || PLAT_EDEN_A0 == me->m_ePlatformType - || PLAT_HELAN2== me->m_ePlatformType - || PLAT_ULC1 == me->m_ePlatformType - || PLAT_HELAN3== me->m_ePlatformType - || PLAT_HELAN4== me->m_ePlatformType - || PLAT_ULC2== me->m_ePlatformType) - { - if(pInstParam->pszTZIIFile) - { - //if (!IsFileExist(pInstParam->pszTZIIFile)) - if (!BinFileWtp_IsFileExist(&gBinFileWtp,pInstParam->pszTZIIFile)) - { - tprintf(_T("TZI Bin file %s is not exist "),pInstParam->pszTZIIFile); - return FALSE; - } - struct stImageFile stiTmp; - stiTmp.nFileType = TZII; - stiTmp.strImageFile = pInstParam->pszTZIIFile; - *kl_pushp(stifl,pImageFileByDDRBR->ImageFileList) = stiTmp; - } - } - - *kl_pushp(stifdl,me->m_lBootRomImageWithDDRList) = pImageFileByDDRBR; - - DDRDownloadIMGIter = kl_next(DDRDownloadIMGIter); - } - - - t_ImageFileByDDRIter Iter = kl_begin(me->m_lBootRomImageWithDDRList); - me->m_plBootRomImageList = &((kl_val(Iter))->ImageFileList); -#if PRINTLOG - printf("Prepared download image\n"); -#endif - return TRUE; -} - -void WtptpDownLoad_ResetParameter(struct CWtptpDownLoad *me) -{ - me->m_plBootRomImageList=NULL; - me->m_plBootLoaderImageList=NULL; - me->m_plJtagEnabledImageList=NULL; - - t_ImageFileByDDRIter DDRDownloadIMGIter = kl_begin(me->m_lBootRomImageWithDDRList); - while(DDRDownloadIMGIter!= kl_end(me->m_lBootRomImageWithDDRList)) - { - free(kl_val(DDRDownloadIMGIter)); - DDRDownloadIMGIter = kl_next(DDRDownloadIMGIter); - } - kl_clear(stifdl,me->m_lBootRomImageWithDDRList); - - DDRDownloadIMGIter = kl_begin(me->m_lBootLoaderImageWithDDRList); - while(DDRDownloadIMGIter!= kl_end(me->m_lBootLoaderImageWithDDRList)) - { - free(kl_val(DDRDownloadIMGIter)); - DDRDownloadIMGIter = kl_next(DDRDownloadIMGIter); - } - kl_clear(stifdl,me->m_lBootLoaderImageWithDDRList); - - DDRDownloadIMGIter = kl_begin(me->m_lJtagEnabledImageWithDDRList); - while(DDRDownloadIMGIter!= kl_end(me->m_lJtagEnabledImageWithDDRList)) - { - free(kl_val(DDRDownloadIMGIter)); - DDRDownloadIMGIter = kl_next(DDRDownloadIMGIter); - } - kl_clear(stifdl,me->m_lJtagEnabledImageWithDDRList); - -} - -eDDREMMCMatchResult WtptpDownLoad_HandleDownloadImagesByDDRIDandEMMCSize(struct CWtptpDownLoad *me,UINT32 uiDdrVendorId, UINT32 uiDdrUnitSize,UINT32 uiEMMCSize) -{ - if(kl_size(stifdl,me->m_lBootLoaderImageWithDDRList)>1) - { - //Verify�Ƿ���map������ֱ�ӱ��� - //verify�Dz�������׼����DDR�б�����ڣ���ֱ�ӱ������ڣ�����m_lBootRomImageList/m_lBootLoaderImageList/m_lJtagEnabledImageList - BOOL IsVendorIDisknown = FALSE; - for (int idx = 0; idx < MAX_DDR_VENDOR_NUM; ++idx) - { - if (vendorDdrPidNameMap[idx].nDdrVendorID == uiDdrVendorId) - { - IsVendorIDisknown = TRUE; - break; - } - } - - if(!IsVendorIDisknown) - return kDDRMismatchError; - - - BOOL bIsDDRFileispreparedBL = FALSE; - BOOL bIsEMMCFileispreparedBL = FALSE; - UINT32 uiDdrPid = (uiDdrVendorId<<8)|uiDdrUnitSize; - t_ImageFileByDDRIter Iter = kl_begin(me->m_lBootLoaderImageWithDDRList); - while(Iter!=kl_end(me->m_lBootLoaderImageWithDDRList)) - { - - if(me->m_uTotalDDRTypeNum>0&&1==me->m_uTotalFlashTypeNum)//Multiple DDR and Single EMMC size type - { - if(Str2Uint32((kl_val(Iter))->sDDRVendorID.s) == uiDdrPid) - { - bIsDDRFileispreparedBL = TRUE; - bIsEMMCFileispreparedBL = TRUE; - me->m_plBootLoaderImageList = &(kl_val(Iter))->ImageFileList; - break; - } - } - else if(me->m_uTotalDDRTypeNum==0&&me->m_uTotalFlashTypeNum>1)//Single DDR and Multiple EMMC size type - { - UINT32 uiEMMCSizecfg = TranslateEx((kl_val(Iter))->sFlashInfo)/UNIT_GB; - //��(*Iter)->sEMMCSizeת��Ϊ����֮���512M��������֮�Ƚ� - if( uiEMMCSizecfg== uiEMMCSize) - { - bIsDDRFileispreparedBL = TRUE; - bIsEMMCFileispreparedBL = TRUE; - me->m_plBootLoaderImageList = &(kl_val(Iter))->ImageFileList; - break; - } - - } - else if(me->m_uTotalFlashTypeNum>1&&me->m_uTotalDDRTypeNum>0)//Multiple DDR and Multiple EMMC size type - { - UINT32 uiEMMCSizecfg = TranslateEx((kl_val(Iter))->sFlashInfo)/UNIT_GB; - if(uiEMMCSizecfg == uiEMMCSize&& Str2Uint32((kl_val(Iter))->sDDRVendorID.s) == uiDdrPid) - { - bIsDDRFileispreparedBL = TRUE; - bIsEMMCFileispreparedBL = TRUE; - me->m_plBootLoaderImageList = &(kl_val(Iter))->ImageFileList; - break; - } - } - else - { - return kImagePreparationError; //total DDR num and EMMCSize num maybe error - } - Iter = kl_next(Iter); - } - if(me->m_uTotalDDRTypeNum>0&&!bIsDDRFileispreparedBL) - return kDDRMismatchError; - if(me->m_uTotalFlashTypeNum>1&&!bIsDDRFileispreparedBL) - return kDDRMismatchError; - - } - else - { - t_ImageFileByDDRIter Iter = kl_begin(me->m_lBootLoaderImageWithDDRList); - me->m_plBootLoaderImageList = &((kl_val(Iter))->ImageFileList); - } - - return kMatchNoError; -} - -eDDREMMCMatchResult WtptpDownLoad_HandleNandDLImgByDDRID(struct CWtptpDownLoad *me,UINT32 uiDdrVendorId, UINT32 uiDdrUnitSize) -{ - if(kl_size(stifdl,me->m_lBootLoaderImageWithDDRList)>1) - { - BOOL bFound = FALSE; - for (int idx = 0; idx < MAX_DDR_VENDOR_NUM; ++idx) - { - if (vendorDdrPidNameMap[idx].nDdrVendorID == uiDdrVendorId) - { - bFound = TRUE; - break; - } - } - - if(!bFound) - { - return kDDRMismatchError; - } - - UINT32 uiDdrPid = (uiDdrVendorId<<8)|uiDdrUnitSize; - BOOL bFoundNandId = FALSE; - for(t_ImageFileByDDRIter ite = kl_begin(me->m_lBootLoaderImageWithDDRList); ite != kl_end(me->m_lBootLoaderImageWithDDRList); ite = kl_next(ite)) - { - if(Str2Uint32((kl_val(ite))->sDDRVendorID.s) == uiDdrPid) - { - me->m_plBootLoaderImageList = &(kl_val(ite))->ImageFileList; - bFoundNandId = TRUE; - break; - } - } - - if(!bFoundNandId) - { - return kDDRMismatchError; - } - } - else - { - t_ImageFileByDDRIter Iter = kl_begin(me->m_lBootLoaderImageWithDDRList); - me->m_plBootLoaderImageList = &((kl_val(Iter))->ImageFileList); - } - - return kMatchNoError; -} - - -char* WtptpDownLoad_replace_all(char* str,const char* old_value,const char* new_value) -{ - char buf[256]={0}; - char *p = NULL,*pstr = str; - int lo = strlen(old_value); - p = strstr(pstr, old_value); - while (p) - { - strncat(buf, pstr, p-pstr); - strcat(buf, new_value); - pstr = p + lo; - p = strstr(pstr,old_value); - } - strcat(buf,pstr); - strcpy(str, buf); - return str; -} - - -EDeviceType WtptpDownLoad_GetDeviceType(struct CWtptpDownLoad *me,ePlatForm ePlatfromType,const char* strDate,const char* strVersion ,const char* strProcessor) -{ - for (int idx = 0; idx < sizeof(gstFlatformBLInfoSet)/sizeof(gstFlatformBLInfoSet[0]); ++idx) - { - if (gstFlatformBLInfoSet[idx].ePlatFormType == ePlatfromType) - { - if((NULL != strstr(strDate, gstFlatformBLInfoSet[idx].strBLDate)) - &&(NULL != strstr(strProcessor,gstFlatformBLInfoSet[idx].strBLProcessor) ) - &&(NULL != strstr(strVersion,gstFlatformBLInfoSet[idx].strBLVersion)) ) - { - return kBootLoader; - } - else - { - return kBootRom; - } - } - } - return kNone; -} - - - diff --git a/fbfdownloader/src/WtptpDownloader.h b/fbfdownloader/src/WtptpDownloader.h deleted file mode 100644 index dcd500209..000000000 --- a/fbfdownloader/src/WtptpDownloader.h +++ /dev/null @@ -1,229 +0,0 @@ -#pragma once -#include -#include "ParaDefine.h" -#include "define.h" -#include "WTPdef.h" -#include "ConvetEdian.h" -#include "ApplicationINI.h" -#include "Typedef.h" -#include "BulkDevNonDrv_Linux.h" -#include "BinFileWtp.h" - -/******************************************************************************************************************* - - (C) Copyright 20011 Marvell Semiconductor Hefei Ltd. All Rights Reserved - - *******************************************************************************************************************/ - - -#define MMP2_BOOTLOADER_PROCESSOR _T("MMP2") -#define MMP2_BOOTLOADER_VERSION _T("3215") -#define MMP2_BOOTLOADER_DATE _T("12052009") - -#define WKNG_BOOTLOADER_PROCESSOR _T("WKNG") -#define WKNG_BOOTLOADER_VERSION _T("3301") -#define WKNG_BOOTLOADER_DATE _T("06172011") - -#define NEVO_BOOTLOADER_PROCESSOR _T("NEVO") -#define NEVO_BOOTLOADER_VERSION _T("3301") -#define NEVO_BOOTLOADER_DATE _T("08182011") - -#define MMP3_BOOTLOADER_PROCESSOR _T("MMP3") -#define MMP3_BOOTLOADER_VERSION _T("3302") -#define MMP3_BOOTLOADER_DATE _T("03082012") - - -#define PXA92X_BOOTLOADER_PROCESSOR _T("TVTD") -#define PXA92X_BOOTLOADER_VERSION _T("3211") -#define PXA92X_BOOTLOADER_DATE _T("06242009") - -#define EMEI_BOOTLOADER_PROCESSOR _T("EMEI") -#define EMEI_BOOTLOADER_VERSION _T("3304") -#define EMEI_BOOTLOADER_DATE _T("07022012") - -#define HELAN_BOOTLOADER_PROCESSOR _T("HELN") -#define HELAN_BOOTLOADER_VERSION _T("3307") -#define HELAN_BOOTLOADER_DATE _T("01152013") - -#define EDEN_BOOTLOADER_PROCESSOR _T("EDEN") -#define EDEN_BOOTLOADER_VERSION _T("3307") -#define EDEN_BOOTLOADER_DATE _T("04162013") - -#define NEZHA3_BOOTLOADER_PROCESSOR _T("NZA3") -#define NEZHA3_BOOTLOADER_VERSION _T("3311") -#define NEZHA3_BOOTLOADER_DATE _T("06012014") - - -#define HELAN2_BOOTLOADER_PROCESSOR _T("HLN2") -#define HELAN2_BOOTLOADER_VERSION _T("3308") -#define HELAN2_BOOTLOADER_DATE _T("02122014") - -#define EDENA0_BOOTLOADER_PROCESSOR _T("EDEN") -#define EDENA0_BOOTLOADER_VERSION _T("3307") -#define EDENA0_BOOTLOADER_DATE _T("02142014") - -#define ULC1_BOOTLOADER_PROCESSOR _T("ULC1") -#define ULC1_BOOTLOADER_VERSION _T("3313") -#define ULC1_BOOTLOADER_DATE _T("09172014") - -#define HELAN3_BOOTLOADER_PROCESSOR _T("HLN3") -#define HELAN3_BOOTLOADER_VERSION _T("3313") -#define HELAN3_BOOTLOADER_DATE _T("11052014") - -#define HELAN4_BOOTLOADER_PROCESSOR _T("HLN4") -#define HELAN4_BOOTLOADER_VERSION _T("3313") -#define HELAN4_BOOTLOADER_DATE _T("25032015") - -#define ULC2_BOOTLOADER_PROCESSOR _T("ULC2") -#define ULC2_BOOTLOADER_VERSION _T("3313") -#define ULC2_BOOTLOADER_DATE _T("08052015") - -struct stFlatformBootLoaderInfo{ - ePlatForm ePlatFormType; - const char* strBLDate; - const char* strBLProcessor; - const char* strBLVersion; -}; - -extern const struct stFlatformBootLoaderInfo gstFlatformBLInfoSet[]; - -#define USBPACKETSIZE 0x4000 -//#define USBPACKETSIZE 4096 //Modify for FD don't work on NEVO c0 and VMWare download -static const int NAND_BURNNING_SPEED = 1000; //per ms -static const int EMMC_BURNNING_SPEED = 8000 ;//per ms -static const int SPINOR_BURNNING_SPEED = 90 ;//per ms - - -static const double SPINOR_16M_ERASE_SPEED = 1.3; -static const double SPINOR_32M_ERASE_SPEED = 0.52; -static const double SPINAND_128M_ERASE_SPEED = 2.8; -static const double EMMC_ERASE_SPPED = 96.0; -static const double NAND_ERASE_SPPED = 49.0; -#define DLCMD_DO_ERASE_ALL_FLASH_MSK 1 -#define DLCMD_DO_UPLOAD_DATA_MSK 2 -#define DLCMD_DO_RESETBBT_MSK 4 -#define DLCMD_DO_ERASE_ALL_FLASH_ONLY_MSK 16 -#define MAX_IMG_FILES 100 -#define MAX_DOWNLOAD_DEVICENUM 32 - -#define IMAGEID_LEN 4 -#define stringer(x) #x -void NewCWtptpDownLoad (struct CWtptpDownLoad *me); -BOOL WtptpDownLoad_DownloadImage(struct CWtptpDownLoad *me,PDEVICE pDev, int iFile,const t_ImageFileList* plImgFileList, UINT64 uiAllimgsize,UINT64 *uidownloadsize,int nImages,char* strDownloadImgName); -BYTE WtptpDownLoad_AckWithImageName (struct CWtptpDownLoad *me,const UINT32 ImageType,TCHAR *szFileName,const t_ImageFileList* plImageList); -BOOL WtptpDownLoad_ParseTim (struct CWtptpDownLoad *me,t_ImageFileByDDRList* ImageFileByDDRlist); -BOOL WtptpDownLoad_SetAndWaitForThreadExit(struct CWtptpDownLoad *me,PDEVICE pDev); -BOOL WtptpDownLoad_RemoveEntryList(struct CWtptpDownLoad *me,PDEVICE pDev); -BOOL WtptpDownLoad_GetDeviceBootType(struct CWtptpDownLoad *me,PDEVICE pDev); -BOOL WtptpDownLoad_UploadDataFromTarget(struct CWtptpDownLoad *me,PDEVICE pDev); -BOOL WtptpDownLoad_OpenDevice(struct CWtptpDownLoad *me,PDEVICE pDev); -void WtptpDownLoad_WtptpOpenDevice(struct CWtptpDownLoad *me,struct CWtptpDownLoad *pWtptpDownLoad, USB_HANDLE *pLinuxUsb); -BOOL WtptpDownLoad_ValidateWTPTPMSGReport(struct CWtptpDownLoad *me,PDEVICE pDev, WTPSTATUS *pWtpStatus, UINT32 *ReturnCode); -UINT32 WtptpDownLoad_GetWTPTPMSGReturnCode(struct CWtptpDownLoad *me,WTPSTATUS *pWtpStatus); -BOOL WtptpDownLoad_WTPTPDownLoad (struct CWtptpDownLoad *me,PDEVICE pDev); -void WtptpDownLoad_Report(struct CWtptpDownLoad *me); -void WtptpDownLoad_AddDisplayInfoDevice(struct CWtptpDownLoad *me,PDEVICE pDev); -void WtptpDownLoad_RemoveDisplayInfoDevice(struct CWtptpDownLoad *me,PDEVICE pDev); -void WtptpDownLoad_ResetParameter(struct CWtptpDownLoad *me); -BOOL WtptpDownLoad_prepareDumpFlashParam(struct CWtptpDownLoad *me,const PInstanceParams pInstParam); -BOOL WtptpDownLoad_prepareEnabledJtagImg(struct CWtptpDownLoad *me,const PInstanceParams pInstParam); -BOOL WtptpDownLoad_prepareDownloadImg(struct CWtptpDownLoad *me,const PInstanceParams pInstParam); -static PVOID WtptpDownLoad_BootRomIOThread(PVOID Arg); -static PVOID WtptpDownLoad_BootLoaderIOThread(PVOID Arg); -static PVOID WtptpDownLoad_BootLoaderUploadThread(PVOID Arg); -static PVOID WtptpDownLoad_WtptpDeviceDetectThread(PVOID Arg); -static int WtptpDownLoad_init_hotplug_sock(); -BOOL WtptpDownLoad_InitializeBL(struct CWtptpDownLoad *me,PInstanceParams pInstParam); -//BOOL WtptpDownLoadInitializeBLEx(struct CWtptpDownLoad *me,PInstanceParams pInstParam,const TCHAR * pszBLFfileName ,const TCHAR * pszFBFTimFile,const TCHAR * pszFBFfileName); -BOOL WtptpDownLoad_TerminateBL(struct CWtptpDownLoad *me); -void WtptpDownLoad_SetBootDeviceType(struct CWtptpDownLoad *me,PDEVICE pDev,EDeviceType eDevieBootType); -eDDREMMCMatchResult WtptpDownLoad_HandleDownloadImagesByDDRIDandEMMCSize(struct CWtptpDownLoad *me,UINT32 uiDdrVendorId, UINT32 uiDdrUnitSize,UINT32 uiEMMCSize); -eDDREMMCMatchResult WtptpDownLoad_HandleNandDLImgByDDRID(struct CWtptpDownLoad *me,UINT32 uiDdrVendorId, UINT32 uiDdrUnitSize); -char* WtptpDownLoad_replace_all(char* str,const char* old_value,const char* new_value) ; -EDeviceType WtptpDownLoad_GetDeviceType(struct CWtptpDownLoad *me,ePlatForm ePlatfromType,const char* strDate,const char* strVersion ,const char* strProcessor); -void DelCWtptpDownLoad (struct CWtptpDownLoad *me); - - - -struct CWtptpDownLoad -{ - struct CConvertLT2B MyConvertLT2B; - TCHAR m_szPrimaryDkbPath[MAX_PATH]; - TCHAR m_szPrimTimPath[MAX_PATH]; - TCHAR m_szSecondaryFlasherPath[MAX_PATH]; - TCHAR m_szOBMPath[MAX_PATH]; - TCHAR m_szWTMPath[MAX_PATH]; - TCHAR m_szSWDPath[MAX_PATH]; - TCHAR m_szTZIPath[MAX_PATH]; - UINT32 m_nFlashDataPageSize ; - UINT32 m_nBurningSpeed; - BOOL m_binitFlag; - volatile BOOL m_bTerminateDownload; - - int m_uTotalDDRTypeNum; - int m_uTotalFlashTypeNum; - int m_uFlashBadBlockRate;//坏块率门限 m_uFlashBadBlockRate/10000 - - t_ImageFileList* m_plBootRomImageList; - t_ImageFileList* m_plBootLoaderImageList; - t_ImageFileList* m_plJtagEnabledImageList; - - - t_ImageFileByDDRList m_lBootRomImageWithDDRList; - t_ImageFileByDDRList m_lBootLoaderImageWithDDRList; - t_ImageFileByDDRList m_lJtagEnabledImageWithDDRList; - - BOOL m_bDumpFlash; //to do upload in wtptpdownload - BOOL m_bEnabledJtag; - - BOOL m_bInitialiezed ; // Indicates whether the InitializeBL was called (and was TerminateBL called afterwards) - BOOL m_bTermination ; - BOOL m_bUploadFromTarget ; //to do upload in wtptpdownload -// - BOOL m_bCustPreamble ; - BOOL m_bTrusted; - BOOL m_bEraseAllFlash ; - BOOL m_bEraseAllFlashOnly; - BOOL m_bResetBBT ; - BOOL m_bDebugTrace; - BOOL m_bOnlyOBMDownload; - volatile BOOL m_bTerminateUSBDetect; - BOOL m_bSingleDownload; - BOOL m_bGetBadBlk; - BOOL m_bImageCrcEnable; - BOOL m_bIsLittleEndian; - ePlatForm m_ePlatformType; - eFlashType m_FlashType; - t_DeviceList m_WtptpDeviceList; - t_DisplayInfoList m_DisplayInfoList; - - - PInstanceParams m_lpInstParam ; - //pWTPTPREAMBLECOMMAND m_lpCustPreambleCmd ; - t_UpLoadDataSpecList* m_lpUpLoadDataSpecList ; - int m_nBootRomDevNum ; - int m_nBootLoaderDevNum ; - int m_nUploadDevNum; - pthread_t BootRomTypeThread[MAX_DOWNLOAD_DEVICENUM]; - pthread_t BootLoaderTypeThread[MAX_DOWNLOAD_DEVICENUM]; - pthread_t UploadThread[MAX_DOWNLOAD_DEVICENUM]; - pthread_t DetectThread; - - pthread_mutex_t DeviceList_mutex; - //pthread_mutex_t Device_mutex; - pthread_mutex_t Quit_mutex; - pthread_mutex_t callback_mutex; - - - - - - - - - -}; - - - - diff --git a/fbfdownloader/src/define.h b/fbfdownloader/src/define.h deleted file mode 100644 index 2ec543ccc..000000000 --- a/fbfdownloader/src/define.h +++ /dev/null @@ -1,145 +0,0 @@ - -#ifndef DEFINE_H -#define DEFINE_H -#include "./Typedef.h" -#include "ParaDefine.h" -#include -#include -#include "kstring.h" - -#define MAX_PATH 1024 -struct CWtpComm; -struct CWtptpDownLoad; -#define RXTIMEOUT 10000 -#define TXTIMEOUT 5000 -#define WTPTPERRORREPORT 1 -#define WTPTPNOTIFICATION 0 -#define WTPTPNOTIFICATION_BURNTSIZE 2 -#define WTPTPNOTIFICATION_UPLOAD 3 -#define WTPTPNOTIFICATION_FLASHSIZE 4 -#define WTPTPREPORT_EXTENDED_FUSE_INFO 5 -#define WTPTPREPORT_UEINFO 6 - -#define MAX_FILE_PATH 1024 -#define USBPACKETSIZE 0x4000 - -#define STOPFLAG 1 -//#define DLCMD_DO_ERASE_ALL_FLASH_MSK 0 -//#define DLCMD_DO_UPLOAD_DATA_MSK 1 -//#define DLCMD_DO_RESETBBT_MSK 2 -//#define DLCMD_DO_CUSTMOIZEPREAMBLE_MSK 3 -//#define DLCMD_DO_ERASE_ALL_FLASH_ONLY_MSK 4 -//#define DLCMD_DO_ENABLE_JTAG_MSK 5 -typedef struct _DEVICE -{ - TCHAR UsbDevName[MAX_FILE_PATH];// - TCHAR LogFileName[MAX_FILE_PATH];// record downloding process to get debug information - TCHAR szCurrentMsg[MAX_FILE_PATH]; - BadBlockData DevBadBlk; // flash bad block data - ImageCRCInfo DevImageCrc; // CRC value of Images read back from flash - FILE *hLog; - int SerialNo; // Serial number of the device. - int npercent; - int nBootRomId, - nBootLoaderId, - nDevType; - struct CWtpComm *pWtpComm ; - volatile int ThreadExit; - pthread_t ThreadId; - eProcessState kProState; - -}DEVICE, *PDEVICE; - -typedef struct _DISPLAYINFO -{ - TCHAR UsbDevName[MAX_FILE_PATH]; - TCHAR szCurrentMsg[MAX_FILE_PATH]; - BadBlockData szBadBlk; // flash bad block data - ImageCRCInfo szImageCrc; // CRC value of Images read back from flash - eProcessState kProState; - int npercent; -}DISPLAYINFO,*PDISPLAYINFO; - -typedef struct _DOWNLOADTARGET -{ - PDEVICE pDev; - struct CWtptpDownLoad *pWtptpDownload; - -}DOWNLOADTARGET,*PDOWNLOADTARGET; - -#define __pdev_free(x) -KLIST_INIT(pdevl, PDEVICE, __pdev_free) -KLIST_INIT(pdisl, PDISPLAYINFO, __pdev_free) - -typedef klist_t(pdevl)* t_DeviceList; -typedef kliter_t(pdevl)* t_DeviceIter; -typedef klist_t(pdisl)* t_DisplayInfoList; -typedef kliter_t(pdisl)* t_DisplayInfoIter; - - -typedef enum _EDeviceType -{ - kNone = 0, - kBootRom = 1, - kBootLoader = 2, -}EDeviceType; - -enum eBootROM_Operation_Mode -{ - NonTrustedBoot1 = 0, - NonTrustedBoot2 = 1, - TrustedBoot = 2, - TamperBoot = 3 // BootROM will not boot device, so, OBM can't detect such mode. -}; - -typedef struct -{ - UINT32 ChipID : 16; // 0x1920 - UINT32 RevisionID : 8; // 0xB0 - UINT32 Reserved : 8; -}ChipIDInfo; - - -// extended message data -typedef struct { - UINT32 OEMKeyHash[8]; - UINT32 DeviceUID[2]; - enum eBootROM_Operation_Mode BRMode; - UINT32 MMCSerialNumber; - ChipIDInfo ChipId; -} ExMessageData, *pExMessageData; - -// extended message report -typedef struct { - UINT8 ReportType; - UINT8 ReportLength; - UINT8 TotalMsgNumber;//OBM分多次送消息,如果消息长度大于0x40 - UINT8 MsgIndex; //Current Msg Index - ExMessageData ReportData; -} ExMessageReport, *pExMessageReport; - -typedef struct { - UINT32 OEMKeyHash[8]; - UINT32 DeviceUID[2]; - UINT32 BRMode; - ChipIDInfo ChipId; - UINT8 eMMCInfo[16]; //128bit - UINT32 Reserved1; - UINT32 Reserved2; - UINT32 EmmcSize; //MB - UINT32 DDRSize; //MB -} UEInfo; -// extended message report -typedef struct { - UINT8 ReportType; - UINT8 ReportLength; - UINT8 TotalMsgNumber; //OBM分多次送消息,如果消息长度大于0x40 - UINT8 MsgIndex; //Current Msg Index - UEInfo ReportData; -} Ex2MessageReport, *pEx2MessageReport; - -typedef struct { - UEInfo UEMessageInfo; - TCHAR lpUsbPortAddress[260]; -} MessageUEInfoReport; -#endif diff --git a/fbfdownloader/src/downloader.h b/fbfdownloader/src/downloader.h deleted file mode 100644 index e961ee56a..000000000 --- a/fbfdownloader/src/downloader.h +++ /dev/null @@ -1,377 +0,0 @@ -/****************************************************************************** -** -** COPYRIGHT (C) 2000, 2002 Intel Corporation. -** -** This software as well as the software described in it is furnished under -** license and may only be used or copied in accordance with the terms of the -** license. The information in this file is furnished for informational use -** only, is subject to change without notice, and should not be construed as -** a commitment by Intel Corporation. Intel Corporation assumes no -** responsibility or liability for any errors or inaccuracies that may appear -** in this document or any software that may be provided in association with -** this document. -** Except as permitted by such license, no part of this document may be -** reproduced, stored in a retrieval system, or transmitted in any form or by -** any means without the express written consent of Intel Corporation. -** -** FILENAME: downloader.h -** -** PURPOSE: -** -** LAST MODIFIED: -******************************************************************************/ - -#ifndef DOWNLOADER_H -#define DOWNLOADER_H - -#include "Macrodef.h" -#include "Typedef.h" -#if !defined (LINUX) -//#include -#else -//#include "global_types_linux.h" -#endif// LINUX - -#define MAX_SIZE_OF_FILENAME_STRING 1024 - - -/* Concentration of all per-build identifiers */ -//#define DEBUG_BUILD - -#define MAX_NUMBER_OF_IMAGES 200 -//#define BLOCK_DEVICE_SECTOR_SIZE (32*1024) // 32 KB - -#ifdef FBFMAKEWEB -#define MAX_NUMBER_OF_IMAGE_STRUCTS_IN_DEVICE_HEADER 150 -#else -#define MAX_NUMBER_OF_IMAGE_STRUCTS_IN_DEVICE_HEADER 30 -#endif - -#define MASTER_BLOCK_HEADER_SIZE_IN_BYTES (sizeof(MasterBlockHeader)) -#define DEVICE_HEADER_SIZE_IN_BYTES (sizeof(DeviceHeader_VPXA92x)) -#define MAX_NUMBER_OF_FLASH_SECTIONS 3 -#define MAX_NUM_OF_FLASH_PROTECTION_REGIONS 10 - -/* end of per-build identifiers */ - -//#define DEBUG_BUILD - - -//#define FLASH_BLOCK_SIZE_IN_BYTES (64*1024) - - -/*-----------------12/22/2004 5:10PM---------------- - * Flash Commands - * --------------------------------------------------*/ -#define FLASH_CMD_WRITE_WORD_1 0x40 -#define FLASH_CMD_WRITE_WORD_2 0x0 - -#define FLASH_CMD_BLOCK_ERASE_1 0x20 -#define FLASH_CMD_BLOCK_ERASE_2 0xD0 /* Confirm erase */ - -#define FLASH_CMD_LOCK_BLOCK_1 0x60 -#define FLASH_CMD_LOCK_BLOCK_2 0x01 - -#define FLASH_CMD_UNLOCK_BLOCK_1 0x60 -#define FLASH_CMD_UNLOCK_BLOCK_2 0xD0 - -#define FLASH_CMD_RESET_FOR_READ 0xFF - -#define FLASH_CMD_CLR_SR 0x50 -#define FLASH_CMD_READ_SR 0x70 - -#define FLASH_ERASED_WORD_16BIT 0xffff -#define FLASH_ERASED_WORD_32BIT 0xffffffff - - -#define SR_STATUS_BLOCK_LOCKED 0x02 - -#define DLCMD_DO_VERIFY_WRITE 1 -#define DLCMD_DO_ERASE_BLOCKS 2 -#define DLCMD_WRITE_IMAGE 3 -#define DLCMD_DUMP_IMAGE 4 -#define DLCMD_IMAGE_TYPE_FIELD_BIT 4 /* bit 4 through 7*/ -#define DLCMD_IMAGE_TYPE_FIELD_SIZE_BITS 4 -#define DLCMD_IMAGE_SPARE_AREA_SZ_BIT 8 /* bit 8 through 15 */ -#define DLCMD_IMAGE_SPARE_AREA_SZ_FIELD_BITS 8 -#define DLCMD_IMAGE_DUMP_SPARE_BIT 16 -#define DLCMD_IMAGE_ABSOLUTE_FLASH_OFFSET_ENABLE_BIT 17 -#define DLCMD_IMAGE_USE_SECTOR_BASED_ADDRESSING 18 -#define DLCMD_PARTITION_NUM_FIELD_BIT (24) /* bit 24 through 31 */ -#define DLCMD_PARTITION_NUM_FIELD_BIT_SIZE (8) - - -//image type define -#define DLCMD_RAW_BINARY_IMAGE_TYPE (0) /* used when burning raw binary */ -#define DLCMD_WINDOWS_MOBILE_IMAGE_TYPE (1) /* used for WM image type */ -#define DLCMD_YAFFS_IMAGE_TYPE (2) /* this image type is used for YAFFS */ -#define DLCMD_UBIFS_IMAGE_TYPE (3) /* this image type is used for UBIFS */ -#define DLCMD_JFFS2_IMAGE_TYPE (4) /* this image type is used for JFFS2 */ -#define DLCMD_RND_IMAGE_TYPE (5) -#define DLCMD_SPARSE_IMAGE_TYPE (6) /* this image type is used for Sparse file of Android*/ -#define DLCMD_LZMA_IMAGE_TYPE (7) //OBM burn compressed image to flash -#define DLCMD_LZMA2_IMAGE_TYPE (8) //OBM burn decompressed image to flash -#define DLCMD_YAFFS_LZMA_IMAGE_TYPE (9) //SWD compress the image with lzma algorithm,write the compressed image to FBF for image type 9-12 -#define DLCMD_UBIFS_LZMA_IMAGE_TYPE (10) -#define DLCMD_JFFS2_LZMA_IMAGE_TYPE (11) -#define DLCMD_RAW_LZMA_IMAGE_TYPE (12) - - - -#define DLCMD_DUMP_BINARY_IMAGE_WITH_SPARE_TYPE (3) -#define DLCMD_ABSOLUTE_FLASH_OFFSET_TYPE (4) -#define DLCMD_ABSOLUTE_FLASH_OFFSET_WITH_SPARE_TYPE (5) - -/* general downloader commands */ -#define FBF_GENERAL_CMD_INITIALIZE_FLASH_MSK (1) -#define FBF_GENERAL_CMD_PRODUCTION_INIT_FLASH_MSK (2) -#define FBF_GENERAL_CMD_DISABLE_ERASE_WM_USER_PARTITIONS_MSK (4) -#define FBF_GENERAL_CMD_ERASE_ALL_FLASH_MSK (8) -#define FBF_GENERAL_CMD_PERFORM_TARGET_RESET_MSK (16) - -/* Flash parameters flags */ -#define FLASH_PARAMETERS_ENABLE_BIT 1 - -#define FLASH_ERASED_VALUE 0xFF - - -#define BUF_FLAG_PRIMARY_VALID 1 -#define BUF_FLAG_SECONDARY_VALID 2 -#define BUF_FLAG_IS_FIRST_SWITCH 4 - - -#define HARD_SECTOR_SIZE 512 //TBD - receive from ini - -//static int numOfFlashDevices = 0; /* number of flash devices */ - - - -typedef UINT16 CORE_ID; - -#define MANITOBA_CORE_ID 0xABAB -#define HERMON_CORE_ID 0xBBAC -#define BULVERDE_CORE_ID 0xABAD -#define TAVOR_CORE_ID 0x1f34 - - - -typedef UINT8 FLASH_FAMILY; - - -#define BOOT_BLOCKS_START_OFFSET 0x0 -#define NUM_OF_BOOT_BLOCKS 4 /* Boot blocks == TIM + OBM + PINMUX + OS Loader */ - - -/* Device Header flags */ -#define DEVICE_EXTERNAL_FLASH 1 - - -#define MAX_NUMBER_OF_FLASH_DEVICES_IN_MASTER_HEADER 4 -#define MAX_NUMBER_OF_FLASH_DEVICES 10 -#define MAX_RESEVERD_LEN 4 -#define MAX_NUM_SKIP_BLOCKS 32 - -#pragma pack (1) - - -typedef struct -{ - UINT32 tCH; /*Enable Signal Hold Time*/ - UINT32 tCS; /*Enable Signal Setup Time*/ - UINT32 tWH; /*ND_nWE high duration*/ - UINT32 tWP; /*ND_nWE pulse width*/ - UINT32 tRH; /*ND_nRE high duration*/ - UINT32 tRP; /*ND_nRE pulse width*/ - UINT32 tR; /*ND_nWE high to ND_nRE Low for Read*/ - UINT32 tWHR; /*ND_nWE High to ND_nRE Low for Read Status*/ - UINT32 tAR; /*ND_ALE Low to ND_nRE Low Delay*/ -} FlashTimingStruct; - -typedef struct -{ - UINT32 TotalNumOfBlocks; /*The total number of blocks in flash*/ - UINT32 FlashBlockSize; /*Block size in Flash*/ - UINT32 FlashOffset; /*Flash offset address*/ - UINT32 FlashBufferSize; /*Buffer size in Flash*/ - UINT32 NumberOfBlocksInBadBlockPool; /*What is the number of Blocks in the Bad Block Pool*/ - UINT32 SpareAreaSize; /* Flash Device spare area size */ - UINT32 ManufacturerBadBlockInfoOffset; /* Where manufacturer bad block information in flash*/ -} FlashSectionStruct; - -typedef struct -{ - FlashTimingStruct FlashTiming; /*Timing Parameters*/ - FlashSectionStruct FlashSection[MAX_NUMBER_OF_FLASH_SECTIONS]; -} FlashParametersStruct; - -typedef struct -{ - UINT32 flash_partition_size; /* flash partition size */ - UINT32 commands; /* bit switches */ - UINT32 First_Sector; /* First sector of the image in the block device */ - UINT32 length; /* Block length in bytes */ - UINT32 Flash_Start_Address; /* start address in flash */ - UINT32 Flash_block_size; /* flash device block size */ - UINT32 ChecksumFormatVersion2; /* new format version image checksum (left for backwards compatibility) */ -} ImageStruct_VPXA92x; - -typedef struct -{ - UINT32 Image_ID; /* image id*/ - UINT32 Image_In_TIM; /* indicate this image is in TIM or not*/ - UINT32 Flash_partition; /* partition number of the image */ - UINT32 Flash_erase_size; /* erase size of the image */ - UINT32 commands; /* bit switches */ - UINT32 First_Sector; /* First sector of the image in the block device */ - UINT32 length; /* Image length in bytes */ - UINT32 Flash_Start_Address; /* start address in flash */ - UINT32 Reserved[MAX_RESEVERD_LEN]; - UINT32 ChecksumFormatVersion2; /* new format version image checksum (left for backwards compatibility) */ -} ImageStruct_V11; - -typedef ImageStruct_V11 *PImageStruct_V11; -typedef struct -{ - UINT32 Total_Number_Of_SkipBlocks; // total numbers of skip blocks - UINT32 Skip_Blocks[MAX_NUM_SKIP_BLOCKS]; -} SkipBlocksInfoStruct; - - -typedef struct -{ - UINT32 EraseAll; // erase all flag for user partition - UINT32 ResetBBT; // indicate if reset BBT - UINT32 NandID; // nand flash ID - UINT32 Reserved[MAX_RESEVERD_LEN - 1]; - SkipBlocksInfoStruct Skip_Blocks_Struct; -}FlashOptStruct; - - -typedef struct -{ - UINT32 DeviceFlags; - FlashParametersStruct FlashParameters; /* Device Parameters */ - UINT8 nOfImages; /* number of images */ - UINT8 BufferSizeLSB; /* init to 0x00 */ - UINT16 AccessWidth; /* init to 0x0000 */ - CORE_ID Core_ID; - FLASH_FAMILY FlashFamily; /* Device Flags */ - UINT8 BufferSizeMSB; - ImageStruct_VPXA92x imageStruct[MAX_NUMBER_OF_IMAGE_STRUCTS_IN_DEVICE_HEADER]; /* array of image structs */ -} DeviceHeader_VPXA92x; - - -typedef struct -{ - UINT32 DeviceFlags; /* NAND, eMMC, SPI-NOR, etc*/ - UINT32 DeviceParameters[16]; /* Device Parameters, reserve 16 U32 here, will be defined depending on different devices */ - FlashOptStruct FlashOpt; - UINT32 ProductionMode; // production mode - UINT8 OptValue; // choice: 0 - Not reset after download, 1 - Reset after download - UINT8 ChipID; - UINT8 BBCS_EN; - UINT8 CRCS_EN; - UINT32 Reserved[MAX_RESEVERD_LEN-2]; - UINT32 nOfImages; /* number of images */ - ImageStruct_V11 imageStruct[MAX_NUMBER_OF_IMAGE_STRUCTS_IN_DEVICE_HEADER]; /* array of image structs */ -} DeviceHeader_V11; - -typedef DeviceHeader_VPXA92x *PDeviceHeader_VPXA92x; -typedef DeviceHeader_V11 *PDeviceHeader_V11; - - -#define NUM_OF_SUPPORTED_FLASH_DEVS 4 - -typedef struct -{ - char Unique[24]; - UINT16 Flash_Device_Spare_Area_Size[NUM_OF_SUPPORTED_FLASH_DEVS]; - UINT16 Format_Version; - UINT16 Size_of_Block; - UINT32 Bytes_To_Program; - UINT32 Bytes_To_Verify; - UINT32 Number_of_Bytes_To_Erase; - UINT32 Main_Commands; - UINT32 nOfDevices; /* number of devices to burn in parallel */ - UINT32 DLerVersion; /* Version of downloader current 1 */ - UINT32 deviceHeaderOffset[MAX_NUMBER_OF_FLASH_DEVICES_IN_MASTER_HEADER]; /* offset in Sector 0 for each flash device header */ -} MasterBlockHeader; -typedef MasterBlockHeader *PMasterBlockHeader; - - -typedef struct -{ - char Unique[24]; - UINT16 Flash_Device_Spare_Area_Size[NUM_OF_SUPPORTED_FLASH_DEVS]; - UINT16 Format_Version; - UINT16 Size_of_Block; - UINT32 Bytes_To_Program; - UINT32 Bytes_To_Verify; - UINT32 Number_of_Bytes_To_Erase; - UINT32 Main_Commands; - UINT32 nOfDevices; /* number of devices to burn in parallel */ - UINT32 DLerVersion; /* Version of downloader current 1 */ - UINT32 deviceHeaderOffset[MAX_NUMBER_OF_FLASH_DEVICES]; /* offset in Sector 0 for each flash device header */ -} MasterBlockHeader_PXA92x; -typedef MasterBlockHeader_PXA92x *PMasterBlockHeader_PXA92x; -#pragma pack () - -/*- Functions declaration */ - -void DLMakeMasterBlock(MasterBlockHeader* pMasterBlock, UINT32 nOfDevices, UINT32 DLerVersion); -void DLmakeDeviceHeader(DeviceHeader_V11* devHeader, UINT32 numOfImages); -UINT16 DLgetMasterBlockHeaderChksum(MasterBlockHeader *mBlockHeader); -void DLaddDeviceToMasterHeader(PMasterBlockHeader mbHeader); -void DLaddImageToDeviceHeader(PDeviceHeader_V11 pDev, PImageStruct_V11 pImageStruct); -//void startFlashProgramming(void); - -void DLmakeImageStruct( PImageStruct_V11 pImageStruct, - UINT32 commands, /* bit switches */ - UINT32 BlockDevice_Start_Block, /* start block in Block device */ - UINT32 length, /* Block length in bytes */ - UINT32 Flash_Start_Address /* start address in flash */ - ); - - -typedef struct -{ - UINT16* startAddr; - UINT32 nOfBlocksToErase; - UINT32 Flash_block_size; /* flash device block size */ -} BlockRange; - - -/* -typedef enum -{ - INVALID = 0, - READ_REQ, - READ_PENDING, - READ_COMPLETE, - FLASH_WRITING - -} BlockStatus; - -typedef struct -{ - UINT32 sectorNumber; - UINT16* ptrBuffer; - BlockStatus status; -} BlockDeviceHandle; - - -*/ - -typedef struct -{ - UINT32 DumpAddressRange; - UINT32 FlashStartAddress; - UINT32 length; - UINT32 Core_ID; -} FilePreamble; - - -typedef void (*pfnDebugLog)(TCHAR* pLogEntry); - -#endif // DOWNLOADER_H - diff --git a/fbfdownloader/src/fbfdownload.h b/fbfdownloader/src/fbfdownload.h deleted file mode 100644 index 598188a52..000000000 --- a/fbfdownloader/src/fbfdownload.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef FBF_H -#define FBF_H - -#include -#include - -//return 0 SUCCRSS -//return 1 FAIL -//timeout 0 Infinite Wait -//timeout >0 Wait N seconds for Download -#ifdef __cplusplus -extern "C"{ -#endif -int fbfdownload(char * strBinFilePath, int timeout); - -#ifdef __cplusplus -} -#endif - - - -#endif diff --git a/fbfdownloader/src/khash.h b/fbfdownloader/src/khash.h deleted file mode 100644 index cfafeab94..000000000 --- a/fbfdownloader/src/khash.h +++ /dev/null @@ -1,627 +0,0 @@ -/* The MIT License - - Copyright (c) 2008, 2009, 2011 by Attractive Chaos - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. -*/ - -/* - An example: - -#include "khash.h" -KHASH_MAP_INIT_INT(32, char) -int main() { - int ret, is_missing; - khiter_t k; - khash_t(32) *h = kh_init(32); - k = kh_put(32, h, 5, &ret); - kh_value(h, k) = 10; - k = kh_get(32, h, 10); - is_missing = (k == kh_end(h)); - k = kh_get(32, h, 5); - kh_del(32, h, k); - for (k = kh_begin(h); k != kh_end(h); ++k) - if (kh_exist(h, k)) kh_value(h, k) = 1; - kh_destroy(32, h); - return 0; -} -*/ - -/* - 2013-05-02 (0.2.8): - - * Use quadratic probing. When the capacity is power of 2, stepping function - i*(i+1)/2 guarantees to traverse each bucket. It is better than double - hashing on cache performance and is more robust than linear probing. - - In theory, double hashing should be more robust than quadratic probing. - However, my implementation is probably not for large hash tables, because - the second hash function is closely tied to the first hash function, - which reduce the effectiveness of double hashing. - - Reference: http://research.cs.vt.edu/AVresearch/hashing/quadratic.php - - 2011-12-29 (0.2.7): - - * Minor code clean up; no actual effect. - - 2011-09-16 (0.2.6): - - * The capacity is a power of 2. This seems to dramatically improve the - speed for simple keys. Thank Zilong Tan for the suggestion. Reference: - - - http://code.google.com/p/ulib/ - - http://nothings.org/computer/judy/ - - * Allow to optionally use linear probing which usually has better - performance for random input. Double hashing is still the default as it - is more robust to certain non-random input. - - * Added Wang's integer hash function (not used by default). This hash - function is more robust to certain non-random input. - - 2011-02-14 (0.2.5): - - * Allow to declare global functions. - - 2009-09-26 (0.2.4): - - * Improve portability - - 2008-09-19 (0.2.3): - - * Corrected the example - * Improved interfaces - - 2008-09-11 (0.2.2): - - * Improved speed a little in kh_put() - - 2008-09-10 (0.2.1): - - * Added kh_clear() - * Fixed a compiling error - - 2008-09-02 (0.2.0): - - * Changed to token concatenation which increases flexibility. - - 2008-08-31 (0.1.2): - - * Fixed a bug in kh_get(), which has not been tested previously. - - 2008-08-31 (0.1.1): - - * Added destructor -*/ - - -#ifndef __AC_KHASH_H -#define __AC_KHASH_H - -/*! - @header - - Generic hash table library. - */ - -#define AC_VERSION_KHASH_H "0.2.8" - -#include -#include -#include - -/* compiler specific configuration */ - -#if UINT_MAX == 0xffffffffu -typedef unsigned int khint32_t; -#elif ULONG_MAX == 0xffffffffu -typedef unsigned long khint32_t; -#endif - -#if ULONG_MAX == ULLONG_MAX -typedef unsigned long khint64_t; -#else -typedef unsigned long long khint64_t; -#endif - -#ifndef kh_inline -#ifdef _MSC_VER -#define kh_inline __inline -#else -#define kh_inline inline -#endif -#endif /* kh_inline */ - -#ifndef klib_unused -#if (defined __clang__ && __clang_major__ >= 3) || (defined __GNUC__ && __GNUC__ >= 3) -#define klib_unused __attribute__ ((__unused__)) -#else -#define klib_unused -#endif -#endif /* klib_unused */ - -typedef khint32_t khint_t; -typedef khint_t khiter_t; - -#define __ac_isempty(flag, i) ((flag[i>>4]>>((i&0xfU)<<1))&2) -#define __ac_isdel(flag, i) ((flag[i>>4]>>((i&0xfU)<<1))&1) -#define __ac_iseither(flag, i) ((flag[i>>4]>>((i&0xfU)<<1))&3) -#define __ac_set_isdel_false(flag, i) (flag[i>>4]&=~(1ul<<((i&0xfU)<<1))) -#define __ac_set_isempty_false(flag, i) (flag[i>>4]&=~(2ul<<((i&0xfU)<<1))) -#define __ac_set_isboth_false(flag, i) (flag[i>>4]&=~(3ul<<((i&0xfU)<<1))) -#define __ac_set_isdel_true(flag, i) (flag[i>>4]|=1ul<<((i&0xfU)<<1)) - -#define __ac_fsize(m) ((m) < 16? 1 : (m)>>4) - -#ifndef kroundup32 -#define kroundup32(x) (--(x), (x)|=(x)>>1, (x)|=(x)>>2, (x)|=(x)>>4, (x)|=(x)>>8, (x)|=(x)>>16, ++(x)) -#endif - -#ifndef kcalloc -#define kcalloc(N,Z) calloc(N,Z) -#endif -#ifndef kmalloc -#define kmalloc(Z) malloc(Z) -#endif -#ifndef krealloc -#define krealloc(P,Z) realloc(P,Z) -#endif -#ifndef kfree -#define kfree(P) free(P) -#endif - -static const double __ac_HASH_UPPER = 0.77; - -#define __KHASH_TYPE(name, khkey_t, khval_t) \ - typedef struct kh_##name##_s { \ - khint_t n_buckets, size, n_occupied, upper_bound; \ - khint32_t *flags; \ - khkey_t *keys; \ - khval_t *vals; \ - } kh_##name##_t; - -#define __KHASH_PROTOTYPES(name, khkey_t, khval_t) \ - extern kh_##name##_t *kh_init_##name(void); \ - extern void kh_destroy_##name(kh_##name##_t *h); \ - extern void kh_clear_##name(kh_##name##_t *h); \ - extern khint_t kh_get_##name(const kh_##name##_t *h, khkey_t key); \ - extern int kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets); \ - extern khint_t kh_put_##name(kh_##name##_t *h, khkey_t key, int *ret); \ - extern void kh_del_##name(kh_##name##_t *h, khint_t x); - -#define __KHASH_IMPL(name, SCOPE, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal) \ - SCOPE kh_##name##_t *kh_init_##name(void) { \ - return (kh_##name##_t*)kcalloc(1, sizeof(kh_##name##_t)); \ - } \ - SCOPE void kh_destroy_##name(kh_##name##_t *h) \ - { \ - if (h) { \ - kfree((void *)h->keys); kfree(h->flags); \ - kfree((void *)h->vals); \ - kfree(h); \ - } \ - } \ - SCOPE void kh_clear_##name(kh_##name##_t *h) \ - { \ - if (h && h->flags) { \ - memset(h->flags, 0xaa, __ac_fsize(h->n_buckets) * sizeof(khint32_t)); \ - h->size = h->n_occupied = 0; \ - } \ - } \ - SCOPE khint_t kh_get_##name(const kh_##name##_t *h, khkey_t key) \ - { \ - if (h->n_buckets) { \ - khint_t k, i, last, mask, step = 0; \ - mask = h->n_buckets - 1; \ - k = __hash_func(key); i = k & mask; \ - last = i; \ - while (!__ac_isempty(h->flags, i) && (__ac_isdel(h->flags, i) || !__hash_equal(h->keys[i], key))) { \ - i = (i + (++step)) & mask; \ - if (i == last) return h->n_buckets; \ - } \ - return __ac_iseither(h->flags, i)? h->n_buckets : i; \ - } else return 0; \ - } \ - SCOPE int kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets) \ - { /* This function uses 0.25*n_buckets bytes of working space instead of [sizeof(key_t+val_t)+.25]*n_buckets. */ \ - khint32_t *new_flags = 0; \ - khint_t j = 1; \ - { \ - kroundup32(new_n_buckets); \ - if (new_n_buckets < 4) new_n_buckets = 4; \ - if (h->size >= (khint_t)(new_n_buckets * __ac_HASH_UPPER + 0.5)) j = 0; /* requested size is too small */ \ - else { /* hash table size to be changed (shrink or expand); rehash */ \ - new_flags = (khint32_t*)kmalloc(__ac_fsize(new_n_buckets) * sizeof(khint32_t)); \ - if (!new_flags) return -1; \ - memset(new_flags, 0xaa, __ac_fsize(new_n_buckets) * sizeof(khint32_t)); \ - if (h->n_buckets < new_n_buckets) { /* expand */ \ - khkey_t *new_keys = (khkey_t*)krealloc((void *)h->keys, new_n_buckets * sizeof(khkey_t)); \ - if (!new_keys) { kfree(new_flags); return -1; } \ - h->keys = new_keys; \ - if (kh_is_map) { \ - khval_t *new_vals = (khval_t*)krealloc((void *)h->vals, new_n_buckets * sizeof(khval_t)); \ - if (!new_vals) { kfree(new_flags); return -1; } \ - h->vals = new_vals; \ - } \ - } /* otherwise shrink */ \ - } \ - } \ - if (j) { /* rehashing is needed */ \ - for (j = 0; j != h->n_buckets; ++j) { \ - if (__ac_iseither(h->flags, j) == 0) { \ - khkey_t key = h->keys[j]; \ - khval_t val; \ - khint_t new_mask; \ - new_mask = new_n_buckets - 1; \ - if (kh_is_map) val = h->vals[j]; \ - __ac_set_isdel_true(h->flags, j); \ - while (1) { /* kick-out process; sort of like in Cuckoo hashing */ \ - khint_t k, i, step = 0; \ - k = __hash_func(key); \ - i = k & new_mask; \ - while (!__ac_isempty(new_flags, i)) i = (i + (++step)) & new_mask; \ - __ac_set_isempty_false(new_flags, i); \ - if (i < h->n_buckets && __ac_iseither(h->flags, i) == 0) { /* kick out the existing element */ \ - { khkey_t tmp = h->keys[i]; h->keys[i] = key; key = tmp; } \ - if (kh_is_map) { khval_t tmp = h->vals[i]; h->vals[i] = val; val = tmp; } \ - __ac_set_isdel_true(h->flags, i); /* mark it as deleted in the old hash table */ \ - } else { /* write the element and jump out of the loop */ \ - h->keys[i] = key; \ - if (kh_is_map) h->vals[i] = val; \ - break; \ - } \ - } \ - } \ - } \ - if (h->n_buckets > new_n_buckets) { /* shrink the hash table */ \ - h->keys = (khkey_t*)krealloc((void *)h->keys, new_n_buckets * sizeof(khkey_t)); \ - if (kh_is_map) h->vals = (khval_t*)krealloc((void *)h->vals, new_n_buckets * sizeof(khval_t)); \ - } \ - kfree(h->flags); /* free the working space */ \ - h->flags = new_flags; \ - h->n_buckets = new_n_buckets; \ - h->n_occupied = h->size; \ - h->upper_bound = (khint_t)(h->n_buckets * __ac_HASH_UPPER + 0.5); \ - } \ - return 0; \ - } \ - SCOPE khint_t kh_put_##name(kh_##name##_t *h, khkey_t key, int *ret) \ - { \ - khint_t x; \ - if (h->n_occupied >= h->upper_bound) { /* update the hash table */ \ - if (h->n_buckets > (h->size<<1)) { \ - if (kh_resize_##name(h, h->n_buckets - 1) < 0) { /* clear "deleted" elements */ \ - *ret = -1; return h->n_buckets; \ - } \ - } else if (kh_resize_##name(h, h->n_buckets + 1) < 0) { /* expand the hash table */ \ - *ret = -1; return h->n_buckets; \ - } \ - } /* TODO: to implement automatically shrinking; resize() already support shrinking */ \ - { \ - khint_t k, i, site, last, mask = h->n_buckets - 1, step = 0; \ - x = site = h->n_buckets; k = __hash_func(key); i = k & mask; \ - if (__ac_isempty(h->flags, i)) x = i; /* for speed up */ \ - else { \ - last = i; \ - while (!__ac_isempty(h->flags, i) && (__ac_isdel(h->flags, i) || !__hash_equal(h->keys[i], key))) { \ - if (__ac_isdel(h->flags, i)) site = i; \ - i = (i + (++step)) & mask; \ - if (i == last) { x = site; break; } \ - } \ - if (x == h->n_buckets) { \ - if (__ac_isempty(h->flags, i) && site != h->n_buckets) x = site; \ - else x = i; \ - } \ - } \ - } \ - if (__ac_isempty(h->flags, x)) { /* not present at all */ \ - h->keys[x] = key; \ - __ac_set_isboth_false(h->flags, x); \ - ++h->size; ++h->n_occupied; \ - *ret = 1; \ - } else if (__ac_isdel(h->flags, x)) { /* deleted */ \ - h->keys[x] = key; \ - __ac_set_isboth_false(h->flags, x); \ - ++h->size; \ - *ret = 2; \ - } else *ret = 0; /* Don't touch h->keys[x] if present and not deleted */ \ - return x; \ - } \ - SCOPE void kh_del_##name(kh_##name##_t *h, khint_t x) \ - { \ - if (x != h->n_buckets && !__ac_iseither(h->flags, x)) { \ - __ac_set_isdel_true(h->flags, x); \ - --h->size; \ - } \ - } - -#define KHASH_DECLARE(name, khkey_t, khval_t) \ - __KHASH_TYPE(name, khkey_t, khval_t) \ - __KHASH_PROTOTYPES(name, khkey_t, khval_t) - -#define KHASH_INIT2(name, SCOPE, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal) \ - __KHASH_TYPE(name, khkey_t, khval_t) \ - __KHASH_IMPL(name, SCOPE, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal) - -#define KHASH_INIT(name, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal) \ - KHASH_INIT2(name, static kh_inline klib_unused, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal) - -/* --- BEGIN OF HASH FUNCTIONS --- */ - -/*! @function - @abstract Integer hash function - @param key The integer [khint32_t] - @return The hash value [khint_t] - */ -#define kh_int_hash_func(key) (khint32_t)(key) -/*! @function - @abstract Integer comparison function - */ -#define kh_int_hash_equal(a, b) ((a) == (b)) -/*! @function - @abstract 64-bit integer hash function - @param key The integer [khint64_t] - @return The hash value [khint_t] - */ -#define kh_int64_hash_func(key) (khint32_t)((key)>>33^(key)^(key)<<11) -/*! @function - @abstract 64-bit integer comparison function - */ -#define kh_int64_hash_equal(a, b) ((a) == (b)) -/*! @function - @abstract const char* hash function - @param s Pointer to a null terminated string - @return The hash value - */ -static kh_inline khint_t __ac_X31_hash_string(const char *s) -{ - khint_t h = (khint_t)*s; - if (h) for (++s ; *s; ++s) h = (h << 5) - h + (khint_t)*s; - return h; -} -/*! @function - @abstract Another interface to const char* hash function - @param key Pointer to a null terminated string [const char*] - @return The hash value [khint_t] - */ -#define kh_str_hash_func(key) __ac_X31_hash_string(key) -/*! @function - @abstract Const char* comparison function - */ -#define kh_str_hash_equal(a, b) (strcmp(a, b) == 0) - -static kh_inline khint_t __ac_Wang_hash(khint_t key) -{ - key += ~(key << 15); - key ^= (key >> 10); - key += (key << 3); - key ^= (key >> 6); - key += ~(key << 11); - key ^= (key >> 16); - return key; -} -#define kh_int_hash_func2(key) __ac_Wang_hash((khint_t)key) - -/* --- END OF HASH FUNCTIONS --- */ - -/* Other convenient macros... */ - -/*! - @abstract Type of the hash table. - @param name Name of the hash table [symbol] - */ -#define khash_t(name) kh_##name##_t - -/*! @function - @abstract Initiate a hash table. - @param name Name of the hash table [symbol] - @return Pointer to the hash table [khash_t(name)*] - */ -#define kh_init(name) kh_init_##name() - -/*! @function - @abstract Destroy a hash table. - @param name Name of the hash table [symbol] - @param h Pointer to the hash table [khash_t(name)*] - */ -#define kh_destroy(name, h) kh_destroy_##name(h) - -/*! @function - @abstract Reset a hash table without deallocating memory. - @param name Name of the hash table [symbol] - @param h Pointer to the hash table [khash_t(name)*] - */ -#define kh_clear(name, h) kh_clear_##name(h) - -/*! @function - @abstract Resize a hash table. - @param name Name of the hash table [symbol] - @param h Pointer to the hash table [khash_t(name)*] - @param s New size [khint_t] - */ -#define kh_resize(name, h, s) kh_resize_##name(h, s) - -/*! @function - @abstract Insert a key to the hash table. - @param name Name of the hash table [symbol] - @param h Pointer to the hash table [khash_t(name)*] - @param k Key [type of keys] - @param r Extra return code: -1 if the operation failed; - 0 if the key is present in the hash table; - 1 if the bucket is empty (never used); 2 if the element in - the bucket has been deleted [int*] - @return Iterator to the inserted element [khint_t] - */ -#define kh_put(name, h, k, r) kh_put_##name(h, k, r) - -/*! @function - @abstract Retrieve a key from the hash table. - @param name Name of the hash table [symbol] - @param h Pointer to the hash table [khash_t(name)*] - @param k Key [type of keys] - @return Iterator to the found element, or kh_end(h) if the element is absent [khint_t] - */ -#define kh_get(name, h, k) kh_get_##name(h, k) - -/*! @function - @abstract Remove a key from the hash table. - @param name Name of the hash table [symbol] - @param h Pointer to the hash table [khash_t(name)*] - @param k Iterator to the element to be deleted [khint_t] - */ -#define kh_del(name, h, k) kh_del_##name(h, k) - -/*! @function - @abstract Test whether a bucket contains data. - @param h Pointer to the hash table [khash_t(name)*] - @param x Iterator to the bucket [khint_t] - @return 1 if containing data; 0 otherwise [int] - */ -#define kh_exist(h, x) (!__ac_iseither((h)->flags, (x))) - -/*! @function - @abstract Get key given an iterator - @param h Pointer to the hash table [khash_t(name)*] - @param x Iterator to the bucket [khint_t] - @return Key [type of keys] - */ -#define kh_key(h, x) ((h)->keys[x]) - -/*! @function - @abstract Get value given an iterator - @param h Pointer to the hash table [khash_t(name)*] - @param x Iterator to the bucket [khint_t] - @return Value [type of values] - @discussion For hash sets, calling this results in segfault. - */ -#define kh_val(h, x) ((h)->vals[x]) - -/*! @function - @abstract Alias of kh_val() - */ -#define kh_value(h, x) ((h)->vals[x]) - -/*! @function - @abstract Get the start iterator - @param h Pointer to the hash table [khash_t(name)*] - @return The start iterator [khint_t] - */ -#define kh_begin(h) (khint_t)(0) - -/*! @function - @abstract Get the end iterator - @param h Pointer to the hash table [khash_t(name)*] - @return The end iterator [khint_t] - */ -#define kh_end(h) ((h)->n_buckets) - -/*! @function - @abstract Get the number of elements in the hash table - @param h Pointer to the hash table [khash_t(name)*] - @return Number of elements in the hash table [khint_t] - */ -#define kh_size(h) ((h)->size) - -/*! @function - @abstract Get the number of buckets in the hash table - @param h Pointer to the hash table [khash_t(name)*] - @return Number of buckets in the hash table [khint_t] - */ -#define kh_n_buckets(h) ((h)->n_buckets) - -/*! @function - @abstract Iterate over the entries in the hash table - @param h Pointer to the hash table [khash_t(name)*] - @param kvar Variable to which key will be assigned - @param vvar Variable to which value will be assigned - @param code Block of code to execute - */ -#define kh_foreach(h, kvar, vvar, code) { khint_t __i; \ - for (__i = kh_begin(h); __i != kh_end(h); ++__i) { \ - if (!kh_exist(h,__i)) continue; \ - (kvar) = kh_key(h,__i); \ - (vvar) = kh_val(h,__i); \ - code; \ - } } - -/*! @function - @abstract Iterate over the values in the hash table - @param h Pointer to the hash table [khash_t(name)*] - @param vvar Variable to which value will be assigned - @param code Block of code to execute - */ -#define kh_foreach_value(h, vvar, code) { khint_t __i; \ - for (__i = kh_begin(h); __i != kh_end(h); ++__i) { \ - if (!kh_exist(h,__i)) continue; \ - (vvar) = kh_val(h,__i); \ - code; \ - } } - -/* More convenient interfaces */ - -/*! @function - @abstract Instantiate a hash set containing integer keys - @param name Name of the hash table [symbol] - */ -#define KHASH_SET_INIT_INT(name) \ - KHASH_INIT(name, khint32_t, char, 0, kh_int_hash_func, kh_int_hash_equal) - -/*! @function - @abstract Instantiate a hash map containing integer keys - @param name Name of the hash table [symbol] - @param khval_t Type of values [type] - */ -#define KHASH_MAP_INIT_INT(name, khval_t) \ - KHASH_INIT(name, khint32_t, khval_t, 1, kh_int_hash_func, kh_int_hash_equal) - -/*! @function - @abstract Instantiate a hash set containing 64-bit integer keys - @param name Name of the hash table [symbol] - */ -#define KHASH_SET_INIT_INT64(name) \ - KHASH_INIT(name, khint64_t, char, 0, kh_int64_hash_func, kh_int64_hash_equal) - -/*! @function - @abstract Instantiate a hash map containing 64-bit integer keys - @param name Name of the hash table [symbol] - @param khval_t Type of values [type] - */ -#define KHASH_MAP_INIT_INT64(name, khval_t) \ - KHASH_INIT(name, khint64_t, khval_t, 1, kh_int64_hash_func, kh_int64_hash_equal) - -typedef const char *kh_cstr_t; -/*! @function - @abstract Instantiate a hash map containing const char* keys - @param name Name of the hash table [symbol] - */ -#define KHASH_SET_INIT_STR(name) \ - KHASH_INIT(name, kh_cstr_t, char, 0, kh_str_hash_func, kh_str_hash_equal) - -/*! @function - @abstract Instantiate a hash map containing const char* keys - @param name Name of the hash table [symbol] - @param khval_t Type of values [type] - */ -#define KHASH_MAP_INIT_STR(name, khval_t) \ - KHASH_INIT(name, kh_cstr_t, khval_t, 1, kh_str_hash_func, kh_str_hash_equal) - -#endif /* __AC_KHASH_H */ diff --git a/fbfdownloader/src/klist.h b/fbfdownloader/src/klist.h deleted file mode 100644 index 09a94bfa9..000000000 --- a/fbfdownloader/src/klist.h +++ /dev/null @@ -1,169 +0,0 @@ -/* The MIT License - - Copyright (c) 2008-2009, by Attractive Chaos - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. -*/ - -#ifndef _AC_KLIST_H -#define _AC_KLIST_H - -#include - -#ifndef klib_unused -#if (defined __clang__ && __clang_major__ >= 3) || (defined __GNUC__ && __GNUC__ >= 3) -#define klib_unused __attribute__ ((__unused__)) -#else -#define klib_unused -#endif -#endif /* klib_unused */ - -#define KMEMPOOL_INIT2(SCOPE, name, kmptype_t, kmpfree_f) \ - typedef struct { \ - size_t cnt, n, max; \ - kmptype_t **buf; \ - } kmp_##name##_t; \ - SCOPE kmp_##name##_t *kmp_init_##name(void) { \ - return (kmp_##name##_t *)calloc(1, sizeof(kmp_##name##_t)); \ - } \ - SCOPE void kmp_destroy_##name(kmp_##name##_t *mp) { \ - size_t k; \ - for (k = 0; k < mp->n; ++k) { \ - kmpfree_f(mp->buf[k]); free(mp->buf[k]); \ - } \ - free(mp->buf); free(mp); \ - } \ - SCOPE kmptype_t *kmp_alloc_##name(kmp_##name##_t *mp) { \ - ++mp->cnt; \ - if (mp->n == 0) return (kmptype_t *)calloc(1, sizeof(kmptype_t)); \ - return mp->buf[--mp->n]; \ - } \ - SCOPE void kmp_free_##name(kmp_##name##_t *mp, kmptype_t *p) { \ - --mp->cnt; \ - if (mp->n == mp->max) { \ - mp->max = mp->max? mp->max<<1 : 16; \ - mp->buf = (kmptype_t **)realloc(mp->buf, sizeof(kmptype_t *) * mp->max); \ - } \ - mp->buf[mp->n++] = p; \ - } - -#define KMEMPOOL_INIT(name, kmptype_t, kmpfree_f) \ - KMEMPOOL_INIT2(static inline klib_unused, name, kmptype_t, kmpfree_f) - -#define kmempool_t(name) kmp_##name##_t -#define kmp_init(name) kmp_init_##name() -#define kmp_destroy(name, mp) kmp_destroy_##name(mp) -#define kmp_alloc(name, mp) kmp_alloc_##name(mp) -#define kmp_free(name, mp, p) kmp_free_##name(mp, p) - -#define KLIST_INIT2(SCOPE, name, kltype_t, kmpfree_t) \ - struct __kl1_##name { \ - kltype_t data; \ - struct __kl1_##name *next; \ - }; \ - typedef struct __kl1_##name kl1_##name; \ - KMEMPOOL_INIT2(SCOPE, name, kl1_##name, kmpfree_t) \ - typedef struct { \ - kl1_##name *head, *tail; \ - kmp_##name##_t *mp; \ - size_t size; \ - } kl_##name##_t; \ - SCOPE kl_##name##_t *kl_init_##name(void) { \ - kl_##name##_t *kl = (kl_##name##_t *)calloc(1, sizeof(kl_##name##_t)); \ - kl->mp = kmp_init(name); \ - kl->head = kl->tail = kmp_alloc(name, kl->mp); \ - kl->head->next = 0; \ - return kl; \ - } \ - SCOPE void kl_destroy_##name(kl_##name##_t *kl) { \ - kl1_##name *p; \ - if (kl == NULL) return; \ - for (p = kl->head; p != kl->tail; p = p->next) \ - kmp_free(name, kl->mp, p); \ - kmp_free(name, kl->mp, p); \ - kmp_destroy(name, kl->mp); \ - free(kl);kl=NULL; \ - } \ - SCOPE kltype_t *kl_pushp_##name(kl_##name##_t *kl) { \ - kl1_##name *q, *p = kmp_alloc(name, kl->mp); \ - q = kl->tail; p->next = 0; kl->tail->next = p; kl->tail = p; \ - ++kl->size; \ - return &q->data; \ - } \ - SCOPE kltype_t *kl_pushf_##name(kl_##name##_t *kl) { \ - kl1_##name *q, *p = kmp_alloc(name, kl->mp); \ - p->next = kl->head; kl->head = p; \ - ++kl->size; \ - return &p->data; \ - } \ - SCOPE kltype_t *kl_back_##name(kl_##name##_t *kl) { \ - kl1_##name *p = kl->head; \ - while (p->next != kl->tail) {p = p->next;} \ - return &p->data; \ - } \ - SCOPE int kl_shift_##name(kl_##name##_t *kl, kltype_t *d) { \ - kl1_##name *p; \ - if (kl->head->next == 0) return -1; \ - --kl->size; \ - p = kl->head; kl->head = kl->head->next; \ - if (d) *d = p->data; \ - kmp_free(name, kl->mp, p); \ - return 0; \ - } \ - SCOPE int kl_erase_##name(kl_##name##_t *kl, kl1_##name **pp) { \ - kl1_##name *p = *pp; \ - if (kl->head->next == 0) return -1; \ - if (p == kl->head) return kl_shift_##name(kl,0); \ - --kl->size; \ - for (kl1_##name *iter=kl->head;iter!=kl->tail;iter=iter->next) \ - if (p == iter->next){iter->next = p->next; \ - kmp_free(name, kl->mp, p);*pp=iter;break;} \ - return 0; \ - } \ - SCOPE size_t kl_size_##name(kl_##name##_t *kl){ \ - return kl->size;} \ - SCOPE void kl_clear_##name(kl_##name##_t *kl){ \ - while(kl_shift_##name(kl,0) != -1){}} - - - -#define KLIST_INIT(name, kltype_t, kmpfree_t) \ - KLIST_INIT2(static inline klib_unused, name, kltype_t, kmpfree_t) - -#define kliter_t(name) kl1_##name -#define klist_t(name) kl_##name##_t -#define kl_val(iter) ((iter)->data) -#define kl_next(iter) ((iter)->next) -#define kl_begin(kl) ((kl)->head) -#define kl_end(kl) ((kl)->tail) - -#define kl_init(name) kl_init_##name() -#define kl_destroy(name, kl) kl_destroy_##name(kl) -#define kl_pushp(name, kl) kl_pushp_##name(kl) -#define kl_pushf(name, kl) kl_pushf_##name(kl) -#define kl_back(name, kl) kl_back_##name(kl) -#define kl_shift(name, kl, d) kl_shift_##name(kl, d) -#define kl_erase(name, kl, pp) kl_erase_##name(kl, pp) -#define kl_size(name, kl) kl_size_##name(kl) -#define kl_clear(name, kl) kl_clear_##name(kl) - - -#endif diff --git a/fbfdownloader/src/kstring.c b/fbfdownloader/src/kstring.c deleted file mode 100644 index 262df91de..000000000 --- a/fbfdownloader/src/kstring.c +++ /dev/null @@ -1,294 +0,0 @@ -#include -#include -#include -#include -#include -#include "kstring.h" - -int kvsprintf(kstring_t *s, const char *fmt, va_list ap) -{ - va_list args; - int l; - va_copy(args, ap); - l = vsnprintf(s->s + s->l, s->m - s->l, fmt, args); // This line does not work with glibc 2.0. See `man snprintf'. - va_end(args); - if (l + 1 > s->m - s->l) { - s->m = s->l + l + 2; - kroundup32(s->m); - s->s = (char*)realloc(s->s, s->m); - va_copy(args, ap); - l = vsnprintf(s->s + s->l, s->m - s->l, fmt, args); - va_end(args); - } - s->l += l; - return l; -} - -int ksprintf(kstring_t *s, const char *fmt, ...) -{ - va_list ap; - int l; - va_start(ap, fmt); - l = kvsprintf(s, fmt, ap); - va_end(ap); - return l; -} - -char *kstrtok(const char *str, const char *sep_in, ks_tokaux_t *aux) -{ - const unsigned char *p, *start, *sep = (unsigned char *) sep_in; - if (sep) { // set up the table - if (str == 0 && aux->finished) return 0; // no need to set up if we have finished - aux->finished = 0; - if (sep[0] && sep[1]) { - aux->sep = -1; - aux->tab[0] = aux->tab[1] = aux->tab[2] = aux->tab[3] = 0; - for (p = sep; *p; ++p) aux->tab[*p>>6] |= 1ull<<(*p&0x3f); - } else aux->sep = sep[0]; - } - if (aux->finished) return 0; - else if (str) start = (unsigned char *) str, aux->finished = 0; - else start = (unsigned char *) aux->p + 1; - if (aux->sep < 0) { - for (p = start; *p; ++p) - if (aux->tab[*p>>6]>>(*p&0x3f)&1) break; - } else { - for (p = start; *p; ++p) - if (*p == aux->sep) break; - } - aux->p = (const char *) p; // end of token - if (*p == 0) aux->finished = 1; // no more tokens - return (char*)start; -} - -// s MUST BE a null terminated string; l = strlen(s) -int ksplit_core(char *s, int delimiter, int *_max, int **_offsets) -{ - int i, n, max, last_char, last_start, *offsets, l; - n = 0; max = *_max; offsets = *_offsets; - l = strlen(s); - -#define __ksplit_aux do { \ - if (_offsets) { \ - s[i] = 0; \ - if (n == max) { \ - int *tmp; \ - max = max? max<<1 : 2; \ - if ((tmp = (int*)realloc(offsets, sizeof(int) * max))) { \ - offsets = tmp; \ - } else { \ - free(offsets); \ - *_offsets = NULL; \ - return 0; \ - } \ - } \ - offsets[n++] = last_start; \ - } else ++n; \ - } while (0) - - for (i = 0, last_char = last_start = 0; i <= l; ++i) { - if (delimiter == 0) { - if (isspace(s[i]) || s[i] == 0) { - if (isgraph(last_char)) __ksplit_aux; // the end of a field - } else { - if (isspace(last_char) || last_char == 0) last_start = i; - } - } else { - if (s[i] == delimiter || s[i] == 0) { - if (last_char != 0 && last_char != delimiter) __ksplit_aux; // the end of a field - } else { - if (last_char == delimiter || last_char == 0) last_start = i; - } - } - last_char = s[i]; - } - *_max = max; *_offsets = offsets; - return n; -} - -int kgetline(kstring_t *s, kgets_func *fgets_fn, void *fp) -{ - size_t l0 = s->l; - - while (s->l == l0 || s->s[s->l-1] != '\n') { - if (s->m - s->l < 200) ks_resize(s, s->m + 200); - if (fgets_fn(s->s + s->l, s->m - s->l, fp) == NULL) break; - s->l += strlen(s->s + s->l); - } - - if (s->l == l0) return EOF; - - if (s->l > l0 && s->s[s->l-1] == '\n') { - s->l--; - if (s->l > l0 && s->s[s->l-1] == '\r') s->l--; - } - s->s[s->l] = '\0'; - return 0; -} - -/********************** - * Boyer-Moore search * - **********************/ - -typedef unsigned char ubyte_t; - -// reference: http://www-igm.univ-mlv.fr/~lecroq/string/node14.html -static int *ksBM_prep(const ubyte_t *pat, int m) -{ - int i, *suff, *prep, *bmGs, *bmBc; - prep = (int*)calloc(m + 256, sizeof(int)); - bmGs = prep; bmBc = prep + m; - { // preBmBc() - for (i = 0; i < 256; ++i) bmBc[i] = m; - for (i = 0; i < m - 1; ++i) bmBc[pat[i]] = m - i - 1; - } - suff = (int*)calloc(m, sizeof(int)); - { // suffixes() - int f = 0, g; - suff[m - 1] = m; - g = m - 1; - for (i = m - 2; i >= 0; --i) { - if (i > g && suff[i + m - 1 - f] < i - g) - suff[i] = suff[i + m - 1 - f]; - else { - if (i < g) g = i; - f = i; - while (g >= 0 && pat[g] == pat[g + m - 1 - f]) --g; - suff[i] = f - g; - } - } - } - { // preBmGs() - int j = 0; - for (i = 0; i < m; ++i) bmGs[i] = m; - for (i = m - 1; i >= 0; --i) - if (suff[i] == i + 1) - for (; j < m - 1 - i; ++j) - if (bmGs[j] == m) - bmGs[j] = m - 1 - i; - for (i = 0; i <= m - 2; ++i) - bmGs[m - 1 - suff[i]] = m - 1 - i; - } - free(suff); - return prep; -} - -void *kmemmem(const void *_str, int n, const void *_pat, int m, int **_prep) -{ - int i, j, *prep = 0, *bmGs, *bmBc; - const ubyte_t *str, *pat; - str = (const ubyte_t*)_str; pat = (const ubyte_t*)_pat; - prep = (_prep == 0 || *_prep == 0)? ksBM_prep(pat, m) : *_prep; - if (_prep && *_prep == 0) *_prep = prep; - bmGs = prep; bmBc = prep + m; - j = 0; - while (j <= n - m) { - for (i = m - 1; i >= 0 && pat[i] == str[i+j]; --i); - if (i >= 0) { - int max = bmBc[str[i+j]] - m + 1 + i; - if (max < bmGs[i]) max = bmGs[i]; - j += max; - } else return (void*)(str + j); - } - if (_prep == 0) free(prep); - return 0; -} - -char *kstrstr(const char *str, const char *pat, int **_prep) -{ - return (char*)kmemmem(str, strlen(str), pat, strlen(pat), _prep); -} - -char *kstrnstr(const char *str, const char *pat, int n, int **_prep) -{ - return (char*)kmemmem(str, n, pat, strlen(pat), _prep); -} - -void kstrcpy(kstring_t *s, const char *src) -{ - const char *buf = strdup(src); - if (s->s) - free(s->s); - ks_release(s); - kputs(buf, s); - free((void*)buf); - return; -} - - -/*********************** - * The main() function * - ***********************/ - -#ifdef KSTRING_MAIN -#include - -char* WtptpDownLoad_replace_all(char* str,const char* old_value,const char* new_value) -{ - char buf[256]={0}; - char *p = NULL,*pstr = str; - int lo = strlen(old_value); - p = strstr(pstr, old_value); - while (p) - { - strncat(buf, pstr, p-pstr); - strcat(buf, new_value); - pstr = p + lo; - p = strstr(pstr,old_value); - } - strcat(buf,pstr); - strcpy(str, buf); - return str; -} -typedef const char* t_conststr; - -int main() -{ - kstring_t *s; - t_conststr a,b; - int *fields, n, i; - ks_tokaux_t aux; - char *p; - char buf[256] = "asdhesdafhehew"; - a = "abc"; - b = "bcd"; - s = (kstring_t*)calloc(1, sizeof(kstring_t)); - // test ksprintf() - ksprintf(s, "abcdefg:%d", 100); - printf("'%s'\n", s->s); - kputs("hehe ",s); - printf("%s\n", s->s); - - ksprintf(s, "abc%sdefg:", "hehehe"); - printf("!!!!%s\n", s->s); - // test ksplit() - fields = ksplit(s, 0, &n); - for (i = 0; i < n; ++i) - printf("field[%d] = '%s'\n", i, s->s + fields[i]); - kstrcpy(s,s->s+fields[0]); - printf("@@@%s\n", s->s); - printf("replace:%s\n",WtptpDownLoad_replace_all(buf,"he","hello")); - // test kstrtok() - s->l = 0; - for (p = kstrtok("ab:cde:fg/hij::k", ":/", &aux); p; p = kstrtok(0, 0, &aux)) { - kputsn(p, aux.p - p, s); - kputc('\n', s); - } - printf("%s", s->s); - // free - free(s->s); free(s); free(fields); - - { - static char *str = "abcdefgcdgcagtcakcdcd"; - static char *pat = "cd"; - char *ret, *s = str; - int *prep = 0; - while ((ret = kstrstr(s, pat, &prep)) != 0) { - printf("match: %s\n", ret); - s = ret + prep[0]; - } - free(prep); - } - return 0; -} -#endif diff --git a/fbfdownloader/src/kstring.h b/fbfdownloader/src/kstring.h deleted file mode 100644 index f14226eea..000000000 --- a/fbfdownloader/src/kstring.h +++ /dev/null @@ -1,278 +0,0 @@ -/* The MIT License - - Copyright (c) by Attractive Chaos - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. -*/ - -#ifndef KSTRING_H -#define KSTRING_H - -#include -#include -#include -#include -#include - -#ifndef kroundup32 -#define kroundup32(x) (--(x), (x)|=(x)>>1, (x)|=(x)>>2, (x)|=(x)>>4, (x)|=(x)>>8, (x)|=(x)>>16, ++(x)) -#endif - -#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4) -#define KS_ATTR_PRINTF(fmt, arg) __attribute__((__format__ (__printf__, fmt, arg))) -#else -#define KS_ATTR_PRINTF(fmt, arg) -#endif - - -/* kstring_t is a simple non-opaque type whose fields are likely to be - * used directly by user code (but see also ks_str() and ks_len() below). - * A kstring_t object is initialised by either of - * kstring_t str = { 0, 0, NULL }; - * kstring_t str; ...; str.l = str.m = 0; str.s = NULL; - * and either ownership of the underlying buffer should be given away before - * the object disappears (see ks_release() below) or the kstring_t should be - * destroyed with free(str.s); */ -#ifndef KSTRING_T -#define KSTRING_T kstring_t -typedef struct __kstring_t { - size_t l, m; - char *s; -} kstring_t; -#endif - -typedef struct { - uint64_t tab[4]; - int sep, finished; - const char *p; // end of the current token -} ks_tokaux_t; - -#ifdef __cplusplus -extern "C" { -#endif - - int kvsprintf(kstring_t *s, const char *fmt, va_list ap) KS_ATTR_PRINTF(2,0); - int ksprintf(kstring_t *s, const char *fmt, ...) KS_ATTR_PRINTF(2,3); - int ksplit_core(char *s, int delimiter, int *_max, int **_offsets); - char *kstrstr(const char *str, const char *pat, int **_prep); - char *kstrnstr(const char *str, const char *pat, int n, int **_prep); - void *kmemmem(const void *_str, int n, const void *_pat, int m, int **_prep); - void kstrcpy(kstring_t *s, const char *src); - - /* kstrtok() is similar to strtok_r() except that str is not - * modified and both str and sep can be NULL. For efficiency, it is - * actually recommended to set both to NULL in the subsequent calls - * if sep is not changed. */ - char *kstrtok(const char *str, const char *sep, ks_tokaux_t *aux); - - /* kgetline() uses the supplied fgets()-like function to read a "\n"- - * or "\r\n"-terminated line from fp. The line read is appended to the - * kstring without its terminator and 0 is returned; EOF is returned at - * EOF or on error (determined by querying fp, as per fgets()). */ - typedef char *kgets_func(char *, int, void *); - int kgetline(kstring_t *s, kgets_func *fgets, void *fp); - -#ifdef __cplusplus -} -#endif - -static inline int ks_resize(kstring_t *s, size_t size) -{ - if (s->m < size) { - char *tmp; - s->m = size; - kroundup32(s->m); - if ((tmp = (char*)realloc(s->s, s->m))) - s->s = tmp; - else - return -1; - } - return 0; -} - -static inline char *ks_str(kstring_t *s) -{ - return s->s; -} - -static inline size_t ks_len(kstring_t *s) -{ - return s->l; -} - -// Give ownership of the underlying buffer away to something else (making -// that something else responsible for freeing it), leaving the kstring_t -// empty and ready to be used again, or ready to go out of scope without -// needing free(str.s) to prevent a memory leak. -static inline char *ks_release(kstring_t *s) -{ - char *ss = s->s; - s->l = s->m = 0; - s->s = NULL; - return ss; -} - -static inline int kputsn(const char *p, int l, kstring_t *s) -{ - if (s->l + l + 1 >= s->m) { - char *tmp; - s->m = s->l + l + 2; - kroundup32(s->m); - if ((tmp = (char*)realloc(s->s, s->m))) - s->s = tmp; - else - return EOF; - } - memcpy(s->s + s->l, p, l); - s->l += l; - s->s[s->l] = 0; - return l; -} - -static inline int kputs(const char *p, kstring_t *s) -{ - return kputsn(p, strlen(p), s); -} - -static inline int kputc(int c, kstring_t *s) -{ - if (s->l + 1 >= s->m) { - char *tmp; - s->m = s->l + 2; - kroundup32(s->m); - if ((tmp = (char*)realloc(s->s, s->m))) - s->s = tmp; - else - return EOF; - } - s->s[s->l++] = c; - s->s[s->l] = 0; - return c; -} - -static inline int kputc_(int c, kstring_t *s) -{ - if (s->l + 1 > s->m) { - char *tmp; - s->m = s->l + 1; - kroundup32(s->m); - if ((tmp = (char*)realloc(s->s, s->m))) - s->s = tmp; - else - return EOF; - } - s->s[s->l++] = c; - return 1; -} - -static inline int kputsn_(const void *p, int l, kstring_t *s) -{ - if (s->l + l > s->m) { - char *tmp; - s->m = s->l + l; - kroundup32(s->m); - if ((tmp = (char*)realloc(s->s, s->m))) - s->s = tmp; - else - return EOF; - } - memcpy(s->s + s->l, p, l); - s->l += l; - return l; -} - -static inline int kputw(int c, kstring_t *s) -{ - char buf[16]; - int i, l = 0; - unsigned int x = c; - if (c < 0) x = -x; - do { buf[l++] = x%10 + '0'; x /= 10; } while (x > 0); - if (c < 0) buf[l++] = '-'; - if (s->l + l + 1 >= s->m) { - char *tmp; - s->m = s->l + l + 2; - kroundup32(s->m); - if ((tmp = (char*)realloc(s->s, s->m))) - s->s = tmp; - else - return EOF; - } - for (i = l - 1; i >= 0; --i) s->s[s->l++] = buf[i]; - s->s[s->l] = 0; - return 0; -} - -static inline int kputuw(unsigned c, kstring_t *s) -{ - char buf[16]; - int l, i; - unsigned x; - if (c == 0) return kputc('0', s); - for (l = 0, x = c; x > 0; x /= 10) buf[l++] = x%10 + '0'; - if (s->l + l + 1 >= s->m) { - char *tmp; - s->m = s->l + l + 2; - kroundup32(s->m); - if ((tmp = (char*)realloc(s->s, s->m))) - s->s = tmp; - else - return EOF; - } - for (i = l - 1; i >= 0; --i) s->s[s->l++] = buf[i]; - s->s[s->l] = 0; - return 0; -} - -static inline int kputl(long c, kstring_t *s) -{ - char buf[32]; - int i, l = 0; - unsigned long x = c; - if (c < 0) x = -x; - do { buf[l++] = x%10 + '0'; x /= 10; } while (x > 0); - if (c < 0) buf[l++] = '-'; - if (s->l + l + 1 >= s->m) { - char *tmp; - s->m = s->l + l + 2; - kroundup32(s->m); - if ((tmp = (char*)realloc(s->s, s->m))) - s->s = tmp; - else - return EOF; - } - for (i = l - 1; i >= 0; --i) s->s[s->l++] = buf[i]; - s->s[s->l] = 0; - return 0; -} - -/* - * Returns 's' split by delimiter, with *n being the number of components; - * NULL on failue. - */ -static inline int *ksplit(kstring_t *s, int delimiter, int *n) -{ - int max = 0, *offsets = 0; - *n = ksplit_core(s->s, delimiter, &max, &offsets); - return offsets; -} - -#endif diff --git a/fbfdownloader/src/libmakefile b/fbfdownloader/src/libmakefile deleted file mode 100644 index c9781ea18..000000000 --- a/fbfdownloader/src/libmakefile +++ /dev/null @@ -1,49 +0,0 @@ -############################################################### -# Makefile for the Marvell download for MMP2/wukong/NEVO. -# -# -############################################################## - -CC = gcc -AR = ar -RM = rm -CP = cp -ECHO = echo -TARGET = libfbfdown.a -include tool.mak #°üº¬×Ómakefile -BASE:=$(shell pwd) -LIBS = -lpthread -INCLUDES = -I./ -CCFLAGS += -O2 $(INCLUDES) -D LINUX=1 -D _FILE_OFFSET_BITS=64 -D WINDOWS=0 -D DEBUG_MODE=0 -D TRUSTED_BOOT=1 -D IFLSWD_STATIC -D STATICLIB_FBFDOWNLOAD -D PRINTLOG=1 -g -std=c99 - - -TBBOBJS =CommonFun.o\ - ParaDefine.o\ - WTPCOMMCLASS.o \ - BinFileWtp.o\ - WtptpDownloader.o \ - WtptpDownLoad.o\ - ConvetEdian.o\ - BulkDevNonDrv_Linux.o\ - kstring.o\ - FBFDownloader.o\ - - -OBJS = $(TBBOBJS) - -all:$(TARGET) -$(TARGET):$(OBJS) $(LIBS) -ldl - $(BUILD_LIBRARY) - - -$(TBBOBJS): %.o: ./%.c - $(CC) -c $(CCFLAGS) -I./ -c "./$*.c" -o "$(BASE)/$*.o" -.PHONY: clean -clean: - -rm *.o - - - - - - diff --git a/fbfdownloader/src/libmakefile_cross b/fbfdownloader/src/libmakefile_cross deleted file mode 100644 index c72896fbf..000000000 --- a/fbfdownloader/src/libmakefile_cross +++ /dev/null @@ -1,56 +0,0 @@ -############################################################### -# Makefile for the Marvell download for MMP2/wukong/NEVO. -# -# -############################################################## - -#CC = arm_1103_le-g++ -#CC = mipsel-linux-uclibc-g++ -#CC = mipsel-openwrt-linux-g++ -#CC = arm-hisiv200-linux-gnueabi-g++ -CC = ${CROSS}gcc -AR = ar -RM = rm -CP = cp -ECHO = echo -TARGET = libfbfdown_cross.a -include tool.mak #包含子makefile -BASE:=$(shell pwd) -LIBS = -lpthread -INCLUDES = -I./ -CCFLAGS += -O2 $(INCLUDES) -D LINUX=1 -D WINDOWS=0 -D DEBUG_MODE=0 -D TRUSTED_BOOT=1 -D IFLSWD_STATIC -D STATICLIB_FBFDOWNLOAD -D PRINTLOG=1 -std=c99 - -ifneq ($(ANDROIDBLD),1) -CCFLAGS += -D _FILE_OFFSET_BITS=64 -endif - -TBBOBJS =CommonFun.o\ - ParaDefine.o\ - WTPCOMMCLASS.o \ - BinFileWtp.o\ - kstring.o\ - WtptpDownloader.o \ - WtptpDownLoad.o\ - ConvetEdian.o\ - BulkDevNonDrv_Linux.o\ - FBFDownloader.o\ - - -OBJS = $(TBBOBJS) - -all:$(TARGET) -$(TARGET):$(OBJS) $(LIBS) -ldl - $(BUILD_LIBRARY) - - -$(TBBOBJS): %.o: ./%.c - $(CC) -c $(CCFLAGS) -I./ -c "./$*.c" -o "$(BASE)/$*.o" -.PHONY: clean -clean: - -rm *.o - - - - - - diff --git a/fbfdownloader/src/源码说明.txt b/fbfdownloader/src/源码说明.txt deleted file mode 100644 index c2c8d9825..000000000 --- a/fbfdownloader/src/源码说明.txt +++ /dev/null @@ -1,72 +0,0 @@ -交叉编译方法 -以使用buildroot-gcc463交叉编译工具链为例: -gcc bin文件路径为: -/home/toolchain/buildroot-gcc463/usr/bin/mipsel-linux-gcc -export CROSS=/home/toolchain/buildroot-gcc463/usr/bin/mipsel-linux- -cd 源码目录 -make -f FBFDownloader_makefile_cross -对于一些toolchain,需要: -export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/toolchain/buildroot-gcc463/usr/lib - -生成的fbfdownloader_cross即为下载工具。 - -程序入口为:FBFDownloader.c:728 main(int argc, char *argv[]) - -FBFDownloader.c:732 ParseCommandLine为解析参数函数,包括 -b BinFile.bin(必选) --p logFilePath(可选,指定下载过程中log和临时文件生成的目录) - -FBFDownloader.c:780 PInstanceParams lpInstanceParam. 该结构体存放下载相关的参数 - -FBFDownloader.c:790-800 该过程为从BinFile.bin文件中提取下载相关参数。 - -FBFDownloader.c:813 执行下载过程函数InitializeBL(lpInstanceParam) -WtptpDownLoad.c:6 InitializeBL(PInstanceParams pInstParam) -WtptpDownloader.c:2762 BOOL WtptpDownLoad_InitializeBL(struct CWtptpDownLoad *me,PInstanceParams pInstParam) -WtptpDownloader.c:2867-2892 下载前参数解析准备过程。 -WtptpDownloader.c:2901 创建设备检测线程,检测下载口枚举 -WtptpDownloader.c:535 PVOID WtptpDownLoad_WtptpDeviceDetectThread(PVOID Arg) -WtptpDownloader.c:541 WtptpDownLoad_init_hotplug_sock 创建socket,用来检测下载设备hotplug -WtptpDownloader.c:542 BulkDevNonDrv_FindAllSupportedDevices 检测已经接入的下载设备,根据设备的PID和VID判断是否为下载设备 -WtptpDownloader.c:554 下载设备已经存在,打开设备WtptpDownLoad_WtptpOpenDevice -WtptpDownloader.c:581 BulkDevNonDrv_CheckDevForNetLink 检测到下载设备插拔事件 - WtptpDownloader.c:590 设备插入 打开设备 WtptpDownLoad_WtptpOpenDevice - WtptpDownloader.c:610 设备移除 停止下载流程 WtptpDownLoad_SetAndWaitForThreadExit - -打开设备 -WtptpDownloader.c:482 void WtptpDownLoad_WtptpOpenDevice(struct CWtptpDownLoad *me,struct CWtptpDownLoad *pWtptpDownLoad, USB_HANDLE *pLinuxUsb) - WtptpDownloader.c:492-507准备工作,根据设备路径创建Log文件 - WtptpDownloader.c:509 打开设备函数WtptpDownLoad_OpenDevice -WtptpDownloader.c:916 BOOL WtptpDownLoad_OpenDevice(struct CWtptpDownLoad *me,PDEVICE pDev) - WtptpDownloader.c:954 WtptpDownLoad_GetDeviceBootType 获取设备型号和类型,(BootRom,BootLoader) - 该过程主要流程为: - 1、打开USB口 WtptpDownloader.c:725 OpenUsbPort - 2、与芯片进行握手,发送Preamble消息 WtptpDownloader.c:736 SendPreamble - 3、获取芯片当前状态 WtptpDownloader.c:747 GetTargetMessage - 4、发送GetVersion消息,获取芯片型号和类型,WtptpDownloader.c:764 GetVersion - 5、处理GetVersion返回的内容,WtptpDownloader.c:769-912 - 如果设备类型为BootRom,即模块为空板,则创建BootRom下载线程。WtptpDownloader.c:971-988 - BootRom下载(空板下载、ForceDownload)是将OBM下载至模块DDR中,下载完成后,当前BootROM设备会自动移除,随后模块以BootLoader类型接入大板(Host),工具会再次检测到设备接入,且其类型为BootLoader。 - 如果设备类型为BootLoader,即非空板,则创建BootLoader下载线程。WtptpDownloader.c:989-1010 -BootRom和BootLoader下载过程类似,都是通过调用WtptpDownLoad_WTPTPDownLoad函数来进行下载。主要区别是BootLoader下载完成后,会将下载状态设置为kProcCompleted(成功WtptpDownloader.c:251)或kProcAborting(失败WtptpDownloader.c:258),此后工具会退出;BootRom下载完成后工具不会退出,设备检测线程会继续运行。 - -下面将描述下载的核心函数的流程WtptpDownloader.c:2044 BOOL WtptpDownLoad_WTPTPDownLoad(struct CWtptpDownLoad *me,PDEVICE pDev) -WtptpDownloader.c:2049-2141 设置下载相关参数和下载的Image List,计算下载总大小。 -WtptpDownloader.c:2143-2561 对每个image进行下载和烧写 - WtptpDownloader.c:2153 WtptpDownLoad_DownloadImage - WtptpDownloader.c:1019 BOOL WtptpDownLoad_DownloadImage(struct CWtptpDownLoad *me,PDEVICE pdev, int iFile,const t_ImageFileList* plImgFileList, UINT64 uiAllimgsize,UINT64 *uidownloadsize,int nImages,char* strDownloadImgName) - 该函数将image下载至模块DDR中,大致流程为: - 1、SendPreamble - 2、GetVersion - 以上两步在下载第一个image时省略,因为WtptpDownLoad_GetDeviceBootType中已经执行上两个步骤 - 3、SelectImage WtptpDownloader.c:1103 - 4、VerifyImage WtptpDownloader.c:1117 - 5、GetBadBlockInfo WtptpDownloader.c:1188 - 6、DataHeader - 7、Data(将image所有数据通过Data传输完) - 8、Done WtptpDownloader.c:1447 - WtptpDownloader.c:2160-2552 Image下载到DDR后,模块开始将image烧写到flash,该段代码主要通过GetWtpMessage获取模块烧写过程中的状态: - WtptpDownloader.c:2512 当工具收到模块处于PlatformReady状态消息后,表明image烧写完毕。 - -所有image下载烧写完毕后,如果在blf中使能CRC校验(部分平台支持),模块会计算烧写完的image CRC,并上报给工具。WtptpDownloader.c:2565-2596 - -其他说明:上述下载过程中提及的image并非指BinFile.bin文件。BinFile.bin是包括下载参数、下载image等内容的包文件,下载过程中通过BinFileWtp.h中的类(c++移植到c形式的类)来解析。 diff --git a/luci-app-passwall/Makefile b/luci-app-passwall/Makefile index f1bd8b95d..e7e95430f 100644 --- a/luci-app-passwall/Makefile +++ b/luci-app-passwall/Makefile @@ -8,7 +8,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=luci-app-passwall PKG_VERSION:=26.4.15 -PKG_RELEASE:=92 +PKG_RELEASE:=93 PKG_PO_VERSION:=$(PKG_VERSION) PKG_CONFIG_DEPENDS:= \ diff --git a/luci-app-passwall/luasrc/view/passwall/global/footer.htm b/luci-app-passwall/luasrc/view/passwall/global/footer.htm index cf0ac607e..97176c654 100644 --- a/luci-app-passwall/luasrc/view/passwall/global/footer.htm +++ b/luci-app-passwall/luasrc/view/passwall/global/footer.htm @@ -16,6 +16,22 @@ local appname = api.appname display: none !important; visibility: hidden !important; } + +@media screen and (max-width: 1152px) { + #cbi-<%=appname%>-socks .cbi-section-table-titles { + display: none !important; + } +} + +@media screen and (min-width: 1152px) { + #cbi-<%=appname%>-socks input[id*=".<%=appname%>."][id$=".port"], + #cbi-<%=appname%>-socks input[id*=".<%=appname%>."][id$=".http_port"] { + width: 100px !important; + min-width: unset !important; + max-width: unset !important; + text-align: center !important; + } +} +