This is an automated email from Gerrit.

"Name of user not set <de...@thom.fr.eu.org>" just uploaded a new patch set to 
Gerrit, which you can find at https://review.openocd.org/c/openocd/+/7564

-- gerrit

commit 94fde8ba9ebcbb906513438b4e63bace5a7e7a8c
Author: François LEGAL <de...@thom.fr.eu.org>
Date:   Wed Mar 29 17:46:38 2023 +0200

    src/target/mips_m4k : add fast read method
    
    Add the fast read method to speed up flash verification
    after programming. Works the same as fast write already
    implemented.
    
    Signed-off-by: François LEGAL <de...@thom.fr.eu.org>
    Change-Id: I74611a3542a88212f0483ec8ee368aba3d1f03c7

diff --git a/src/target/mips_m4k.c b/src/target/mips_m4k.c
index d3b07585dd..cd6c03dc4f 100644
--- a/src/target/mips_m4k.c
+++ b/src/target/mips_m4k.c
@@ -1021,6 +1021,12 @@ static int mips_m4k_read_memory(struct target *target, 
target_addr_t address,
        if (((size == 4) && (address & 0x3u)) || ((size == 2) && (address & 
0x1u)))
                return ERROR_TARGET_UNALIGNED_ACCESS;
 
+       if (size == 4 && count > 32) {
+               int retval = mips_m4k_bulk_read_memory(target, address, count, 
buffer);
+               if (retval == ERROR_OK)
+                       return ERROR_OK;
+               LOG_WARNING("Falling back to non-bulk write");
+       }
        /* since we don't know if buffer is aligned, we allocate new mem that 
is always aligned */
        void *t = NULL;
 
@@ -1249,6 +1255,72 @@ static int mips_m4k_bulk_write_memory(struct target 
*target, target_addr_t addre
        return retval;
 }
 
+static int mips_m4k_bulk_read_memory(struct target *target, target_addr_t 
address,
+               uint32_t count, const uint8_t *buffer)
+{
+       struct mips32_common *mips32 = target_to_mips32(target);
+       struct mips_ejtag *ejtag_info = &mips32->ejtag_info;
+       struct working_area *fast_data_area;
+       int retval;
+       int write_t = 0;
+
+       LOG_DEBUG("address: " TARGET_ADDR_FMT ", count: 0x%8.8" PRIx32 "",
+                       address, count);
+
+       /* check alignment */
+       if (address & 0x3u)
+               return ERROR_TARGET_UNALIGNED_ACCESS;
+
+       if (!mips32->fast_data_area) {
+               /* 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_ERROR("No working area available");
+                       return retval;
+               }
+
+               /* reset fastadata state so the algo get reloaded */
+               ejtag_info->fast_access_save = -1;
+       }
+
+       fast_data_area = mips32->fast_data_area;
+
+       if (address < (fast_data_area->address + fast_data_area->size) &&
+                       fast_data_area->address < (address + count)) {
+               LOG_ERROR("fast_data (" TARGET_ADDR_FMT ") is within write area 
"
+                               "(" TARGET_ADDR_FMT "-" TARGET_ADDR_FMT ").",
+                               fast_data_area->address, address, address + 
count);
+               LOG_ERROR("Change work-area-phys or load_image address!");
+               return ERROR_FAIL;
+       }
+
+       /* mips32_pracc_fastdata_xfer requires uint32_t in host endianness, */
+       /* but byte array represents target endianness                      */
+       uint32_t *t = NULL;
+       t = malloc(count * sizeof(uint32_t));
+       if (!t) {
+               LOG_ERROR("Out of memory");
+               return ERROR_FAIL;
+       }
+
+       retval = mips32_pracc_fastdata_xfer(ejtag_info, mips32->fast_data_area, 
write_t, address,
+                       count, t);
+
+       target_buffer_get_u32_array(target, (uint8_t *)t, count, (uint32_t 
*)buffer);
+
+       free(t);
+
+       if (retval != ERROR_OK)
+               LOG_ERROR("Fastdata access Failed");
+
+       return retval;
+}
+
 static int mips_m4k_verify_pointer(struct command_invocation *cmd,
                struct mips_m4k_common *mips_m4k)
 {

-- 

Reply via email to