summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2020-04-24 13:04:38 -0400
committerTom Rini <trini@konsulko.com>2020-04-24 13:04:38 -0400
commit18b9c98024ec89e00a57707f07ff6ada06089d26 (patch)
tree60b4659a673d7a9dff309ee0d0b324c242a53cfc /tools
parentb897306341024695d17296efc1f9d83d06368209 (diff)
parent08140dba0f539842d4836afb56fe43a33d8ba045 (diff)
Merge branch '2020-04-24-master-imports'
- Assorted minor bugfixes. - Resync fixdep with Linux v5.7-rc1 - Numerous changes to reduce SPL in various cases including when we have read-only env support. - Allow mkimage to align the header on FIT images to a specific size.
Diffstat (limited to 'tools')
-rw-r--r--tools/aisimage.c8
-rw-r--r--tools/fit_image.c62
-rw-r--r--tools/ifwitool.c4
-rw-r--r--tools/image-host.c2
-rw-r--r--tools/imagetool.h4
-rw-r--r--tools/imx8mimage.c3
-rw-r--r--tools/kwbimage.c8
-rw-r--r--tools/kwbimage.h2
-rw-r--r--tools/mingw_support.c113
-rw-r--r--tools/mingw_support.h45
-rw-r--r--tools/mkimage.c19
-rw-r--r--tools/mksunxiboot.c4
-rw-r--r--tools/os_support.c7
-rw-r--r--tools/os_support.h3
-rw-r--r--tools/socfpgaimage.c2
15 files changed, 70 insertions, 216 deletions
diff --git a/tools/aisimage.c b/tools/aisimage.c
index 4cd76ab843..b8b3ee3207 100644
--- a/tools/aisimage.c
+++ b/tools/aisimage.c
@@ -10,7 +10,6 @@
#define IS_FNC_EXEC(c) (cmd_table[c].AIS_cmd == AIS_CMD_FNLOAD)
#define WORD_ALIGN0 4
-#define WORD_ALIGN(len) (((len)+WORD_ALIGN0-1) & ~(WORD_ALIGN0-1))
#define MAX_CMD_BUFFER 4096
static uint32_t ais_img_size;
@@ -202,8 +201,9 @@ static uint32_t *ais_alloc_buffer(struct image_tool_params *params)
* is not left to the main program, because after the datafile
* the header must be terminated with the Jump & Close command.
*/
- ais_img_size = WORD_ALIGN(sbuf.st_size) + MAX_CMD_BUFFER;
- ptr = (uint32_t *)malloc(WORD_ALIGN(sbuf.st_size) + MAX_CMD_BUFFER);
+ ais_img_size = ALIGN(sbuf.st_size, WORD_ALIGN0) + MAX_CMD_BUFFER;
+ ptr = (uint32_t *)malloc(ALIGN(sbuf.st_size, WORD_ALIGN0)
+ + MAX_CMD_BUFFER);
if (!ptr) {
fprintf(stderr, "%s: malloc return failure: %s\n",
params->cmdname, strerror(errno));
@@ -242,7 +242,7 @@ static uint32_t *ais_copy_image(struct image_tool_params *params,
*aisptr++ = params->ep;
*aisptr++ = sbuf.st_size;
memcpy((void *)aisptr, ptr, sbuf.st_size);
- aisptr += WORD_ALIGN(sbuf.st_size) / sizeof(uint32_t);
+ aisptr += ALIGN(sbuf.st_size, WORD_ALIGN0) / sizeof(uint32_t);
(void) munmap((void *)ptr, sbuf.st_size);
(void) close(dfd);
diff --git a/tools/fit_image.c b/tools/fit_image.c
index 4301b5decb..4aeabbcfe9 100644
--- a/tools/fit_image.c
+++ b/tools/fit_image.c
@@ -422,7 +422,7 @@ err_buf:
*/
static int fit_extract_data(struct image_tool_params *params, const char *fname)
{
- void *buf;
+ void *buf = NULL;
int buf_ptr;
int fit_size, new_size;
int fd;
@@ -431,26 +431,33 @@ static int fit_extract_data(struct image_tool_params *params, const char *fname)
int ret;
int images;
int node;
+ int image_number;
+ int align_size;
+ align_size = params->bl_len ? params->bl_len : 4;
fd = mmap_fdt(params->cmdname, fname, 0, &fdt, &sbuf, false, false);
if (fd < 0)
return -EIO;
fit_size = fdt_totalsize(fdt);
- /* Allocate space to hold the image data we will extract */
- buf = malloc(fit_size);
- if (!buf) {
- ret = -ENOMEM;
- goto err_munmap;
- }
- buf_ptr = 0;
-
images = fdt_path_offset(fdt, FIT_IMAGES_PATH);
if (images < 0) {
debug("%s: Cannot find /images node: %d\n", __func__, images);
ret = -EINVAL;
goto err_munmap;
}
+ image_number = fdtdec_get_child_count(fdt, images);
+
+ /*
+ * Allocate space to hold the image data we will extract,
+ * extral space allocate for image alignment to prevent overflow.
+ */
+ buf = malloc(fit_size + (align_size * image_number));
+ if (!buf) {
+ ret = -ENOMEM;
+ goto err_munmap;
+ }
+ buf_ptr = 0;
for (node = fdt_first_subnode(fdt, images);
node >= 0;
@@ -478,17 +485,17 @@ static int fit_extract_data(struct image_tool_params *params, const char *fname)
buf_ptr);
}
fdt_setprop_u32(fdt, node, FIT_DATA_SIZE_PROP, len);
-
- buf_ptr += (len + 3) & ~3;
+ buf_ptr += ALIGN(len, align_size);
}
/* Pack the FDT and place the data after it */
fdt_pack(fdt);
+ new_size = fdt_totalsize(fdt);
+ new_size = ALIGN(new_size, align_size);
+ fdt_set_totalsize(fdt, new_size);
debug("Size reduced from %x to %x\n", fit_size, fdt_totalsize(fdt));
debug("External data size %x\n", buf_ptr);
- new_size = fdt_totalsize(fdt);
- new_size = (new_size + 3) & ~3;
munmap(fdt, sbuf.st_size);
if (ftruncate(fd, new_size)) {
@@ -527,8 +534,7 @@ static int fit_extract_data(struct image_tool_params *params, const char *fname)
err_munmap:
munmap(fdt, sbuf.st_size);
err:
- if (buf)
- free(buf);
+ free(buf);
close(fd);
return ret;
}
@@ -547,7 +553,7 @@ static int fit_import_data(struct image_tool_params *params, const char *fname)
if (fd < 0)
return -EIO;
fit_size = fdt_totalsize(old_fdt);
- data_base = (fit_size + 3) & ~3;
+ data_base = ALIGN(fit_size, 4);
/* Allocate space to hold the new FIT */
size = sbuf.st_size + 16384;
@@ -556,21 +562,21 @@ static int fit_import_data(struct image_tool_params *params, const char *fname)
fprintf(stderr, "%s: Failed to allocate memory (%d bytes)\n",
__func__, size);
ret = -ENOMEM;
- goto err_has_fd;
+ goto err_munmap;
}
ret = fdt_open_into(old_fdt, fdt, size);
if (ret) {
debug("%s: Failed to expand FIT: %s\n", __func__,
fdt_strerror(errno));
ret = -EINVAL;
- goto err_has_fd;
+ goto err_munmap;
}
images = fdt_path_offset(fdt, FIT_IMAGES_PATH);
if (images < 0) {
debug("%s: Cannot find /images node: %d\n", __func__, images);
ret = -EINVAL;
- goto err_has_fd;
+ goto err_munmap;
}
for (node = fdt_first_subnode(fdt, images);
@@ -591,10 +597,12 @@ static int fit_import_data(struct image_tool_params *params, const char *fname)
debug("%s: Failed to write property: %s\n", __func__,
fdt_strerror(ret));
ret = -EINVAL;
- goto err_has_fd;
+ goto err_munmap;
}
}
+ munmap(old_fdt, sbuf.st_size);
+
/* Close the old fd so we can re-use it. */
close(fd);
@@ -609,22 +617,24 @@ static int fit_import_data(struct image_tool_params *params, const char *fname)
fprintf(stderr, "%s: Can't open %s: %s\n",
params->cmdname, fname, strerror(errno));
ret = -EIO;
- goto err_no_fd;
+ goto err;
}
if (write(fd, fdt, new_size) != new_size) {
debug("%s: Failed to write external data to file %s\n",
__func__, strerror(errno));
ret = -EIO;
- goto err_has_fd;
+ goto err;
}
- ret = 0;
-
-err_has_fd:
+ free(fdt);
close(fd);
-err_no_fd:
+ return 0;
+
+err_munmap:
munmap(old_fdt, sbuf.st_size);
+err:
free(fdt);
+ close(fd);
return ret;
}
diff --git a/tools/ifwitool.c b/tools/ifwitool.c
index 543e9d4e70..b2b06cc921 100644
--- a/tools/ifwitool.c
+++ b/tools/ifwitool.c
@@ -8,15 +8,13 @@
#include <assert.h>
#include <stdbool.h>
#include <getopt.h>
+#include "imagetool.h"
#include "os_support.h"
#ifndef __packed
#define __packed __attribute__((packed))
#endif
#define KiB 1024
-#define ALIGN(x, a) __ALIGN_MASK((x), (typeof(x))(a) - 1)
-#define __ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask))
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
/*
* min()/max()/clamp() macros that also do
diff --git a/tools/image-host.c b/tools/image-host.c
index 4e57ddea96..5bb68965e7 100644
--- a/tools/image-host.c
+++ b/tools/image-host.c
@@ -307,7 +307,7 @@ static int fit_image_read_data(char *filename, unsigned char *data,
/* Check that we have read all the file */
if (n != sbuf.st_size) {
- printf("Can't read all file %s (read %ld bytes, expexted %ld)\n",
+ printf("Can't read all file %s (read %zd bytes, expexted %ld)\n",
filename, n, sbuf.st_size);
goto err;
}
diff --git a/tools/imagetool.h b/tools/imagetool.h
index e1c778b0df..f54809cd57 100644
--- a/tools/imagetool.h
+++ b/tools/imagetool.h
@@ -25,6 +25,9 @@
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+#define __ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask))
+#define ALIGN(x, a) __ALIGN_MASK((x), (typeof(x))(a) - 1)
+
#define IH_ARCH_DEFAULT IH_ARCH_INVALID
/* Information about a file that needs to be placed into the FIT */
@@ -76,6 +79,7 @@ struct image_tool_params {
bool external_data; /* Store data outside the FIT */
bool quiet; /* Don't output text in normal operation */
unsigned int external_offset; /* Add padding to external data */
+ int bl_len; /* Block length in byte for external data */
const char *engine_id; /* Engine to use for signing */
};
diff --git a/tools/imx8mimage.c b/tools/imx8mimage.c
index 2b0d946a7d..bc4ee793cb 100644
--- a/tools/imx8mimage.c
+++ b/tools/imx8mimage.c
@@ -32,8 +32,6 @@ static uint32_t rom_version = ROM_V1;
#define HDMI_FW_SIZE 0x17000 /* Use Last 0x1000 for IVT and CSF */
#define ALIGN_SIZE 0x1000
-#define ALIGN(x,a) __ALIGN_MASK((x), (__typeof__(x))(a) - 1, a)
-#define __ALIGN_MASK(x,mask,mask2) (((x) + (mask)) / (mask2) * (mask2))
static uint32_t get_cfg_value(char *token, char *name, int linenr)
{
@@ -343,7 +341,6 @@ static int generate_ivt_for_fit(int fd, int fit_offset, uint32_t ep,
}
fit_size = fdt_totalsize(&image_header);
- fit_size = (fit_size + 3) & ~3;
fit_size = ALIGN(fit_size, ALIGN_SIZE);
diff --git a/tools/kwbimage.c b/tools/kwbimage.c
index b8f8d38212..02fd0c949f 100644
--- a/tools/kwbimage.c
+++ b/tools/kwbimage.c
@@ -1015,7 +1015,7 @@ static size_t image_headersz_v1(int *hasext)
* The payload should be aligned on some reasonable
* boundary
*/
- return ALIGN_SUP(headersz, 4096);
+ return ALIGN(headersz, 4096);
}
int add_binary_header_v1(uint8_t *cur)
@@ -1058,7 +1058,7 @@ int add_binary_header_v1(uint8_t *cur)
* up to a 4-byte boundary. Plus 4 bytes for the
* next-header byte and 3-byte alignment at the end.
*/
- binhdrsz = ALIGN_SUP(binhdrsz, 4) + 4;
+ binhdrsz = ALIGN(binhdrsz, 4) + 4;
hdr->headersz_lsb = cpu_to_le16(binhdrsz & 0xFFFF);
hdr->headersz_msb = (binhdrsz & 0xFFFF0000) >> 16;
@@ -1082,7 +1082,7 @@ int add_binary_header_v1(uint8_t *cur)
fclose(bin);
- cur += ALIGN_SUP(s.st_size, 4);
+ cur += ALIGN(s.st_size, 4);
/*
* For now, we don't support more than one binary
@@ -1548,7 +1548,7 @@ static void kwbimage_set_header(void *ptr, struct stat *sbuf, int ifd,
}
/* The MVEBU BootROM does not allow non word aligned payloads */
- sbuf->st_size = ALIGN_SUP(sbuf->st_size, 4);
+ sbuf->st_size = ALIGN(sbuf->st_size, 4);
version = image_get_version();
switch (version) {
diff --git a/tools/kwbimage.h b/tools/kwbimage.h
index 25bc08c5ce..0b6d05bef1 100644
--- a/tools/kwbimage.h
+++ b/tools/kwbimage.h
@@ -29,8 +29,6 @@
#define IBR_HDR_UART_ID 0x69
#define IBR_DEF_ATTRIB 0x00
-#define ALIGN_SUP(x, a) (((x) + (a - 1)) & ~(a - 1))
-
/* Structure of the main header, version 0 (Kirkwood, Dove) */
struct main_hdr_v0 {
uint8_t blockid; /* 0x0 */
diff --git a/tools/mingw_support.c b/tools/mingw_support.c
deleted file mode 100644
index 2b17bf7dd2..0000000000
--- a/tools/mingw_support.c
+++ /dev/null
@@ -1,113 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0+
-/*
- * Copyright 2008 Extreme Engineering Solutions, Inc.
- *
- * mmap/munmap implementation derived from:
- * Clamav Native Windows Port : mmap win32 compatibility layer
- * Copyright (c) 2005-2006 Gianluigi Tiesi <sherpya@netfarm.it>
- * Parts by Kees Zeelenberg <kzlg@users.sourceforge.net> (LibGW32C)
- */
-
-#include "mingw_support.h"
-#include <stdio.h>
-#include <stdint.h>
-#include <string.h>
-#include <errno.h>
-#include <assert.h>
-#include <io.h>
-
-int fsync(int fd)
-{
- return _commit(fd);
-}
-
-void *mmap(void *addr, size_t len, int prot, int flags, int fd, int offset)
-{
- void *map = NULL;
- HANDLE handle = INVALID_HANDLE_VALUE;
- DWORD cfm_flags = 0, mvf_flags = 0;
-
- switch (prot) {
- case PROT_READ | PROT_WRITE:
- cfm_flags = PAGE_READWRITE;
- mvf_flags = FILE_MAP_ALL_ACCESS;
- break;
- case PROT_WRITE:
- cfm_flags = PAGE_READWRITE;
- mvf_flags = FILE_MAP_WRITE;
- break;
- case PROT_READ:
- cfm_flags = PAGE_READONLY;
- mvf_flags = FILE_MAP_READ;
- break;
- default:
- return MAP_FAILED;
- }
-
- handle = CreateFileMappingA((HANDLE) _get_osfhandle(fd), NULL,
- cfm_flags, HIDWORD(len), LODWORD(len), NULL);
- if (!handle)
- return MAP_FAILED;
-
- map = MapViewOfFile(handle, mvf_flags, HIDWORD(offset),
- LODWORD(offset), len);
- CloseHandle(handle);
-
- if (!map)
- return MAP_FAILED;
-
- return map;
-}
-
-int munmap(void *addr, size_t len)
-{
- if (!UnmapViewOfFile(addr))
- return -1;
-
- return 0;
-}
-
-/* Reentrant string tokenizer. Generic version.
- Copyright (C) 1991,1996-1999,2001,2004,2007 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- */
-
-/* Parse S into tokens separated by characters in DELIM.
- If S is NULL, the saved pointer in SAVE_PTR is used as
- the next starting point. For example:
- char s[] = "-abc-=-def";
- char *sp;
- x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def"
- x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL
- x = strtok_r(NULL, "=", &sp); // x = NULL
- // s = "abc\0-def\0"
-*/
-char *strtok_r(char *s, const char *delim, char **save_ptr)
-{
- char *token;
-
- if (s == NULL)
- s = *save_ptr;
-
- /* Scan leading delimiters. */
- s += strspn(s, delim);
- if (*s == '\0') {
- *save_ptr = s;
- return NULL;
- }
-
- /* Find the end of the token. */
- token = s;
- s = strpbrk (token, delim);
- if (s == NULL) {
- /* This token finishes the string. */
- *save_ptr = memchr(token, '\0', strlen(token));
- } else {
- /* Terminate the token and make *SAVE_PTR point past it. */
- *s = '\0';
- *save_ptr = s + 1;
- }
- return token;
-}
-
-#include "getline.c"
diff --git a/tools/mingw_support.h b/tools/mingw_support.h
deleted file mode 100644
index e0b8ac3ebc..0000000000
--- a/tools/mingw_support.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/* SPDX-License-Identifier: LGPL-2.0+ */
-/*
- * Copyright 2008 Extreme Engineering Solutions, Inc.
- */
-
-#ifndef __MINGW_SUPPORT_H_
-#define __WINGW_SUPPORT_H_ 1
-
-/* Defining __INSIDE_MSYS__ helps to prevent u-boot/mingw overlap */
-#define __INSIDE_MSYS__ 1
-
-#include <windows.h>
-
-/* mmap protections */
-#define PROT_READ 0x1 /* Page can be read */
-#define PROT_WRITE 0x2 /* Page can be written */
-#define PROT_EXEC 0x4 /* Page can be executed */
-#define PROT_NONE 0x0 /* Page can not be accessed */
-
-/* Sharing types (must choose one and only one of these) */
-#define MAP_SHARED 0x01 /* Share changes */
-#define MAP_PRIVATE 0x02 /* Changes are private */
-
-/* File perms */
-#ifndef S_IRGRP
-# define S_IRGRP 0
-#endif
-#ifndef S_IWGRP
-# define S_IWGRP 0
-#endif
-
-/* Windows 64-bit access macros */
-#define LODWORD(x) ((DWORD)((DWORDLONG)(x)))
-#define HIDWORD(x) ((DWORD)(((DWORDLONG)(x) >> 32) & 0xffffffff))
-
-typedef UINT uint;
-typedef ULONG ulong;
-
-int fsync(int fd);
-void *mmap(void *, size_t, int, int, int, int);
-int munmap(void *, size_t);
-char *strtok_r(char *s, const char *delim, char **save_ptr);
-#include "getline.h"
-
-#endif /* __MINGW_SUPPORT_H_ */
diff --git a/tools/mkimage.c b/tools/mkimage.c
index 5f51d2cc89..336376f8d0 100644
--- a/tools/mkimage.c
+++ b/tools/mkimage.c
@@ -7,6 +7,7 @@
* Wolfgang Denk, wd@denx.de
*/
+#include "imagetool.h"
#include "mkimage.h"
#include "imximage.h"
#include <image.h>
@@ -97,8 +98,9 @@ static void usage(const char *msg)
" -i => input filename for ramdisk file\n");
#ifdef CONFIG_FIT_SIGNATURE
fprintf(stderr,
- "Signing / verified boot options: [-E] [-k keydir] [-K dtb] [ -c <comment>] [-p addr] [-r] [-N engine]\n"
+ "Signing / verified boot options: [-E] [-B size] [-k keydir] [-K dtb] [ -c <comment>] [-p addr] [-r] [-N engine]\n"
" -E => place data outside of the FIT structure\n"
+ " -B => align size in hex for FIT structure and header\n"
" -k => set directory containing private keys\n"
" -K => write public keys to this .dtb file\n"
" -c => add comment in signature node\n"
@@ -143,7 +145,7 @@ static void process_args(int argc, char **argv)
int opt;
while ((opt = getopt(argc, argv,
- "a:A:b:c:C:d:D:e:Ef:Fk:i:K:ln:N:p:O:rR:qsT:vVx")) != -1) {
+ "a:A:b:B:c:C:d:D:e:Ef:Fk:i:K:ln:N:p:O:rR:qsT:vVx")) != -1) {
switch (opt) {
case 'a':
params.addr = strtoull(optarg, &ptr, 16);
@@ -168,6 +170,15 @@ static void process_args(int argc, char **argv)
exit(EXIT_FAILURE);
}
break;
+ case 'B':
+ params.bl_len = strtoull(optarg, &ptr, 16);
+ if (*ptr) {
+ fprintf(stderr, "%s: invalid block length %s\n",
+ params.cmdname, optarg);
+ exit(EXIT_FAILURE);
+ }
+
+ break;
case 'c':
params.comment = optarg;
break;
@@ -557,8 +568,8 @@ int main(int argc, char **argv)
}
if (params.type == IH_TYPE_FIRMWARE_IVT) {
/* Add alignment and IVT */
- uint32_t aligned_filesize = (params.file_size + 0x1000
- - 1) & ~(0x1000 - 1);
+ uint32_t aligned_filesize = ALIGN(params.file_size,
+ 0x1000);
flash_header_v2_t ivt_header = { { 0xd1, 0x2000, 0x40 },
params.addr, 0, 0, 0, params.addr
+ aligned_filesize
diff --git a/tools/mksunxiboot.c b/tools/mksunxiboot.c
index 1c8701e75e..a18c9d98bc 100644
--- a/tools/mksunxiboot.c
+++ b/tools/mksunxiboot.c
@@ -14,6 +14,7 @@
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include "imagetool.h"
#include "../arch/arm/include/asm/arch-sunxi/spl.h"
#define STAMP_VALUE 0x5F0A6C39
@@ -44,9 +45,6 @@ int gen_check_sum(struct boot_file_head *head_p)
return 0;
}
-#define ALIGN(x, a) __ALIGN_MASK((x), (typeof(x))(a)-1)
-#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
-
#define SUNXI_SRAM_SIZE 0x8000 /* SoC with smaller size are limited before */
#define SRAM_LOAD_MAX_SIZE (SUNXI_SRAM_SIZE - sizeof(struct boot_file_head))
diff --git a/tools/os_support.c b/tools/os_support.c
index 21e43c876a..6890c3183f 100644
--- a/tools/os_support.c
+++ b/tools/os_support.c
@@ -3,13 +3,12 @@
* Copyright 2009 Extreme Engineering Solutions, Inc.
*/
+#include "compiler.h"
+
/*
* Include additional files required for supporting different operating systems
*/
-#include "compiler.h"
-#ifdef __MINGW32__
-#include "mingw_support.c"
-#endif
+
#if defined(__APPLE__) && __DARWIN_C_LEVEL < 200809L
#include "getline.c"
#endif
diff --git a/tools/os_support.h b/tools/os_support.h
index 3a2106ed7e..471d605f5c 100644
--- a/tools/os_support.h
+++ b/tools/os_support.h
@@ -11,9 +11,6 @@
/*
* Include additional files required for supporting different operating systems
*/
-#ifdef __MINGW32__
-#include "mingw_support.h"
-#endif
#if defined(__APPLE__) && __DARWIN_C_LEVEL < 200809L
#include "getline.h"
diff --git a/tools/socfpgaimage.c b/tools/socfpgaimage.c
index 8fa098338b..6dfd64e31d 100644
--- a/tools/socfpgaimage.c
+++ b/tools/socfpgaimage.c
@@ -203,7 +203,7 @@ static int sfp_sign_buffer(uint8_t *buf, uint8_t ver, uint8_t flags,
uint32_t calc_crc;
/* Align the length up */
- len = (len + 3) & ~3;
+ len = ALIGN(len, 4);
/* Build header, adding 4 bytes to length to hold the CRC32. */
sfp_build_header(buf + HEADER_OFFSET, ver, flags, len + 4);