#include <stdlib.h>
#include <string.h>
#include <linux/types.h>
+
#include <sys/stat.h>
#include <sys/types.h>
{
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);
}
#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
}
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");
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;
}
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;
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;
}
}
}
- /* 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);
}