FreeCalypso > hg > freecalypso-sw
changeset 407:f2cc551e597f
fc-loadtool flash: beginning of Intel command set support
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Tue, 17 Jun 2014 01:39:59 +0000 |
parents | 0b8e5072abde |
children | 431023033c86 |
files | loadtools/flashops.c loadtools/flutil.c |
diffstat | 2 files changed, 87 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/loadtools/flashops.c Tue Jun 17 00:53:07 2014 +0000 +++ b/loadtools/flashops.c Tue Jun 17 01:39:59 2014 +0000 @@ -93,3 +93,90 @@ .loadagent_setbase_cmd = "AMFB", .loadagent_program_cmd = "AMFW", }; + +/* Intel flash functions */ + +intel_reset_cmd(bi) + struct flash_bank_info *bi; +{ + if (do_w16(bi->base_addr, 0xFF)) { + fprintf(stderr, + "unexpected response to w16 when resetting flash to read mode!\n"); + return(-1); + } + return(0); +} + +intel_sector_unlock(bi, sp) + struct flash_bank_info *bi; + struct sector_info *sp; +{ + int stat; + + stat = do_w16(bi->base_addr + sp->start, 0x60); + if (stat) { +bad_w16: fprintf(stderr, + "unexpected response to w16 in block unlock cmd sequence - aborting\n"); + return(-1); + } + stat = do_w16(bi->base_addr + sp->start, 0xD0); + if (stat) + goto bad_w16; + return(0); +} + +intel_sector_erase(bi, sp) + struct flash_bank_info *bi; + struct sector_info *sp; +{ + int stat; + uint16_t flstat; + time_t start_time, curtime; + + stat = intel_sector_unlock(bi, sp); + if (stat) + return(stat); /* error msg already printed */ + /* clear SR */ + stat = do_w16(bi->base_addr + sp->start, 0x50); + if (stat) { +bad_w16: fprintf(stderr, + "unexpected response to w16 in erase cmd sequence - aborting\n"); + return(-1); + } + /* send the actual block erase command */ + stat = do_w16(bi->base_addr + sp->start, 0x20); + if (stat) + goto bad_w16; + stat = do_w16(bi->base_addr + sp->start, 0xD0); + if (stat) + goto bad_w16; + /* wait for completion */ + start_time = time(0); + for (;;) { + stat = do_r16(bi->base_addr + sp->start, &flstat); + if (stat) + return(stat); /* error msg already printed */ + if (flstat & 0x80) + break; + curtime = time(0); + if (curtime >= start_time + 20) { + fprintf(stderr, "erase timeout, aborting\n"); + return(-1); + } + } + if (flstat & 0x20) { + fprintf(stderr, "block erase failed!\n"); + return(-1); + } else + return(0); +} + +struct flash_cmdset flash_cmdset_intel = { + .cmdset_name = "Intel", + .reset_cmd = intel_reset_cmd, + .status_cmd = invalid, + .unlock_sector = intel_sector_unlock, + .erase_sector = intel_sector_erase, + .loadagent_setbase_cmd = "INFB", + .loadagent_program_cmd = "INFW", +};
--- a/loadtools/flutil.c Tue Jun 17 00:53:07 2014 +0000 +++ b/loadtools/flutil.c Tue Jun 17 01:39:59 2014 +0000 @@ -79,11 +79,9 @@ case 2: bi->ops = &flash_cmdset_amd; break; -#if 0 case 3: bi->ops = &flash_cmdset_intel; break; -#endif default: fprintf(stderr, "error: command set %04X unsupported\n", cmdset_id);