Skip to content

Commit b5674bd

Browse files
committed
Added Cortex-M FPB support to CLI
1 parent 4de10bf commit b5674bd

File tree

2 files changed

+143
-14
lines changed

2 files changed

+143
-14
lines changed

jtagsh/commands.cpp

Lines changed: 142 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,13 @@ void TargetShell(DebuggableDevice* pdev)
252252
else if(args[0].find("debug-") == 0)
253253
OnDebugCommand(pdev, args[0].substr(6), args);
254254

255+
else if(args[0] == "info")
256+
{
257+
auto papb = dynamic_cast<ARMAPBDevice*>(pdev);
258+
if(papb)
259+
papb->PrintInfo();
260+
}
261+
255262
else
256263
{
257264
LogNotice("Unrecognized command\n");
@@ -349,7 +356,9 @@ void OnTarget(DebuggerInterface* iface, const vector<string>& args)
349356
}
350357

351358
//Run the interactive shell
352-
TargetShell(iface->GetTarget(tnum));
359+
auto ptarget = iface->GetTarget(tnum);
360+
LogNotice("Selected target %u: %s\n", tnum, ptarget->GetDescription().c_str());
361+
TargetShell(ptarget);
353362
}
354363

355364
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -370,6 +379,69 @@ void OnDebugCommand(DebuggableDevice* pdev, const string& cmd, const vector<stri
370379
else if(cmd == "regs")
371380
pdev->PrintRegisters();
372381

382+
else if(cmd == "fpb")
383+
{
384+
if(args.size() < 2)
385+
{
386+
LogError("Usage: debug-fpb [command]\n");
387+
return;
388+
}
389+
390+
auto cpu = dynamic_cast<ARMv7MProcessor*>(pdev);
391+
if(cpu)
392+
{
393+
auto fpb = cpu->GetFlashPatchBreakpoint();
394+
if(fpb)
395+
OnDebugFPBCommand(fpb, args[1], args);
396+
else
397+
LogError("debug-fpb requires a CPU with a Flash Patch/Breakpoint unit\n");
398+
}
399+
else
400+
LogError("debug-fpb requires an ARMv7-M target\n");
401+
}
402+
403+
//Dump memory to a file
404+
else if(cmd == "dumpmem")
405+
{
406+
if(args.size() != 4)
407+
{
408+
LogError("Usage: dumpmem [hex base address] [hex length] [filename]\n");
409+
return;
410+
}
411+
412+
uint32_t addr;
413+
sscanf(args[1].c_str(), "%x", &addr);
414+
415+
uint32_t len;
416+
sscanf(args[2].c_str(), "%x", &len);
417+
418+
string fname = args[3];
419+
420+
FILE* fp = fopen(fname.c_str(), "wb");
421+
if(!fp)
422+
{
423+
LogError("couldn't open file\n");
424+
return;
425+
}
426+
427+
LogIndenter li;
428+
for(uint32_t off=0; off<len; off += 4)
429+
{
430+
uint32_t ptr = addr + off;
431+
432+
if( (ptr & 0xfff) == 0)
433+
LogNotice("%08x\n", ptr);
434+
435+
uint32_t value = pdev->ReadMemory(ptr);
436+
if(1 != fwrite(&value, 4, 1, fp))
437+
{
438+
LogError("couldn't write file\n");
439+
return;
440+
}
441+
}
442+
fclose(fp);
443+
}
444+
373445
//Read memory from the default RAM source (generally AHB or AXI bus on ARM targets)
374446
else if(cmd == "readmem")
375447
{
@@ -408,6 +480,75 @@ void OnDebugCommand(DebuggableDevice* pdev, const string& cmd, const vector<stri
408480
LogNotice("Unrecognized command\n");
409481
}
410482

483+
void OnDebugFPBCommand(ARMFlashPatchBreakpoint* pdev, const string& cmd, const vector<string>& args)
484+
{
485+
//Turn the FPB on/off
486+
if(cmd == "enable")
487+
pdev->Enable();
488+
else if(cmd == "disable")
489+
pdev->Disable();
490+
491+
//Print debug info
492+
else if(cmd == "info")
493+
pdev->PrintInfo();
494+
495+
//Set the base address of the remapping table
496+
else if(cmd == "setbase")
497+
{
498+
if(args.size() != 3)
499+
{
500+
LogError("Usage: debug-fpb setbase [hex address]\n");
501+
return;
502+
}
503+
504+
uint32_t addr;
505+
sscanf(args[2].c_str(), "%x", &addr);
506+
507+
pdev->SetRemapTableBase(addr);
508+
}
509+
510+
//Write to the remapping table
511+
else if(cmd == "remap")
512+
{
513+
if(args.size() != 5)
514+
{
515+
LogError("Usage: debug-fpb remap [slot] [hex flash address] [new hex opcode]\n");
516+
return;
517+
}
518+
519+
uint32_t slot;
520+
sscanf(args[2].c_str(), "%d", &slot);
521+
522+
uint32_t addr;
523+
sscanf(args[3].c_str(), "%x", &addr);
524+
525+
uint32_t opcode;
526+
sscanf(args[4].c_str(), "%x", &opcode);
527+
528+
pdev->RemapFlashWord(slot, addr, opcode);
529+
}
530+
531+
else
532+
LogNotice("Unrecognized command\n");
533+
}
534+
535+
void OnTargets(DebuggerInterface* iface)
536+
{
537+
if(iface == NULL)
538+
{
539+
LogError("The \"targets\" command can only be used on a debugger interface\n");
540+
return;
541+
}
542+
543+
LogNotice("%10s %-50s\n", "Index", "Description");
544+
for(size_t i=0; i<iface->GetNumTargets(); i++)
545+
{
546+
auto target = iface->GetTarget(i);
547+
LogNotice("%10zu %-50s\n", i, target->GetDescription().c_str() );
548+
}
549+
}
550+
551+
411552
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
412553
// Vendor commands
413554

@@ -497,16 +638,3 @@ void OnXilinxCommand(XilinxFPGA* pdev, const string& cmd, const vector<string>&
497638
LogNotice("Unrecognized command\n");
498639

499640
}
500-
501-
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
502-
// Vendor commands
503-
504-
void OnTargets(DebuggerInterface* iface)
505-
{
506-
LogNotice("%10s %-50s\n", "Index", "Description");
507-
for(size_t i=0; i<iface->GetNumTargets(); i++)
508-
{
509-
auto target = iface->GetTarget(i);
510-
LogNotice("%10zu %-50s\n", i, target->GetDescription().c_str() );
511-
}
512-
}

jtagsh/jtagsh.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ void OnTargets(DebuggerInterface* iface);
5959

6060
void OnARMCommand(ARMDebugPort* pdev, const std::string& cmd, const std::vector<std::string>& args);
6161
void OnDebugCommand(DebuggableDevice* pdev, const std::string& cmd, const std::vector<std::string>& args);
62+
void OnDebugFPBCommand(ARMFlashPatchBreakpoint* pdev, const std::string& cmd, const std::vector<std::string>& args);
6263
void OnXilinxCommand(XilinxFPGA* pdev, const std::string& cmd, const std::vector<std::string>& args);
6364

6465
#endif

0 commit comments

Comments
 (0)