   }
   buf_pos += byte_count / 4;
 
-  // Endian swap.  Is there a better way than doing this?  The ROM data on disk on the host machine
-  // is big-endian.
-  for (uint32_t pos = 0; pos < (range_end - range_start); ++pos) {
-    read_buf[pos] =
-      ((read_buf[pos] & 0xFF000000L) >> 24)
-      | ((read_buf[pos] & 0xFF0000L) >> 8)
-      | ((read_buf[pos] & 0xFF00L) << 8)
-      | ((read_buf[pos] & 0xFFL) << 24);
-  }
+  // Endian swap.  Disabled this because I think the data coming from the host may
+  // already have the correct endianness.
+
+  // for (uint32_t pos = 0; pos < (range_end - range_start); ++pos) {
+  //   read_buf[pos] =
+  //     ((read_buf[pos] & 0xFF000000L) >> 24)
+  //     | ((read_buf[pos] & 0xFF0000L) >> 8)
+  //     | ((read_buf[pos] & 0xFF00L) << 8)
+  //     | ((read_buf[pos] & 0xFFL) << 24);
+  // }
 
   return true;
 }

  return (uint8_t)Serial.read();
}

// Read a big-endian uint32 from the USB serial port
uint32_t serial_get_uint32() {
  uint32_t v = (uint32_t)serial_get_uint8() << 24L;
  v |= (uint32_t)serial_get_uint8() << 16L;
  v |= (uint32_t)serial_get_uint8() << 8L;
  v |= (uint32_t)serial_get_uint8();
  return v;
}

// Write a big-endian uint32 to the USB serial port
void serial_put_uint32(uint32_t v) {
  Serial.write((uint8_t)((v & 0xFF000000) >> 24));
  Serial.write((uint8_t)((v & 0xFF0000) >> 16));
  Serial.write((uint8_t)((v & 0xFF00) >> 8));
  Serial.write((uint8_t)(v & 0xFF));
}

// Programming chunks: write 128 words (512 bytes) at a time
#define CHUNK_SIZE 128
#define BUF_SIZE (CHUNK_SIZE + 1)

// TODO move all these vars into the programming code -- we have more RAM in this chip than the atmega32u4 this was originally written for
static uint32_t read_buf[BUF_SIZE];

  }
  // leave flash accessible by host machine
  flash_unlock();
  Serial.println("OK");
}

uint32_t chip_size() {
