Root/
Source at commit 6a1f486 created 13 years 3 months ago. By Peter Zotov, Reworked directory structure. | |
---|---|
1 | /* |
2 | * JzBoot: an USB bootloader for JZ series of Ingenic(R) microprocessors. |
3 | * Copyright (C) 2010 Peter Zotov <whitequark@whitequark.org> |
4 | * |
5 | * This program is free software: you can redistribute it and/or modify |
6 | * it under the terms of the GNU General Public License as published by |
7 | * the Free Software Foundation, either version 3 of the License, or |
8 | * (at your option) any later version. |
9 | * |
10 | * This program is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * GNU General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU General Public License |
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | */ |
18 | |
19 | #include <string.h> |
20 | #include <stdio.h> |
21 | #include <stdlib.h> |
22 | |
23 | #include "shell.h" |
24 | #include "config.h" |
25 | #include "ingenic.h" |
26 | #include "config.h" |
27 | |
28 | static int usbboot_boot(shell_context_t *ctx, int argc, char *argv[]); |
29 | static int usbboot_load(shell_context_t *ctx, int argc, char *argv[]); |
30 | static int usbboot_go(shell_context_t *ctx, int argc, char *argv[]); |
31 | static int usbboot_nquery(shell_context_t *ctx, int argc, char *argv[]); |
32 | static int usbboot_ndump(shell_context_t *ctx, int argc, char *argv[]); |
33 | static int usbboot_nerase(shell_context_t *ctx, int argc, char *argv[]); |
34 | static int usbboot_nprogram(shell_context_t *ctx, int argc, char *argv[]); |
35 | static int usbboot_nload(shell_context_t *ctx, int argc, char *argv[]); |
36 | |
37 | const shell_command_t usbboot_cmdset[] = { |
38 | |
39 | { "boot", "Reconfigure stage2", usbboot_boot, NULL }, |
40 | { "load", "Load file to SDRAM", usbboot_load, "<FILE> <BASE>" }, |
41 | { "go", "Jump to <ADDRESS>", usbboot_go, "<ADDRESS>" }, |
42 | |
43 | { "nquery", "Query NAND information", usbboot_nquery, "<DEVICE>" }, |
44 | { "ndump", "Dump NAND to file", usbboot_ndump, "<DEVICE> <STARTPAGE> <PAGES> <FILE>" }, |
45 | { "ndump_oob", "Dump NAND with OOB to file", usbboot_ndump, "<DEVICE> <STARTPAGE> <PAGES> <FILE>" }, |
46 | { "nerase", "Erase NAND blocks", usbboot_nerase, "<DEVICE> <STARTBLOCK> <BLOCKS>" }, |
47 | { "nprogram", "Program NAND from file", usbboot_nprogram, "<DEVICE> <STARTPAGE> <FILE>" }, |
48 | { "nprogram_oob", "Program NAND with OOB from file", usbboot_nprogram, "<DEVICE> <STARTPAGE> <FILE>" }, |
49 | { "nload", "Load NAND data to SDRAM", usbboot_nload, "<DEVICE> <STARTPAGE> <PAGES> <BASE>" }, |
50 | |
51 | { NULL, NULL, NULL, NULL } |
52 | }; |
53 | |
54 | static int usbboot_boot(shell_context_t *ctx, int argc, char *argv[]) { |
55 | int ret = ingenic_configure_stage2(shell_device(ctx)); |
56 | |
57 | if(ret == -1) |
58 | perror("ingenic_configure_stage2"); |
59 | |
60 | return ret; |
61 | } |
62 | |
63 | static int usbboot_load(shell_context_t *ctx, int argc, char *argv[]) { |
64 | int ret = ingenic_load_sdram_file(shell_device(ctx), strtoul(argv[2], NULL, 0), argv[1]); |
65 | |
66 | if(ret == -1) |
67 | perror("ingenic_load_sdram_file"); |
68 | |
69 | return ret; |
70 | } |
71 | |
72 | static int usbboot_go(shell_context_t *ctx, int argc, char *argv[]) { |
73 | int ret = ingenic_go(shell_device(ctx), strtoul(argv[1], NULL, 0)); |
74 | |
75 | if(ret == -1) |
76 | perror("ingenic_go"); |
77 | |
78 | return ret; |
79 | } |
80 | |
81 | static int usbboot_nquery(shell_context_t *ctx, int argc, char *argv[]) { |
82 | nand_info_t info; |
83 | |
84 | int ret = ingenic_query_nand(shell_device(ctx), atoi(argv[1]), &info); |
85 | |
86 | if(ret == -1) { |
87 | perror("ingenic_query_nand"); |
88 | |
89 | return -1; |
90 | } |
91 | |
92 | printf( |
93 | "VID: %02hhX\n" |
94 | "PID: %02hhX\n" |
95 | "Chip: %02hhX\n" |
96 | "Page: %02hhX\n" |
97 | "Plane: %02hhX\n", |
98 | info.vid, info.pid, info.chip, info.page, info.plane); |
99 | |
100 | |
101 | return 0; |
102 | } |
103 | |
104 | static int usbboot_ndump(shell_context_t *ctx, int argc, char *argv[]) { |
105 | int type = strcmp(argv[0], "ndump_oob") ? NO_OOB : OOB_ECC; |
106 | |
107 | if(cfg_getenv("NAND_RAW")) |
108 | type |= NAND_RAW; |
109 | |
110 | int ret = ingenic_dump_nand(shell_device(ctx), atoi(argv[1]), atoi(argv[2]), atoi(argv[3]), type, argv[4]); |
111 | |
112 | if(ret == -1) |
113 | perror("ingenic_dump_nand"); |
114 | |
115 | return ret; |
116 | } |
117 | |
118 | static int usbboot_nerase(shell_context_t *ctx, int argc, char *argv[]) { |
119 | int ret = ingenic_erase_nand(shell_device(ctx), atoi(argv[1]), atoi(argv[2]), atoi(argv[3])); |
120 | |
121 | if(ret == -1) |
122 | perror("ingenic_erase_nand"); |
123 | |
124 | return ret; |
125 | |
126 | } |
127 | |
128 | static int usbboot_nprogram(shell_context_t *ctx, int argc, char *argv[]) { |
129 | int type = strcmp(argv[0], "nprogram_oob") ? NO_OOB : OOB_ECC; |
130 | |
131 | if(strcmp(argv[0], "nprogram_oob") == 0) { |
132 | if(cfg_getenv("NAND_RAW")) |
133 | type = OOB_ECC; |
134 | else |
135 | type = OOB_NO_ECC; |
136 | } else |
137 | type = NO_OOB; |
138 | |
139 | int ret = ingenic_program_nand(shell_device(ctx), atoi(argv[1]), atoi(argv[2]), type, argv[3]); |
140 | |
141 | if(ret == -1) |
142 | perror("ingenic_program_nand"); |
143 | |
144 | return ret; |
145 | } |
146 | |
147 | static int usbboot_nload(shell_context_t *ctx, int argc, char *argv[]) { |
148 | int ret = ingenic_load_nand(shell_device(ctx), atoi(argv[1]), atoi(argv[2]), atoi(argv[3]), strtoul(argv[4], NULL, 0)); |
149 | |
150 | if(ret == -1) |
151 | perror("ingenic_load_nand"); |
152 | |
153 | return ret; |
154 | } |
155 |