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

SBV6220 Script SPI

Status
Not open for further replies.

D3m0n

Administrator
Staff member
MyDevice = "Motorola SBV6220" #Name of device
ImgFile = "images\Motorola.gif"
FwBase = 0x40000

if not (Memory.Exist)
Writeline("Error in script: Flash not connected")
exit script
endif

ObjTxt = Memory.ReadString(0x40020)
if (ObjTxt = Nothing)
Writeline("Flash data does not contain proper firmware format")
exit script
endif
if not (ObjTxt = "Boot Script File")
Writeline("Flash data does not contain proper firmware format")
exit script
endif

FwFileOffset = Memory.Read(0x4000E,2,true)
FwFileOffsetInt = HWord(FwFileOffset,0)
ReadOffset = FwFileOffsetInt + FwBase + 76
FwFileOffset = Memory.Read(ReadOffset,4,true)
FwSize = Word(FwFileOffset,0) + FwFileOffsetInt + 128

t1 = Tab.Create(MyDevice)

Tab(t1).AddGroup("Firmware",90,10,290,65)
Tab(t1).AddButton("ReadFirmware","Read UBFI1",120,32)
Tab(t1).AddButton("WriteFirmware","Write UBFI1",270,32)

Tab(t1).AddGroup("Read Areas (Beta)",90,80,140,150)
Tab(t1).AddButton("ReadUBoot","U-Boot",120,107)
Tab(t1).AddButton("ReadNVRAM","NVRAM",120,147)
Tab(t1).AddButton("ReadALL","FULL",120,187)

Tab(t1).AddGroup("Write Areas (Beta)",240,80,140,150)
Tab(t1).AddButton("WriteUBoot","U-Boot",270,107)
#Tab(t1).AddButton("WriteNVRAM","NVRAM",270,147)
#Tab(t1).AddButton("WriteALL","FULL",270,187)
Tab(t1).AddImage("LOGO",ImgFile,45,240)

CreateEvent(ReadFirmware)
Status("Saving the SBV6220's Firmware")
Tab(t1).ButtonDisable()
MyData = Memory.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,"SBV6220_UBFI1.bin")
Status("Successfully read firmware from Flash")
Tab(t1).ButtonEnable()
EndEvent

CreateEvent(WriteFirmware)
Status("Programming the SBV6220'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
If not (HWORD(MyData,0) = 0x2705)
Status("Error: File does not appear to be compatible firmware")
exit event
endif
FwLen = Len(MyData)
Memory.Write(MyData,FwBase,FwLen)
FwSize = FwLen
Status("New firmware successfully installed")
Tab(t1).ButtonEnable()
Exit
ExitWriteFwErr:
Status(WriteErr)
Tab(t1).ButtonEnable()
EndEvent

CreateEvent(ReadUBoot)
Status("Saving the SBV6220's U-Boot")
Tab(t1).ButtonDisable()
MyData = Memory.ReadVerify(0x00000,0x20000)
if (MyData = Nothing)
Status("Error: data read back failed")
Tab(t1).ButtonEnable()
Exit Event
endif
Prompt = "Choose filename to save the U-Boot firmware"
SaveFile(MyData,Prompt,"SBV6220_U-Boot.bin")
Status("Successfully read U-Boot firmware from Flash")
Tab(t1).ButtonEnable()
EndEvent

CreateEvent(ReadNVRAM)
Status("Saving the SBV6220's NVRAM")
Tab(t1).ButtonDisable()
MyData = Memory.ReadVerify(0xFB0000,0x50000)
if (MyData = Nothing)
Status("Error: data read back failed")
Tab(t1).ButtonEnable()
Exit Event
endif
Prompt = "Choose filename to save the NVRAM"
SaveFile(MyData,Prompt,"SBV6220_NVRAM.bin")
Status("Successfully read NVRAM from Flash")
Tab(t1).ButtonEnable()
EndEvent

CreateEvent(ReadALL)
Status("Saving the SBV6220's Full Image")
Tab(t1).ButtonDisable()
MyData = Memory.ReadVerify(0x000000,0xFA0000)
if (MyData = Nothing)
Status("Error: data read back failed")
Tab(t1).ButtonEnable()
Exit Event
endif
Prompt = "Choose filename to save the NVRAM"
SaveFile(MyData,Prompt,"SBV6220_FULL.bin")
Status("Successfully read the Full Firmware from Flash")
Tab(t1).ButtonEnable()
EndEvent

CreateEvent(WriteUBoot)
Status("Programming the SBV6220's Bootloader")
Tab(t1).ButtonDisable()
Prompt = "Choose a U-Boot firmware to install"
MyData = OpenFile(Prompt,"Firmware files (*.bin)|*.bin")
if (MyData = Nothing)
WriteErr = "User cancelled opperation"
goto ExitWriteFwErr
endif
FwLen = Len(MyData)
Memory.Write(MyData,0,FwLen)
FwSize = FwLen
Status("New U-Boot successfully installed")
Tab(t1).ButtonEnable()
Exit
ExitWriteFwErr:
Status(WriteErr)
Tab(t1).ButtonEnable()
EndEvent

CreateEvent(WriteNVRAM)
Status("Programming the SBV6220's NVRAM")
Tab(t1).ButtonDisable()
Prompt = "Choose a NVRAM backup to restore"
MyData = OpenFile(Prompt,"Firmware files (*.bin)|*.bin")
if (MyData = Nothing)
WriteErr = "User cancelled opperation"
goto ExitWriteFwErr
endif
FwLen = Len(MyData)
Memory.Write(MyData,FB,FwLen)
FwSize = FwLen
Status("New NVRAM data loaded")
Tab(t1).ButtonEnable()
Exit
ExitWriteFwErr:
Status(WriteErr)
Tab(t1).ButtonEnable()
EndEvent

CreateEvent(WriteFULL)
Status("Programming the SBV6220's Full Image")
Tab(t1).ButtonDisable()
Prompt = "Choose a U-Boot firmware to install"
MyData = OpenFile(Prompt,"Firmware files (*.bin)|*.bin")
if (MyData = Nothing)
WriteErr = "User cancelled opperation"
goto ExitWriteFwErr
endif
FwLen = Len(MyData)
Memory.Write(MyData,0,FwLen)
FwSize = FwLen
Status("Full Restore Complete")
Tab(t1).ButtonEnable()
Exit
ExitWriteFwErr:
Status(WriteErr)
Tab(t1).ButtonEnable()
EndEvent
 

Attachments

  • SBV6220_SPI.bcs
    5.7 KB · Views: 157
Status
Not open for further replies.
Back
Top