fix verification of radio; save radio version read back

The image offset is specified as a raw offset (ignoring any bad
blocks), so we can't seek there by reading that many bytes.

Save the radio data we read and checksummed to the /tmp so we can see
what was read if the checksum is wrong.

Change-Id: Ie855f67932cdcce7c0f2b6772b9531e729fcf9f0
diff --git a/updater/firmware.c b/updater/firmware.c
index 4672e18..42c674c 100644
--- a/updater/firmware.c
+++ b/updater/firmware.c
@@ -101,16 +101,11 @@
     unsigned image_offset = *(unsigned*)(buffer+24);
     unsigned image_length = *(unsigned*)(buffer+28);
     printf("image offset 0x%x length 0x%x\n", image_offset, image_length);
+    mtd_read_skip_to(ctx, image_offset);
 
-    while (pos < image_offset) {
-        size_t to_read = image_offset - pos;
-        if (to_read > block_size) to_read = block_size;
-        ssize_t read = mtd_read_data(ctx, buffer, to_read);
-        if (read < 0) {
-            printf("verify image: failed to skip to image start\n");
-            return -1;
-        }
-        pos += read;
+    FILE* f = fopen("/tmp/read-radio.dat", "wb");
+    if (f == NULL) {
+        printf("verify image: failed to open temp file\n");
     }
 
     SHA_CTX sha_ctx;
@@ -126,11 +121,17 @@
                    total);
             return -1;
         }
+        if (f) {
+            fwrite(buffer, 1, read, f);
+        }
         SHA_update(&sha_ctx, buffer, read);
         total += read;
     }
 
+    if (f) fclose(f);
+
     free(buffer);
+    mtd_read_close(ctx);
 
     const uint8_t* sha1 = SHA_final(&sha_ctx);
     if (memcmp(sha1, expected_sha1, SHA_DIGEST_SIZE) != 0) {