]> git.sur5r.net Git - u-boot/blobdiff - tools/pblimage.c
Merge branch 'master' of git://git.denx.de/u-boot-sunxi
[u-boot] / tools / pblimage.c
index 2a799ab4b64eb9214c1a38b317d782cd5fe1e0ea..d11f9afe24521cb78c2298c31c4700595b76f397 100644 (file)
@@ -1,7 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright 2012-2014 Freescale Semiconductor, Inc.
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 #include "imagetool.h"
 #include <image.h>
@@ -194,17 +193,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 +267,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 +292,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;
@@ -297,7 +302,7 @@ int pblimage_check_params(struct image_tool_params *params)
                pbi_crc_cmd1 = 0x13;
                pbi_crc_cmd2 = 0x80;
                pbl_cmd_initaddr = 0x82000000;
-               pbl_end_cmd[0] = 0x09138000;
+               pbl_end_cmd[0] = 0x091380c0;
                pbl_end_cmd[1] = 0x00000000;
                pbl_end_cmd[2] = 0x091380c0;
                pbl_end_cmd[3] = 0x00000000;
@@ -308,19 +313,17 @@ int pblimage_check_params(struct image_tool_params *params)
 };
 
 /* pblimage parameters */
-static struct image_type_params pblimage_params = {
-       .name           = "Freescale PBL Boot Image support",
-       .header_size    = sizeof(struct pbl_header),
-       .hdr            = (void *)&pblimage_header,
-       .check_image_type = pblimage_check_image_types,
-       .check_params   = pblimage_check_params,
-       .verify_header  = pblimage_verify_header,
-       .print_header   = pblimage_print_header,
-       .set_header     = pblimage_set_header,
-};
-
-void init_pbl_image_type(void)
-{
-       pbl_size = 0;
-       register_image_type(&pblimage_params);
-}
+U_BOOT_IMAGE_TYPE(
+       pblimage,
+       "Freescale PBL Boot Image support",
+       sizeof(struct pbl_header),
+       (void *)&pblimage_header,
+       pblimage_check_params,
+       pblimage_verify_header,
+       pblimage_print_header,
+       pblimage_set_header,
+       NULL,
+       pblimage_check_image_types,
+       NULL,
+       NULL
+);