apalis_t30: describe pcie ports
[oweals/u-boot.git] / tools / zynqmpimage.c
index 9667b11b2f8a5a235c352255b57aeee37b570718..421558d46e328155d87e7d63e2e18d1b1b636768 100644 (file)
@@ -1,9 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright (C) 2016 Michal Simek <michals@xilinx.com>
  * Copyright (C) 2015 Nathan Rossi <nathan@nathanrossi.com>
  *
- * SPDX-License-Identifier:    GPL-2.0+
- *
  * The following Boot Header format/structures and values are defined in the
  * following documents:
  *   * ug1085 ZynqMP TRM doc v1.4 (Chapter 11, Table 11-4)
@@ -178,7 +177,7 @@ static void zynqmpimage_print_header(const void *ptr)
        struct zynqmp_header *zynqhdr = (struct zynqmp_header *)ptr;
        int i;
 
-       printf("Image Type   : Xilinx Zynq Boot Image support\n");
+       printf("Image Type   : Xilinx ZynqMP Boot Image support\n");
        printf("Image Offset : 0x%08x\n", le32_to_cpu(zynqhdr->image_offset));
        printf("Image Size   : %lu bytes (%lu bytes packed)\n",
               (unsigned long)le32_to_cpu(zynqhdr->image_size),
@@ -245,16 +244,38 @@ static int zynqmpimage_check_image_types(uint8_t type)
        return EXIT_FAILURE;
 }
 
-static int fsize(FILE *fp)
+static uint32_t fsize(FILE *fp)
 {
-       int size;
-       int origin = ftell(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);
+       }
 
-       fseek(fp, 0L, SEEK_END);
        size = ftell(fp);
+       if (size < 0) {
+               fprintf(stderr, "Incorrect file size\n");
+               fclose(fp);
+               exit(4);
+       }
 
        /* going back */
-       fseek(fp, origin, SEEK_SET);
+       ret = fseek(fp, origin, SEEK_SET);
+       if (ret) {
+               fprintf(stderr, "Incorrect file SEEK_SET to %d\n", origin);
+               fclose(fp);
+               exit(3);
+       }
 
        return size;
 }