Advertisement
Guest User

SB 6141 FCS

a guest
Dec 22nd, 2018
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 10.46 KB | None | 0 0
  1. MyDevice = "SB6141" #Name of device
  2.  
  3. FlBase = 0x0
  4. FLSize = 0x7FFFFF
  5. FwBase = 0x40000
  6. FwSize = 3866624
  7. Fw1Base = 0x3F0000
  8. Fw1Size = 3866624
  9. BootBase = 0x0
  10. BootSize = 131072
  11. Env1Base = 0x20000
  12. Env1Size = 131072
  13. BlankBase = 0x7A0000
  14. BlankSize = 196608
  15. LogBase = 0x7D0000
  16. LogSize = 131072
  17. CfgBase = 0x7F0000
  18. CfgSize = 65536
  19.  
  20. #JTAG.MemoryType("SPI")
  21. SPIFLASH = JTAG.MemoryInit("SPI", 1)
  22. t1 = Tab.Create(MyDevice)
  23.  
  24. Tab(t1).AddGroup("U-Boot",10,10,100,150)
  25. Tab(t1).AddGroup("BootParam",110,10,100,150)
  26. Tab(t1).AddGroup("UBFI1",210,10,100,150)
  27. Tab(t1).AddGroup("UBFI2",310,10,100,150)
  28. Tab(t1).AddGroup("Blank",10,160,100,150)
  29. Tab(t1).AddGroup("Log",110,160,100,150)
  30. Tab(t1).AddGroup("Cfg",210,160,100,150)
  31. Tab(t1).AddGroup("FullFlash",310,160,100,150)
  32. Tab(t1).AddButton("ReadU-Boot","Read",20,42)
  33. Tab(t1).AddButton("WriteU-Boot","Write",20,102)
  34. Tab(t1).AddButton("ReadBootParam","Read",120,42)
  35. Tab(t1).AddButton("WriteBootParam","Write",120,102)
  36. Tab(t1).AddButton("ReadUBFI1","Read",220,42)
  37. Tab(t1).AddButton("WriteUBFI1","Write",220,102)
  38. Tab(t1).AddButton("ReadUBFI2","Read",320,42)
  39. Tab(t1).AddButton("WriteUBFI2","Write",320,102)
  40. Tab(t1).AddButton("ReadBlank","Read",20,192)
  41. Tab(t1).AddButton("WriteBlank","Write",20,252)
  42. Tab(t1).AddButton("ReadLog","Read",120,192)
  43. Tab(t1).AddButton("WriteLog","Write",120,252)
  44. Tab(t1).AddButton("ReadCfg","Read",220,192)
  45. Tab(t1).AddButton("WriteCfg","Write",220,252)
  46. Tab(t1).AddButton("ReadFullFlash","Read",320,192)
  47. Tab(t1).AddButton("WriteFullFlash","Write",320,252)
  48.  
  49. CreateEvent(ReadU-Boot)
  50.     Status("Reading U-Boot")
  51.         Tab(t1).ButtonDisable()
  52.     MyData = Memory(SPIFLASH).ReadVerify(BootBase,BootSize)
  53.         if (MyData == Nothing)
  54.         Status("Error: data read back failed")
  55.             Tab(t1).ButtonEnable()
  56.         Exit Event
  57.     endif
  58.     Prompt = "Choose filename for U-Boot"
  59.     IO.Save(MyData,Prompt,"U-Boot.bin")
  60.     #SaveFile(MyData,Prompt,"U-Boot.bin")
  61.     Status("Successfully read U-Boot from Flash!")
  62.         Tab(t1).ButtonEnable()
  63. EndEvent
  64.  
  65.  
  66. CreateEvent(WriteU-Boot)
  67.         Tab(t1).ButtonDisable()
  68.     Prompt = "Choose U-Boot to write to Flash" 
  69.     #MyData = OpenFile(Prompt,"U-Boot files (*.bin)|*.bin")
  70.     MyData = IO.Open(Prompt, "U-Boot files (*.bin)|*.bin")
  71.     if (MyData == Nothing)
  72.         goto    WriteU-BootExit
  73.     endif
  74. #   if not (Len(MyData) = U-BootSize)
  75. #       Status("Error: File is not the size of the U-Boot")
  76. #       goto    WriteU-BootExit
  77. #   endif
  78.     Memory(SPIFLASH).Write(MyData,BootBase,BootSize)
  79.     Status("New U-Boot successfully written!")
  80.  WriteU-BootExit:
  81.         Tab(t1).ButtonEnable()
  82. EndEvent
  83.  
  84. CreateEvent(ReadBootParam)
  85.     Status("Reading BootParams")
  86.         Tab(t1).ButtonDisable()
  87.     MyData = Memory(SPIFLASH).ReadVerify(Env1Base,Env1Size)
  88.         if (MyData == Nothing)
  89.         Status("Error: data read back failed")
  90.             Tab(t1).ButtonEnable()
  91.         Exit Event
  92.     endif
  93.     Prompt = "Choose filename to save the firmware"
  94.     #SaveFile(MyData,Prompt,"BootParam.bin")
  95.     IO.Save(MyData,Prompt,"BootParam.bin")
  96.     Status("Successfully read BootParam from Flash")
  97.         Tab(t1).ButtonEnable()
  98. EndEvent
  99.  
  100.  
  101. CreateEvent(WriteBootParam)
  102.         Tab(t1).ButtonDisable()
  103.     Prompt = "Choose BootParams to write to Flash" 
  104.     #MyData = OpenFile(Prompt,"BootParam files (*.bin)|*.bin")
  105.     MyData = IO.Open(Prompt, "BootParam files (*.bin)|*.bin")
  106.     if (MyData == Nothing)
  107.         goto    WriteEnv1Exit
  108.     endif
  109.     if not (Data.Length(MyData) == Env1Size)
  110.         Status("Error: File is not the size of the BootParam")
  111.         goto    WriteEnv1Exit
  112.     endif
  113.     Memory(SPIFLASH).Write(MyData,Env1Base,Env1Size)
  114.     Status("New BootParam successfully written")
  115.  WriteEnv1Exit:
  116.         Tab(t1).ButtonEnable()
  117. EndEvent
  118.  
  119. CreateEvent(ReadUBFI1)
  120.     Status("Saving the SB6141's UBFI1")
  121.         Tab(t1).ButtonDisable()
  122.     MyData = Memory(SPIFLASH).ReadVerify(FwBase,FwSize)
  123.         if (MyData == Nothing)
  124.         Status("Error: data read back failed")
  125.             Tab(t1).ButtonEnable()
  126.         Exit Event
  127.     endif
  128.     Prompt = "Choose filename for UBFI1"
  129.     #SaveFile(MyData,Prompt,"UBFI1.bin")
  130.     IO.Save(MyData,Prompt,"UBFI1.bin")
  131.     Status("Successfully read UBFI1 from Flash")
  132.         Tab(t1).ButtonEnable()
  133. EndEvent
  134.  
  135. CreateEvent(WriteUBFI1)
  136.     Status("Programming the SB6141's UBFI1")
  137.         Tab(t1).ButtonDisable()
  138.     Prompt = "Choose a firmware to install"
  139.     #MyData = OpenFile(Prompt,"Firmware files (*.bin,*.p7)|*.bin;*.p7")
  140.     MyData = IO.Open(Prompt,"Firmware files (*.bin,*.p7)|*.bin;*.p7")
  141.     if (MyData == Nothing)
  142.         WriteErr = "User cancelled operation"
  143.         goto    ExitWriteFwErr
  144.     endif
  145.     If (Data.Hword(MyData,0) == 12418)      #Remove header if .p7 fw
  146.         Writeline("Removing .p7 firmware header")
  147.         HeadLen = Data.Hword(MyData,2) + 52 #increases Headlen by 7
  148.         NewLen = Data.Length(MyData) - HeadLen
  149.         Data.Resize(MyData,HeadLen,NewLen)  #Removes the p7 header
  150.     endif
  151.     FwLen = Data.Length(MyData)
  152.     Memory(SPIFLASH).Write(MyData,FwBase,FwLen)
  153.     FwSize = FwLen
  154.     Status("New firmware successfully installed")
  155.         Tab(t1).ButtonEnable()
  156.         Exit
  157.   ExitWriteFwErr:
  158.     Status(WriteErr)
  159.         Tab(t1).ButtonEnable()
  160. EndEvent
  161.  
  162. CreateEvent(ReadUBFI2)
  163.     Status("Saving the SB6141's UBFI2")
  164.         Tab(t1).ButtonDisable()
  165.     MyData = Memory(SPIFLASH).ReadVerify(Fw1Base,Fw1Size)
  166.         if (MyData == Nothing)
  167.         Status("Error: data read back failed")
  168.             Tab(t1).ButtonEnable()
  169.         Exit Event
  170.     endif
  171.     Prompt = "Choose filename for UBFI2"
  172.     #SaveFile(MyData,Prompt,"UBFI2.bin")
  173.     IO.Save(MyData,Prompt,"UBFI2.bin")
  174.     Status("Successfully read UBFI2 from Flash")
  175.         Tab(t1).ButtonEnable()
  176. EndEvent
  177.  
  178. CreateEvent(WriteUBFI2)
  179.     Status("Programming the SB6141's UBFI2")
  180.         Tab(t1).ButtonDisable()
  181.     Prompt = "Choose a firmware to install"
  182.     #MyData = OpenFile(Prompt,"Firmware files (*.bin,*.p7)|*.bin;*.p7")
  183.     MyData = IO.Open(Prompt,"Firmware files (*.bin,*.p7)|*.bin;*.p7")
  184.     if (MyData == Nothing)
  185.         WriteErr = "User cancelled operation"
  186.         goto    ExitWriteFwErr
  187.     endif
  188.     If (Data.Hword(MyData,0) == 12418)      #Remove header if .p7 fw
  189.         Writeline("Removing .p7 firmware header")
  190.         HeadLen = Data.Hword(MyData,2) + 52 #increases Headlen by 7
  191.         NewLen = Data.Length(MyData) - HeadLen
  192.         Data.Resize(MyData,HeadLen,NewLen)  #Removes the p7 header
  193.     endif
  194.     FwLen = Data.Length(MyData)
  195.     Memory(SPIFLASH).Write(MyData,Fw1Base,FwLen)
  196.     Fw1Size = FwLen
  197.     Status("New firmware successfully installed")
  198.         Tab(t1).ButtonEnable()
  199.         Exit
  200.   ExitWriteFwErr:
  201.     Status(WriteErr)
  202.         Tab(t1).ButtonEnable()
  203. EndEvent
  204.  
  205. CreateEvent(ReadBlank)
  206.     Status("Saving 'Blank' area")
  207.         Tab(t1).ButtonDisable()
  208.     MyData = Memory(SPIFLASH).ReadVerify(BlankBase,BlankSize)
  209.         if (MyData == Nothing)
  210.         Status("Error: data read back failed")
  211.             Tab(t1).ButtonEnable()
  212.         Exit Event
  213.     endif
  214.     Prompt = "Choose filename to save Blank"
  215.     #SaveFile(MyData,Prompt,"Blank.bin")
  216.     IO.Save(MyData,Prompt,"Blank.bin")
  217.     Status("Successfully read Blank from Flash")
  218.         Tab(t1).ButtonEnable()
  219. EndEvent
  220.  
  221.  
  222. CreateEvent(WriteBlank)
  223.         Tab(t1).ButtonDisable()
  224.     Prompt = "Choose a Blank to write to Flash"
  225.     #MyData = OpenFile(Prompt,"Blank files (*.bin)|*.bin")
  226.     MyData = IO.Open(Prompt,"Blank files (*.bin)|*.bin")
  227.     if (MyData == Nothing)
  228.         goto    WriteBlankExit
  229.     endif
  230.     if not (Data.Length(MyData) == BlankSize)
  231.         Status("Error: File is not the size of the Blank")
  232.         goto    WriteBlankExit
  233.     endif
  234.     Memory(SPIFLASH).Write(MyData,BlankBase,BlankSize)
  235.     Status("New Blank successfully written")
  236.  WriteBlankExit:
  237.         Tab(t1).ButtonEnable()
  238. EndEvent
  239.  
  240. CreateEvent(ReadLog)
  241.     Status("Reading the Log")
  242.         Tab(t1).ButtonDisable()
  243.     MyData = Memory(SPIFLASH).ReadVerify(LogBase,LogSize)
  244.         if (MyData == Nothing)
  245.         Status("Error: data read back failed")
  246.             Tab(t1).ButtonEnable()
  247.         Exit Event
  248.     endif
  249.     Prompt = "Choose filename to save Log"
  250.     #SaveFile(MyData,Prompt,"Log.bin")
  251.     IO.Save(MyData,Prompt,"Log.bin")
  252.     Status("Successfully read Log from Flash")
  253.         Tab(t1).ButtonEnable()
  254. EndEvent
  255.  
  256.  
  257. CreateEvent(WriteLog)
  258.         Tab(t1).ButtonDisable()
  259.     Prompt = "Choose a Log to write to Flash"  
  260.     #MyData = OpenFile(Prompt,"Log files (*.bin)|*.bin")
  261.     MyData = IO.Open(Prompt,"Log files (*.bin)|*.bin")
  262.     if (MyData == Nothing)
  263.         goto    WriteLogExit
  264.     endif
  265.     if not (Data.Length(MyData) == LogSize)
  266.         Status("Error: File is not the size of the Log")
  267.         goto    WriteLogExit
  268.     endif
  269.     Memory(SPIFLASH).Write(MyData,LogBase,LogSize)
  270.     Status("New Log successfully written")
  271.  WriteLogExit:
  272.         Tab(t1).ButtonEnable()
  273. EndEvent
  274.  
  275. CreateEvent(ReadCfg)
  276.     Status("Reading the Cfg")
  277.         Tab(t1).ButtonDisable()
  278.     MyData = Memory(SPIFLASH).ReadVerify(CfgBase,CfgSize)
  279.         if (MyData == Nothing)
  280.         Status("Error: data read back failed")
  281.             Tab(t1).ButtonEnable()
  282.         Exit Event
  283.     endif
  284.     Prompt = "Choose filename to save Cfg"
  285.     #SaveFile(MyData,Prompt,"Cfg.bin")
  286.     IO.Save(MyData,Prompt,"Cfg.bin")
  287.     Status("Successfully read Cfg from Flash")
  288.         Tab(t1).ButtonEnable()
  289. EndEvent
  290.  
  291.  
  292. CreateEvent(WriteCfg)
  293.         Tab(t1).ButtonDisable()
  294.     Prompt = "Choose a Cfg to write to Flash"  
  295.     #MyData = OpenFile(Prompt,"Cfg files (*.bin)|*.bin")
  296.     MyData = IO.Open(Prompt,"Cfg files (*.bin)|*.bin")
  297.     if (MyData == Nothing)
  298.         goto    WriteCfgExit
  299.     endif
  300.     if not (Data.Length(MyData) == CfgSize)
  301.         Status("Error: File is not the size of the Cfg")
  302.         goto    WriteCfgExit
  303.     endif
  304.     Memory(SPIFLASH).Write(MyData,CfgBase,CfgSize)
  305.     Status("New Cfg successfully written")
  306.  WriteCfgExit:
  307.         Tab(t1).ButtonEnable()
  308. EndEvent
  309.  
  310.  
  311. CreateEvent(ReadFullFlash)
  312.     Status("Saving the SB6141's Full Flash")
  313.         Tab(t1).ButtonDisable()
  314.     MyData = Memory(SPIFLASH).ReadVerify(FlBase,FlSize)
  315.         if (MyData == Nothing)
  316.         Status("Error: data read back failed")
  317.             Tab(t1).ButtonEnable()
  318.         Exit Event
  319.     endif
  320.     Prompt = "Choose filename to save Full Flash"
  321.     #SaveFile(MyData,Prompt,"FullFlash.bin")
  322.     IO.Save(MyData,Prompt,"FullFlash.bin")
  323.     Status("Successfully read Full Flash!")
  324.         Tab(t1).ButtonEnable()
  325. EndEvent
  326.  
  327. CreateEvent(WriteFullFlash)
  328.     Status("Programming the SB6141's Full Flash")
  329.         Tab(t1).ButtonDisable()
  330.     Prompt = "Choose a firmware to install"
  331.     #MyData = OpenFile(Prompt,"Full Flash files (*.bin)|*.bin")
  332.     MyData = IO.Open(Prompt,"Full Flash files (*.bin)|*.bin")
  333.     if (MyData == Nothing)
  334.         WriteErr = "User cancelled operation"
  335.         goto    ExitWriteFwErr
  336.     endif
  337.     FlLen = Data.Length(MyData)
  338.     Memory(SPIFLASH).Write(MyData,FlBase,FlLen)
  339.     FlSize = FlLen
  340.     Status("Full Flash successful!")
  341.         Tab(t1).ButtonEnable()
  342.         Exit
  343.   ExitWriteFwErr:
  344.     Status(WriteErr)
  345.         Tab(t1).ButtonEnable()
  346. EndEvent
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement