diff --git a/common/boot_fit.c b/common/boot_fit.c index 4b5cec58d0..4dedd08a8e 100644 --- a/common/boot_fit.c +++ b/common/boot_fit.c @@ -62,7 +62,7 @@ void *locate_dtb_in_fit(const void *fit) int ret; size = fdt_totalsize(fit); - size = (size + 3) & ~3; + size = FIT_ALIGN(size); header = (struct image_header *)fit; diff --git a/common/image-fit.c b/common/image-fit.c index a60f234206..2b09756a15 100644 --- a/common/image-fit.c +++ b/common/image-fit.c @@ -850,7 +850,7 @@ int fit_image_get_data(const void *fit, int noffset, fit_image_get_data_size(fit, noffset, &data_sz); if (data_sz) { data_off += (ulong)fit; - data_off += round_up(fdt_totalsize(fit), 4); + data_off += FIT_ALIGN(fdt_totalsize(fit)); *data = (void *)data_off; *size = data_sz; return 0; diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c index 063d2b1a75..160dd6f70b 100644 --- a/common/spl/spl_fit.c +++ b/common/spl/spl_fit.c @@ -359,8 +359,8 @@ int spl_load_simple_fit(struct spl_image_info *spl_image, * image. */ size = fdt_totalsize(fit); - size = (size + 3) & ~3; - base_offset = (size + 3) & ~3; + size = FIT_ALIGN(size); + base_offset = FIT_ALIGN(size); /* * So far we only have one block of data from the FIT. Read the entire diff --git a/common/splash_source.c b/common/splash_source.c index e0defdebd6..6a987eaa83 100644 --- a/common/splash_source.c +++ b/common/splash_source.c @@ -358,7 +358,7 @@ static int splash_load_fit(struct splash_location *location, u32 bmp_load_addr) /* Align data offset to 4-byte boundrary */ fit_size = fdt_totalsize(fit_header); - fit_size = (fit_size + 3) & ~3; + fit_size = FIT_ALIGN(fit_size); /* Read in the splash data */ location->offset = (location->offset + fit_size + splash_offset); diff --git a/include/image.h b/include/image.h index e3bee8774f..fdbd80dd39 100644 --- a/include/image.h +++ b/include/image.h @@ -921,6 +921,12 @@ int bootz_setup(ulong image, ulong *start, ulong *end); #define FIT_MAX_HASH_LEN HASH_MAX_DIGEST_SIZE #if IMAGE_ENABLE_FIT + +#ifndef IMAGE_ALIGN_SIZE +#define IMAGE_ALIGN_SIZE 512 +#endif +#define FIT_ALIGN(x) (((x)+IMAGE_ALIGN_SIZE-1)&~(IMAGE_ALIGN_SIZE-1)) + /* cmdline argument format parsing */ int fit_parse_conf(const char *spec, ulong addr_curr, ulong *addr, const char **conf_name); diff --git a/tools/fit_image.c b/tools/fit_image.c index 6dcc88bae0..21afed6ee0 100644 --- a/tools/fit_image.c +++ b/tools/fit_image.c @@ -460,7 +460,7 @@ static int fit_extract_data(struct image_tool_params *params, const char *fname) } fdt_setprop_u32(fdt, node, "data-size", len); - buf_ptr += (len + 3) & ~3; + buf_ptr += FIT_ALIGN(len); } /* Pack the FDT and place the data after it */ @@ -469,7 +469,7 @@ static int fit_extract_data(struct image_tool_params *params, const char *fname) 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; + new_size = FIT_ALIGN(new_size); munmap(fdt, sbuf.st_size); if (ftruncate(fd, new_size)) { @@ -528,7 +528,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 = FIT_ALIGN(fit_size); /* Allocate space to hold the new FIT */ size = sbuf.st_size + 16384;