diff mbox series

image: fit: Align hash output buffers

Message ID 20220324152611.1970384-1-sean.anderson@seco.com
State Accepted
Commit b583348ca8c8ce74d5dd665446d20f4c6c6e3f06
Delegated to: Tom Rini
Headers show
Series image: fit: Align hash output buffers | expand

Commit Message

Sean Anderson March 24, 2022, 3:26 p.m. UTC
Hardware-accelerated hash functions require that the input and output
buffers be aligned to the minimum DMA alignment. memalign.h helpfully
provides a macro just for this purpose. It doesn't exist on the host,
but we don't need to be aligned there either.

Fixes: 5dfb521386 ("[new uImage] New uImage low-level API")
Signed-off-by: Sean Anderson <sean.anderson@seco.com>
---

 boot/image-fit.c | 4 +++-
 tools/mkimage.h  | 3 +++
 2 files changed, 6 insertions(+), 1 deletion(-)

Comments

Simon Glass March 28, 2022, 6:35 a.m. UTC | #1
On Thu, 24 Mar 2022 at 09:26, Sean Anderson <sean.anderson@seco.com> wrote:
>
> Hardware-accelerated hash functions require that the input and output
> buffers be aligned to the minimum DMA alignment. memalign.h helpfully
> provides a macro just for this purpose. It doesn't exist on the host,
> but we don't need to be aligned there either.
>
> Fixes: 5dfb521386 ("[new uImage] New uImage low-level API")
> Signed-off-by: Sean Anderson <sean.anderson@seco.com>
> ---
>
>  boot/image-fit.c | 4 +++-
>  tools/mkimage.h  | 3 +++
>  2 files changed, 6 insertions(+), 1 deletion(-)

Reviewed-by: Simon Glass <sjg@chromium.org>


>
> diff --git a/boot/image-fit.c b/boot/image-fit.c
> index f01cafe4e2..6610035d0a 100644
> --- a/boot/image-fit.c
> +++ b/boot/image-fit.c
> @@ -24,6 +24,7 @@
>  #include <mapmem.h>
>  #include <asm/io.h>
>  #include <malloc.h>
> +#include <memalign.h>
>  #include <asm/global_data.h>
>  #ifdef CONFIG_DM_HASH
>  #include <dm.h>
> @@ -1263,7 +1264,8 @@ int calculate_hash(const void *data, int data_len, const char *name,
>  static int fit_image_check_hash(const void *fit, int noffset, const void *data,
>                                 size_t size, char **err_msgp)
>  {
> -       uint8_t value[FIT_MAX_HASH_LEN];
> +       DEFINE_ALIGN_BUFFER(uint8_t, value, FIT_MAX_HASH_LEN,
> +                           ARCH_DMA_MINALIGN);
>         int value_len;
>         const char *algo;
>         uint8_t *fit_value;
> diff --git a/tools/mkimage.h b/tools/mkimage.h
> index 0d3148444c..7652c8b001 100644
> --- a/tools/mkimage.h
> +++ b/tools/mkimage.h
> @@ -41,6 +41,9 @@ static inline ulong map_to_sysmem(void *ptr)
>         return (ulong)(uintptr_t)ptr;
>  }
>
> +#define ARCH_DMA_MINALIGN 1
> +#define DEFINE_ALIGN_BUFFER(type, name, size, alugn) type name[size]
> +
>  #define MKIMAGE_TMPFILE_SUFFIX         ".tmp"
>  #define MKIMAGE_MAX_TMPFILE_LEN                256
>  #define MKIMAGE_DEFAULT_DTC_OPTIONS    "-I dts -O dtb -p 500"
> --
> 2.25.1
>
Tom Rini April 11, 2022, 8:15 p.m. UTC | #2
On Thu, Mar 24, 2022 at 11:26:11AM -0400, Sean Anderson wrote:

> Hardware-accelerated hash functions require that the input and output
> buffers be aligned to the minimum DMA alignment. memalign.h helpfully
> provides a macro just for this purpose. It doesn't exist on the host,
> but we don't need to be aligned there either.
> 
> Fixes: 5dfb521386 ("[new uImage] New uImage low-level API")
> Signed-off-by: Sean Anderson <sean.anderson@seco.com>
> Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/boot/image-fit.c b/boot/image-fit.c
index f01cafe4e2..6610035d0a 100644
--- a/boot/image-fit.c
+++ b/boot/image-fit.c
@@ -24,6 +24,7 @@ 
 #include <mapmem.h>
 #include <asm/io.h>
 #include <malloc.h>
+#include <memalign.h>
 #include <asm/global_data.h>
 #ifdef CONFIG_DM_HASH
 #include <dm.h>
@@ -1263,7 +1264,8 @@  int calculate_hash(const void *data, int data_len, const char *name,
 static int fit_image_check_hash(const void *fit, int noffset, const void *data,
 				size_t size, char **err_msgp)
 {
-	uint8_t value[FIT_MAX_HASH_LEN];
+	DEFINE_ALIGN_BUFFER(uint8_t, value, FIT_MAX_HASH_LEN,
+			    ARCH_DMA_MINALIGN);
 	int value_len;
 	const char *algo;
 	uint8_t *fit_value;
diff --git a/tools/mkimage.h b/tools/mkimage.h
index 0d3148444c..7652c8b001 100644
--- a/tools/mkimage.h
+++ b/tools/mkimage.h
@@ -41,6 +41,9 @@  static inline ulong map_to_sysmem(void *ptr)
 	return (ulong)(uintptr_t)ptr;
 }
 
+#define ARCH_DMA_MINALIGN 1
+#define DEFINE_ALIGN_BUFFER(type, name, size, alugn) type name[size]
+
 #define MKIMAGE_TMPFILE_SUFFIX		".tmp"
 #define MKIMAGE_MAX_TMPFILE_LEN		256
 #define MKIMAGE_DEFAULT_DTC_OPTIONS	"-I dts -O dtb -p 500"