]> git.ipfire.org Git - u-boot.git/blobdiff - tools/zynqimage.c
Merge git://git.denx.de/u-boot-mmc
[u-boot.git] / tools / zynqimage.c
index 25f558d24c789c0dbf119db88dff156ab4fdbb85..021d2d3fc91f0ae515b160b33a56a8872fd5dda2 100644 (file)
@@ -212,8 +212,7 @@ static int zynqimage_check_params(struct image_tool_params *params)
                return -1;
        }
 
-       return !((params->lflag || params->dflag) ||
-                       (params->dflag && params->eflag));
+       return !(params->lflag || params->dflag);
 }
 
 static int zynqimage_check_image_types(uint8_t type)
@@ -223,6 +222,44 @@ static int zynqimage_check_image_types(uint8_t type)
        return EXIT_FAILURE;
 }
 
+static void zynqimage_parse_initparams(struct zynq_header *zynqhdr,
+       const char *filename)
+{
+       FILE *fp;
+       struct zynq_reginit reginit;
+       unsigned int reg_count = 0;
+       int r, err;
+       struct stat path_stat;
+
+       /* Expect a table of register-value pairs, e.g. "0x12345678 0x4321" */
+       fp = fopen(filename, "r");
+       if (!fp) {
+               fprintf(stderr, "Cannot open initparams file: %s\n", filename);
+               exit(1);
+       }
+
+       err = fstat(fileno(fp), &path_stat);
+       if (err) {
+               fclose(fp);
+               return;
+       }
+
+       if (!S_ISREG(path_stat.st_mode)) {
+               fclose(fp);
+               return;
+       }
+
+       do {
+               r = fscanf(fp, "%x %x", &reginit.address, &reginit.data);
+               if (r == 2) {
+                       zynqhdr->register_init[reg_count] = reginit;
+                       ++reg_count;
+               }
+               r = fscanf(fp, "%*[^\n]\n"); /* Skip to next line */
+       } while ((r != EOF) && (reg_count < HEADER_REGINITS));
+       fclose(fp);
+}
+
 static void zynqimage_set_header(void *ptr, struct stat *sbuf, int ifd,
                struct image_tool_params *params)
 {
@@ -238,6 +275,10 @@ static void zynqimage_set_header(void *ptr, struct stat *sbuf, int ifd,
        if (params->eflag)
                zynqhdr->image_load = cpu_to_le32((uint32_t)params->ep);
 
+       /* User can pass in text file with init list */
+       if (strlen(params->imagename2))
+               zynqimage_parse_initparams(zynqhdr, params->imagename2);
+
        zynqhdr->checksum = zynqimage_checksum(zynqhdr);
 }