mips32: add fastdata loader working area
[fw/openocd] / src / target / mips_m4k.c
index c0adc066e81d7c9ad7f6093ebbeaf2978fde5659..8afee9cd66a7a19aab138a21c27c1052430acd5a 100644 (file)
@@ -964,7 +964,6 @@ static int mips_m4k_bulk_write_memory(struct target *target, uint32_t address,
 {
        struct mips32_common *mips32 = target_to_mips32(target);
        struct mips_ejtag *ejtag_info = &mips32->ejtag_info;
-       struct working_area *source;
        int retval;
        int write_t = 1;
 
@@ -980,12 +979,23 @@ static int mips_m4k_bulk_write_memory(struct target *target, uint32_t address,
        if (address & 0x3u)
                return ERROR_TARGET_UNALIGNED_ACCESS;
 
-       /* Get memory for block write handler */
-       retval = target_alloc_working_area(target, MIPS32_FASTDATA_HANDLER_SIZE, &source);
-       if (retval != ERROR_OK)
+       if (mips32->fast_data_area == NULL)
        {
-               LOG_WARNING("No working area available, falling back to non-bulk write");
-               return mips_m4k_write_memory(target, address, 4, count, buffer);
+               /* Get memory for block write handler
+                * we preserve this area between calls and gain a speed increase
+                * of about 3kb/sec when writing flash
+                * this will be released/nulled by the system when the target is resumed or reset */
+               retval = target_alloc_working_area(target,
+                               MIPS32_FASTDATA_HANDLER_SIZE,
+                               &mips32->fast_data_area);
+               if (retval != ERROR_OK)
+               {
+                       LOG_WARNING("No working area available, falling back to non-bulk write");
+                       return mips_m4k_write_memory(target, address, 4, count, buffer);
+               }
+
+               /* reset fastadata state so the algo get reloaded */
+               ejtag_info->fast_access_save = -1;
        }
 
        /* TAP data register is loaded LSB first (little endian) */
@@ -999,7 +1009,7 @@ static int mips_m4k_bulk_write_memory(struct target *target, uint32_t address,
                }
        }
 
-       retval = mips32_pracc_fastdata_xfer(ejtag_info, source, write_t, address,
+       retval = mips32_pracc_fastdata_xfer(ejtag_info, mips32->fast_data_area, write_t, address,
                        count, (uint32_t*) (void *)buffer);
        if (retval != ERROR_OK)
        {
@@ -1008,9 +1018,6 @@ static int mips_m4k_bulk_write_memory(struct target *target, uint32_t address,
                retval = mips_m4k_write_memory(target, address, 4, count, buffer);
        }
 
-       if (source)
-               target_free_working_area(target, source);
-
        return retval;
 }