This is an automated email from Gerrit.

Tomas Vanek ([email protected]) just uploaded a new patch set to Gerrit, which you 
can find at http://openocd.zylin.com/5752

-- gerrit

commit c92c501de9226455ae8bd2ad667bcfeee819e873
Author: Tomas Vanek <[email protected]>
Date:   Thu Jul 2 09:33:57 2020 +0200

    flash/nor/kinetis: use target_get_working_area_avail()
    
    Since e22c6484eaedd56d71 the trial/error allocation shows
    "not enough working area available(requested 2048)" message
    on klx.cfg. The message is not clear if it means a problem or not.
    
    Replace with new style allocation using target_get_working_area_avail()
    
    Change-Id: I87fe1e38248fcac29982b72aaba12217a0552f38
    Signed-off-by: Tomas Vanek <[email protected]>

diff --git a/src/flash/nor/kinetis.c b/src/flash/nor/kinetis.c
index 084e009..7cc0441 100644
--- a/src/flash/nor/kinetis.c
+++ b/src/flash/nor/kinetis.c
@@ -1250,7 +1250,7 @@ static int kinetis_write_block(struct flash_bank *bank, 
const uint8_t *buffer,
                uint32_t offset, uint32_t wcount)
 {
        struct target *target = bank->target;
-       uint32_t buffer_size = 2048;            /* Default minimum value */
+       uint32_t buffer_size;
        struct working_area *write_algorithm;
        struct working_area *source;
        struct kinetis_flash_bank *k_bank = bank->driver_priv;
@@ -1261,10 +1261,6 @@ static int kinetis_write_block(struct flash_bank *bank, 
const uint8_t *buffer,
        int retval;
        uint8_t fstat;
 
-       /* Increase buffer_size if needed */
-       if (buffer_size < (target->working_area_size/2))
-               buffer_size = (target->working_area_size/2);
-
        /* allocate working area with flash programming code */
        if (target_alloc_working_area(target, sizeof(kinetis_flash_write_code),
                        &write_algorithm) != ERROR_OK) {
@@ -1277,16 +1273,19 @@ static int kinetis_write_block(struct flash_bank *bank, 
const uint8_t *buffer,
        if (retval != ERROR_OK)
                return retval;
 
-       /* memory buffer */
-       while (target_alloc_working_area(target, buffer_size, &source) != 
ERROR_OK) {
-               buffer_size /= 4;
-               if (buffer_size <= 256) {
-                       /* free working area, write algorithm already allocated 
*/
-                       target_free_working_area(target, write_algorithm);
+       /* memory buffer, size *must* be multiple of word */
+       buffer_size = target_get_working_area_avail(target) & 
~(sizeof(uint32_t) - 1);
+       if (buffer_size < 256) {
+               LOG_WARNING("large enough working area not available, can't do 
block memory writes");
+               return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
+       } else if (buffer_size > 16384) {
+               /* probably won't benefit from more than 16k ... */
+               buffer_size = 16384;
+       }
 
-                       LOG_WARNING("No large enough working area available, 
can't do block memory writes");
-                       return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
-               }
+       if (target_alloc_working_area(target, buffer_size, &source) != 
ERROR_OK) {
+               LOG_ERROR("allocating working area failed");
+               return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
        }
 
        armv7m_info.common_magic = ARMV7M_COMMON_MAGIC;

-- 


_______________________________________________
OpenOCD-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openocd-devel

Reply via email to