2010-12-04 05:43:15 +02:00
|
|
|
/*
|
|
|
|
* JzBoot: an USB bootloader for JZ series of Ingenic(R) microprocessors.
|
|
|
|
* Copyright (C) 2010 Peter Zotov <whitequark@whitequark.org>
|
|
|
|
*
|
|
|
|
* 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 12:17:33 +02:00
|
|
|
#include <stdlib.h>
|
2010-12-04 05:43:15 +02:00
|
|
|
|
|
|
|
#include "shell.h"
|
|
|
|
#include "config.h"
|
|
|
|
#include "ingenic.h"
|
2010-12-04 15:56:31 +02:00
|
|
|
#include "config.h"
|
2010-12-04 05:43:15 +02:00
|
|
|
|
2010-12-04 11:35:49 +02:00
|
|
|
static int usbboot_boot(int argc, char *argv[]);
|
2010-12-04 12:17:33 +02:00
|
|
|
static int usbboot_load(int argc, char *argv[]);
|
|
|
|
static int usbboot_go(int argc, char *argv[]);
|
2010-12-04 13:03:43 +02:00
|
|
|
static int usbboot_nquery(int argc, char *argv[]);
|
2010-12-04 15:16:57 +02:00
|
|
|
static int usbboot_ndump(int argc, char *argv[]);
|
2010-12-04 15:56:31 +02:00
|
|
|
static int usbboot_nerase(int argc, char *argv[]);
|
2010-12-04 11:35:49 +02:00
|
|
|
|
2010-12-04 05:43:15 +02:00
|
|
|
const shell_command_t usbboot_cmdset[] = {
|
2010-12-04 13:03:43 +02:00
|
|
|
|
2010-12-04 11:35:49 +02:00
|
|
|
{ "boot", "- Reconfigure stage2", usbboot_boot },
|
2010-12-04 12:17:33 +02:00
|
|
|
{ "load", "<FILE> <BASE> - Load file to SDRAM", usbboot_load },
|
|
|
|
{ "go", "<ADDRESS> - Jump to <ADDRESS>", usbboot_go },
|
2010-12-04 11:35:49 +02:00
|
|
|
|
2010-12-04 13:03:43 +02:00
|
|
|
{ "nquery", "<DEVICE> - Query NAND information", usbboot_nquery },
|
2010-12-04 15:16:57 +02:00
|
|
|
{ "ndump", "<DEVICE> <STARTPAGE> <PAGES> <FILE> - Dump NAND to file", usbboot_ndump },
|
|
|
|
{ "ndump_oob", "<DEVICE> <STARTPAGE> <PAGES> <FILE> - Dump NAND with OOB to file", usbboot_ndump },
|
2010-12-04 15:56:31 +02:00
|
|
|
{ "nerase", "<DEVICE> <STARTBLOCK> <BLOCKS> - Erase NAND blocks", usbboot_nerase },
|
2010-12-04 15:16:57 +02:00
|
|
|
|
2010-12-04 05:43:15 +02:00
|
|
|
{ NULL, NULL, NULL }
|
|
|
|
};
|
2010-12-04 11:35:49 +02:00
|
|
|
|
|
|
|
static int usbboot_boot(int argc, char *argv[]) {
|
|
|
|
int ret = ingenic_configure_stage2(shell_device());
|
|
|
|
|
|
|
|
if(ret == -1)
|
|
|
|
perror("ingenic_configure_stage2");
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-12-04 12:17:33 +02:00
|
|
|
static int usbboot_load(int argc, char *argv[]) {
|
|
|
|
if(argc != 3) {
|
|
|
|
printf("Usage: %s <FILE> <BASE>\n", argv[0]);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ret = ingenic_load_sdram_file(shell_device(), strtoul(argv[2], NULL, 0), argv[1]);
|
|
|
|
|
|
|
|
if(ret == -1)
|
|
|
|
perror("ingenic_load_sdram_file");
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int usbboot_go(int argc, char *argv[]) {
|
|
|
|
if(argc != 2) {
|
|
|
|
printf("Usage: %s <ADDRESS>\n", argv[0]);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ret = ingenic_go(shell_device(), strtoul(argv[1], NULL, 0));
|
|
|
|
|
|
|
|
if(ret == -1)
|
|
|
|
perror("ingenic_go");
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-12-04 13:03:43 +02:00
|
|
|
static int usbboot_nquery(int argc, char *argv[]) {
|
|
|
|
if(argc != 2) {
|
|
|
|
printf("Usage: %s <DEVICE>\n", argv[0]);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
nand_info_t info;
|
|
|
|
|
|
|
|
int ret = ingenic_query_nand(shell_device(), atoi(argv[1]), &info);
|
|
|
|
|
|
|
|
if(ret == -1) {
|
|
|
|
perror("ingenic_query_nand");
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf(
|
|
|
|
"VID: %02hhX\n"
|
|
|
|
"PID: %02hhX\n"
|
|
|
|
"Chip: %02hhX\n"
|
|
|
|
"Page: %02hhX\n"
|
|
|
|
"Plane: %02hhX\n",
|
|
|
|
info.vid, info.pid, info.chip, info.page, info.plane);
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-12-04 15:16:57 +02:00
|
|
|
static int usbboot_ndump(int argc, char *argv[]) {
|
|
|
|
if(argc != 5) {
|
|
|
|
printf("Usage: %s <DEVICE> <STARTPAGE> <PAGES> <FILE>\n", argv[0]);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int type = strcmp(argv[0], "ndump_oob") ? NO_OOB : OOB_ECC;
|
|
|
|
|
2010-12-04 15:56:31 +02:00
|
|
|
if(cfg_getenv("NAND_IGNORE_ECC"))
|
|
|
|
type |= IGNORE_ECC;
|
|
|
|
|
2010-12-04 15:16:57 +02:00
|
|
|
int ret = ingenic_dump_nand(shell_device(), atoi(argv[1]), atoi(argv[2]), atoi(argv[3]), type, argv[4]);
|
|
|
|
|
2010-12-04 15:56:31 +02:00
|
|
|
if(ret == -1)
|
2010-12-04 15:16:57 +02:00
|
|
|
perror("ingenic_dump_nand");
|
2010-12-04 15:56:31 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int usbboot_nerase(int argc, char *argv[]) {
|
|
|
|
if(argc != 4) {
|
|
|
|
printf("Usage: %s <DEVICE> <STARTBLOCK> <BLOCKS>\n", argv[0]);
|
2010-12-04 15:16:57 +02:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-12-04 15:56:31 +02:00
|
|
|
int ret = ingenic_erase_nand(shell_device(), atoi(argv[1]), atoi(argv[2]), atoi(argv[3]));
|
|
|
|
|
|
|
|
if(ret == -1)
|
|
|
|
perror("ingenic_erase_nand");
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
2010-12-04 15:16:57 +02:00
|
|
|
}
|