• Visit https://www.embeddedcomputers.net/ for Hardware; Software and all other things related to FlashcatUSB

DPC3000 Script SPI

Status
Not open for further replies.

D3m0n

Administrator
Staff member
MyDevice = "DPC3000" #Name of device
Imgfile = "images\DPC3000-ISP.jpg" #Name of image

FwBase = 0x40000
FwSize = 8060928
Fw1Base = 0x7F0000
Fw1Size = 8060928
U-BootBase = 0x0
U-BootSize = 131072
Env1Base = 0x20000
Env1Size = 65536
Env2Base = 0x30000
Env2Size = 65536
BlankBase = 0xFA0000
BlankSize = 196608
LogBase = 0xFD0000
LogSize = 131072
CfgBase = 0xFF0000
CfgSize = 65536

JTAG.MemoryType("SPI")
SPIFLASH = JTAG.MemoryInit()


t1 = Tab.Create(MyDevice)
t2 = Tab.Create(Imgfile)

Tab(t1).AddGroup("U-Boot",10,10,100,150)
Tab(t1).AddGroup("Env1",110,10,100,150)
Tab(t1).AddGroup("Env2",210,10,100,150)
Tab(t1).AddGroup("UBFI1",310,10,100,150)
Tab(t1).AddGroup("UBFI2",10,160,100,150)
Tab(t1).AddGroup("Blank",110,160,100,150)
Tab(t1).AddGroup("Log",210,160,100,150)
Tab(t1).AddGroup("Cfg",310,160,100,150)
Tab(t1).AddButton("ReadU-Boot","Read",20,42)
Tab(t1).AddButton("WriteU-Boot","Write",20,102)
Tab(t1).AddButton("ReadEnv1","Read",120,42)
Tab(t1).AddButton("WriteEnv1","Write",120,102)
Tab(t1).AddButton("ReadEnv2","Read",220,42)
Tab(t1).AddButton("WriteEnv2","Write",220,102)
Tab(t1).AddButton("ReadUBFI1","Read",320,42)
Tab(t1).AddButton("WriteUBFI1","Write",320,102)
Tab(t1).AddButton("ReadUBFI2","Read",20,192)
Tab(t1).AddButton("WriteUBFI2","Write",20,252)
Tab(t1).AddButton("ReadBlank","Read",120,192)
Tab(t1).AddButton("WriteBlank","Write",120,252)
Tab(t1).AddButton("ReadLog","Read",220,192)
Tab(t1).AddButton("WriteLog","Write",220,252)
Tab(t1).AddButton("ReadCfg","Read",320,192)
Tab(t1).AddButton("WriteCfg","Write",320,252)
Tab(t2).AddImage("LOGO",ImgFile,120,10)

CreateEvent(ReadU-Boot)
Status("Reading the U-Boot")
Tab(t1).ButtonDisable()
MyData = Memory(SPIFLASH).ReadVerify(U-BootBase,U-BootSize)
if (MyData = Nothing)
Status("Error: data read back failed")
Tab(t1).ButtonEnable()
Exit Event
endif
Prompt = "Choose filename to save the firmware"
SaveFile(MyData,Prompt,"U-Boot.bin")
Status("Successfully read U-Boot from Flash")
Tab(t1).ButtonEnable()
EndEvent


CreateEvent(WriteU-Boot)
Tab(t1).ButtonDisable()
Prompt = "Choose a U-Boot to write into Flash"
MyData = OpenFile(Prompt,"U-Boot files (*.bin)|*.bin")
if (MyData = Nothing)
goto WriteU-BootExit
endif
if not (Len(MyData) = U-BootSize)
Status("Error: File is not the size of the U-Boot")
goto WriteU-BootExit
endif
Memory(SPIFLASH).Write(MyData,U-BootBase,U-BootSize)
Status("New U-Boot successfully written")
WriteU-BootExit:
Tab(t1).ButtonEnable()
EndEvent

CreateEvent(ReadEnv1)
Status("Reading the Env1")
Tab(t1).ButtonDisable()
MyData = Memory(SPIFLASH).ReadVerify(Env1Base,Env1Size)
if (MyData = Nothing)
Status("Error: data read back failed")
Tab(t1).ButtonEnable()
Exit Event
endif
Prompt = "Choose filename to save the firmware"
SaveFile(MyData,Prompt,"Env1.bin")
Status("Successfully read Env1 from Flash")
Tab(t1).ButtonEnable()
EndEvent


