Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MyDevice = "Motorola SB6120" #Name of device
- ImgFile = "images\Motorola.gif"
- # FwBase = 0x40000 ## OFFSET TO UBFI1
- FwBase = 0x3f0000 ## OFFSET TO UBFI2(SB6121 DEFAULTS TO THIS ONE)
- if not (Memory.Exist)
- Writeline("Error in script: Flash not connected")
- exit script
- endif
- # ObjTxt = Memory.ReadString(0x40020) ## OFFSET + 0x20
- ObjTxt = Memory.ReadString(0x3F0020)
- if (ObjTxt = Nothing)
- Writeline("Flash data does not contain proper firmware format...nothing")
- exit script
- endif
- if not (ObjTxt = "Boot Script File")
- Writeline("Flash data does not contain proper firmware format, boot script file tag not found")
- exit script
- endif
- # FwFileOffset = Memory.Read(0x4000E,2,true) # OFFSET + 0xE
- FwFileOffset = Memory.Read(0x3F000E,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",10,10,420,75)
- Tab(t1).AddButton("ReadFirmware","Read",120,42)
- Tab(t1).AddButton("WriteFirmware","Write",270,42)
- Tab(t1).AddImage("LOGO",ImgFile,45,240)
- CreateEvent(ReadFirmware)
- Status("Saving the SB6120'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,"SB6120.bin")
- Status("Successfully read firmware from Flash")
- Tab(t1).ButtonEnable()
- EndEvent
- CreateEvent(WriteFirmware)
- Status("Programming the SB6120'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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement