Freddie Chopin <freddie_chopin@op.pl> move files about to where they belong
[openocd.git] / src / flash / pic32mx.c
index 3fa79e5287f318d18e7c23592d50f4bb2d144a1e..2a5ce64186a2ce2e512236d73868288b8d5ce20d 100644 (file)
 #include "config.h"
 #endif
 
-#include "replacements.h"
-
 #include "pic32mx.h"
-#include "flash.h"
-#include "target.h"
-#include "log.h"
 #include "mips32.h"
-#include "algorithm.h"
-#include "binarybuffer.h"
 
-#include <stdlib.h>
-#include <string.h>
 
 static
 struct pic32mx_devs_s {
@@ -463,9 +454,10 @@ static int pic32mx_write_block(struct flash_bank_s *bank, u8 *buffer, u32 offset
 
        while(count > 0)
        {
-               u32 status;
+               u32 value;
+               memcpy(&value, buffer, sizeof(u32));
 
-               status = pic32mx_write_word(bank, address, *(u32*)buffer);
+               u32 status = pic32mx_write_word(bank, address, value);
                if( status & NVMCON_NVMERR ) {
                        LOG_ERROR("Flash write error NVMERR (status=0x%08x)", status);
                        retval = ERROR_FLASH_OPERATION_FAILED;
@@ -526,7 +518,7 @@ static int pic32mx_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32
        u32 address = bank->base + offset;
        u32 bytes_written = 0;
        u32 status;
-       u32 retval;
+       int retval;
 
        if (bank->target->state != TARGET_HALTED)
        {
@@ -568,8 +560,10 @@ static int pic32mx_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32
 
        while (words_remaining > 0)
        {
-               status = pic32mx_write_word(bank, address, *(u32*)(buffer + bytes_written));
+               u32 value;
+               memcpy(&value, buffer + bytes_written, sizeof(u32));
 
+               status = pic32mx_write_word(bank, address, value);
                if( status & NVMCON_NVMERR )
                        return ERROR_FLASH_OPERATION_FAILED;
                if( status & NVMCON_LVDERR )
@@ -582,19 +576,10 @@ static int pic32mx_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32
 
        if (bytes_remaining)
        {
-               u8 last_word[4] = {0xff, 0xff, 0xff, 0xff};
-               int i = 0;
-
-               while(bytes_remaining > 0)
-               {
-                       /* Assumes little endian */
-                       last_word[i++] = *(buffer + bytes_written);
-                       bytes_remaining--;
-                       bytes_written++;
-               }
-
-               status = pic32mx_write_word(bank, address, *(u32*)last_word);
+               u32 value = 0xffffffff;
+               memcpy(&value, buffer + bytes_written, bytes_remaining);
 
+               status = pic32mx_write_word(bank, address, value);
                if( status & NVMCON_NVMERR )
                        return ERROR_FLASH_OPERATION_FAILED;
                if( status & NVMCON_LVDERR )
@@ -611,7 +596,7 @@ static int pic32mx_probe(struct flash_bank_s *bank)
        mips32_common_t *mips32 = target->arch_info;
        mips_ejtag_t *ejtag_info = &mips32->ejtag_info;
        int i;
-       u16 num_pages;
+       u16 num_pages = 0;
        u32 device_id;
        int page_size;
 
@@ -704,7 +689,7 @@ static int pic32mx_info(struct flash_bank_s *bank, char *buf, int buf_size)
        mips32_common_t *mips32 = target->arch_info;
        mips_ejtag_t *ejtag_info = &mips32->ejtag_info;
        u32 device_id;
-       int printed, i;
+       int printed = 0, i;
 
        device_id = ejtag_info->idcode;
 

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)