]> git.sur5r.net Git - openocd/blobdiff - src/flash/mflash.c
Eliminate MixedCaps symbol from public JTAG TAP API:
[openocd] / src / flash / mflash.c
index b5c7d46ba912171649bec9ef59eec0b88005d231..2587b6b5f931f42fcd49ccaf68457a5b1912f37a 100644 (file)
@@ -345,7 +345,7 @@ static int mg_dsk_drv_info(void)
        if (! mflash_bank->drv_info)
                mflash_bank->drv_info = malloc(sizeof(mg_drv_info_t));
 
-       target->type->read_memory(target, mg_buff, 2, sizeof(mg_io_type_drv_info) >> 1,
+       target_read_memory(target, mg_buff, 2, sizeof(mg_io_type_drv_info) >> 1,
                        (u8 *)&mflash_bank->drv_info->drv_id);
 
        mflash_bank->drv_info->tot_sects = (u32)(mflash_bank->drv_info->drv_id.total_user_addressable_sectors_hi << 16)
@@ -428,7 +428,7 @@ static int mg_mflash_do_read_sects(void *buff, u32 sect_num, u32 sect_cnt)
        for (i = 0; i < sect_cnt; i++) {
                mg_dsk_wait(mg_io_wait_drq, MG_OEM_DISK_WAIT_TIME_NORMAL);
 
-               target->type->read_memory(target, address, 2, MG_MFLASH_SECTOR_SIZE / 2, buff_ptr);
+               target_read_memory(target, address, 2, MG_MFLASH_SECTOR_SIZE / 2, buff_ptr);
                buff_ptr += MG_MFLASH_SECTOR_SIZE;
 
                target_write_u8(target, mflash_bank->base + MG_REG_OFFSET + MG_REG_COMMAND, mg_io_cmd_confirm_read);
@@ -494,7 +494,7 @@ static int mg_mflash_do_write_sects(void *buff, u32 sect_num, u32 sect_cnt,
                if (ret != ERROR_OK)
                        LOG_ERROR("mg_io_wait_drq time out");
 
-               ret = target->type->write_memory(target, address, 2, MG_MFLASH_SECTOR_SIZE / 2, buff_ptr);
+               ret = target_write_memory(target, address, 2, MG_MFLASH_SECTOR_SIZE / 2, buff_ptr);
                if (ret != ERROR_OK)
                        LOG_ERROR("mem write error");
                buff_ptr += MG_MFLASH_SECTOR_SIZE;
@@ -670,13 +670,11 @@ static int mg_mflash_write(u32 addr, u8 *buff, u32 len)
 
 static int mg_write_cmd(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
 {
-       u32 address, buf_cnt;
+       u32 address, buf_cnt, cnt, res, i;
        u8 *buffer;
-       /* TODO : multi-bank support, large file support */
        fileio_t fileio;
        duration_t duration;
        char *duration_text;
-       int ret;
 
        if (argc != 3) {
                return ERROR_COMMAND_SYNTAX_ERROR;
@@ -688,18 +686,32 @@ static int mg_write_cmd(struct command_context_s *cmd_ctx, char *cmd, char **arg
                return ERROR_FAIL;
        }
 
-       buffer = malloc(fileio.size);
-
-       if (fileio_read(&fileio, fileio.size, buffer, &buf_cnt) != ERROR_OK)
-       {
-               free(buffer);
+       buffer = malloc(MG_FILEIO_CHUNK);
+       if (!buffer) {
                fileio_close(&fileio);
                return ERROR_FAIL;
        }
 
+       cnt = fileio.size / MG_FILEIO_CHUNK;
+       res = fileio.size % MG_FILEIO_CHUNK;
+
        duration_start_measure(&duration);
 
-       ret = mg_mflash_write(address, buffer, (u32)fileio.size);
+       for (i = 0; i < cnt; i++) {
+               if (fileio_read(&fileio, MG_FILEIO_CHUNK, buffer, &buf_cnt) !=
+                               ERROR_OK)
+                       goto mg_write_cmd_err;
+               if (mg_mflash_write(address, buffer, MG_FILEIO_CHUNK) != ERROR_OK)
+                       goto mg_write_cmd_err;
+               address += MG_FILEIO_CHUNK;
+       }
+       if (res) {
+               if (fileio_read(&fileio, res, buffer, &buf_cnt) != ERROR_OK)
+                       goto mg_write_cmd_err;                  
+               if (mg_mflash_write(address, buffer, res) != ERROR_OK)
+                       goto mg_write_cmd_err;
+       }
 
        duration_stop_measure(&duration, &duration_text);
 
@@ -708,19 +720,24 @@ static int mg_write_cmd(struct command_context_s *cmd_ctx, char *cmd, char **arg
                (float)fileio.size / 1024.0 / ((float)duration.duration.tv_sec + ((float)duration.duration.tv_usec / 1000000.0)));
 
        free(duration_text);
-
-       fileio_close(&fileio);
-
        free(buffer);
+       fileio_close(&fileio);
 
        return ERROR_OK;
+
+mg_write_cmd_err:
+       duration_stop_measure(&duration, &duration_text);
+       free(duration_text);
+       free(buffer);
+       fileio_close(&fileio);
+
+       return ERROR_FAIL;
 }
 
 static int mg_dump_cmd(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
 {
-       u32 address, size_written, size;
+       u32 address, size_written, size, cnt, res, i;
        u8 *buffer;
-       /* TODO : multi-bank support */
        fileio_t fileio;
        duration_t duration;
        char *duration_text;
@@ -735,30 +752,54 @@ static int mg_dump_cmd(struct command_context_s *cmd_ctx, char *cmd, char **args
        if (fileio_open(&fileio, args[1], FILEIO_WRITE, FILEIO_BINARY) != ERROR_OK) {
                return ERROR_FAIL;
        }
+       buffer = malloc(MG_FILEIO_CHUNK);
+       if (!buffer) {
+               fileio_close(&fileio);
+               return ERROR_FAIL;
+       }
 
-       buffer = malloc(size);
-
+       cnt = size / MG_FILEIO_CHUNK;
+       res = size % MG_FILEIO_CHUNK;
        duration_start_measure(&duration);
 
-       mg_mflash_read(address, buffer, size);
+       for (i = 0; i < cnt; i++) {
+               if (mg_mflash_read(address, buffer, MG_FILEIO_CHUNK) != ERROR_OK)
+                       goto mg_dump_cmd_err;
+               if (fileio_write(&fileio, MG_FILEIO_CHUNK, buffer, &size_written)
+                               != ERROR_OK)
+                       goto mg_dump_cmd_err;
+               address += MG_FILEIO_CHUNK;
+       }
+       if (res) {
+               if (mg_mflash_read(address, buffer, res) != ERROR_OK)
+                       goto mg_dump_cmd_err;
+               if (fileio_write(&fileio, res, buffer, &size_written) != ERROR_OK)
+                       goto mg_dump_cmd_err;
+       }
 
        duration_stop_measure(&duration, &duration_text);
 
-       fileio_write(&fileio, size, buffer, &size_written);
-
        command_print(cmd_ctx, "dump image (address 0x%8.8x size %u) to file %s in %s (%f kB/s)",
                                address, size, args[1], duration_text,
                                (float)size / 1024.0 / ((float)duration.duration.tv_sec + ((float)duration.duration.tv_usec / 1000000.0)));
 
        free(duration_text);
-
-       fileio_close(&fileio);
-
        free(buffer);
+       fileio_close(&fileio);
 
        return ERROR_OK;
-}
 
+mg_dump_cmd_err:
+       duration_stop_measure(&duration, &duration_text);
+       free(duration_text);
+       free(buffer);
+       fileio_close(&fileio);
+       return ERROR_FAIL;      
+}
 
 static int mg_set_feature(mg_feature_id feature, mg_feature_val config)
 {
@@ -886,12 +927,12 @@ static int mg_verify_interface(void)
                for (i = 0; i < MG_MFLASH_SECTOR_SIZE >> 1; i++)
                        buff[i] = i;
 
-               target->type->write_memory(target, address, 2,
+               target_write_memory(target, address, 2,
                                MG_MFLASH_SECTOR_SIZE / 2, (u8 *)buff);
 
                memset(buff, 0xff, MG_MFLASH_SECTOR_SIZE);
 
-               target->type->read_memory(target, address, 2,
+               target_read_memory(target, address, 2,
                                MG_MFLASH_SECTOR_SIZE / 2, (u8 *)buff);
 
                for (i = 0; i < MG_MFLASH_SECTOR_SIZE >> 1; i++) {
@@ -1085,8 +1126,9 @@ static int mg_set_pll(mg_pll_t *pll)
        u8 buff[512];
 
        memset(buff, 0xff, 512);
-       *((u32 *)&buff[0]) = pll->lock_cyc;     /* PLL Lock cycle */
-       *((u16 *)&buff[4]) = pll->feedback_div; /* PLL Feedback 9bit Divider */
+       /* PLL Lock cycle and Feedback 9bit Divider */
+       memcpy(buff, &pll->lock_cyc, sizeof(u32));
+       memcpy(buff + 4, &pll->feedback_div, sizeof(u16));
        buff[6] = pll->input_div;               /* PLL Input 5bit Divider */
        buff[7] = pll->output_div;              /* PLL Output Divider */