Merge tag 'u-boot-rockchip-20200531' of https://gitlab.denx.de/u-boot/custodians...
[oweals/u-boot.git] / tools / pblimage.c
index 16d94c98c611d1b1992f320c5634cee04b054823..3c823e96cf17d127de25a0c42f18fed5a712eadc 100644 (file)
@@ -1,12 +1,12 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright 2012-2014 Freescale Semiconductor, Inc.
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 #include "imagetool.h"
 #include <image.h>
 #include "pblimage.h"
 #include "pbl_crc32.h"
+#include <u-boot/crc.h>
 
 #define roundup(x, y)          ((((x) + ((y) - 1)) / (y)) * (y))
 #define PBL_ACS_CONT_CMD       0x81000000
@@ -194,17 +194,20 @@ void pbl_load_uboot(int ifd, struct image_tool_params *params)
        pbl_parser(params->imagename);
 
        /* parse the pbi.cfg file. */
-       pbl_parser(params->imagename2);
+       if (params->imagename2[0] != '\0')
+               pbl_parser(params->imagename2);
+
+       if (params->datafile) {
+               fp_uboot = fopen(params->datafile, "r");
+               if (fp_uboot == NULL) {
+                       printf("Error: %s open failed\n", params->datafile);
+                       exit(EXIT_FAILURE);
+               }
 
-       fp_uboot = fopen(params->datafile, "r");
-       if (fp_uboot == NULL) {
-               printf("Error: %s open failed\n", params->datafile);
-               exit(EXIT_FAILURE);
+               load_uboot(fp_uboot);
+               fclose(fp_uboot);
        }
-
-       load_uboot(fp_uboot);
        add_end_cmd();
-       fclose(fp_uboot);
        lseek(ifd, 0, SEEK_SET);
 
        size = pbl_size;
@@ -265,21 +268,24 @@ int pblimage_check_params(struct image_tool_params *params)
        if (!params)
                return EXIT_FAILURE;
 
-       fp_uboot = fopen(params->datafile, "r");
-       if (fp_uboot == NULL) {
-               printf("Error: %s open failed\n", params->datafile);
-               exit(EXIT_FAILURE);
-       }
-       fd = fileno(fp_uboot);
+       if (params->datafile) {
+               fp_uboot = fopen(params->datafile, "r");
+               if (fp_uboot == NULL) {
+                       printf("Error: %s open failed\n", params->datafile);
+                       exit(EXIT_FAILURE);
+               }
+               fd = fileno(fp_uboot);
 
-       if (fstat(fd, &st) == -1) {
-               printf("Error: Could not determine u-boot image size. %s\n",
-                      strerror(errno));
-               exit(EXIT_FAILURE);
-       }
+               if (fstat(fd, &st) == -1) {
+                       printf("Error: Could not determine u-boot image size. %s\n",
+                              strerror(errno));
+                       exit(EXIT_FAILURE);
+               }
 
-       /* For the variable size, we need to pad it to 64 byte boundary */
-       uboot_size = roundup(st.st_size, 64);
+               /* For the variable size, pad it to 64 byte boundary */
+               uboot_size = roundup(st.st_size, 64);
+               fclose(fp_uboot);
+       }
 
        if (params->arch == IH_ARCH_ARM) {
                arch_flag = IH_ARCH_ARM;
@@ -287,7 +293,7 @@ int pblimage_check_params(struct image_tool_params *params)
                pbi_crc_cmd2 = 0;
                pbl_cmd_initaddr = params->addr & PBL_ADDR_24BIT_MASK;
                pbl_cmd_initaddr |= PBL_ACS_CONT_CMD;
-               pbl_cmd_initaddr |= uboot_size;
+               pbl_cmd_initaddr += uboot_size;
                pbl_end_cmd[0] = 0x09610000;
                pbl_end_cmd[1] = 0x00000000;
                pbl_end_cmd[2] = 0x096100c0;