2010-12-04 03:14:23 +02:00
|
|
|
/*
|
|
|
|
* JzBoot: an USB bootloader for JZ series of Ingenic(R) microprocessors.
|
2010-12-04 03:36:25 +02:00
|
|
|
* Copyright (C) 2010 Sergey Gridassov <grindars@gmail.com>,
|
|
|
|
* Peter Zotov <whitequark@whitequark.org>
|
2010-12-04 03:14:23 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
2010-12-04 06:01:21 +02:00
|
|
|
#include <stdlib.h>
|
2010-12-04 10:16:33 +02:00
|
|
|
#include <errno.h>
|
2010-12-04 03:14:23 +02:00
|
|
|
|
|
|
|
#include "shell.h"
|
|
|
|
#include "config.h"
|
|
|
|
#include "ingenic.h"
|
|
|
|
|
2010-12-10 11:43:54 +02:00
|
|
|
static int spl_memtest(shell_context_t *ctx, int argc, char *argv[]);
|
|
|
|
static int spl_gpio(shell_context_t *ctx, int argc, char *argv[]);
|
|
|
|
static int spl_boot(shell_context_t *ctx, int argc, char *argv[]);
|
2010-12-04 03:14:23 +02:00
|
|
|
|
|
|
|
const shell_command_t spl_cmdset[] = {
|
2010-12-10 13:41:16 +02:00
|
|
|
{ "memtest", "SDRAM test", spl_memtest, "[BASE] <SIZE>" },
|
|
|
|
{ "gpio", "Set GPIO #PIN to STATE 0 or 1", spl_gpio, "<PIN> <STATE>" },
|
|
|
|
{ "boot", "Load stage2 USB bootloader", spl_boot, NULL },
|
|
|
|
{ NULL, NULL, NULL, NULL }
|
2010-12-04 03:14:23 +02:00
|
|
|
};
|
|
|
|
|
2010-12-10 11:43:54 +02:00
|
|
|
static int spl_stage1_op(shell_context_t *ctx, uint32_t op, uint32_t pin, uint32_t base, uint32_t size) {
|
2010-12-04 03:46:29 +02:00
|
|
|
if(cfg_getenv("STAGE1_FILE") == NULL) {
|
|
|
|
printf("Variable STAGE1_FILE is not set\n");
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-12-10 11:43:54 +02:00
|
|
|
int ret = ingenic_stage1_debugop(shell_device(ctx), cfg_getenv("STAGE1_FILE"), op, pin, base, size);
|
2010-12-04 09:45:49 +02:00
|
|
|
|
|
|
|
if(ret == -1)
|
|
|
|
perror("ingenic_stage1_debugop");
|
|
|
|
|
|
|
|
return ret;
|
2010-12-04 03:36:25 +02:00
|
|
|
}
|
|
|
|
|
2010-12-10 11:43:54 +02:00
|
|
|
static int spl_memtest(shell_context_t *ctx, int argc, char *argv[]) {
|
2010-12-04 10:16:33 +02:00
|
|
|
uint32_t start, size;
|
2010-12-04 06:23:33 +02:00
|
|
|
|
|
|
|
if(argc == 3) {
|
2010-12-04 10:16:33 +02:00
|
|
|
start = strtoul(argv[1], NULL, 0);
|
|
|
|
size = strtoul(argv[2], NULL, 0);
|
2010-12-04 06:23:33 +02:00
|
|
|
} else {
|
2010-12-04 10:16:33 +02:00
|
|
|
start = SDRAM_BASE;
|
2010-12-10 11:43:54 +02:00
|
|
|
size = ingenic_sdram_size(shell_device(ctx));
|
2010-12-04 03:14:23 +02:00
|
|
|
}
|
|
|
|
|
2010-12-04 10:16:33 +02:00
|
|
|
if(cfg_getenv("STAGE1_FILE") == NULL) {
|
|
|
|
printf("Variable STAGE1_FILE is not set\n");
|
2010-12-04 06:23:33 +02:00
|
|
|
|
2010-12-04 10:16:33 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2010-12-04 06:23:33 +02:00
|
|
|
|
2010-12-04 10:16:33 +02:00
|
|
|
uint32_t fail;
|
2010-12-04 06:23:33 +02:00
|
|
|
|
2010-12-10 11:43:54 +02:00
|
|
|
int ret = ingenic_memtest(shell_device(ctx), cfg_getenv("STAGE1_FILE"), start, size, &fail);
|
2010-12-04 06:23:33 +02:00
|
|
|
|
2010-12-04 10:16:33 +02:00
|
|
|
if(ret == -1) {
|
|
|
|
if(errno == EFAULT) {
|
|
|
|
printf("Memory test failed at address 0x%08X\n", fail);
|
|
|
|
} else {
|
|
|
|
perror("ingenic_memtest");
|
|
|
|
}
|
2010-12-04 06:23:33 +02:00
|
|
|
|
2010-12-04 10:16:33 +02:00
|
|
|
} else {
|
|
|
|
printf("Memory test passed\n");
|
|
|
|
}
|
2010-12-04 06:23:33 +02:00
|
|
|
|
|
|
|
return ret;
|
2010-12-04 03:36:25 +02:00
|
|
|
}
|
|
|
|
|
2010-12-10 11:43:54 +02:00
|
|
|
static int spl_gpio(shell_context_t *ctx, int argc, char *argv[]) {
|
2010-12-10 13:41:16 +02:00
|
|
|
if(strcmp(argv[2], "0") && strcmp(argv[2], "1")) {
|
2010-12-04 06:01:21 +02:00
|
|
|
printf("Usage: %s <PIN> <STATE>\n", argv[0]);
|
|
|
|
printf(" STATE := 0 | 1\n");
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-12-10 11:43:54 +02:00
|
|
|
return spl_stage1_op(ctx, !strcmp(argv[2], "1") ? STAGE1_DEBUG_GPIO_SET : STAGE1_DEBUG_GPIO_CLEAR, atoi(argv[1]), 0, 0);
|
2010-12-04 06:01:21 +02:00
|
|
|
}
|
|
|
|
|
2010-12-10 11:43:54 +02:00
|
|
|
static int spl_boot(shell_context_t *ctx, int argc, char *argv[]) {
|
|
|
|
int ret = spl_stage1_op(ctx, STAGE1_DEBUG_BOOT, 0, 0, 0);
|
2010-12-04 03:36:25 +02:00
|
|
|
|
|
|
|
if(ret == -1)
|
|
|
|
return -1;
|
|
|
|
|
2010-12-04 03:46:29 +02:00
|
|
|
if(cfg_getenv("STAGE2_FILE") == NULL) {
|
|
|
|
printf("Variable STAGE2_FILE is not set\n");
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-12-10 11:43:54 +02:00
|
|
|
ret = ingenic_loadstage(shell_device(ctx), INGENIC_STAGE2, cfg_getenv("STAGE2_FILE"));
|
2010-12-04 09:45:49 +02:00
|
|
|
|
2010-12-04 11:35:49 +02:00
|
|
|
if(ret == -1) {
|
2010-12-04 09:45:49 +02:00
|
|
|
perror("ingenic_loadstage");
|
|
|
|
|
2010-12-04 11:35:49 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-12-10 11:43:54 +02:00
|
|
|
ret = ingenic_configure_stage2(shell_device(ctx));
|
2010-12-04 11:35:49 +02:00
|
|
|
|
|
|
|
if(ret == -1)
|
|
|
|
perror("ingenic_configure_stage2");
|
|
|
|
|
2010-12-04 09:45:49 +02:00
|
|
|
return ret;
|
2010-12-04 03:14:23 +02:00
|
|
|
}
|
2010-12-04 09:45:49 +02:00
|
|
|
|