         if (Serial.read() != '\n') break;
         chip_end = chip_size();
         Serial.print("Program whole chip.  Size = ");
-        Serial.println(chip_end * 2);  // Because we actually have double this
-        program_range(0, chip_end / 2);  // Program chip_end/2 words
+        Serial.println(chip_end);
+        program_range(0, chip_end / 4);  // Program chip_end/4 words
         flash_unlock();
         reset();
         break;

  if (Serial.available()) {
    int c = Serial.read();
    switch (c) {
      case 'C': {
        // program CPLD
        Serial.println("SEND SVF");
        arduino_play_svf(TMS_PIN, TDI_PIN, TDO_PIN, TCK_PIN, -1);
        Serial.println("SVF DONE");
        break;
      }
      case 'I': {

  Serial.println("OK");
}

// Return the number of bytes of flash on this board, i.e. double the byte count of one chip
uint32_t chip_size() {
  flash_write_both(0x55, 0x0098L);  // Enter CFI mode
  uint32_t size_log2 = flash_read(0x27) & 0xffff;
