src/ingenic.c |
34 | 34 | #define CPUID(id) ((id) & 0xFFFF) |
35 | 35 | #define CMDSET(id) (((id) & 0xFFFF0000) >> 16) |
36 | 36 | |
37 | | #define CFGOPT(name, var, exp) { char *str = cfg_getenv(name); if(str == NULL) { debug(LEVEL_ERROR, "%s is not set\n", name); errno = EINVAL; return -1; }; int v = atoi(str); if(!(exp)) { debug(LEVEL_ERROR, "%s must be in %s\n", name, #exp); return -1; }; handle->cfg.var = v; } |
| 37 | #define CFGOPT(name, var, exp) { \ |
| 38 | char *str = cfg_getenv(name); \ |
| 39 | if(str == NULL) { \ |
| 40 | debug(LEVEL_ERROR, "%s is not set\n", name); errno = EINVAL; return -1; }; \ |
| 41 | int v = atoi(str); \ |
| 42 | if(!(exp)) { debug(LEVEL_ERROR, "%s must be in %s\n", name, #exp); return -1; }; \ |
| 43 | var = v; \ |
| 44 | } |
38 | 45 | |
39 | | #define NOPT(name, var, exp) { char *str = cfg_getenv("NAND_" name); if(str == NULL) { debug(LEVEL_ERROR, "%s is not set\n", "NAND_" name); errno = EINVAL; return -1; }; int v = atoi(str); if(!(exp)) { debug(LEVEL_ERROR, "%s must be in %s\n", "NAND_" name, #exp); return -1; }; handle->nand.nand_##var = v; } |
| 46 | #define NOPT(name, var, exp) { \ |
| 47 | char *str = cfg_getenv("NAND_" name); \ |
| 48 | if(str == NULL) { debug(LEVEL_ERROR, "%s is not set\n", "NAND_" name); errno = EINVAL; return -1; }; \ |
| 49 | int v = atoi(str); \ |
| 50 | if(!(exp)) { debug(LEVEL_ERROR, "%s must be in %s\n", "NAND_" name, #exp); return -1; }; \ |
| 51 | var = v; \ |
| 52 | } |
40 | 53 | |
41 | 54 | #define CALLBACK(function, ...) if(handle->callbacks && handle->callbacks->function) handle->callbacks->function(__VA_ARGS__, handle->callbacks_data) |
42 | 55 | |
... | ... | |
144 | 157 | |
145 | 158 | int ingenic_rebuild(void *hndl) { |
146 | 159 | HANDLE; |
| 160 | unsigned int cpu_speed; /* the uint8_t in handle structure won't do for values > 255 */ |
147 | 161 | |
148 | 162 | handle->cfg.cpu_id = CPUID(handle->type); |
149 | 163 | |
150 | | CFGOPT("EXTCLK", ext_clk, v <= 27 && v >= 12); |
| 164 | CFGOPT("EXTCLK", handle->cfg.ext_clk, v <= 27 && v >= 12); |
151 | 165 | CFGOPT("CPUSPEED", cpu_speed, (v % 12) == 0); |
152 | | handle->cfg.cpu_speed /= handle->cfg.ext_clk; |
153 | | CFGOPT("PHMDIV", phm_div, v <= 32 && v >= 2); |
154 | | CFGOPT("USEUART", use_uart, 1); |
155 | | CFGOPT("BAUDRATE", baudrate, 1); |
| 166 | handle->cfg.cpu_speed = cpu_speed / handle->cfg.ext_clk; |
| 167 | CFGOPT("PHMDIV", handle->cfg.phm_div, v <= 32 && v >= 2); |
| 168 | CFGOPT("USEUART", handle->cfg.use_uart, 1); |
| 169 | CFGOPT("BAUDRATE", handle->cfg.baudrate, 1); |
156 | 170 | |
157 | | CFGOPT("SDRAM_BUSWIDTH", bus_width, (v == 16) || (v == 32)); |
| 171 | CFGOPT("SDRAM_BUSWIDTH", handle->cfg.bus_width, (v == 16) || (v == 32)); |
158 | 172 | handle->cfg.bus_width = handle->cfg.bus_width == 16 ? 1 : 0; |
159 | | CFGOPT("SDRAM_BANKS", bank_num, (v >= 4) && ((v % 4) == 0)); |
| 173 | CFGOPT("SDRAM_BANKS", handle->cfg.bank_num, (v >= 4) && ((v % 4) == 0)); |
160 | 174 | handle->cfg.bank_num /= 4; |
161 | | CFGOPT("SDRAM_ROWADDR", row_addr, 1); |
162 | | CFGOPT("SDRAM_COLADDR", col_addr, 1); |
163 | | CFGOPT("SDRAM_ISMOBILE", is_mobile, v == 0 || v == 1); |
164 | | CFGOPT("SDRAM_ISBUSSHARE", is_busshare, v == 0 || v == 1); |
| 175 | CFGOPT("SDRAM_ROWADDR", handle->cfg.row_addr, 1); |
| 176 | CFGOPT("SDRAM_COLADDR", handle->cfg.col_addr, 1); |
| 177 | CFGOPT("SDRAM_ISMOBILE", handle->cfg.is_mobile, v == 0 || v == 1); |
| 178 | CFGOPT("SDRAM_ISBUSSHARE", handle->cfg.is_busshare, v == 0 || v == 1); |
165 | 179 | |
166 | 180 | memset(&handle->cfg.debug, 0, sizeof(ingenic_stage1_debug_t)); |
167 | 181 | |
... | ... | |
172 | 186 | |
173 | 187 | handle->nand.cpuid = CPUID(handle->type); |
174 | 188 | |
175 | | NOPT("BUSWIDTH", bw, 1); |
176 | | NOPT("ROWCYCLES", rc, 1); |
177 | | NOPT("PAGESIZE", ps, 1); |
178 | | NOPT("PAGEPERBLOCK", ppb, 1); |
179 | | NOPT("FORCEERASE", force_erase, 1); |
| 189 | NOPT("BUSWIDTH", handle->nand.nand_bw, 1); |
| 190 | NOPT("ROWCYCLES", handle->nand.nand_rc, 1); |
| 191 | NOPT("PAGESIZE", handle->nand.nand_ps, 1); |
| 192 | NOPT("PAGEPERBLOCK", handle->nand.nand_ppb, 1); |
| 193 | NOPT("FORCEERASE", handle->nand.nand_force_erase, 1); |
180 | 194 | // FIXME: pn is not set by xburst-tools usbboot. Is this intended? |
181 | | NOPT("OOBSIZE", os, 1); |
182 | | NOPT("ECCPOS", eccpos, 1); |
183 | | NOPT("BADBLOCKPOS", bbpos, 1); |
184 | | NOPT("BADBLOCKPAGE", bbpage, 1); |
185 | | NOPT("PLANENUM", plane, 1); |
186 | | NOPT("BCHBIT", bchbit, 1); |
187 | | NOPT("WPPIN", wppin, 1); |
188 | | NOPT("BLOCKPERCHIP", bpc, 1); |
| 195 | NOPT("OOBSIZE", handle->nand.nand_os, 1); |
| 196 | NOPT("ECCPOS", handle->nand.nand_eccpos, 1); |
| 197 | NOPT("BADBLOCKPOS", handle->nand.nand_bbpos, 1); |
| 198 | NOPT("BADBLOCKPAGE", handle->nand.nand_bbpage, 1); |
| 199 | NOPT("PLANENUM", handle->nand.nand_plane, 1); |
| 200 | NOPT("BCHBIT", handle->nand.nand_bchbit, 1); |
| 201 | NOPT("WPPIN", handle->nand.nand_wppin, 1); |
| 202 | NOPT("BLOCKPERCHIP", handle->nand.nand_bpc, 1); |
189 | 203 | |
190 | 204 | return 0; |
191 | 205 | } |