mtd: detect image format when writing
[librecmc/librecmc.git] / package / system / mtd / src / trx.c
index 245ee7630ae26aee54e286fd719cda6ecb53b6b0..00c4d6c0b50b7006f5ac503b98db2320000ae63b 100644 (file)
@@ -112,10 +112,12 @@ trx_check(int imagefd, const char *mtd, char *buf, int *len)
        if (strcmp(mtd, "firmware") != 0)
                return 1;
 
-       *len = read(imagefd, buf, 32);
        if (*len < 32) {
-               fprintf(stdout, "Could not get image header, file too small (%d bytes)\n", *len);
-               return 0;
+               *len += read(imagefd, buf + *len, 32 - *len);
+               if (*len < 32) {
+                       fprintf(stdout, "Could not get image header, file too small (%d bytes)\n", *len);
+                       return 0;
+               }
        }
 
        if (trx->magic != TRX_MAGIC || trx->len < sizeof(struct trx_header)) {