# HG changeset patch # User Michael Spacefalcon # Date 1387788578 0 # Node ID 61c7480b3c507c3c6084cf6375638213b56fab15 # Parent 99c234bf6a9b4a9139784d9f1dd8eb8b314f2e3a fc-loadtool: flash idcheck standalone command implemented diff -r 99c234bf6a9b -r 61c7480b3c50 loadtools/flutil.c --- 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); +} diff -r 99c234bf6a9b -r 61c7480b3c50 loadtools/ltflash.c --- a/loadtools/ltflash.c Mon Dec 23 07:26:37 2013 +0000 +++ b/loadtools/ltflash.c Mon Dec 23 08:49:38 2013 +0000 @@ -313,6 +313,7 @@ } extern int flashcmd_erase(); +extern int flashcmd_idcheck(); extern int flashcmd_progbin(); extern int flashcmd_program_m0(); extern int flashcmd_program_srec(); @@ -327,6 +328,7 @@ {"dump2srec", flashcmd_dump2file}, {"erase", flashcmd_erase}, {"help", flashcmd_help}, + {"idcheck", flashcmd_idcheck}, {"info", flashcmd_info}, {"program-bin", flashcmd_progbin}, {"program-m0", flashcmd_program_m0},