CreateEvent(WriteEnv1)
Tab(t1).ButtonDisable()
Prompt = "Choose an Env1 to write into Flash"
MyData = OpenFile(Prompt,"Env1 files (*.bin)|*.bin")
if (MyData = Nothing)
goto WriteEnv1Exit
endif
if not (Len(MyData) = Env1Size)
Status("Error: File is not the size of the Env1")
goto WriteEnv1Exit
endif
Memory(SPIFLASH).Write(MyData,Env1Base,Env1Size)
Status("New Env1 successfully written")
WriteEnv1Exit:
Tab(t1).ButtonEnable()
EndEvent

CreateEvent(ReadEnv2)
Status("Reading the Env2")
Tab(t1).ButtonDisable()
MyData = Memory(SPIFLASH).ReadVerify(Env2Base,Env2Size)
if (MyData = Nothing)
Status("Error: data read back failed")
Tab(t1).ButtonEnable()
Exit Event
endif
Prompt = "Choose filename to save the firmware"
SaveFile(MyData,Prompt,"Env2.bin")
Status("Successfully read Env2 from Flash")
Tab(t1).ButtonEnable()
EndEvent


CreateEvent(WriteEnv2)
Tab(t1).ButtonDisable()
Prompt = "Choose an Env2 to write into Flash"
MyData = OpenFile(Prompt,"Env2 files (*.bin)|*.bin")
if (MyData = Nothing)
goto WriteEnv2Exit
endif
if not (Len(MyData) = Env2Size)
Status("Error: File is not the size of the Env2")
goto WriteEnv2Exit
endif
Memory(SPIFLASH).Write(MyData,Env2Base,Env2Size)
Status("New Env2 successfully written")
WriteEnv2Exit:
Tab(t1).ButtonEnable()
EndEvent

CreateEvent(ReadUBFI1)
Status("Saving the DPC3000's Firmware")
Tab(t1).ButtonDisable()
MyData = Memory(SPIFLASH).ReadVerify(FwBase,FwSize)
if (MyData = Nothing)
Status("Error: data read back failed")
Tab(t1).ButtonEnable()
Exit Event
endif
Prompt = "Choose filename to save the firmware"
SaveFile(MyData,Prompt,"UBFI1.bin")
Status("Successfully read UBFI1 from Flash")
Tab(t1).ButtonEnable()
EndEvent

CreateEvent(WriteUBFI1)
Status("Programming the DPC3000's Firmware")
Tab(t1).ButtonDisable()
Prompt = "Choose a firmware to install"
MyData = OpenFile(Prompt,"Firmware files (*.bin,*.p7)|*.bin;*.p7")
if (MyData = Nothing)
WriteErr = "User cancelled opperation"
goto ExitWriteFwErr
endif
If (HWORD(MyData,0) = 12418) #Remove header if .p7 fw
Writeline("Removing .p7 firmware header")
HeadLen = HWORD(MyData,2) + 52 #increases Headlen by 7
NewLen = Len(MyData) - HeadLen
Resize(MyData,HeadLen,NewLen) #Removes the p7 header
endif
FwLen = Len(MyData)
Memory(SPIFLASH).Write(MyData,FwBase,FwLen)
FwSize = FwLen
Status("New firmware successfully installed")
Tab(t1).ButtonEnable()
Exit
ExitWriteFwErr:
Status(WriteErr)
Tab(t1).ButtonEnable()
EndEvent

CreateEvent(ReadUBFI2)
Status("Saving the DPC3000's Firmware")
Tab(t1).ButtonDisable()
MyData = Memory(SPIFLASH).ReadVerify(Fw1Base,Fw1Size)
if (MyData = Nothing)
Status("Error: data read back failed")
Tab(t1).ButtonEnable()
Exit Event
endif
Prompt = "Choose filename to save the firmware"
SaveFile(MyData,Prompt,"UBFI2.bin")
Status("Successfully read UBFI2 from Flash")
Tab(t1).ButtonEnable()
EndEvent

