FreeCalypso > hg > freecalypso-sw
diff loadtools/flutil.c @ 204:61c7480b3c50
fc-loadtool: flash idcheck standalone command implemented
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Mon, 23 Dec 2013 08:49:38 +0000 |
parents | 96f56e875862 |
children | cd12d1049f91 |
line wrap: on
line diff
--- a/loadtools/flutil.c Mon Dec 23 07:26:37 2013 +0000 +++ b/loadtools/flutil.c Mon Dec 23 08:49:38 2013 +0000 @@ -147,3 +147,70 @@ } *s = '\0'; } + +flash_id_check(bank, repeat) +{ + struct flash_bank_info *bi; + struct flash_bank_desc *bd; + struct flash_idcheck *id; + int stat, fail; + uint16_t rdval; + unsigned cnt; + + bi = flash_bank_info + bank; + if (bi->idcheck_done && !repeat) + return(0); + printf("Performing flash ID check\n"); + stat = do_w16(bi->base_addr + 0xAAA, 0xAA); + if (stat) { +bad_w16: fprintf(stderr, + "unexpected response to w16 in read ID cmd sequence - aborting\n"); + return(-1); + } + stat = do_w16(bi->base_addr + 0x554, 0x55); + if (stat) + goto bad_w16; + stat = do_w16(bi->base_addr + 0xAAA, 0x90); + if (stat) + goto bad_w16; + bd = bi->bank_desc; + id = bd->idcheck_table; + fail = 0; + for (cnt = 0; cnt < bd->idcheck_num; cnt++) { + stat = do_r16(bi->base_addr + id->offset, &rdval); + if (stat) + return(stat); /* error msg already printed */ + printf("offset %02X: %04X -- ", (int)id->offset, (int)rdval); + if (rdval == id->expect_val) + printf("PASS\n"); + else { + printf("FAIL: expected %04X\n", (int)id->expect_val); + fail = 1; + break; + } + id++; + } + /* reset flash to read mode */ + stat = do_w16(bi->base_addr + 0xAAA, 0xF0); + if (stat) { + fprintf(stderr, + "unexpected response to w16 when resetting flash to read mode!\n"); + return(-1); + } + if (fail) + return(-1); + bi->idcheck_done = 1; + return(0); +} + +flashcmd_idcheck(argc, argv, bank) + char **argv; +{ + struct flash_bank_info *bi; + + if (argc > 2) { + fprintf(stderr, "error: too many arguments\n"); + return(-1); + } + return flash_id_check(bank, 1); +}