X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=tools%2Fomapimage.c;h=c59cdcc79b3d0f4934817fca231bc4e6c6fc7c87;hb=270f1fb7b213a315b9b5fbde394d390d0c4876ae;hp=e31b94ae4f72d2e05c90781d5d9d0e67b9b9a81d;hpb=ce38ebb6f7f0e2111b7d457651ae0a76bc5a2636;p=oweals%2Fu-boot.git diff --git a/tools/omapimage.c b/tools/omapimage.c index e31b94ae4f..c59cdcc79b 100644 --- a/tools/omapimage.c +++ b/tools/omapimage.c @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0+ /* * (C) Copyright 2010 * Linaro LTD, www.linaro.org @@ -10,8 +11,6 @@ * (C) Copyright 2008 * Marvell Semiconductor * Written-by: Prafulla Wadaskar - * - * SPDX-License-Identifier: GPL-2.0+ */ #include "imagetool.h" @@ -20,6 +19,8 @@ #include "gpheader.h" #include "omapimage.h" +#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) + /* Header size is CH header rounded up to 512 bytes plus GP header */ #define OMAP_CH_HDR_SIZE 512 #define OMAP_FILE_HDR_SIZE (OMAP_CH_HDR_SIZE + GPIMAGE_HDR_SIZE) @@ -143,15 +144,17 @@ static void omapimage_set_header(void *ptr, struct stat *sbuf, int ifd, toc++; memset(toc, 0xff, sizeof(*toc)); - gph_set_header(gph, sbuf->st_size - OMAP_CH_HDR_SIZE + GPIMAGE_HDR_SIZE, + gph_set_header(gph, sbuf->st_size - OMAP_CH_HDR_SIZE, params->addr, 0); if (strncmp(params->imagename, "byteswap", 8) == 0) { do_swap32 = 1; int swapped = 0; uint32_t *data = (uint32_t *)ptr; + const off_t size_in_words = + DIV_ROUND_UP(sbuf->st_size, sizeof(uint32_t)); - while (swapped <= (sbuf->st_size / sizeof(uint32_t))) { + while (swapped < size_in_words) { *data = cpu_to_be32(*data); swapped++; data++;