OpenOCD
dsp5680xx_flash.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 /***************************************************************************
4  * Copyright (C) 2011 by Rodrigo L. Rosa *
5  * rodrigorosa.LG@gmail.com *
6  * *
7  * Based on a file written by: *
8  * Kevin McGuire *
9  * Marcel Wijlaars *
10  * Michael Ashton *
11  ***************************************************************************/
12 
25 #ifdef HAVE_CONFIG_H
26 #include "config.h"
27 #endif
28 
29 #include "imp.h"
30 #include <helper/binarybuffer.h>
31 #include <helper/time_support.h>
32 #include <target/algorithm.h>
33 #include <target/dsp5680xx.h>
34 
36 {
37  bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
38 
39  for (unsigned int i = 0; i < bank->num_sectors; ++i) {
40  bank->sectors[i].offset = i * HFM_SECTOR_SIZE;
41  bank->sectors[i].size = HFM_SECTOR_SIZE;
42  bank->sectors[i].is_erased = -1;
43  bank->sectors[i].is_protected = -1;
44  }
45  LOG_USER("%s not tested yet.", __func__);
46  return ERROR_OK;
47 
48 }
49 
50 /* flash bank dsp5680xx 0 0 0 0 <target#> */
51 FLASH_BANK_COMMAND_HANDLER(dsp5680xx_flash_bank_command)
52 {
53  bank->base = HFM_FLASH_BASE_ADDR;
54  bank->size = HFM_SIZE_BYTES; /* top 4k not accessible */
55  bank->num_sectors = HFM_SECTOR_COUNT;
57 
58  return ERROR_OK;
59 }
60 
71 {
72  int retval = ERROR_OK;
73 
74  uint16_t protected = 0;
75 
76  retval = dsp5680xx_f_protect_check(bank->target, &protected);
77  if (retval != ERROR_OK) {
78  for (int i = 0; i < HFM_SECTOR_COUNT; i++)
79  bank->sectors[i].is_protected = -1;
80  return ERROR_OK;
81  }
82  for (int i = 0; i < HFM_SECTOR_COUNT / 2; i++) {
83  if (protected & 1) {
84  bank->sectors[2 * i].is_protected = 1;
85  bank->sectors[2 * i + 1].is_protected = 1;
86  } else {
87  bank->sectors[2 * i].is_protected = 0;
88  bank->sectors[2 * i + 1].is_protected = 0;
89  }
90  protected = (protected >> 1);
91  }
92  return retval;
93 }
94 
108 static int dsp5680xx_flash_protect(struct flash_bank *bank, int set,
109  unsigned int first, unsigned int last)
110 {
115  int retval;
116 
117  if (set)
118  retval = dsp5680xx_f_lock(bank->target);
119  else
120  retval = dsp5680xx_f_unlock(bank->target);
121 
122  return retval;
123 }
124 
136 static int dsp5680xx_flash_write(struct flash_bank *bank, const uint8_t *buffer,
137  uint32_t offset, uint32_t count)
138 {
139  if ((offset + count / 2) > bank->size) {
140  LOG_ERROR("%s: Flash bank cannot fit data.", __func__);
141  return ERROR_FAIL;
142  }
143  if (offset % 2) {
149  LOG_ERROR("%s: Writing to odd addresses not supported for this target", __func__);
150  return ERROR_FAIL;
151  }
152  return dsp5680xx_f_wr(bank->target, buffer, bank->base + offset / 2, count, 0);
153 }
154 
155 static int dsp5680xx_probe(struct flash_bank *bank)
156 {
157  LOG_DEBUG("%s not implemented", __func__);
158  return ERROR_OK;
159 }
160 
174 static int dsp5680xx_flash_erase(struct flash_bank *bank, unsigned int first,
175  unsigned int last)
176 {
177  return dsp5680xx_f_erase(bank->target, (uint32_t) first, (uint32_t) last);
178 }
179 
189 {
190  int retval = ERROR_OK;
191 
192  uint8_t erased = 0;
193 
194  uint32_t i;
195 
196  for (i = 0; i < HFM_SECTOR_COUNT; i++) {
197  retval = dsp5680xx_f_erase_check(bank->target, &erased, i);
198  if (retval != ERROR_OK) {
199  bank->sectors[i].is_erased = -1;
200  } else {
201  if (erased)
202  bank->sectors[i].is_erased = 1;
203  else
204  bank->sectors[i].is_erased = 0;
205  }
206  }
207  return retval;
208 }
209 
210 const struct flash_driver dsp5680xx_flash = {
211  .name = "dsp5680xx_flash",
212  .flash_bank_command = dsp5680xx_flash_bank_command,
213  .erase = dsp5680xx_flash_erase,
214  .protect = dsp5680xx_flash_protect,
215  .write = dsp5680xx_flash_write,
216  /* .read = default_flash_read, */
217  .probe = dsp5680xx_probe,
218  .auto_probe = dsp5680xx_probe,
219  .erase_check = dsp5680xx_flash_erase_check,
220  .protect_check = dsp5680xx_flash_protect_check,
221 };
Support functions to access arbitrary bits in a byte array.
int dsp5680xx_f_erase(struct target *target, int first, int last)
Erases either a sector or the complete flash array.
Definition: dsp5680xx.c:1862
int dsp5680xx_f_lock(struct target *target)
Writes the flash security words with a specific value.
Definition: dsp5680xx.c:2196
int dsp5680xx_f_unlock(struct target *target)
Executes a mass erase command.
Definition: dsp5680xx.c:2095
int dsp5680xx_f_wr(struct target *t, const uint8_t *b, uint32_t a, uint32_t count, int is_flash_lock)
Writes to flash memory.
Definition: dsp5680xx.c:1956
int dsp5680xx_f_protect_check(struct target *target, uint16_t *protected)
Reads the memory mapped protection register.
Definition: dsp5680xx.c:1572
int dsp5680xx_f_erase_check(struct target *target, uint8_t *erased, uint32_t sector)
The FM has the functionality of checking if the flash array is erased.
Definition: dsp5680xx.c:1799
Basic support for the 5680xx DSP from Freescale. The chip has two taps in the JTAG chain,...
#define HFM_SIZE_BYTES
Definition: dsp5680xx.h:194
#define HFM_SECTOR_SIZE
Definition: dsp5680xx.h:196
#define HFM_FLASH_BASE_ADDR
Definition: dsp5680xx.h:193
#define HFM_SECTOR_COUNT
Definition: dsp5680xx.h:197
static int dsp5680xx_flash_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
The dsp5680xx use word addressing.
static int dsp5680xx_probe(struct flash_bank *bank)
static int dsp5680xx_flash_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
The flash module (FM) on the dsp5680xx supports both individual sector and mass erase of the flash me...
FLASH_BANK_COMMAND_HANDLER(dsp5680xx_flash_bank_command)
const struct flash_driver dsp5680xx_flash
static int dsp5680xx_flash_protect(struct flash_bank *bank, int set, unsigned int first, unsigned int last)
Protection functionality is not implemented.
static int dsp5680xx_flash_erase_check(struct flash_bank *bank)
The flash module (FM) on the dsp5680xx support a blank check function.
static int dsp5680xx_flash_protect_check(struct flash_bank *bank)
A memory mapped register (PROT) holds information regarding sector protection.
static int dsp5680xx_build_sector_list(struct flash_bank *bank)
uint8_t bank
Definition: esirisc.c:135
#define LOG_USER(expr ...)
Definition: log.h:126
#define ERROR_FAIL
Definition: log.h:161
#define LOG_ERROR(expr ...)
Definition: log.h:123
#define LOG_DEBUG(expr ...)
Definition: log.h:109
#define ERROR_OK
Definition: log.h:155
Provides details of a flash bank, available either on-chip or through a major interface.
Definition: nor/core.h:75
Provides the implementation-independent structure that defines all of the callbacks required by OpenO...
Definition: nor/driver.h:39
const char * name
Gives a human-readable name of this flash driver, This field is used to select and initialize the dri...
Definition: nor/driver.h:44
Describes the geometry and status of a single flash sector within a flash bank.
Definition: nor/core.h:28
uint8_t offset[4]
Definition: vdebug.c:9
uint8_t count[4]
Definition: vdebug.c:22