+static uint32_t fsize(FILE *fp)
+{
+ int size, ret, origin;
+
+ origin = ftell(fp);
+ if (origin < 0) {
+ fprintf(stderr, "Incorrect file size\n");
+ fclose(fp);
+ exit(2);
+ }
+
+ ret = fseek(fp, 0L, SEEK_END);
+ if (ret) {
+ fprintf(stderr, "Incorrect file SEEK_END\n");
+ fclose(fp);
+ exit(3);
+ }
+
+ size = ftell(fp);
+ if (size < 0) {
+ fprintf(stderr, "Incorrect file size\n");
+ fclose(fp);
+ exit(4);
+ }
+
+ /* going back */
+ ret = fseek(fp, origin, SEEK_SET);
+ if (ret) {
+ fprintf(stderr, "Incorrect file SEEK_SET to %d\n", origin);
+ fclose(fp);
+ exit(3);
+ }
+
+ return size;
+}
+
+static void zynqmpimage_pmufw(struct zynqmp_header *zynqhdr,
+ const char *filename)
+{
+ uint32_t size;
+
+ /* Setup PMU fw size */
+ zynqhdr->pfw_image_length = fsize(fpmu);
+ zynqhdr->total_pfw_image_length = zynqhdr->pfw_image_length;
+
+ zynqhdr->image_size -= zynqhdr->pfw_image_length;
+ zynqhdr->image_stored_size -= zynqhdr->total_pfw_image_length;
+
+ /* Read the whole PMUFW to the header */
+ size = fread(&zynqhdr->__reserved4[66], 1,
+ zynqhdr->pfw_image_length, fpmu);
+ if (size != zynqhdr->pfw_image_length) {
+ fprintf(stderr, "Cannot read PMUFW file: %s\n", filename);
+ fclose(fpmu);
+ exit(1);
+ }
+
+ fclose(fpmu);
+}
+