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

SB4200 Script BCM3345 JTAG

Status
Not open for further replies.

D3m0n

Administrator
Staff member
# Script file for BCM3345 (SB4200) - 334517F
# This script is automatically executed when BlackcatUSB
# reads the CPU ID that the SB4200 uses. Which is 0x334517F.

Require(240) #Need to use RC12+ software
Writeline("*** Tip: for programming the entire flash, stop the CPU")
Writeline("*** first by running the command Ejctrl(0x10000)")
MyDevice = "Motorola SB4200" #Name of device
BootSize = 262143 #Size of bootloader (in bytes)
BS1 = 0x40000 #Firmware location (to boot)
BS2 = 0x120000 #Firmware backup (to upgrade or restore)
BOOTSTR = 0x11000 #VxWorks Bootstring
FWINFO = 0x10FC00 #Header info (161 bytes)
ImgFile = "images\Motorola.gif" #Location of the logo

SetParam(1,150) #Sets the Intel flash delay
SetParam(2,150) #Sets the AMD flash delay
SetParam(3,100) #Sets the DMA read delay

JTAG.BigEndian #Sets the device endian

JTAG.MemoryAddress(0x0)
JTAG.MemoryType("RAM")
JTAG.MemorySize(0x800000)
CFGMEM = JTAG.MemoryInit()
JTAG.MemoryAddress(0x1FC00000)
JTAG.MemoryType("CFI")
CFGFLASH = JTAG.MemoryInit()

JTAG.Poke(0xfffe0224,0x0)
JTAG.Poke(0xfffe2300,0x1a)
JTAG.Poke(0xfffe2304,0x0)
JTAG.Poke(0xfffe2308,0x8040)
JTAG.Poke(0xfffe230C,0x3)
JTAG.Poke(0xfffe2310,0x4824)

If not (Memory(CFGFLASH).Exist())
Writeline("No flash detected, exiting script")
Exit
endif

SizeStrLoc = FWINFO + 24 #0x10FC18
FwSizeStr = Memory(CFGFLASH).ReadString(SizeStrLoc)
StrLen = Len(FwSizeStr)
FwSize = ToInteger(FwSizeStr)
FnLocation = FWINFO + 47
MyFirmName = "(No firmware installed)"

t1 = Tab.Create(MyDevice) #Adds the flash device specific tab

Tab(t1).AddGroup("Firmware",10,10,424,100)
Tab(t1).AddText("TITLE1","Version currently installed:",18,26)
Tab(t1).AddText("TITLE2",MyFirmName,154,26)
Tab(t1).AddText("TITLE3","Size (in bytes):",18,44)
Tab(t1).AddText("TITLE4",FwSize,96,44)
Tab(t1).AddButton("ReadFw","Read",140,74)
Tab(t1).AddButton("WriteFw","Write",230,74)
Tab(t1).AddImage("LOGO",ImgFile,45,200)

Memory(1).WRITEWORD(0xFFFE0224,0) #Disables watchdog

SetDisplay()

CreateEvent(SetDisplay)
MyFirmName = Memory(CFGFLASH).ReadString(FnLocation)
FwSizeStr = Memory(CFGFLASH).ReadString(SizeStrLoc)
Tab.SetText("TITLE2",MyFirmName)
Tab.SetText("TITLE4",FwSizeStr)
EndEvent

CreateEvent(ReadFw) #This reads the firmware (and correctly!)
Tab(t1).ButtonDisable()
Status("Reading the SB4200 firmware")
FwBase = Memory(CFGFLASH).ReadVerify(BS1,FwSize)
If (FwBase = Nothing)
Status("Error reading firmware!")
Tab(t1).ButtonEnable()
Exit Event
EndIf
Header = Memory(CFGFLASH).Read(FWINFO,161,False)
FwFile = Copy(Header,FwBase)
MyFwName = MyFirmName & ".hex.bin" #Creates a copy of the fw name
FwFile(0x58) = 0 #Erase current location
FwFile(0x59) = 0
Prompt = "Choose filename to save the firmware"
SaveFile(FwFile,Prompt,MyFwName)
Status("Successfully read firmware from Flash")
Tab(t1).ButtonEnable()
EndEvent

CreateEvent(WriteFw)
Tab(t1).ButtonDisable()
Status("Programming the SB4200's Firmware")
Prompt = "Choose a firmware to install"
MyData = OpenFile(Prompt,"Firmware files (*.bin,*.p7)|*.bin;*.p7")
FwLen = Len(MyData)

If (FwLen = 0)
WriteErr = "User canceled"
goto ExitWriteFwErr
endif
If (FwLen > 875000)
WriteErr = "Error: File is too large to be firmware"
goto ExitWriteFwErr
endif

FWSTART = HWORD(MyData,0)

If (FWSTART = 12418) #Remove header if .p7 fw
Writeline("Removing .p7 firmware header")
HeadLen = HWORD(MyData,2)
HeadLen = HeadLen + 10 #increases Headlen by 10
NewLen = Len(MyData)
NewLen -= HeadLen
Resize(MyData,HeadLen,NewLen) #Removes the p7 header
endif

FwLen = Len(MyData)
Header = bytes(MyData,0,161) #Grabs the header
Resize(MyData,161) #Removes header
Header(0x58) = 191
Header(0x59) = 196
FwLen = Len(MyData)
Writeline("Writing base firmware image(s)")
Memory(CFGFLASH).Write(MyData,BS1,FwLen) #Write firmware slot 1 data
#Memory(CFGFLASH).Write(MyData,BS2,FwLen) #Write firmware slot 2 data
SetDisplay() #Updates the GUI's firmware info
Status("New firmware successfully installed")
Tab(t1).ButtonEnable()
Exit
ExitWriteFwErr:
Status(WriteErr)
Tab(t1).ButtonEnable()
EndEvent
 

Attachments

  • SB4200_JTAG.bcs
    4.3 KB · Views: 28
Status
Not open for further replies.
Back
Top