]> git.ipfire.org Git - people/ms/u-boot.git/blobdiff - tools/kwboot.c
net: phy: ensure Gigabit features are masked off if requested
[people/ms/u-boot.git] / tools / kwboot.c
index 1368b4c948ae74e977683880fc8828ea86b95bb7..c5f4492b5f7ab3d4a3b1a609740316cebcb7dae5 100644 (file)
@@ -614,9 +614,10 @@ static int
 kwboot_img_patch_hdr(void *img, size_t size)
 {
        int rc;
-       bhr_t *hdr;
+       struct main_hdr_v1 *hdr;
        uint8_t csum;
-       const size_t hdrsz = sizeof(*hdr);
+       size_t hdrsz = sizeof(*hdr);
+       int image_ver;
 
        rc = -1;
        hdr = img;
@@ -626,8 +627,20 @@ kwboot_img_patch_hdr(void *img, size_t size)
                goto out;
        }
 
-       csum = kwboot_img_csum8(hdr, hdrsz) - hdr->checkSum;
-       if (csum != hdr->checkSum) {
+       image_ver = image_version(img);
+       if (image_ver < 0) {
+               fprintf(stderr, "Invalid image header version\n");
+               errno = EINVAL;
+               goto out;
+       }
+
+       if (image_ver == 0)
+               hdrsz = sizeof(*hdr);
+       else
+               hdrsz = KWBHEADER_V1_SIZE(hdr);
+
+       csum = kwboot_img_csum8(hdr, hdrsz) - hdr->checksum;
+       if (csum != hdr->checksum) {
                errno = EINVAL;
                goto out;
        }
@@ -639,14 +652,18 @@ kwboot_img_patch_hdr(void *img, size_t size)
 
        hdr->blockid = IBR_HDR_UART_ID;
 
-       hdr->nandeccmode = IBR_HDR_ECC_DISABLED;
-       hdr->nandpagesize = 0;
+       if (image_ver == 0) {
+               struct main_hdr_v0 *hdr_v0 = img;
 
-       hdr->srcaddr = hdr->ext
-               ? sizeof(struct kwb_header)
-               : sizeof(*hdr);
+               hdr_v0->nandeccmode = IBR_HDR_ECC_DISABLED;
+               hdr_v0->nandpagesize = 0;
 
-       hdr->checkSum = kwboot_img_csum8(hdr, hdrsz) - csum;
+               hdr_v0->srcaddr = hdr_v0->ext
+                       ? sizeof(struct kwb_header)
+                       : sizeof(*hdr_v0);
+       }
+
+       hdr->checksum = kwboot_img_csum8(hdr, hdrsz) - csum;
 
        rc = 0;
 out:
@@ -657,7 +674,7 @@ static void
 kwboot_usage(FILE *stream, char *progname)
 {
        fprintf(stream,
-               "Usage: %s [-d | -a | -b <image> | -D <image> ] [ -t ] [-B <baud> ] <TTY>\n",
+               "Usage: %s [-d | -a | -q <req-delay> | -s <resp-timeo> | -b <image> | -D <image> ] [ -t ] [-B <baud> ] <TTY>\n",
                progname);
        fprintf(stream, "\n");
        fprintf(stream,
@@ -667,6 +684,8 @@ kwboot_usage(FILE *stream, char *progname)
                "  -D <image>: boot <image> without preamble (Dove)\n");
        fprintf(stream, "  -d: enter debug mode\n");
        fprintf(stream, "  -a: use timings for Armada XP\n");
+       fprintf(stream, "  -q <req-delay>:  use specific request-delay\n");
+       fprintf(stream, "  -s <resp-timeo>: use specific response-timeout\n");
        fprintf(stream, "\n");
        fprintf(stream, "  -t: mini terminal\n");
        fprintf(stream, "\n");
@@ -699,7 +718,7 @@ main(int argc, char **argv)
        kwboot_verbose = isatty(STDOUT_FILENO);
 
        do {
-               int c = getopt(argc, argv, "hb:ptaB:dD:");
+               int c = getopt(argc, argv, "hb:ptaB:dD:q:s:");
                if (c < 0)
                        break;
 
@@ -731,6 +750,14 @@ main(int argc, char **argv)
                        msg_rsp_timeo = KWBOOT_MSG_RSP_TIMEO_AXP;
                        break;
 
+               case 'q':
+                       msg_req_delay = atoi(optarg);
+                       break;
+
+               case 's':
+                       msg_rsp_timeo = atoi(optarg);
+                       break;
+
                case 'B':
                        speed = kwboot_tty_speed(atoi(optarg));
                        if (speed == -1)