aboutsummaryrefslogtreecommitdiff
path: root/tools/kwboot.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/kwboot.c')
-rw-r--r--tools/kwboot.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/tools/kwboot.c b/tools/kwboot.c
index 4be094c9c8..7feeaa45a2 100644
--- a/tools/kwboot.c
+++ b/tools/kwboot.c
@@ -26,12 +26,6 @@
#include <sys/mman.h>
#include <sys/stat.h>
-#ifdef __GNUC__
-#define PACKED __attribute((packed))
-#else
-#define PACKED
-#endif
-
/*
* Marvell BootROM UART Sensing
*/
@@ -68,7 +62,7 @@ struct kwboot_block {
uint8_t _pnum;
uint8_t data[128];
uint8_t csum;
-} PACKED;
+} __packed;
#define KWBOOT_BLK_RSP_TIMEO 1000 /* ms */
@@ -471,7 +465,7 @@ kwboot_term_pipe(int in, int out, char *quit, int *s)
ssize_t nin, nout;
char _buf[128], *buf = _buf;
- nin = read(in, buf, sizeof(buf));
+ nin = read(in, buf, sizeof(_buf));
if (nin <= 0)
return -1;
@@ -485,13 +479,14 @@ kwboot_term_pipe(int in, int out, char *quit, int *s)
return 0;
buf++;
nin--;
- } else
+ } else {
while (*s > 0) {
nout = write(out, quit, *s);
if (nout <= 0)
return -1;
(*s) -= nout;
}
+ }
}
}
@@ -564,7 +559,9 @@ kwboot_terminal(int tty)
}
} while (quit[s] != 0);
- tcsetattr(in, TCSANOW, &otio);
+ if (in >= 0)
+ tcsetattr(in, TCSANOW, &otio);
+ printf("\n");
out:
return rc;
}
@@ -637,7 +634,7 @@ kwboot_img_patch_hdr(void *img, size_t size)
}
image_ver = image_version(img);
- if (image_ver < 0) {
+ if (image_ver != 0 && image_ver != 1) {
fprintf(stderr, "Invalid image header version\n");
errno = EINVAL;
goto out;
@@ -648,6 +645,11 @@ kwboot_img_patch_hdr(void *img, size_t size)
else
hdrsz = KWBHEADER_V1_SIZE(hdr);
+ if (size < hdrsz) {
+ errno = EINVAL;
+ goto out;
+ }
+
csum = kwboot_img_csum8(hdr, hdrsz) - hdr->checksum;
if (csum != hdr->checksum) {
errno = EINVAL;