arm: am335x: Enable SPL_OF_CONTROL on some configs
[platform/kernel/u-boot.git] / tools / mkeficapsule.c
index 426038e..4995ba4 100644 (file)
@@ -11,6 +11,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <linux/types.h>
+
 #include <sys/stat.h>
 #include <sys/types.h>
 
@@ -51,11 +52,12 @@ static void print_usage(void)
 {
        printf("Usage: %s [options] <output file>\n"
               "Options:\n"
-              "\t--fit <fit image>      new FIT image file\n"
-              "\t--raw <raw image>      new raw image file\n"
-              "\t--index <index>        update image index\n"
-              "\t--instance <instance>  update hardware instance\n"
-              "\t--help                 print a help message\n",
+
+              "\t-f, --fit <fit image>       new FIT image file\n"
+              "\t-r, --raw <raw image>       new raw image file\n"
+              "\t-i, --index <index>         update image index\n"
+              "\t-I, --instance <instance>   update hardware instance\n"
+              "\t-h, --help                  print a help message\n",
               tool_name);
 }
 
@@ -73,7 +75,7 @@ static int create_fwbin(char *path, char *bin, efi_guid_t *guid,
 
 #ifdef DEBUG
        printf("For output: %s\n", path);
-       printf("\tbin: %s\n\ttype: %pUl\n" bin, guid);
+       printf("\tbin: %s\n\ttype: %pUl\n", bin, guid);
        printf("\tindex: %ld\n\tinstance: %ld\n", index, instance);
 #endif
 
@@ -88,7 +90,7 @@ static int create_fwbin(char *path, char *bin, efi_guid_t *guid,
        }
        data = malloc(bin_stat.st_size);
        if (!data) {
-               printf("cannot allocate memory: %lx\n", bin_stat.st_size);
+               printf("cannot allocate memory: %zx\n", (size_t)bin_stat.st_size);
                goto err_1;
        }
        f = fopen(path, "w");
@@ -98,7 +100,8 @@ static int create_fwbin(char *path, char *bin, efi_guid_t *guid,
        }
        header.capsule_guid = efi_guid_fm_capsule;
        header.header_size = sizeof(header);
-       header.flags = CAPSULE_FLAGS_PERSIST_ACROSS_RESET; /* TODO */
+       /* TODO: The current implementation ignores flags */
+       header.flags = CAPSULE_FLAGS_PERSIST_ACROSS_RESET;
        header.capsule_image_size = sizeof(header)
                                        + sizeof(capsule) + sizeof(u64)
                                        + sizeof(image)
@@ -106,7 +109,7 @@ static int create_fwbin(char *path, char *bin, efi_guid_t *guid,
 
        size = fwrite(&header, 1, sizeof(header), f);
        if (size < sizeof(header)) {
-               printf("write failed (%lx)\n", size);
+               printf("write failed (%zx)\n", size);
                goto err_3;
        }
 
@@ -115,19 +118,22 @@ static int create_fwbin(char *path, char *bin, efi_guid_t *guid,
        capsule.payload_item_count = 1;
        size = fwrite(&capsule, 1, sizeof(capsule), f);
        if (size < (sizeof(capsule))) {
-               printf("write failed (%lx)\n", size);
+               printf("write failed (%zx)\n", size);
                goto err_3;
        }
        offset = sizeof(capsule) + sizeof(u64);
        size = fwrite(&offset, 1, sizeof(offset), f);
        if (size < sizeof(offset)) {
-               printf("write failed (%lx)\n", size);
+               printf("write failed (%zx)\n", size);
                goto err_3;
        }
 
        image.version = 0x00000003;
        memcpy(&image.update_image_type_id, guid, sizeof(*guid));
        image.update_image_index = index;
+       image.reserved[0] = 0;
+       image.reserved[1] = 0;
+       image.reserved[2] = 0;
        image.update_image_size = bin_stat.st_size;
        image.update_vendor_code_size = 0; /* none */
        image.update_hardware_instance = instance;
@@ -135,17 +141,17 @@ static int create_fwbin(char *path, char *bin, efi_guid_t *guid,
 
        size = fwrite(&image, 1, sizeof(image), f);
        if (size < sizeof(image)) {
-               printf("write failed (%lx)\n", size);
+               printf("write failed (%zx)\n", size);
                goto err_3;
        }
        size = fread(data, 1, bin_stat.st_size, g);
        if (size < bin_stat.st_size) {
-               printf("read failed (%lx)\n", size);
+               printf("read failed (%zx)\n", size);
                goto err_3;
        }
        size = fwrite(data, 1, bin_stat.st_size, f);
        if (size < bin_stat.st_size) {
-               printf("write failed (%lx)\n", size);
+               printf("write failed (%zx)\n", size);
                goto err_3;
        }
 
@@ -214,23 +220,23 @@ int main(int argc, char **argv)
                }
        }
 
-       /* need a output file */
+       /* need an output file */
        if (argc != optind + 1) {
                print_usage();
-               return -1;
+               exit(EXIT_FAILURE);
        }
 
        /* need a fit image file or raw image file */
        if (!file) {
                print_usage();
-               return -1;
+               exit(EXIT_SUCCESS);
        }
 
        if (create_fwbin(argv[optind], file, guid, index, instance)
                        < 0) {
                printf("Creating firmware capsule failed\n");
-               return -1;
+               exit(EXIT_FAILURE);
        }
 
-       return 0;
+       exit(EXIT_SUCCESS);
 }