mirror of
				https://github.com/eledio-devices/thirdparty-littlefs.git
				synced 2025-10-31 16:14:16 +01:00 
			
		
		
		
	Don't bypass cache in lfs_cache_prog() and lfs_cache_read()
				
					
				
			In some cases specific alignment of buffer passed to underlying device is required. For example SDMMC in STM32F7 (when used with DMA) requires the buffers to be aligned to 16 bytes. If you enable data cache in STM32F7, the alignment of buffer passed to any driver which uses DMA should generally be at least 32 bytes. While it is possible to provide sufficiently aligned "read", "prog" and per-file caches to littlefs, the cases where caches are bypassed are hard to control when littlefs is hidden under some additional layers. For example if you couple littlefs with stdio and use it via `FILE*`, then littlefs functions will operate on internal `FIlE*` buffer, usually allocated dynamically, so in these specific cases - with insufficient alignment (8 bytes on ARM Cortex-M). The easy path was taken - remove all cases of cache bypassing. Fixes #158
This commit is contained in:
		
				
					committed by
					
						 Christopher Haster
						Christopher Haster
					
				
			
			
				
	
			
			
			
						parent
						
							0907ba7813
						
					
				
				
					commit
					fdd239fe21
				
			
							
								
								
									
										15
									
								
								lfs.c
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								lfs.c
									
									
									
									
									
								
							| @@ -80,21 +80,6 @@ static int lfs_bd_read(lfs_t *lfs, | |||||||
|             diff = lfs_min(diff, rcache->off-off); |             diff = lfs_min(diff, rcache->off-off); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         if (size >= hint && off % lfs->cfg->read_size == 0 && |  | ||||||
|                 size >= lfs->cfg->read_size) { |  | ||||||
|             // bypass cache? |  | ||||||
|             diff = lfs_aligndown(diff, lfs->cfg->read_size); |  | ||||||
|             int err = lfs->cfg->read(lfs->cfg, block, off, data, diff); |  | ||||||
|             if (err) { |  | ||||||
|                 return err; |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             data += diff; |  | ||||||
|             off += diff; |  | ||||||
|             size -= diff; |  | ||||||
|             continue; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         // load to cache, first condition can no longer fail |         // load to cache, first condition can no longer fail | ||||||
|         LFS_ASSERT(block < lfs->cfg->block_count); |         LFS_ASSERT(block < lfs->cfg->block_count); | ||||||
|         rcache->block = block; |         rcache->block = block; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user