Root/usbboot/src/ingenic_cfg.c

1/*
2 * Copyright(C) 2009 Qi Hardware Inc.,
3 * Authors: Marek Lindner <lindner_marek@yahoo.de>
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 <errno.h>
20#include <confuse.h>
21#include <unistd.h>
22#include <string.h>
23#include "ingenic_cfg.h"
24#include "usb_boot_defines.h"
25
26extern unsigned int total_size;
27
28int hand_init_def(struct hand *hand)
29{
30    /* nand flash info */
31    /* hand.nand_start=0; */ /* important !!!! */
32    hand->pt = JZ4740; /* cpu type */
33    hand->nand_bw = 8;
34    hand->nand_rc = 3;
35    hand->nand_ps = 2048;
36    hand->nand_os = 64;
37    hand->nand_ppb = 64;
38    hand->nand_eccpos = 6;
39    hand->nand_bbpage = 0;
40    hand->nand_bbpos = 0;
41    hand->nand_force_erase = 0;
42    /* hand.nand_ids=0; */ /* vendor_id & device_id */
43    hand->fw_args.cpu_id = 0x4740;
44    hand->fw_args.ext_clk = 12;
45    hand->fw_args.cpu_speed = 225 / hand->fw_args.ext_clk;
46    hand->fw_args.phm_div = 3;
47    hand->fw_args.use_uart = 0;
48    hand->fw_args.boudrate = 57600;
49    hand->fw_args.bus_width = 0;
50    hand->fw_args.bank_num = 1;
51    hand->fw_args.row_addr = 13;
52    hand->fw_args.col_addr = 9;
53    hand->fw_args.is_mobile = 0;
54    hand->fw_args.is_busshare = 1;
55
56    return 1;
57}
58
59int check_dump_cfg(struct hand *hand)
60{
61    printf("Now checking whether all configure args valid:");
62    /* check PLL */
63    if (hand->fw_args.ext_clk > 27 || hand->fw_args.ext_clk < 12) {
64        printf(" EXTCLK setting invalid!\n");
65        return 0;
66    }
67    if (hand->fw_args.phm_div > 32 || hand->fw_args.ext_clk < 2) {
68        printf(" PHMDIV setting invalid!\n");
69        return 0;
70    }
71    if ((hand->fw_args.cpu_speed * hand->fw_args.ext_clk ) % 12 != 0) {
72        printf(" CPUSPEED setting invalid!\n");
73        return 0;
74    }
75
76    /* check SDRAM */
77    if (hand->fw_args.bus_width > 1 ) {
78        printf(" SDRAMWIDTH setting invalid!\n");
79        return 0;
80    }
81    if (hand->fw_args.bank_num > 1 ) {
82        printf(" BANKNUM setting invalid!\n");
83        return 0;
84    }
85    if (hand->fw_args.row_addr > 13 && hand->fw_args.row_addr < 11 ) {
86        printf(" ROWADDR setting invalid!\n");
87        return 0;
88    }
89    if (hand->fw_args.col_addr > 13 && hand->fw_args.col_addr < 11 ) {
90        printf(" COLADDR setting invalid!\n");
91        return 0;
92    }
93
94    /* check NAND */
95    if ( hand->nand_ps < 2048 && hand->nand_os > 16 ) {
96        printf(" PAGESIZE or OOBSIZE setting invalid!\n");
97        printf(" PAGESIZE is %d,\t OOBSIZE is %d\n",
98               hand->nand_ps, hand->nand_os);
99        return 0;
100    }
101    if ( hand->nand_ps < 2048 && hand->nand_ppb > 32 ) {
102        printf(" PAGESIZE or PAGEPERBLOCK setting invalid!\n");
103        return 0;
104    }
105
106    if ( hand->nand_ps > 512 && hand->nand_os <= 16 ) {
107        printf(" PAGESIZE or OOBSIZE setting invalid!\n");
108        printf(" PAGESIZE is %d,\t OOBSIZE is %d\n",
109               hand->nand_ps, hand->nand_os);
110        return 0;
111    }
112    if ( hand->nand_ps > 512 && hand->nand_ppb < 64 ) {
113        printf(" PAGESIZE or PAGEPERBLOCK setting invalid!\n");
114        return 0;
115    }
116    printf(" YES\n");
117
118    printf("Current device information:\n");
119    printf("CPU type is Ingenic XBurst Jz%x\n",hand->fw_args.cpu_id);
120    printf("Crystal work at %dMHz, the CCLK up to %dMHz and PMH_CLK up to %dMHz\n",
121        hand->fw_args.ext_clk,
122        (unsigned int)hand->fw_args.cpu_speed * hand->fw_args.ext_clk,
123        ((unsigned int)hand->fw_args.cpu_speed * hand->fw_args.ext_clk) / hand->fw_args.phm_div);
124
125    printf("SDRAM Total size is %d MB, work in %d bank and %d bit mode\n",
126        total_size / 0x100000, 2 * (hand->fw_args.bank_num + 1),
127           16 * (2 - hand->fw_args.bus_width));
128
129    printf("Nand page per block %d, "
130           "Nand page size %d, "
131           "ECC offset in OOB %d, "
132           "bad block offset in OOB %d, "
133           "bad block page %d, "
134           "use %d plane mode\n",
135           hand->nand_ppb,
136           hand->nand_ps,
137           hand->nand_eccpos,
138           hand->nand_bbpos,
139           hand->nand_bbpage,
140           hand->nand_plane);
141    return 1;
142}
143
144int parse_configure(struct hand *hand, char * file_path)
145{
146    long cpu_speed;
147    if (access(file_path, F_OK)) {
148        fprintf(stderr, "Error - can't read configure file %s.\n",
149            file_path);
150        return -1;
151    }
152
153
154    hand_init_def(hand);
155
156    cfg_opt_t opts[] = {
157        CFG_INT("BOUDRATE", 57600, CFGF_NONE),
158        CFG_INT("EXTCLK", 0, CFGF_NONE),
159        CFG_INT("CPUSPEED", 0, CFGF_NONE),
160        CFG_INT("PHMDIV", 0, CFGF_NONE),
161        CFG_INT("USEUART", 0, CFGF_NONE),
162
163        CFG_INT("BUSWIDTH", 0, CFGF_NONE),
164        CFG_INT("BANKS", 0, CFGF_NONE),
165        CFG_INT("ROWADDR", 0, CFGF_NONE),
166        CFG_INT("COLADDR", 0, CFGF_NONE),
167
168        CFG_INT("ISMOBILE", 0, CFGF_NONE),
169        CFG_INT("ISBUSSHARE", 0, CFGF_NONE),
170        CFG_INT("DEBUGOPS", 0, CFGF_NONE),
171        CFG_INT("PINNUM", 0, CFGF_NONE),
172        CFG_INT("START", 0, CFGF_NONE),
173        CFG_INT("SIZE", 0, CFGF_NONE),
174
175        CFG_INT("NAND_BUSWIDTH", 0, CFGF_NONE),
176        CFG_INT("NAND_ROWCYCLES", 0, CFGF_NONE),
177        CFG_INT("NAND_PAGESIZE", 0, CFGF_NONE),
178        CFG_INT("NAND_PAGEPERBLOCK", 0, CFGF_NONE),
179        CFG_INT("NAND_FORCEERASE", 0, CFGF_NONE),
180        CFG_INT("NAND_OOBSIZE", 0, CFGF_NONE),
181        CFG_INT("NAND_ECCPOS", 0, CFGF_NONE),
182        CFG_INT("NAND_BADBLOCKPOS", 0, CFGF_NONE),
183        CFG_INT("NAND_BADBLOCKPAGE", 0, CFGF_NONE),
184        CFG_INT("NAND_PLANENUM", 0, CFGF_NONE),
185        CFG_INT("NAND_BCHBIT", 0, CFGF_NONE),
186        CFG_INT("NAND_WPPIN", 0, CFGF_NONE),
187        CFG_INT("NAND_BLOCKPERCHIP", 0, CFGF_NONE),
188
189        CFG_END()
190    };
191
192    cfg_t *cfg;
193    cfg = cfg_init(opts, 0);
194    if (cfg_parse(cfg, file_path) == CFG_PARSE_ERROR)
195        return -1;
196
197    hand->fw_args.boudrate = cfg_getint(cfg, "BOUDRATE");
198    hand->fw_args.ext_clk = cfg_getint(cfg, "EXTCLK");
199    cpu_speed = cfg_getint(cfg, "CPUSPEED");
200    hand->fw_args.phm_div = cfg_getint(cfg, "PHMDIV");
201    hand->fw_args.use_uart = cfg_getint(cfg, "USEUART");
202
203    hand->fw_args.bus_width = cfg_getint(cfg, "BUSWIDTH");
204    hand->fw_args.bank_num = cfg_getint(cfg, "BANKS");
205    hand->fw_args.row_addr = cfg_getint(cfg, "ROWADDR");
206    hand->fw_args.col_addr = cfg_getint(cfg, "COLADDR");
207
208    hand->fw_args.is_mobile = cfg_getint(cfg, "ISMOBILE");
209    hand->fw_args.is_busshare = cfg_getint(cfg, "ISBUSSHARE");
210    hand->fw_args.debug_ops = cfg_getint(cfg, "DEBUGOPS");
211    hand->fw_args.pin_num = cfg_getint(cfg, "PINNUM");
212    hand->fw_args.start = cfg_getint(cfg, "START");
213    hand->fw_args.size = cfg_getint(cfg, "SIZE");
214
215    hand->nand_bw = cfg_getint(cfg, "NAND_BUSWIDTH");
216    hand->nand_rc = cfg_getint(cfg, "NAND_ROWCYCLES");
217    hand->nand_ps = cfg_getint(cfg, "NAND_PAGESIZE");
218    hand->nand_ppb = cfg_getint(cfg, "NAND_PAGEPERBLOCK");
219    hand->nand_force_erase = cfg_getint(cfg, "NAND_FORCEERASE");
220    hand->nand_os = cfg_getint(cfg, "NAND_OOBSIZE");
221    hand->nand_eccpos = cfg_getint(cfg, "NAND_ECCPOS");
222    hand->nand_bbpos = cfg_getint(cfg, "NAND_BADBLOCKPOS");
223    hand->nand_bbpage = cfg_getint(cfg, "NAND_BADBLOCKPAGE");
224    hand->nand_plane = cfg_getint(cfg, "NAND_PLANENUM");
225    hand->nand_bchbit = cfg_getint(cfg, "NAND_BCHBIT");
226    hand->nand_wppin = cfg_getint(cfg, "NAND_WPPIN");
227    hand->nand_bpc = cfg_getint(cfg, "NAND_BLOCKPERCHIP");
228
229    cfg_free(cfg);
230
231    hand->fw_args.cpu_id = 0x4740;
232    if (hand->fw_args.bus_width == 32)
233        hand->fw_args.bus_width = 0;
234    else
235        hand->fw_args.bus_width = 1;
236    hand->fw_args.bank_num = hand->fw_args.bank_num / 4;
237    hand->fw_args.cpu_speed = cpu_speed / hand->fw_args.ext_clk;
238
239    total_size = (unsigned int)
240        (2 << (hand->fw_args.row_addr + hand->fw_args.col_addr - 1)) * 2
241        * (hand->fw_args.bank_num + 1) * 2
242        * (2 - hand->fw_args.bus_width);
243
244    if (check_dump_cfg(hand) < 1)
245        return -1;
246
247    return 0;
248}
249

Archive Download this file



interactive