summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/debug_menu.c58
1 files changed, 56 insertions, 2 deletions
diff --git a/apps/debug_menu.c b/apps/debug_menu.c
index 7fa7103210..eadd6030aa 100644
--- a/apps/debug_menu.c
+++ b/apps/debug_menu.c
@@ -188,6 +188,43 @@ bool dbg_mpeg_thread(void)
188} 188}
189#endif 189#endif
190 190
191
192/* Tool function to calculate a CRC16 across some buffer */
193unsigned short crc_16(unsigned char* buf, unsigned len)
194{
195 static const unsigned short crc16_lookup[16] =
196 { /* lookup table for 4 bits at a time is affordable */
197 0x0000, 0x1021, 0x2042, 0x3063,
198 0x4084, 0x50A5, 0x60C6, 0x70E7,
199 0x8108, 0x9129, 0xA14A, 0xB16B,
200 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF
201 };
202 unsigned short crc16 = 0xFFFF; /* initialise to 0xFFFF (CCITT specification) */
203 unsigned t;
204 unsigned char byte;
205
206 while (len--)
207 {
208 byte = *buf++; /* get one byte of data */
209
210 /* upper nibble of our data */
211 t = crc16 >> 12; /* extract the 4 most significant bits */
212 t ^= byte >> 4; /* XOR in 4 bits of the data into the extracted bits */
213 crc16 <<= 4; /* shift the CRC Register left 4 bits */
214 crc16 ^= crc16_lookup[t]; /* do the table lookup and XOR the result */
215
216 /* lower nibble of our data */
217 t = crc16 >> 12; /* extract the 4 most significant bits */
218 t ^= byte & 0x0F; /* XOR in 4 bits of the data into the extracted bits */
219 crc16 <<= 4; /* shift the CRC Register left 4 bits */
220 crc16 ^= crc16_lookup[t]; /* do the table lookup and XOR the result */
221 }
222
223 return crc16;
224}
225
226
227
191/* Tool function to read the flash manufacturer and type, if available. 228/* Tool function to read the flash manufacturer and type, if available.
192 Only chips which could be reprogrammed in system will return values. 229 Only chips which could be reprogrammed in system will return values.
193 (The mode switch addresses vary between flash manufacturers, hence addr1/2) */ 230 (The mode switch addresses vary between flash manufacturers, hence addr1/2) */
@@ -235,6 +272,7 @@ bool dbg_hw_info(void)
235 int rom_version = *(unsigned short*)0x20000fe; 272 int rom_version = *(unsigned short*)0x20000fe;
236 unsigned manu, id; /* flash IDs */ 273 unsigned manu, id; /* flash IDs */
237 bool got_id; /* flag if we managed to get the flash IDs */ 274 bool got_id; /* flag if we managed to get the flash IDs */
275 unsigned rom_crc; /* CRC16 of the boot ROM */
238 276
239 if(PADR & 0x400) 277 if(PADR & 0x400)
240 usb_polarity = 0; /* Negative */ 278 usb_polarity = 0; /* Negative */
@@ -251,6 +289,9 @@ bool dbg_hw_info(void)
251 if (!got_id) 289 if (!got_id)
252 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */ 290 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
253 291
292 /* calculate CRC16 checksum of boot ROM */
293 rom_crc = crc_16((unsigned char*)0x0000, 64*1024);
294
254 lcd_setmargins(0, 0); 295 lcd_setmargins(0, 0);
255 lcd_setfont(FONT_SYSFIXED); 296 lcd_setfont(FONT_SYSFIXED);
256 lcd_clear_display(); 297 lcd_clear_display();
@@ -277,6 +318,13 @@ bool dbg_hw_info(void)
277 else 318 else
278 snprintf(buf, 32, "Flash: M=?? D=??"); /* unknown, sorry */ 319 snprintf(buf, 32, "Flash: M=?? D=??"); /* unknown, sorry */
279 lcd_puts(0, 6, buf); 320 lcd_puts(0, 6, buf);
321
322 snprintf(buf, 32-3, "ROM CRC: 0x%04x", rom_crc);
323 if (rom_crc == 0x222F) /* Version 1 */
324 strcat(buf, " V1");
325 else if (rom_crc == 0x8C1E) /* Version 2 */
326 strcat(buf, " V2");
327 lcd_puts(0, 7, buf);
280 328
281 lcd_update(); 329 lcd_update();
282 330
@@ -300,6 +348,7 @@ bool dbg_hw_info(void)
300 int rom_version = *(unsigned short*)0x20000fe; 348 int rom_version = *(unsigned short*)0x20000fe;
301 unsigned manu, id; /* flash IDs */ 349 unsigned manu, id; /* flash IDs */
302 bool got_id; /* flag if we managed to get the flash IDs */ 350 bool got_id; /* flag if we managed to get the flash IDs */
351 unsigned rom_crc; /* CRC16 of the boot ROM */
303 352
304 if(PADR & 0x400) 353 if(PADR & 0x400)
305 usb_polarity = 0; /* Negative */ 354 usb_polarity = 0; /* Negative */
@@ -311,6 +360,9 @@ bool dbg_hw_info(void)
311 if (!got_id) 360 if (!got_id)
312 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */ 361 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
313 362
363 /* calculate CRC16 checksum of boot ROM */
364 rom_crc = crc_16((unsigned char*)0x0000, 64*1024);
365
314 lcd_clear_display(); 366 lcd_clear_display();
315 367
316 lcd_puts(0, 0, "[HW Info]"); 368 lcd_puts(0, 0, "[HW Info]");
@@ -338,6 +390,8 @@ bool dbg_hw_info(void)
338 else 390 else
339 snprintf(buf, 32, "Flash:??,??"); /* unknown, sorry */ 391 snprintf(buf, 32, "Flash:??,??"); /* unknown, sorry */
340 break; 392 break;
393 case 5:
394 snprintf(buf, 32, "ROM CRC:%04x", rom_crc);
341 } 395 }
342 396
343 lcd_puts(0, 1, buf); 397 lcd_puts(0, 1, buf);
@@ -353,12 +407,12 @@ bool dbg_hw_info(void)
353 case BUTTON_LEFT: 407 case BUTTON_LEFT:
354 currval--; 408 currval--;
355 if(currval < 0) 409 if(currval < 0)
356 currval = 4; 410 currval = 5;
357 break; 411 break;
358 412
359 case BUTTON_RIGHT: 413 case BUTTON_RIGHT:
360 currval++; 414 currval++;
361 if(currval > 4) 415 if(currval > 5)
362 currval = 0; 416 currval = 0;
363 break; 417 break;
364 } 418 }