X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=tools%2Fkwboot.c;h=8a421cda4ea5804224b02436be2ea0440a533715;hb=57f0bc428aeecbc30a89a10be05fa69fd3e64aef;hp=af7a6ee3f6a12c04ac3782cb8703617d63375b45;hpb=b48b69ba10fd1fd1f0de73220438ba8052fc2a33;p=u-boot diff --git a/tools/kwboot.c b/tools/kwboot.c index af7a6ee3f6..8a421cda4e 100644 --- a/tools/kwboot.c +++ b/tools/kwboot.c @@ -9,10 +9,14 @@ * 2008. Chapter 24.2 "BootROM Firmware". */ +#include "kwbimage.h" +#include "mkimage.h" + #include #include #include #include +#include #include #include #include @@ -22,8 +26,6 @@ #include #include -#include "kwbimage.h" - #ifdef __GNUC__ #define PACKED __attribute((packed)) #else @@ -74,6 +76,7 @@ static int kwboot_verbose; static int msg_req_delay = KWBOOT_MSG_REQ_DELAY; static int msg_rsp_timeo = KWBOOT_MSG_RSP_TIMEO; +static int blk_rsp_timeo = KWBOOT_BLK_RSP_TIMEO; static void kwboot_printv(const char *fmt, ...) @@ -378,7 +381,7 @@ kwboot_xm_sendblock(int fd, struct kwboot_block *block) break; do { - rc = kwboot_tty_recv(fd, &c, 1, KWBOOT_BLK_RSP_TIMEO); + rc = kwboot_tty_recv(fd, &c, 1, blk_rsp_timeo); if (rc) break; @@ -614,9 +617,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 +630,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 +655,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_v0->srcaddr = hdr_v0->ext + ? sizeof(struct kwb_header) + : sizeof(*hdr_v0); + } - hdr->checkSum = kwboot_img_csum8(hdr, hdrsz) - csum; + hdr->checksum = kwboot_img_csum8(hdr, hdrsz) - csum; rc = 0; out: @@ -657,7 +677,7 @@ static void kwboot_usage(FILE *stream, char *progname) { fprintf(stream, - "Usage: %s [-d | -a | -q | -s | -b | -D ] [ -t ] [-B ] \n", + "Usage: %s [OPTIONS] [-b | -D ] [-B ] \n", progname); fprintf(stream, "\n"); fprintf(stream, @@ -669,6 +689,8 @@ kwboot_usage(FILE *stream, char *progname) fprintf(stream, " -a: use timings for Armada XP\n"); fprintf(stream, " -q : use specific request-delay\n"); fprintf(stream, " -s : use specific response-timeout\n"); + fprintf(stream, + " -o : use specific xmodem block timeout\n"); fprintf(stream, "\n"); fprintf(stream, " -t: mini terminal\n"); fprintf(stream, "\n"); @@ -701,7 +723,7 @@ main(int argc, char **argv) kwboot_verbose = isatty(STDOUT_FILENO); do { - int c = getopt(argc, argv, "hb:ptaB:dD:q:s:"); + int c = getopt(argc, argv, "hb:ptaB:dD:q:s:o:"); if (c < 0) break; @@ -741,6 +763,10 @@ main(int argc, char **argv) msg_rsp_timeo = atoi(optarg); break; + case 'o': + blk_rsp_timeo = atoi(optarg); + break; + case 'B': speed = kwboot_tty_speed(atoi(optarg)); if (speed == -1)