X-Git-Url: https://review.openocd.org/gitweb?p=openocd.git;a=blobdiff_plain;f=src%2Fflash%2Fnor%2Fem357.c;h=b14e0323c7916e272f66c073a07351d3d930d8b9;hp=7c697f13efa53e33ecfedf7b41d358915d0b1298;hb=463257903e61947c942df3fc79519bb49074dd10;hpb=9f0cba528a163645c8ecace413731c23310f2c26 diff --git a/src/flash/nor/em357.c b/src/flash/nor/em357.c index 7c697f13ef..b14e0323c7 100644 --- a/src/flash/nor/em357.c +++ b/src/flash/nor/em357.c @@ -19,9 +19,7 @@ * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + * along with this program. If not, see . * ***************************************************************************/ #ifdef HAVE_CONFIG_H @@ -88,7 +86,6 @@ struct em357_options { struct em357_flash_bank { struct em357_options option_bytes; - struct working_area *write_algorithm; int ppage_size; int probed; }; @@ -107,7 +104,6 @@ FLASH_BANK_COMMAND_HANDLER(em357_flash_bank_command) em357_info = malloc(sizeof(struct em357_flash_bank)); bank->driver_priv = em357_info; - em357_info->write_algorithm = NULL; em357_info->probed = 0; return ERROR_OK; @@ -360,6 +356,9 @@ static int em357_erase(struct flash_bank *bank, int first, int last) if ((first == 0) && (last == (bank->num_sectors - 1))) return em357_mass_erase(bank); + /* Enable FPEC clock */ + target_write_u32(target, EM357_FPEC_CLK, 0x00000001); + /* unlock flash registers */ int retval = target_write_u32(target, EM357_FLASH_KEYR, KEY1); if (retval != ERROR_OK) @@ -454,12 +453,12 @@ static int em357_protect(struct flash_bank *bank, int set, int first, int last) return em357_write_options(bank); } -static int em357_write_block(struct flash_bank *bank, uint8_t *buffer, +static int em357_write_block(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count) { - struct em357_flash_bank *em357_info = bank->driver_priv; struct target *target = bank->target; uint32_t buffer_size = 16384; + struct working_area *write_algorithm; struct working_area *source; uint32_t address = bank->base + offset; struct reg_param reg_params[4]; @@ -497,14 +496,13 @@ static int em357_write_block(struct flash_bank *bank, uint8_t *buffer, /* flash write code */ if (target_alloc_working_area(target, sizeof(em357_flash_write_code), - &em357_info->write_algorithm) != ERROR_OK) { + &write_algorithm) != ERROR_OK) { LOG_WARNING("no working area available, can't do block memory writes"); return ERROR_TARGET_RESOURCE_NOT_AVAILABLE; } - ; - retval = target_write_buffer(target, em357_info->write_algorithm->address, - sizeof(em357_flash_write_code), (uint8_t *)em357_flash_write_code); + retval = target_write_buffer(target, write_algorithm->address, + sizeof(em357_flash_write_code), em357_flash_write_code); if (retval != ERROR_OK) return retval; @@ -512,20 +510,18 @@ static int em357_write_block(struct flash_bank *bank, uint8_t *buffer, while (target_alloc_working_area_try(target, buffer_size, &source) != ERROR_OK) { buffer_size /= 2; if (buffer_size <= 256) { - /* if we already allocated the writing code, but failed to get a + /* we already allocated the writing code, but failed to get a * buffer, free the algorithm */ - if (em357_info->write_algorithm) - target_free_working_area(target, em357_info->write_algorithm); + target_free_working_area(target, write_algorithm); LOG_WARNING( "no large enough working area available, can't do block memory writes"); return ERROR_TARGET_RESOURCE_NOT_AVAILABLE; } } - ; armv7m_info.common_magic = ARMV7M_COMMON_MAGIC; - armv7m_info.core_mode = ARMV7M_MODE_ANY; + armv7m_info.core_mode = ARM_MODE_THREAD; init_reg_param(®_params[0], "r0", 32, PARAM_OUT); init_reg_param(®_params[1], "r1", 32, PARAM_OUT); @@ -546,7 +542,7 @@ static int em357_write_block(struct flash_bank *bank, uint8_t *buffer, buf_set_u32(reg_params[3].value, 0, 32, 0); retval = target_run_algorithm(target, 0, NULL, 4, reg_params, - em357_info->write_algorithm->address, 0, 10000, &armv7m_info); + write_algorithm->address, 0, 10000, &armv7m_info); if (retval != ERROR_OK) { LOG_ERROR("error executing em357 flash write algorithm"); break; @@ -574,7 +570,7 @@ static int em357_write_block(struct flash_bank *bank, uint8_t *buffer, } target_free_working_area(target, source); - target_free_working_area(target, em357_info->write_algorithm); + target_free_working_area(target, write_algorithm); destroy_reg_param(®_params[0]); destroy_reg_param(®_params[1]); @@ -584,7 +580,7 @@ static int em357_write_block(struct flash_bank *bank, uint8_t *buffer, return retval; } -static int em357_write(struct flash_bank *bank, uint8_t *buffer, +static int em357_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count) { struct target *target = bank->target; @@ -612,6 +608,8 @@ static int em357_write(struct flash_bank *bank, uint8_t *buffer, if (retval != ERROR_OK) return retval; + target_write_u32(target, EM357_FPEC_CLK, 0x00000001); + /* multiple half words (2-byte) to be programmed? */ if (words_remaining > 0) { /* try using a block write */ @@ -683,14 +681,45 @@ static int em357_probe(struct flash_bank *bank) em357_info->probed = 0; + switch (bank->size) { + case 0x10000: + /* 64k -- 64 1k pages */ + num_pages = 64; + page_size = 1024; + break; + case 0x20000: + /* 128k -- 128 1k pages */ + num_pages = 128; + page_size = 1024; + break; + case 0x30000: + /* 192k -- 96 2k pages */ + num_pages = 96; + page_size = 2048; + break; + case 0x40000: + /* 256k -- 128 2k pages */ + num_pages = 128; + page_size = 2048; + break; + case 0x80000: + /* 512k -- 256 2k pages */ + num_pages = 256; + page_size = 2048; + break; + default: + LOG_WARNING("No size specified for em357 flash driver, assuming 192k!"); + num_pages = 96; + page_size = 2048; + break; + } + /* Enable FPEC CLK */ int retval = target_write_u32(target, EM357_FPEC_CLK, 0x00000001); if (retval != ERROR_OK) return retval; - page_size = 2048; em357_info->ppage_size = 4; - num_pages = 96; LOG_INFO("flash size = %dkbytes", num_pages*page_size/1024); @@ -724,13 +753,6 @@ static int em357_auto_probe(struct flash_bank *bank) return em357_probe(bank); } - -static int get_em357_info(struct flash_bank *bank, char *buf, int buf_size) -{ - snprintf(buf, buf_size, "em357\n"); - return ERROR_OK; -} - COMMAND_HANDLER(em357_handle_lock_command) { struct target *target = NULL; @@ -816,6 +838,9 @@ static int em357_mass_erase(struct flash_bank *bank) return ERROR_TARGET_NOT_HALTED; } + /* Make sure the flash clock is on */ + target_write_u32(target, EM357_FPEC_CLK, 0x00000001); + /* unlock option flash registers */ int retval = target_write_u32(target, EM357_FLASH_KEYR, KEY1); if (retval != ERROR_OK) @@ -914,7 +939,7 @@ struct flash_driver em357_flash = { .read = default_flash_read, .probe = em357_probe, .auto_probe = em357_auto_probe, - .erase_check = default_flash_mem_blank_check, + .erase_check = default_flash_blank_check, .protect_check = em357_protect_check, - .info = get_em357_info, + .free_driver_priv = default_flash_free_driver_priv, };