From f4a3db0d4a353ccc6d701a2645390ef9039e0d02 Mon Sep 17 00:00:00 2001 From: "Rodrigo L. Rosa" Date: Fri, 10 Jun 2011 12:19:58 -0700 Subject: [PATCH] fix flash driver size, sector erase --- src/flash/nor/dsp5680xx_flash.c | 68 ++++++++----- src/target/dsp5680xx.c | 174 +++++++++----------------------- src/target/dsp5680xx.h | 19 ++-- 3 files changed, 98 insertions(+), 163 deletions(-) diff --git a/src/flash/nor/dsp5680xx_flash.c b/src/flash/nor/dsp5680xx_flash.c index e9c4e825d..4e7a0b610 100644 --- a/src/flash/nor/dsp5680xx_flash.c +++ b/src/flash/nor/dsp5680xx_flash.c @@ -41,17 +41,13 @@ struct dsp5680xx_flash_bank { }; static int dsp5680xx_build_sector_list(struct flash_bank *bank){ - //LOG_USER("%s not implemented",__FUNCTION__); - //return ERROR_OK; - - // sector size is 512 - // bank->num_sectors = bank->size / 512; // Bank size is actually 0x2000, but it is set much higher as part of the workaround for byte/word addressing issues. + uint32_t offset = HFM_FLASH_BASE_ADDR; bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors); int i; for (i = 0; i < bank->num_sectors; ++i){ - bank->sectors[i].offset = 0;// not implemented. + bank->sectors[i].offset = i*HFM_SECTOR_SIZE; bank->sectors[i].size = HFM_SECTOR_SIZE; - //offset += bank->sectors[i].size; + offset += bank->sectors[i].size; bank->sectors[i].is_erased = -1; bank->sectors[i].is_protected = -1; } @@ -67,9 +63,9 @@ FLASH_BANK_COMMAND_HANDLER(dsp5680xx_flash_bank_command){ nbank = malloc(sizeof(struct dsp5680xx_flash_bank)); bank->base = HFM_FLASH_BASE_ADDR; - bank->size = HFM_SIZE; // top 4k not accessible + bank->size = HFM_SIZE_BYTES; // top 4k not accessible bank->driver_priv = nbank; - bank->num_sectors = HFM_SECTOR_COUNT;// This number is anything >0. not really used. + bank->num_sectors = HFM_SECTOR_COUNT; dsp5680xx_build_sector_list(bank); return ERROR_OK; @@ -77,30 +73,40 @@ FLASH_BANK_COMMAND_HANDLER(dsp5680xx_flash_bank_command){ static int dsp5680xx_flash_protect_check(struct flash_bank *bank){ int retval = ERROR_OK; - uint8_t protected = 0; - if(bank->sectors[0].is_protected == -1){ + uint16_t protected = 0; retval = dsp5680xx_f_protect_check(bank->target,&protected); - if(retval == ERROR_OK) - if(protected) - bank->sectors[0].is_protected = 1; - else - bank->sectors[0].is_protected = 0; - else - bank->sectors[0].is_protected = -1; + if(retval != ERROR_OK){ + for(int i = 0;isectors[i].is_protected = -1; + return ERROR_OK; + } + for(int i = 0;isectors[2*i].is_protected = 1; + bank->sectors[2*i+1].is_protected = 1; + }else{ + bank->sectors[2*i].is_protected = 0; + bank->sectors[2*i+1].is_protected = 0; + } + protected = (protected >> 1); } return retval; } static int dsp5680xx_flash_protect(struct flash_bank *bank, int set, int first, int last){ + // This applies security to flash module after next reset, it does not actually apply protection (protection refers to undesired access from the core) int retval; if(set){ retval = dsp5680xx_f_lock(bank->target); - if(retval == ERROR_OK) - bank->sectors[0].is_protected = 1; + if(retval == ERROR_OK){ + for(int i = first;isectors[i].is_protected = 1; + } }else{ retval = dsp5680xx_f_unlock(bank->target); if(retval == ERROR_OK) - bank->sectors[0].is_protected = 0; + for(int i = first;isectors[i].is_protected = 0; } return retval; } @@ -167,24 +173,30 @@ static int dsp5680xx_flash_erase(struct flash_bank * bank, int first, int last){ int retval; retval = dsp5680xx_f_erase(bank->target, (uint32_t) first, (uint32_t) last); if(retval == ERROR_OK) - bank->sectors[0].is_erased = 1; + for(int i = first;i<=last;i++) + bank->sectors[i].is_erased = 1; else - bank->sectors[0].is_erased = -1; + // If an error occurred unknown status is set even though some sector could have been correctly erased. + for(int i = first;i<=last;i++) + bank->sectors[i].is_erased = -1; return retval; } static int dsp5680xx_flash_erase_check(struct flash_bank * bank){ int retval = ERROR_OK; uint8_t erased = 0; - if(bank->sectors[0].is_erased == -1){ - retval = dsp5680xx_f_erase_check(bank->target,&erased); + uint32_t i; + for(i=0;isectors[i].is_erased == -1){ + retval = dsp5680xx_f_erase_check(bank->target,&erased,i); if (retval != ERROR_OK){ - bank->sectors[0].is_erased = -1; + bank->sectors[i].is_erased = -1; }else{ if(erased) - bank->sectors[0].is_erased = 1; + bank->sectors[i].is_erased = 1; else - bank->sectors[0].is_erased = 0; + bank->sectors[i].is_erased = 0; + } } } return retval; diff --git a/src/target/dsp5680xx.c b/src/target/dsp5680xx.c index 9eba3742c..c79ee3ae3 100644 --- a/src/target/dsp5680xx.c +++ b/src/target/dsp5680xx.c @@ -244,17 +244,6 @@ static int eonce_read_status_reg(struct target * target, uint16_t * data){ return retval; } -static int dsp5680xx_obase_addr(struct target * target, uint32_t * addr){ - // Finds out the default value of the OBASE register address. - int retval; - uint32_t data_to_shift_into_dr;// just to make jtag happy - retval = eonce_instruction_exec(target,DSP5680XX_ONCE_OBASE,1,0,0,NULL); - err_check_propagate(retval); - retval = dsp5680xx_drscan(target,(uint8_t *)& data_to_shift_into_dr,(uint8_t *) addr, 8); - err_check_propagate(retval); - return retval; -} - static int dsp5680xx_halt(struct target *target){ int retval; uint8_t jtag_status; @@ -614,24 +603,15 @@ static int eonce_move_value_to_pc(struct target * target, uint32_t value) static int eonce_load_TX_RX_to_r0(struct target * target) { - uint32_t obase_addr; - int retval = dsp5680xx_obase_addr(target,& obase_addr); - err_check_propagate(retval); - retval = eonce_move_long_to_r0(target,((MC568013_EONCE_TX_RX_ADDR)+(obase_addr<<16))); + int retval; + retval = eonce_move_long_to_r0(target,((MC568013_EONCE_TX_RX_ADDR)+(MC568013_EONCE_OBASE_ADDR<<16))); return retval; } static int eonce_load_TX_RX_high_to_r0(struct target * target) { - uint32_t obase_addr; - int retval = dsp5680xx_obase_addr(target,& obase_addr); - err_check_propagate(retval); - if(!(obase_addr && 0xff)){ - LOG_USER("%s: OBASE address read as 0x%04X instead of 0xFF.",__FUNCTION__,obase_addr); - return ERROR_FAIL; - } - eonce_move_long_to_r0(target,((MC568013_EONCE_TX1_RX1_HIGH_ADDR)+(obase_addr<<16))); - err_check_propagate(retval); + int retval = 0; + retval = eonce_move_long_to_r0(target,((MC568013_EONCE_TX1_RX1_HIGH_ADDR)+(MC568013_EONCE_OBASE_ADDR<<16))); return retval; } @@ -804,11 +784,11 @@ static int dsp5680xx_write_8(struct target * target, uint32_t address, uint32_t uint16_t * data_w = (uint16_t *)data; uint32_t iter; - int counter = FLUSH_COUNT_WRITE; + int counter = FLUSH_COUNT_READ_WRITE; for(iter = 0; iter