cmd: Split commands into their own files
Commands shouldn't all live in main.c. Move everything except "help" into its own command file.
This commit is contained in:
parent
555af9447c
commit
72f92b7fd2
7 changed files with 146 additions and 131 deletions
4
Makefile
4
Makefile
|
@ -10,7 +10,11 @@ LIBS =
|
||||||
|
|
||||||
SRC_C = \
|
SRC_C = \
|
||||||
bionic.c \
|
bionic.c \
|
||||||
|
cmd-hex.c \
|
||||||
cmd-irq.c \
|
cmd-irq.c \
|
||||||
|
cmd-peekpoke.c \
|
||||||
|
cmd-reboot.c \
|
||||||
|
cmd-sleep.c \
|
||||||
emi.c \
|
emi.c \
|
||||||
irq.c \
|
irq.c \
|
||||||
main.c \
|
main.c \
|
||||||
|
|
24
cmd-hex.c
Normal file
24
cmd-hex.c
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
#include <string.h>
|
||||||
|
#include "bionic.h"
|
||||||
|
#include "memio.h"
|
||||||
|
#include "printf.h"
|
||||||
|
#include "serial.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
|
int cmd_hex(int argc, char **argv)
|
||||||
|
{
|
||||||
|
uint32_t offset;
|
||||||
|
int count = 0x200;
|
||||||
|
if (argc < 1) {
|
||||||
|
printf("Usage: hex [offset] [[count]]\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
offset = _strtoul(argv[0], NULL, 0);
|
||||||
|
|
||||||
|
if (argc > 1)
|
||||||
|
count = _strtoul(argv[1], NULL, 0);
|
||||||
|
|
||||||
|
serial_print_hex((const void *)offset, count);
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -50,3 +50,12 @@ int cmd_irq(int argc, char **argv)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int cmd_swi(int argc, char **argv)
|
||||||
|
{
|
||||||
|
printf("Generating SWI...\n");
|
||||||
|
asm volatile ("swi #0\n");
|
||||||
|
printf("Returned from SWI\n");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
41
cmd-peekpoke.c
Normal file
41
cmd-peekpoke.c
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
#include <string.h>
|
||||||
|
#include "bionic.h"
|
||||||
|
#include "memio.h"
|
||||||
|
#include "printf.h"
|
||||||
|
#include "serial.h"
|
||||||
|
|
||||||
|
int cmd_peek(int argc, char **argv)
|
||||||
|
{
|
||||||
|
uint32_t offset;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
17
cmd-reboot.c
Normal file
17
cmd-reboot.c
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
#include <string.h>
|
||||||
|
#include "memio.h"
|
||||||
|
#include "printf.h"
|
||||||
|
|
||||||
|
static int wdt_reboot(void)
|
||||||
|
{
|
||||||
|
writel(0x1209, 0xa003001c);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int cmd_reboot(int argc, char **argv)
|
||||||
|
{
|
||||||
|
printf("Rebooting...\n");
|
||||||
|
wdt_reboot();
|
||||||
|
while(1);
|
||||||
|
return 0;
|
||||||
|
}
|
44
cmd-sleep.c
Normal file
44
cmd-sleep.c
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
#include <string.h>
|
||||||
|
#include "bionic.h"
|
||||||
|
#include "memio.h"
|
||||||
|
#include "printf.h"
|
||||||
|
|
||||||
|
int cmd_msleep(int argc, char **argv)
|
||||||
|
{
|
||||||
|
uint32_t msecs, i, j;
|
||||||
|
|
||||||
|
if (argc != 1) {
|
||||||
|
printf("Usage: msleep [milliseconds]\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
msecs = _strtoul(argv[0], NULL, 0);
|
||||||
|
|
||||||
|
for (i = 0; i < msecs; i++) {
|
||||||
|
for (j = 0; j < 73000; j++) {
|
||||||
|
asm("nop");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int cmd_usleep(int argc, char **argv)
|
||||||
|
{
|
||||||
|
uint32_t usecs, i, j;
|
||||||
|
|
||||||
|
if (argc != 1) {
|
||||||
|
printf("Usage: usleep [microseconds]\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
usecs = _strtoul(argv[0], NULL, 0);
|
||||||
|
|
||||||
|
for (i = 0; i < usecs; i++) {
|
||||||
|
for (j = 0; j < 73; j++) {
|
||||||
|
asm("nop");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
138
main.c
138
main.c
|
@ -83,20 +83,6 @@ static int serial_get_line(char *bfr, int len)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
|
||||||
static int wdt_kick(void)
|
|
||||||
{
|
|
||||||
writel(0x1971, 0xa0030008);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
static int wdt_reboot(void)
|
|
||||||
{
|
|
||||||
writel(0x1209, 0xa003001c);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int list_registers(void)
|
static int list_registers(void)
|
||||||
{
|
{
|
||||||
int var;
|
int var;
|
||||||
|
@ -350,14 +336,13 @@ static int loop(void)
|
||||||
#else /* AUTOMATED */
|
#else /* AUTOMATED */
|
||||||
|
|
||||||
static int cmd_help(int argc, char **argv);
|
static int cmd_help(int argc, char **argv);
|
||||||
static int cmd_hex(int argc, char **argv);
|
extern int cmd_hex(int argc, char **argv);
|
||||||
static int cmd_peek(int argc, char **argv);
|
extern int cmd_peek(int argc, char **argv);
|
||||||
static int cmd_poke(int argc, char **argv);
|
extern int cmd_poke(int argc, char **argv);
|
||||||
static int cmd_swi(int argc, char **argv);
|
extern int cmd_swi(int argc, char **argv);
|
||||||
static int cmd_reboot(int argc, char **argv);
|
extern int cmd_reboot(int argc, char **argv);
|
||||||
static int cmd_args(int argc, char **argv);
|
extern int cmd_msleep(int argc, char **argv);
|
||||||
static int cmd_msleep(int argc, char **argv);
|
extern int cmd_irq(int argc, char **argv);
|
||||||
int cmd_irq(int argc, char **argv);
|
|
||||||
|
|
||||||
static const struct {
|
static const struct {
|
||||||
int (*func)(int argc, char **argv);
|
int (*func)(int argc, char **argv);
|
||||||
|
@ -399,11 +384,6 @@ static const struct {
|
||||||
.name = "irq",
|
.name = "irq",
|
||||||
.help = "Manipulate IRQs",
|
.help = "Manipulate IRQs",
|
||||||
},
|
},
|
||||||
{
|
|
||||||
.func = cmd_args,
|
|
||||||
.name = "args",
|
|
||||||
.help = "Print contents of arc and argv",
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
.func = cmd_swi,
|
.func = cmd_swi,
|
||||||
.name = "swi",
|
.name = "swi",
|
||||||
|
@ -426,110 +406,6 @@ int cmd_help(int argc, char **argv)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int cmd_msleep(int argc, char **argv)
|
|
||||||
{
|
|
||||||
unsigned int msecs, i, j;
|
|
||||||
|
|
||||||
if (argc != 1) {
|
|
||||||
printf("Usage: msleep [milliseconds]\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
msecs = _strtoul(argv[0], NULL, 0);
|
|
||||||
|
|
||||||
for (i = 0; i < msecs; i++) {
|
|
||||||
for (j = 0; j < 65000; j++) {
|
|
||||||
asm("nop");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int cmd_args(int argc, char **argv)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
printf("argc: %d\n", argc);
|
|
||||||
for (i = 0; i < argc; i++) {
|
|
||||||
printf("argv[%d]: ", i);
|
|
||||||
serial_puts(argv[i]);
|
|
||||||
serial_puts("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int cmd_hex(int argc, char **argv)
|
|
||||||
{
|
|
||||||
uint32_t offset;
|
|
||||||
int count = 0x200;
|
|
||||||
if (argc < 1) {
|
|
||||||
printf("Usage: hex [offset] [[count]]\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
offset = _strtoul(argv[0], NULL, 0);
|
|
||||||
|
|
||||||
if (argc > 1)
|
|
||||||
count = _strtoul(argv[1], NULL, 0);
|
|
||||||
|
|
||||||
serial_print_hex((const void *)offset, count);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int cmd_peek(int argc, char **argv)
|
|
||||||
{
|
|
||||||
uint32_t offset;
|
|
||||||
|
|
||||||
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");
|
|
||||||
asm volatile ("swi #0\n");
|
|
||||||
printf("Returned from SWI\n");
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int cmd_reboot(int argc, char **argv)
|
|
||||||
{
|
|
||||||
printf("Rebooting...\n");
|
|
||||||
wdt_reboot();
|
|
||||||
while(1);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int shell_run_command(char *line)
|
static int shell_run_command(char *line)
|
||||||
{
|
{
|
||||||
char *lp, *cmd, *tokp;
|
char *lp, *cmd, *tokp;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue