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

VMG300 Script SPI

Status
Not open for further replies.

D3m0n

Administrator
Staff member
MyDevice = "VMG300" #Name of SPI device
ImgFile = "images\Motorola.gif" #Location of the logo

FwBase = 0x40000
Fw1Base = 0x3F0000
Fw1Size = 3866624
U-BootBase = 0x0
U-BootSize = 131072
NvBase = 0x7B0000
NvSize = 327680

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

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

ObjTxt = Memory(SPIFLASH).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(SPIFLASH).Read(0x4000E,2,true)
FwFileOffsetInt = HWord(FwFileOffset,0)
ReadOffset = FwFileOffsetInt + FwBase + 76
FwFileOffset = Memory(SPIFLASH).Read(ReadOffset,4,true)
FwSize = Word(FwFileOffset,0) + FwFileOffsetInt + 128

t1 = Tab.Create(MyDevice)


Tab(t1).AddGroup("U-Boot",10,10,100,150)
Tab(t1).AddGroup("Firmware",110,10,100,150)
Tab(t1).AddGroup("Firmware1",210,10,100,150)
Tab(t1).AddGroup("Nvram",310,10,100,150)
Tab(t1).AddButton("ReadU-Boot","Read",20,42)
Tab(t1).AddButton("WriteU-Boot","Write",20,102)
Tab(t1).AddButton("ReadFirmware","Read",120,42)
Tab(t1).AddButton("WriteFirmware","Write",120,102)
Tab(t1).AddButton("ReadFirmware1","Read",220,42)
Tab(t1).AddButton("WriteFirmware1","Write",220,102)
Tab(t1).AddButton("ReadNvram","Read",320,42)
Tab(t1).AddButton("WriteNvram","Write",320,102)


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(ReadFirmware)
Status("Saving the VMG300'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,"VMG300.bin")
Status("Successfully read firmware from Flash")
Tab(t1).ButtonEnable()
EndEvent

CreateEvent(WriteFirmware)
Status("Programming the VMG300'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(SPIFLASH).Write(MyData,FwBase,FwLen)
FwSize = FwLen
Status("New firmware successfully installed")
Tab(t1).ButtonEnable()
Exit
ExitWriteFwErr:
Status(WriteErr)
Tab(t1).ButtonEnable()
EndEvent

CreateEvent(ReadFirmware1)
Status("Saving the VMG300'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,"VMG300_1.bin")
Status("Successfully read firmware1 from Flash")
Tab(t1).ButtonEnable()
EndEvent

CreateEvent(WriteFirmware1)
Status("Programming the VMG300'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(SPIFLASH).Write(MyData,Fw1Base,FwLen)
Fw1Size = FwLen
Status("New firmware successfully installed")
Tab(t1).ButtonEnable()
Exit
ExitWriteFwErr:
Status(WriteErr)
Tab(t1).ButtonEnable()
EndEvent

CreateEvent(ReadNVRAM)
Status("Reading the NVRAM")
Tab(t1).ButtonDisable()
MyData = Memory(SPIFLASH).ReadVerify(NvBase,NvSize)
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,"NVRAM.bin")
Status("Successfully read NVRAM from Flash")
Tab(t1).ButtonEnable()
EndEvent

CreateEvent(WriteNVRAM)
Status("Programming the NVRAM")
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
NvLen = Len(MyData)
Memory(SPIFLASH).Write(MyData,NvBase,NvLen)
NvSize = NvLen
Status("New NVRAM successfully installed")
Tab(t1).ButtonEnable()
Exit
ExitWriteFwErr:
Status(WriteErr)
Tab(t1).ButtonEnable()

EndEvent
 

Attachments

  • VMG300_SPI.bcs
    6.2 KB · Views: 72
Status
Not open for further replies.
Back
Top