Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BACKPORT] fsutils/mkfatfs:Allow for configurable buffer alignment #12

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions fsutils/mkfatfs/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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.
17 changes: 15 additions & 2 deletions fsutils/mkfatfs/mkfatfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
****************************************************************************/
Expand Down Expand Up @@ -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");
Expand Down