From 8c36acee575ceaf4d395d76c23e93f312d2e5275 Mon Sep 17 00:00:00 2001 From: Peter Zotov Date: Sat, 4 Dec 2010 07:01:21 +0300 Subject: [PATCH] Implement GPIO changing with SPL commands. --- ingenic.h | 4 ++++ spl_cmdset.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/ingenic.h b/ingenic.h index f9a280e..0432301 100644 --- a/ingenic.h +++ b/ingenic.h @@ -38,6 +38,10 @@ int ingenic_loadstage(void *hndl, int id, const char *filename); #define INGENIC_STAGE1 1 #define INGENIC_STAGE2 2 +#define SPL_DEBUG_MEMTEST "1" +#define SPL_DEBUG_GPIO_SET "2" +#define SPL_DEBUG_GPIO_CLEAR "3" + #define STAGE1_BASE 0x2000 #define STAGE2_CODESIZE 0x400000 #define SDRAM_BASE 0x80000000 diff --git a/spl_cmdset.c b/spl_cmdset.c index 8b9fe53..0d37a2b 100644 --- a/spl_cmdset.c +++ b/spl_cmdset.c @@ -19,16 +19,19 @@ #include #include +#include #include "shell.h" #include "config.h" #include "ingenic.h" static int spl_memtest(int argc, char *argv[]); +static int spl_gpio(int argc, char *argv[]); static int spl_boot(int argc, char *argv[]); const shell_command_t spl_cmdset[] = { { "memtest", "[BASE ] - SDRAM test", spl_memtest }, + { "gpio", " - Set GPIO #PIN to STATE 0 or 1", spl_gpio }, { "boot", " - Load stage2 USB bootloader", spl_boot }, { NULL, NULL, NULL } }; @@ -51,6 +54,40 @@ static int spl_memtest(int argc, char *argv[]) { return spl_load_stage1(); // TODO } +static int spl_gpio(int argc, char *argv[]) { + if(argc != 3 || (strcmp(argv[2], "0") && strcmp(argv[2], "1"))) { + printf("Usage: %s \n", argv[0]); + printf(" STATE := 0 | 1\n"); + + return -1; + } + + char *old_debugops = strdup(cfg_getenv("DEBUGOPS")), + *old_pinnum = strdup(cfg_getenv("PINNUM")); + + cfg_setenv("DEBUGOPS", (!strcmp(argv[2], "1")) ? + SPL_DEBUG_GPIO_SET : SPL_DEBUG_GPIO_CLEAR); + cfg_setenv("PINNUM", argv[1]); + + int ret = 0; + + ret = shell_execute("rebuildcfg"); + + if(ret == -1) + goto finally; + + ret = spl_load_stage1(); + +finally: + cfg_setenv("DEBUGOPS", old_debugops); + cfg_setenv("PINNUM", old_pinnum); + + free(old_debugops); + free(old_pinnum); + + return ret; +} + static int spl_boot(int argc, char *argv[]) { if(argc != 1) { printf("Usage: %s\n", argv[0]);