diff options
Diffstat (limited to 'tools/fiptool')
-rw-r--r-- | tools/fiptool/Makefile | 5 | ||||
-rw-r--r-- | tools/fiptool/Makefile.msvc | 67 | ||||
-rw-r--r-- | tools/fiptool/fiptool.c | 74 | ||||
-rw-r--r-- | tools/fiptool/fiptool.h | 2 | ||||
-rw-r--r-- | tools/fiptool/tbbr_config.c | 17 | ||||
-rw-r--r-- | tools/fiptool/win_posix.c | 91 | ||||
-rw-r--r-- | tools/fiptool/win_posix.h | 8 |
7 files changed, 160 insertions, 104 deletions
diff --git a/tools/fiptool/Makefile b/tools/fiptool/Makefile index ef3501432..df8ab5c7b 100644 --- a/tools/fiptool/Makefile +++ b/tools/fiptool/Makefile @@ -1,5 +1,5 @@ # -# Copyright (c) 2014-2018, ARM Limited and Contributors. All rights reserved. +# Copyright (c) 2014-2020, ARM Limited and Contributors. All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause # @@ -8,7 +8,8 @@ MAKE_HELPERS_DIRECTORY := ../../make_helpers/ include ${MAKE_HELPERS_DIRECTORY}build_macros.mk include ${MAKE_HELPERS_DIRECTORY}build_env.mk -PROJECT := fiptool${BIN_EXT} +FIPTOOL ?= fiptool${BIN_EXT} +PROJECT := $(notdir ${FIPTOOL}) OBJECTS := fiptool.o tbbr_config.o V ?= 0 diff --git a/tools/fiptool/Makefile.msvc b/tools/fiptool/Makefile.msvc index 58dbb8973..9081bc64c 100644 --- a/tools/fiptool/Makefile.msvc +++ b/tools/fiptool/Makefile.msvc @@ -1,30 +1,37 @@ -#
-# Copyright (c) 2019, Arm Limited. All rights reserved.
-#
-# SPDX-License-Identifier: BSD-3-Clause
-#
-
-CC = cl.exe
-LD = link.exe
-
-FIPTOOL = fiptool.exe
-OBJECTS = fiptool.obj tbbr_config.obj win_posix.obj
-
-INC = -I. -I..\..\include\tools_share
-CFLAGS = $(CFLAGS) /nologo /Za /Zi /c /O2 /MT
-
-all: $(FIPTOOL)
-
-$(FIPTOOL): $(OBJECTS)
- $(LD) /INCREMENTAL:NO /debug /nodefaultlib:libc.lib /out:$@ $(LIBS) $**
-
-.PHONY: clean realclean
-
-clean:
- del /f /q $(OBJECTS) > nul
-
-realclean:
- del /f /q $(OBJECTS) $(FIPTOOL) > nul
-
-.c.obj:
- $(CC) -c $(CFLAGS) $(INC) $< -Fo$@
+# +# Copyright (c) 2019-2020, Arm Limited. All rights reserved. +# +# SPDX-License-Identifier: BSD-3-Clause +# + +CC = cl.exe +LD = link.exe + +# FIPTOOLPATH and FIPTOOL are passed from the main makefile. + +OBJECTS = $(FIPTOOLPATH)\fiptool.obj \ + $(FIPTOOLPATH)\tbbr_config.obj \ + $(FIPTOOLPATH)\win_posix.obj + +INC = -I$(FIPTOOLPATH) -Iinclude\tools_share + +CFLAGS = $(CFLAGS) /nologo /Za /Zi /c /O2 /MT + +all: $(FIPTOOL) + +$(FIPTOOL): $(OBJECTS) + $(LD) /nologo /INCREMENTAL:NO /debug /nodefaultlib:libc.lib /out:$@ $(LIBS) $** + +.PHONY: clean realclean + +clean: + -@del /f /q $(OBJECTS) > nul + -@del /f /q $(FIPTOOLPATH)\*.pdb > nul + +realclean: + -@del /f /q $(OBJECTS) > nul + -@del /f /q $(FIPTOOLPATH)\*.pdb > nul + -@del /f /q $(FIPTOOL) > nul + +.c.obj: + $(CC) -c $(CFLAGS) $(INC) $< -Fo$@ diff --git a/tools/fiptool/fiptool.c b/tools/fiptool/fiptool.c index 80b498e47..8c5b04a55 100644 --- a/tools/fiptool/fiptool.c +++ b/tools/fiptool/fiptool.c @@ -24,17 +24,17 @@ #define OPT_ALIGN 2 static int info_cmd(int argc, char *argv[]); -static void info_usage(void); +static void info_usage(int); static int create_cmd(int argc, char *argv[]); -static void create_usage(void); +static void create_usage(int); static int update_cmd(int argc, char *argv[]); -static void update_usage(void); +static void update_usage(int); static int unpack_cmd(int argc, char *argv[]); -static void unpack_usage(void); +static void unpack_usage(int); static int remove_cmd(int argc, char *argv[]); -static void remove_usage(void); +static void remove_usage(int); static int version_cmd(int argc, char *argv[]); -static void version_usage(void); +static void version_usage(int); static int help_cmd(int argc, char *argv[]); static void usage(void); @@ -448,7 +448,7 @@ static int info_cmd(int argc, char *argv[]) fip_toc_header_t toc_header; if (argc != 2) - info_usage(); + info_usage(EXIT_FAILURE); argc--, argv++; parse_fip(argv[0], &toc_header); @@ -487,10 +487,10 @@ static int info_cmd(int argc, char *argv[]) return 0; } -static void info_usage(void) +static void info_usage(int exit_status) { printf("fiptool info FIP_FILENAME\n"); - exit(1); + exit(exit_status); } static int pack_images(const char *filename, uint64_t toc_flags, unsigned long align) @@ -669,7 +669,7 @@ static int create_cmd(int argc, char *argv[]) unsigned long align = 1; if (argc < 2) - create_usage(); + create_usage(EXIT_FAILURE); opts = fill_common_opts(opts, &nr_opts, required_argument); opts = add_opt(opts, &nr_opts, "plat-toc-flags", required_argument, @@ -710,7 +710,7 @@ static int create_cmd(int argc, char *argv[]) if (memcmp(&uuid, &uuid_null, sizeof(uuid_t)) == 0 || filename[0] == '\0') - create_usage(); + create_usage(EXIT_FAILURE); desc = lookup_image_desc_from_uuid(&uuid); if (desc == NULL) { @@ -722,7 +722,7 @@ static int create_cmd(int argc, char *argv[]) break; } default: - create_usage(); + create_usage(EXIT_FAILURE); } } argc -= optind; @@ -730,7 +730,7 @@ static int create_cmd(int argc, char *argv[]) free(opts); if (argc == 0) - create_usage(); + create_usage(EXIT_SUCCESS); update_fip(); @@ -738,7 +738,7 @@ static int create_cmd(int argc, char *argv[]) return 0; } -static void create_usage(void) +static void create_usage(int exit_status) { toc_entry_t *toc_entry = toc_entries; @@ -753,7 +753,7 @@ static void create_usage(void) for (; toc_entry->cmdline_name != NULL; toc_entry++) printf(" --%-16s FILENAME\t%s\n", toc_entry->cmdline_name, toc_entry->name); - exit(1); + exit(exit_status); } static int update_cmd(int argc, char *argv[]) @@ -767,7 +767,7 @@ static int update_cmd(int argc, char *argv[]) int pflag = 0; if (argc < 2) - update_usage(); + update_usage(EXIT_FAILURE); opts = fill_common_opts(opts, &nr_opts, required_argument); opts = add_opt(opts, &nr_opts, "align", required_argument, OPT_ALIGN); @@ -807,7 +807,7 @@ static int update_cmd(int argc, char *argv[]) if (memcmp(&uuid, &uuid_null, sizeof(uuid_t)) == 0 || filename[0] == '\0') - update_usage(); + update_usage(EXIT_FAILURE); desc = lookup_image_desc_from_uuid(&uuid); if (desc == NULL) { @@ -825,7 +825,7 @@ static int update_cmd(int argc, char *argv[]) snprintf(outfile, sizeof(outfile), "%s", optarg); break; default: - update_usage(); + update_usage(EXIT_FAILURE); } } argc -= optind; @@ -833,7 +833,7 @@ static int update_cmd(int argc, char *argv[]) free(opts); if (argc == 0) - update_usage(); + update_usage(EXIT_SUCCESS); if (outfile[0] == '\0') snprintf(outfile, sizeof(outfile), "%s", argv[0]); @@ -851,7 +851,7 @@ static int update_cmd(int argc, char *argv[]) return 0; } -static void update_usage(void) +static void update_usage(int exit_status) { toc_entry_t *toc_entry = toc_entries; @@ -867,7 +867,7 @@ static void update_usage(void) for (; toc_entry->cmdline_name != NULL; toc_entry++) printf(" --%-16s FILENAME\t%s\n", toc_entry->cmdline_name, toc_entry->name); - exit(1); + exit(exit_status); } static int unpack_cmd(int argc, char *argv[]) @@ -880,7 +880,7 @@ static int unpack_cmd(int argc, char *argv[]) int unpack_all = 1; if (argc < 2) - unpack_usage(); + unpack_usage(EXIT_FAILURE); opts = fill_common_opts(opts, &nr_opts, required_argument); opts = add_opt(opts, &nr_opts, "blob", required_argument, 'b'); @@ -915,7 +915,7 @@ static int unpack_cmd(int argc, char *argv[]) if (memcmp(&uuid, &uuid_null, sizeof(uuid_t)) == 0 || filename[0] == '\0') - unpack_usage(); + unpack_usage(EXIT_FAILURE); desc = lookup_image_desc_from_uuid(&uuid); if (desc == NULL) { @@ -934,7 +934,7 @@ static int unpack_cmd(int argc, char *argv[]) snprintf(outdir, sizeof(outdir), "%s", optarg); break; default: - unpack_usage(); + unpack_usage(EXIT_FAILURE); } } argc -= optind; @@ -942,7 +942,7 @@ static int unpack_cmd(int argc, char *argv[]) free(opts); if (argc == 0) - unpack_usage(); + unpack_usage(EXIT_SUCCESS); parse_fip(argv[0], NULL); @@ -986,7 +986,7 @@ static int unpack_cmd(int argc, char *argv[]) return 0; } -static void unpack_usage(void) +static void unpack_usage(int exit_status) { toc_entry_t *toc_entry = toc_entries; @@ -1003,7 +1003,7 @@ static void unpack_usage(void) toc_entry->name); printf("\n"); printf("If no options are provided, all images will be unpacked.\n"); - exit(1); + exit(exit_status); } static int remove_cmd(int argc, char *argv[]) @@ -1017,7 +1017,7 @@ static int remove_cmd(int argc, char *argv[]) int fflag = 0; if (argc < 2) - remove_usage(); + remove_usage(EXIT_FAILURE); opts = fill_common_opts(opts, &nr_opts, no_argument); opts = add_opt(opts, &nr_opts, "align", required_argument, OPT_ALIGN); @@ -1053,7 +1053,7 @@ static int remove_cmd(int argc, char *argv[]) filename, sizeof(filename)); if (memcmp(&uuid, &uuid_null, sizeof(uuid_t)) == 0) - remove_usage(); + remove_usage(EXIT_FAILURE); desc = lookup_image_desc_from_uuid(&uuid); if (desc == NULL) { @@ -1071,7 +1071,7 @@ static int remove_cmd(int argc, char *argv[]) snprintf(outfile, sizeof(outfile), "%s", optarg); break; default: - remove_usage(); + remove_usage(EXIT_FAILURE); } } argc -= optind; @@ -1079,7 +1079,7 @@ static int remove_cmd(int argc, char *argv[]) free(opts); if (argc == 0) - remove_usage(); + remove_usage(EXIT_SUCCESS); if (outfile[0] != '\0' && access(outfile, F_OK) == 0 && !fflag) log_errx("File %s already exists, use --force to overwrite it", @@ -1110,7 +1110,7 @@ static int remove_cmd(int argc, char *argv[]) return 0; } -static void remove_usage(void) +static void remove_usage(int exit_status) { toc_entry_t *toc_entry = toc_entries; @@ -1126,7 +1126,7 @@ static void remove_usage(void) for (; toc_entry->cmdline_name != NULL; toc_entry++) printf(" --%-16s\t%s\n", toc_entry->cmdline_name, toc_entry->name); - exit(1); + exit(exit_status); } static int version_cmd(int argc, char *argv[]) @@ -1140,10 +1140,10 @@ static int version_cmd(int argc, char *argv[]) return 0; } -static void version_usage(void) +static void version_usage(int exit_status) { printf("fiptool version\n"); - exit(1); + exit(exit_status); } static int help_cmd(int argc, char *argv[]) @@ -1157,7 +1157,7 @@ static int help_cmd(int argc, char *argv[]) for (i = 0; i < NELEM(cmds); i++) { if (strcmp(cmds[i].name, argv[0]) == 0 && cmds[i].usage != NULL) - cmds[i].usage(); + cmds[i].usage(EXIT_SUCCESS); } if (i == NELEM(cmds)) printf("No help for subcommand '%s'\n", argv[0]); @@ -1178,7 +1178,7 @@ static void usage(void) printf(" remove\tRemove images from FIP.\n"); printf(" version\tShow fiptool version.\n"); printf(" help\t\tShow help for given command.\n"); - exit(1); + exit(EXIT_SUCCESS); } int main(int argc, char *argv[]) diff --git a/tools/fiptool/fiptool.h b/tools/fiptool/fiptool.h index af3fcbdee..88c4a7edb 100644 --- a/tools/fiptool/fiptool.h +++ b/tools/fiptool/fiptool.h @@ -48,7 +48,7 @@ typedef struct image { typedef struct cmd { char *name; int (*handler)(int, char **); - void (*usage)(void); + void (*usage)(int); } cmd_t; #endif /* FIPTOOL_H */ diff --git a/tools/fiptool/tbbr_config.c b/tools/fiptool/tbbr_config.c index 86b8581f8..c1e5217f0 100644 --- a/tools/fiptool/tbbr_config.c +++ b/tools/fiptool/tbbr_config.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2018, ARM Limited and Contributors. All rights reserved. + * Copyright (c) 2016-2020, ARM Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -69,6 +69,11 @@ toc_entry_t toc_entries[] = { }, /* Dynamic Configs */ { + .name = "FW_CONFIG", + .uuid = UUID_FW_CONFIG, + .cmdline_name = "fw-config" + }, + { .name = "HW_CONFIG", .uuid = UUID_HW_CONFIG, .cmdline_name = "hw-config" @@ -152,6 +157,16 @@ toc_entry_t toc_entries[] = { .cmdline_name = "nt-fw-cert" }, { + .name = "SiP owned Secure Partition content certificate", + .uuid = UUID_SIP_SECURE_PARTITION_CONTENT_CERT, + .cmdline_name = "sip-sp-cert" + }, + { + .name = "Platform owned Secure Partition content certificate", + .uuid = UUID_PLAT_SECURE_PARTITION_CONTENT_CERT, + .cmdline_name = "plat-sp-cert" + }, + { .name = NULL, .uuid = { {0} }, .cmdline_name = NULL, diff --git a/tools/fiptool/win_posix.c b/tools/fiptool/win_posix.c index 48feb162e..33b44d4c6 100644 --- a/tools/fiptool/win_posix.c +++ b/tools/fiptool/win_posix.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved. + * Copyright (c) 2017 - 2020, Arm Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -137,7 +137,8 @@ int getopt(int argc, * Note that we only match over the shorter length of the pair, to allow * for abbreviation or say --match=value * Long option names may be abbreviated if the abbreviation is unique or an - * exact match for some defined option. + * exact match for some defined option. This function does not check that the + * abbreviations are unique and should be handled by the caller. * A long option may take a parameter, of the form --opt=param or --opt param. */ static @@ -160,42 +161,72 @@ int getopt_1long(const int argc, { int result = RET_UNKNOWN_OPT; size_t loptn = 0; + bool match_found = false; - while (longopts[loptn].name != 0) { - if (optmatch(optname, longopts[loptn].name) == 0) { - /* We found a match. */ - result = longopts[loptn].val; - if (indexptr != 0) - *indexptr = loptn; - switch (longopts[loptn].has_arg) { - case required_argument: - if ((optind + 1) >= argc) { - /* Missing argument. */ - optopt = result; - return RET_NO_PARAM; - } - /* Fallthrough to get option value. */ + /* + * Long option names may be abbreviated if the abbreviation + * is unique or an exact match for some defined option. + * To handle this: + * - First search for an exact match. + * - If exact match was not found search for a abbreviated match. + * By doing this an incorrect option selection can be avoided. + */ - case optional_argument: - if ((argc - optind) > 0) { - /* Found argument. */ - optarg = argv[++optind]; - } - /* Fallthrough to handle flag. */ + /* 1. Search for an exact match. */ + while (longopts[loptn].name != NULL) { + if (strcmp(optname, longopts[loptn].name) == 0) { + match_found = true; + break; + } + ++loptn; + } - case no_argument: - optind++; - if (longopts[loptn].flag != 0) { - *longopts[loptn].flag = result; - result = 0; - } + /* 2. If exact match was not found search for a abbreviated match. */ + if (!match_found) { + loptn = 0; + while (longopts[loptn].name != NULL) { + if (optmatch(optname, longopts[loptn].name) == 0) { + match_found = true; break; + } + ++loptn; + } + } + + if (match_found) { + /* We found a match. */ + result = longopts[loptn].val; + if (indexptr != 0) { + *indexptr = loptn; + } + switch (longopts[loptn].has_arg) { + case required_argument: + if ((optind + 1) >= argc) { + /* Missing argument. */ + optopt = result; + return RET_NO_PARAM; + } + /* Fallthrough to get option value. */ + case optional_argument: + if ((argc - optind) > 0) { + /* Found argument. */ + optarg = argv[++optind]; } - return result; + /* Fallthrough to handle flag. */ + + case no_argument: + optind++; + if (longopts[loptn].flag != 0) { + *longopts[loptn].flag = result; + result = 0; + } + break; + } - ++loptn; + return result; } + /* * If getopt finds an option character in argv that was not included * in options, ... it returns '?' and sets the external variable diff --git a/tools/fiptool/win_posix.h b/tools/fiptool/win_posix.h index 836ffed31..6f0d8e6b6 100644 --- a/tools/fiptool/win_posix.h +++ b/tools/fiptool/win_posix.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved. + * Copyright (c) 2017-2020, Arm Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -9,13 +9,15 @@ #define _CRT_SECURE_NO_WARNINGS -#include <direct.h> -#include <io.h> +#include <stdbool.h> #include <stdint.h> #include <stdlib.h> #include <string.h> #include <sys/stat.h> +#include <direct.h> +#include <io.h> + #include "uuid.h" /* Derive or provide Windows equivalents of Posix/GCC/Unix stuff. */ |