mkimage: Allow display of a list of any image header category
[platform/kernel/u-boot.git] / tools / mkimage.c
index aefe22f..d375c2a 100644 (file)
@@ -25,6 +25,49 @@ static struct image_tool_params params = {
        .imagename2 = "",
 };
 
+static enum ih_category cur_category;
+
+static int h_compare_category_name(const void *vtype1, const void *vtype2)
+{
+       const int *type1 = vtype1;
+       const int *type2 = vtype2;
+       const char *name1 = genimg_get_cat_short_name(cur_category, *type1);
+       const char *name2 = genimg_get_cat_short_name(cur_category, *type2);
+
+       return strcmp(name1, name2);
+}
+
+int show_valid_options(enum ih_category category)
+{
+       int *order;
+       int count;
+       int item;
+       int i;
+
+       count = genimg_get_cat_count(category);
+       order = calloc(count, sizeof(*order));
+       if (!order)
+               return -ENOMEM;
+
+       /* Sort the names in order of short name for easier reading */
+       for (item = 0; item < count; item++)
+               order[item] = item;
+       cur_category = category;
+       qsort(order, count, sizeof(int), h_compare_category_name);
+
+       fprintf(stderr, "\nInvalid %s, supported are:\n",
+               genimg_get_cat_desc(category));
+       for (i = 0; i < count; i++) {
+               item = order[i];
+               fprintf(stderr, "\t%-15s  %s\n",
+                       genimg_get_cat_short_name(category, item),
+                       genimg_get_cat_name(category, item));
+       }
+       fprintf(stderr, "\n");
+
+       return 0;
+}
+
 static int h_compare_image_name(const void *vtype1, const void *vtype2)
 {
        const int *type1 = vtype1;
@@ -93,11 +136,13 @@ static void usage(const char *msg)
                "          -f => input filename for FIT source\n");
 #ifdef CONFIG_FIT_SIGNATURE
        fprintf(stderr,
-               "Signing / verified boot options: [-k keydir] [-K dtb] [ -c <comment>] [-r]\n"
+               "Signing / verified boot options: [-E] [-k keydir] [-K dtb] [ -c <comment>] [-p addr] [-r]\n"
+               "          -E => place data outside of the FIT structure\n"
                "          -k => set directory containing private keys\n"
                "          -K => write public keys to this .dtb file\n"
                "          -c => add comment in signature node\n"
                "          -F => re-sign existing FIT image\n"
+               "          -p => place external data at a static position\n"
                "          -r => mark keys used as 'required' in dtb\n");
 #else
        fprintf(stderr,
@@ -136,7 +181,7 @@ static void process_args(int argc, char **argv)
        int opt;
 
        while ((opt = getopt(argc, argv,
-                            "a:A:b:cC:d:D:e:Ef:Fk:K:ln:O:rR:qsT:vVx")) != -1) {
+                            "a:A:b:cC:d:D:e:Ef:Fk:K:ln:p:O:rR:qsT:vVx")) != -1) {
                switch (opt) {
                case 'a':
                        params.addr = strtoull(optarg, &ptr, 16);
@@ -195,7 +240,6 @@ static void process_args(int argc, char **argv)
                         * The flattened image tree (FIT) format
                         * requires a flattened device tree image type
                         */
-                       params.fit_image_type = params.type;
                        params.type = IH_TYPE_FLATDT;
                        params.fflag = 1;
                        break;
@@ -216,6 +260,13 @@ static void process_args(int argc, char **argv)
                        if (params.os < 0)
                                usage("Invalid operating system");
                        break;
+               case 'p':
+                       params.external_offset = strtoull(optarg, &ptr, 16);
+                       if (*ptr) {
+                               fprintf(stderr, "%s: invalid offset size %s\n",
+                                       params.cmdname, optarg);
+                               exit(EXIT_FAILURE);
+                       }
                case 'q':
                        params.quiet = 1;
                        break;
@@ -263,9 +314,12 @@ static void process_args(int argc, char **argv)
         * will always be IH_TYPE_FLATDT in this case).
         */
        if (params.type == IH_TYPE_FLATDT) {
-               params.fit_image_type = type;
+               params.fit_image_type = type ? type : IH_TYPE_KERNEL;
+               /* For auto_its, datafile is always 'auto' */
                if (!params.auto_its)
                        params.datafile = datafile;
+               else if (!params.datafile)
+                       usage("Missing data file for auto-FIT (use -d)");
        } else if (type != IH_TYPE_INVALID) {
                params.type = type;
        }
@@ -274,7 +328,6 @@ static void process_args(int argc, char **argv)
                usage("Missing output filename");
 }
 
-
 int main(int argc, char **argv)
 {
        int ifd = -1;