@@ -150,6 +150,7 @@ static int armv7m_identify_cache_internal(struct target *target)
150150
151151 // separate d or unified d/i cache at this level ?
152152 if (ctype & (CLIDR_CTYPE_UNIFIED_CACHE | CLIDR_CTYPE_D_CACHE )) {
153+ cache -> has_d_u_cache = true;
153154 cache -> arch [cl ].d_u_size = decode_ccsidr (d_u_ccsidr [cl ]);
154155
155156 LOG_TARGET_DEBUG (target ,
@@ -167,6 +168,7 @@ static int armv7m_identify_cache_internal(struct target *target)
167168 }
168169
169170 if (ctype & CLIDR_CTYPE_I_CACHE ) {
171+ cache -> has_i_cache = true;
170172 cache -> arch [cl ].i_size = decode_ccsidr (i_ccsidr [cl ]);
171173
172174 LOG_TARGET_DEBUG (target ,
@@ -306,7 +308,6 @@ static int armv7m_cache_helper(struct target *target, const char *helper,
306308
307309int armv7m_d_cache_flush (struct target * target , uint32_t address ,
308310 unsigned int length )
309-
310311{
311312 struct armv7m_common * armv7m = target_to_armv7m (target );
312313 struct armv7m_cache_common * cache = & armv7m -> armv7m_cache ;
@@ -315,23 +316,17 @@ int armv7m_d_cache_flush(struct target *target, uint32_t address,
315316 if (retval != ERROR_NOT_IMPLEMENTED )
316317 return retval ;
317318
318- if (!cache -> info_valid )
319- return ERROR_OK ;
320-
321- if (target -> state != TARGET_HALTED ) {
322- LOG_TARGET_ERROR (target , "not halted" );
323- return ERROR_TARGET_NOT_HALTED ;
324- }
325-
326- if (!armv7m -> armv7m_cache .d_u_cache_enabled )
319+ if (!cache -> info_valid || !cache -> has_d_u_cache )
327320 return ERROR_OK ;
328321
329322 uint32_t line_len = cache -> d_min_line_len ;
330323 uint32_t addr_line = ALIGN_DOWN (address , line_len );
331324 uint32_t addr_end = address + length ;
332325
333326 while (addr_line < addr_end ) {
334- mem_ap_write_u32 (armv7m -> debug_ap , DCCIMVAC , addr_line );
327+ retval = mem_ap_write_u32 (armv7m -> debug_ap , DCCIMVAC , addr_line );
328+ if (retval != ERROR_OK )
329+ return retval ;
335330 addr_line += line_len ;
336331 keep_alive ();
337332 }
@@ -349,23 +344,17 @@ int armv7m_i_cache_inval(struct target *target, uint32_t address,
349344 if (retval != ERROR_NOT_IMPLEMENTED )
350345 return retval ;
351346
352- if (!cache -> info_valid )
353- return ERROR_OK ;
354-
355- if (target -> state != TARGET_HALTED ) {
356- LOG_TARGET_ERROR (target , "not halted" );
357- return ERROR_TARGET_NOT_HALTED ;
358- }
359-
360- if (!armv7m -> armv7m_cache .i_cache_enabled )
347+ if (!cache -> info_valid || !cache -> has_i_cache )
361348 return ERROR_OK ;
362349
363350 uint32_t line_len = cache -> i_min_line_len ;
364351 uint32_t addr_line = ALIGN_DOWN (address , line_len );
365352 uint32_t addr_end = address + length ;
366353
367354 while (addr_line < addr_end ) {
368- mem_ap_write_u32 (armv7m -> debug_ap , ICIMVAU , addr_line );
355+ retval = mem_ap_write_u32 (armv7m -> debug_ap , ICIMVAU , addr_line );
356+ if (retval != ERROR_OK )
357+ return retval ;
369358 addr_line += line_len ;
370359 keep_alive ();
371360 }
0 commit comments