From 0cd84000daab056dea61eb9d60cca538a3716acd Mon Sep 17 00:00:00 2001 From: Spencer Oliver Date: Tue, 4 Jan 2011 12:29:49 +0000 Subject: [PATCH] mips32: add fastdata loader working area Add a working area that is preserved between calls to mips_m4k_bulk_write_memory - this gives us a speed increase of approx 3kb/sec during flash writes to the pic32mx. This area is released during a resume/reset. Signed-off-by: Spencer Oliver --- src/target/mips32.c | 1 + src/target/mips32.h | 3 +++ src/target/mips32_pracc.c | 7 ++++++- src/target/mips_ejtag.c | 1 + src/target/mips_ejtag.h | 1 + src/target/mips_m4k.c | 27 +++++++++++++++++---------- 6 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/target/mips32.c b/src/target/mips32.c index 533701aa..e48a040c 100644 --- a/src/target/mips32.c +++ b/src/target/mips32.c @@ -309,6 +309,7 @@ int mips32_init_arch_info(struct target *target, struct mips32_common *mips32, s { target->arch_info = mips32; mips32->common_magic = MIPS32_COMMON_MAGIC; + mips32->fast_data_area = NULL; /* has breakpoint/watchpint unit been scanned */ mips32->bp_scanned = 0; diff --git a/src/target/mips32.h b/src/target/mips32.h index 7ffe95fc..0d544a40 100644 --- a/src/target/mips32.h +++ b/src/target/mips32.h @@ -57,6 +57,9 @@ struct mips32_common uint32_t core_regs[MIPS32NUMCOREREGS]; enum mips32_isa_mode isa_mode; + /* working area for fastdata access */ + struct working_area *fast_data_area; + int bp_scanned; int num_inst_bpoints; int num_data_bpoints; diff --git a/src/target/mips32_pracc.c b/src/target/mips32_pracc.c index 236f3894..a4ea2d36 100644 --- a/src/target/mips32_pracc.c +++ b/src/target/mips32_pracc.c @@ -985,7 +985,12 @@ int mips32_pracc_fastdata_xfer(struct mips_ejtag *ejtag_info, struct working_are } /* write program into RAM */ - mips32_pracc_write_mem32(ejtag_info, source->address, ARRAY_SIZE(handler_code), handler_code); + if (write_t != ejtag_info->fast_access_save) + { + mips32_pracc_write_mem32(ejtag_info, source->address, ARRAY_SIZE(handler_code), handler_code); + /* save previous operation to speed to any consecutive read/writes */ + ejtag_info->fast_access_save = write_t; + } LOG_DEBUG("%s using 0x%.8" PRIx32 " for write handler", __func__, source->address); diff --git a/src/target/mips_ejtag.c b/src/target/mips_ejtag.c index 33507b55..e3810639 100644 --- a/src/target/mips_ejtag.c +++ b/src/target/mips_ejtag.c @@ -300,6 +300,7 @@ int mips_ejtag_init(struct mips_ejtag *ejtag_info) /* set initial state for ejtag control reg */ ejtag_info->ejtag_ctrl = EJTAG_CTRL_ROCC | EJTAG_CTRL_PRACC | EJTAG_CTRL_PROBEN | EJTAG_CTRL_SETDEV; + ejtag_info->fast_access_save = -1; return ERROR_OK; } diff --git a/src/target/mips_ejtag.h b/src/target/mips_ejtag.h index a4430b6e..0db0504a 100644 --- a/src/target/mips_ejtag.h +++ b/src/target/mips_ejtag.h @@ -128,6 +128,7 @@ struct mips_ejtag uint32_t impcode; uint32_t idcode; uint32_t ejtag_ctrl; + int fast_access_save; }; int mips_ejtag_set_instr(struct mips_ejtag *ejtag_info, diff --git a/src/target/mips_m4k.c b/src/target/mips_m4k.c index c0adc066..8afee9cd 100644 --- a/src/target/mips_m4k.c +++ b/src/target/mips_m4k.c @@ -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; } -- 2.39.5