Date:2011-05-22 15:43:58 (12 years 10 months ago)
Author:Ignacio Garcia Perez
Commit:1cfb149d351c6e20bfa387de4dafdbc81cd5df11
Message:FIXED: values of CPUSPEED greater than 255 were misread because the value was directly read into handle->cfg.cpu_speed (uint8_t) before dividing it by the external crystal frequency, and overflow resulted. Now intermediate variable is used and only the final result of the division is placed in handle->cfg.cpu_speed.

Files: src/ingenic.c (3 diffs)

Change Details

src/ingenic.c
3434#define CPUID(id) ((id) & 0xFFFF)
3535#define CMDSET(id) (((id) & 0xFFFF0000) >> 16)
3636
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    }
3845
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}
4053
4154#define CALLBACK(function, ...) if(handle->callbacks && handle->callbacks->function) handle->callbacks->function(__VA_ARGS__, handle->callbacks_data)
4255
...... 
144157
145158int ingenic_rebuild(void *hndl) {
146159    HANDLE;
160    unsigned int cpu_speed; /* the uint8_t in handle structure won't do for values > 255 */
147161
148162    handle->cfg.cpu_id = CPUID(handle->type);
149163
150    CFGOPT("EXTCLK", ext_clk, v <= 27 && v >= 12);
164    CFGOPT("EXTCLK", handle->cfg.ext_clk, v <= 27 && v >= 12);
151165    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);
156170
157    CFGOPT("SDRAM_BUSWIDTH", bus_width, (v == 16) || (v == 32));
171    CFGOPT("SDRAM_BUSWIDTH", handle->cfg.bus_width, (v == 16) || (v == 32));
158172    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));
160174    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);
165179
166180    memset(&handle->cfg.debug, 0, sizeof(ingenic_stage1_debug_t));
167181
...... 
172186
173187    handle->nand.cpuid = CPUID(handle->type);
174188
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);
180194// 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);
189203
190204    return 0;
191205}

Archive Download the corresponding diff file



interactive