Fix usage of timeval_ms()
[openocd.git] / src / flash / nor / aduc702x.c
index dce6a5e4e5762ff72169c927ef5e57757cb53009..34cc362eba7444233a5ea3c3560264c67025eb92 100644 (file)
@@ -14,9 +14,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 <http://www.gnu.org/licenses/>. *
  ***************************************************************************/
 
 #ifdef HAVE_CONFIG_H
@@ -43,21 +41,12 @@ static int aduc702x_set_write_enable(struct target *target, int enable);
 #define ADUC702x_FLASH_FEEPRO           (6*4)
 #define ADUC702x_FLASH_FEEHIDE          (7*4)
 
-struct aduc702x_flash_bank {
-       struct working_area *write_algorithm;
-};
-
 /* flash bank aduc702x 0 0 0 0 <target#>
  * The ADC7019-28 devices all have the same flash layout */
 FLASH_BANK_COMMAND_HANDLER(aduc702x_flash_bank_command)
 {
-       struct aduc702x_flash_bank *nbank;
-
-       nbank = malloc(sizeof(struct aduc702x_flash_bank));
-
        bank->base = 0x80000;
        bank->size = 0xF800;    /* top 4k not accessible */
-       bank->driver_priv = nbank;
 
        aduc702x_build_sector_list(bank);
 
@@ -153,13 +142,13 @@ static int aduc702x_protect(struct flash_bank *bank, int set, int first, int las
  * Caller should not check for other return values specifically
  */
 static int aduc702x_write_block(struct flash_bank *bank,
-       uint8_t *buffer,
+       const uint8_t *buffer,
        uint32_t offset,
        uint32_t count)
 {
-       struct aduc702x_flash_bank *aduc702x_info = bank->driver_priv;
        struct target *target = bank->target;
        uint32_t buffer_size = 7000;
+       struct working_area *write_algorithm;
        struct working_area *source;
        uint32_t address = bank->base + offset;
        struct reg_param reg_params[6];
@@ -210,13 +199,15 @@ static int aduc702x_write_block(struct flash_bank *bank,
 
        /* flash write code */
        if (target_alloc_working_area(target, sizeof(aduc702x_flash_write_code),
-                       &aduc702x_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, aduc702x_info->write_algorithm->address,
-                       sizeof(aduc702x_flash_write_code), (uint8_t *)aduc702x_flash_write_code);
+       uint8_t code[sizeof(aduc702x_flash_write_code)];
+       target_buffer_set_u32_array(target, code, ARRAY_SIZE(aduc702x_flash_write_code),
+                       aduc702x_flash_write_code);
+       retval = target_write_buffer(target, write_algorithm->address, sizeof(code), code);
        if (retval != ERROR_OK)
                return retval;
 
@@ -224,10 +215,9 @@ static int aduc702x_write_block(struct flash_bank *bank,
        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 buffer,
+                       /* we already allocated the writing code, but failed to get a buffer,
                         *free the algorithm */
-                       if (aduc702x_info->write_algorithm)
-                               target_free_working_area(target, aduc702x_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;
@@ -257,8 +247,8 @@ static int aduc702x_write_block(struct flash_bank *bank,
                buf_set_u32(reg_params[4].value, 0, 32, 0xFFFFF800);
 
                retval = target_run_algorithm(target, 0, NULL, 5,
-                               reg_params, aduc702x_info->write_algorithm->address,
-                               aduc702x_info->write_algorithm->address +
+                               reg_params, write_algorithm->address,
+                               write_algorithm->address +
                                sizeof(aduc702x_flash_write_code) - 4,
                                10000, &arm_algo);
                if (retval != ERROR_OK) {
@@ -279,7 +269,7 @@ static int aduc702x_write_block(struct flash_bank *bank,
        }
 
        target_free_working_area(target, source);
-       target_free_working_area(target, aduc702x_info->write_algorithm);
+       target_free_working_area(target, write_algorithm);
 
        destroy_reg_param(&reg_params[0]);
        destroy_reg_param(&reg_params[1]);
@@ -293,7 +283,7 @@ static int aduc702x_write_block(struct flash_bank *bank,
 /* All-JTAG, single-access method.  Very slow.  Used only if there is no
  * working area available. */
 static int aduc702x_write_single(struct flash_bank *bank,
-       uint8_t *buffer,
+       const uint8_t *buffer,
        uint32_t offset,
        uint32_t count)
 {
@@ -334,7 +324,7 @@ static int aduc702x_write_single(struct flash_bank *bank,
        return ERROR_OK;
 }
 
-static int aduc702x_write(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t count)
+static int aduc702x_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
 {
        int retval;
 
@@ -362,12 +352,6 @@ static int aduc702x_probe(struct flash_bank *bank)
        return ERROR_OK;
 }
 
-static int aduc702x_info(struct flash_bank *bank, char *buf, int buf_size)
-{
-       snprintf(buf, buf_size, "aduc702x flash driver info");
-       return ERROR_OK;
-}
-
 /* sets FEEMOD bit 3
  * enable = 1 enables writes & erases, 0 disables them */
 static int aduc702x_set_write_enable(struct target *target, int enable)
@@ -387,7 +371,7 @@ static int aduc702x_check_flash_completion(struct target *target, unsigned int t
 {
        uint8_t v = 4;
 
-       long long endtime = timeval_ms() + timeout_ms;
+       int64_t endtime = timeval_ms() + timeout_ms;
        while (1) {
                target_read_u8(target, ADUC702x_FLASH + ADUC702x_FLASH_FEESTA, &v);
                if ((v & 4) == 0)
@@ -417,5 +401,4 @@ struct flash_driver aduc702x_flash = {
        .auto_probe = aduc702x_probe,
        .erase_check = default_flash_blank_check,
        .protect_check = aduc702x_protect_check,
-       .info = aduc702x_info
 };

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)