MyDevice = "SBG6580" #Name of device
BootBase = 0x0
BootSize = 0x10000
CfgBase = 0x10000
CfgSize = 0x10000
Img0Base = 0x20000
Img0Size = 0x7E0000
Img1Base = 0x800000
Img1Size = 0x7E0000
LogBase = 0xFE0000
LogSize = 0x20000
t1 = Tab.Create(MyDevice)
Tab(t1).AddProgress(10,142,440)
Tab(t1).AddGroup("Read",10,10,440,120)
Tab(t1).AddGroup("Write",10,160,440,120)
Tab(t1).AddButton("ReadBoot","Boot",20,42)
Tab(t1).AddButton("WriteBoot","Boot",20,192)
Tab(t1).AddButton("ReadCFG","cfg",105,42)
Tab(t1).AddButton("WriteCFG","cfg",105,192)
Tab(t1).AddButton("ReadImage0","Image0",190,42)
Tab(t1).AddButton("WriteImage0","Image0",190,192)
Tab(t1).AddButton("ReadImage1","Image1",275,42)
Tab(t1).AddButton("WriteImage1","Image1",275,192)
Tab(t1).AddButton("ReadLog","Log",360,42)
Tab(t1).AddButton("WriteLog","Log",360,192)
CreateEvent(ReadBoot)
Status("Reading Boot")
Tab(t1).ButtonDisable()
MyData = Memory(0).ReadVerify(BootBase,BootSize)
if (MyData == Nothing)
Status("Error: data read back failed")
Tab(t1).ButtonEnable()
Exit Event
endif
Prompt = "Choose filename for Boot"
IO.Save(MyData,Prompt,"Boot.bin")
Status("Successfully read Boot from Flash!")
Tab(t1).ButtonEnable()
EndEvent
CreateEvent(WriteBoot)
Tab(t1).ButtonDisable()
Prompt = "Choose a Boot to write to Flash"
MyData = IO.Open(Prompt,"Boot files (*.bin)|*.bin")
if (MyData == Nothing)
goto Write BootExit
endif
# if not (Data.Length(MyData)== BootSize)
# Status("Error: File is not the size of the Boot")
# goto Write BootExit
# endif
Memory(0).Write(MyData,BootBase,BootSize)
Status("New Boot successfully written!")
WriteBootExit:
Tab(t1).ButtonEnable()
EndEvent
CreateEvent(ReadImage0)
Status("Saving the SBG6580's Image0")
Tab(t1).ButtonDisable()
MyData = Memory(0).ReadVerify(Img0Base,Img0Size)
if (MyData == Nothing)
Status("Error: data read back failed")
Tab(t1).ButtonEnable()
Exit Event
endif
Prompt = "Choose filename for Image0"
IO.Save(MyData,Prompt,"Image0.bin")
Status("Successfully read Image0 from Flash")
Tab(t1).ButtonEnable()
EndEvent
CreateEvent(WriteImage0)
Status("Programming the SBG6580's Image0")
Tab(t1).ButtonDisable()
Prompt = "Choose a firmware to install"
MyData = IO.Open(Prompt,"Firmware files (*.bin,*.p7)|*.bin;*.p7")
if (MyData == Nothing)
WriteErr = "User cancelled operation"
goto ExitWriteFwErr
endif
If (Data.HWORD(MyData,0)==12418) #Remove header if .p7 fw
Writeline("Removing .p7 firmware header")
HeadLen = Data.HWORD(MyData,2) + 52 #increases Headlen by 7
NewLen = Data.Length(MyData) - HeadLen
Data.Resize(MyData,HeadLen,NewLen) #Removes the p7 header
endif
FwLen = Data.Length(MyData)
Memory(0).Write(MyData,Img0Base,FwLen)
Img0Size = FwLen
Status("New firmware successfully installed")
Tab(t1).ButtonEnable()
Exit
ExitWriteFwErr:
Status(WriteErr)
Tab(t1).ButtonEnable()
EndEvent
CreateEvent(ReadImage1)
Status("Saving the SBG6580's Image1")
Tab(t1).ButtonDisable()
MyData = Memory(0).ReadVerify(Img1Base,Img1Size)
if (MyData == Nothing)
Status("Error: data read back failed")
Tab(t1).ButtonEnable()
Exit Event
endif
Prompt = "Choose filename for Image1"
IO.Save(MyData,Prompt,"Image1.bin")
Status("Successfully read Image1 from Flash")
Tab(t1).ButtonEnable()
EndEvent
CreateEvent(WriteImage1)
Status("Programming the SBG6580's Image1")
Tab(t1).ButtonDisable()
Prompt = "Choose a firmware to install"
MyData = IO.Open(Prompt,"Firmware files (*.bin,*.p7)|*.bin;*.p7")
if (MyData == Nothing)
WriteErr = "User cancelled operation"
goto ExitWriteFwErr
endif
If (Data.HWORD(MyData,0)==12418) #Remove header if .p7 fw
Writeline("Removing .p7 firmware header")
HeadLen = Data.HWORD(MyData,2) + 52 #increases Headlen by 7
NewLen = Data.Length(MyData) - HeadLen
Data.Resize(MyData,HeadLen,NewLen) #Removes the p7 header
endif
FwLen = Data.Length(MyData)
Memory(0).Write(MyData,Img1Base,FwLen)
Img1Size = FwLen
Status("New firmware successfully installed")
Tab(t1).ButtonEnable()
Exit
ExitWriteFwErr:
Status(WriteErr)
Tab(t1).ButtonEnable()
EndEvent
CreateEvent(ReadLog)
Status("Reading the Log")
Tab(t1).ButtonDisable()
MyData = Memory(0).ReadVerify(LogBase,LogSize)
if (MyData == Nothing)
Status("Error: data read back failed")
Tab(t1).ButtonEnable()
Exit Event
endif
Prompt = "Choose filename to save Log"
IO.Save(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 to Flash"
MyData = IO.Open(Prompt,"Log files (*.bin)|*.bin")
if (MyData == Nothing)
goto WriteLogExit
endif
if not (Data.Length(MyData)== LogSize)
Status("Error: File is not the size of the Log")
goto WriteLogExit
endif
Memory(0).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(0).ReadVerify(CfgBase,CfgSize)
if (MyData == Nothing)
Status("Error: data read back failed")
Tab(t1).ButtonEnable()
Exit Event
endif
Prompt = "Choose filename to save cfg"
IO.Save(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 to Flash"
MyData = IO.Open(Prompt,"cfg files (*.bin)|*.bin")
if (MyData == Nothing)
goto WriteCFGExit
endif
if not (Data.Length(MyData)== CfgSize)
Status("Error: File is not the size of the cfg")
goto WriteCFGExit
endif
Memory(0).Write(MyData,CfgBase,CfgSize)
Status("New cfg successfully written")
WriteCFGExit:
Tab(t1).ButtonEnable()
EndEvent