From c738adb8dbbf28a34f8574239a241e85d46f3877 Mon Sep 17 00:00:00 2001 From: Kever Yang Date: Mon, 30 Mar 2020 11:56:17 +0800 Subject: tool: Move ALIGN_MASK to header as common MACRO The ALIGN code is need by many files who need handle structure or image align, so move the macro to imagetool.h file. Signed-off-by: Kever Yang Reviewed-by: Punit Agrawal Reviewed-by: Tom Rini --- tools/ifwitool.c | 4 +--- tools/imagetool.h | 3 +++ tools/imx8mimage.c | 2 -- tools/mksunxiboot.c | 4 +--- 4 files changed, 5 insertions(+), 8 deletions(-) (limited to 'tools') diff --git a/tools/ifwitool.c b/tools/ifwitool.c index 543e9d4e702..b2b06cc9219 100644 --- a/tools/ifwitool.c +++ b/tools/ifwitool.c @@ -8,15 +8,13 @@ #include #include #include +#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/imagetool.h b/tools/imagetool.h index e1c778b0dff..81e5cd0c5cc 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 */ diff --git a/tools/imx8mimage.c b/tools/imx8mimage.c index 2b0d946a7d7..7defb13962f 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) { diff --git a/tools/mksunxiboot.c b/tools/mksunxiboot.c index 1c8701e75ed..a18c9d98bc7 100644 --- a/tools/mksunxiboot.c +++ b/tools/mksunxiboot.c @@ -14,6 +14,7 @@ #include #include #include +#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)) -- cgit v1.2.3 From cd1cec6364cef9b38f4070ec7377757e757d50c4 Mon Sep 17 00:00:00 2001 From: Kever Yang Date: Mon, 30 Mar 2020 11:56:18 +0800 Subject: tool: aisimage: use ALIGN instead of self defiend macro The ALIGN() is available at imagetool.h, no need to self define one. Signed-off-by: Kever Yang Reviewed-by: Punit Agrawal Reviewed-by: Tom Rini --- tools/aisimage.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tools') diff --git a/tools/aisimage.c b/tools/aisimage.c index 4cd76ab843a..b8b3ee32070 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); -- cgit v1.2.3 From 29e7ab01866f44eec9dbe9ec7093eb1d1dda57d5 Mon Sep 17 00:00:00 2001 From: Kever Yang Date: Mon, 30 Mar 2020 11:56:19 +0800 Subject: tools: mkimage: use common ALIGN to do the size align The ALIGN() is now available at imagetool.h, migrate to use it. Signed-off-by: Kever Yang Reviewed-by: Punit Agrawal Reviewed-by: Tom Rini --- tools/mkimage.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'tools') diff --git a/tools/mkimage.c b/tools/mkimage.c index 5f51d2cc89f..0279f6867e9 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 @@ -557,8 +558,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 -- cgit v1.2.3 From e002ee7efc4a236f239aed54f89da913105ac6d5 Mon Sep 17 00:00:00 2001 From: Kever Yang Date: Mon, 30 Mar 2020 11:56:20 +0800 Subject: tools: kwbimage: use common ALIGN to do the size align The ALIGN() is now available at imagetool.h, migrate to use it. Signed-off-by: Kever Yang Reviewed-by: Punit Agrawal Reviewed-by: Tom Rini Reviewed-by: Stefan Roese --- tools/kwbimage.c | 8 ++++---- tools/kwbimage.h | 2 -- 2 files changed, 4 insertions(+), 6 deletions(-) (limited to 'tools') diff --git a/tools/kwbimage.c b/tools/kwbimage.c index b8f8d38212f..02fd0c949ff 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 25bc08c5ce5..0b6d05bef10 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 */ -- cgit v1.2.3 From e5ad99cc9924e374d9cedbec38b6303cb80d693f Mon Sep 17 00:00:00 2001 From: Kever Yang Date: Mon, 30 Mar 2020 11:56:21 +0800 Subject: tools: imx8mimage: remove redundant code The align for fit_size has been done twice, remove the first one for it does not make any sense. Signed-off-by: Kever Yang Reviewed-by: Punit Agrawal Reviewed-by: Tom Rini --- tools/imx8mimage.c | 1 - 1 file changed, 1 deletion(-) (limited to 'tools') diff --git a/tools/imx8mimage.c b/tools/imx8mimage.c index 7defb13962f..bc4ee793cb9 100644 --- a/tools/imx8mimage.c +++ b/tools/imx8mimage.c @@ -341,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); -- cgit v1.2.3 From 02560b13689650cf0d2f5825eaf480629ce9238f Mon Sep 17 00:00:00 2001 From: Kever Yang Date: Mon, 30 Mar 2020 11:56:22 +0800 Subject: tool: use ALIGN() to align the size Use the ALIGN() for size align so that the code is more readable. Signed-off-by: Kever Yang Reviewed-by: Punit Agrawal Reviewed-by: Tom Rini Reviewed-by: Heinrich Schuchardt --- tools/fit_image.c | 2 +- tools/socfpgaimage.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'tools') diff --git a/tools/fit_image.c b/tools/fit_image.c index 4301b5decbb..55efe12eeb8 100644 --- a/tools/fit_image.c +++ b/tools/fit_image.c @@ -547,7 +547,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; diff --git a/tools/socfpgaimage.c b/tools/socfpgaimage.c index 8fa098338b2..6dfd64e31dd 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); -- cgit v1.2.3 From ebfe611be91e0075c040588a30a9996519d30aa6 Mon Sep 17 00:00:00 2001 From: Kever Yang Date: Mon, 30 Mar 2020 11:56:24 +0800 Subject: mkimage: fit_image: Add option to make fit header align The image is usually stored in block device like emmc, SD card, make the offset of image data aligned to block(512 byte) can avoid data copy during boot process. eg. SPL boot from FIT image with external data: - SPL read the first block of FIT image, and then parse the header; - SPL read image data separately; - The first image offset is the base_offset which is the header size; - The second image offset is just after the first image; - If the offset of imge does not aligned, SPL will do memcpy; The header size is a ramdon number, which is very possible not aligned, so add '-B size'to specify the align size in hex for better performance. example usage: ./tools/mkimage -E -f u-boot.its -B 0x200 u-boot.itb Signed-off-by: Kever Yang Reviewed-by: Punit Agrawal Reviewed-by: Tom Rini --- tools/fit_image.c | 33 ++++++++++++++++++++------------- tools/imagetool.h | 1 + tools/mkimage.c | 14 ++++++++++++-- 3 files changed, 33 insertions(+), 15 deletions(-) (limited to 'tools') diff --git a/tools/fit_image.c b/tools/fit_image.c index 55efe12eeb8..f32ee49575b 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)) { diff --git a/tools/imagetool.h b/tools/imagetool.h index 81e5cd0c5cc..f54809cd578 100644 --- a/tools/imagetool.h +++ b/tools/imagetool.h @@ -79,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/mkimage.c b/tools/mkimage.c index 0279f6867e9..336376f8d0a 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -98,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 ] [-p addr] [-r] [-N engine]\n" + "Signing / verified boot options: [-E] [-B size] [-k keydir] [-K dtb] [ -c ] [-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" @@ -144,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 +169,15 @@ static void process_args(int argc, char **argv) params.cmdname, optarg); 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; -- cgit v1.2.3 From b21c08a12b8ebeea0cb77830d662ee118245774e Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sat, 11 Apr 2020 18:36:04 +0200 Subject: tools: image-host.c: use correct output format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When building on a 32bit host the following warning occurs: tools/image-host.c: In function ‘fit_image_read_data’: tools/image-host.c:310:42: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 3 has type ‘ssize_t’ {aka ‘int’} [-Wformat=] printf("Can't read all file %s (read %ld bytes, expexted %ld)\n", ~~^ %d filename, n, sbuf.st_size); ~ n is of type ssize_t so we should use %zd for printing. Fixes: 7298e422504e ("mkimage: fit: add support to encrypt image with aes") Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- tools/image-host.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/image-host.c b/tools/image-host.c index 4e57ddea969..5bb68965e76 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; } -- cgit v1.2.3 From 3b32cf096bd6b1d8871ecaddb4250756242fb5f9 Mon Sep 17 00:00:00 2001 From: Bin Meng Date: Sat, 18 Apr 2020 01:59:09 -0700 Subject: tools: Remove the out-of-date MinGW support codes MinGW build for U-Boot tools has been broken for years. The official support of Windows build is now MSYS2. Remove the MinGW support codes. Signed-off-by: Bin Meng --- tools/mingw_support.c | 113 -------------------------------------------------- tools/mingw_support.h | 45 -------------------- tools/os_support.c | 7 ++-- tools/os_support.h | 3 -- 4 files changed, 3 insertions(+), 165 deletions(-) delete mode 100644 tools/mingw_support.c delete mode 100644 tools/mingw_support.h (limited to 'tools') diff --git a/tools/mingw_support.c b/tools/mingw_support.c deleted file mode 100644 index 2b17bf7dd28..00000000000 --- 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 - * Parts by Kees Zeelenberg (LibGW32C) - */ - -#include "mingw_support.h" -#include -#include -#include -#include -#include -#include - -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 e0b8ac3ebc9..00000000000 --- 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 - -/* 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/os_support.c b/tools/os_support.c index 21e43c876a9..6890c3183f6 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 3a2106ed7e5..471d605f5c5 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" -- cgit v1.2.3 From 3fc85a782a3d46fcb32bfb93829d2424d696c4d3 Mon Sep 17 00:00:00 2001 From: Lihua Zhao Date: Sat, 18 Apr 2020 01:59:10 -0700 Subject: mkimage: fit: Unmmap the memory before closing fd in fit_import_data() Without calling munmap(), the follow-up call to open() the same file with a flag O_TRUNC seems not to cause any issue on Linux, but it fails on Windows with error like below: Can't open kernel_fdt.itb.tmp: Permission denied Fix this by unmapping the memory before closing fd in fit_import_data(). Signed-off-by: Lihua Zhao Signed-off-by: Bin Meng --- tools/fit_image.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'tools') diff --git a/tools/fit_image.c b/tools/fit_image.c index f32ee49575b..c37cae3b260 100644 --- a/tools/fit_image.c +++ b/tools/fit_image.c @@ -563,21 +563,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); @@ -598,10 +598,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); @@ -616,22 +618,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; } -- cgit v1.2.3 From 0dbd6e3698b58f60cddb64a0d58a4e23fb5f55d3 Mon Sep 17 00:00:00 2001 From: Bin Meng Date: Sat, 18 Apr 2020 01:59:11 -0700 Subject: mkimage: fit: Free buf directly in fit_extract_data() If given ptr to free() is NULL, no operation is performed. Hence we can just free buf directly in fit_extract_data(). Signed-off-by: Bin Meng --- tools/fit_image.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'tools') diff --git a/tools/fit_image.c b/tools/fit_image.c index c37cae3b260..4aeabbcfe97 100644 --- a/tools/fit_image.c +++ b/tools/fit_image.c @@ -534,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; } -- cgit v1.2.3