From 4e9921c9b2d419c81a5e3e3985c2c4d965651fa4 Mon Sep 17 00:00:00 2001 From: David Sidrane Date: Mon, 22 Nov 2021 12:56:52 -0800 Subject: [PATCH] fsutils/mkfatfs:Allow for configurable buffer alignment --- fsutils/mkfatfs/Kconfig | 9 +++++++++ fsutils/mkfatfs/mkfatfs.c | 17 +++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/fsutils/mkfatfs/Kconfig b/fsutils/mkfatfs/Kconfig index d22329f66..ebf5cd560 100644 --- a/fsutils/mkfatfs/Kconfig +++ b/fsutils/mkfatfs/Kconfig @@ -10,3 +10,12 @@ config FSUTILS_MKFATFS select BCH ---help--- Enables support for the mkfatfs utility + +config MKFATFS_BUFFER_ALIGMENT + int "Buffer alignment" + default 0 + depends on FSUTILS_MKFATFS + ---help--- + Enables alignment of the buffers used by the mkfatfs application + to N bytes. This may be needed for systems with cache or buffer + alignment constraints. diff --git a/fsutils/mkfatfs/mkfatfs.c b/fsutils/mkfatfs/mkfatfs.c index 2466e91a7..8b1e51bf7 100644 --- a/fsutils/mkfatfs/mkfatfs.c +++ b/fsutils/mkfatfs/mkfatfs.c @@ -38,6 +38,17 @@ #include "fat32.h" #include "mkfatfs.h" +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#if defined(CONFIG_MKFATFS_BUFFER_ALIGMENT) && \ + CONFIG_MKFATFS_BUFFER_ALIGMENT > 0 +# define fat_buffer_alloc(s) memalign(CONFIG_MKFATFS_BUFFER_ALIGMENT, (s)) +#else +# define fat_buffer_alloc(s) malloc((s)) +#endif + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -337,9 +348,11 @@ int mkfatfs(FAR const char *pathname, FAR struct fat_format_s *fmt) goto errout_with_driver; } - /* Allocate a buffer that will be working sector memory */ + /* Allocate a buffer that will be working sector memory + * Lets align it as needed + */ - var.fv_sect = (FAR uint8_t *)malloc(var.fv_sectorsize); + var.fv_sect = (FAR uint8_t *)fat_buffer_alloc(var.fv_sectorsize); if (!var.fv_sect) { ferr("ERROR: Failed to allocate working buffers\n");