CreateEvent(WriteUBFI2)
Status("Programming the DPC3000's Firmware")
Tab(t1).ButtonDisable()
Prompt = "Choose a firmware to install"
MyData = OpenFile(Prompt,"Firmware files (*.bin,*.p7)|*.bin;*.p7")
if (MyData = Nothing)
WriteErr = "User cancelled opperation"
goto ExitWriteFwErr
endif
If (HWORD(MyData,0) = 12418) #Remove header if .p7 fw
Writeline("Removing .p7 firmware header")
HeadLen = HWORD(MyData,2) + 52 #increases Headlen by 7
NewLen = Len(MyData) - HeadLen
Resize(MyData,HeadLen,NewLen) #Removes the p7 header
endif
FwLen = Len(MyData)
Memory(SPIFLASH).Write(MyData,Fw1Base,FwLen)
Fw1Size = FwLen
Status("New firmware successfully installed")
Tab(t1).ButtonEnable()
Exit
ExitWriteFwErr:
Status(WriteErr)
Tab(t1).ButtonEnable()
EndEvent

CreateEvent(ReadBlank)
Status("Reading the Blank")
Tab(t1).ButtonDisable()
MyData = Memory(SPIFLASH).ReadVerify(BlankBase,BlankSize)
if (MyData = Nothing)
Status("Error: data read back failed")
Tab(t1).ButtonEnable()
Exit Event
endif
Prompt = "Choose filename to save the firmware"
SaveFile(MyData,Prompt,"Blank.bin")
Status("Successfully read Blank from Flash")
Tab(t1).ButtonEnable()
EndEvent


CreateEvent(WriteBlank)
Tab(t1).ButtonDisable()
Prompt = "Choose a Blank to write into Flash"
MyData = OpenFile(Prompt,"Blank files (*.bin)|*.bin")
if (MyData = Nothing)
goto WriteBlankExit
endif
if not (Len(MyData) = BlankSize)
Status("Error: File is not the size of the Blank")
goto WriteBlankExit
endif
Memory(SPIFLASH).Write(MyData,BlankBase,BlankSize)
Status("New Blank successfully written")
WriteBlankExit:
Tab(t1).ButtonEnable()
EndEvent

CreateEvent(ReadLog)
Status("Reading the Log")
Tab(t1).ButtonDisable()
MyData = Memory(SPIFLASH).ReadVerify(LogBase,LogSize)
if (MyData = Nothing)
Status("Error: data read back failed")
Tab(t1).ButtonEnable()
Exit Event
endif
Prompt = "Choose filename to save the firmware"
SaveFile(MyData,Prompt,"Log.bin")
Status("Successfully read Log from Flash")
Tab(t1).ButtonEnable()
EndEvent


CreateEvent(WriteLog)
Tab(t1).ButtonDisable()
Prompt = "Choose a Log to write into Flash"
MyData = OpenFile(Prompt,"Log files (*.bin)|*.bin")
if (MyData = Nothing)
goto WriteLogExit
endif
if not (Len(MyData) = LogSize)
Status("Error: File is not the size of the Log")
goto WriteLogExit
endif
Memory(SPIFLASH).Write(MyData,LogBase,LogSize)
Status("New Log successfully written")
WriteLogExit:
Tab(t1).ButtonEnable()
EndEvent

CreateEvent(ReadCfg)
Status("Reading the Cfg")
Tab(t1).ButtonDisable()
MyData = Memory(SPIFLASH).ReadVerify(CfgBase,CfgSize)
if (MyData = Nothing)
Status("Error: data read back failed")
Tab(t1).ButtonEnable()
Exit Event
endif
Prompt = "Choose filename to save the firmware"
SaveFile(MyData,Prompt,"Cfg.bin")
Status("Successfully read Cfg from Flash")
Tab(t1).ButtonEnable()
EndEvent


CreateEvent(WriteCfg)
Tab(t1).ButtonDisable()
Prompt = "Choose a Cfg to write into Flash"
MyData = OpenFile(Prompt,"Cfg files (*.bin)|*.bin")
if (MyData = Nothing)
goto WriteCfgExit
endif
if not (Len(MyData) = CfgSize)
Status("Error: File is not the size of the Cfg")
goto WriteCfgExit
endif
Memory(SPIFLASH).Write(MyData,CfgBase,CfgSize)
Status("New Cfg successfully written")
WriteCfgExit:
Tab(t1).ButtonEnable()
EndEvent
 

Attachments

  • DPC3000_SPI.bcs
    9.6 KB · Views: 133
Status
Not open for further replies.
Top