main: Add peek and poke commands

This commit is contained in:
Sean Cross 2014-09-09 11:14:06 +08:00
parent 48710a3b69
commit a066600558

51
main.c
View file

@ -6,7 +6,7 @@
#include "serial.h"
#include "utils.h"
#define AUTOMATED
//#define AUTOMATED
#if !defined(AUTOMATED)
#define PROMPT "fernly> "
@ -342,6 +342,8 @@ static int loop(void)
static int cmd_help(int argc, char **argv);
static int cmd_hex(int argc, char **argv);
static int cmd_peek(int argc, char **argv);
static int cmd_poke(int argc, char **argv);
static int cmd_swi(int argc, char **argv);
static int cmd_reboot(int argc, char **argv);
static int cmd_args(int argc, char **argv);
@ -367,6 +369,16 @@ static struct {
.name = "hex",
.help = "Print area of memory as hex",
},
{
.func = cmd_peek,
.name = "peek",
.help = "Look at one area of memory",
},
{
.func = cmd_poke,
.name = "poke",
.help = "Write a value to an area of memory",
},
{
.func = cmd_irq,
.name = "irq",
@ -430,6 +442,43 @@ int cmd_hex(int argc, char **argv)
return 0;
}
int cmd_peek(int argc, char **argv)
{
uint32_t offset;
uint32_t val;
if (argc < 1) {
printf("Usage: peek [offset\n");
return -1;
}
offset = _strtoul(argv[0], NULL, 0);
printf("Value at 0x%08x: ", offset);
printf("0x%08x\n", *((volatile uint32_t *)offset));
return 0;
}
int cmd_poke(int argc, char **argv)
{
uint32_t offset;
uint32_t val;
if (argc < 2) {
printf("Usage: poke [offset] [val]\n");
return -1;
}
offset = _strtoul(argv[0], NULL, 0);
val = _strtoul(argv[1], NULL, 0);
printf("Setting value at 0x%08x to 0x%08x: ", offset, val);
writel(val, offset);
printf("Ok\n");
return 0;
}
int cmd_swi(int argc, char **argv)
{
printf("Generating SWI...\n");