public CustomStartupSequence BuildSequence(string targetPath, Dictionary <string, string> bspDict, Dictionary <string, string> debugMethodConfig, LiveMemoryLineHandler lineHandler) { List <CustomStartStep> cmds = new List <CustomStartStep>(); cmds.Add(new CustomStartStep("mon esp108 chip_reset")); string bspPath = bspDict["SYS:BSP_ROOT"]; string val; if (bspDict.TryGetValue("com.sysprogs.esp32.load_flash", out val) && val == "1") { //Not a FLASHless project, FLASH loading required if (debugMethodConfig.TryGetValue("com.sysprogs.esp8266.xt-ocd.program_flash", out val) && val != "0") { string loader = bspPath + @"\sysprogs\flashprog\ESP32FlashProg.bin"; if (!File.Exists(loader)) { throw new Exception("FLASH loader not found: " + loader); } var parsedLoader = new ParsedFLASHLoader(loader); //List<ProgrammableRegion> regions = new List<ProgrammableRegion>(); //regions.Add(new ProgrammableRegion { FileName = @"E:\temp\esp\build\bootloader\bootloader.bin", Offset = 0x1000, Size = 4224 }); //regions.Add(new ProgrammableRegion { FileName = @"E:\temp\esp\build\blink.bin", Offset = 0x10000, Size = 245328 }); //regions.Add(new ProgrammableRegion { FileName = @"E:\temp\esp\build\partitions_singleapp.bin", Offset = 0x4000, Size = 96 }); var regions = BuildFLASHImages(targetPath, bspDict, debugMethodConfig, lineHandler); int eraseBlockSize = int.Parse(debugMethodConfig["com.sysprogs.esp8266.xt-ocd.erase_sector_size"]); cmds.Add(parsedLoader.QueueInvocation(0, "$$com.sysprogs.esp8266.xt-ocd.prog_sector_size$$", "0", null, 0, 0, true)); for (int pass = 0; pass < 2; pass++) { foreach (var region in regions) { parsedLoader.QueueRegionProgramming(cmds, region, eraseBlockSize, pass == 0); } } } cmds.Add(new CustomStartStep("mon esp108 chip_reset")); } else { cmds.Add(new CustomStartStep("load")); } return(new CustomStartupSequence { Steps = cmds }); }
public static CustomStartupSequence BuildSequence(BSPEngine.IDebugStartService service, ESP8266OpenOCDSettings settings, BSPEngine.LiveMemoryLineHandler lineHandler, bool programFLASH) { List <CustomStartStep> cmds = new List <CustomStartStep>(); cmds.Add(new CustomStartStep("mon reset halt", "-exec-next-instruction", "set $com_sysprogs_esp8266_wdcfg=0", "set $vecbase=0x40000000", "$$com.sysprogs.esp8266.interrupt_disable_command$$", "set $ccompare=0", "set $intclear=-1", "set $intenable=0", "set $eps2=0x20", "set $icountlevel=0")); var result = new CustomStartupSequence { Steps = cmds }; var bspDict = service.SystemDictionary; var targetPath = service.TargetPath; string val; if (bspDict.TryGetValue("com.sysprogs.esp8266.load_flash", out val) && val == "1") //Not a FLASHless project { if (programFLASH) { string bspPath = bspDict["SYS:BSP_ROOT"]; List <ProgrammableRegion> regions = BuildFLASHImages(service, settings, lineHandler); string loader = bspPath + @"\sysprogs\flashprog\ESP8266FlashProg.bin"; if (!File.Exists(loader)) { throw new Exception("FLASH loader not found: " + loader); } var parsedLoader = new ParsedFLASHLoader(loader); cmds.Add(new CustomStartStep("print *((int *)0x60000900)", "set *((int *)0x60000900)=0")); cmds.Add(parsedLoader.QueueInvocation(0, settings.ProgramSectorSize.ToString(), settings.EraseSectorSize.ToString(), null, 0, 0, true)); foreach (var region in regions) { parsedLoader.QueueRegionProgramming(cmds, region); } } var resetMode = settings.ResetMode; if (resetMode == ResetMode.Soft) { try { using (var elfFile = new ELFFile(targetPath)) { string pathBase = Path.Combine(Path.GetDirectoryName(targetPath), Path.GetFileName(targetPath)); string status; int appMode = ESP8266BinaryImage.DetectAppMode(elfFile, out status); if (appMode != 0) { if (service.GUIService.Prompt("The soft reset mechanism is not compatible with the OTA images. Use the jump-to-entry reset instead?")) { resetMode = ResetMode.Hard; } } } } catch { } } if (resetMode == ResetMode.Soft || resetMode == ResetMode.JumpToEntry) { string entry = "0x40000080"; if (resetMode == ResetMode.JumpToEntry) { using (ELFFile elf = new ELFFile(targetPath)) { foreach (var sec in elf.AllSections) { if (!sec.PresentInMemory || !sec.HasData || sec.Type != ELFFile.SectionType.SHT_PROGBITS) { continue; } bool isInRAM = false; if (sec.VirtualAddress >= 0x3FFE8000 && sec.VirtualAddress < (0x3FFE8000 + 81920)) { isInRAM = true; } else if (sec.VirtualAddress >= 0x40100000 && sec.VirtualAddress <= (0x40100000 + 32768)) { isInRAM = true; } if (isInRAM) { cmds.Add(new CustomStartStep(string.Format("restore {0} binary 0x{1:x} 0x{2:x} 0x{3:x}", targetPath.Replace('\\', '/'), sec.VirtualAddress - sec.OffsetInFile, sec.OffsetInFile, sec.OffsetInFile + sec.Size)) { CheckResult = true, ErrorMessage = "Failed to program the " + sec.SectionName + " section" }); } } } entry = "$$DEBUG:ENTRY_POINT$$"; } cmds.Add(new CustomStartStep("set $ps=0x20", "set $epc2=" + entry, "set $sp=$$DEBUG:INITIAL_STACK_POINTER$$", "set $vecbase=0x40000000", "$$com.sysprogs.esp8266.interrupt_disable_command$$", "set $intclear=-1", "set $intenable=0", "set $eps2=0x20", "set $icountlevel=0")); result.InitialHardBreakpointExpression = "*$$DEBUG:ENTRY_POINT$$"; } else { cmds.Add(new CustomStartStep("mon reset halt")); } } else { cmds.Add(new CustomStartStep("load", "set $ps=0x20", "set $epc2=$$DEBUG:ENTRY_POINT$$", "set $sp=$$DEBUG:INITIAL_STACK_POINTER$$", "set $vecbase=0x40000000", "$$com.sysprogs.esp8266.interrupt_disable_command$$", "set $ccompare=0", "set $intclear=-1", "set $intenable=0", "set $eps2=0x20", "set $icountlevel=0")); } return(result); }
public CustomStartupSequence BuildSequence(string targetPath, Dictionary<string, string> bspDict, Dictionary<string, string> debugMethodConfig, LiveMemoryLineHandler lineHandler) { bool isOpenOCD = debugMethodConfig.ContainsKey("com.sysprogs.esp8266.openocd.iface_script"); List<CustomStartStep> cmds = new List<CustomStartStep>(); cmds.Add(new CustomStartStep(isOpenOCD ? "mon reset halt" : "maint packet R", "-exec-next-instruction", "set $com_sysprogs_esp8266_wdcfg=0", "set $vecbase=0x40000000", "$$com.sysprogs.esp8266.interrupt_disable_command$$", "set $ccompare=0", "set $intclear=-1", "set $intenable=0", "set $eps2=0x20", "set $icountlevel=0")); var result = new CustomStartupSequence { Steps = cmds }; string val; if (bspDict.TryGetValue("com.sysprogs.esp8266.load_flash", out val) && val == "1") //Not a FLASHless project { if (debugMethodConfig.TryGetValue("com.sysprogs.esp8266.xt-ocd.program_flash", out val) && val != "0") { string bspPath = bspDict["SYS:BSP_ROOT"]; List<ProgrammableRegion> regions = BuildFLASHImages(targetPath, bspDict, debugMethodConfig, lineHandler); string loader = bspPath + @"\sysprogs\flashprog\ESP8266FlashProg.bin"; if (!File.Exists(loader)) throw new Exception("FLASH loader not found: " + loader); var parsedLoader = new ParsedFLASHLoader(loader); cmds.Add(new CustomStartStep("print *((int *)0x60000900)", "set *((int *)0x60000900)=0")); cmds.Add(parsedLoader.QueueInvocation(0, "$$com.sysprogs.esp8266.xt-ocd.prog_sector_size$$", "$$com.sysprogs.esp8266.xt-ocd.erase_sector_size$$", null, 0, 0, true)); foreach (var region in regions) parsedLoader.QueueRegionProgramming(cmds, region); } if (!debugMethodConfig.TryGetValue("com.sysprogs.esp8266.xt-ocd.flash_start_mode", out val)) val = "soft_reset"; if (val == "soft_reset") { try { using (var elfFile = new ELFFile(targetPath)) { string pathBase = Path.Combine(Path.GetDirectoryName(targetPath), Path.GetFileName(targetPath)); string status; int appMode = ESP8266BinaryImage.DetectAppMode(elfFile, out status); if (appMode != 0) { if (System.Windows.Forms.MessageBox.Show("The soft reset mechanism is not compatible with the OTA images. Use the jump-to-entry reset instead?", "VisualGDB", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.Yes) val = "entry_point"; } } } catch { } } if (val == "soft_reset" || val == "entry_point") { string entry = "0x40000080"; if (val == "entry_point") { using (ELFFile elf = new ELFFile(targetPath)) { foreach (var sec in elf.AllSections) { if (!sec.PresentInMemory || !sec.HasData || sec.Type != ELFFile.SectionType.SHT_PROGBITS) continue; bool isInRAM = false; if (sec.VirtualAddress >= 0x3FFE8000 && sec.VirtualAddress < (0x3FFE8000 + 81920)) isInRAM = true; else if (sec.VirtualAddress >= 0x40100000 && sec.VirtualAddress <= (0x40100000 + 32768)) isInRAM = true; if (isInRAM) { cmds.Add(new CustomStartStep(string.Format("restore {0} binary 0x{1:x} 0x{2:x} 0x{3:x}", targetPath.Replace('\\', '/'), sec.VirtualAddress - sec.OffsetInFile, sec.OffsetInFile, sec.OffsetInFile + sec.Size)) { CheckResult = true, ErrorMessage = "Failed to program the " + sec.SectionName + " section" }); } } } entry = "$$DEBUG:ENTRY_POINT$$"; } cmds.Add(new CustomStartStep("set $ps=0x20", "set $epc2=" + entry, "set $sp=$$DEBUG:INITIAL_STACK_POINTER$$", "set $vecbase=0x40000000", "$$com.sysprogs.esp8266.interrupt_disable_command$$", "set $intclear=-1", "set $intenable=0", "set $eps2=0x20", "set $icountlevel=0")); result.InitialHardBreakpointExpression = "*$$DEBUG:ENTRY_POINT$$"; } else cmds.Add(new CustomStartStep(isOpenOCD ? "mon reset halt" : "maint packet R")); } else { cmds.Add(new CustomStartStep("load", "set $ps=0x20", "set $epc2=$$DEBUG:ENTRY_POINT$$", "set $sp=$$DEBUG:INITIAL_STACK_POINTER$$", "set $vecbase=0x40000000", "$$com.sysprogs.esp8266.interrupt_disable_command$$", "set $ccompare=0", "set $intclear=-1", "set $intenable=0", "set $eps2=0x20", "set $icountlevel=0")); } return result; }
public CustomStartupSequence BuildSequence(string targetPath, Dictionary<string, string> bspDict, Dictionary<string, string> debugMethodConfig, LiveMemoryLineHandler lineHandler) { List<CustomStartStep> cmds = new List<CustomStartStep>(); cmds.Add(new CustomStartStep("mon esp108 chip_reset")); string bspPath = bspDict["SYS:BSP_ROOT"]; string val; if (bspDict.TryGetValue("com.sysprogs.esp32.load_flash", out val) && val == "1") { //Not a FLASHless project, FLASH loading required if (debugMethodConfig.TryGetValue("com.sysprogs.esp8266.xt-ocd.program_flash", out val) && val != "0") { string loader = bspPath + @"\sysprogs\flashprog\ESP32FlashProg.bin"; if (!File.Exists(loader)) throw new Exception("FLASH loader not found: " + loader); var parsedLoader = new ParsedFLASHLoader(loader); //List<ProgrammableRegion> regions = new List<ProgrammableRegion>(); //regions.Add(new ProgrammableRegion { FileName = @"E:\temp\esp\build\bootloader\bootloader.bin", Offset = 0x1000, Size = 4224 }); //regions.Add(new ProgrammableRegion { FileName = @"E:\temp\esp\build\blink.bin", Offset = 0x10000, Size = 245328 }); //regions.Add(new ProgrammableRegion { FileName = @"E:\temp\esp\build\partitions_singleapp.bin", Offset = 0x4000, Size = 96 }); var regions = BuildFLASHImages(targetPath, bspDict, debugMethodConfig, lineHandler); int eraseBlockSize = int.Parse(debugMethodConfig["com.sysprogs.esp8266.xt-ocd.erase_sector_size"]); cmds.Add(parsedLoader.QueueInvocation(0, "$$com.sysprogs.esp8266.xt-ocd.prog_sector_size$$", "0", null, 0, 0, true)); for (int pass = 0; pass < 2; pass++) foreach (var region in regions) parsedLoader.QueueRegionProgramming(cmds, region, eraseBlockSize, pass == 0); } cmds.Add(new CustomStartStep("mon esp108 chip_reset")); } else { cmds.Add(new CustomStartStep("load")); } return new CustomStartupSequence { Steps = cmds }; }
public CustomStartupSequence BuildSequence(string targetPath, Dictionary <string, string> bspDict, Dictionary <string, string> debugMethodConfig, LiveMemoryLineHandler lineHandler) { bool isOpenOCD = debugMethodConfig.ContainsKey("com.sysprogs.esp8266.openocd.iface_script"); List <CustomStartStep> cmds = new List <CustomStartStep>(); cmds.Add(new CustomStartStep(isOpenOCD ? "mon reset halt" : "maint packet R", "-exec-next-instruction", "set $com_sysprogs_esp8266_wdcfg=0", "set $vecbase=0x40000000", "$$com.sysprogs.esp8266.interrupt_disable_command$$", "set $ccompare=0", "set $intclear=-1", "set $intenable=0", "set $eps2=0x20", "set $icountlevel=0")); var result = new CustomStartupSequence { Steps = cmds }; string val; if (bspDict.TryGetValue("com.sysprogs.esp8266.load_flash", out val) && val == "1") //Not a FLASHless project { if (debugMethodConfig.TryGetValue("com.sysprogs.esp8266.xt-ocd.program_flash", out val) && val != "0") { string bspPath = bspDict["SYS:BSP_ROOT"]; List <ProgrammableRegion> regions = BuildFLASHImages(targetPath, bspDict, debugMethodConfig, lineHandler); string loader = bspPath + @"\sysprogs\flashprog\ESP8266FlashProg.bin"; if (!File.Exists(loader)) { throw new Exception("FLASH loader not found: " + loader); } var parsedLoader = new ParsedFLASHLoader(loader); cmds.Add(new CustomStartStep("print *((int *)0x60000900)", "set *((int *)0x60000900)=0")); cmds.Add(parsedLoader.QueueInvocation(0, "$$com.sysprogs.esp8266.xt-ocd.prog_sector_size$$", "$$com.sysprogs.esp8266.xt-ocd.erase_sector_size$$", null, 0, 0, true)); foreach (var region in regions) { parsedLoader.QueueRegionProgramming(cmds, region); } } if (!debugMethodConfig.TryGetValue("com.sysprogs.esp8266.xt-ocd.flash_start_mode", out val)) { val = "soft_reset"; } if (val == "soft_reset") { try { using (var elfFile = new ELFFile(targetPath)) { string pathBase = Path.Combine(Path.GetDirectoryName(targetPath), Path.GetFileName(targetPath)); string status; int appMode = ESP8266BinaryImage.DetectAppMode(elfFile, out status); if (appMode != 0) { if (System.Windows.Forms.MessageBox.Show("The soft reset mechanism is not compatible with the OTA images. Use the jump-to-entry reset instead?", "VisualGDB", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.Yes) { val = "entry_point"; } } } } catch { } } if (val == "soft_reset" || val == "entry_point") { string entry = "0x40000080"; if (val == "entry_point") { using (ELFFile elf = new ELFFile(targetPath)) { foreach (var sec in elf.AllSections) { if (!sec.PresentInMemory || !sec.HasData || sec.Type != ELFFile.SectionType.SHT_PROGBITS) { continue; } bool isInRAM = false; if (sec.VirtualAddress >= 0x3FFE8000 && sec.VirtualAddress < (0x3FFE8000 + 81920)) { isInRAM = true; } else if (sec.VirtualAddress >= 0x40100000 && sec.VirtualAddress <= (0x40100000 + 32768)) { isInRAM = true; } if (isInRAM) { cmds.Add(new CustomStartStep(string.Format("restore {0} binary 0x{1:x} 0x{2:x} 0x{3:x}", targetPath.Replace('\\', '/'), sec.VirtualAddress - sec.OffsetInFile, sec.OffsetInFile, sec.OffsetInFile + sec.Size)) { CheckResult = true, ErrorMessage = "Failed to program the " + sec.SectionName + " section" }); } } } entry = "$$DEBUG:ENTRY_POINT$$"; } cmds.Add(new CustomStartStep("set $ps=0x20", "set $epc2=" + entry, "set $sp=$$DEBUG:INITIAL_STACK_POINTER$$", "set $vecbase=0x40000000", "$$com.sysprogs.esp8266.interrupt_disable_command$$", "set $intclear=-1", "set $intenable=0", "set $eps2=0x20", "set $icountlevel=0")); result.InitialHardBreakpointExpression = "*$$DEBUG:ENTRY_POINT$$"; } else { cmds.Add(new CustomStartStep(isOpenOCD ? "mon reset halt" : "maint packet R")); } } else { cmds.Add(new CustomStartStep("load", "set $ps=0x20", "set $epc2=$$DEBUG:ENTRY_POINT$$", "set $sp=$$DEBUG:INITIAL_STACK_POINTER$$", "set $vecbase=0x40000000", "$$com.sysprogs.esp8266.interrupt_disable_command$$", "set $ccompare=0", "set $intclear=-1", "set $intenable=0", "set $eps2=0x20", "set $icountlevel=0")); } return(result); }